Add option to clean up uncaterogized album

This commit is contained in:
Neeraj Gupta 2023-12-11 19:27:35 +05:30
parent 42533f285c
commit 0e062eb2d9
2 changed files with 65 additions and 4 deletions

View file

@ -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<void> removeFromUncatIfPresentInOtherAlbum(
Collection collection,
BuildContext bContext,
) async {
try {
final List<EnteFile> 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<bool> _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<int, List<EnteFile>> 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,
);
}
}
}

View file

@ -71,6 +71,7 @@ enum AlbumPopupAction {
addPhotos,
pinAlbum,
removeLink,
cleanUncategorized,
}
class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
@ -385,6 +386,25 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
),
);
}
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<GalleryAppBarWidget> {
}
} 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));
}