From 2a24d2f031909a1a4ccf04917578042897238246 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:27:35 +0530 Subject: [PATCH] Add option to clean up uncaterogized album --- .../collection_sharing_actions.dart | 44 +++++++++++++++++-- .../gallery/gallery_app_bar_widget.dart | 25 +++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/lib/ui/actions/collection/collection_sharing_actions.dart b/lib/ui/actions/collection/collection_sharing_actions.dart index 9428c56da..21d4543a2 100644 --- a/lib/ui/actions/collection/collection_sharing_actions.dart +++ b/lib/ui/actions/collection/collection_sharing_actions.dart @@ -1,3 +1,5 @@ +import "dart:async"; + import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; import 'package:photos/core/configuration.dart'; @@ -257,8 +259,10 @@ class CollectionActions { labelText: S.of(context).sendInvite, isInAlert: true, onTap: () async { - shareText( - S.of(context).shareTextRecommendUsingEnte, + unawaited( + shareText( + S.of(context).shareTextRecommendUsingEnte, + ), ); }, ), @@ -384,6 +388,23 @@ class CollectionActions { await collectionsService.trashEmptyCollection(collection); } + Future removeFromUncatIfPresentInOtherAlbum( + Collection collection, + BuildContext bContext, + ) async { + try { + final List files = + await FilesDB.instance.getAllFilesCollection(collection.id); + await moveFilesFromCurrentCollection(bContext, collection, files); + } catch (e) { + logger.severe("Failed to remove files from uncategorized", e); + await showErrorDialogForException( + context: bContext, + exception: e as Exception, + ); + } + } + // _confirmSharedAlbumDeletion should be shown when user tries to delete an // album shared with other ente users. Future _confirmSharedAlbumDeletion( @@ -446,7 +467,9 @@ class CollectionActions { } if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) { - showShortToast(context, S.of(context).canOnlyRemoveFilesOwnedByYou); + unawaited( + showShortToast(context, S.of(context).canOnlyRemoveFilesOwnedByYou), + ); return; } @@ -528,7 +551,20 @@ class CollectionActions { for (MapEntry> entry in destCollectionToFilesMap.entries) { - await collectionsService.move(entry.key, collection.id, entry.value); + if (collection.type == CollectionType.uncategorized && + entry.key == collection.id) { + // skip moving files to uncategorized collection from uncategorized + // this flow is triggered while cleaning up uncategerized collection + logger.info( + 'skipping moving ${entry.value.length} files to uncategorized collection', + ); + } else { + await collectionsService.move( + entry.key, + collection.id, + entry.value, + ); + } } } diff --git a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index 848535ee6..58f94ba3b 100644 --- a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -71,6 +71,7 @@ enum AlbumPopupAction { addPhotos, pinAlbum, removeLink, + cleanUncategorized, } class _GalleryAppBarWidgetState extends State { @@ -385,6 +386,25 @@ class _GalleryAppBarWidgetState extends State { ), ); } + + if (galleryType == GalleryType.uncategorized) { + items.add( + PopupMenuItem( + value: AlbumPopupAction.cleanUncategorized, + child: Row( + children: [ + const Icon(Icons.crop_original_outlined), + const Padding( + padding: EdgeInsets.all(8), + ), + Text( + "Clean Uncategorized", + ), + ], + ), + ), + ); + } if (galleryType.canPin()) { items.add( PopupMenuItem( @@ -588,6 +608,11 @@ class _GalleryAppBarWidgetState extends State { } } else if (value == AlbumPopupAction.map) { await showOnMap(); + } else if (value == AlbumPopupAction.cleanUncategorized) { + await collectionActions.removeFromUncatIfPresentInOtherAlbum( + widget.collection!, + context, + ); } else { unawaited(showToast(context, S.of(context).somethingWentWrong)); }