diff --git a/app/lib/controller/pref_controller.dart b/app/lib/controller/pref_controller.dart index 75e85040..bf466517 100644 --- a/app/lib/controller/pref_controller.dart +++ b/app/lib/controller/pref_controller.dart @@ -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 { diff --git a/app/lib/controller/pref_controller/util.dart b/app/lib/controller/pref_controller/util.dart new file mode 100644 index 00000000..eb727c50 --- /dev/null +++ b/app/lib/controller/pref_controller/util.dart @@ -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 setHomeAlbumsSort(int value) => + provider.setInt(PrefKey.homeAlbumsSort, value); + + bool? isDarkTheme() => provider.getBool(PrefKey.darkTheme); + bool isDarkThemeOr(bool def) => isDarkTheme() ?? def; + Future setDarkTheme(bool value) => + provider.setBool(PrefKey.darkTheme, value); + + bool? isFollowSystemTheme() => provider.getBool(PrefKey.followSystemTheme); + bool isFollowSystemThemeOr(bool def) => isFollowSystemTheme() ?? def; + Future setFollowSystemTheme(bool value) => + provider.setBool(PrefKey.followSystemTheme, value); + + bool? isUseBlackInDarkTheme() => + provider.getBool(PrefKey.useBlackInDarkTheme); + bool isUseBlackInDarkThemeOr(bool def) => isUseBlackInDarkTheme() ?? def; + Future setUseBlackInDarkTheme(bool value) => + provider.setBool(PrefKey.useBlackInDarkTheme, value); + + int? getGpsMapProvider() => provider.getInt(PrefKey.gpsMapProvider); + int getGpsMapProviderOr(int def) => getGpsMapProvider() ?? def; + Future setGpsMapProvider(int value) => + provider.setInt(PrefKey.gpsMapProvider, value); + + int? getSeedColor() => provider.getInt(PrefKey.seedColor); + // int getSeedColorOr(int def) => getSeedColor() ?? def; + Future 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 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 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 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 setProtectedPageAuthPassword(String? value) { + if (value == null) { + return provider.remove(PrefKey.protectedPageAuthPassword); + } else { + return provider.setString(PrefKey.protectedPageAuthPassword, value); + } + } +} diff --git a/app/lib/entity/pref/extension.dart b/app/lib/entity/pref/extension.dart index df4ac543..4898cc54 100644 --- a/app/lib/entity/pref/extension.dart +++ b/app/lib/entity/pref/extension.dart @@ -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 setHomeAlbumsSort(int value) => _set(PrefKey.homeAlbumsSort, - value, (key, value) => provider.setInt(key, value)); - bool? isEnableExif() => provider.getBool(PrefKey.enableExif); bool isEnableExifOr([bool def = true]) => isEnableExif() ?? def; Future setEnableExif(bool value) => _set( @@ -101,35 +96,6 @@ extension PrefExtension on Pref { Future setLastVersion(int value) => _set( 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 setDarkTheme(bool value) => _set( - 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 setFollowSystemTheme(bool value) => _set( - 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 setUseBlackInDarkTheme(bool value) => _set( - PrefKey.useBlackInDarkTheme, - value, - (key, value) => provider.setBool(key, value)); - int? getLanguage() => provider.getInt(PrefKey.language); int getLanguageOr(int def) => getLanguage() ?? def; Future setLanguage(int value) => _set( @@ -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 setGpsMapProvider(int value) => _set(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 setSeedColor(int? value) { - if (value == null) { - return _remove(PrefKey.seedColor); - } else { - return _set(PrefKey.seedColor, value, - (key, value) => provider.setInt(key, value)); - } - } - bool? isVideoPlayerMute() => provider.getBool(PrefKey.isVideoPlayerMute); bool isVideoPlayerMuteOr([bool def = false]) => isVideoPlayerMute() ?? def; Future setVideoPlayerMute(bool value) => _set( @@ -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 setSecondarySeedColor(int? value) { - if (value == null) { - return _remove(PrefKey.secondarySeedColor); - } else { - return _set(PrefKey.secondarySeedColor, value, - (key, value) => provider.setInt(key, value)); - } - } - - int? getProtectedPageAuthType() => - provider.getInt(PrefKey.protectedPageAuthType); - int getProtectedPageAuthTypeOr(int def) => getProtectedPageAuthType() ?? def; - Future setProtectedPageAuthType(int? value) { - if (value == null) { - return _remove(PrefKey.protectedPageAuthType); - } else { - return _set(PrefKey.protectedPageAuthType, value, - (key, value) => provider.setInt(key, value)); - } - } - - String? getProtectedPageAuthPin() => - provider.getString(PrefKey.protectedPageAuthPin); - String getProtectedPageAuthPinOr(String def) => - getProtectedPageAuthPin() ?? def; - Future setProtectedPageAuthPin(String? value) { - if (value == null) { - return _remove(PrefKey.protectedPageAuthPin); - } else { - return _set(PrefKey.protectedPageAuthPin, value, - (key, value) => provider.setString(key, value)); - } - } - - String? getProtectedPageAuthPassword() => - provider.getString(PrefKey.protectedPageAuthPassword); - String getProtectedPageAuthPasswordOr(String def) => - getProtectedPageAuthPassword() ?? def; - Future setProtectedPageAuthPassword(String? value) { - if (value == null) { - return _remove(PrefKey.protectedPageAuthPassword); - } else { - return _set(PrefKey.protectedPageAuthPassword, value, - (key, value) => provider.setString(key, value)); - } - } } extension AccountPrefExtension on AccountPref {