|
|
@@ -3,21 +3,22 @@ import 'dart:async';
|
|
|
import 'package:clean/base/base_controller.dart';
|
|
|
import 'package:clean/data/bean/photos_type.dart';
|
|
|
import 'package:clean/module/image_picker/image_picker_util.dart';
|
|
|
+import 'package:clean/module/locations_photo/locations_single_photo_controller.dart';
|
|
|
import 'package:clean/module/people_photo/people_photo_controller.dart';
|
|
|
import 'package:clean/module/people_photo/photo_group.dart';
|
|
|
import 'package:clean/module/screenshots_blurry/screenshots_controller.dart';
|
|
|
import 'package:clean/module/similar_photo/similar_photo_controller.dart';
|
|
|
+import 'package:clean/utils/file_utils.dart';
|
|
|
import 'package:flutter/Material.dart';
|
|
|
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
-
|
|
|
class PhotoPreviewController extends BaseController {
|
|
|
Rx<CardSwiperController> cardSwiperController = CardSwiperController().obs;
|
|
|
final RxList<AssetEntity> photoGroups = <AssetEntity>[].obs;
|
|
|
final RxSet<String> selectedPhotosIds = <String>{}.obs;
|
|
|
-
|
|
|
+ final RxBool isSwiperEnd = false.obs;
|
|
|
RxInt groupIndex = 0.obs;
|
|
|
|
|
|
late PhotosType photosType;
|
|
|
@@ -28,7 +29,7 @@ class PhotoPreviewController extends BaseController {
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
-
|
|
|
+ isSwiperEnd.value = false;
|
|
|
print('PhotoPreviewController onInit');
|
|
|
_getArgs(); // 获取传递的参数
|
|
|
_initData(); // 初始化数据
|
|
|
@@ -57,39 +58,44 @@ class PhotoPreviewController extends BaseController {
|
|
|
photoGroups.clear();
|
|
|
selectedPhotosIds.clear();
|
|
|
|
|
|
- switch(photosType) {
|
|
|
+ switch (photosType) {
|
|
|
case PhotosType.peoplePhotos:
|
|
|
photoGroups.assignAll(ImagePickerUtil.peoplePhotos);
|
|
|
selectedPhotosIds.assignAll(ImagePickerUtil.selectedPeoplePhotosIds);
|
|
|
- selectedFileCount.value = ImagePickerUtil.selectedPeoplePhotosIds.length;
|
|
|
+ selectedFileCount.value =
|
|
|
+ ImagePickerUtil.selectedPeoplePhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.screenshots:
|
|
|
photoGroups.assignAll(ImagePickerUtil.screenshotPhotos);
|
|
|
- selectedPhotosIds.assignAll(ImagePickerUtil.selectedScreenshotPhotosIds);
|
|
|
- selectedFileCount.value = ImagePickerUtil.selectedScreenshotPhotosIds.length;
|
|
|
+ selectedPhotosIds
|
|
|
+ .assignAll(ImagePickerUtil.selectedScreenshotPhotosIds);
|
|
|
+ selectedFileCount.value =
|
|
|
+ ImagePickerUtil.selectedScreenshotPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.similarPhotos:
|
|
|
for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
photoGroups.addAll(group);
|
|
|
}
|
|
|
selectedPhotosIds.assignAll(ImagePickerUtil.selectedSimilarPhotosIds);
|
|
|
- selectedFileCount.value = ImagePickerUtil.selectedSimilarPhotosIds.length;
|
|
|
+ selectedFileCount.value =
|
|
|
+ ImagePickerUtil.selectedSimilarPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.locationPhotos:
|
|
|
for (var group in ImagePickerUtil.locationPhotos.values) {
|
|
|
photoGroups.addAll(group);
|
|
|
}
|
|
|
selectedPhotosIds.assignAll(ImagePickerUtil.selectedLocationPhotosIds);
|
|
|
- selectedFileCount.value = ImagePickerUtil.selectedLocationPhotosIds.length;
|
|
|
+ selectedFileCount.value =
|
|
|
+ ImagePickerUtil.selectedLocationPhotosIds.length;
|
|
|
break;
|
|
|
- case PhotosType.blurryPhotos:
|
|
|
+ case PhotosType.blurryPhotos:
|
|
|
photoGroups.assignAll(ImagePickerUtil.blurryPhotos);
|
|
|
selectedPhotosIds.assignAll(ImagePickerUtil.selectedBlurryPhotosIds);
|
|
|
- selectedFileCount.value = ImagePickerUtil.selectedBlurryPhotosIds.length;
|
|
|
+ selectedFileCount.value =
|
|
|
+ ImagePickerUtil.selectedBlurryPhotosIds.length;
|
|
|
break;
|
|
|
}
|
|
|
updateSelectedFilesSize();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
Future<void> updateSelectedFilesSize() async {
|
|
|
@@ -109,12 +115,11 @@ class PhotoPreviewController extends BaseController {
|
|
|
}
|
|
|
|
|
|
void recoverSelectPhoto() {
|
|
|
+
|
|
|
cardSwiperController.value.undo();
|
|
|
}
|
|
|
|
|
|
void clickSelect() {
|
|
|
-
|
|
|
-
|
|
|
cardSwiperController.value.swipe(CardSwiperDirection.left);
|
|
|
}
|
|
|
|
|
|
@@ -124,11 +129,9 @@ class PhotoPreviewController extends BaseController {
|
|
|
|
|
|
// 清理操作,释放资源
|
|
|
cardSwiperController.value.dispose();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void clickBack() {
|
|
|
-
|
|
|
_saveSelectedPhotos(photosType);
|
|
|
Get.back();
|
|
|
}
|
|
|
@@ -139,28 +142,38 @@ class PhotoPreviewController extends BaseController {
|
|
|
case PhotosType.peoplePhotos:
|
|
|
ImagePickerUtil.selectedPeoplePhotosIds.assignAll(selectedPhotosIds);
|
|
|
PeoplePhotoController controller = Get.find<PeoplePhotoController>();
|
|
|
+ controller.loadPeoplePhoto();
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.screenshots:
|
|
|
- ImagePickerUtil.selectedScreenshotPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ ImagePickerUtil.selectedScreenshotPhotosIds
|
|
|
+ .assignAll(selectedPhotosIds);
|
|
|
ScreenShotsController controller = Get.find<ScreenShotsController>();
|
|
|
+ controller.loadScreenshots();
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.similarPhotos:
|
|
|
ImagePickerUtil.selectedSimilarPhotosIds.assignAll(selectedPhotosIds);
|
|
|
SimilarPhotoController controller = Get.find<SimilarPhotoController>();
|
|
|
+ controller.loadSimilarPhotos();
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.locationPhotos:
|
|
|
ImagePickerUtil.selectedLocationPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ LocationsSinglePhotoController controller =
|
|
|
+ Get.find<LocationsSinglePhotoController>();
|
|
|
+ controller.loadLocationsSinglePhoto();
|
|
|
+ controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.blurryPhotos:
|
|
|
ImagePickerUtil.selectedBlurryPhotosIds.assignAll(selectedPhotosIds);
|
|
|
ScreenShotsController controller = Get.find<ScreenShotsController>();
|
|
|
+ controller.loadScreenshots();
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
void clickUnselect() {
|
|
|
print("clickUnselect");
|
|
|
cardSwiperController.value.swipe(CardSwiperDirection.right);
|
|
|
@@ -219,5 +232,63 @@ class PhotoPreviewController extends BaseController {
|
|
|
updateSelectedFilesSize();
|
|
|
return true;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ onSwiperEnd() {
|
|
|
+ isSwiperEnd.value = true;
|
|
|
+ print('onSwiperEnd');
|
|
|
+ }
|
|
|
+
|
|
|
+ clickDelete() async{
|
|
|
+ print('clickDelete');
|
|
|
+ switch(photosType){
|
|
|
+ case PhotosType.peoplePhotos:
|
|
|
+ ImagePickerUtil.selectedPeoplePhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ break;
|
|
|
+ case PhotosType.screenshots:
|
|
|
+ ImagePickerUtil.selectedScreenshotPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ break;
|
|
|
+ case PhotosType.similarPhotos:
|
|
|
+ ImagePickerUtil.selectedSimilarPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ break;
|
|
|
+ case PhotosType.locationPhotos:
|
|
|
+ ImagePickerUtil.selectedLocationPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ break;
|
|
|
+ case PhotosType.blurryPhotos:
|
|
|
+ ImagePickerUtil.selectedBlurryPhotosIds.assignAll(selectedPhotosIds);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (selectedPhotosIds.isNotEmpty) {
|
|
|
+ // 获取要删除的资产
|
|
|
+ final assetsToDelete = photoGroups.where(
|
|
|
+ (asset) => selectedPhotosIds.contains(asset.id),
|
|
|
+ ).toList();
|
|
|
+
|
|
|
+ // 调用方法会返回被删除的资源,如果全部失败会返回空列表。
|
|
|
+ final List<String> result = await PhotoManager.editor.deleteWithIds(
|
|
|
+ assetsToDelete.map((e) => e.id).toList(),
|
|
|
+ );
|
|
|
+ print ('PhotoPreviewController result $result');
|
|
|
+ }
|
|
|
+
|
|
|
+ switch(photosType){
|
|
|
+ case PhotosType.peoplePhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(PhotosType.peoplePhotos);
|
|
|
+ break;
|
|
|
+ case PhotosType.screenshots:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(PhotosType.screenshots);
|
|
|
+ break;
|
|
|
+ case PhotosType.similarPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(PhotosType.similarPhotos);
|
|
|
+ break;
|
|
|
+ case PhotosType.locationPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(PhotosType.locationPhotos);
|
|
|
+ break;
|
|
|
+ case PhotosType.blurryPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(PhotosType.blurryPhotos);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ _initData();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|