mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Refactoring: hide resync and populate
This commit is contained in:
parent
4c222a239a
commit
7bb41887b3
6 changed files with 34 additions and 10 deletions
|
@ -3,7 +3,7 @@ import 'package:nc_photos/account.dart';
|
|||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/album/item.dart';
|
||||
import 'package:nc_photos/entity/album/provider.dart';
|
||||
import 'package:nc_photos/use_case/resync_album.dart';
|
||||
import 'package:nc_photos/use_case/preprocess_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||
|
||||
|
@ -16,7 +16,7 @@ class AddToAlbum {
|
|||
_log.info("[call] Add ${items.length} items to album '${album.name}'");
|
||||
assert(album.provider is AlbumStaticProvider);
|
||||
// resync is needed to work out album cover and latest item
|
||||
final oldItems = await ResyncAlbum()(account, album);
|
||||
final oldItems = await PreProcessAlbum()(account, album);
|
||||
final newItems = makeDistinctAlbumItems([
|
||||
...items,
|
||||
...oldItems,
|
||||
|
|
24
lib/use_case/preprocess_album.dart
Normal file
24
lib/use_case/preprocess_album.dart
Normal file
|
@ -0,0 +1,24 @@
|
|||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/album/item.dart';
|
||||
import 'package:nc_photos/entity/album/provider.dart';
|
||||
import 'package:nc_photos/use_case/populate_album.dart';
|
||||
import 'package:nc_photos/use_case/resync_album.dart';
|
||||
|
||||
/// Pre-process an album such that it's ready to be displayed
|
||||
///
|
||||
/// Internally, it'll dispatch the work depending on the album:
|
||||
/// - with AlbumStaticProvider: [ResyncAlbum]
|
||||
/// - with AlbumDirProvider: [PopulateAlbum]
|
||||
class PreProcessAlbum {
|
||||
Future<List<AlbumItem>> call(Account account, Album album) {
|
||||
if (album.provider is AlbumStaticProvider) {
|
||||
return ResyncAlbum()(account, album);
|
||||
} else if (album.provider is AlbumDynamicProvider) {
|
||||
return PopulateAlbum()(account, album);
|
||||
} else {
|
||||
throw ArgumentError(
|
||||
"Unknown album provider: ${album.provider.runtimeType}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ import 'package:nc_photos/entity/album/item.dart';
|
|||
import 'package:nc_photos/entity/album/provider.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/use_case/resync_album.dart';
|
||||
import 'package:nc_photos/use_case/preprocess_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||
|
||||
|
@ -34,7 +34,7 @@ class RemoveFromAlbum {
|
|||
element.file.bestDateTime == album.provider.latestItemTime)) {
|
||||
_log.info("[call] Resync as latest item is being removed");
|
||||
// need to update the album properties
|
||||
final newItemsSynced = await ResyncAlbum()(account, newAlbum);
|
||||
final newItemsSynced = await PreProcessAlbum()(account, newAlbum);
|
||||
newAlbum = await UpdateAlbumWithActualItems(null)(
|
||||
account,
|
||||
newAlbum,
|
||||
|
|
|
@ -23,8 +23,8 @@ import 'package:nc_photos/session_storage.dart';
|
|||
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/use_case/preprocess_album.dart';
|
||||
import 'package:nc_photos/use_case/remove_from_album.dart';
|
||||
import 'package:nc_photos/use_case/resync_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||
import 'package:nc_photos/widget/album_browser_mixin.dart';
|
||||
|
@ -655,7 +655,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
|
||||
Future<void> _setAlbum(Album album) async {
|
||||
assert(album.provider is AlbumStaticProvider);
|
||||
final items = await ResyncAlbum()(widget.account, album);
|
||||
final items = await PreProcessAlbum()(widget.account, album);
|
||||
album = album.copyWith(
|
||||
provider: AlbumStaticProvider.of(album).copyWith(
|
||||
items: items,
|
||||
|
|
|
@ -17,7 +17,7 @@ import 'package:nc_photos/k.dart' as k;
|
|||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:nc_photos/theme.dart';
|
||||
import 'package:nc_photos/use_case/create_album.dart';
|
||||
import 'package:nc_photos/use_case/populate_album.dart';
|
||||
import 'package:nc_photos/use_case/preprocess_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||
import 'package:nc_photos/widget/processing_dialog.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -235,7 +235,7 @@ class _AlbumImporterState extends State<AlbumImporter> {
|
|||
);
|
||||
_log.info("[_createAllAlbums] Creating dir album: $album");
|
||||
|
||||
final items = await PopulateAlbum()(widget.account, album);
|
||||
final items = await PreProcessAlbum()(widget.account, album);
|
||||
album = await UpdateAlbumWithActualItems(null)(
|
||||
widget.account, album, items);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import 'package:nc_photos/platform/k.dart' as platform_k;
|
|||
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/use_case/populate_album.dart';
|
||||
import 'package:nc_photos/use_case/preprocess_album.dart';
|
||||
import 'package:nc_photos/use_case/remove.dart';
|
||||
import 'package:nc_photos/use_case/update_album.dart';
|
||||
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||
|
@ -161,7 +161,7 @@ class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
|
|||
|
||||
Future<void> _initAlbum() async {
|
||||
assert(widget.album.provider is AlbumDynamicProvider);
|
||||
final items = await PopulateAlbum()(widget.account, widget.album);
|
||||
final items = await PreProcessAlbum()(widget.account, widget.album);
|
||||
final album = await _updateAlbumPostPopulate(widget.album, items);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
|
Loading…
Reference in a new issue