mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Refactor: hide some migrated pref accessors
This commit is contained in:
parent
68b4273bfa
commit
0b766723d8
3 changed files with 85 additions and 105 deletions
|
@ -16,6 +16,7 @@ import 'package:np_string/np_string.dart';
|
|||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
part 'pref_controller.g.dart';
|
||||
part 'pref_controller/util.dart';
|
||||
|
||||
@npSubjectAccessor
|
||||
class PrefController {
|
||||
|
|
84
app/lib/controller/pref_controller/util.dart
Normal file
84
app/lib/controller/pref_controller/util.dart
Normal file
|
@ -0,0 +1,84 @@
|
|||
part of '../pref_controller.dart';
|
||||
|
||||
extension on Pref {
|
||||
int? getHomeAlbumsSort() => provider.getInt(PrefKey.homeAlbumsSort);
|
||||
int getHomeAlbumsSortOr(int def) => getHomeAlbumsSort() ?? def;
|
||||
Future<bool> setHomeAlbumsSort(int value) =>
|
||||
provider.setInt(PrefKey.homeAlbumsSort, value);
|
||||
|
||||
bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme);
|
||||
bool isDarkThemeOr(bool def) => isDarkTheme() ?? def;
|
||||
Future<bool> setDarkTheme(bool value) =>
|
||||
provider.setBool(PrefKey.darkTheme, value);
|
||||
|
||||
bool? isFollowSystemTheme() => provider.getBool(PrefKey.followSystemTheme);
|
||||
bool isFollowSystemThemeOr(bool def) => isFollowSystemTheme() ?? def;
|
||||
Future<bool> setFollowSystemTheme(bool value) =>
|
||||
provider.setBool(PrefKey.followSystemTheme, value);
|
||||
|
||||
bool? isUseBlackInDarkTheme() =>
|
||||
provider.getBool(PrefKey.useBlackInDarkTheme);
|
||||
bool isUseBlackInDarkThemeOr(bool def) => isUseBlackInDarkTheme() ?? def;
|
||||
Future<bool> setUseBlackInDarkTheme(bool value) =>
|
||||
provider.setBool(PrefKey.useBlackInDarkTheme, value);
|
||||
|
||||
int? getGpsMapProvider() => provider.getInt(PrefKey.gpsMapProvider);
|
||||
int getGpsMapProviderOr(int def) => getGpsMapProvider() ?? def;
|
||||
Future<bool> setGpsMapProvider(int value) =>
|
||||
provider.setInt(PrefKey.gpsMapProvider, value);
|
||||
|
||||
int? getSeedColor() => provider.getInt(PrefKey.seedColor);
|
||||
// int getSeedColorOr(int def) => getSeedColor() ?? def;
|
||||
Future<bool> setSeedColor(int? value) {
|
||||
if (value == null) {
|
||||
return provider.remove(PrefKey.seedColor);
|
||||
} else {
|
||||
return provider.setInt(PrefKey.seedColor, value);
|
||||
}
|
||||
}
|
||||
|
||||
int? getSecondarySeedColor() => provider.getInt(PrefKey.secondarySeedColor);
|
||||
// int getSecondarySeedColorOr(int def) => getSecondarySeedColor() ?? def;
|
||||
Future<bool> setSecondarySeedColor(int? value) {
|
||||
if (value == null) {
|
||||
return provider.remove(PrefKey.secondarySeedColor);
|
||||
} else {
|
||||
return provider.setInt(PrefKey.secondarySeedColor, value);
|
||||
}
|
||||
}
|
||||
|
||||
int? getProtectedPageAuthType() =>
|
||||
provider.getInt(PrefKey.protectedPageAuthType);
|
||||
// int getProtectedPageAuthTypeOr(int def) => getProtectedPageAuthType() ?? def;
|
||||
Future<bool> setProtectedPageAuthType(int? value) {
|
||||
if (value == null) {
|
||||
return provider.remove(PrefKey.protectedPageAuthType);
|
||||
} else {
|
||||
return provider.setInt(PrefKey.protectedPageAuthType, value);
|
||||
}
|
||||
}
|
||||
|
||||
String? getProtectedPageAuthPin() =>
|
||||
provider.getString(PrefKey.protectedPageAuthPin);
|
||||
// String getProtectedPageAuthPinOr(String def) =>
|
||||
// getProtectedPageAuthPin() ?? def;
|
||||
Future<bool> setProtectedPageAuthPin(String? value) {
|
||||
if (value == null) {
|
||||
return provider.remove(PrefKey.protectedPageAuthPin);
|
||||
} else {
|
||||
return provider.setString(PrefKey.protectedPageAuthPin, value);
|
||||
}
|
||||
}
|
||||
|
||||
String? getProtectedPageAuthPassword() =>
|
||||
provider.getString(PrefKey.protectedPageAuthPassword);
|
||||
// String getProtectedPageAuthPasswordOr(String def) =>
|
||||
// getProtectedPageAuthPassword() ?? def;
|
||||
Future<bool> setProtectedPageAuthPassword(String? value) {
|
||||
if (value == null) {
|
||||
return provider.remove(PrefKey.protectedPageAuthPassword);
|
||||
} else {
|
||||
return provider.setString(PrefKey.protectedPageAuthPassword, value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,11 +62,6 @@ extension PrefExtension on Pref {
|
|||
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>(
|
||||
|
@ -101,35 +96,6 @@ extension PrefExtension on Pref {
|
|||
Future<bool> setLastVersion(int value) => _set<int>(
|
||||
PrefKey.lastVersion, value, (key, value) => provider.setInt(key, value));
|
||||
|
||||
@Deprecated("Use PrefController")
|
||||
bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme);
|
||||
@Deprecated("Use PrefController")
|
||||
bool isDarkThemeOr(bool def) => isDarkTheme() ?? def;
|
||||
@Deprecated("Use PrefController")
|
||||
Future<bool> setDarkTheme(bool value) => _set<bool>(
|
||||
PrefKey.darkTheme, value, (key, value) => provider.setBool(key, value));
|
||||
|
||||
@Deprecated("Use PrefController")
|
||||
bool? isFollowSystemTheme() => provider.getBool(PrefKey.followSystemTheme);
|
||||
@Deprecated("Use PrefController")
|
||||
bool isFollowSystemThemeOr(bool def) => isFollowSystemTheme() ?? def;
|
||||
@Deprecated("Use PrefController")
|
||||
Future<bool> setFollowSystemTheme(bool value) => _set<bool>(
|
||||
PrefKey.followSystemTheme,
|
||||
value,
|
||||
(key, value) => provider.setBool(key, value));
|
||||
|
||||
@Deprecated("Use PrefController")
|
||||
bool? isUseBlackInDarkTheme() =>
|
||||
provider.getBool(PrefKey.useBlackInDarkTheme);
|
||||
@Deprecated("Use PrefController")
|
||||
bool isUseBlackInDarkThemeOr(bool def) => isUseBlackInDarkTheme() ?? def;
|
||||
@Deprecated("Use PrefController")
|
||||
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>(
|
||||
|
@ -165,11 +131,6 @@ extension PrefExtension on Pref {
|
|||
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;
|
||||
|
@ -249,20 +210,6 @@ extension PrefExtension on Pref {
|
|||
value,
|
||||
(key, value) => provider.setBool(key, value));
|
||||
|
||||
@Deprecated("Use PrefController")
|
||||
int? getSeedColor() => provider.getInt(PrefKey.seedColor);
|
||||
@Deprecated("Use PrefController")
|
||||
int getSeedColorOr(int def) => getSeedColor() ?? def;
|
||||
@Deprecated("Use PrefController")
|
||||
Future<bool> setSeedColor(int? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.seedColor);
|
||||
} else {
|
||||
return _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>(
|
||||
|
@ -276,58 +223,6 @@ extension PrefExtension on Pref {
|
|||
PrefKey.isVideoPlayerLoop,
|
||||
value,
|
||||
(key, value) => provider.setBool(key, value));
|
||||
|
||||
@Deprecated("Use PrefController")
|
||||
int? getSecondarySeedColor() => provider.getInt(PrefKey.secondarySeedColor);
|
||||
@Deprecated("Use PrefController")
|
||||
int getSecondarySeedColorOr(int def) => getSecondarySeedColor() ?? def;
|
||||
@Deprecated("Use PrefController")
|
||||
Future<bool> setSecondarySeedColor(int? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.secondarySeedColor);
|
||||
} else {
|
||||
return _set<int>(PrefKey.secondarySeedColor, value,
|
||||
(key, value) => provider.setInt(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
int? getProtectedPageAuthType() =>
|
||||
provider.getInt(PrefKey.protectedPageAuthType);
|
||||
int getProtectedPageAuthTypeOr(int def) => getProtectedPageAuthType() ?? def;
|
||||
Future<bool> setProtectedPageAuthType(int? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.protectedPageAuthType);
|
||||
} else {
|
||||
return _set<int>(PrefKey.protectedPageAuthType, value,
|
||||
(key, value) => provider.setInt(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
String? getProtectedPageAuthPin() =>
|
||||
provider.getString(PrefKey.protectedPageAuthPin);
|
||||
String getProtectedPageAuthPinOr(String def) =>
|
||||
getProtectedPageAuthPin() ?? def;
|
||||
Future<bool> setProtectedPageAuthPin(String? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.protectedPageAuthPin);
|
||||
} else {
|
||||
return _set<String>(PrefKey.protectedPageAuthPin, value,
|
||||
(key, value) => provider.setString(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
String? getProtectedPageAuthPassword() =>
|
||||
provider.getString(PrefKey.protectedPageAuthPassword);
|
||||
String getProtectedPageAuthPasswordOr(String def) =>
|
||||
getProtectedPageAuthPassword() ?? def;
|
||||
Future<bool> setProtectedPageAuthPassword(String? value) {
|
||||
if (value == null) {
|
||||
return _remove(PrefKey.protectedPageAuthPassword);
|
||||
} else {
|
||||
return _set<String>(PrefKey.protectedPageAuthPassword, value,
|
||||
(key, value) => provider.setString(key, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension AccountPrefExtension on AccountPref {
|
||||
|
|
Loading…
Reference in a new issue