2022-01-22 13:02:24 +01:00
|
|
|
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';
|
2022-10-15 16:29:18 +02:00
|
|
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
import 'package:nc_photos/notified_action.dart';
|
2022-10-15 16:29:18 +02:00
|
|
|
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
import 'package:nc_photos/use_case/update_property.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
2022-01-22 13:02:24 +01:00
|
|
|
|
2022-12-16 16:01:04 +01:00
|
|
|
part 'archive_selection_handler.g.dart';
|
|
|
|
|
|
|
|
@npLog
|
2022-01-22 13:02:24 +01:00
|
|
|
class ArchiveSelectionHandler {
|
2022-10-15 16:29:18 +02:00
|
|
|
ArchiveSelectionHandler(this._c)
|
|
|
|
: assert(require(_c)),
|
|
|
|
assert(InflateFileDescriptor.require(_c));
|
2022-01-22 13:02:24 +01:00
|
|
|
|
|
|
|
static bool require(DiContainer c) => DiContainer.has(c, DiType.fileRepo);
|
|
|
|
|
|
|
|
/// Archive [selectedFiles] and return the archived count
|
|
|
|
Future<int> call({
|
|
|
|
required Account account,
|
2022-10-15 16:29:18 +02:00
|
|
|
required List<FileDescriptor> selection,
|
2022-10-16 17:19:51 +02:00
|
|
|
bool shouldShowProcessingText = true,
|
2022-10-15 16:29:18 +02:00
|
|
|
}) async {
|
|
|
|
final selectedFiles = await InflateFileDescriptor(_c)(account, selection);
|
2022-01-22 13:02:24 +01:00
|
|
|
return NotifiedListAction<File>(
|
|
|
|
list: selectedFiles,
|
|
|
|
action: (file) async {
|
|
|
|
await UpdateProperty(_c.fileRepo).updateIsArchived(account, file, true);
|
|
|
|
},
|
2022-10-16 17:19:51 +02:00
|
|
|
processingText: shouldShowProcessingText
|
|
|
|
? L10n.global()
|
|
|
|
.archiveSelectedProcessingNotification(selectedFiles.length)
|
|
|
|
: null,
|
2022-01-22 13:02:24 +01:00
|
|
|
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;
|
|
|
|
}
|