mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Migrate old (un)archive code to use filescontroller
This commit is contained in:
parent
8ccc50ac16
commit
dccbad2185
6 changed files with 42 additions and 153 deletions
|
@ -1,52 +0,0 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/notified_action.dart';
|
||||
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
|
||||
import 'package:nc_photos/use_case/update_property.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
|
||||
part 'archive_selection_handler.g.dart';
|
||||
|
||||
@npLog
|
||||
class ArchiveSelectionHandler {
|
||||
ArchiveSelectionHandler(this._c)
|
||||
: assert(require(_c)),
|
||||
assert(InflateFileDescriptor.require(_c));
|
||||
|
||||
static bool require(DiContainer c) => DiContainer.has(c, DiType.fileRepo);
|
||||
|
||||
/// Archive [selectedFiles] and return the archived count
|
||||
Future<int> call({
|
||||
required Account account,
|
||||
required List<FileDescriptor> selection,
|
||||
bool shouldShowProcessingText = true,
|
||||
}) async {
|
||||
final selectedFiles = await InflateFileDescriptor(_c)(account, selection);
|
||||
return NotifiedListAction<File>(
|
||||
list: selectedFiles,
|
||||
action: (file) async {
|
||||
await UpdateProperty(_c).updateIsArchived(account, file, true);
|
||||
},
|
||||
processingText: shouldShowProcessingText
|
||||
? L10n.global()
|
||||
.archiveSelectedProcessingNotification(selectedFiles.length)
|
||||
: null,
|
||||
successText: L10n.global().archiveSelectedSuccessNotification,
|
||||
getFailureText: (failures) =>
|
||||
L10n.global().archiveSelectedFailureNotification(failures.length),
|
||||
onActionError: (file, e, stackTrace) {
|
||||
_log.shout(
|
||||
"[call] Failed while archiving file: ${logFilename(file.path)}",
|
||||
e,
|
||||
stackTrace);
|
||||
},
|
||||
)();
|
||||
}
|
||||
|
||||
final DiContainer _c;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'archive_selection_handler.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// NpLogGenerator
|
||||
// **************************************************************************
|
||||
|
||||
extension _$ArchiveSelectionHandlerNpLog on ArchiveSelectionHandler {
|
||||
// ignore: unused_element
|
||||
Logger get _log => log;
|
||||
|
||||
static final log = Logger(
|
||||
"widget.handler.archive_selection_handler.ArchiveSelectionHandler");
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/notified_action.dart';
|
||||
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
|
||||
import 'package:nc_photos/use_case/update_property.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
|
||||
part 'unarchive_selection_handler.g.dart';
|
||||
|
||||
@npLog
|
||||
class UnarchiveSelectionHandler {
|
||||
UnarchiveSelectionHandler(this._c)
|
||||
: assert(require(_c)),
|
||||
assert(InflateFileDescriptor.require(_c));
|
||||
|
||||
static bool require(DiContainer c) => DiContainer.has(c, DiType.fileRepo);
|
||||
|
||||
/// Unarchive [selectedFiles] and return the unarchived count
|
||||
Future<int> call({
|
||||
required Account account,
|
||||
required List<FileDescriptor> selection,
|
||||
bool shouldShowProcessingText = true,
|
||||
}) async {
|
||||
final selectedFiles = await InflateFileDescriptor(_c)(account, selection);
|
||||
return await NotifiedListAction<File>(
|
||||
list: selectedFiles,
|
||||
action: (file) async {
|
||||
await UpdateProperty(_c).updateIsArchived(account, file, false);
|
||||
},
|
||||
processingText: shouldShowProcessingText
|
||||
? L10n.global()
|
||||
.unarchiveSelectedProcessingNotification(selectedFiles.length)
|
||||
: null,
|
||||
successText: L10n.global().unarchiveSelectedSuccessNotification,
|
||||
getFailureText: (failures) =>
|
||||
L10n.global().unarchiveSelectedFailureNotification(failures.length),
|
||||
onActionError: (file, e, stackTrace) {
|
||||
_log.shout(
|
||||
"[call] Failed while unarchiving file: ${logFilename(file.path)}",
|
||||
e,
|
||||
stackTrace);
|
||||
},
|
||||
)();
|
||||
}
|
||||
|
||||
final DiContainer _c;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'unarchive_selection_handler.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// NpLogGenerator
|
||||
// **************************************************************************
|
||||
|
||||
extension _$UnarchiveSelectionHandlerNpLog on UnarchiveSelectionHandler {
|
||||
// ignore: unused_element
|
||||
Logger get _log => log;
|
||||
|
||||
static final log = Logger(
|
||||
"widget.handler.unarchive_selection_handler.UnarchiveSelectionHandler");
|
||||
}
|
|
@ -25,7 +25,6 @@ import 'package:nc_photos/theme/dimension.dart';
|
|||
import 'package:nc_photos/throttler.dart';
|
||||
import 'package:nc_photos/widget/builder/photo_list_item_builder.dart';
|
||||
import 'package:nc_photos/widget/handler/add_selection_to_collection_handler.dart';
|
||||
import 'package:nc_photos/widget/handler/archive_selection_handler.dart';
|
||||
import 'package:nc_photos/widget/handler/remove_selection_handler.dart';
|
||||
import 'package:nc_photos/widget/home_search_suggestion.dart';
|
||||
import 'package:nc_photos/widget/navigation_bar_blur_filter.dart';
|
||||
|
@ -39,6 +38,7 @@ import 'package:nc_photos/widget/viewer.dart';
|
|||
import 'package:np_async/np_async.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/object_util.dart';
|
||||
import 'package:np_common/or_null.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
|
||||
part 'home_search.g.dart';
|
||||
|
@ -478,7 +478,6 @@ class _HomeSearchState extends State<HomeSearch>
|
|||
}
|
||||
|
||||
Future<void> _onSelectionArchivePressed(BuildContext context) async {
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
final selectedFiles = selectedListItems
|
||||
.whereType<PhotoListFileItem>()
|
||||
.map((e) => e.file)
|
||||
|
@ -486,9 +485,19 @@ class _HomeSearchState extends State<HomeSearch>
|
|||
setState(() {
|
||||
clearSelectedItems();
|
||||
});
|
||||
await ArchiveSelectionHandler(c)(
|
||||
account: widget.account,
|
||||
selection: selectedFiles,
|
||||
await context.read<AccountController>().filesController.updateProperty(
|
||||
selectedFiles,
|
||||
isArchived: const OrNull(true),
|
||||
errorBuilder: (fileIds) {
|
||||
if (mounted) {
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global()
|
||||
.archiveSelectedFailureNotification(fileIds.length)),
|
||||
duration: k.snackBarDurationNormal,
|
||||
));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,7 @@ import 'package:nc_photos/share_handler.dart';
|
|||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:nc_photos/theme.dart';
|
||||
import 'package:nc_photos/widget/disposable.dart';
|
||||
import 'package:nc_photos/widget/handler/archive_selection_handler.dart';
|
||||
import 'package:nc_photos/widget/handler/remove_selection_handler.dart';
|
||||
import 'package:nc_photos/widget/handler/unarchive_selection_handler.dart';
|
||||
import 'package:nc_photos/widget/horizontal_page_viewer.dart';
|
||||
import 'package:nc_photos/widget/image_editor.dart';
|
||||
import 'package:nc_photos/widget/image_enhancer.dart';
|
||||
|
@ -42,6 +40,7 @@ import 'package:nc_photos/widget/viewer_bottom_app_bar.dart';
|
|||
import 'package:nc_photos/widget/viewer_detail_pane.dart';
|
||||
import 'package:nc_photos/widget/viewer_mixin.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/or_null.dart';
|
||||
|
||||
part 'viewer.g.dart';
|
||||
|
||||
|
@ -661,27 +660,42 @@ class _ViewerState extends State<Viewer>
|
|||
|
||||
void _onArchivePressed(BuildContext context) {
|
||||
final index = _viewerController.currentPage;
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
final file = _streamFilesView[index];
|
||||
_log.info("[_onArchivePressed] Archive file: ${file.fdPath}");
|
||||
unawaited(ArchiveSelectionHandler(c)(
|
||||
account: widget.account,
|
||||
selection: [file],
|
||||
shouldShowProcessingText: false,
|
||||
));
|
||||
context.read<AccountController>().filesController.updateProperty(
|
||||
[file],
|
||||
isArchived: const OrNull(true),
|
||||
errorBuilder: (fileIds) {
|
||||
if (mounted) {
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().archiveSelectedFailureNotification(1)),
|
||||
duration: k.snackBarDurationNormal,
|
||||
));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
_removeCurrentItemFromStream(context, index);
|
||||
}
|
||||
|
||||
void _onUnarchivePressed(BuildContext context) {
|
||||
final index = _viewerController.currentPage;
|
||||
final c = KiwiContainer().resolve<DiContainer>();
|
||||
final file = _streamFilesView[index];
|
||||
_log.info("[_onUnarchivePressed] Unarchive file: ${file.fdPath}");
|
||||
unawaited(UnarchiveSelectionHandler(c)(
|
||||
account: widget.account,
|
||||
selection: [file],
|
||||
shouldShowProcessingText: false,
|
||||
));
|
||||
context.read<AccountController>().filesController.updateProperty(
|
||||
[file],
|
||||
isArchived: const OrNull(false),
|
||||
errorBuilder: (fileIds) {
|
||||
if (mounted) {
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content:
|
||||
Text(L10n.global().unarchiveSelectedFailureNotification(1)),
|
||||
duration: k.snackBarDurationNormal,
|
||||
));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
_removeCurrentItemFromStream(context, index);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue