Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

78 行
1.7 KiB

  1. import 'package:photo_manager/photo_manager.dart';
  2. part './sort_asset_delegate.dart';
  3. /// SortPathDelegate
  4. abstract class SortDelegate {
  5. final SortAssetDelegate assetDelegate;
  6. const SortDelegate({
  7. this.assetDelegate = const DefaultAssetDelegate(),
  8. });
  9. void sort(List<AssetPathEntity> list);
  10. static const none = DefaultSortDelegate();
  11. static const common = CommonSortDelegate();
  12. }
  13. class DefaultSortDelegate extends SortDelegate {
  14. const DefaultSortDelegate({
  15. SortAssetDelegate assetDelegate = const DefaultAssetDelegate(),
  16. }) : super(assetDelegate: assetDelegate);
  17. @override
  18. void sort(List<AssetPathEntity> list) {}
  19. }
  20. class CommonSortDelegate extends SortDelegate {
  21. const CommonSortDelegate({
  22. SortAssetDelegate assetDelegate = const DefaultAssetDelegate(),
  23. }) : super(assetDelegate: assetDelegate);
  24. @override
  25. void sort(List<AssetPathEntity> list) {
  26. list.sort((path1, path2) {
  27. if (path1.isAll) {
  28. return -1;
  29. }
  30. if (path2.isAll) {
  31. return 1;
  32. }
  33. if (_isCamera(path1)) {
  34. return -1;
  35. }
  36. if (_isCamera(path2)) {
  37. return 1;
  38. }
  39. if (_isScreenShot(path1)) {
  40. return -1;
  41. }
  42. if (_isScreenShot(path2)) {
  43. return 1;
  44. }
  45. return otherSort(path1, path2);
  46. });
  47. }
  48. int otherSort(AssetPathEntity path1, AssetPathEntity path2) {
  49. return path1.name.compareTo(path2.name);
  50. }
  51. bool _isCamera(AssetPathEntity entity) {
  52. return entity.name.toUpperCase() == "camera".toUpperCase();
  53. }
  54. bool _isScreenShot(AssetPathEntity entity) {
  55. return entity.name.toUpperCase() == "screenshots".toUpperCase() ||
  56. entity.name.toUpperCase() == "screenshot".toUpperCase();
  57. }
  58. }