diff --git a/lib/pref.dart b/lib/pref.dart index 892e6211..1c710382 100644 --- a/lib/pref.dart +++ b/lib/pref.dart @@ -11,14 +11,14 @@ import 'package:shared_preferences/shared_preferences.dart'; class Pref { factory Pref() => _inst; - Pref._(); + Pref.scoped(); Future init() async { if (await CompatV32.isPrefNeedMigration()) { await CompatV32.migratePref(); } return SharedPreferences.getInstance().then((pref) { - _inst._pref = pref; + _pref = pref; }); } @@ -207,7 +207,7 @@ class Pref { } } - static late final _inst = Pref._(); + static late final _inst = Pref.scoped(); late SharedPreferences _pref; } diff --git a/lib/use_case/add_to_album.dart b/lib/use_case/add_to_album.dart index 9739cbb7..3716ec21 100644 --- a/lib/use_case/add_to_album.dart +++ b/lib/use_case/add_to_album.dart @@ -15,7 +15,7 @@ import 'package:nc_photos/use_case/update_album.dart'; import 'package:nc_photos/use_case/update_album_with_actual_items.dart'; class AddToAlbum { - const AddToAlbum(this.albumRepo, this.shareRepo, this.appDb); + const AddToAlbum(this.albumRepo, this.shareRepo, this.appDb, this.pref); /// Add a list of AlbumItems to [album] Future call( @@ -42,7 +42,7 @@ class AddToAlbum { ); await UpdateAlbum(albumRepo)(account, newAlbum); - if (Pref().isLabEnableSharedAlbumOr(false)) { + if (pref.isLabEnableSharedAlbumOr(false)) { final newFiles = items.whereType().map((e) => e.file).toList(); if (newFiles.isNotEmpty) { @@ -99,6 +99,7 @@ class AddToAlbum { final AlbumRepo albumRepo; final ShareRepo shareRepo; final AppDb appDb; + final Pref pref; static final _log = Logger("use_case.add_to_album.AddToAlbum"); } diff --git a/lib/use_case/remove_album.dart b/lib/use_case/remove_album.dart index d43e4151..2800d649 100644 --- a/lib/use_case/remove_album.dart +++ b/lib/use_case/remove_album.dart @@ -12,12 +12,12 @@ import 'package:nc_photos/use_case/remove_share.dart'; import 'package:nc_photos/use_case/unshare_file_from_album.dart'; class RemoveAlbum { - const RemoveAlbum(this.fileRepo, this.albumRepo, this.shareRepo); + const RemoveAlbum(this.fileRepo, this.albumRepo, this.shareRepo, this.pref); /// Remove an album Future call(Account account, Album album) async { _log.info("[call] Remove album: $album"); - if (Pref().isLabEnableSharedAlbumOr(false)) { + if (pref.isLabEnableSharedAlbumOr(false)) { final files = []; if (album.provider is AlbumStaticProvider) { files.addAll(AlbumStaticProvider.of(album) @@ -59,6 +59,7 @@ class RemoveAlbum { final FileRepo fileRepo; final AlbumRepo albumRepo; final ShareRepo shareRepo; + final Pref pref; static final _log = Logger("use_case.remove_album.RemoveAlbum"); } diff --git a/lib/use_case/remove_from_album.dart b/lib/use_case/remove_from_album.dart index 39e1432c..a0a30b13 100644 --- a/lib/use_case/remove_from_album.dart +++ b/lib/use_case/remove_from_album.dart @@ -16,7 +16,7 @@ import 'package:nc_photos/use_case/update_album_with_actual_items.dart'; class RemoveFromAlbum { const RemoveFromAlbum( - this.albumRepo, this.shareRepo, this.fileRepo, this.appDb); + this.albumRepo, this.shareRepo, this.fileRepo, this.appDb, this.pref); /// Remove a list of AlbumItems from [album] /// @@ -49,7 +49,7 @@ class RemoveFromAlbum { } await UpdateAlbum(albumRepo)(account, newAlbum); - if (Pref().isLabEnableSharedAlbumOr(false)) { + if (pref.isLabEnableSharedAlbumOr(false)) { final removeFiles = items.whereType().map((e) => e.file).toList(); if (removeFiles.isNotEmpty) { @@ -72,6 +72,7 @@ class RemoveFromAlbum { final ShareRepo shareRepo; final FileRepo fileRepo; final AppDb appDb; + final Pref pref; static final _log = Logger("use_case.remove_from_album.RemoveFromAlbum"); } diff --git a/lib/widget/album_browser.dart b/lib/widget/album_browser.dart index 1cc4bacf..28ca516e 100644 --- a/lib/widget/album_browser.dart +++ b/lib/widget/album_browser.dart @@ -408,7 +408,7 @@ class _AlbumBrowserState extends State final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb())); final shareRepo = ShareRepo(ShareRemoteDataSource()); final fileRepo = FileRepo(FileCachedDataSource(AppDb())); - await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb())( + await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb(), Pref())( widget.account, _album!, selectedItems); SnackBarManager().showSnackBar(SnackBar( content: Text(L10n.global().removeSelectedFromAlbumSuccessNotification( diff --git a/lib/widget/home_albums.dart b/lib/widget/home_albums.dart index a3f14015..915149be 100644 --- a/lib/widget/home_albums.dart +++ b/lib/widget/home_albums.dart @@ -394,7 +394,8 @@ class _HomeAlbumsState extends State final failures = []; for (final a in selectedAlbums) { try { - await RemoveAlbum(fileRepo, albumRepo, shareRepo)(widget.account, a); + await RemoveAlbum(fileRepo, albumRepo, shareRepo, Pref())( + widget.account, a); } catch (e, stackTrace) { _log.shout( "[_onSelectionDeletePressed] Failed while removing album: '${a.name}'", diff --git a/lib/widget/home_photos.dart b/lib/widget/home_photos.dart index 5449792e..80ce2eac 100644 --- a/lib/widget/home_photos.dart +++ b/lib/widget/home_photos.dart @@ -429,7 +429,7 @@ class _HomePhotosState extends State .toList(); final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb())); final shareRepo = ShareRepo(ShareRemoteDataSource()); - await AddToAlbum(albumRepo, shareRepo, AppDb())( + await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())( widget.account, value, selected); if (mounted) { setState(() { diff --git a/lib/widget/person_browser.dart b/lib/widget/person_browser.dart index 7c0511be..285dba7c 100644 --- a/lib/widget/person_browser.dart +++ b/lib/widget/person_browser.dart @@ -379,7 +379,7 @@ class _PersonBrowserState extends State .toList(); final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb())); final shareRepo = ShareRepo(ShareRemoteDataSource()); - await AddToAlbum(albumRepo, shareRepo, AppDb())( + await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())( widget.account, value, selected); setState(() { clearSelectedItems(); diff --git a/lib/widget/viewer_detail_pane.dart b/lib/widget/viewer_detail_pane.dart index e2f10a93..7a7a161d 100644 --- a/lib/widget/viewer_detail_pane.dart +++ b/lib/widget/viewer_detail_pane.dart @@ -28,6 +28,7 @@ import 'package:nc_photos/mobile/platform.dart' import 'package:nc_photos/notified_action.dart'; import 'package:nc_photos/platform/features.dart' as features; import 'package:nc_photos/platform/k.dart' as platform_k; +import 'package:nc_photos/pref.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/add_to_album.dart'; @@ -307,7 +308,8 @@ class _ViewerDetailPaneState extends State { .items .whereType() .firstWhere((element) => element.file.path == widget.file.path); - await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb())( + await RemoveFromAlbum( + albumRepo, shareRepo, fileRepo, AppDb(), Pref())( widget.account, widget.album!, [thisItem]); if (mounted) { Navigator.of(context).pop(); @@ -511,7 +513,7 @@ class _ViewerDetailPaneState extends State { )); return Future.error(ArgumentError("File already in album")); } - await AddToAlbum(albumRepo, shareRepo, AppDb())( + await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())( widget.account, album, [newItem]); } catch (e, stacktrace) { _log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);