Refactor pref

This commit is contained in:
Ming Ming 2023-07-17 15:35:45 +08:00
parent 4bfe37b94c
commit 0725e8ebce
56 changed files with 802 additions and 774 deletions

View file

@ -22,6 +22,9 @@ import 'package:nc_photos/entity/nc_album/data_source.dart';
import 'package:nc_photos/entity/nc_album/repo.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/entity/person/data_source.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref/provider/shared_preferences.dart';
import 'package:nc_photos/entity/pref_util.dart' as pref_util;
import 'package:nc_photos/entity/search.dart';
import 'package:nc_photos/entity/search/data_source.dart';
import 'package:nc_photos/entity/share.dart';
@ -42,8 +45,6 @@ import 'package:nc_photos/mobile/platform.dart'
import 'package:nc_photos/mobile/self_signed_cert_manager.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/pref_util.dart' as pref_util;
import 'package:nc_photos/touch_manager.dart';
import 'package:visibility_detector/visibility_detector.dart';

View file

@ -12,11 +12,11 @@ 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/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/event/native_event.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/progress_util.dart';
import 'package:nc_photos/throttler.dart';
import 'package:nc_photos/use_case/ls.dart';

View file

@ -1,6 +1,6 @@
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:rxdart/rxdart.dart';

View file

@ -1,5 +1,6 @@
import 'package:logging/logging.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/lazy.dart';
import 'package:np_codegen/np_codegen.dart';

View file

@ -6,6 +6,7 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/local_file.dart';
import 'package:nc_photos/entity/nc_album/repo.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/search.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/entity/sharee.dart';
@ -13,7 +14,6 @@ import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/entity/tag.dart';
import 'package:nc_photos/entity/tagged_file.dart';
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/touch_manager.dart';
enum DiType {

View file

@ -8,6 +8,7 @@ import 'package:nc_photos/entity/collection_item.dart';
import 'package:nc_photos/entity/collection_item/basic_item.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/use_case/list_location_file.dart';
class CollectionMemoryAdapter

301
app/lib/entity/pref.dart Normal file
View file

@ -0,0 +1,301 @@
import 'dart:async';
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/pref/provider/memory.dart';
import 'package:nc_photos/event/event.dart';
import 'package:np_codegen/np_codegen.dart';
part 'pref.g.dart';
part 'pref/extension.dart';
@npLog
class Pref {
factory Pref() {
_inst ??= Pref.scoped(PrefMemoryProvider());
return _inst!;
}
Pref.scoped(this.provider);
/// Set the global [Pref] instance returned by the default constructor
static void setGlobalInstance(Pref pref) {
assert(_inst == null);
_inst = pref;
}
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) {
KiwiContainer().resolve<EventBus>().fire(PrefUpdatedEvent(key, value));
return true;
} else {
return false;
}
}
Future<bool> _remove(PrefKey key) => provider.remove(key);
final PrefProvider provider;
static Pref? _inst;
}
class AccountPref {
AccountPref.scoped(this.provider);
static AccountPref of(Account account) {
_insts.putIfAbsent(
account.id, () => AccountPref.scoped(PrefMemoryProvider()));
return _insts[account.id]!;
}
/// Set the global [AccountPref] instance returned by the default constructor
static void setGlobalInstance(Account account, AccountPref? pref) {
if (pref != null) {
assert(!_insts.containsKey(account.id));
_insts[account.id] = pref;
} else {
assert(_insts.containsKey(account.id));
_insts.remove(account.id);
}
}
bool? isEnableFaceRecognitionApp() =>
provider.getBool(PrefKey.isEnableFaceRecognitionApp);
bool isEnableFaceRecognitionAppOr([bool def = true]) =>
isEnableFaceRecognitionApp() ?? def;
Future<bool> setEnableFaceRecognitionApp(bool value) => _set<bool>(
PrefKey.isEnableFaceRecognitionApp,
value,
(key, value) => provider.setBool(key, value));
String? getShareFolder() => provider.getString(PrefKey.shareFolder);
String getShareFolderOr([String def = ""]) => getShareFolder() ?? def;
Future<bool> setShareFolder(String value) => _set<String>(PrefKey.shareFolder,
value, (key, value) => provider.setString(key, value));
bool? hasNewSharedAlbum() => provider.getBool(PrefKey.hasNewSharedAlbum);
bool hasNewSharedAlbumOr([bool def = false]) => hasNewSharedAlbum() ?? def;
Future<bool> setNewSharedAlbum(bool value) => _set<bool>(
PrefKey.hasNewSharedAlbum,
value,
(key, value) => provider.setBool(key, value));
bool? isEnableMemoryAlbum() => provider.getBool(PrefKey.isEnableMemoryAlbum);
bool isEnableMemoryAlbumOr([bool def = false]) =>
isEnableMemoryAlbum() ?? def;
Future<bool> setEnableMemoryAlbum(bool value) => _set<bool>(
PrefKey.isEnableMemoryAlbum,
value,
(key, value) => provider.setBool(key, value));
String? getTouchRootEtag() => provider.getString(PrefKey.touchRootEtag);
String getTouchRootEtagOr([String def = ""]) => getTouchRootEtag() ?? def;
Future<bool> setTouchRootEtag(String value) => _set<String>(
PrefKey.touchRootEtag,
value,
(key, value) => provider.setString(key, value));
Future<bool> removeTouchRootEtag() => _remove(PrefKey.touchRootEtag);
String? getAccountLabel() => provider.getString(PrefKey.accountLabel);
String getAccountLabelOr([String def = ""]) => getAccountLabel() ?? def;
Future<bool> setAccountLabel(String? value) {
if (value == null) {
return _remove(PrefKey.accountLabel);
} else {
return _set<String>(PrefKey.accountLabel, value,
(key, value) => provider.setString(key, value));
}
}
int? getLastNewCollectionType() =>
provider.getInt(PrefKey.lastNewCollectionType);
int getLastNewCollectionTypeOr(int def) => getLastNewCollectionType() ?? def;
Future<bool> setLastNewCollectionType(int? value) {
if (value == null) {
return _remove(PrefKey.lastNewCollectionType);
} else {
return _set<int>(PrefKey.lastNewCollectionType, value,
(key, value) => provider.setInt(key, value));
}
}
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) {
KiwiContainer()
.resolve<EventBus>()
.fire(AccountPrefUpdatedEvent(this, key, value));
return true;
} else {
return false;
}
}
Future<bool> _remove(PrefKey key) => provider.remove(key);
final PrefProvider provider;
static final _insts = <String, AccountPref>{};
}
enum PrefKey {
accounts3,
currentAccountIndex,
homePhotosZoomLevel,
albumBrowserZoomLevel,
homeAlbumsSort,
enableExif,
viewerScreenBrightness,
viewerForceRotation,
setupProgress,
lastVersion,
darkTheme,
followSystemTheme,
useBlackInDarkTheme,
language,
labEnableSharedAlbum,
slideshowDuration,
isSlideshowShuffle,
isSlideshowRepeat,
isAlbumBrowserShowDate,
gpsMapProvider,
hasShownSharedAlbumInfo,
enhanceMaxWidth,
enhanceMaxHeight,
hasShownEnhanceInfo,
firstRunTime,
isPhotosTabSortByName,
shouldProcessExifWifiOnly,
doubleTapExit,
memoriesRange,
saveEditResultToServer,
hasShownSaveEditResultDialog,
isSlideshowReverse,
seedColor,
isVideoPlayerMute,
isVideoPlayerLoop,
// account pref
isEnableFaceRecognitionApp,
shareFolder,
hasNewSharedAlbum,
isEnableMemoryAlbum,
touchRootEtag,
accountLabel,
lastNewCollectionType;
String toStringKey() {
switch (this) {
case PrefKey.accounts3:
return "accounts3";
case PrefKey.currentAccountIndex:
return "currentAccountIndex";
case PrefKey.homePhotosZoomLevel:
return "homePhotosZoomLevel";
case PrefKey.albumBrowserZoomLevel:
return "albumViewerZoomLevel";
case PrefKey.homeAlbumsSort:
return "homeAlbumsSort";
case PrefKey.enableExif:
return "isEnableExif";
case PrefKey.viewerScreenBrightness:
return "viewerScreenBrightness";
case PrefKey.viewerForceRotation:
return "viewerForceRotation";
case PrefKey.setupProgress:
return "setupProgress";
case PrefKey.lastVersion:
return "lastVersion";
case PrefKey.darkTheme:
return "isDarkTheme";
case PrefKey.followSystemTheme:
return "isFollowSystemTheme";
case PrefKey.useBlackInDarkTheme:
return "isUseBlackInDarkTheme";
case PrefKey.language:
return "language";
case PrefKey.labEnableSharedAlbum:
return "isLabEnableSharedAlbum";
case PrefKey.slideshowDuration:
return "slideshowDuration";
case PrefKey.isSlideshowShuffle:
return "isSlideshowShuffle";
case PrefKey.isSlideshowRepeat:
return "isSlideshowRepeat";
case PrefKey.isAlbumBrowserShowDate:
return "isAlbumBrowserShowDate";
case PrefKey.gpsMapProvider:
return "gpsMapProvider";
case PrefKey.hasShownSharedAlbumInfo:
return "hasShownSharedAlbumInfo";
case PrefKey.enhanceMaxWidth:
return "enhanceMaxWidth";
case PrefKey.enhanceMaxHeight:
return "enhanceMaxHeight";
case PrefKey.hasShownEnhanceInfo:
return "hasShownEnhanceInfo";
case PrefKey.firstRunTime:
return "firstRunTime";
case PrefKey.isPhotosTabSortByName:
return "isPhotosTabSortByName";
case PrefKey.shouldProcessExifWifiOnly:
return "shouldProcessExifWifiOnly";
case PrefKey.doubleTapExit:
return "doubleTapExit";
case PrefKey.memoriesRange:
return "memoriesRange";
case PrefKey.saveEditResultToServer:
return "saveEditResultToServer";
case PrefKey.hasShownSaveEditResultDialog:
return "hasShownSaveEditResultDialog";
case PrefKey.isSlideshowReverse:
return "isSlideshowReverse";
case PrefKey.seedColor:
return "seedColor";
case PrefKey.isVideoPlayerMute:
return "isVideoPlayerMute";
case PrefKey.isVideoPlayerLoop:
return "isVideoPlayerLoop";
// account pref
case PrefKey.isEnableFaceRecognitionApp:
return "isEnableFaceRecognitionApp";
case PrefKey.shareFolder:
return "shareFolder";
case PrefKey.hasNewSharedAlbum:
return "hasNewSharedAlbum";
case PrefKey.isEnableMemoryAlbum:
return "isEnableMemoryAlbum";
case PrefKey.touchRootEtag:
return "touchRootEtag";
case PrefKey.accountLabel:
return "accountLabel";
case PrefKey.lastNewCollectionType:
return "lastNewCollectionType";
}
}
}
/// Provide the data for [Pref]
abstract class PrefProvider {
bool? getBool(PrefKey key);
Future<bool> setBool(PrefKey key, bool value);
int? getInt(PrefKey key);
Future<bool> setInt(PrefKey key, int value);
String? getString(PrefKey key);
Future<bool> setString(PrefKey key, String value);
List<String>? getStringList(PrefKey key);
Future<bool> setStringList(PrefKey key, List<String> value);
Future<bool> remove(PrefKey key);
Future<bool> clear();
}

View file

@ -0,0 +1,270 @@
part of '../pref.dart';
extension PrefExtension on Pref {
Account? getCurrentAccount() {
try {
return getAccounts3()![getCurrentAccountIndex()!];
} catch (_) {
return null;
}
}
List<Account>? getAccounts3() {
final jsonObjs = provider.getStringList(PrefKey.accounts3);
return jsonObjs
?.map((e) => Account.fromJson(
jsonDecode(e),
upgraderV1: const AccountUpgraderV1(),
))
.where((e) {
if (e == null) {
_log.shout("[getAccounts3] Failed upgrading account");
}
return true;
})
.whereNotNull()
.toList();
}
List<Account> getAccounts3Or(List<Account> def) => getAccounts3() ?? def;
Future<bool> setAccounts3(List<Account>? value) {
if (value == null) {
return _remove(PrefKey.accounts3);
} else {
final jsons = value.map((e) => jsonEncode(e.toJson())).toList();
return provider.setStringList(PrefKey.accounts3, jsons);
}
}
int? getCurrentAccountIndex() => provider.getInt(PrefKey.currentAccountIndex);
int getCurrentAccountIndexOr(int def) => getCurrentAccountIndex() ?? def;
Future<bool> setCurrentAccountIndex(int? value) {
if (value == null) {
return _remove(PrefKey.currentAccountIndex);
} else {
return _set<int>(PrefKey.currentAccountIndex, value,
(key, value) => provider.setInt(key, value));
}
}
int? getHomePhotosZoomLevel() => provider.getInt(PrefKey.homePhotosZoomLevel);
int getHomePhotosZoomLevelOr(int def) => getHomePhotosZoomLevel() ?? def;
Future<bool> setHomePhotosZoomLevel(int value) => _set<int>(
PrefKey.homePhotosZoomLevel,
value,
(key, value) => provider.setInt(key, value));
int? getAlbumBrowserZoomLevel() =>
provider.getInt(PrefKey.albumBrowserZoomLevel);
int getAlbumBrowserZoomLevelOr(int def) => getAlbumBrowserZoomLevel() ?? def;
Future<bool> setAlbumBrowserZoomLevel(int value) => _set<int>(
PrefKey.albumBrowserZoomLevel,
value,
(key, value) => provider.setInt(key, value));
int? getHomeAlbumsSort() => provider.getInt(PrefKey.homeAlbumsSort);
int getHomeAlbumsSortOr(int def) => getHomeAlbumsSort() ?? def;
Future<bool> setHomeAlbumsSort(int value) => _set<int>(PrefKey.homeAlbumsSort,
value, (key, value) => provider.setInt(key, value));
bool? isEnableExif() => provider.getBool(PrefKey.enableExif);
bool isEnableExifOr([bool def = true]) => isEnableExif() ?? def;
Future<bool> setEnableExif(bool value) => _set<bool>(
PrefKey.enableExif, value, (key, value) => provider.setBool(key, value));
int? getViewerScreenBrightness() =>
provider.getInt(PrefKey.viewerScreenBrightness);
int getViewerScreenBrightnessOr([int def = -1]) =>
getViewerScreenBrightness() ?? def;
Future<bool> setViewerScreenBrightness(int value) => _set<int>(
PrefKey.viewerScreenBrightness,
value,
(key, value) => provider.setInt(key, value));
bool? isViewerForceRotation() =>
provider.getBool(PrefKey.viewerForceRotation);
bool isViewerForceRotationOr([bool def = false]) =>
isViewerForceRotation() ?? def;
Future<bool> setViewerForceRotation(bool value) => _set<bool>(
PrefKey.viewerForceRotation,
value,
(key, value) => provider.setBool(key, value));
int? getSetupProgress() => provider.getInt(PrefKey.setupProgress);
int getSetupProgressOr([int def = 0]) => getSetupProgress() ?? def;
Future<bool> setSetupProgress(int value) => _set<int>(PrefKey.setupProgress,
value, (key, value) => provider.setInt(key, value));
/// Return the version number when the app last ran
int? getLastVersion() => provider.getInt(PrefKey.lastVersion);
int getLastVersionOr(int def) => getLastVersion() ?? def;
Future<bool> setLastVersion(int value) => _set<int>(
PrefKey.lastVersion, value, (key, value) => provider.setInt(key, value));
bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme);
bool isDarkThemeOr(bool def) => isDarkTheme() ?? def;
Future<bool> setDarkTheme(bool value) => _set<bool>(
PrefKey.darkTheme, value, (key, value) => provider.setBool(key, value));
bool? isFollowSystemTheme() => provider.getBool(PrefKey.followSystemTheme);
bool isFollowSystemThemeOr(bool def) => isFollowSystemTheme() ?? def;
Future<bool> setFollowSystemTheme(bool value) => _set<bool>(
PrefKey.followSystemTheme,
value,
(key, value) => provider.setBool(key, value));
bool? isUseBlackInDarkTheme() =>
provider.getBool(PrefKey.useBlackInDarkTheme);
bool isUseBlackInDarkThemeOr(bool def) => isUseBlackInDarkTheme() ?? def;
Future<bool> setUseBlackInDarkTheme(bool value) => _set<bool>(
PrefKey.useBlackInDarkTheme,
value,
(key, value) => provider.setBool(key, value));
int? getLanguage() => provider.getInt(PrefKey.language);
int getLanguageOr(int def) => getLanguage() ?? def;
Future<bool> setLanguage(int value) => _set<int>(
PrefKey.language, value, (key, value) => provider.setInt(key, value));
int? getSlideshowDuration() => provider.getInt(PrefKey.slideshowDuration);
int getSlideshowDurationOr(int def) => getSlideshowDuration() ?? def;
Future<bool> setSlideshowDuration(int value) => _set<int>(
PrefKey.slideshowDuration,
value,
(key, value) => provider.setInt(key, value));
bool? isSlideshowShuffle() => provider.getBool(PrefKey.isSlideshowShuffle);
bool isSlideshowShuffleOr(bool def) => isSlideshowShuffle() ?? def;
Future<bool> setSlideshowShuffle(bool value) => _set<bool>(
PrefKey.isSlideshowShuffle,
value,
(key, value) => provider.setBool(key, value));
bool? isSlideshowRepeat() => provider.getBool(PrefKey.isSlideshowRepeat);
bool isSlideshowRepeatOr(bool def) => isSlideshowRepeat() ?? def;
Future<bool> setSlideshowRepeat(bool value) => _set<bool>(
PrefKey.isSlideshowRepeat,
value,
(key, value) => provider.setBool(key, value));
bool? isAlbumBrowserShowDate() =>
provider.getBool(PrefKey.isAlbumBrowserShowDate);
bool isAlbumBrowserShowDateOr([bool def = false]) =>
isAlbumBrowserShowDate() ?? def;
Future<bool> setAlbumBrowserShowDate(bool value) => _set<bool>(
PrefKey.isAlbumBrowserShowDate,
value,
(key, value) => provider.setBool(key, value));
int? getGpsMapProvider() => provider.getInt(PrefKey.gpsMapProvider);
int getGpsMapProviderOr(int def) => getGpsMapProvider() ?? def;
Future<bool> setGpsMapProvider(int value) => _set<int>(PrefKey.gpsMapProvider,
value, (key, value) => provider.setInt(key, value));
bool? hasShownSharedAlbumInfo() =>
provider.getBool(PrefKey.hasShownSharedAlbumInfo);
bool hasShownSharedAlbumInfoOr(bool def) => hasShownSharedAlbumInfo() ?? def;
Future<bool> setHasShownSharedAlbumInfo(bool value) => _set<bool>(
PrefKey.hasShownSharedAlbumInfo,
value,
(key, value) => provider.setBool(key, value));
int? getEnhanceMaxWidth() => provider.getInt(PrefKey.enhanceMaxWidth);
int getEnhanceMaxWidthOr([int def = 2048]) => getEnhanceMaxWidth() ?? def;
Future<bool> setEnhanceMaxWidth(int value) => _set<int>(
PrefKey.enhanceMaxWidth,
value,
(key, value) => provider.setInt(key, value));
int? getEnhanceMaxHeight() => provider.getInt(PrefKey.enhanceMaxHeight);
int getEnhanceMaxHeightOr([int def = 1536]) => getEnhanceMaxHeight() ?? def;
Future<bool> setEnhanceMaxHeight(int value) => _set<int>(
PrefKey.enhanceMaxHeight,
value,
(key, value) => provider.setInt(key, value));
bool? hasShownEnhanceInfo() => provider.getBool(PrefKey.hasShownEnhanceInfo);
bool hasShownEnhanceInfoOr([bool def = false]) =>
hasShownEnhanceInfo() ?? def;
Future<bool> setHasShownEnhanceInfo(bool value) => _set<bool>(
PrefKey.hasShownEnhanceInfo,
value,
(key, value) => provider.setBool(key, value));
int? getFirstRunTime() => provider.getInt(PrefKey.firstRunTime);
int getFirstRunTimeOr(int def) => getFirstRunTime() ?? def;
Future<bool> setFirstRunTime(int value) => _set<int>(
PrefKey.firstRunTime, value, (key, value) => provider.setInt(key, value));
bool? isPhotosTabSortByName() =>
provider.getBool(PrefKey.isPhotosTabSortByName);
bool isPhotosTabSortByNameOr([bool def = false]) =>
isPhotosTabSortByName() ?? def;
Future<bool> setPhotosTabSortByName(bool value) => _set<bool>(
PrefKey.isPhotosTabSortByName,
value,
(key, value) => provider.setBool(key, value));
bool? shouldProcessExifWifiOnly() =>
provider.getBool(PrefKey.shouldProcessExifWifiOnly);
bool shouldProcessExifWifiOnlyOr([bool def = true]) =>
shouldProcessExifWifiOnly() ?? def;
Future<bool> setProcessExifWifiOnly(bool value) => _set<bool>(
PrefKey.shouldProcessExifWifiOnly,
value,
(key, value) => provider.setBool(key, value));
bool? isDoubleTapExit() => provider.getBool(PrefKey.doubleTapExit);
bool isDoubleTapExitOr([bool def = false]) => isDoubleTapExit() ?? def;
Future<bool> setDoubleTapExit(bool value) => _set<bool>(PrefKey.doubleTapExit,
value, (key, value) => provider.setBool(key, value));
int? getMemoriesRange() => provider.getInt(PrefKey.memoriesRange);
int getMemoriesRangeOr([int def = 2]) => getMemoriesRange() ?? def;
Future<bool> setMemoriesRange(int value) => _set<int>(PrefKey.memoriesRange,
value, (key, value) => provider.setInt(key, value));
bool? isSaveEditResultToServer() =>
provider.getBool(PrefKey.saveEditResultToServer);
bool isSaveEditResultToServerOr([bool def = true]) =>
isSaveEditResultToServer() ?? def;
Future<bool> setSaveEditResultToServer(bool value) => _set<bool>(
PrefKey.saveEditResultToServer,
value,
(key, value) => provider.setBool(key, value));
bool? hasShownSaveEditResultDialog() =>
provider.getBool(PrefKey.hasShownSaveEditResultDialog);
bool hasShownSaveEditResultDialogOr([bool def = false]) =>
hasShownSaveEditResultDialog() ?? def;
Future<bool> setHasShownSaveEditResultDialog(bool value) => _set<bool>(
PrefKey.hasShownSaveEditResultDialog,
value,
(key, value) => provider.setBool(key, value));
bool? isSlideshowReverse() => provider.getBool(PrefKey.isSlideshowReverse);
bool isSlideshowReverseOr(bool def) => isSlideshowReverse() ?? def;
Future<bool> setSlideshowReverse(bool value) => _set<bool>(
PrefKey.isSlideshowReverse,
value,
(key, value) => provider.setBool(key, value));
int? getSeedColor() => provider.getInt(PrefKey.seedColor);
int getSeedColorOr(int def) => getSeedColor() ?? def;
Future<bool> setSeedColor(int value) => _set<int>(
PrefKey.seedColor, value, (key, value) => provider.setInt(key, value));
bool? isVideoPlayerMute() => provider.getBool(PrefKey.isVideoPlayerMute);
bool isVideoPlayerMuteOr([bool def = false]) => isVideoPlayerMute() ?? def;
Future<bool> setVideoPlayerMute(bool value) => _set<bool>(
PrefKey.isVideoPlayerMute,
value,
(key, value) => provider.setBool(key, value));
bool? isVideoPlayerLoop() => provider.getBool(PrefKey.isVideoPlayerLoop);
bool isVideoPlayerLoopOr([bool def = false]) => isVideoPlayerLoop() ?? def;
Future<bool> setVideoPlayerLoop(bool value) => _set<bool>(
PrefKey.isVideoPlayerLoop,
value,
(key, value) => provider.setBool(key, value));
}

