Quellcode durchsuchen

Merge pull request #30 from CaiJingLong/sort-asset

Sort asset
C vor 5 Jahren
Ursprung
Commit
dd791a0d7f
Es ist kein Benutzerkonto mit dieser Commiter-Email verbunden

+ 4
- 4
example/android/app/build.gradle Datei anzeigen

@@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
25 25
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
26 26
 
27 27
 android {
28
-    compileSdkVersion 27
28
+    compileSdkVersion 28
29 29
 
30 30
     lintOptions {
31 31
         disable 'InvalidPackage'
@@ -35,7 +35,7 @@ android {
35 35
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
36 36
         applicationId "com.example.example"
37 37
         minSdkVersion 16
38
-        targetSdkVersion 27
38
+        targetSdkVersion 28
39 39
         versionCode flutterVersionCode.toInteger()
40 40
         versionName flutterVersionName
41 41
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -56,6 +56,6 @@ flutter {
56 56
 
57 57
 dependencies {
58 58
     testImplementation 'junit:junit:4.12'
59
-    androidTestImplementation 'com.android.support.test:runner:1.0.2'
60
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
59
+//    androidTestImplementation 'com.android.support.test:runner:1.0.2'
60
+//    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
61 61
 }

+ 1
- 1
example/android/build.gradle Datei anzeigen

@@ -5,7 +5,7 @@ buildscript {
5 5
     }
6 6
 
7 7
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:3.1.2'
8
+        classpath 'com.android.tools.build:gradle:3.3.1'
9 9
     }
10 10
 }
11 11
 

+ 2
- 0
example/android/gradle.properties Datei anzeigen

@@ -1 +1,3 @@
1 1
 org.gradle.jvmargs=-Xmx1536M
2
+android.enableJetifier=true
3
+android.useAndroidX=true

+ 1
- 1
example/android/gradle/wrapper/gradle-wrapper.properties Datei anzeigen

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

+ 18
- 0
lib/src/delegate/sort_asset_delegate.dart Datei anzeigen

@@ -0,0 +1,18 @@
1
+part of './sort_delegate.dart';
2
+
3
+abstract class SortAssetDelegate {
4
+  const SortAssetDelegate();
5
+
6
+  void sort(List<AssetEntity> list);
7
+}
8
+
9
+class DefaultAssetDelegate extends SortAssetDelegate {
10
+  const DefaultAssetDelegate();
11
+
12
+  @override
13
+  void sort(List<AssetEntity> list) {
14
+    list.sort((entity1, entity2) {
15
+      return entity2.createTime.compareTo(entity1.createTime);
16
+    });
17
+  }
18
+}

+ 14
- 3
lib/src/delegate/sort_delegate.dart Datei anzeigen

@@ -1,7 +1,14 @@
1 1
 import 'package:photo_manager/photo_manager.dart';
2 2
 
3
+part './sort_asset_delegate.dart';
4
+
5
+/// SortPathDelegate
3 6
 abstract class SortDelegate {
4
-  const SortDelegate();
7
+  final SortAssetDelegate assetDelegate;
8
+
9
+  const SortDelegate({
10
+    this.assetDelegate = const DefaultAssetDelegate(),
11
+  });
5 12
 
6 13
   void sort(List<AssetPathEntity> list);
7 14
 
@@ -11,14 +18,18 @@ abstract class SortDelegate {
11 18
 }
12 19
 
13 20
 class DefaultSortDelegate extends SortDelegate {
14
-  const DefaultSortDelegate();
21
+  const DefaultSortDelegate({
22
+    SortAssetDelegate assetDelegate = const DefaultAssetDelegate(),
23
+  }) : super(assetDelegate: assetDelegate);
15 24
 
16 25
   @override
17 26
   void sort(List<AssetPathEntity> list) {}
18 27
 }
19 28
 
20 29
 class CommonSortDelegate extends SortDelegate {
21
-  const CommonSortDelegate();
30
+  const CommonSortDelegate({
31
+    SortAssetDelegate assetDelegate = const DefaultAssetDelegate(),
32
+  }) : super(assetDelegate: assetDelegate);
22 33
 
23 34
   @override
24 35
   void sort(List<AssetPathEntity> list) {

+ 7
- 0
lib/src/ui/page/photo_main_page.dart Datei anzeigen

@@ -178,6 +178,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
178 178
     galleryPathList.addAll(widget.photoList);
179 179
     this.list.clear();
180 180
     var assetList = await galleryPathList[0].assetList;
181
+    _sortAssetList(assetList);
181 182
     this.list.addAll(assetList);
182 183
     setState(() {
183 184
       _isInit = true;
@@ -210,6 +211,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
210 211
 
211 212
     if (pathList.isNotEmpty) {
212 213
       imageList = await pathList[0].assetList;
214
+      _sortAssetList(imageList);
213 215
       _currentPath = pathList[0];
214 216
     }
215 217
 
@@ -228,6 +230,10 @@ class _PhotoMainPageState extends State<PhotoMainPage>
228 230
     });
229 231
   }
230 232
 
233
+  void _sortAssetList(List<AssetEntity> assetList) {
234
+    options?.sortDelegate?.assetDelegate?.sort(assetList);
235
+  }
236
+
231 237
   Widget _buildBody() {
232 238
     if (!_isInit) {
233 239
       return _buildLoading();
@@ -342,6 +348,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
342 348
     _currentPath = value;
343 349
 
344 350
     _currentPath.assetList.then((v) {
351
+      _sortAssetList(v);
345 352
       list.clear();
346 353
       list.addAll(v);
347 354
       scrollController.jumpTo(0.0);

+ 6
- 4
pubspec.lock Datei anzeigen

@@ -70,10 +70,12 @@ packages:
70 70
   photo_manager:
71 71
     dependency: "direct main"
72 72
     description:
73
-      name: photo_manager
74
-      url: "https://pub.flutter-io.cn"
75
-    source: hosted
76
-    version: "0.2.1"
73
+      path: "."
74
+      ref: "8ef0bf9047cdd86e2331f0db8d15c4c50f35610d"
75
+      resolved-ref: "8ef0bf9047cdd86e2331f0db8d15c4c50f35610d"
76
+      url: "https://github.com/CaiJingLong/flutter_photo_manager.git"
77
+    source: git
78
+    version: "0.3.0"
77 79
   quiver:
78 80
     dependency: transitive
79 81
     description:

+ 5
- 5
pubspec.yaml Datei anzeigen

@@ -11,11 +11,11 @@ dependencies:
11 11
   flutter:
12 12
     sdk: flutter
13 13
 
14
-  photo_manager: ^0.2.1
15
-  # photo_manager:
16
-  #   git:
17
-  #     url: https://github.com/CaiJingLong/flutter_photo_manager.git
18
-  #     ref: 29d844b2c4594d7e524d0169658bc4f3b9ef2ddc
14
+  # photo_manager: ^0.2.1
15
+  photo_manager:
16
+    git:
17
+      url: https://github.com/CaiJingLong/flutter_photo_manager.git
18
+      ref: 8ef0bf9047cdd86e2331f0db8d15c4c50f35610d
19 19
   # photo_manager:
20 20
   #   path: ../flutter_photo_manager
21 21