mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-04 22:38:51 +01:00
Inject Pref to use cases
This commit is contained in:
parent
7583b09bb8
commit
456975360a
9 changed files with 21 additions and 15 deletions
|
@ -11,14 +11,14 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||||
class Pref {
|
class Pref {
|
||||||
factory Pref() => _inst;
|
factory Pref() => _inst;
|
||||||
|
|
||||||
Pref._();
|
Pref.scoped();
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
if (await CompatV32.isPrefNeedMigration()) {
|
if (await CompatV32.isPrefNeedMigration()) {
|
||||||
await CompatV32.migratePref();
|
await CompatV32.migratePref();
|
||||||
}
|
}
|
||||||
return SharedPreferences.getInstance().then((pref) {
|
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;
|
late SharedPreferences _pref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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';
|
import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||||
|
|
||||||
class AddToAlbum {
|
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]
|
/// Add a list of AlbumItems to [album]
|
||||||
Future<Album> call(
|
Future<Album> call(
|
||||||
|
@ -42,7 +42,7 @@ class AddToAlbum {
|
||||||
);
|
);
|
||||||
await UpdateAlbum(albumRepo)(account, newAlbum);
|
await UpdateAlbum(albumRepo)(account, newAlbum);
|
||||||
|
|
||||||
if (Pref().isLabEnableSharedAlbumOr(false)) {
|
if (pref.isLabEnableSharedAlbumOr(false)) {
|
||||||
final newFiles =
|
final newFiles =
|
||||||
items.whereType<AlbumFileItem>().map((e) => e.file).toList();
|
items.whereType<AlbumFileItem>().map((e) => e.file).toList();
|
||||||
if (newFiles.isNotEmpty) {
|
if (newFiles.isNotEmpty) {
|
||||||
|
@ -99,6 +99,7 @@ class AddToAlbum {
|
||||||
final AlbumRepo albumRepo;
|
final AlbumRepo albumRepo;
|
||||||
final ShareRepo shareRepo;
|
final ShareRepo shareRepo;
|
||||||
final AppDb appDb;
|
final AppDb appDb;
|
||||||
|
final Pref pref;
|
||||||
|
|
||||||
static final _log = Logger("use_case.add_to_album.AddToAlbum");
|
static final _log = Logger("use_case.add_to_album.AddToAlbum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ import 'package:nc_photos/use_case/remove_share.dart';
|
||||||
import 'package:nc_photos/use_case/unshare_file_from_album.dart';
|
import 'package:nc_photos/use_case/unshare_file_from_album.dart';
|
||||||
|
|
||||||
class RemoveAlbum {
|
class RemoveAlbum {
|
||||||
const RemoveAlbum(this.fileRepo, this.albumRepo, this.shareRepo);
|
const RemoveAlbum(this.fileRepo, this.albumRepo, this.shareRepo, this.pref);
|
||||||
|
|
||||||
/// Remove an album
|
/// Remove an album
|
||||||
Future<void> call(Account account, Album album) async {
|
Future<void> call(Account account, Album album) async {
|
||||||
_log.info("[call] Remove album: $album");
|
_log.info("[call] Remove album: $album");
|
||||||
if (Pref().isLabEnableSharedAlbumOr(false)) {
|
if (pref.isLabEnableSharedAlbumOr(false)) {
|
||||||
final files = <File>[];
|
final files = <File>[];
|
||||||
if (album.provider is AlbumStaticProvider) {
|
if (album.provider is AlbumStaticProvider) {
|
||||||
files.addAll(AlbumStaticProvider.of(album)
|
files.addAll(AlbumStaticProvider.of(album)
|
||||||
|
@ -59,6 +59,7 @@ class RemoveAlbum {
|
||||||
final FileRepo fileRepo;
|
final FileRepo fileRepo;
|
||||||
final AlbumRepo albumRepo;
|
final AlbumRepo albumRepo;
|
||||||
final ShareRepo shareRepo;
|
final ShareRepo shareRepo;
|
||||||
|
final Pref pref;
|
||||||
|
|
||||||
static final _log = Logger("use_case.remove_album.RemoveAlbum");
|
static final _log = Logger("use_case.remove_album.RemoveAlbum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import 'package:nc_photos/use_case/update_album_with_actual_items.dart';
|
||||||
|
|
||||||
class RemoveFromAlbum {
|
class RemoveFromAlbum {
|
||||||
const 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]
|
/// Remove a list of AlbumItems from [album]
|
||||||
///
|
///
|
||||||
|
@ -49,7 +49,7 @@ class RemoveFromAlbum {
|
||||||
}
|
}
|
||||||
await UpdateAlbum(albumRepo)(account, newAlbum);
|
await UpdateAlbum(albumRepo)(account, newAlbum);
|
||||||
|
|
||||||
if (Pref().isLabEnableSharedAlbumOr(false)) {
|
if (pref.isLabEnableSharedAlbumOr(false)) {
|
||||||
final removeFiles =
|
final removeFiles =
|
||||||
items.whereType<AlbumFileItem>().map((e) => e.file).toList();
|
items.whereType<AlbumFileItem>().map((e) => e.file).toList();
|
||||||
if (removeFiles.isNotEmpty) {
|
if (removeFiles.isNotEmpty) {
|
||||||
|
@ -72,6 +72,7 @@ class RemoveFromAlbum {
|
||||||
final ShareRepo shareRepo;
|
final ShareRepo shareRepo;
|
||||||
final FileRepo fileRepo;
|
final FileRepo fileRepo;
|
||||||
final AppDb appDb;
|
final AppDb appDb;
|
||||||
|
final Pref pref;
|
||||||
|
|
||||||
static final _log = Logger("use_case.remove_from_album.RemoveFromAlbum");
|
static final _log = Logger("use_case.remove_from_album.RemoveFromAlbum");
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,7 +408,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
||||||
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
||||||
await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb())(
|
await RemoveFromAlbum(albumRepo, shareRepo, fileRepo, AppDb(), Pref())(
|
||||||
widget.account, _album!, selectedItems);
|
widget.account, _album!, selectedItems);
|
||||||
SnackBarManager().showSnackBar(SnackBar(
|
SnackBarManager().showSnackBar(SnackBar(
|
||||||
content: Text(L10n.global().removeSelectedFromAlbumSuccessNotification(
|
content: Text(L10n.global().removeSelectedFromAlbumSuccessNotification(
|
||||||
|
|
|
@ -394,7 +394,8 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
final failures = <Album>[];
|
final failures = <Album>[];
|
||||||
for (final a in selectedAlbums) {
|
for (final a in selectedAlbums) {
|
||||||
try {
|
try {
|
||||||
await RemoveAlbum(fileRepo, albumRepo, shareRepo)(widget.account, a);
|
await RemoveAlbum(fileRepo, albumRepo, shareRepo, Pref())(
|
||||||
|
widget.account, a);
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_log.shout(
|
_log.shout(
|
||||||
"[_onSelectionDeletePressed] Failed while removing album: '${a.name}'",
|
"[_onSelectionDeletePressed] Failed while removing album: '${a.name}'",
|
||||||
|
|
|
@ -429,7 +429,7 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
.toList();
|
.toList();
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
||||||
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
await AddToAlbum(albumRepo, shareRepo, AppDb())(
|
await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())(
|
||||||
widget.account, value, selected);
|
widget.account, value, selected);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
@ -379,7 +379,7 @@ class _PersonBrowserState extends State<PersonBrowser>
|
||||||
.toList();
|
.toList();
|
||||||
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
final albumRepo = AlbumRepo(AlbumCachedDataSource(AppDb()));
|
||||||
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||||
await AddToAlbum(albumRepo, shareRepo, AppDb())(
|
await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())(
|
||||||
widget.account, value, selected);
|
widget.account, value, selected);
|
||||||
setState(() {
|
setState(() {
|
||||||
clearSelectedItems();
|
clearSelectedItems();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import 'package:nc_photos/mobile/platform.dart'
|
||||||
import 'package:nc_photos/notified_action.dart';
|
import 'package:nc_photos/notified_action.dart';
|
||||||
import 'package:nc_photos/platform/features.dart' as features;
|
import 'package:nc_photos/platform/features.dart' as features;
|
||||||
import 'package:nc_photos/platform/k.dart' as platform_k;
|
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/snack_bar_manager.dart';
|
||||||
import 'package:nc_photos/theme.dart';
|
import 'package:nc_photos/theme.dart';
|
||||||
import 'package:nc_photos/use_case/add_to_album.dart';
|
import 'package:nc_photos/use_case/add_to_album.dart';
|
||||||
|
@ -307,7 +308,8 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
.items
|
.items
|
||||||
.whereType<AlbumFileItem>()
|
.whereType<AlbumFileItem>()
|
||||||
.firstWhere((element) => element.file.path == widget.file.path);
|
.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]);
|
widget.account, widget.album!, [thisItem]);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
@ -511,7 +513,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
||||||
));
|
));
|
||||||
return Future.error(ArgumentError("File already in album"));
|
return Future.error(ArgumentError("File already in album"));
|
||||||
}
|
}
|
||||||
await AddToAlbum(albumRepo, shareRepo, AppDb())(
|
await AddToAlbum(albumRepo, shareRepo, AppDb(), Pref())(
|
||||||
widget.account, album, [newItem]);
|
widget.account, album, [newItem]);
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
_log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);
|
_log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);
|
||||||
|
|
Loading…
Reference in a new issue