View file

@ -0,0 +1,50 @@
import 'package:nc_photos/entity/pref.dart';
/// [Pref] stored in memory, useful in unit tests
class PrefMemoryProvider extends PrefProvider {
PrefMemoryProvider([
Map<String, dynamic> initialData = const <String, dynamic>{},
]) : _data = Map.of(initialData);
@override
bool? getBool(PrefKey key) => _get<bool>(key);
@override
Future<bool> setBool(PrefKey key, bool value) => _set(key, value);
@override
int? getInt(PrefKey key) => _get<int>(key);
@override
Future<bool> setInt(PrefKey key, int value) => _set(key, value);
@override
String? getString(PrefKey key) => _get<String>(key);
@override
Future<bool> setString(PrefKey key, String value) => _set(key, value);
@override
List<String>? getStringList(PrefKey key) => _get<List<String>>(key);
@override
Future<bool> setStringList(PrefKey key, List<String> value) =>
_set(key, value);
@override
Future<bool> remove(PrefKey key) async {
_data.remove(key);
return true;
}
@override
Future<bool> clear() async {
_data.clear();
return true;
}
T? _get<T>(PrefKey key) => _data[key.toStringKey()];
Future<bool> _set<T>(PrefKey key, T value) async {
_data[key.toStringKey()] = value;
return true;
}
final Map<String, dynamic> _data;
}

