|
|
@@ -1,6 +1,7 @@
|
|
|
import 'dart:async';
|
|
|
|
|
|
import 'package:clean/base/base_controller.dart';
|
|
|
+import 'package:clean/base/base_photo_controller.dart';
|
|
|
import 'package:clean/data/bean/photos_type.dart';
|
|
|
import 'package:clean/data/consts/constants.dart';
|
|
|
import 'package:clean/dialog/photo_delete_finish_dialog.dart';
|
|
|
@@ -22,8 +23,9 @@ 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 RxList<AssetEntity> listAssetEntity = <AssetEntity>[].obs;
|
|
|
final RxSet<String> selectedPhotosIds = <String>{}.obs;
|
|
|
+
|
|
|
final RxBool isSwiperEnd = false.obs;
|
|
|
RxInt groupIndex = 0.obs;
|
|
|
|
|
|
@@ -35,16 +37,16 @@ class PhotoPreviewController extends BaseController {
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
- isSwiperEnd.value = false;
|
|
|
+
|
|
|
print('PhotoPreviewController onInit');
|
|
|
_getArgs(); // 获取传递的参数
|
|
|
_initData(); // 初始化数据
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
if (currentImageId != null) {
|
|
|
- for (int i = 0; i < photoGroups.length; i++) {
|
|
|
- if (photoGroups[i].id == currentImageId) {
|
|
|
- print('photoGroups[i].id ${photoGroups[i].id},i $i');
|
|
|
+ for (int i = 0; i < listAssetEntity.length; i++) {
|
|
|
+ if (listAssetEntity[i].id == currentImageId) {
|
|
|
+ print('photoGroups[i].id ${listAssetEntity[i].id},i $i');
|
|
|
groupIndex.value = i;
|
|
|
cardSwiperController.value.moveTo(i);
|
|
|
break;
|
|
|
@@ -58,12 +60,13 @@ class PhotoPreviewController extends BaseController {
|
|
|
void onReady() {
|
|
|
// TODO: implement onReady
|
|
|
super.onReady();
|
|
|
-
|
|
|
+ print('PhotoPreviewController onReady');
|
|
|
if (isFirstOpenPhotoPreview()) {
|
|
|
photoPreviewTipDialog(clickCallback: () {
|
|
|
setFirstOpenPhotoPreview(false);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 获取参数
|
|
|
@@ -73,54 +76,81 @@ class PhotoPreviewController extends BaseController {
|
|
|
}
|
|
|
|
|
|
void _initData() {
|
|
|
- photoGroups.clear();
|
|
|
+ listAssetEntity.clear();
|
|
|
selectedPhotosIds.clear();
|
|
|
|
|
|
switch (photosType) {
|
|
|
case PhotosType.peoplePhotos:
|
|
|
- photoGroups.assignAll(ImagePickerUtil.peoplePhotos);
|
|
|
- selectedPhotosIds.assignAll(ImagePickerUtil.selectedPeoplePhotosIds);
|
|
|
- selectedFileCount.value =
|
|
|
- ImagePickerUtil.selectedPeoplePhotosIds.length;
|
|
|
+ final PeoplePhotoController controller =
|
|
|
+ Get.find<PeoplePhotoController>();
|
|
|
+ listAssetEntity.assignAll(controller.getAllPhotos());
|
|
|
+ selectedPhotosIds.assignAll(controller.selectedPhotosIds);
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.screenshots:
|
|
|
- photoGroups.assignAll(ImagePickerUtil.screenshotPhotos);
|
|
|
- selectedPhotosIds
|
|
|
- .assignAll(ImagePickerUtil.selectedScreenshotPhotosIds);
|
|
|
- selectedFileCount.value =
|
|
|
- ImagePickerUtil.selectedScreenshotPhotosIds.length;
|
|
|
+ final ScreenShotsController controller =
|
|
|
+ Get.find<ScreenShotsController>();
|
|
|
+ listAssetEntity.assignAll(controller.getAllPhotos());
|
|
|
+ selectedPhotosIds.assignAll(controller.selectedPhotosIds);
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.similarPhotos:
|
|
|
- for (var group in ImagePickerUtil.similarPhotos) {
|
|
|
- photoGroups.addAll(group);
|
|
|
- }
|
|
|
- selectedPhotosIds.assignAll(ImagePickerUtil.selectedSimilarPhotosIds);
|
|
|
- selectedFileCount.value =
|
|
|
- ImagePickerUtil.selectedSimilarPhotosIds.length;
|
|
|
+ final SimilarPhotoController controller =
|
|
|
+ Get.find<SimilarPhotoController>();
|
|
|
+ listAssetEntity.assignAll(controller.getAllPhotos());
|
|
|
+ selectedPhotosIds.assignAll(controller.selectedPhotosIds);
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.locationPhotos:
|
|
|
- for (var group in ImagePickerUtil.locationPhotos.values) {
|
|
|
- photoGroups.addAll(group);
|
|
|
- }
|
|
|
- selectedPhotosIds.assignAll(ImagePickerUtil.selectedLocationPhotosIds);
|
|
|
- selectedFileCount.value =
|
|
|
- ImagePickerUtil.selectedLocationPhotosIds.length;
|
|
|
+ final LocationsSinglePhotoController controller =
|
|
|
+ Get.find<LocationsSinglePhotoController>();
|
|
|
+ listAssetEntity.assignAll(controller.getAllPhotos());
|
|
|
+ selectedPhotosIds.assignAll(controller.selectedPhotosIds);
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
break;
|
|
|
case PhotosType.blurryPhotos:
|
|
|
- photoGroups.assignAll(ImagePickerUtil.blurryPhotos);
|
|
|
- selectedPhotosIds.assignAll(ImagePickerUtil.selectedBlurryPhotosIds);
|
|
|
- selectedFileCount.value =
|
|
|
- ImagePickerUtil.selectedBlurryPhotosIds.length;
|
|
|
+ final ScreenShotsController controller =
|
|
|
+ Get.find<ScreenShotsController>();
|
|
|
+ listAssetEntity.assignAll(controller.getAllPhotos());
|
|
|
+ selectedPhotosIds.assignAll(controller.selectedPhotosIds);
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
updateSelectedFilesSize();
|
|
|
}
|
|
|
|
|
|
- void restoreSelections() async {
|
|
|
- photoGroups
|
|
|
+ //删除成功清除选中的图片
|
|
|
+ void cleanSelections() async {
|
|
|
+ listAssetEntity
|
|
|
.removeWhere((element) => selectedPhotosIds.contains(element.id));
|
|
|
selectedPhotosIds.clear();
|
|
|
- if (photoGroups.isNotEmpty) {
|
|
|
+ if (listAssetEntity.isEmpty) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ isSwiperEnd.value = false;
|
|
|
+
|
|
|
+ if (listAssetEntity.isNotEmpty) {
|
|
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
+ groupIndex.value = 0;
|
|
|
+ cardSwiperController.value.moveTo(0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ updateSelectedFilesSize();
|
|
|
+ selectedFileCount.value = selectedPhotosIds.length;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 恢复状态
|
|
|
+ void restoreSelections() {
|
|
|
+ if (listAssetEntity.isEmpty) {
|
|
|
+ clickBack();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ isSwiperEnd.value = false;
|
|
|
+
|
|
|
+ if (listAssetEntity.isNotEmpty) {
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
groupIndex.value = 0;
|
|
|
cardSwiperController.value.moveTo(0);
|
|
|
@@ -146,6 +176,13 @@ class PhotoPreviewController extends BaseController {
|
|
|
selectedFilesSize.value = totalSize / 1024; // Convert to KB
|
|
|
}
|
|
|
|
|
|
+ void updateSelections(Set<String> selectedIds) {
|
|
|
+ print('PhotoPreviewController updateSelections photosType $photosType selectedIds $selectedIds');
|
|
|
+ selectedPhotosIds.assignAll(selectedIds);
|
|
|
+
|
|
|
+ restoreSelections();
|
|
|
+ }
|
|
|
+
|
|
|
void recoverSelectPhoto() {
|
|
|
cardSwiperController.value.undo();
|
|
|
}
|
|
|
@@ -156,7 +193,9 @@ class PhotoPreviewController extends BaseController {
|
|
|
|
|
|
@override
|
|
|
void onClose() {
|
|
|
+ print('PhotoPreviewController onClose');
|
|
|
super.onClose();
|
|
|
+ isSwiperEnd.value = false;
|
|
|
|
|
|
// 清理操作,释放资源
|
|
|
cardSwiperController.value.dispose();
|
|
|
@@ -167,37 +206,34 @@ class PhotoPreviewController extends BaseController {
|
|
|
Get.back();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// // 保存选择的图片ID列表
|
|
|
void _saveSelectedPhotos(PhotosType type) {
|
|
|
switch (type) {
|
|
|
case PhotosType.peoplePhotos:
|
|
|
- ImagePickerUtil.selectedPeoplePhotosIds.assignAll(selectedPhotosIds);
|
|
|
PeoplePhotoController controller = Get.find<PeoplePhotoController>();
|
|
|
+ controller.updateSelections(selectedPhotosIds);
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.screenshots:
|
|
|
- ImagePickerUtil.selectedScreenshotPhotosIds
|
|
|
- .assignAll(selectedPhotosIds);
|
|
|
ScreenShotsController controller = Get.find<ScreenShotsController>();
|
|
|
+ controller.updateSelections(selectedPhotosIds);
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.similarPhotos:
|
|
|
- ImagePickerUtil.selectedSimilarPhotosIds.assignAll(selectedPhotosIds);
|
|
|
SimilarPhotoController controller = Get.find<SimilarPhotoController>();
|
|
|
-
|
|
|
+ controller.updateSelections(selectedPhotosIds);
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.locationPhotos:
|
|
|
- ImagePickerUtil.selectedLocationPhotosIds.assignAll(selectedPhotosIds);
|
|
|
LocationsSinglePhotoController controller =
|
|
|
Get.find<LocationsSinglePhotoController>();
|
|
|
-
|
|
|
+ controller.updateSelections(selectedPhotosIds);
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
case PhotosType.blurryPhotos:
|
|
|
- ImagePickerUtil.selectedBlurryPhotosIds.assignAll(selectedPhotosIds);
|
|
|
ScreenShotsController controller = Get.find<ScreenShotsController>();
|
|
|
-
|
|
|
+ controller.updateSelections(selectedPhotosIds);
|
|
|
controller.restoreSelections();
|
|
|
break;
|
|
|
}
|
|
|
@@ -222,17 +258,17 @@ class PhotoPreviewController extends BaseController {
|
|
|
// 如果direction是left,
|
|
|
if (direction == CardSwiperDirection.left) {
|
|
|
// 先看看图片id是不是在selectedPhotosIds里面,如果在,不处理,如果不在,添加到selectedPhotosIds里面
|
|
|
- if (!selectedPhotosIds.contains(photoGroups[previousIndex].id)) {
|
|
|
+ if (!selectedPhotosIds.contains(listAssetEntity[previousIndex].id)) {
|
|
|
print(
|
|
|
- 'add photoGroups[groupIndex.value].id ${photoGroups[previousIndex].id}');
|
|
|
- selectedPhotosIds.add(photoGroups[previousIndex].id);
|
|
|
+ 'add photoGroups[groupIndex.value].id ${listAssetEntity[previousIndex].id}');
|
|
|
+ selectedPhotosIds.add(listAssetEntity[previousIndex].id);
|
|
|
}
|
|
|
} else if (direction == CardSwiperDirection.right) {
|
|
|
// 先看看图片id是不是在selectedPhotosIds里面,如果在,在selectedPhotosIds移除,不处理,如果不在,不处理
|
|
|
- if (selectedPhotosIds.contains(photoGroups[previousIndex].id)) {
|
|
|
+ if (selectedPhotosIds.contains(listAssetEntity[previousIndex].id)) {
|
|
|
print(
|
|
|
- 'remove photoGroups[groupIndex.value].id ${photoGroups[previousIndex].id}');
|
|
|
- selectedPhotosIds.remove(photoGroups[previousIndex].id);
|
|
|
+ 'remove photoGroups[groupIndex.value].id ${listAssetEntity[previousIndex].id}');
|
|
|
+ selectedPhotosIds.remove(listAssetEntity[previousIndex].id);
|
|
|
}
|
|
|
}
|
|
|
selectedFileCount.value = selectedPhotosIds.length;
|
|
|
@@ -252,9 +288,9 @@ class PhotoPreviewController extends BaseController {
|
|
|
// 撤销之前左滑的操作
|
|
|
if (direction == CardSwiperDirection.left) {
|
|
|
print(
|
|
|
- 'photoGroups[groupIndex.value].id ${photoGroups[groupIndex.value].id}');
|
|
|
- if (selectedPhotosIds.contains(photoGroups[groupIndex.value].id)) {
|
|
|
- selectedPhotosIds.remove(photoGroups[groupIndex.value].id);
|
|
|
+ 'photoGroups[groupIndex.value].id ${listAssetEntity[groupIndex.value].id}');
|
|
|
+ if (selectedPhotosIds.contains(listAssetEntity[groupIndex.value].id)) {
|
|
|
+ selectedPhotosIds.remove(listAssetEntity[groupIndex.value].id);
|
|
|
}
|
|
|
}
|
|
|
selectedFileCount.value = selectedPhotosIds.length;
|
|
|
@@ -292,7 +328,7 @@ class PhotoPreviewController extends BaseController {
|
|
|
}
|
|
|
if (selectedPhotosIds.isNotEmpty) {
|
|
|
// 获取要删除的资产
|
|
|
- final assetsToDelete = photoGroups
|
|
|
+ final assetsToDelete = listAssetEntity
|
|
|
.where(
|
|
|
(asset) => selectedPhotosIds.contains(asset.id),
|
|
|
)
|
|
|
@@ -335,12 +371,22 @@ class PhotoPreviewController extends BaseController {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- restoreSelections();
|
|
|
-
|
|
|
+ cleanSelections();
|
|
|
} else {
|
|
|
// 删除失败
|
|
|
ToastUtil.show("Delete failed");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 将selectedFilesSize转成String类型,然后单位转换,如果超过1MB,则转成MB,超过1GB,则转成GB,否则KB
|
|
|
+ String get selectedFilesSizeString {
|
|
|
+ if (selectedFilesSize.value > 1024) {
|
|
|
+ return "${(selectedFilesSize.value / 1024).toStringAsFixed(2)}MB";
|
|
|
+ } else if (selectedFilesSize.value > 1024 * 1024) {
|
|
|
+ return "${(selectedFilesSize.value / 1024 / 1024).toStringAsFixed(2)}GB";
|
|
|
+ } else {
|
|
|
+ return "${(selectedFilesSize.value).toStringAsFixed(2)}KB";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|