Преглед на файлове

更新预览页删除功能

云天逵 преди 1 година
родител
ревизия
057145281d

+ 1 - 1
lib/module/home/home_controller.dart

@@ -52,7 +52,7 @@ class HomeController extends BaseController {
   Future<void> onInit() async {
     // TODO: implement onInit
     super.onInit();
-    // loadPhotosFromDirectory();
+    loadPhotosFromDirectory();
     if (await Permission.photos.request().isGranted) {
       PhotoManager.clearFileCache();
       getStorageInfo();

+ 27 - 1
lib/module/image_picker/image_picker_util.dart

@@ -3,7 +3,11 @@ import 'dart:math';
 
 import 'package:clean/data/bean/photos_type.dart';
 import 'package:clean/model/asset_group.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:get/get.dart';
 import 'package:photo_manager/photo_manager.dart';
 
@@ -60,8 +64,14 @@ class ImagePickerUtil {
     switch (photosType) {
       case PhotosType.screenshots:
         // 去除包含在selectedScreenshotPhotosIds中的screenshotPhotos
-        screenshotPhotos.removeWhere((element) => selectedScreenshotPhotosIds.contains(element.id));
+        screenshotPhotos.removeWhere(
+            (element) => selectedScreenshotPhotosIds.contains(element.id));
+
+        ScreenShotsController controller = Get.find<ScreenShotsController>();
+        // 同时移除控制器photoGroups中images对应的数据
+        controller.photoGroups.removeWhere((element) => element.images.any((element) => selectedScreenshotPhotosIds.contains(element.id)));
         selectedScreenshotPhotosIds.clear();
+        controller.restoreSelections();
         print(screenshotPhotos);
 
         break;
@@ -71,7 +81,11 @@ class ImagePickerUtil {
           group.removeWhere(
               (element) => selectedSimilarPhotosIds.contains(element.id));
         }
+        SimilarPhotoController controller = Get.find<SimilarPhotoController>();
+        // 同时移除控制器photoGroups中images对应的数据
+        controller.photoGroups.removeWhere((element) => element.images.any((element) => selectedSimilarPhotosIds.contains(element.id)));
         selectedSimilarPhotosIds.clear();
+        controller.restoreSelections();
         break;
       case PhotosType.locationPhotos:
         // 去除包含在selectedLocationPhotosIds中的locationPhotos
@@ -79,20 +93,32 @@ class ImagePickerUtil {
           group.removeWhere(
               (element) => selectedLocationPhotosIds.contains(element.id));
         }
+        LocationsSinglePhotoController controller = Get.find<LocationsSinglePhotoController>();
+        // 同时移除控制器photoGroups中images对应的数据
+        controller.photoGroups.removeWhere((element) => element.images.any((element) => selectedLocationPhotosIds.contains(element.id)));
         selectedLocationPhotosIds.clear();
+        controller.restoreSelections();
 
         break;
       case PhotosType.peoplePhotos:
         // 去除包含在selectedPeoplePhotosIds中的peoplePhotos
         peoplePhotos.removeWhere(
             (element) => selectedPeoplePhotosIds.contains(element.id));
+        PeoplePhotoController controller = Get.find<PeoplePhotoController>();
+        // 同时移除控制器photoGroups中images对应的数据
+        controller.photoGroups.removeWhere((element) => element.images.any((element) => selectedPeoplePhotosIds.contains(element.id)));
         selectedPeoplePhotosIds.clear();
+        controller.restoreSelections();
         break;
       case PhotosType.blurryPhotos:
         // 去除包含在selectedBlurryPhotosIds中的blurryPhotos
         blurryPhotos.removeWhere(
             (element) => selectedBlurryPhotosIds.contains(element.id));
+        ScreenShotsController controller = Get.find<ScreenShotsController>();
+        // 同时移除控制器photoGroups中images对应的数据
+        controller.photoGroups.removeWhere((element) => element.images.any((element) => selectedBlurryPhotosIds.contains(element.id)));
         selectedBlurryPhotosIds.clear();
+        controller.restoreSelections();
         break;
     }
   }

+ 2 - 1
lib/module/locations_photo/locations_photo_view.dart

@@ -140,7 +140,8 @@ class LocationsPhotoPage extends BasePage<LocationsPhotoController> {
                           borderRadius: BorderRadius.circular(8.r),
                         ),
                         image: DecorationImage(
-                          image: AssetEntityImageProvider(imagePath),
+                          image: AssetEntityImageProvider(imagePath,thumbnailSize: const ThumbnailSize.square(300),
+                            isOriginal: false,),
                           fit: BoxFit.cover,
                         ),
                       ),

+ 2 - 1
lib/module/locations_photo/locations_single_photo_view.dart

@@ -176,7 +176,8 @@ class LocationsSinglePhotoPage
                       borderRadius: BorderRadius.circular(9.27.sp),
                     ),
                     image: DecorationImage(
-                      image: AssetEntityImageProvider(assetEntity),
+                      image: AssetEntityImageProvider(assetEntity,thumbnailSize: const ThumbnailSize.square(300),
+                        isOriginal: false,),
                       fit: BoxFit.cover,
                     ),
                   ),