View file

@ -0,0 +1,58 @@
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:nc_photos/use_case/compat/v34.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// [Pref] stored with [SharedPreferences] lib
class PrefSharedPreferencesProvider extends PrefProvider {
Future<void> init() async {
// Obsolete, CompatV34 is compatible with pre v32 versions
// if (await CompatV32.isPrefNeedMigration()) {
// await CompatV32.migratePref();
// }
if (await CompatV34.isPrefNeedMigration()) {
await CompatV34.migratePref(platform.UniversalStorage());
}
return SharedPreferences.getInstance().then((pref) {
_pref = pref;
});
}
@override
bool? getBool(PrefKey key) => _pref.getBool(key.toStringKey());
@override
Future<bool> setBool(PrefKey key, bool value) =>
_pref.setBool(key.toStringKey(), value);
@override
int? getInt(PrefKey key) => _pref.getInt(key.toStringKey());
@override
Future<bool> setInt(PrefKey key, int value) =>
_pref.setInt(key.toStringKey(), value);
@override
String? getString(PrefKey key) => _pref.getString(key.toStringKey());
@override
Future<bool> setString(PrefKey key, String value) =>
_pref.setString(key.toStringKey(), value);
@override
List<String>? getStringList(PrefKey key) =>
_pref.getStringList(key.toStringKey());
@override
Future<bool> setStringList(PrefKey key, List<String> value) =>
_pref.setStringList(key.toStringKey(), value);
@override
Future<bool> remove(PrefKey key) => _pref.remove(key.toStringKey());
@override
Future<bool> clear() => _pref.clear();
late SharedPreferences _pref;
}

View file

@ -0,0 +1,66 @@
import 'dart:convert';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
/// [Pref] backed by [UniversalStorage]
class PrefUniversalStorageProvider extends PrefProvider {
PrefUniversalStorageProvider(this.name);
Future<void> init() async {
final prefStr = await platform.UniversalStorage().getString(name) ?? "{}";
_data
..clear()
..addAll(jsonDecode(prefStr));
}
@override
bool? getBool(PrefKey key) => _get<bool>(key);
@override
Future<bool> setBool(PrefKey key, bool value) => _set(key, value);
@override
int? getInt(PrefKey key) => _get<int>(key);
@override
Future<bool> setInt(PrefKey key, int value) => _set(key, value);
@override
String? getString(PrefKey key) => _get<String>(key);
@override
Future<bool> setString(PrefKey key, String value) => _set(key, value);
@override
List<String>? getStringList(PrefKey key) => _get<List<String>>(key);
@override
Future<bool> setStringList(PrefKey key, List<String> value) =>
_set(key, value);
@override
Future<bool> remove(PrefKey key) async {
final newData = Map.of(_data)..remove(key.toStringKey());
await platform.UniversalStorage().putString(name, jsonEncode(newData));
_data.remove(key.toStringKey());
return true;
}
@override
Future<bool> clear() async {
await platform.UniversalStorage().remove(name);
_data.clear();
return true;
}
T? _get<T>(PrefKey key) => _data[key.toStringKey()];
Future<bool> _set<T>(PrefKey key, T value) async {
final newData = Map.of(_data)
..addEntries([MapEntry(key.toStringKey(), value)]);
await platform.UniversalStorage().putString(name, jsonEncode(newData));
_data[key.toStringKey()] = value;
return true;
}
final String name;
final _data = <String, dynamic>{};
}

View file

