|
@@ -10,9 +10,12 @@ import 'package:clean/module/people_photo/photo_group.dart';
|
|
|
import 'package:clean/module/photo_preview/photo_preview_controller.dart';
|
|
import 'package:clean/module/photo_preview/photo_preview_controller.dart';
|
|
|
import 'package:clean/module/screenshots_blurry/screenshots_controller.dart';
|
|
import 'package:clean/module/screenshots_blurry/screenshots_controller.dart';
|
|
|
import 'package:clean/module/similar_photo/similar_photo_controller.dart';
|
|
import 'package:clean/module/similar_photo/similar_photo_controller.dart';
|
|
|
|
|
+import 'package:flutter/widgets.dart';
|
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get.dart';
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
|
|
|
|
|
|
+import '../calendar/calendar_state.dart';
|
|
|
|
|
+
|
|
|
class ImagePickerUtil {
|
|
class ImagePickerUtil {
|
|
|
ImagePickerUtil._();
|
|
ImagePickerUtil._();
|
|
|
|
|
|
|
@@ -38,6 +41,10 @@ class ImagePickerUtil {
|
|
|
// 人物图片
|
|
// 人物图片
|
|
|
static final RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
static final RxList<AssetEntity> peoplePhotos = <AssetEntity>[].obs;
|
|
|
|
|
|
|
|
|
|
+ // android测试
|
|
|
|
|
+
|
|
|
|
|
+ static late List<AssetEntity> androidPhotos = <AssetEntity>[];
|
|
|
|
|
+
|
|
|
static final RxSet<String> selectedScreenshotPhotosIds = <String>{}.obs;
|
|
static final RxSet<String> selectedScreenshotPhotosIds = <String>{}.obs;
|
|
|
static final RxSet<String> selectedSimilarPhotosIds = <String>{}.obs;
|
|
static final RxSet<String> selectedSimilarPhotosIds = <String>{}.obs;
|
|
|
static final RxSet<String> selectedLocationPhotosIds = <String>{}.obs;
|
|
static final RxSet<String> selectedLocationPhotosIds = <String>{}.obs;
|
|
@@ -64,54 +71,36 @@ class ImagePickerUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- static Future<void> updatePhotoGroupDate(PhotosType photosType,Set<String> selectedPhotosIds) async {
|
|
|
|
|
- // 1. 统一移除相关的照片列表
|
|
|
|
|
- screenshotPhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
- for (var group in similarPhotos) {
|
|
|
|
|
- group.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
- }
|
|
|
|
|
- locationPhotos.forEach((key, group) => group.removeWhere((element) => selectedPhotosIds.contains(element.id)));
|
|
|
|
|
- peoplePhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
- blurryPhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
- // 2. 移除空的集合
|
|
|
|
|
- similarPhotos.removeWhere((element) => element.isEmpty);
|
|
|
|
|
- locationPhotos.removeWhere((key, value) => value.isEmpty);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- selectedScreenshotPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
- selectedSimilarPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
- selectedLocationPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
- selectedPeoplePhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
- selectedBlurryPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
+ static Future<void> updatePhotoGroupDate(PhotosType photosType,Set<String> selectedPhotosIds1) async {
|
|
|
|
|
+ // 1. 统一移除相关的照片列表
|
|
|
|
|
+ debugPrint("updatePhotoGroupDate1 ScreenshotsController screenshotController $selectedPhotosIds1");
|
|
|
|
|
+ // 2. 移除控制器中的数据
|
|
|
|
|
+ Set<String> selectedPhotosIds = Set.from(selectedPhotosIds1);
|
|
|
|
|
+ updatePhotoData(selectedPhotosIds);
|
|
|
|
|
|
|
|
|
|
+ debugPrint("updatePhotoGroupDate2 ScreenshotsController screenshotController $selectedPhotosIds");
|
|
|
// 3. 根据photosType来处理不同的控制器和photoGroups
|
|
// 3. 根据photosType来处理不同的控制器和photoGroups
|
|
|
switch (photosType) {
|
|
switch (photosType) {
|
|
|
case PhotosType.screenshots:
|
|
case PhotosType.screenshots:
|
|
|
ScreenShotsController screenshotController = Get.find<ScreenShotsController>();
|
|
ScreenShotsController screenshotController = Get.find<ScreenShotsController>();
|
|
|
- screenshotController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- screenshotController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
|
|
+ removeImagesAndEmptyGroups(screenshotController, selectedPhotosIds);
|
|
|
selectedScreenshotPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
selectedScreenshotPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
-
|
|
|
|
|
screenshotController.restoreSelections();
|
|
screenshotController.restoreSelections();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PhotosType.similarPhotos:
|
|
case PhotosType.similarPhotos:
|
|
|
SimilarPhotoController similarController = Get.find<SimilarPhotoController>();
|
|
SimilarPhotoController similarController = Get.find<SimilarPhotoController>();
|
|
|
- similarController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- similarController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
|
|
+ removeImagesAndEmptyGroups(similarController, selectedPhotosIds);
|
|
|
selectedSimilarPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
selectedSimilarPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
similarController.restoreSelections();
|
|
similarController.restoreSelections();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PhotosType.locationPhotos:
|
|
case PhotosType.locationPhotos:
|
|
|
LocationsSinglePhotoController locationsSingleController = Get.find<LocationsSinglePhotoController>();
|
|
LocationsSinglePhotoController locationsSingleController = Get.find<LocationsSinglePhotoController>();
|
|
|
- locationsSingleController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- locationsSingleController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
LocationsPhotoController locationsPhotoController = Get.find<LocationsPhotoController>();
|
|
LocationsPhotoController locationsPhotoController = Get.find<LocationsPhotoController>();
|
|
|
- locationsPhotoController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- locationsPhotoController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
|
|
+ removeImagesAndEmptyGroups(locationsSingleController, selectedPhotosIds);
|
|
|
|
|
+ removeImagesAndEmptyGroups(locationsPhotoController, selectedPhotosIds);
|
|
|
selectedLocationPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
selectedLocationPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
locationsSingleController.restoreSelections();
|
|
locationsSingleController.restoreSelections();
|
|
|
locationsPhotoController.restoreSelections();
|
|
locationsPhotoController.restoreSelections();
|
|
@@ -119,21 +108,55 @@ class ImagePickerUtil {
|
|
|
|
|
|
|
|
case PhotosType.peoplePhotos:
|
|
case PhotosType.peoplePhotos:
|
|
|
PeoplePhotoController peoplePhotoController = Get.find<PeoplePhotoController>();
|
|
PeoplePhotoController peoplePhotoController = Get.find<PeoplePhotoController>();
|
|
|
- peoplePhotoController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- peoplePhotoController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
|
|
+ removeImagesAndEmptyGroups(peoplePhotoController, selectedPhotosIds);
|
|
|
selectedPeoplePhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
selectedPeoplePhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
peoplePhotoController.restoreSelections();
|
|
peoplePhotoController.restoreSelections();
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case PhotosType.blurryPhotos:
|
|
case PhotosType.blurryPhotos:
|
|
|
ScreenShotsController blurryController = Get.find<ScreenShotsController>();
|
|
ScreenShotsController blurryController = Get.find<ScreenShotsController>();
|
|
|
- blurryController.photoGroups.removeWhere((element) => element.images.any((image) => selectedPhotosIds.contains(image.id)));
|
|
|
|
|
- blurryController.photoGroups.removeWhere((element) => element.images.isEmpty);
|
|
|
|
|
|
|
+ removeImagesAndEmptyGroups(blurryController, selectedPhotosIds);
|
|
|
selectedBlurryPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
selectedBlurryPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
blurryController.restoreSelections();
|
|
blurryController.restoreSelections();
|
|
|
break;
|
|
break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 移除每组图片里面对应的元素并删除空的组
|
|
|
|
|
+ static void removeImagesAndEmptyGroups(dynamic controller, Set<String> selectedPhotosIds) {
|
|
|
|
|
+ // 创建photoGroups的副本进行遍历,避免遍历过程中修改photoGroups
|
|
|
|
|
+ for (var group in List.from(controller.photoGroups)) {
|
|
|
|
|
+ // 移除所有与selectedPhotosIds匹配的图片
|
|
|
|
|
+ group.images.removeWhere((image) => selectedPhotosIds.contains(image.id));
|
|
|
|
|
+
|
|
|
|
|
+ // 如果当前组内没有图片了,删除该组
|
|
|
|
|
+ if (group.images.isEmpty) {
|
|
|
|
|
+ controller.photoGroups.remove(group);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ static void updatePhotoData(Set<String> selectedPhotosIds1) {
|
|
|
|
|
|
|
|
|
|
+ debugPrint("ImagePickerUtil1 updatePhotoData $selectedPhotosIds1");
|
|
|
|
|
+ Set<String> selectedPhotosIds = Set.from(selectedPhotosIds1);
|
|
|
|
|
+ screenshotPhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
+ for (var group in similarPhotos) {
|
|
|
|
|
+ group.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
}
|
|
}
|
|
|
|
|
+ locationPhotos.forEach((key, group) => group.removeWhere((element) => selectedPhotosIds.contains(element.id)));
|
|
|
|
|
+ peoplePhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
+ blurryPhotos.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
|
|
+ // 2. 移除空的集合
|
|
|
|
|
+ similarPhotos.removeWhere((element) => element.isEmpty);
|
|
|
|
|
+ locationPhotos.removeWhere((key, value) => value.isEmpty);
|
|
|
|
|
+
|
|
|
|
|
+ debugPrint("ImagePickerUtil2 updatePhotoData $selectedPhotosIds");
|
|
|
|
|
+ selectedScreenshotPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
+ selectedSimilarPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
+ selectedLocationPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
+ selectedPeoplePhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
+ selectedBlurryPhotosIds.removeWhere((element) => selectedPhotosIds.contains(element));
|
|
|
|
|
+ debugPrint("ImagePickerUtil3 updatePhotoData $selectedPhotosIds");
|
|
|
|
|
+ CalendarState.removePhotosData(selectedPhotosIds);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新照片数据
|
|
// 更新照片数据
|
|
@@ -278,11 +301,16 @@ class ImagePickerUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- static Future<List<AssetEntity>> loadAssetsAndroid({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();
|
|
|
if (!result.isAuth) return [];
|
|
if (!result.isAuth) return [];
|
|
|
|
|
|
|
|
|
|
+ if (androidPhotos.isNotEmpty) return androidPhotos;
|
|
|
// 选择相册
|
|
// 选择相册
|
|
|
|
|
+
|
|
|
final List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
|
|
final List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
|
|
|
type: RequestType.image,
|
|
type: RequestType.image,
|
|
|
filterOption: FilterOptionGroup(
|
|
filterOption: FilterOptionGroup(
|
|
@@ -298,12 +326,13 @@ class ImagePickerUtil {
|
|
|
|
|
|
|
|
if (albums.isEmpty) return [];
|
|
if (albums.isEmpty) return [];
|
|
|
|
|
|
|
|
|
|
+ print('相册数量:$albums');
|
|
|
// 获取图片资源
|
|
// 获取图片资源
|
|
|
- final List<AssetEntity> assets = await albums.first.getAssetListPaged(
|
|
|
|
|
|
|
+ androidPhotos = await albums.first.getAssetListPaged(
|
|
|
page: 0,
|
|
page: 0,
|
|
|
- size: 10000, // 获取 10000 张图片
|
|
|
|
|
|
|
+ size: 10000,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- return assets;
|
|
|
|
|
|
|
+ return androidPhotos;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|