+ 2 - 1
lib/module/people_photo/people_photo_view.dart

@@ -49,7 +49,7 @@ class PeoplePhotoPage extends BasePage<PeoplePhotoController> {
                               _buildPhotoGroup(
                                 images: group.images,
                                 title: group.title,
-                                imageCount: group.imageCount,
+                                imageCount: group.images.length,
                               ),
                               SizedBox(height: 15.h),
                             ],
@@ -273,6 +273,7 @@ class PeoplePhotoPage extends BasePage<PeoplePhotoController> {
                     image: DecorationImage(
                       image: AssetEntityImageProvider(
                         assetEntity,
+                        thumbnailSize: const ThumbnailSize.square(300),
                         isOriginal: false,
                       ),
                       fit: BoxFit.cover,

+ 9 - 17
lib/module/photo_preview/photo_preview_controller.dart

@@ -142,33 +142,32 @@ 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);
         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;
     }
@@ -273,30 +272,23 @@ class PhotoPreviewController extends BaseController {
     switch(photosType){
       case PhotosType.peoplePhotos:
         ImagePickerUtil.updatePhotoGroupDate(PhotosType.peoplePhotos);
-        PeoplePhotoController controller = Get.find<PeoplePhotoController>();
-        controller.loadPeoplePhoto();
-        controller.restoreSelections();
+
         break;
       case PhotosType.screenshots:
         ImagePickerUtil.updatePhotoGroupDate(PhotosType.screenshots);
-        ScreenShotsController controller = Get.find<ScreenShotsController>();
-        controller.loadScreenshots();
-        controller.restoreSelections();
+
         break;
       case PhotosType.similarPhotos:
         ImagePickerUtil.updatePhotoGroupDate(PhotosType.similarPhotos);
-        SimilarPhotoController controller = Get.find<SimilarPhotoController>();
-        controller.loadSimilarPhotos();
+
         break;
       case PhotosType.locationPhotos:
         ImagePickerUtil.updatePhotoGroupDate(PhotosType.locationPhotos);
-        LocationsSinglePhotoController controller = Get.find<LocationsSinglePhotoController>();
-        controller.loadLocationsSinglePhoto();
+
         break;
       case PhotosType.blurryPhotos:
         ImagePickerUtil.updatePhotoGroupDate(PhotosType.blurryPhotos);
-        ScreenShotsController controller = Get.find<ScreenShotsController>();
-        controller.loadScreenshots();
+
         break;
     }
     _initData();

+ 11 - 2
lib/module/photo_preview/photo_preview_view.dart

@@ -37,6 +37,14 @@ class PhotoPreviewPage extends BasePage<PhotoPreviewController> {
   Widget buildBody(BuildContext context) {
     return Stack(children: [
       Container(
+          child: PopScope(
+        canPop: false,
+        onPopInvokedWithResult: (didPop, result) {
+          if (didPop) {
+            return;
+          }
+          controller.clickBack();
+        },
         child: SafeArea(
           child: Container(
             child: Obx(() {
@@ -48,7 +56,7 @@ class PhotoPreviewPage extends BasePage<PhotoPreviewController> {
             }),
           ),
         ),
-      ),
+      )),
       IgnorePointer(
         child: Assets.images.bgHome.image(
           width: 360.w,
@@ -63,7 +71,7 @@ class PhotoPreviewPage extends BasePage<PhotoPreviewController> {
       children: [
         _titleCard(),
         Spacer(),
-        (controller.photoGroups.length == 1)
+        (controller.photoGroups.length == 0)
             ? Container(
                 width: 314.w,
                 height: 392.h,
@@ -88,6 +96,7 @@ class PhotoPreviewPage extends BasePage<PhotoPreviewController> {
                   cardsCount: controller.photoGroups.length,
                   onSwipe: controller.onSwipe,
                   onUndo: controller.onSwiperUndo,
+                  numberOfCardsDisplayed: 1,
                   onEnd: controller.onSwiperEnd,
                   cardBuilder: (context, index, horizontalOffsetPercentage,
                       verticalOffsetPercentage) {

+ 3 - 0
lib/module/screenshots_blurry/screenshots_controller.dart

@@ -98,6 +98,9 @@ class ScreenShotsController extends BaseController {
     }
 
     // print('screenshots restoreSelections ${selectedPhotosIds.length}');
+    if (selectedPhotosIds.isEmpty) {
+      return;
+    }
     for (var group in photoGroups) {
       for (int i = 0; i < group.images.length; i++) {
         if (selectedPhotosIds.contains(group.images[i].id)) {

+ 130 - 115
lib/module/screenshots_blurry/screenshots_view.dart

@@ -31,34 +31,37 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
     return Stack(children: [
       Container(
         child: SafeArea(
-          child: Column(
-            children: [
-              _titleCard(),
-              // Photo groups
-              Expanded(
-                child: Obx(() {
-                  return SizedBox(
-                    child: GridView.builder(
-                        padding: EdgeInsets.symmetric(horizontal: 16.w),
-                        scrollDirection: Axis.vertical,
-                        // 设置为垂直方向滚动
-                        physics: BouncingScrollPhysics(),
-                        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
-                          crossAxisCount: 3, // 每行显示 2 个元素
-                          mainAxisSpacing: 8.w, // 垂直间距
-                          crossAxisSpacing: 8.h, // 水平间距
-                        ),
-                        itemCount: controller.photoGroups[0].imageCount,
-                        itemBuilder:
-                            _buildPhotoItem(controller.photoGroups[0].title)),
-                  );
-                }),
-              ),
-
-              _bottomBarCard(),
-              SizedBox(height: 8.h),
-            ],
-          ),
+          child: (controller.photoGroups.isEmpty ||
+                  controller.photoGroups[0].images.isEmpty)
+              ? _noNoPicturesCard()
+              : Column(
+                  children: [
+                    _titleCard(),
+                    Flexible(
+                      child: Obx(() {
+                        return SizedBox(
+                          child: GridView.builder(
+                              padding: EdgeInsets.symmetric(horizontal: 16.w),
+                              scrollDirection: Axis.vertical,
+                              // 设置为垂直方向滚动
+                              physics: BouncingScrollPhysics(),
+                              gridDelegate:
+                                  SliverGridDelegateWithFixedCrossAxisCount(
+                                crossAxisCount: 3, // 每行显示 2 个元素
+                                mainAxisSpacing: 8.w, // 垂直间距
+                                crossAxisSpacing: 8.h, // 水平间距
+                              ),
+                              itemCount:
+                                  controller.photoGroups[0].images.length,
+                              itemBuilder: _buildPhotoItem(
+                                  controller.photoGroups[0].title)),
+                        );
+                      }),
+                    ),
+                    _bottomBarCard(),
+                    SizedBox(height: 8.h),
+                  ],
+                ),
         ),
       ),
       IgnorePointer(
@@ -77,46 +80,59 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
       child: Column(
         crossAxisAlignment: CrossAxisAlignment.start,
         children: [
-          Row(
-            mainAxisAlignment: MainAxisAlignment.spaceBetween,
-            children: [
-              GestureDetector(
-                onTap: () => Get.back(),
-                child: Assets.images.iconBackArrow.image(
-                  width: 28.w,
-                  height: 28.h,
+          Obx(() {
+            return Row(
+              mainAxisAlignment: MainAxisAlignment.spaceBetween,
+              children: [
+                GestureDetector(
+                  onTap: () => Get.back(),
+                  child: Assets.images.iconBackArrow.image(
+                    width: 28.w,
+                    height: 28.h,
+                  ),
                 ),
-              ),
-              GestureDetector(
-                onTap: () => controller
-                    .toggleGroupSelection(controller.photoGroups[0].title),
-                child: Obx(() => Text(
-                      controller.photoGroups
-                              .firstWhere((g) =>
-                                  g.title == controller.photoGroups[0].title)
-                              .isSelected
-                              .value
-                          ? 'Deselect All'
-                          : 'Select All',
+                // 如果photoGroup数据为空,不显示全选按钮
+                controller.photoGroups.isEmpty ||
+                        controller.photoGroups[0].images.isEmpty
+                    ? Container()
+                    : GestureDetector(
+                        onTap: () => controller.toggleGroupSelection(
+                            controller.photoGroups[0].title),
+                        child: Obx(() => Text(
+                              controller.photoGroups
+                                      .firstWhere((g) =>
+                                          g.title ==
+                                          controller.photoGroups[0].title)
+                                      .isSelected
+                                      .value
+                                  ? 'Deselect All'
+                                  : 'Select All',
+                              style: TextStyle(
+                                color: Colors.white.withValues(alpha: 0.7),
+                                fontSize: 14.sp,
+                                fontWeight: FontWeight.w400,
+                              ),
+                            )),
+                      ),
+              ],
+            );
+          }),
+          controller.photoGroups.isEmpty
+              ? Container()
+              : Column(
+                  children: [
+                    SizedBox(height: 12.h),
+                    Text(
+                      controller.titleName,
                       style: TextStyle(
-                        color: Colors.white.withValues(alpha: 0.7),
-                        fontSize: 14.sp,
-                        fontWeight: FontWeight.w400,
+                        color: Colors.white,
+                        fontSize: 24.sp,
+                        fontWeight: FontWeight.w700,
                       ),
-                    )),
-              ),
-            ],
-          ),
-          SizedBox(height: 12.h),
-          Text(
-            controller.titleName,
-            style: TextStyle(
-              color: Colors.white,
-              fontSize: 24.sp,
-              fontWeight: FontWeight.w700,
-            ),
-          ),
-          SizedBox(height: 20.h),
+                    ),
+                    SizedBox(height: 20.h),
+                  ],
+                ),
         ],
       ),
     );
@@ -161,12 +177,11 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
       (context, index) {
         final group =
             controller.photoGroups.firstWhere((group) => group.title == title);
-        final assetEntity = group.images[index];
 
         return GestureDetector(
           onTap: () => controller.clickImage(title, index),
           child: Obx(() {
-            final isSelected = group.selectedImages[index];
+            var isSelected = group.selectedImages[index];
             return Stack(
               children: [
                 Container(
@@ -178,7 +193,8 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
                       borderRadius: BorderRadius.circular(9.27.sp),
                     ),
                     image: DecorationImage(
-                      image: AssetEntityImageProvider(assetEntity),
+                      image: AssetEntityImageProvider(group.images[index],thumbnailSize: const ThumbnailSize.square(300),
+                        isOriginal: false,),
                       fit: BoxFit.cover,
                     ),
                   ),
@@ -190,19 +206,19 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
                       onTap: () =>
                           controller.toggleImageSelection(title, index),
                       child: Container(
-                    child: isSelected
-                        ? Center(
-                            child: Assets.images.iconSelected.image(
-                              width: 20.w,
-                              height: 20.h,
-                            ),
-                          )
-                        : Center(
-                            child: Assets.images.iconUnselected.image(
-                            width: 20.w,
-                            height: 20.h,
-                          )),
-                  )),
+                        child: isSelected
+                            ? Center(
+                                child: Assets.images.iconSelected.image(
+                                  width: 20.w,
+                                  height: 20.h,
+                                ),
+                              )
+                            : Center(
+                                child: Assets.images.iconUnselected.image(
+                                width: 20.w,
+                                height: 20.h,
+                              )),
+                      )),
                 ),
               ],
             );
@@ -212,45 +228,44 @@ class ScreenshotsPage extends BasePage<ScreenShotsController> {
 
   Widget _noNoPicturesCard() {
     return Column(
+      mainAxisAlignment: MainAxisAlignment.start,
       children: [
         _titleCard(),
-        Expanded(
-          child: Center(
-            child: Column(
-              mainAxisAlignment: MainAxisAlignment.center,
-              crossAxisAlignment: CrossAxisAlignment.center,
-              children: [
-                Container(
-                  width: 70.w,
-                  height: 70.h,
-                  clipBehavior: Clip.antiAlias,
-                  decoration: BoxDecoration(),
-                  child: Assets.images.iconNoPictures.image(),
-                ),
-                SizedBox(height: 22.h),
-                Text(
-                  'No pictures found',
-                  textAlign: TextAlign.center,
-                  style: TextStyle(
-                    color: Colors.white,
-                    fontSize: 20.sp,
-                    fontWeight: FontWeight.w700,
-                  ),
+        Expanded(child: Center(
+          child: Column(
+            mainAxisAlignment: MainAxisAlignment.center,
+            crossAxisAlignment: CrossAxisAlignment.center,
+            children: [
+              Container(
+                width: 70.w,
+                height: 70.h,
+                clipBehavior: Clip.antiAlias,
+                decoration: BoxDecoration(),
+                child: Assets.images.iconNoPictures.image(),
+              ),
+              SizedBox(height: 22.h),
+              Text(
+                'No pictures found',
+                textAlign: TextAlign.center,
+                style: TextStyle(
+                  color: Colors.white,
+                  fontSize: 20.sp,
+                  fontWeight: FontWeight.w700,
                 ),
-                SizedBox(height: 12.h),
-                Text(
-                  'No pictures available at the moment',
-                  textAlign: TextAlign.center,
-                  style: TextStyle(
-                    color: Colors.white.withValues(alpha: 0.6),
-                    fontSize: 14.sp,
-                    fontWeight: FontWeight.w400,
-                  ),
+              ),
+              SizedBox(height: 12.h),
+              Text(
+                'No pictures available at the moment',
+                textAlign: TextAlign.center,
+                style: TextStyle(
+                  color: Colors.white.withValues(alpha: 0.6),
+                  fontSize: 14.sp,
+                  fontWeight: FontWeight.w400,
                 ),
-              ],
-            ),
+              ),
+            ],
           ),
-        ),
+        )),
       ],
     );
   }

+ 4 - 2
lib/module/similar_photo/similar_photo_view.dart

@@ -233,7 +233,8 @@ class SimilarPhotoPage extends BasePage<SimilarPhotoController> {
                                 ),
                                 image: DecorationImage(
                                   image:
-                                      AssetEntityImageProvider(group.images[0]),
+                                      AssetEntityImageProvider(group.images[0],thumbnailSize: const ThumbnailSize.square(300),
+                                        isOriginal: false,),
                                   fit: BoxFit.cover,
                                 ),
                               ),
@@ -335,7 +336,8 @@ class SimilarPhotoPage extends BasePage<SimilarPhotoController> {
                                     ),
                                     image: DecorationImage(
                                       image: AssetEntityImageProvider(
-                                          group.images[realIndex]),
+                                          group.images[realIndex],thumbnailSize: const ThumbnailSize.square(300),
+                                        isOriginal: false,),
                                       fit: BoxFit.cover,
                                     ),
                                   ),