Przeglądaj źródła

[feat]调整加载方式

Destiny 1 rok temu
rodzic
commit
3df795ea69

+ 46 - 24
lib/handler/photo_scan_handler.dart

@@ -207,8 +207,8 @@ class PhotoScanHandler {
 
     peoplePhotos.clear();
     if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
-      for (var personPhotos in ImagePickerUtil.peoplePhotos) {
-        peoplePhotos.add(personPhotos);
+      for (var personPhoto in ImagePickerUtil.peoplePhotos) {
+        peoplePhotos.add(personPhoto);
         if (peoplePhotos.length == 2) {
           break;
         }
@@ -247,23 +247,13 @@ class PhotoScanHandler {
           progress.value = event.progress;
           final result = event.result;
           if (result != null) {
-            similarResult.addAll(result.similarGroups ?? []);
-            for (var group in similarResult) {
-              await ImagePickerUtil.newUpdatePhotos("similar", group.images);
-            }
-            peopleResult.addAll (result.peopleImages ?? []);
-            await ImagePickerUtil.newUpdatePhotos("people", peopleResult);
-            screenshotResult.addAll(result.screenshotImages ?? []);
-            await ImagePickerUtil.newUpdatePhotos(
-                "screenshot", screenshotResult);
-            blurryResult.addAll(result.blurryImages ?? []);
-            await ImagePickerUtil.newUpdatePhotos("blurry", blurryResult);
+           await loadData(result);
           }
           if (event.progress?.isCompleted == true) {
             isClassifying.value = false;
             _subscription?.cancel();
             _subscription = null;
-            completeClassification();
+            Future.delayed(Duration(seconds: 3),(){ completeClassification();});
           }
         },
         onError: (error) {
@@ -275,6 +265,8 @@ class PhotoScanHandler {
             errorMessage.value = '分类过程意外结束';
             isClassifying.value = false;
           }
+
+
         },
       );
     } catch (e) {
@@ -303,8 +295,6 @@ class PhotoScanHandler {
   void completeClassification() {
     if (ImagePickerUtil.similarPhotos.isNotEmpty) {
       for (var group in ImagePickerUtil.similarPhotos) {
-        print(
-            " ImagePickerUtil.similarPhotos ${ImagePickerUtil.similarPhotos.length}");
         for (var asset in group) {
           similarPhotos.add(asset);
           if (similarPhotos.length == 4) {
@@ -313,14 +303,7 @@ class PhotoScanHandler {
         }
       }
     }
-    if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
-      for (var personPhotos in ImagePickerUtil.peoplePhotos) {
-        peoplePhotos.add(personPhotos);
-        if (peoplePhotos.length == 2) {
-          break;
-        }
-      }
-    }
+
     if (ImagePickerUtil.blurryPhotos.isNotEmpty) {
       var asset = ImagePickerUtil.blurryPhotos.first;
       blurryPhoto.value = asset;
@@ -330,7 +313,46 @@ class PhotoScanHandler {
       var asset = ImagePickerUtil.screenshotPhotos.first;
       screenshotPhoto.value = asset;
     }
+    print("qqq personPhotos ${ImagePickerUtil.peoplePhotos.length}");
+    if (ImagePickerUtil.peoplePhotos.isNotEmpty) {
+      for (AssetEntity personPhotos in ImagePickerUtil.peoplePhotos) {
+        print("qqq personPhotos ${personPhotos.id}");
+        peoplePhotos.add(personPhotos);
+        if (peoplePhotos.length == 2) {
+          break;
+        }
+      }
+    }
+
+    isSimilarScanned.value = true;
+    isPeopleScanned.value = true;
+    isBlurryScanned.value = true;
+    isScreenShotScanned.value = true;
+
   }
 
+  loadData(ClassificationResult result) async {
+
+      if(result.similarGroups!=null){
+        similarResult.assignAll(result.similarGroups??[]);
+        await ImagePickerUtil.newUpdatePhotoGroups("similar", similarResult);
+      }
+
+      if(result.peopleImages!=null){
+        peopleResult.addAll(result.peopleImages ?? []);
+        await ImagePickerUtil.newUpdatePhotoGroup("people", peopleResult);
+      }
+
+      if(result.screenshotImages!=null) {
+        screenshotResult.addAll(result.screenshotImages ?? []);
+        await ImagePickerUtil.newUpdatePhotoGroup(
+            "screenshots", screenshotResult);
+      }
+      if(result.blurryImages!=null){
+        blurryResult.addAll(result.blurryImages ?? []);
+        await ImagePickerUtil.newUpdatePhotoGroup("blurry", blurryResult);
+      }
+
+  }
 
 }

+ 23 - 13
lib/module/image_picker/image_picker_util.dart

@@ -270,20 +270,30 @@ class ImagePickerUtil {
     }
   }
 
-  static Future<void> newUpdatePhotos( String type,
-      List<ClassifiedImage> photoGroups) async {
+  static Future<void> newUpdatePhotoGroups(
+      String type,List<ClassifiedImageGroup> photoGroup
+      )async{
+    if(type=='similar') {
+      // similarPhotos.clear();
+      for (var group in photoGroup) {
+        similarPhotos.add(await _newConvertToAssetEntities(group.images));
+        similarPhotosSize.value +=  group.groupFileSize;
+        similarPhotoCount.value += group.groupImageCount;
+      }
+    }
+  }
+
+  static Future<void> newUpdatePhotoGroup( String type,
+      List<ClassifiedImage> photoGroup) async {
 
       switch (type) {
         case 'screenshots':
           screenshotPhotos.clear();
-          screenshotPhotos.value = await _newConvertToAssetEntities(photoGroups);
-          screenshotsSize.value = photoGroups.fold(0, (sum, image) => sum + image.fileSize);
-          break;
-        case 'similar':
-          similarPhotos.add(await _newConvertToAssetEntities(photoGroups));
-          similarPhotosSize.value = photoGroups.fold(0, (sum, image) => sum + image.fileSize);
-          similarPhotoCount.value = photoGroups.length;
+          screenshotPhotos.value = await _newConvertToAssetEntities(photoGroup);
+          screenshotsSize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
+
           break;
+
         // case 'location':
         //   String location = group['name'] as String;
         //   locationPhotos[location] = await _convertToAssetEntities(photos);
@@ -291,13 +301,13 @@ class ImagePickerUtil {
           break;
         case 'people':
           peoplePhotos.clear();
-          peoplePhotos.value = await _newConvertToAssetEntities(photoGroups);
-          peopleSize.value = photoGroups.fold(0, (sum, image) => sum + image.fileSize);
+          peoplePhotos.assignAll(await _newConvertToAssetEntities(photoGroup));
+          peopleSize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
           break;
         case 'blurry':
           blurryPhotos.clear();
-          blurryPhotos.value = await _newConvertToAssetEntities(photoGroups);
-          blurrySize.value = photoGroups.fold(0, (sum, image) => sum + image.fileSize);
+          blurryPhotos.value = await _newConvertToAssetEntities(photoGroup);
+          blurrySize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
           break;
       }