浏览代码

Add option to remove files from a collection

Vishnu Mohandas 4 年之前
父节点
当前提交
c880ead160
共有 4 个文件被更改,包括 103 次插入20 次删除
  1. 1 1
      lib/services/collections_service.dart
  2. 3 0
      lib/ui/collection_page.dart
  3. 1 1
      lib/ui/detail_page.dart
  4. 98 18
      lib/ui/gallery_app_bar_widget.dart

+ 1 - 1
lib/services/collections_service.dart

@@ -217,7 +217,7 @@ class CollectionsService {
     params["collectionID"] = collectionID;
     params["collectionID"] = collectionID;
     for (final file in files) {
     for (final file in files) {
       if (params["fileIDs"] == null) {
       if (params["fileIDs"] == null) {
-        params["fileIDs"] = [];
+        params["fileIDs"] = List<int>();
       }
       }
       params["fileIDs"].add(file.uploadedFileID);
       params["fileIDs"].add(file.uploadedFileID);
     }
     }

+ 3 - 0
lib/ui/collection_page.dart

@@ -1,6 +1,8 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
+import 'package:photos/core/event_bus.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
+import 'package:photos/events/collection_updated_event.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/models/selected_files.dart';
 
 
@@ -29,6 +31,7 @@ class _CollectionPageState extends State<CollectionPage> {
                   ? DateTime.now().microsecondsSinceEpoch
                   ? DateTime.now().microsecondsSinceEpoch
                   : lastFile.creationTime,
                   : lastFile.creationTime,
               limit),
               limit),
+      reloadEvent: Bus.instance.on<CollectionUpdatedEvent>(),
       tagPrefix: "collection",
       tagPrefix: "collection",
       selectedFiles: _selectedFiles,
       selectedFiles: _selectedFiles,
     );
     );

+ 1 - 1
lib/ui/detail_page.dart

@@ -179,7 +179,7 @@ class _DetailPageState extends State<DetailPage> {
   Widget _getFavoriteButton() {
   Widget _getFavoriteButton() {
     final file = _files[_selectedIndex];
     final file = _files[_selectedIndex];
     return LikeButton(
     return LikeButton(
-      isLiked: FavoritesService.instance.isLiked(file),
+      isLiked: FavoritesService.instance.isLiked(file.uploadedFileID),
       onTap: (oldValue) async {
       onTap: (oldValue) async {
         final isLiked = !oldValue;
         final isLiked = !oldValue;
         bool hasError = false;
         bool hasError = false;

+ 98 - 18
lib/ui/gallery_app_bar_widget.dart

@@ -1,6 +1,7 @@
 import 'dart:async';
 import 'dart:async';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
+import 'package:logging/logging.dart';
 import 'package:page_transition/page_transition.dart';
 import 'package:page_transition/page_transition.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
@@ -50,7 +51,10 @@ class GalleryAppBarWidget extends StatefulWidget
 }
 }
 
 
 class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
 class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
+  final _logger = Logger("GalleryAppBar");
+
   StreamSubscription _userAuthEventSubscription;
   StreamSubscription _userAuthEventSubscription;
+
   @override
   @override
   void initState() {
   void initState() {
     widget.selectedFiles.addListener(() {
     widget.selectedFiles.addListener(() {
@@ -183,27 +187,62 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
 
 
   List<Widget> _getActions(BuildContext context) {
   List<Widget> _getActions(BuildContext context) {
     List<Widget> actions = List<Widget>();
     List<Widget> actions = List<Widget>();
-    if (widget.selectedFiles.files.isNotEmpty) {
-      if (widget.type == GalleryAppBarType.homepage ||
-          widget.type == GalleryAppBarType.local_folder ||
-          widget.type == GalleryAppBarType.collection) {
-        actions.add(IconButton(
-          icon: Icon(Icons.delete),
-          onPressed: () {
-            _showDeleteSheet(context);
-          },
-        ));
-      }
+    actions.add(IconButton(
+      icon: Icon(Icons.add),
+      onPressed: () {
+        _createAlbum();
+      },
+    ));
+    actions.add(IconButton(
+      icon: Icon(Icons.share),
+      onPressed: () {
+        _shareSelected(context);
+      },
+    ));
+    if (widget.type == GalleryAppBarType.homepage ||
+        widget.type == GalleryAppBarType.local_folder) {
       actions.add(IconButton(
       actions.add(IconButton(
-        icon: Icon(Icons.add),
+        icon: Icon(Icons.delete),
         onPressed: () {
         onPressed: () {
-          _createAlbum();
+          _showDeleteSheet(context);
         },
         },
       ));
       ));
-      actions.add(IconButton(
-        icon: Icon(Icons.share),
-        onPressed: () {
-          _shareSelected(context);
+    } else if (widget.type == GalleryAppBarType.collection) {
+      actions.add(PopupMenuButton(
+        itemBuilder: (context) {
+          return [
+            PopupMenuItem(
+              value: 1,
+              child: Row(
+                children: [
+                  Icon(Icons.remove_circle),
+                  Padding(
+                    padding: EdgeInsets.all(8),
+                  ),
+                  Text("Remove"),
+                ],
+              ),
+            ),
+            PopupMenuItem(
+              value: 2,
+              child: Row(
+                children: [
+                  Icon(Icons.delete),
+                  Padding(
+                    padding: EdgeInsets.all(8),
+                  ),
+                  Text("Delete"),
+                ],
+              ),
+            )
+          ];
+        },
+        onSelected: (value) {
+          if (value == 1) {
+            _showRemoveFromCollectionSheet(context);
+          } else if (value == 2) {
+            _showDeleteSheet(context);
+          }
         },
         },
       ));
       ));
     }
     }
@@ -214,9 +253,50 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
     shareMultiple(context, widget.selectedFiles.files.toList());
     shareMultiple(context, widget.selectedFiles.files.toList());
   }
   }
 
 
+  void _showRemoveFromCollectionSheet(BuildContext context) {
+    final action = CupertinoActionSheet(
+      title: Text("Remove " +
+          widget.selectedFiles.files.length.toString() +
+          " files from " +
+          widget.collection.name +
+          "?"),
+      actions: <Widget>[
+        CupertinoActionSheetAction(
+          child: Text("Remove"),
+          isDestructiveAction: true,
+          onPressed: () async {
+            final dialog = createProgressDialog(context, "Removing files...");
+            await dialog.show();
+            try {
+              CollectionsService.instance.removeFromCollection(
+                  widget.collection.id, widget.selectedFiles.files.toList());
+              await dialog.hide();
+              widget.selectedFiles.clearAll();
+              Navigator.of(context).pop();
+            } catch (e, s) {
+              _logger.severe(e, s);
+              await dialog.hide();
+              Navigator.of(context).pop();
+              showGenericErrorDialog(context);
+            }
+          },
+        ),
+      ],
+      cancelButton: CupertinoActionSheetAction(
+        child: Text("Cancel"),
+        onPressed: () {
+          Navigator.of(context, rootNavigator: true).pop();
+        },
+      ),
+    );
+    showCupertinoModalPopup(context: context, builder: (_) => action);
+  }
+
   void _showDeleteSheet(BuildContext context) {
   void _showDeleteSheet(BuildContext context) {
     final action = CupertinoActionSheet(
     final action = CupertinoActionSheet(
-      title: Text("Delete file?"),
+      title: Text("Permanently delete " +
+          widget.selectedFiles.files.length.toString() +
+          " files?"),
       actions: <Widget>[
       actions: <Widget>[
         CupertinoActionSheetAction(
         CupertinoActionSheetAction(
           child: Text("Delete"),
           child: Text("Delete"),