mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-15 03:38:53 +01:00
Unset album cover
This commit is contained in:
parent
12aedf4fbe
commit
db73464232
4 changed files with 106 additions and 29 deletions
|
@ -735,6 +735,22 @@
|
||||||
"@emptyTrashbinConfirmationDialogContent": {
|
"@emptyTrashbinConfirmationDialogContent": {
|
||||||
"description": "Make sure the user wants to delete all items"
|
"description": "Make sure the user wants to delete all items"
|
||||||
},
|
},
|
||||||
|
"unsetAlbumCoverTooltip": "Unset cover",
|
||||||
|
"@unsetAlbumCoverTooltip": {
|
||||||
|
"description": "Unset the cover of the opened album"
|
||||||
|
},
|
||||||
|
"unsetAlbumCoverProcessingNotification": "Unsetting cover",
|
||||||
|
"@unsetAlbumCoverProcessingNotification": {
|
||||||
|
"description": "Unsetting the cover of the opened album"
|
||||||
|
},
|
||||||
|
"unsetAlbumCoverSuccessNotification": "Unset cover successfully",
|
||||||
|
"@unsetAlbumCoverSuccessNotification": {
|
||||||
|
"description": "Unset the cover of the opened album successfully"
|
||||||
|
},
|
||||||
|
"unsetAlbumCoverFailureNotification": "Failed unsetting cover",
|
||||||
|
"@unsetAlbumCoverFailureNotification": {
|
||||||
|
"description": "Cannot unset the cover of the opened album"
|
||||||
|
},
|
||||||
|
|
||||||
"errorUnauthenticated": "Unauthenticated access. Please sign-in again if the problem continues",
|
"errorUnauthenticated": "Unauthenticated access. Please sign-in again if the problem continues",
|
||||||
"@errorUnauthenticated": {
|
"@errorUnauthenticated": {
|
||||||
|
|
|
@ -36,7 +36,11 @@
|
||||||
"fileSharedByDescription",
|
"fileSharedByDescription",
|
||||||
"emptyTrashbinTooltip",
|
"emptyTrashbinTooltip",
|
||||||
"emptyTrashbinConfirmationDialogTitle",
|
"emptyTrashbinConfirmationDialogTitle",
|
||||||
"emptyTrashbinConfirmationDialogContent"
|
"emptyTrashbinConfirmationDialogContent",
|
||||||
|
"unsetAlbumCoverTooltip",
|
||||||
|
"unsetAlbumCoverProcessingNotification",
|
||||||
|
"unsetAlbumCoverSuccessNotification",
|
||||||
|
"unsetAlbumCoverFailureNotification"
|
||||||
],
|
],
|
||||||
|
|
||||||
"es": [
|
"es": [
|
||||||
|
@ -45,7 +49,11 @@
|
||||||
"settingsFollowSystemThemeTitle",
|
"settingsFollowSystemThemeTitle",
|
||||||
"settingsUseBlackInDarkThemeTitle",
|
"settingsUseBlackInDarkThemeTitle",
|
||||||
"settingsUseBlackInDarkThemeTrueDescription",
|
"settingsUseBlackInDarkThemeTrueDescription",
|
||||||
"settingsUseBlackInDarkThemeFalseDescription"
|
"settingsUseBlackInDarkThemeFalseDescription",
|
||||||
|
"unsetAlbumCoverTooltip",
|
||||||
|
"unsetAlbumCoverProcessingNotification",
|
||||||
|
"unsetAlbumCoverSuccessNotification",
|
||||||
|
"unsetAlbumCoverFailureNotification"
|
||||||
],
|
],
|
||||||
|
|
||||||
"fr": [
|
"fr": [
|
||||||
|
@ -65,7 +73,11 @@
|
||||||
"fileSharedByDescription",
|
"fileSharedByDescription",
|
||||||
"emptyTrashbinTooltip",
|
"emptyTrashbinTooltip",
|
||||||
"emptyTrashbinConfirmationDialogTitle",
|
"emptyTrashbinConfirmationDialogTitle",
|
||||||
"emptyTrashbinConfirmationDialogContent"
|
"emptyTrashbinConfirmationDialogContent",
|
||||||
|
"unsetAlbumCoverTooltip",
|
||||||
|
"unsetAlbumCoverProcessingNotification",
|
||||||
|
"unsetAlbumCoverSuccessNotification",
|
||||||
|
"unsetAlbumCoverFailureNotification"
|
||||||
],
|
],
|
||||||
|
|
||||||
"ru": [
|
"ru": [
|
||||||
|
@ -85,6 +97,10 @@
|
||||||
"fileSharedByDescription",
|
"fileSharedByDescription",
|
||||||
"emptyTrashbinTooltip",
|
"emptyTrashbinTooltip",
|
||||||
"emptyTrashbinConfirmationDialogTitle",
|
"emptyTrashbinConfirmationDialogTitle",
|
||||||
"emptyTrashbinConfirmationDialogContent"
|
"emptyTrashbinConfirmationDialogContent",
|
||||||
|
"unsetAlbumCoverTooltip",
|
||||||
|
"unsetAlbumCoverProcessingNotification",
|
||||||
|
"unsetAlbumCoverSuccessNotification",
|
||||||
|
"unsetAlbumCoverFailureNotification"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,18 @@ import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||||
import 'package:nc_photos/app_localizations.dart';
|
import 'package:nc_photos/app_localizations.dart';
|
||||||
import 'package:nc_photos/entity/album.dart';
|
import 'package:nc_photos/entity/album.dart';
|
||||||
|
import 'package:nc_photos/entity/album/cover_provider.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/lab.dart';
|
import 'package:nc_photos/lab.dart';
|
||||||
|
import 'package:nc_photos/notified_action.dart';
|
||||||
import 'package:nc_photos/pref.dart';
|
import 'package:nc_photos/pref.dart';
|
||||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
import 'package:nc_photos/use_case/import_pending_shared_album.dart';
|
import 'package:nc_photos/use_case/import_pending_shared_album.dart';
|
||||||
|
import 'package:nc_photos/use_case/update_album.dart';
|
||||||
import 'package:nc_photos/widget/album_browser_app_bar.dart';
|
import 'package:nc_photos/widget/album_browser_app_bar.dart';
|
||||||
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart';
|
||||||
import 'package:nc_photos/widget/selection_app_bar.dart';
|
import 'package:nc_photos/widget/selection_app_bar.dart';
|
||||||
|
@ -47,6 +50,18 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
||||||
List<PopupMenuEntry<int>> Function(BuildContext)? menuItemBuilder,
|
List<PopupMenuEntry<int>> Function(BuildContext)? menuItemBuilder,
|
||||||
void Function(int)? onSelectedMenuItem,
|
void Function(int)? onSelectedMenuItem,
|
||||||
}) {
|
}) {
|
||||||
|
final menuItems = [
|
||||||
|
if (canEdit)
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _menuValueEdit,
|
||||||
|
child: Text(L10n.global().editAlbumMenuLabel),
|
||||||
|
),
|
||||||
|
if (album.coverProvider is AlbumManualCoverProvider)
|
||||||
|
PopupMenuItem(
|
||||||
|
value: _menuValueUnsetCover,
|
||||||
|
child: Text(L10n.global().unsetAlbumCoverTooltip),
|
||||||
|
),
|
||||||
|
];
|
||||||
return AlbumBrowserAppBar(
|
return AlbumBrowserAppBar(
|
||||||
account: account,
|
account: account,
|
||||||
album: album,
|
album: album,
|
||||||
|
@ -79,32 +94,15 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
||||||
tooltip: "Add to collection",
|
tooltip: "Add to collection",
|
||||||
),
|
),
|
||||||
...(actions ?? []),
|
...(actions ?? []),
|
||||||
if (menuItemBuilder != null || canEdit)
|
if (menuItemBuilder != null || menuItems.isNotEmpty)
|
||||||
PopupMenuButton<int>(
|
PopupMenuButton<int>(
|
||||||
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
|
tooltip: MaterialLocalizations.of(context).moreButtonTooltip,
|
||||||
itemBuilder: (context) => [
|
itemBuilder: (context) => [
|
||||||
if (canEdit)
|
...menuItems,
|
||||||
PopupMenuItem(
|
|
||||||
value: -1,
|
|
||||||
child: Text(L10n.global().editAlbumMenuLabel),
|
|
||||||
),
|
|
||||||
...(menuItemBuilder?.call(context) ?? []),
|
...(menuItemBuilder?.call(context) ?? []),
|
||||||
],
|
],
|
||||||
onSelected: (option) {
|
onSelected: (option) => _onMenuOptionSelected(
|
||||||
if (option >= 0) {
|
option, account, album, onSelectedMenuItem),
|
||||||
onSelectedMenuItem?.call(option);
|
|
||||||
} else {
|
|
||||||
switch (option) {
|
|
||||||
case _menuValueEdit:
|
|
||||||
_onAppBarEditPressed(context, album);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
_log.shout("[buildNormalAppBar] Unknown value: $option");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -189,7 +187,28 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAppBarEditPressed(BuildContext context, Album album) {
|
void _onMenuOptionSelected(int option, Account account, Album album,
|
||||||
|
void Function(int)? onSelectedMenuItem) {
|
||||||
|
if (option >= 0) {
|
||||||
|
onSelectedMenuItem?.call(option);
|
||||||
|
} else {
|
||||||
|
switch (option) {
|
||||||
|
case _menuValueEdit:
|
||||||
|
_onAppBarEditPressed(album);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case _menuValueUnsetCover:
|
||||||
|
_onUnsetCoverPressed(account, album);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_log.shout("[_onMenuOptionSelected] Unknown value: $option");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onAppBarEditPressed(Album album) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isEditMode = true;
|
_isEditMode = true;
|
||||||
enterEditMode();
|
enterEditMode();
|
||||||
|
@ -197,6 +216,29 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onUnsetCoverPressed(Account account, Album album) async {
|
||||||
|
_log.info("[_onUnsetCoverPressed] Unset album cover for '${album.name}'");
|
||||||
|
await NotifiedAction(
|
||||||
|
() async {
|
||||||
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
|
try {
|
||||||
|
await UpdateAlbum(albumRepo).call(
|
||||||
|
account,
|
||||||
|
album.copyWith(
|
||||||
|
coverProvider: AlbumAutoCoverProvider(),
|
||||||
|
));
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout("[_onUnsetCoverPressed] Failed while updating album", e,
|
||||||
|
stackTrace);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
L10n.global().unsetAlbumCoverProcessingNotification,
|
||||||
|
L10n.global().unsetAlbumCoverSuccessNotification,
|
||||||
|
failureText: L10n.global().unsetAlbumCoverFailureNotification,
|
||||||
|
)();
|
||||||
|
}
|
||||||
|
|
||||||
void _onSharePressed(BuildContext context, Account account, Album album) {
|
void _onSharePressed(BuildContext context, Account account, Album album) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -247,6 +289,7 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
||||||
|
|
||||||
static final _log = Logger("widget.album_browser_mixin.AlbumBrowserMixin");
|
static final _log = Logger("widget.album_browser_mixin.AlbumBrowserMixin");
|
||||||
static const _menuValueEdit = -1;
|
static const _menuValueEdit = -1;
|
||||||
|
static const _menuValueUnsetCover = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EditFormValue {
|
class _EditFormValue {
|
||||||
|
|
|
@ -168,8 +168,8 @@ class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateAlbumPostPopulate(List<AlbumItem> items) {
|
Future<void> _updateAlbumPostPopulate(List<AlbumItem> items) async {
|
||||||
List<File> timeDescSortedFiles;
|
final List<File> timeDescSortedFiles;
|
||||||
if (widget.album.sortProvider is AlbumTimeSortProvider) {
|
if (widget.album.sortProvider is AlbumTimeSortProvider) {
|
||||||
if ((widget.album.sortProvider as AlbumTimeSortProvider).isAscending) {
|
if ((widget.album.sortProvider as AlbumTimeSortProvider).isAscending) {
|
||||||
timeDescSortedFiles = _backingFiles.reversed.toList();
|
timeDescSortedFiles = _backingFiles.reversed.toList();
|
||||||
|
@ -204,7 +204,8 @@ class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
|
||||||
_album = albumUpdatedTime;
|
_album = albumUpdatedTime;
|
||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
UpdateAlbum(AlbumRepo(AlbumCachedDataSource()))(widget.account, _album!);
|
await UpdateAlbum(AlbumRepo(AlbumCachedDataSource()))(
|
||||||
|
widget.account, _album!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,6 +510,7 @@ class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
|
||||||
setState(() {
|
setState(() {
|
||||||
_album = ev.album;
|
_album = ev.album;
|
||||||
initCover(widget.account, ev.album);
|
initCover(widget.account, ev.album);
|
||||||
|
_updateAlbumPostPopulate(_sortedItems);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue