nc-photos/app/lib/pref.dart

606 lines
20 KiB
Dart
Raw Normal View History

import 'dart:async';
2021-04-10 06:28:12 +02:00
import 'dart:convert';
2021-09-11 14:03:40 +02:00
import 'package:event_bus/event_bus.dart';
import 'package:kiwi/kiwi.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/account.dart';
2021-09-11 14:03:40 +02:00
import 'package:nc_photos/event/event.dart';
2021-12-05 13:02:22 +01:00
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';
2021-04-10 06:28:12 +02:00
import 'package:shared_preferences/shared_preferences.dart';
class Pref {
factory Pref() {
_inst ??= Pref.scoped(PrefMemoryProvider());
return _inst!;
}
2021-10-27 22:40:54 +02:00
Pref.scoped(this.provider);
2021-10-27 22:40:54 +02:00
/// Set the global [Pref] instance returned by the default constructor
static void setGlobalInstance(Pref pref) {
assert(_inst == null);
_inst = pref;
2021-04-10 06:28:12 +02:00
}
2021-12-05 13:02:22 +01:00
List<Account>? getAccounts3() {
final jsonObjs = provider.getStringList(PrefKey.accounts3);
return jsonObjs?.map((e) => Account.fromJson(jsonDecode(e))).toList();
2021-04-10 06:28:12 +02:00
}
2021-12-05 13:02:22 +01:00
List<Account> getAccounts3Or(List<Account> def) => getAccounts3() ?? def;
Future<bool> setAccounts3(List<Account> value) {
2021-04-10 06:28:12 +02:00
final jsons = value.map((e) => jsonEncode(e.toJson())).toList();
2021-12-05 13:02:22 +01:00
return provider.setStringList(PrefKey.accounts3, jsons);
2021-04-10 06:28:12 +02:00
}
int? getCurrentAccountIndex() => provider.getInt(PrefKey.currentAccountIndex);
2021-07-23 22:05:57 +02:00
int getCurrentAccountIndexOr(int def) => getCurrentAccountIndex() ?? def;
Future<bool> setCurrentAccountIndex(int value) => _set<int>(
PrefKey.currentAccountIndex,
value,
(key, value) => provider.setInt(key, value));
2021-04-10 06:28:12 +02:00
int? getHomePhotosZoomLevel() => provider.getInt(PrefKey.homePhotosZoomLevel);
2021-07-23 22:05:57 +02:00
int getHomePhotosZoomLevelOr(int def) => getHomePhotosZoomLevel() ?? def;
Future<bool> setHomePhotosZoomLevel(int value) => _set<int>(
PrefKey.homePhotosZoomLevel,
value,
(key, value) => provider.setInt(key, value));
2021-04-10 06:28:12 +02:00
2021-09-11 14:03:40 +02:00
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));
2021-04-10 06:28:12 +02:00
int? getHomeAlbumsSort() => provider.getInt(PrefKey.homeAlbumsSort);
2021-09-08 18:23:42 +02:00
int getHomeAlbumsSortOr(int def) => getHomeAlbumsSort() ?? def;
Future<bool> setHomeAlbumsSort(int value) => _set<int>(PrefKey.homeAlbumsSort,
value, (key, value) => provider.setInt(key, value));
2021-09-08 18:23:42 +02:00
bool? isEnableExif() => provider.getBool(PrefKey.enableExif);
2021-07-23 22:05:57 +02:00
bool isEnableExifOr([bool def = true]) => isEnableExif() ?? def;
Future<bool> setEnableExif(bool value) => _set<bool>(
PrefKey.enableExif, value, (key, value) => provider.setBool(key, value));
2021-04-10 06:28:12 +02:00
2021-09-11 14:03:40 +02:00
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));
2021-09-11 14:03:40 +02:00
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);
2021-07-23 22:05:57 +02:00
int getSetupProgressOr([int def = 0]) => getSetupProgress() ?? def;
Future<bool> setSetupProgress(int value) => _set<int>(PrefKey.setupProgress,
value, (key, value) => provider.setInt(key, value));
2021-04-10 06:28:12 +02:00
2021-04-16 10:45:17 +02:00
/// Return the version number when the app last ran
int? getLastVersion() => provider.getInt(PrefKey.lastVersion);
2021-07-23 22:05:57 +02:00
int getLastVersionOr(int def) => getLastVersion() ?? def;
Future<bool> setLastVersion(int value) => _set<int>(
PrefKey.lastVersion, value, (key, value) => provider.setInt(key, value));
2021-04-16 10:45:17 +02:00
bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme);
2021-07-23 22:05:57 +02:00
bool isDarkThemeOr(bool def) => isDarkTheme() ?? def;
Future<bool> setDarkTheme(bool value) => _set<bool>(
PrefKey.darkTheme, value, (key, value) => provider.setBool(key, value));
2021-04-17 11:04:46 +02:00
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));
2021-09-11 14:03:40 +02:00
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);
2021-07-23 22:05:57 +02:00
int getLanguageOr(int def) => getLanguage() ?? def;
Future<bool> setLanguage(int value) => _set<int>(
PrefKey.language, value, (key, value) => provider.setInt(key, value));
2021-06-23 10:15:25 +02:00
int? getSlideshowDuration() => provider.getInt(PrefKey.slideshowDuration);
2021-09-14 23:00:24 +02:00
int getSlideshowDurationOr(int def) => getSlideshowDuration() ?? def;
Future<bool> setSlideshowDuration(int value) => _set<int>(
PrefKey.slideshowDuration,
value,
(key, value) => provider.setInt(key, value));
2021-09-14 23:00:24 +02:00
bool? isSlideshowShuffle() => provider.getBool(PrefKey.isSlideshowShuffle);
2021-09-14 23:00:24 +02:00
bool isSlideshowShuffleOr(bool def) => isSlideshowShuffle() ?? def;
Future<bool> setSlideshowShuffle(bool value) => _set<bool>(
PrefKey.isSlideshowShuffle,
value,
(key, value) => provider.setBool(key, value));
2021-09-14 23:00:24 +02:00
bool? isSlideshowRepeat() => provider.getBool(PrefKey.isSlideshowRepeat);
2021-09-14 23:00:24 +02:00
bool isSlideshowRepeatOr(bool def) => isSlideshowRepeat() ?? def;
Future<bool> setSlideshowRepeat(bool value) => _set<bool>(
PrefKey.isSlideshowRepeat,
value,
(key, value) => provider.setBool(key, value));
2021-09-14 23:00:24 +02:00
2021-10-04 15:53:03 +02:00
bool? isAlbumBrowserShowDate() =>
provider.getBool(PrefKey.isAlbumBrowserShowDate);
2021-10-04 15:53:03 +02:00
bool isAlbumBrowserShowDateOr([bool def = false]) =>
isAlbumBrowserShowDate() ?? def;
Future<bool> setAlbumBrowserShowDate(bool value) => _set<bool>(
PrefKey.isAlbumBrowserShowDate,
value,
(key, value) => provider.setBool(key, value));
2021-10-04 15:53:03 +02:00
2021-11-17 15:41:11 +01:00
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));
2021-11-17 15:41:11 +01:00
2021-09-11 14:03:40 +02:00
bool? isLabEnableSharedAlbum() =>
provider.getBool(PrefKey.labEnableSharedAlbum);
2021-08-08 20:46:16 +02:00
bool isLabEnableSharedAlbumOr(bool def) => isLabEnableSharedAlbum() ?? def;
Future<bool> setLabEnableSharedAlbum(bool value) => _set<bool>(
PrefKey.labEnableSharedAlbum,
value,
(key, value) => provider.setBool(key, value));
2021-08-08 20:46:16 +02:00
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);
2022-05-17 13:40:45 +02:00
bool hasShownEnhanceInfoOr([bool def = false]) =>
hasShownEnhanceInfo() ?? def;
Future<bool> setHasShownEnhanceInfo(bool value) => _set<bool>(
PrefKey.hasShownEnhanceInfo,
value,
(key, value) => provider.setBool(key, value));
2022-05-17 13:32:19 +02:00
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));
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;
}
}
final PrefProvider provider;
2021-09-11 14:03:40 +02:00
static Pref? _inst;
}
2021-09-11 14:03:40 +02:00
2021-12-05 13:02:22 +01:00
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));
2021-12-05 13:02:22 +01:00
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));
2021-12-05 13:02:22 +01:00
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));
2022-01-15 15:21:22 +01:00
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));
2022-01-20 06:23:49 +01:00
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);
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;
}
}
2022-01-20 06:23:49 +01:00
Future<bool> _remove(PrefKey key) => provider.remove(key);
2021-12-05 13:02:22 +01:00
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);
2021-12-05 13:02:22 +01:00
String? getString(PrefKey key);
Future<bool> setString(PrefKey key, String value);
List<String>? getStringList(PrefKey key);
Future<bool> setStringList(PrefKey key, List<String> value);
2021-09-11 14:03:40 +02:00
2022-01-20 06:23:49 +01:00
Future<bool> remove(PrefKey key);
2021-12-05 13:02:22 +01:00
Future<bool> clear();
}
2021-09-11 14:03:40 +02:00
/// [Pref] stored with [SharedPreferences] lib
class PrefSharedPreferencesProvider extends PrefProvider {
Future<void> init() async {
2021-12-05 13:02:22 +01:00
// Obsolete, CompatV34 is compatible with pre v32 versions
// if (await CompatV32.isPrefNeedMigration()) {
// await CompatV32.migratePref();
// }
if (await CompatV34.isPrefNeedMigration()) {
await CompatV34.migratePref(platform.UniversalStorage());
2021-09-11 14:03:40 +02:00
}
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);
2021-12-05 13:02:22 +01:00
@override
getString(PrefKey key) => _pref.getString(key.toStringKey());
@override
setString(PrefKey key, String value) =>
_pref.setString(key.toStringKey(), value);
2021-12-05 13:02:22 +01:00
@override
getStringList(PrefKey key) => _pref.getStringList(key.toStringKey());
@override
setStringList(PrefKey key, List<String> value) =>
_pref.setStringList(key.toStringKey(), value);
2021-09-11 14:03:40 +02:00
2022-01-20 06:23:49 +01:00
@override
remove(PrefKey key) => _pref.remove(key.toStringKey());
2021-12-05 13:02:22 +01:00
@override
clear() => _pref.clear();
2021-07-23 22:05:57 +02:00
late SharedPreferences _pref;
2021-04-10 06:28:12 +02:00
}
2021-12-05 13:02:22 +01:00
/// [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);
2022-01-20 06:23:49 +01:00
@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;
}
2021-12-05 13:02:22 +01:00
@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
2021-12-05 13:02:22 +01:00
getBool(PrefKey key) => _get<bool>(key);
@override
2021-12-05 13:02:22 +01:00
setBool(PrefKey key, bool value) => _set(key, value);
@override
2021-12-05 13:02:22 +01:00
getInt(PrefKey key) => _get<int>(key);
@override
setInt(PrefKey key, int value) => _set(key, value);
@override
2021-12-05 13:02:22 +01:00
getString(PrefKey key) => _get<String>(key);
@override
setString(PrefKey key, String value) => _set(key, value);
@override
2021-12-05 13:02:22 +01:00
getStringList(PrefKey key) => _get<List<String>>(key);
@override
setStringList(PrefKey key, List<String> value) => _set(key, value);
2022-01-20 06:23:49 +01:00
@override
remove(PrefKey key) async {
_data.remove(key);
return true;
}
@override
2021-12-05 13:02:22 +01:00
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;
}
2021-09-11 14:03:40 +02:00
enum PrefKey {
2021-12-05 13:02:22 +01:00
accounts3,
2021-09-11 14:03:40 +02:00
currentAccountIndex,
homePhotosZoomLevel,
albumBrowserZoomLevel,
homeAlbumsSort,
enableExif,
viewerScreenBrightness,
viewerForceRotation,
setupProgress,
lastVersion,
darkTheme,
followSystemTheme,
useBlackInDarkTheme,
language,
labEnableSharedAlbum,
2021-09-14 23:00:24 +02:00
slideshowDuration,
isSlideshowShuffle,
isSlideshowRepeat,
2021-10-04 15:53:03 +02:00
isAlbumBrowserShowDate,
2021-11-17 15:41:11 +01:00
gpsMapProvider,
hasShownSharedAlbumInfo,
enhanceMaxWidth,
enhanceMaxHeight,
hasShownEnhanceInfo,
2022-05-17 13:32:19 +02:00
firstRunTime,
isPhotosTabSortByName,
shouldProcessExifWifiOnly,
2021-12-05 13:02:22 +01:00
// account pref
isEnableFaceRecognitionApp,
shareFolder,
hasNewSharedAlbum,
2022-01-15 15:21:22 +01:00
isEnableMemoryAlbum,
2022-01-20 06:23:49 +01:00
touchRootEtag,
2021-09-11 14:03:40 +02:00
}
extension on PrefKey {
String toStringKey() {
switch (this) {
2021-12-05 13:02:22 +01:00
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";
2021-11-17 15:41:11 +01:00
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";
2022-05-17 13:32:19 +02:00
case PrefKey.firstRunTime:
return "firstRunTime";
case PrefKey.isPhotosTabSortByName:
return "isPhotosTabSortByName";
case PrefKey.shouldProcessExifWifiOnly:
return "shouldProcessExifWifiOnly";
2021-12-05 13:02:22 +01:00
// account pref
case PrefKey.isEnableFaceRecognitionApp:
return "isEnableFaceRecognitionApp";
case PrefKey.shareFolder:
return "shareFolder";
case PrefKey.hasNewSharedAlbum:
return "hasNewSharedAlbum";
2022-01-15 15:21:22 +01:00
case PrefKey.isEnableMemoryAlbum:
return "isEnableMemoryAlbum";
2022-01-20 06:23:49 +01:00
case PrefKey.touchRootEtag:
return "touchRootEtag";
}
}
}
2021-04-10 06:28:12 +02:00
extension PrefExtension on Pref {
2021-07-23 22:05:57 +02:00
Account? getCurrentAccount() {
2021-04-10 06:28:12 +02:00
try {
2021-12-05 13:02:22 +01:00
return Pref().getAccounts3()![Pref().getCurrentAccountIndex()!];
2021-04-10 06:28:12 +02:00
} catch (_) {
return null;
}
}
}