@ -1,5 +1,6 @@
import 'package:nc_photos/account.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref/provider/universal_storage.dart';
Future<AccountPref> loadAccountPref(Account account) async {
final provider = PrefUniversalStorageProvider("accounts/${account.id}/pref");

View file

@ -8,8 +8,8 @@ import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/local_file.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/pref.dart';
class AppEventListener<T> {
AppEventListener(this._listener);

View file

@ -1,6 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
class AppLanguage {
const AppLanguage(this.langId, this._nativeName, this.isoName, this.locale);

View file

@ -6,13 +6,13 @@ import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref_util.dart' as pref_util;
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/help_utils.dart' as help_utils;
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/legacy/connect.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/pref_util.dart' as pref_util;
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/url_launcher_util.dart';
import 'package:nc_photos/widget/home.dart';

View file

@ -7,8 +7,8 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/reverse_geocoder.dart';
import 'package:nc_photos/use_case/update_missing_metadata.dart';
import 'package:np_codegen/np_codegen.dart';

View file

@ -1,732 +0,0 @@
import 'dart:async';
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:nc_photos/use_case/compat/v34.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'pref.g.dart';
@npLog
class Pref {
factory Pref() {
_inst ??= Pref.scoped(PrefMemoryProvider());
return _inst!;
}
Pref.scoped(this.provider);
/// Set the global [Pref] instance returned by the default constructor
static void setGlobalInstance(Pref pref) {
assert(_inst == null);
_inst = pref;
}
List<Account>? getAccounts3() {
final jsonObjs = provider.getStringList(PrefKey.accounts3);
return jsonObjs
?.map((e) => Account.fromJson(
jsonDecode(e),
upgraderV1: const AccountUpgraderV1(),
))
.where((e) {
if (e == null) {
_log.shout("[getAccounts3] Failed upgrading account");
}
return true;
})
.whereNotNull()
.toList();
}
List<Account> getAccounts3Or(List<Account> def) => getAccounts3() ?? def;
Future<bool> setAccounts3(List<Account>? value) {
if (value == null) {
return _remove(PrefKey.accounts3);
} else {
final jsons = value.map((e) => jsonEncode(e.toJson())).toList();
return provider.setStringList(PrefKey.accounts3, jsons);
}
}
int? getCurrentAccountIndex() => provider.getInt(PrefKey.currentAccountIndex);
int getCurrentAccountIndexOr(int def) => getCurrentAccountIndex() ?? def;
Future<bool> setCurrentAccountIndex(int? value) {
if (value == null) {
return _remove(PrefKey.currentAccountIndex);
} else {
return _set<int>(PrefKey.currentAccountIndex, value,
(key, value) => provider.setInt(key, value));
}
}
int? getHomePhotosZoomLevel() => provider.getInt(PrefKey.homePhotosZoomLevel);
int getHomePhotosZoomLevelOr(int def) => getHomePhotosZoomLevel() ?? def;
Future<bool> setHomePhotosZoomLevel(int value) => _set<int>(
PrefKey.homePhotosZoomLevel,
value,
(key, value) => provider.setInt(key, value));
int? getAlbumBrowserZoomLevel() =>
provider.getInt(PrefKey.albumBrowserZoomLevel);
int getAlbumBrowserZoomLevelOr(int def) => getAlbumBrowserZoomLevel() ?? def;
Future<bool> setAlbumBrowserZoomLevel(int value) => _set<int>(
PrefKey.albumBrowserZoomLevel,
value,
(key, value) => provider.setInt(key, value));
int? getHomeAlbumsSort() => provider.getInt(PrefKey.homeAlbumsSort);
int getHomeAlbumsSortOr(int def) => getHomeAlbumsSort() ?? def;
Future<bool> setHomeAlbumsSort(int value) => _set<int>(PrefKey.homeAlbumsSort,
value, (key, value) => provider.setInt(key, value));
bool? isEnableExif() => provider.getBool(PrefKey.enableExif);
bool isEnableExifOr([bool def = true]) => isEnableExif() ?? def;
Future<bool> setEnableExif(bool value) => _set<bool>(
PrefKey.enableExif, value, (key, value) => provider.setBool(key, value));
int? getViewerScreenBrightness() =>
provider.getInt(PrefKey.viewerScreenBrightness);
int getViewerScreenBrightnessOr([int def = -1]) =>
getViewerScreenBrightness() ?? def;
Future<bool> setViewerScreenBrightness(int value) => _set<int>(
PrefKey.viewerScreenBrightness,
value,
(key, value) => provider.setInt(key, value));
bool? isViewerForceRotation() =>
provider.getBool(PrefKey.viewerForceRotation);
bool isViewerForceRotationOr([bool def = false]) =>
isViewerForceRotation() ?? def;
Future<bool> setViewerForceRotation(bool value) => _set<bool>(
PrefKey.viewerForceRotation,
value,
(key, value) => provider.setBool(key, value));
int? getSetupProgress() => provider.getInt(PrefKey.setupProgress);
int getSetupProgressOr([int def = 0]) => getSetupProgress() ?? def;
Future<bool> setSetupProgress(int value) => _set<int>(PrefKey.setupProgress,
value, (key, value) => provider.setInt(key, value));
/// Return the version number when the app last ran
int? getLastVersion() => provider.getInt(PrefKey.lastVersion);
int getLastVersionOr(int def) => getLastVersion() ?? def;
Future<bool> setLastVersion(int value) => _set<int>(
PrefKey.lastVersion, value, (key, value) => provider.setInt(key, value));
bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme);
bool isDarkThemeOr(bool def) => isDarkTheme() ?? def;
Future<bool> setDarkTheme(bool value) => _set<bool>(
PrefKey.darkTheme, value, (key, value) => provider.setBool(key, value));
bool? isFollowSystemTheme() => provider.getBool(PrefKey.followSystemTheme);
bool isFollowSystemThemeOr(bool def) => isFollowSystemTheme() ?? def;
Future<bool> setFollowSystemTheme(bool value) => _set<bool>(
PrefKey.followSystemTheme,
value,
(key, value) => provider.setBool(key, value));
bool? isUseBlackInDarkTheme() =>
provider.getBool(PrefKey.useBlackInDarkTheme);
bool isUseBlackInDarkThemeOr(bool def) => isUseBlackInDarkTheme() ?? def;
Future<bool> setUseBlackInDarkTheme(bool value) => _set<bool>(
PrefKey.useBlackInDarkTheme,
value,
(key, value) => provider.setBool(key, value));
int? getLanguage() => provider.getInt(PrefKey.language);
int getLanguageOr(int def) => getLanguage() ?? def;
Future<bool> setLanguage(int value) => _set<int>(
PrefKey.language, value, (key, value) => provider.setInt(key, value));
int? getSlideshowDuration() => provider.getInt(PrefKey.slideshowDuration);
int getSlideshowDurationOr(int def) => getSlideshowDuration() ?? def;
Future<bool> setSlideshowDuration(int value) => _set<int>(
PrefKey.slideshowDuration,
value,
(key, value) => provider.setInt(key, value));
bool? isSlideshowShuffle() => provider.getBool(PrefKey.isSlideshowShuffle);
bool isSlideshowShuffleOr(bool def) => isSlideshowShuffle() ?? def;
Future<bool> setSlideshowShuffle(bool value) => _set<bool>(
PrefKey.isSlideshowShuffle,
value,
(key, value) => provider.setBool(key, value));
bool? isSlideshowRepeat() => provider.getBool(PrefKey.isSlideshowRepeat);
bool isSlideshowRepeatOr(bool def) => isSlideshowRepeat() ?? def;
Future<bool> setSlideshowRepeat(bool value) => _set<bool>(
PrefKey.isSlideshowRepeat,
value,
(key, value) => provider.setBool(key, value));
bool? isAlbumBrowserShowDate() =>
provider.getBool(PrefKey.isAlbumBrowserShowDate);
bool isAlbumBrowserShowDateOr([bool def = false]) =>
isAlbumBrowserShowDate() ?? def;
Future<bool> setAlbumBrowserShowDate(bool value) => _set<bool>(
PrefKey.isAlbumBrowserShowDate,
value,
(key, value) => provider.setBool(key, value));
int? getGpsMapProvider() => provider.getInt(PrefKey.gpsMapProvider);
int getGpsMapProviderOr(int def) => getGpsMapProvider() ?? def;
Future<bool> setGpsMapProvider(int value) => _set<int>(PrefKey.gpsMapProvider,
value, (key, value) => provider.setInt(key, value));
bool? hasShownSharedAlbumInfo() =>
provider.getBool(PrefKey.hasShownSharedAlbumInfo);
bool hasShownSharedAlbumInfoOr(bool def) => hasShownSharedAlbumInfo() ?? def;
Future<bool> setHasShownSharedAlbumInfo(bool value) => _set<bool>(
PrefKey.hasShownSharedAlbumInfo,
value,
(key, value) => provider.setBool(key, value));
int? getEnhanceMaxWidth() => provider.getInt(PrefKey.enhanceMaxWidth);
int getEnhanceMaxWidthOr([int def = 2048]) => getEnhanceMaxWidth() ?? def;
Future<bool> setEnhanceMaxWidth(int value) => _set<int>(
PrefKey.enhanceMaxWidth,
value,
(key, value) => provider.setInt(key, value));
int? getEnhanceMaxHeight() => provider.getInt(PrefKey.enhanceMaxHeight);
int getEnhanceMaxHeightOr([int def = 1536]) => getEnhanceMaxHeight() ?? def;
Future<bool> setEnhanceMaxHeight(int value) => _set<int>(
PrefKey.enhanceMaxHeight,
value,
(key, value) => provider.setInt(key, value));
bool? hasShownEnhanceInfo() => provider.getBool(PrefKey.hasShownEnhanceInfo);
bool hasShownEnhanceInfoOr([bool def = false]) =>
hasShownEnhanceInfo() ?? def;
Future<bool> setHasShownEnhanceInfo(bool value) => _set<bool>(
PrefKey.hasShownEnhanceInfo,
value,
(key, value) => provider.setBool(key, value));
int? getFirstRunTime() => provider.getInt(PrefKey.firstRunTime);
int getFirstRunTimeOr(int def) => getFirstRunTime() ?? def;
Future<bool> setFirstRunTime(int value) => _set<int>(
PrefKey.firstRunTime, value, (key, value) => provider.setInt(key, value));
bool? isPhotosTabSortByName() =>
provider.getBool(PrefKey.isPhotosTabSortByName);
bool isPhotosTabSortByNameOr([bool def = false]) =>
isPhotosTabSortByName() ?? def;
Future<bool> setPhotosTabSortByName(bool value) => _set<bool>(
PrefKey.isPhotosTabSortByName,
value,
(key, value) => provider.setBool(key, value));
bool? shouldProcessExifWifiOnly() =>
provider.getBool(PrefKey.shouldProcessExifWifiOnly);
bool shouldProcessExifWifiOnlyOr([bool def = true]) =>
shouldProcessExifWifiOnly() ?? def;
Future<bool> setProcessExifWifiOnly(bool value) => _set<bool>(
PrefKey.shouldProcessExifWifiOnly,
value,
(key, value) => provider.setBool(key, value));
bool? isDoubleTapExit() => provider.getBool(PrefKey.doubleTapExit);
bool isDoubleTapExitOr([bool def = false]) => isDoubleTapExit() ?? def;
Future<bool> setDoubleTapExit(bool value) => _set<bool>(PrefKey.doubleTapExit,
value, (key, value) => provider.setBool(key, value));
int? getMemoriesRange() => provider.getInt(PrefKey.memoriesRange);
int getMemoriesRangeOr([int def = 2]) => getMemoriesRange() ?? def;
Future<bool> setMemoriesRange(int value) => _set<int>(PrefKey.memoriesRange,
value, (key, value) => provider.setInt(key, value));
bool? isSaveEditResultToServer() =>
provider.getBool(PrefKey.saveEditResultToServer);
bool isSaveEditResultToServerOr([bool def = true]) =>
isSaveEditResultToServer() ?? def;
Future<bool> setSaveEditResultToServer(bool value) => _set<bool>(
PrefKey.saveEditResultToServer,
value,
(key, value) => provider.setBool(key, value));
bool? hasShownSaveEditResultDialog() =>
provider.getBool(PrefKey.hasShownSaveEditResultDialog);
bool hasShownSaveEditResultDialogOr([bool def = false]) =>
hasShownSaveEditResultDialog() ?? def;
Future<bool> setHasShownSaveEditResultDialog(bool value) => _set<bool>(
PrefKey.hasShownSaveEditResultDialog,
value,
(key, value) => provider.setBool(key, value));
bool? isSlideshowReverse() => provider.getBool(PrefKey.isSlideshowReverse);
bool isSlideshowReverseOr(bool def) => isSlideshowReverse() ?? def;
Future<bool> setSlideshowReverse(bool value) => _set<bool>(
PrefKey.isSlideshowReverse,
value,
(key, value) => provider.setBool(key, value));
int? getSeedColor() => provider.getInt(PrefKey.seedColor);
int getSeedColorOr(int def) => getSeedColor() ?? def;
Future<bool> setSeedColor(int value) => _set<int>(
PrefKey.seedColor, value, (key, value) => provider.setInt(key, value));
bool? isVideoPlayerMute() => provider.getBool(PrefKey.isVideoPlayerMute);
bool isVideoPlayerMuteOr([bool def = false]) => isVideoPlayerMute() ?? def;
Future<bool> setVideoPlayerMute(bool value) => _set<bool>(
PrefKey.isVideoPlayerMute,
value,
(key, value) => provider.setBool(key, value));
bool? isVideoPlayerLoop() => provider.getBool(PrefKey.isVideoPlayerLoop);
bool isVideoPlayerLoopOr([bool def = false]) => isVideoPlayerLoop() ?? def;
Future<bool> setVideoPlayerLoop(bool value) => _set<bool>(
PrefKey.isVideoPlayerLoop,
value,
(key, value) => provider.setBool(key, value));
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) {
KiwiContainer().resolve<EventBus>().fire(PrefUpdatedEvent(key, value));
return true;
} else {
return false;
}
}
Future<bool> _remove(PrefKey key) => provider.remove(key);
final PrefProvider provider;
static Pref? _inst;
}
class AccountPref {
AccountPref.scoped(this.provider);
static AccountPref of(Account account) {
_insts.putIfAbsent(
account.id, () => AccountPref.scoped(PrefMemoryProvider()));
return _insts[account.id]!;
}
/// Set the global [AccountPref] instance returned by the default constructor
static void setGlobalInstance(Account account, AccountPref? pref) {
if (pref != null) {
assert(!_insts.containsKey(account.id));
_insts[account.id] = pref;
} else {
assert(_insts.containsKey(account.id));
_insts.remove(account.id);
}
}
bool? isEnableFaceRecognitionApp() =>
provider.getBool(PrefKey.isEnableFaceRecognitionApp);
bool isEnableFaceRecognitionAppOr([bool def = true]) =>
isEnableFaceRecognitionApp() ?? def;
Future<bool> setEnableFaceRecognitionApp(bool value) => _set<bool>(
PrefKey.isEnableFaceRecognitionApp,
value,
(key, value) => provider.setBool(key, value));
String? getShareFolder() => provider.getString(PrefKey.shareFolder);
String getShareFolderOr([String def = ""]) => getShareFolder() ?? def;
Future<bool> setShareFolder(String value) => _set<String>(PrefKey.shareFolder,
value, (key, value) => provider.setString(key, value));
bool? hasNewSharedAlbum() => provider.getBool(PrefKey.hasNewSharedAlbum);
bool hasNewSharedAlbumOr([bool def = false]) => hasNewSharedAlbum() ?? def;
Future<bool> setNewSharedAlbum(bool value) => _set<bool>(
PrefKey.hasNewSharedAlbum,
value,
(key, value) => provider.setBool(key, value));
bool? isEnableMemoryAlbum() => provider.getBool(PrefKey.isEnableMemoryAlbum);
bool isEnableMemoryAlbumOr([bool def = false]) =>
isEnableMemoryAlbum() ?? def;
Future<bool> setEnableMemoryAlbum(bool value) => _set<bool>(
PrefKey.isEnableMemoryAlbum,
value,
(key, value) => provider.setBool(key, value));
String? getTouchRootEtag() => provider.getString(PrefKey.touchRootEtag);
String getTouchRootEtagOr([String def = ""]) => getTouchRootEtag() ?? def;
Future<bool> setTouchRootEtag(String value) => _set<String>(
PrefKey.touchRootEtag,
value,
(key, value) => provider.setString(key, value));
Future<bool> removeTouchRootEtag() => _remove(PrefKey.touchRootEtag);
String? getAccountLabel() => provider.getString(PrefKey.accountLabel);
String getAccountLabelOr([String def = ""]) => getAccountLabel() ?? def;
Future<bool> setAccountLabel(String? value) {
if (value == null) {
return _remove(PrefKey.accountLabel);
} else {
return _set<String>(PrefKey.accountLabel, value,
(key, value) => provider.setString(key, value));
}
}
int? getLastNewCollectionType() =>
provider.getInt(PrefKey.lastNewCollectionType);
int getLastNewCollectionTypeOr(int def) => getLastNewCollectionType() ?? def;
Future<bool> setLastNewCollectionType(int? value) {
if (value == null) {
return _remove(PrefKey.lastNewCollectionType);
} else {
return _set<int>(PrefKey.lastNewCollectionType, value,
(key, value) => provider.setInt(key, value));
}
}
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) {
KiwiContainer()
.resolve<EventBus>()
.fire(AccountPrefUpdatedEvent(this, key, value));
return true;
} else {
return false;
}
}
Future<bool> _remove(PrefKey key) => provider.remove(key);
final PrefProvider provider;
static final _insts = <String, AccountPref>{};
}
/// Provide the data for [Pref]
abstract class PrefProvider {
bool? getBool(PrefKey key);
Future<bool> setBool(PrefKey key, bool value);
int? getInt(PrefKey key);
Future<bool> setInt(PrefKey key, int value);
String? getString(PrefKey key);
Future<bool> setString(PrefKey key, String value);
List<String>? getStringList(PrefKey key);
Future<bool> setStringList(PrefKey key, List<String> value);
Future<bool> remove(PrefKey key);
Future<bool> clear();
}
/// [Pref] stored with [SharedPreferences] lib
class PrefSharedPreferencesProvider extends PrefProvider {
Future<void> init() async {
// Obsolete, CompatV34 is compatible with pre v32 versions
// if (await CompatV32.isPrefNeedMigration()) {
// await CompatV32.migratePref();
// }
if (await CompatV34.isPrefNeedMigration()) {
await CompatV34.migratePref(platform.UniversalStorage());
}
return SharedPreferences.getInstance().then((pref) {
_pref = pref;
});
}
@override
getBool(PrefKey key) => _pref.getBool(key.toStringKey());
@override
setBool(PrefKey key, bool value) => _pref.setBool(key.toStringKey(), value);
@override
getInt(PrefKey key) => _pref.getInt(key.toStringKey());
@override
setInt(PrefKey key, int value) => _pref.setInt(key.toStringKey(), value);
@override
getString(PrefKey key) => _pref.getString(key.toStringKey());
@override
setString(PrefKey key, String value) =>
_pref.setString(key.toStringKey(), value);
@override
getStringList(PrefKey key) => _pref.getStringList(key.toStringKey());
@override
setStringList(PrefKey key, List<String> value) =>
_pref.setStringList(key.toStringKey(), value);
@override
remove(PrefKey key) => _pref.remove(key.toStringKey());
@override
clear() => _pref.clear();
late SharedPreferences _pref;
}
/// [Pref] backed by [UniversalStorage]
class PrefUniversalStorageProvider extends PrefProvider {
PrefUniversalStorageProvider(this.name);
Future<void> init() async {
final prefStr = await platform.UniversalStorage().getString(name) ?? "{}";
_data
..clear()
..addAll(jsonDecode(prefStr));
}
@override
getBool(PrefKey key) => _get<bool>(key);
@override
setBool(PrefKey key, bool value) => _set(key, value);
@override
getInt(PrefKey key) => _get<int>(key);
@override
setInt(PrefKey key, int value) => _set(key, value);
@override
getString(PrefKey key) => _get<String>(key);
@override
setString(PrefKey key, String value) => _set(key, value);
@override
getStringList(PrefKey key) => _get<List<String>>(key);
@override
setStringList(PrefKey key, List<String> value) => _set(key, value);
@override
remove(PrefKey key) async {
final newData = Map.of(_data)..remove(key.toStringKey());
await platform.UniversalStorage().putString(name, jsonEncode(newData));
_data.remove(key.toStringKey());
return true;
}
@override
clear() async {
await platform.UniversalStorage().remove(name);
_data.clear();
return true;
}
T? _get<T>(PrefKey key) => _data[key.toStringKey()];
Future<bool> _set<T>(PrefKey key, T value) async {
final newData = Map.of(_data)
..addEntries([MapEntry(key.toStringKey(), value)]);
await platform.UniversalStorage().putString(name, jsonEncode(newData));
_data[key.toStringKey()] = value;
return true;
}
final String name;
final _data = <String, dynamic>{};
}
/// [Pref] stored in memory, useful in unit tests
class PrefMemoryProvider extends PrefProvider {
PrefMemoryProvider([
Map<String, dynamic> initialData = const <String, dynamic>{},
]) : _data = Map.of(initialData);
@override
getBool(PrefKey key) => _get<bool>(key);
@override
setBool(PrefKey key, bool value) => _set(key, value);
@override
getInt(PrefKey key) => _get<int>(key);
@override
setInt(PrefKey key, int value) => _set(key, value);
@override
getString(PrefKey key) => _get<String>(key);
@override
setString(PrefKey key, String value) => _set(key, value);
@override
getStringList(PrefKey key) => _get<List<String>>(key);
@override
setStringList(PrefKey key, List<String> value) => _set(key, value);
@override
remove(PrefKey key) async {
_data.remove(key);
return true;
}
@override
clear() async {
_data.clear();
return true;
}
T? _get<T>(PrefKey key) => _data[key.toStringKey()];
Future<bool> _set<T>(PrefKey key, T value) async {
_data[key.toStringKey()] = value;
return true;
}
final Map<String, dynamic> _data;
}
enum PrefKey {
accounts3,
currentAccountIndex,
homePhotosZoomLevel,
albumBrowserZoomLevel,
homeAlbumsSort,
enableExif,
viewerScreenBrightness,
viewerForceRotation,
setupProgress,
lastVersion,
darkTheme,
followSystemTheme,
useBlackInDarkTheme,
language,
labEnableSharedAlbum,
slideshowDuration,
isSlideshowShuffle,
isSlideshowRepeat,
isAlbumBrowserShowDate,
gpsMapProvider,
hasShownSharedAlbumInfo,
enhanceMaxWidth,
enhanceMaxHeight,
hasShownEnhanceInfo,
firstRunTime,
isPhotosTabSortByName,
shouldProcessExifWifiOnly,
doubleTapExit,
memoriesRange,
saveEditResultToServer,
hasShownSaveEditResultDialog,
isSlideshowReverse,
seedColor,
isVideoPlayerMute,
isVideoPlayerLoop,
// account pref
isEnableFaceRecognitionApp,
shareFolder,
hasNewSharedAlbum,
isEnableMemoryAlbum,
touchRootEtag,
accountLabel,
lastNewCollectionType,
}
extension on PrefKey {
String toStringKey() {
switch (this) {
case PrefKey.accounts3:
return "accounts3";
case PrefKey.currentAccountIndex:
return "currentAccountIndex";
case PrefKey.homePhotosZoomLevel:
return "homePhotosZoomLevel";
case PrefKey.albumBrowserZoomLevel:
return "albumViewerZoomLevel";
case PrefKey.homeAlbumsSort:
return "homeAlbumsSort";
case PrefKey.enableExif:
return "isEnableExif";
case PrefKey.viewerScreenBrightness:
return "viewerScreenBrightness";
case PrefKey.viewerForceRotation:
return "viewerForceRotation";
case PrefKey.setupProgress:
return "setupProgress";
case PrefKey.lastVersion:
return "lastVersion";
case PrefKey.darkTheme:
return "isDarkTheme";
case PrefKey.followSystemTheme:
return "isFollowSystemTheme";
case PrefKey.useBlackInDarkTheme:
return "isUseBlackInDarkTheme";
case PrefKey.language:
return "language";
case PrefKey.labEnableSharedAlbum:
return "isLabEnableSharedAlbum";
case PrefKey.slideshowDuration:
return "slideshowDuration";
case PrefKey.isSlideshowShuffle:
return "isSlideshowShuffle";
case PrefKey.isSlideshowRepeat:
return "isSlideshowRepeat";
case PrefKey.isAlbumBrowserShowDate:
return "isAlbumBrowserShowDate";
case PrefKey.gpsMapProvider:
return "gpsMapProvider";
case PrefKey.hasShownSharedAlbumInfo:
return "hasShownSharedAlbumInfo";
case PrefKey.enhanceMaxWidth:
return "enhanceMaxWidth";
case PrefKey.enhanceMaxHeight:
return "enhanceMaxHeight";
case PrefKey.hasShownEnhanceInfo:
return "hasShownEnhanceInfo";
case PrefKey.firstRunTime:
return "firstRunTime";
case PrefKey.isPhotosTabSortByName:
return "isPhotosTabSortByName";
case PrefKey.shouldProcessExifWifiOnly:
return "shouldProcessExifWifiOnly";
case PrefKey.doubleTapExit:
return "doubleTapExit";
case PrefKey.memoriesRange:
return "memoriesRange";
case PrefKey.saveEditResultToServer:
return "saveEditResultToServer";
case PrefKey.hasShownSaveEditResultDialog:
return "hasShownSaveEditResultDialog";
case PrefKey.isSlideshowReverse:
return "isSlideshowReverse";
case PrefKey.seedColor:
return "seedColor";
case PrefKey.isVideoPlayerMute:
return "isVideoPlayerMute";
case PrefKey.isVideoPlayerLoop:
return "isVideoPlayerLoop";
// account pref
case PrefKey.isEnableFaceRecognitionApp:
return "isEnableFaceRecognitionApp";
case PrefKey.shareFolder:
return "shareFolder";
case PrefKey.hasNewSharedAlbum:
return "hasNewSharedAlbum";
case PrefKey.isEnableMemoryAlbum:
return "isEnableMemoryAlbum";
case PrefKey.touchRootEtag:
return "touchRootEtag";
case PrefKey.accountLabel:
return "accountLabel";
case PrefKey.lastNewCollectionType:
return "lastNewCollectionType";
}
}
}
extension PrefExtension on Pref {
Account? getCurrentAccount() {
try {
return Pref().getAccounts3()![Pref().getCurrentAccountIndex()!];
} catch (_) {
return null;
}
}
}

