mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +01:00
Remove opened photo from an album
This commit is contained in:
parent
607e8a23ca
commit
ea8d351187
4 changed files with 68 additions and 10 deletions
|
@ -654,6 +654,10 @@
|
|||
"configButtonLabel": "CONFIG",
|
||||
"useAsAlbumCoverTooltip": "Use as album cover",
|
||||
"helpTooltip": "Help",
|
||||
"removeFromAlbumTooltip": "Remove from album",
|
||||
"@removeFromAlbumTooltip": {
|
||||
"description": "Remove the opened photo from an album"
|
||||
},
|
||||
|
||||
"changelogTitle": "Changelog",
|
||||
"@changelogTitle": {
|
||||
|
|
|
@ -20,18 +20,22 @@
|
|||
"metadataTaskPauseNoWiFiNotification",
|
||||
"configButtonLabel",
|
||||
"useAsAlbumCoverTooltip",
|
||||
"helpTooltip"
|
||||
"helpTooltip",
|
||||
"removeFromAlbumTooltip"
|
||||
],
|
||||
|
||||
"es": [
|
||||
"helpTooltip"
|
||||
"helpTooltip",
|
||||
"removeFromAlbumTooltip"
|
||||
],
|
||||
|
||||
"fr": [
|
||||
"helpTooltip"
|
||||
"helpTooltip",
|
||||
"removeFromAlbumTooltip"
|
||||
],
|
||||
|
||||
"ru": [
|
||||
"helpTooltip"
|
||||
"helpTooltip",
|
||||
"removeFromAlbumTooltip"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
}
|
||||
Navigator.pushNamed(context, Viewer.routeName,
|
||||
arguments: ViewerArguments(widget.account, _backingFiles, fileIndex,
|
||||
album: widget.album));
|
||||
album: _album));
|
||||
}
|
||||
|
||||
void _onSelectionAppBarSharePressed(BuildContext context) {
|
||||
|
@ -508,6 +508,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
if (ev.album.albumFile!.path == _album?.albumFile?.path) {
|
||||
setState(() {
|
||||
_album = ev.album;
|
||||
_transformItems();
|
||||
initCover(widget.account, ev.album);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -115,6 +115,15 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
children: [
|
||||
Row(
|
||||
children: [
|
||||
if (widget.album != null &&
|
||||
widget.album!.albumFile?.isOwned(widget.account.username) ==
|
||||
true &&
|
||||
widget.album!.provider is AlbumStaticProvider)
|
||||
_DetailPaneButton(
|
||||
icon: Icons.remove_outlined,
|
||||
label: L10n.of(context).removeFromAlbumTooltip,
|
||||
onPressed: () => _onRemoveFromAlbumPressed(context),
|
||||
),
|
||||
if (widget.album != null &&
|
||||
widget.album!.albumFile?.isOwned(widget.account.username) ==
|
||||
true)
|
||||
|
@ -245,6 +254,43 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _onRemoveFromAlbumPressed(BuildContext context) async {
|
||||
assert(widget.album!.provider is AlbumStaticProvider);
|
||||
await _onAction(
|
||||
context,
|
||||
null,
|
||||
L10n.of(context).removeSelectedFromAlbumSuccessNotification(1),
|
||||
() async {
|
||||
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||
try {
|
||||
final newItems =
|
||||
AlbumStaticProvider.of(widget.album!).items.where((element) {
|
||||
if (element is AlbumFileItem) {
|
||||
return element.file.path != widget.file.path;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}).toList();
|
||||
await UpdateAlbum(albumRepo)(
|
||||
widget.account,
|
||||
widget.album!.copyWith(
|
||||
provider: AlbumStaticProvider(
|
||||
items: newItems,
|
||||
),
|
||||
));
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_log.shout("[_onRemoveFromAlbumPressed] Failed while updating album",
|
||||
e, stackTrace);
|
||||
rethrow;
|
||||
}
|
||||
},
|
||||
failureText: L10n.of(context).removeSelectedFromAlbumFailureNotification,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSetAlbumCoverPressed(BuildContext context) async {
|
||||
assert(widget.album != null);
|
||||
_log.info(
|
||||
|
@ -401,15 +447,18 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
|
||||
Future<void> _onAction(
|
||||
BuildContext context,
|
||||
String processingText,
|
||||
String? processingText,
|
||||
String successText,
|
||||
FutureOr<void> Function() action, {
|
||||
String? failureText,
|
||||
}) async {
|
||||
var controller = SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(processingText),
|
||||
duration: k.snackBarDurationShort,
|
||||
));
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? controller;
|
||||
if (processingText != null) {
|
||||
controller = SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(processingText),
|
||||
duration: k.snackBarDurationShort,
|
||||
));
|
||||
}
|
||||
controller?.closed.whenComplete(() {
|
||||
controller = null;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue