zefyr

asset_picker_sort_delegate.dart 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. part of ct_assets_picker;
  2. // TODO(lucky1213): 此处需修改翻译
  3. class CustomSortPathDelegate extends SortPathDelegate {
  4. const CustomSortPathDelegate();
  5. @override
  6. void sort(List<AssetPathEntity> list) {
  7. for (final AssetPathEntity entity in list) {
  8. if (entity.isAll) {
  9. entity.name = '图片和视频';
  10. } else if (_isVideo(entity)) {
  11. entity.name = '全部视频';
  12. } else if (_isCamera(entity)) {
  13. entity.name = '相机';
  14. } else if (_isScreenShot(entity)) {
  15. entity.name = '截图';
  16. }
  17. }
  18. list.sort((AssetPathEntity path1, AssetPathEntity path2) {
  19. if (path1.isAll) {
  20. return -1;
  21. }
  22. if (path2.isAll) {
  23. return 1;
  24. }
  25. if (_isCamera(path1)) {
  26. return -1;
  27. }
  28. if (_isCamera(path2)) {
  29. return 1;
  30. }
  31. if (_isVideo(path1)) {
  32. return -1;
  33. }
  34. if (_isVideo(path2)) {
  35. return 1;
  36. }
  37. if (_isScreenShot(path1)) {
  38. return -1;
  39. }
  40. if (_isScreenShot(path2)) {
  41. return 1;
  42. }
  43. return otherSort(path1, path2);
  44. });
  45. }
  46. int otherSort(AssetPathEntity path1, AssetPathEntity path2) {
  47. return path1.name.compareTo(path2.name);
  48. }
  49. bool _isCamera(AssetPathEntity entity) {
  50. return entity.name.toUpperCase() == 'camera'.toUpperCase();
  51. }
  52. bool _isScreenShot(AssetPathEntity entity) {
  53. return entity.name.toUpperCase() == 'screenshots'.toUpperCase() ||
  54. entity.name.toUpperCase() == 'screenshot'.toUpperCase();
  55. }
  56. bool _isVideo(AssetPathEntity entity) {
  57. return entity.name.toUpperCase() == 'Videos'.toUpperCase();
  58. }
  59. }