|
|
@@ -4,6 +4,7 @@ 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/data/repositories/user_repository.dart';
|
|
|
import 'package:clean/dialog/photo_delete_finish_dialog.dart';
|
|
|
import 'package:clean/dialog/photo_deleting_dialog.dart';
|
|
|
import 'package:clean/dialog/photo_preview_tip_dialog.dart';
|
|
|
@@ -14,14 +15,18 @@ import 'package:clean/module/people_photo/photo_group.dart';
|
|
|
import 'package:clean/module/photo_preview/phtoto_selected_preview_view.dart';
|
|
|
import 'package:clean/module/screenshots_blurry/screenshots_controller.dart';
|
|
|
import 'package:clean/module/similar_photo/similar_photo_controller.dart';
|
|
|
+import 'package:clean/module/store/store_view.dart';
|
|
|
import 'package:clean/utils/file_utils.dart';
|
|
|
import 'package:clean/utils/toast_util.dart';
|
|
|
import 'package:flutter/Material.dart';
|
|
|
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
|
|
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:lottie/lottie.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
-class PhotoPreviewController extends BaseController {
|
|
|
+class PhotoPreviewController extends BaseController
|
|
|
+ with GetSingleTickerProviderStateMixin {
|
|
|
Rx<CardSwiperController> cardSwiperController = CardSwiperController().obs;
|
|
|
final RxList<AssetEntity> listAssetEntity = <AssetEntity>[].obs;
|
|
|
final RxSet<String> selectedPhotosIds = <String>{}.obs;
|
|
|
@@ -34,10 +39,16 @@ class PhotoPreviewController extends BaseController {
|
|
|
RxDouble selectedFilesSize = 0.0.obs;
|
|
|
RxInt selectedFileCount = 0.obs;
|
|
|
|
|
|
+ late AnimationController animationController;
|
|
|
+ RxBool animationIsComplete = false.obs;
|
|
|
+
|
|
|
@override
|
|
|
void onInit() {
|
|
|
super.onInit();
|
|
|
-
|
|
|
+ animationController = AnimationController(
|
|
|
+ vsync: this,
|
|
|
+ duration: const Duration(seconds: 3),
|
|
|
+ );
|
|
|
print('PhotoPreviewController onInit');
|
|
|
_getArgs(); // 获取传递的参数
|
|
|
_initData(); // 初始化数据
|
|
|
@@ -54,19 +65,33 @@ class PhotoPreviewController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ animationController.addStatusListener((status) {
|
|
|
+ if (status == AnimationStatus.forward) {
|
|
|
+ // 延迟一秒
|
|
|
+ Future.delayed(Duration(seconds: 1), () {
|
|
|
+ animationIsComplete.value = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (status == AnimationStatus.completed) {
|
|
|
+ Future.delayed(Duration(seconds: 1), () {
|
|
|
+ PhotoSelectedPreviewPage.start(photosType, selectedPhotosIds);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void onReady() {
|
|
|
// TODO: implement onReady
|
|
|
super.onReady();
|
|
|
+
|
|
|
print('PhotoPreviewController onReady');
|
|
|
if (isFirstOpenPhotoPreview()) {
|
|
|
photoPreviewTipDialog(clickCallback: () {
|
|
|
setFirstOpenPhotoPreview(false);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 获取参数
|
|
|
@@ -177,13 +202,15 @@ class PhotoPreviewController extends BaseController {
|
|
|
}
|
|
|
|
|
|
void updateSelections(Set<String> selectedIds) {
|
|
|
- print('PhotoPreviewController updateSelections photosType $photosType selectedIds $selectedIds');
|
|
|
+ print(
|
|
|
+ 'PhotoPreviewController updateSelections photosType $photosType selectedIds $selectedIds');
|
|
|
selectedPhotosIds.assignAll(selectedIds);
|
|
|
|
|
|
restoreSelections();
|
|
|
}
|
|
|
|
|
|
void recoverSelectPhoto() {
|
|
|
+ print('PhotoPreviewController recoverSelectPhoto');
|
|
|
cardSwiperController.value.undo();
|
|
|
}
|
|
|
|
|
|
@@ -194,6 +221,7 @@ class PhotoPreviewController extends BaseController {
|
|
|
@override
|
|
|
void onClose() {
|
|
|
print('PhotoPreviewController onClose');
|
|
|
+ animationController.dispose();
|
|
|
super.onClose();
|
|
|
isSwiperEnd.value = false;
|
|
|
|
|
|
@@ -206,7 +234,6 @@ class PhotoPreviewController extends BaseController {
|
|
|
Get.back();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// // 保存选择的图片ID列表
|
|
|
void _saveSelectedPhotos(PhotosType type) {
|
|
|
switch (type) {
|
|
|
@@ -302,89 +329,106 @@ class PhotoPreviewController extends BaseController {
|
|
|
isSwiperEnd.value = true;
|
|
|
print('onSwiperEnd');
|
|
|
|
|
|
- PhotoSelectedPreviewPage.start(photosType, selectedPhotosIds);
|
|
|
+ // 延迟500ms
|
|
|
+ Future.delayed(Duration(milliseconds: 200), () {
|
|
|
+ animationController.forward(from: 0);
|
|
|
+ });
|
|
|
+
|
|
|
+ // PhotoSelectedPreviewPage.start(photosType, selectedPhotosIds);
|
|
|
}
|
|
|
|
|
|
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 = listAssetEntity
|
|
|
- .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');
|
|
|
-
|
|
|
- // 比较result和selectedPhotosIds,如果result和selectedPhotosIds相等,说明删除成功,走下面的逻辑
|
|
|
- // 如果不相等,说明有删除失败的,走else逻辑
|
|
|
- if (result.length == selectedPhotosIds.length) {
|
|
|
- switch (photosType) {
|
|
|
- case PhotosType.peoplePhotos:
|
|
|
- ImagePickerUtil.updatePhotoGroupDate(
|
|
|
- photosType, ImagePickerUtil.selectedPeoplePhotosIds);
|
|
|
-
|
|
|
- break;
|
|
|
- case PhotosType.screenshots:
|
|
|
- ImagePickerUtil.updatePhotoGroupDate(
|
|
|
- photosType, ImagePickerUtil.selectedScreenshotPhotosIds);
|
|
|
-
|
|
|
- break;
|
|
|
- case PhotosType.similarPhotos:
|
|
|
- ImagePickerUtil.updatePhotoGroupDate(
|
|
|
- photosType, ImagePickerUtil.selectedSimilarPhotosIds);
|
|
|
-
|
|
|
- break;
|
|
|
- case PhotosType.locationPhotos:
|
|
|
- ImagePickerUtil.updatePhotoGroupDate(
|
|
|
- photosType, ImagePickerUtil.selectedLocationPhotosIds);
|
|
|
-
|
|
|
- break;
|
|
|
- case PhotosType.blurryPhotos:
|
|
|
- ImagePickerUtil.updatePhotoGroupDate(
|
|
|
- photosType, ImagePickerUtil.selectedBlurryPhotosIds);
|
|
|
+ if (userRepository.isVip()) {
|
|
|
+ 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) {
|
|
|
+ photoDeletingDialog();
|
|
|
+ // 获取要删除的资产
|
|
|
+ final assetsToDelete = listAssetEntity
|
|
|
+ .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');
|
|
|
+
|
|
|
+ // 比较result和selectedPhotosIds,如果result和selectedPhotosIds相等,说明删除成功,走下面的逻辑
|
|
|
+ // 如果不相等,说明有删除失败的,走else逻辑
|
|
|
+ if (result.length == selectedPhotosIds.length) {
|
|
|
+ switch (photosType) {
|
|
|
+ case PhotosType.peoplePhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(
|
|
|
+ photosType, ImagePickerUtil.selectedPeoplePhotosIds);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case PhotosType.screenshots:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(
|
|
|
+ photosType, ImagePickerUtil.selectedScreenshotPhotosIds);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case PhotosType.similarPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(
|
|
|
+ photosType, ImagePickerUtil.selectedSimilarPhotosIds);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case PhotosType.locationPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(
|
|
|
+ photosType, ImagePickerUtil.selectedLocationPhotosIds);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case PhotosType.blurryPhotos:
|
|
|
+ ImagePickerUtil.updatePhotoGroupDate(
|
|
|
+ photosType, ImagePickerUtil.selectedBlurryPhotosIds);
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- break;
|
|
|
+ cleanSelections();
|
|
|
+ ToastUtil.show('Delete success');
|
|
|
+ Future.delayed(Duration(seconds: 2), () {
|
|
|
+ SmartDialog.dismiss(tag: 'photoDeletingDialog');
|
|
|
+ photoDeleteFinishDialog();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ SmartDialog.dismiss(tag: 'photoDeletingDialog');
|
|
|
+ // 删除失败
|
|
|
+ ToastUtil.show("Delete failed");
|
|
|
}
|
|
|
-
|
|
|
- cleanSelections();
|
|
|
- } else {
|
|
|
- // 删除失败
|
|
|
- ToastUtil.show("Delete failed");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ StorePage.start();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 将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";
|
|
|
+ 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";
|
|
|
}
|