瀏覽代碼

Cover: Support for resetting to default

Neeraj Gupta 2 年之前
父節點
當前提交
3c77f3e981

+ 2 - 0
lib/models/collection.dart

@@ -97,6 +97,8 @@ class Collection {
   // including expired links
   bool get hasLink => publicURLs != null && publicURLs!.isNotEmpty;
 
+  bool get hasCover => (pubMagicMetadata.coverID ?? 0) > 0;
+
   // hasSharees returns true if the collection is shared with other ente users
   bool get hasSharees => sharees != null && sharees!.isNotEmpty;
 

+ 2 - 2
lib/services/collections_service.dart

@@ -235,8 +235,8 @@ class CollectionsService {
     if (kDebugMode) {
       debugPrint("getCover for collection ${c.id} ${c.displayName}");
     }
-    final coverID = c.pubMagicMetadata.coverID;
-    if (coverID != null && coverID >= 0) {
+    if (c.hasCover) {
+      final coverID = c.pubMagicMetadata.coverID ?? 0;
       final File? cover = await filesDB.getUploadedFile(coverID, c.id);
       if (cover != null) {
         _coverCache[coverKey] = cover;

+ 1 - 1
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -537,7 +537,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
 
   Future<void> setCoverPhoto(BuildContext context) async {
     final int? coverPhotoID = await showPickCoverPhotoSheet(context, widget
-        .collection!);
+        .collection!,);
     if (coverPhotoID != null) {
       changeCoverPhoto(context, widget.collection!, coverPhotoID);
     }

+ 10 - 3
lib/ui/viewer/gallery/hooks/pick_cover_photo.dart

@@ -66,7 +66,7 @@ class PickCoverPhotoWidget extends StatelessWidget {
               maxWidth: min(428, MediaQuery.of(context).size.width),
             ),
             child: Padding(
-              padding: const EdgeInsets.fromLTRB(0, 32, 0, 8),
+              padding: const EdgeInsets.fromLTRB(0, 24, 0, 8),
               child: Column(
                 mainAxisSize: MainAxisSize.max,
                 children: [
@@ -78,6 +78,7 @@ class PickCoverPhotoWidget extends StatelessWidget {
                             title: "Select cover photo",
                           ),
                           caption: collection.displayName,
+                          showCloseButton: true,
                         ),
                         Expanded(
                           child: Gallery(
@@ -161,9 +162,15 @@ class PickCoverPhotoWidget extends StatelessWidget {
                           ButtonWidget(
                             buttonType: ButtonType.secondary,
                             buttonAction: ButtonAction.cancel,
-                            labelText: S.of(context).cancel,
+                            labelText: collection.hasCover
+                                ? S.of(context).resetToDefault
+                                : S.of(context).cancel,
                             onTap: () async {
-                              Navigator.of(context).pop();
+                              if(collection.hasCover) {
+                                Navigator.pop(context, 0);
+                              } else {
+                                Navigator.of(context).pop();
+                              }
                             },
                           ),
                         ],

+ 1 - 1
lib/utils/magic_util.dart

@@ -127,7 +127,7 @@ Future<void> updateOrder(
 }
 
 // changeCoverPhoto is used to change cover photo for a collection. To reset to
-// default cover photo, pass uploadedFileID as -1
+// default cover photo, pass uploadedFileID as 0
 Future<void> changeCoverPhoto(
   BuildContext context,
   Collection collection,