|
@@ -62,8 +62,10 @@ class ImagePickerUtil {
|
|
|
static final Rx<int> peopleSize = 0.obs;
|
|
static final Rx<int> peopleSize = 0.obs;
|
|
|
static final Rx<int> similarPhotosSize = 0.obs;
|
|
static final Rx<int> similarPhotosSize = 0.obs;
|
|
|
|
|
|
|
|
- // // 用来缓存文件大小
|
|
|
|
|
- // static final Map<String, double> fileSizeCache = {};
|
|
|
|
|
|
|
+ static var similarResult = <ClassifiedImageGroup>[].obs;
|
|
|
|
|
+ static var peopleResult = <ClassifiedImage>[].obs;
|
|
|
|
|
+ static var screenshotResult = <ClassifiedImage>[].obs;
|
|
|
|
|
+ static var blurryResult = <ClassifiedImage>[].obs;
|
|
|
|
|
|
|
|
// 清除所有照片数据
|
|
// 清除所有照片数据
|
|
|
static void clearAllPhotos() {
|
|
static void clearAllPhotos() {
|
|
@@ -74,16 +76,38 @@ class ImagePickerUtil {
|
|
|
peoplePhotos.clear();
|
|
peoplePhotos.clear();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ static loadData(ClassificationResult result) async {
|
|
|
|
|
+ if (result.similarGroups != null) {
|
|
|
|
|
+ similarResult.assignAll(result.similarGroups ?? []);
|
|
|
|
|
+ await newUpdatePhotoGroups("similar", similarResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ if (result.peopleImages != null) {
|
|
|
|
|
+ peopleResult.addAll(result.peopleImages ?? []);
|
|
|
|
|
+ await newUpdatePhotoGroup("people", peopleResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- static Future<void> updatePhotoGroupDate(PhotosType photosType,Set<String> selectedPhotosIds1) async {
|
|
|
|
|
|
|
+ if (result.screenshotImages != null) {
|
|
|
|
|
+ screenshotResult.addAll(result.screenshotImages ?? []);
|
|
|
|
|
+ await newUpdatePhotoGroup("screenshots", screenshotResult);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (result.blurryImages != null) {
|
|
|
|
|
+ blurryResult.addAll(result.blurryImages ?? []);
|
|
|
|
|
+ await newUpdatePhotoGroup("blurry", blurryResult);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ static Future<void> updatePhotoGroupDate(
|
|
|
|
|
+ PhotosType photosType, Set<String> selectedPhotosIds1) async {
|
|
|
// // 1. 统一移除相关的照片列表
|
|
// // 1. 统一移除相关的照片列表
|
|
|
- debugPrint("updatePhotoGroupDate1 ScreenshotsController screenshotController $selectedPhotosIds1");
|
|
|
|
|
|
|
+ debugPrint(
|
|
|
|
|
+ "updatePhotoGroupDate1 ScreenshotsController screenshotController $selectedPhotosIds1");
|
|
|
// 2. 移除控制器中的数据
|
|
// 2. 移除控制器中的数据
|
|
|
Set<String> selectedPhotosIds = Set.from(selectedPhotosIds1);
|
|
Set<String> selectedPhotosIds = Set.from(selectedPhotosIds1);
|
|
|
updatePhotoData(selectedPhotosIds);
|
|
updatePhotoData(selectedPhotosIds);
|
|
|
//
|
|
//
|
|
|
- debugPrint("updatePhotoGroupDate2 ScreenshotsController screenshotController $selectedPhotosIds");
|
|
|
|
|
|
|
+ debugPrint(
|
|
|
|
|
+ "updatePhotoGroupDate2 ScreenshotsController screenshotController $selectedPhotosIds");
|
|
|
// 3. 根据photosType来处理不同的控制器和photoGroups
|
|
// 3. 根据photosType来处理不同的控制器和photoGroups
|
|
|
switch (photosType) {
|
|
switch (photosType) {
|
|
|
case PhotosType.screenshots:
|
|
case PhotosType.screenshots:
|
|
@@ -94,9 +118,11 @@ class ImagePickerUtil {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PhotosType.similarPhotos:
|
|
case PhotosType.similarPhotos:
|
|
|
- SimilarPhotoController similarController = Get.find<SimilarPhotoController>();
|
|
|
|
|
|
|
+ SimilarPhotoController similarController =
|
|
|
|
|
+ Get.find<SimilarPhotoController>();
|
|
|
removeImagesAndEmptyGroups(similarController, selectedPhotosIds);
|
|
removeImagesAndEmptyGroups(similarController, selectedPhotosIds);
|
|
|
- selectedSimilarPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
|
|
+ selectedSimilarPhotosIds
|
|
|
|
|
+ .removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
similarController.restoreSelections();
|
|
similarController.restoreSelections();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -224,6 +250,23 @@ class ImagePickerUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ peopleResult
|
|
|
|
|
+ .removeWhere((element) => selectedPhotosIds.contains(element.assetsId));
|
|
|
|
|
+ peopleSize.value =
|
|
|
|
|
+ peopleResult.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
+ screenshotResult
|
|
|
|
|
+ .removeWhere((element) => selectedPhotosIds.contains(element.assetsId));
|
|
|
|
|
+ screenshotsSize.value =
|
|
|
|
|
+ screenshotResult.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
+ blurryResult
|
|
|
|
|
+ .removeWhere((element) => selectedPhotosIds.contains(element.assetsId));
|
|
|
|
|
+ blurrySize.value =
|
|
|
|
|
+ blurryResult.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
+ similarResult.map((group) => group.images.removeWhere(
|
|
|
|
|
+ (element) => selectedPhotosIds.contains(element.assetsId)));
|
|
|
|
|
+ similarPhotoCount.value =
|
|
|
|
|
+ similarResult.fold(0, (sum, group) => sum + group.groupImageCount);
|
|
|
|
|
+
|
|
|
debugPrint("ImagePickerUtil3 updatePhotoData $selectedPhotosIds");
|
|
debugPrint("ImagePickerUtil3 updatePhotoData $selectedPhotosIds");
|
|
|
CalendarState.removePhotosData(selectedPhotosIds);
|
|
CalendarState.removePhotosData(selectedPhotosIds);
|
|
|
}
|
|
}
|
|
@@ -271,46 +314,46 @@ class ImagePickerUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static Future<void> newUpdatePhotoGroups(
|
|
static Future<void> newUpdatePhotoGroups(
|
|
|
- String type,List<ClassifiedImageGroup> photoGroup
|
|
|
|
|
- )async{
|
|
|
|
|
- if(type=='similar') {
|
|
|
|
|
|
|
+ String type, List<ClassifiedImageGroup> photoGroup) async {
|
|
|
|
|
+ if (type == 'similar') {
|
|
|
// similarPhotos.clear();
|
|
// similarPhotos.clear();
|
|
|
for (var group in photoGroup) {
|
|
for (var group in photoGroup) {
|
|
|
similarPhotos.add(await _newConvertToAssetEntities(group.images));
|
|
similarPhotos.add(await _newConvertToAssetEntities(group.images));
|
|
|
- similarPhotosSize.value += group.groupFileSize;
|
|
|
|
|
|
|
+ similarPhotosSize.value += group.groupFileSize;
|
|
|
similarPhotoCount.value += group.groupImageCount;
|
|
similarPhotoCount.value += group.groupImageCount;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static Future<void> newUpdatePhotoGroup( String type,
|
|
|
|
|
- List<ClassifiedImage> photoGroup) async {
|
|
|
|
|
|
|
+ static Future<void> newUpdatePhotoGroup(
|
|
|
|
|
+ String type, List<ClassifiedImage> photoGroup) async {
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case 'screenshots':
|
|
|
|
|
+ screenshotPhotos.clear();
|
|
|
|
|
+ screenshotPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
|
|
+ screenshotsSize.value =
|
|
|
|
|
+ photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
|
|
|
- switch (type) {
|
|
|
|
|
- case 'screenshots':
|
|
|
|
|
- screenshotPhotos.clear();
|
|
|
|
|
- screenshotPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
|
|
- screenshotsSize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
-
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
// case 'location':
|
|
// case 'location':
|
|
|
// String location = group['name'] as String;
|
|
// String location = group['name'] as String;
|
|
|
// locationPhotos[location] = await _convertToAssetEntities(photos);
|
|
// locationPhotos[location] = await _convertToAssetEntities(photos);
|
|
|
// locationsSize.value = totalSize;
|
|
// locationsSize.value = totalSize;
|
|
|
- break;
|
|
|
|
|
- case 'people':
|
|
|
|
|
- peoplePhotos.clear();
|
|
|
|
|
- peoplePhotos.assignAll(await _newConvertToAssetEntities(photoGroup));
|
|
|
|
|
- peopleSize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
- break;
|
|
|
|
|
- case 'blurry':
|
|
|
|
|
- blurryPhotos.clear();
|
|
|
|
|
- blurryPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
|
|
- blurrySize.value = photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'people':
|
|
|
|
|
+ peoplePhotos.clear();
|
|
|
|
|
+ peoplePhotos.assignAll(await _newConvertToAssetEntities(photoGroup));
|
|
|
|
|
+ peopleSize.value =
|
|
|
|
|
+ photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'blurry':
|
|
|
|
|
+ blurryPhotos.clear();
|
|
|
|
|
+ blurryPhotos.value = await _newConvertToAssetEntities(photoGroup);
|
|
|
|
|
+ blurrySize.value =
|
|
|
|
|
+ photoGroup.fold(0, (sum, image) => sum + image.fileSize);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将原始照片数据转换为 AssetEntity 列表
|
|
// 将原始照片数据转换为 AssetEntity 列表
|
|
@@ -427,6 +470,7 @@ class ImagePickerUtil {
|
|
|
return '${(sizeInGB / 1024).toStringAsFixed(1)} ';
|
|
return '${(sizeInGB / 1024).toStringAsFixed(1)} ';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
static Future<List<AssetEntity>> loadAssetsPaged({
|
|
static Future<List<AssetEntity>> loadAssetsPaged({
|
|
|
int page = 0,
|
|
int page = 0,
|
|
|
int pageSize = 9,
|
|
int pageSize = 9,
|
|
@@ -460,6 +504,7 @@ class ImagePickerUtil {
|
|
|
|
|
|
|
|
return assets;
|
|
return assets;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// 加载图片资源
|
|
// 加载图片资源
|
|
|
static Future<List<AssetEntity>> loadAssets({bool sortByDate = true}) async {
|
|
static Future<List<AssetEntity>> loadAssets({bool sortByDate = true}) async {
|
|
|
final PermissionState result = await PhotoManager.requestPermissionExtend();
|
|
final PermissionState result = await PhotoManager.requestPermissionExtend();
|