View file

@ -15,11 +15,11 @@ import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/event/native_event.dart';
import 'package:nc_photos/future_extension.dart';
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/reverse_geocoder.dart';
import 'package:nc_photos/use_case/update_missing_metadata.dart';
import 'package:nc_photos_plugin/nc_photos_plugin.dart';

View file

@ -1,8 +1,8 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/material3.dart';
import 'package:nc_photos/pref.dart';
extension ThemeExtension on ThemeData {
double get widthLimitedContentMaxWidth => 550.0;

View file

@ -1,6 +1,6 @@
import 'package:logging/logging.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/pref.dart';
import 'package:np_codegen/np_codegen.dart';
part 'v46.g.dart';

View file

@ -3,7 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/use_case/list_potential_shared_album.dart';
import 'package:nc_photos/use_case/move.dart';

View file

@ -4,7 +4,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/use_case/ls.dart';
import 'package:np_codegen/np_codegen.dart';

View file

@ -3,7 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/use_case/cache_favorite.dart';
import 'package:np_codegen/np_codegen.dart';

View file

@ -16,6 +16,7 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc_util.dart';
import 'package:nc_photos/controller/account_controller.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/server_status.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/event/event.dart';
@ -23,7 +24,6 @@ import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/toast.dart';
import 'package:nc_photos/url_launcher_util.dart';

View file

@ -12,11 +12,11 @@ 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/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
import 'package:nc_photos/use_case/update_property.dart';

View file

@ -32,6 +32,7 @@ import 'package:nc_photos/entity/collection_item/sorter.dart';
import 'package:nc_photos/entity/collection_item/util.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/flutter_util.dart' as flutter_util;

View file

@ -9,6 +9,7 @@ import 'package:nc_photos/compute_queue.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/local_file.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k;
@ -16,7 +17,6 @@ import 'package:nc_photos/mobile/android/android_info.dart';
import 'package:nc_photos/mobile/android/permission_util.dart';
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/share_handler.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/widget/empty_list_indicator.dart';

View file

@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:nc_photos/app_init.dart' as app_init;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/url_launcher_util.dart';
import 'package:tuple/tuple.dart';

View file

@ -1,8 +1,8 @@
import 'package:clock/clock.dart';
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
class DoubleTapExitHandler {

View file

@ -13,9 +13,9 @@ import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/album/data_source.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/import_potential_shared_album.dart';
import 'package:nc_photos/widget/home_collections.dart';

View file

@ -19,12 +19,12 @@ import 'package:nc_photos/entity/collection.dart';
import 'package:nc_photos/entity/collection/content_provider/album.dart';
import 'package:nc_photos/entity/collection/content_provider/nc_album.dart';
import 'package:nc_photos/entity/collection/util.dart' as collection_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';
import 'package:nc_photos/platform/features.dart' as features;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/widget/album_importer.dart';

View file

@ -20,6 +20,7 @@ import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/download_handler.dart';
import 'package:nc_photos/entity/collection.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/event/native_event.dart';
@ -29,7 +30,6 @@ import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/metadata_task_manager.dart';
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/primitive.dart';
import 'package:nc_photos/service.dart' as service;
import 'package:nc_photos/share_handler.dart';

View file

@ -13,12 +13,12 @@ import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/download_handler.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/search.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/share_handler.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';

View file

@ -9,6 +9,7 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/cache_manager_util.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/material3.dart';

View file

@ -5,6 +5,7 @@ import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';

View file

@ -12,6 +12,7 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/help_utils.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/android/android_info.dart';

View file

@ -7,12 +7,12 @@ import 'package:logging/logging.dart';
import 'package:nc_photos/controller/account_controller.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/legacy/connect.dart' as legacy;
import 'package:nc_photos/legacy/sign_in.dart' as legacy;
import 'package:nc_photos/navigation_manager.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/stream_util.dart';
import 'package:nc_photos/theme.dart';

View file

@ -17,13 +17,13 @@ import 'package:nc_photos/entity/collection/content_provider/album.dart';
import 'package:nc_photos/entity/collection/content_provider/nc_album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/nc_album.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/tag.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/help_utils.dart' as help_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/toast.dart';
import 'package:nc_photos/url_launcher_util.dart';
import 'package:nc_photos/widget/album_dir_picker.dart';

View file

@ -5,9 +5,9 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as 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/ls_single_file.dart';

View file

@ -7,6 +7,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/debug_util.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
@ -15,7 +16,6 @@ import 'package:nc_photos/mobile/platform.dart'
import 'package:nc_photos/platform/features.dart' as features;
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/platform/notification.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/service.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/stream_util.dart';

View file

@ -10,6 +10,7 @@ import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/controller/account_controller.dart';
import 'package:nc_photos/controller/account_pref_controller.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;

View file

@ -7,6 +7,7 @@ import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/sqlite/database.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;

View file

@ -9,6 +9,7 @@ import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/android/android_info.dart';

View file

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/widget/home.dart';
import 'package:nc_photos/widget/sign_in.dart';
import 'package:page_view_indicators/circle_page_indicator.dart';

View file

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/help_utils.dart' as help_utils;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/url_launcher_util.dart';
class SharedAlbumInfoDialog extends StatefulWidget {

View file

@ -13,12 +13,12 @@ import 'package:nc_photos/entity/album/data_source.dart';
import 'package:nc_photos/entity/collection/builder.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/import_potential_shared_album.dart';
import 'package:nc_photos/widget/collection_browser.dart';

View file

@ -7,11 +7,11 @@ import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref_util.dart' as pref_util;
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/legacy/sign_in.dart' as legacy;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/pref_util.dart' as pref_util;
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/widget/connect.dart';
import 'package:nc_photos/widget/home.dart';

View file

@ -7,11 +7,11 @@ import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/mobile/android/activity.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/use_case/compat/v29.dart';
import 'package:nc_photos/use_case/compat/v46.dart';
import 'package:nc_photos/use_case/compat/v55.dart';

View file

@ -13,11 +13,11 @@ 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/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/language_util.dart' as language_util;
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/use_case/inflate_file_descriptor.dart';
import 'package:nc_photos/use_case/restore_trashbin.dart';

View file

@ -8,6 +8,7 @@ import 'package:nc_photos/api/api_util.dart' as api_util;
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/np_api_util.dart';

View file

@ -19,12 +19,12 @@ import 'package:nc_photos/entity/collection/adapter.dart';
import 'package:nc_photos/entity/collection_item.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/flutter_util.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/notified_action.dart';
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/platform/features.dart' as features;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/share_handler.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';

View file

@ -4,8 +4,8 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:logging/logging.dart';
import 'package:native_device_orientation/native_device_orientation.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/throttler.dart';
import 'package:nc_photos/widget/disposable.dart';
import 'package:np_codegen/np_codegen.dart';

View file

@ -8,8 +8,9 @@ import 'package:nc_photos/entity/album/item.dart';
import 'package:nc_photos/entity/album/provider.dart';
import 'package:nc_photos/entity/album/sort_provider.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref/provider/memory.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/use_case/album/add_file_to_album.dart';
import 'package:np_common/ci_string.dart';
import 'package:test/test.dart';

View file

@ -1,8 +1,9 @@
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref/provider/memory.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/use_case/album/remove_album.dart';
import 'package:test/test.dart';

View file

@ -5,9 +5,10 @@ import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/album/cover_provider.dart';
import 'package:nc_photos/entity/album/provider.dart';
import 'package:nc_photos/entity/album/sort_provider.dart';
import 'package:nc_photos/entity/pref.dart';
import 'package:nc_photos/entity/pref/provider/memory.dart';
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
import 'package:nc_photos/or_null.dart';
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/use_case/remove.dart';
import 'package:test/test.dart';