mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-22 15:09:22 +01:00
Archive/unarchive opened file
This commit is contained in:
parent
64d7cc66b9
commit
058320ffe4
1 changed files with 116 additions and 30 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:android_intent_plus/android_intent.dart';
|
import 'package:android_intent_plus/android_intent.dart';
|
||||||
import 'package:exifdart/exifdart.dart';
|
import 'package:exifdart/exifdart.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -114,6 +116,18 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
label: L10n.of(context).addToAlbumTooltip,
|
label: L10n.of(context).addToAlbumTooltip,
|
||||||
onPressed: () => _onAddToAlbumPressed(context),
|
onPressed: () => _onAddToAlbumPressed(context),
|
||||||
),
|
),
|
||||||
|
if (widget.file.isArchived == true)
|
||||||
|
_DetailPaneButton(
|
||||||
|
icon: Icons.unarchive_outlined,
|
||||||
|
label: L10n.of(context).unarchiveTooltip,
|
||||||
|
onPressed: () => _onUnarchivePressed(context),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_DetailPaneButton(
|
||||||
|
icon: Icons.archive_outlined,
|
||||||
|
label: L10n.of(context).archiveTooltip,
|
||||||
|
onPressed: () => _onArchivePressed(context),
|
||||||
|
),
|
||||||
_DetailPaneButton(
|
_DetailPaneButton(
|
||||||
icon: Icons.delete_outline,
|
icon: Icons.delete_outline,
|
||||||
label: L10n.of(context).deleteTooltip,
|
label: L10n.of(context).deleteTooltip,
|
||||||
|
@ -259,37 +273,78 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onArchivePressed(BuildContext context) async {
|
||||||
|
_log.info("[_onArchivePressed] Archive file: ${widget.file.path}");
|
||||||
|
await _onAction(
|
||||||
|
context,
|
||||||
|
L10n.of(context).archiveSelectedProcessingNotification(1),
|
||||||
|
L10n.of(context).archiveSelectedSuccessNotification,
|
||||||
|
() async {
|
||||||
|
final fileRepo = FileRepo(FileCachedDataSource());
|
||||||
|
try {
|
||||||
|
await UpdateProperty(fileRepo)
|
||||||
|
.updateIsArchived(widget.account, widget.file, true);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout(
|
||||||
|
"[_onArchivePressed] Failed while archiving file" +
|
||||||
|
(kDebugMode ? ": ${widget.file.path}" : ""),
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
failureText: L10n.of(context).archiveSelectedFailureNotification(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUnarchivePressed(BuildContext context) async {
|
||||||
|
_log.info("[_onUnarchivePressed] Unarchive file: ${widget.file.path}");
|
||||||
|
await _onAction(
|
||||||
|
context,
|
||||||
|
L10n.of(context).unarchiveSelectedProcessingNotification(1),
|
||||||
|
L10n.of(context).unarchiveSelectedSuccessNotification,
|
||||||
|
() async {
|
||||||
|
final fileRepo = FileRepo(FileCachedDataSource());
|
||||||
|
try {
|
||||||
|
await UpdateProperty(fileRepo)
|
||||||
|
.updateIsArchived(widget.account, widget.file, false);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout(
|
||||||
|
"[_onUnarchivePressed] Failed while archiving file" +
|
||||||
|
(kDebugMode ? ": ${widget.file.path}" : ""),
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
failureText: L10n.of(context).unarchiveSelectedFailureNotification(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _onDeletePressed(BuildContext context) async {
|
void _onDeletePressed(BuildContext context) async {
|
||||||
_log.info("[_onDeletePressed] Removing file: ${widget.file.path}");
|
_log.info("[_onDeletePressed] Delete file: ${widget.file.path}");
|
||||||
var controller = SnackBarManager().showSnackBar(SnackBar(
|
await _onAction(
|
||||||
content: Text(L10n.of(context).deleteProcessingNotification),
|
context,
|
||||||
duration: k.snackBarDurationShort,
|
L10n.of(context).deleteProcessingNotification,
|
||||||
));
|
L10n.of(context).deleteSuccessNotification,
|
||||||
controller?.closed.whenComplete(() {
|
() async {
|
||||||
controller = null;
|
final fileRepo = FileRepo(FileCachedDataSource());
|
||||||
});
|
final albumRepo = AlbumRepo(AlbumCachedDataSource());
|
||||||
try {
|
try {
|
||||||
await Remove(FileRepo(FileCachedDataSource()),
|
await Remove(fileRepo, albumRepo)(widget.account, widget.file);
|
||||||
AlbumRepo(AlbumCachedDataSource()))(widget.account, widget.file);
|
Navigator.of(context).pop();
|
||||||
controller?.close();
|
} catch (e, stackTrace) {
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
_log.shout(
|
||||||
content: Text(L10n.of(context).deleteSuccessNotification),
|
"[_onUnarchivePressed] Failed while archiving file" +
|
||||||
duration: k.snackBarDurationNormal,
|
(kDebugMode ? ": ${widget.file.path}" : ""),
|
||||||
));
|
e,
|
||||||
Navigator.of(context).pop();
|
stackTrace);
|
||||||
} catch (e, stacktrace) {
|
rethrow;
|
||||||
_log.shout(
|
}
|
||||||
"[_onDeletePressed] Failed while remove" +
|
},
|
||||||
(kDebugMode ? ": ${widget.file.path}" : ""),
|
);
|
||||||
e,
|
|
||||||
stacktrace);
|
|
||||||
controller?.close();
|
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
|
||||||
content: Text("${L10n.of(context).deleteFailureNotification}: "
|
|
||||||
"${exception_util.toUserString(e, context)}"),
|
|
||||||
duration: k.snackBarDurationNormal,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onMapTap() {
|
void _onMapTap() {
|
||||||
|
@ -333,6 +388,37 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onAction(
|
||||||
|
BuildContext context,
|
||||||
|
String processingText,
|
||||||
|
String successText,
|
||||||
|
FutureOr<void> Function() action, {
|
||||||
|
String? failureText,
|
||||||
|
}) async {
|
||||||
|
var controller = SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(processingText),
|
||||||
|
duration: k.snackBarDurationShort,
|
||||||
|
));
|
||||||
|
controller?.closed.whenComplete(() {
|
||||||
|
controller = null;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await action();
|
||||||
|
controller?.close();
|
||||||
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(successText),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
|
content: Text(
|
||||||
|
(failureText?.isNotEmpty == true ? "$failureText: " : "") +
|
||||||
|
exception_util.toUserString(e, context)),
|
||||||
|
duration: k.snackBarDurationNormal,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static double _gpsDmsToDouble(List<Rational> dms) {
|
static double _gpsDmsToDouble(List<Rational> dms) {
|
||||||
double product = dms[0].toDouble();
|
double product = dms[0].toDouble();
|
||||||
if (dms.length > 1) {
|
if (dms.length > 1) {
|
||||||
|
|
Loading…
Reference in a new issue