mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Simplify Pref access
This commit is contained in:
parent
be220071cd
commit
9ca333403f
24 changed files with 93 additions and 96 deletions
|
@ -47,7 +47,7 @@ enum _AppLanguageEnum {
|
|||
|
||||
AppLanguage _getSelectedLanguage() {
|
||||
try {
|
||||
final lang = Pref.inst().getLanguageOr(0);
|
||||
final lang = Pref().getLanguageOr(0);
|
||||
return supportedLanguages[lang]!;
|
||||
} catch (_) {
|
||||
return supportedLanguages[_AppLanguageEnum.systemDefault.index]!;
|
||||
|
|
|
@ -75,14 +75,14 @@ void _initLog() {
|
|||
}
|
||||
|
||||
Future<void> _initPref() async {
|
||||
await Pref.init();
|
||||
if (Pref.inst().getLastVersion() == null) {
|
||||
if (Pref.inst().getSetupProgress() == null) {
|
||||
await Pref().init();
|
||||
if (Pref().getLastVersion() == null) {
|
||||
if (Pref().getSetupProgress() == null) {
|
||||
// new install
|
||||
await Pref.inst().setLastVersion(k.version);
|
||||
await Pref().setLastVersion(k.version);
|
||||
} else {
|
||||
// v6 is the last version without saving the version number in pref
|
||||
await Pref.inst().setLastVersion(6);
|
||||
await Pref().setLastVersion(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class MetadataTask {
|
|||
final op = UpdateMissingMetadata(fileRepo);
|
||||
await for (final _ in op(account,
|
||||
File(path: "${api_util.getWebdavRootUrlRelative(account)}/$r"))) {
|
||||
if (!Pref.inst().isEnableExifOr()) {
|
||||
if (!Pref().isEnableExifOr()) {
|
||||
_log.info("[call] EXIF disabled, task ending immaturely");
|
||||
op.stop();
|
||||
return;
|
||||
|
@ -76,7 +76,7 @@ class MetadataTaskManager {
|
|||
|
||||
void _handleStream() async {
|
||||
await for (final task in _streamController.stream) {
|
||||
if (Pref.inst().isEnableExifOr()) {
|
||||
if (Pref().isEnableExifOr()) {
|
||||
_log.info("[_doTask] Executing task: $task");
|
||||
await task();
|
||||
} else {
|
||||
|
|
|
@ -9,7 +9,11 @@ import 'package:nc_photos/use_case/compat/v32.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Pref {
|
||||
static Future<void> init() async {
|
||||
factory Pref() => _inst;
|
||||
|
||||
Pref._();
|
||||
|
||||
Future<void> init() async {
|
||||
if (await CompatV32.isPrefNeedMigration()) {
|
||||
await CompatV32.migratePref();
|
||||
}
|
||||
|
@ -18,8 +22,6 @@ class Pref {
|
|||
});
|
||||
}
|
||||
|
||||
factory Pref.inst() => _inst;
|
||||
|
||||
List<PrefAccount>? getAccounts2() {
|
||||
final jsonObjs = _pref.getStringList(_toKey(PrefKey.accounts2));
|
||||
return jsonObjs?.map((e) => PrefAccount.fromJson(jsonDecode(e))).toList();
|
||||
|
@ -138,8 +140,6 @@ class Pref {
|
|||
Future<bool> setLabEnableSharedAlbum(bool value) =>
|
||||
_setBool(PrefKey.labEnableSharedAlbum, value);
|
||||
|
||||
Pref._();
|
||||
|
||||
Future<bool> _setBool(PrefKey key, bool value) async {
|
||||
return _onPostSet(await _pref.setBool(_toKey(key), value), key, value);
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ class Pref {
|
|||
}
|
||||
}
|
||||
|
||||
static final _inst = Pref._();
|
||||
static late final _inst = Pref._();
|
||||
late SharedPreferences _pref;
|
||||
}
|
||||
|
||||
|
@ -277,16 +277,14 @@ enum PrefKey {
|
|||
extension PrefExtension on Pref {
|
||||
Account? getCurrentAccount() {
|
||||
try {
|
||||
return Pref.inst()
|
||||
.getAccounts2()![Pref.inst().getCurrentAccountIndex()!]
|
||||
.account;
|
||||
return Pref().getAccounts2()![Pref().getCurrentAccountIndex()!].account;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
AccountSettings getAccountSettings(Account account) {
|
||||
return Pref.inst()
|
||||
return Pref()
|
||||
.getAccounts2()!
|
||||
.firstWhere((element) => element.account == account)
|
||||
.settings;
|
||||
|
|
|
@ -97,7 +97,7 @@ class AppTheme extends StatelessWidget {
|
|||
static ThemeData _buildDarkThemeData(BuildContext context, ThemeData theme) {
|
||||
final Color background;
|
||||
final Color popup;
|
||||
if (Pref.inst().isUseBlackInDarkThemeOr(false)) {
|
||||
if (Pref().isUseBlackInDarkThemeOr(false)) {
|
||||
background = Colors.black;
|
||||
popup = Colors.grey[900]!;
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,7 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_accounts = Pref.inst().getAccounts2Or([]);
|
||||
_accounts = Pref().getAccounts2Or([]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -102,7 +102,7 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
|
|||
}
|
||||
|
||||
void _onItemPressed(PrefAccount account) {
|
||||
Pref.inst().setCurrentAccountIndex(_accounts.indexOf(account));
|
||||
Pref().setCurrentAccountIndex(_accounts.indexOf(account));
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(Home.routeName, (_) => false,
|
||||
arguments: HomeArguments(account.account));
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
|
|||
try {
|
||||
_removeAccount(account);
|
||||
setState(() {
|
||||
_accounts = Pref.inst().getAccounts2()!;
|
||||
_accounts = Pref().getAccounts2()!;
|
||||
});
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
|
@ -135,9 +135,9 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
|
|||
|
||||
void _removeAccount(PrefAccount account) {
|
||||
_log.info("[_removeAccount] Remove account: ${account.account}");
|
||||
final currentAccounts = Pref.inst().getAccounts2()!;
|
||||
final currentAccounts = Pref().getAccounts2()!;
|
||||
final currentAccount =
|
||||
currentAccounts[Pref.inst().getCurrentAccountIndex()!];
|
||||
currentAccounts[Pref().getCurrentAccountIndex()!];
|
||||
final newAccounts = currentAccounts
|
||||
.where((element) => element.account != account.account)
|
||||
.toList();
|
||||
|
@ -145,7 +145,7 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
|
|||
if (newAccountIndex == -1) {
|
||||
throw StateError("Active account not found in resulting account list");
|
||||
}
|
||||
Pref.inst()
|
||||
Pref()
|
||||
..setAccounts2(newAccounts)
|
||||
..setCurrentAccountIndex(newAccountIndex);
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
_album!,
|
||||
actions: [
|
||||
if (_album!.albumFile!.isOwned(widget.account.username) &&
|
||||
Pref.inst().isLabEnableSharedAlbumOr(false))
|
||||
Pref().isLabEnableSharedAlbumOr(false))
|
||||
IconButton(
|
||||
onPressed: () => _onSharePressed(context),
|
||||
icon: const Icon(Icons.share),
|
||||
|
@ -250,7 +250,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
],
|
||||
menuItemBuilder: (_) => [
|
||||
if (_album!.albumFile!.isOwned(widget.account.username) &&
|
||||
Pref.inst().isLabEnableSharedAlbumOr(false))
|
||||
Pref().isLabEnableSharedAlbumOr(false))
|
||||
PopupMenuItem(
|
||||
value: _menuValueFixShares,
|
||||
child: Text(L10n.global().fixSharesTooltip),
|
||||
|
@ -642,7 +642,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
|
|||
height: k.photoThumbSize,
|
||||
);
|
||||
if ((_editAlbum ?? _album)?.sortProvider is AlbumTimeSortProvider &&
|
||||
Pref.inst().isAlbumBrowserShowDateOr()) {
|
||||
Pref().isAlbumBrowserShowDateOr()) {
|
||||
final date = dateHelper.onFile(item.file);
|
||||
if (date != null) {
|
||||
yield _DateListItem(date: date);
|
||||
|
|
|
@ -26,7 +26,7 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_thumbZoomLevel = Pref.inst().getAlbumBrowserZoomLevelOr(0);
|
||||
_thumbZoomLevel = Pref().getAlbumBrowserZoomLevelOr(0);
|
||||
}
|
||||
|
||||
@protected
|
||||
|
@ -72,7 +72,7 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
|
|||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
Pref().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
if (album.albumFile?.path.startsWith(
|
||||
|
|
|
@ -62,7 +62,7 @@ class _ArchiveBrowserState extends State<ArchiveBrowser>
|
|||
initState() {
|
||||
super.initState();
|
||||
_initBloc();
|
||||
_thumbZoomLevel = Pref.inst().getAlbumBrowserZoomLevelOr(0);
|
||||
_thumbZoomLevel = Pref().getAlbumBrowserZoomLevelOr(0);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -187,7 +187,7 @@ class _ArchiveBrowserState extends State<ArchiveBrowser>
|
|||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
Pref().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
@ -549,7 +549,7 @@ class _DynamicAlbumBrowserState extends State<DynamicAlbumBrowser>
|
|||
height: k.photoThumbSize,
|
||||
);
|
||||
if ((_editAlbum ?? _album)?.sortProvider is AlbumTimeSortProvider &&
|
||||
Pref.inst().isAlbumBrowserShowDateOr()) {
|
||||
Pref().isAlbumBrowserShowDateOr()) {
|
||||
final date = dateHelper.onFile(item.file);
|
||||
if (date != null) {
|
||||
yield _DateListItem(date: date);
|
||||
|
|
|
@ -47,10 +47,10 @@ class _HomeState extends State<Home> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
if (Pref.inst().isLabEnableSharedAlbumOr(false)) {
|
||||
if (Pref().isLabEnableSharedAlbumOr(false)) {
|
||||
_importPotentialSharedAlbum().then((value) {
|
||||
if (value.isNotEmpty) {
|
||||
Pref.inst().setNewSharedAlbum(true);
|
||||
Pref().setNewSharedAlbum(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ class _HomeState extends State<Home> {
|
|||
final albumRepo = AlbumRepo(AlbumRemoteDataSource());
|
||||
try {
|
||||
return await ImportPotentialSharedAlbum(fileRepo, albumRepo)(
|
||||
widget.account, Pref.inst().getAccountSettings(widget.account));
|
||||
widget.account, Pref().getAccountSettings(widget.account));
|
||||
} catch (e, stacktrace) {
|
||||
_log.shout(
|
||||
"[_importPotentialSharedAlbum] Failed while ImportPotentialSharedAlbum",
|
||||
|
|
|
@ -241,7 +241,7 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
|||
return _ButtonListItem(
|
||||
icon: Icons.share_outlined,
|
||||
label: L10n.global().collectionSharingLabel,
|
||||
isShowIndicator: Pref.inst().hasNewSharedAlbumOr(false),
|
||||
isShowIndicator: Pref().hasNewSharedAlbumOr(false),
|
||||
onTap: () {
|
||||
if (!isSelectionMode) {
|
||||
Navigator.of(context).pushNamed(SharingBrowser.routeName,
|
||||
|
@ -362,7 +362,7 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
|||
}
|
||||
|
||||
void _onSortSelected(_Sort sort) async {
|
||||
await Pref.inst().setHomeAlbumsSort(sort.index);
|
||||
await Pref().setHomeAlbumsSort(sort.index);
|
||||
setState(() {
|
||||
_transformItems(_bloc.state.items);
|
||||
});
|
||||
|
@ -443,7 +443,7 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
|||
}
|
||||
}).map((e) => e.item2);
|
||||
itemStreamListItems = [
|
||||
if (Pref.inst()
|
||||
if (Pref()
|
||||
.getAccountSettings(widget.account)
|
||||
.isEnableFaceRecognitionApp ==
|
||||
true)
|
||||
|
@ -616,7 +616,7 @@ enum _Sort {
|
|||
|
||||
_Sort _getSortFromPref() {
|
||||
try {
|
||||
return _Sort.values[Pref.inst().getHomeAlbumsSort()!];
|
||||
return _Sort.values[Pref().getHomeAlbumsSort()!];
|
||||
} catch (_) {
|
||||
// default
|
||||
return _Sort.dateDescending;
|
||||
|
|
|
@ -79,7 +79,7 @@ class HomeSliverAppBar extends StatelessWidget {
|
|||
automaticallyImplyLeading: false,
|
||||
actions: (actions ?? []) +
|
||||
[
|
||||
if (!Pref.inst().isFollowSystemThemeOr(false))
|
||||
if (!Pref().isFollowSystemThemeOr(false))
|
||||
Switch(
|
||||
value: Theme.of(context).brightness == Brightness.dark,
|
||||
onChanged: _onDarkModeChanged,
|
||||
|
@ -125,7 +125,7 @@ class HomeSliverAppBar extends StatelessWidget {
|
|||
}
|
||||
|
||||
void _onDarkModeChanged(bool value) {
|
||||
Pref.inst().setDarkTheme(value).then((_) {
|
||||
Pref().setDarkTheme(value).then((_) {
|
||||
KiwiContainer().resolve<EventBus>().fire(ThemeChangedEvent());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_thumbZoomLevel = Pref.inst().getHomePhotosZoomLevelOr(0);
|
||||
_thumbZoomLevel = Pref().getHomePhotosZoomLevelOr(0);
|
||||
_initBloc();
|
||||
_metadataTaskStateChangedListener.begin();
|
||||
_prefUpdatedListener.begin();
|
||||
|
@ -241,7 +241,7 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
setState(() {
|
||||
_setThumbZoomLevel(value.round());
|
||||
});
|
||||
Pref.inst().setHomePhotosZoomLevel(_thumbZoomLevel);
|
||||
Pref().setHomePhotosZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -546,7 +546,7 @@ class _HomePhotosState extends State<HomePhotos>
|
|||
bool ignoreFired = false,
|
||||
}) {
|
||||
if (_bloc.state is ScanDirBlocSuccess &&
|
||||
Pref.inst().isEnableExifOr() &&
|
||||
Pref().isEnableExifOr() &&
|
||||
(!_hasFiredMetadataTask.value || ignoreFired)) {
|
||||
MetadataTaskManager().addTask(MetadataTask(widget.account));
|
||||
_metadataTaskProcessTotalCount = _backingFiles
|
||||
|
|
|
@ -61,11 +61,11 @@ class _MyAppState extends State<MyApp> implements SnackBarHandler {
|
|||
@override
|
||||
build(BuildContext context) {
|
||||
final ThemeMode themeMode;
|
||||
if (Pref.inst().isFollowSystemThemeOr(false)) {
|
||||
if (Pref().isFollowSystemThemeOr(false)) {
|
||||
themeMode = ThemeMode.system;
|
||||
} else {
|
||||
themeMode =
|
||||
Pref.inst().isDarkThemeOr(false) ? ThemeMode.dark : ThemeMode.light;
|
||||
Pref().isDarkThemeOr(false) ? ThemeMode.dark : ThemeMode.light;
|
||||
}
|
||||
return MaterialApp(
|
||||
onGenerateTitle: (context) => AppLocalizations.of(context)!.appTitle,
|
||||
|
|
|
@ -84,7 +84,7 @@ class _PersonBrowserState extends State<PersonBrowser>
|
|||
initState() {
|
||||
super.initState();
|
||||
_initBloc();
|
||||
_thumbZoomLevel = Pref.inst().getAlbumBrowserZoomLevelOr(0);
|
||||
_thumbZoomLevel = Pref().getAlbumBrowserZoomLevelOr(0);
|
||||
|
||||
_filePropertyUpdatedListener.begin();
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class _PersonBrowserState extends State<PersonBrowser>
|
|||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
Pref().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
@ -57,7 +57,7 @@ class _SettingsState extends State<Settings> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_isEnableExif = Pref.inst().isEnableExifOr();
|
||||
_isEnableExif = Pref().isEnableExifOr();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -220,7 +220,7 @@ class _SettingsState extends State<Settings> {
|
|||
|
||||
void _onLanguageTap(BuildContext context) {
|
||||
final selected =
|
||||
Pref.inst().getLanguageOr(language_util.supportedLanguages[0]!.langId);
|
||||
Pref().getLanguageOr(language_util.supportedLanguages[0]!.langId);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => FancyOptionPicker(
|
||||
|
@ -240,7 +240,7 @@ class _SettingsState extends State<Settings> {
|
|||
),
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
Pref.inst().setLanguage(value).then((_) {
|
||||
Pref().setLanguage(value).then((_) {
|
||||
KiwiContainer().resolve<EventBus>().fire(LanguageChangedEvent());
|
||||
});
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ class _SettingsState extends State<Settings> {
|
|||
setState(() {
|
||||
_isEnableExif = value;
|
||||
});
|
||||
if (!await Pref.inst().setEnableExif(value)) {
|
||||
if (!await Pref().setEnableExif(value)) {
|
||||
_log.severe("[_setExifSupport] Failed writing pref");
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
|
@ -406,7 +406,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
super.initState();
|
||||
_account = widget.account;
|
||||
|
||||
final settings = Pref.inst().getAccountSettings(_account);
|
||||
final settings = Pref().getAccountSettings(_account);
|
||||
_isEnableFaceRecognitionApp = settings.isEnableFaceRecognitionApp;
|
||||
_shareFolder = settings.shareFolder;
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
_log.fine("[_onIncludedFoldersPressed] No changes");
|
||||
return;
|
||||
}
|
||||
final accounts = Pref.inst().getAccounts2()!;
|
||||
final accounts = Pref().getAccounts2()!;
|
||||
if (accounts.any((element) => element.account == result)) {
|
||||
// conflict with another account. This normally won't happen because
|
||||
// the app passwords are unique to each entry, but just in case
|
||||
|
@ -515,7 +515,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
account: result,
|
||||
);
|
||||
accounts[index] = newAccount;
|
||||
if (!await Pref.inst().setAccounts2(accounts)) {
|
||||
if (!await Pref().setAccounts2(accounts)) {
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
duration: k.snackBarDurationNormal,
|
||||
|
@ -605,7 +605,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
String? shareFolder,
|
||||
}) {
|
||||
try {
|
||||
final accounts = Pref.inst().getAccounts2()!;
|
||||
final accounts = Pref().getAccounts2()!;
|
||||
final index = _findAccount(account, accounts);
|
||||
accounts[index] = accounts[index].copyWith(
|
||||
settings: accounts[index].settings.copyWith(
|
||||
|
@ -613,7 +613,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
shareFolder: shareFolder,
|
||||
),
|
||||
);
|
||||
return Pref.inst().setAccounts2(accounts);
|
||||
return Pref().setAccounts2(accounts);
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe(
|
||||
"[_modifyAccountSettings] Failed while setting account settings",
|
||||
|
@ -625,7 +625,7 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
|
|||
|
||||
/// Return the index of [account] in [Pref.getAccounts2]
|
||||
static int _findAccount(Account account, [List<PrefAccount>? accounts]) {
|
||||
final from = accounts ?? Pref.inst().getAccounts2Or([]);
|
||||
final from = accounts ?? Pref().getAccounts2Or([]);
|
||||
return from.indexWhere((element) => element.account == account);
|
||||
}
|
||||
|
||||
|
@ -711,8 +711,8 @@ class _ViewerSettingsState extends State<_ViewerSettings> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_screenBrightness = Pref.inst().getViewerScreenBrightnessOr(-1);
|
||||
_isForceRotation = Pref.inst().isViewerForceRotationOr(false);
|
||||
_screenBrightness = Pref().getViewerScreenBrightnessOr(-1);
|
||||
_isForceRotation = Pref().isViewerForceRotationOr(false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -833,7 +833,7 @@ class _ViewerSettingsState extends State<_ViewerSettings> {
|
|||
setState(() {
|
||||
_screenBrightness = value;
|
||||
});
|
||||
if (!await Pref.inst().setViewerScreenBrightness(value)) {
|
||||
if (!await Pref().setViewerScreenBrightness(value)) {
|
||||
_log.severe("[_setScreenBrightness] Failed writing pref");
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
|
@ -850,7 +850,7 @@ class _ViewerSettingsState extends State<_ViewerSettings> {
|
|||
setState(() {
|
||||
_isForceRotation = value;
|
||||
});
|
||||
if (!await Pref.inst().setViewerForceRotation(value)) {
|
||||
if (!await Pref().setViewerForceRotation(value)) {
|
||||
_log.severe("[_setForceRotation] Failed writing pref");
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
|
@ -877,7 +877,7 @@ class _AlbumSettingsState extends State<_AlbumSettings> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_isBrowserShowDate = Pref.inst().isAlbumBrowserShowDateOr();
|
||||
_isBrowserShowDate = Pref().isAlbumBrowserShowDateOr();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -920,7 +920,7 @@ class _AlbumSettingsState extends State<_AlbumSettings> {
|
|||
setState(() {
|
||||
_isBrowserShowDate = value;
|
||||
});
|
||||
if (!await Pref.inst().setAlbumBrowserShowDate(value)) {
|
||||
if (!await Pref().setAlbumBrowserShowDate(value)) {
|
||||
_log.severe("[_onBrowserShowDateChanged] Failed writing pref");
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
|
@ -946,8 +946,8 @@ class _ThemeSettingsState extends State<_ThemeSettings> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_isFollowSystemTheme = Pref.inst().isFollowSystemThemeOr(false);
|
||||
_isUseBlackInDarkTheme = Pref.inst().isUseBlackInDarkThemeOr(false);
|
||||
_isFollowSystemTheme = Pref().isFollowSystemThemeOr(false);
|
||||
_isUseBlackInDarkTheme = Pref().isUseBlackInDarkThemeOr(false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -999,7 +999,7 @@ class _ThemeSettingsState extends State<_ThemeSettings> {
|
|||
setState(() {
|
||||
_isFollowSystemTheme = value;
|
||||
});
|
||||
if (await Pref.inst().setFollowSystemTheme(value)) {
|
||||
if (await Pref().setFollowSystemTheme(value)) {
|
||||
KiwiContainer().resolve<EventBus>().fire(ThemeChangedEvent());
|
||||
} else {
|
||||
_log.severe("[_onFollowSystemThemeChanged] Failed writing pref");
|
||||
|
@ -1018,7 +1018,7 @@ class _ThemeSettingsState extends State<_ThemeSettings> {
|
|||
setState(() {
|
||||
_isUseBlackInDarkTheme = value;
|
||||
});
|
||||
if (await Pref.inst().setUseBlackInDarkTheme(value)) {
|
||||
if (await Pref().setUseBlackInDarkTheme(value)) {
|
||||
if (Theme.of(context).brightness == Brightness.dark) {
|
||||
KiwiContainer().resolve<EventBus>().fire(ThemeChangedEvent());
|
||||
}
|
||||
|
@ -1049,7 +1049,7 @@ class _ExperimentalSettingsState extends State<_ExperimentalSettings> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
_isEnableSharedAlbum = Pref.inst().isLabEnableSharedAlbumOr(false);
|
||||
_isEnableSharedAlbum = Pref().isLabEnableSharedAlbumOr(false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1092,7 +1092,7 @@ class _ExperimentalSettingsState extends State<_ExperimentalSettings> {
|
|||
setState(() {
|
||||
_isEnableSharedAlbum = value;
|
||||
});
|
||||
if (!await Pref.inst().setLabEnableSharedAlbum(value)) {
|
||||
if (!await Pref().setLabEnableSharedAlbum(value)) {
|
||||
_log.severe("[_onEnableSharedAlbumChanged] Failed writing pref");
|
||||
SnackBarManager().showSnackBar(SnackBar(
|
||||
content: Text(L10n.global().writePreferenceFailureNotification),
|
||||
|
|
|
@ -8,8 +8,7 @@ import 'package:nc_photos/widget/home.dart';
|
|||
import 'package:nc_photos/widget/sign_in.dart';
|
||||
import 'package:page_view_indicators/circle_page_indicator.dart';
|
||||
|
||||
bool isNeedSetup() =>
|
||||
Pref.inst().getSetupProgressOr() & _PageId.all != _PageId.all;
|
||||
bool isNeedSetup() => Pref().getSetupProgressOr() & _PageId.all != _PageId.all;
|
||||
|
||||
class Setup extends StatefulWidget {
|
||||
static const routeName = "/setup";
|
||||
|
@ -102,9 +101,9 @@ class _SetupState extends State<Setup> {
|
|||
}
|
||||
|
||||
void _onDonePressed() {
|
||||
Pref.inst().setSetupProgress(_PageId.all);
|
||||
Pref().setSetupProgress(_PageId.all);
|
||||
|
||||
final account = Pref.inst().getCurrentAccount();
|
||||
final account = Pref().getCurrentAccount();
|
||||
if (account == null) {
|
||||
Navigator.pushReplacementNamed(context, SignIn.routeName);
|
||||
} else {
|
||||
|
@ -114,12 +113,12 @@ class _SetupState extends State<Setup> {
|
|||
}
|
||||
|
||||
void _onNextPressed(int pageId) {
|
||||
Pref.inst().setSetupProgress(Pref.inst().getSetupProgressOr() | pageId);
|
||||
Pref().setSetupProgress(Pref().getSetupProgressOr() | pageId);
|
||||
_pageController.nextPage(
|
||||
duration: k.animationDurationNormal, curve: Curves.easeInOut);
|
||||
}
|
||||
|
||||
final _initialProgress = Pref.inst().getSetupProgressOr();
|
||||
final _initialProgress = Pref().getSetupProgressOr();
|
||||
final _pageController = PageController();
|
||||
final _currentPageNotifier = ValueNotifier<int>(0);
|
||||
}
|
||||
|
@ -178,7 +177,7 @@ class _ExifState extends State<_Exif> {
|
|||
dispose() {
|
||||
super.dispose();
|
||||
// persist user's choice
|
||||
Pref.inst().setEnableExif(_isEnableExif);
|
||||
Pref().setEnableExif(_isEnableExif);
|
||||
}
|
||||
|
||||
void _onValueChanged(bool value) {
|
||||
|
@ -187,7 +186,7 @@ class _ExifState extends State<_Exif> {
|
|||
});
|
||||
}
|
||||
|
||||
bool _isEnableExif = Pref.inst().isEnableExifOr();
|
||||
bool _isEnableExif = Pref().isEnableExifOr();
|
||||
}
|
||||
|
||||
class _HiddenPrefDirNotice extends StatefulWidget implements _Page {
|
||||
|
|
|
@ -61,11 +61,11 @@ class _SharingBrowserState extends State<SharingBrowser> {
|
|||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
if (Pref.inst().isLabEnableSharedAlbumOr(false)) {
|
||||
if (Pref().isLabEnableSharedAlbumOr(false)) {
|
||||
_importPotentialSharedAlbum().whenComplete(() {
|
||||
_initBloc();
|
||||
});
|
||||
Pref.inst().setNewSharedAlbum(false);
|
||||
Pref().setNewSharedAlbum(false);
|
||||
} else {
|
||||
_initBloc();
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ class _SharingBrowserState extends State<SharingBrowser> {
|
|||
final albumRepo = AlbumRepo(AlbumRemoteDataSource());
|
||||
try {
|
||||
return await ImportPotentialSharedAlbum(fileRepo, albumRepo)(
|
||||
widget.account, Pref.inst().getAccountSettings(widget.account));
|
||||
widget.account, Pref().getAccountSettings(widget.account));
|
||||
} catch (e, stackTrace) {
|
||||
_log.shout(
|
||||
"[_importPotentialSharedAlbum] Failed while ImportPotentialSharedAlbum",
|
||||
|
|
|
@ -228,11 +228,11 @@ class _SignInState extends State<SignIn> {
|
|||
// we've got a good account
|
||||
final pa = PrefAccount(result);
|
||||
// only signing in with app password would trigger distinct
|
||||
final accounts = (Pref.inst().getAccounts2Or([])..add(pa)).distinctIf(
|
||||
final accounts = (Pref().getAccounts2Or([])..add(pa)).distinctIf(
|
||||
(a, b) => a.account == b.account,
|
||||
(a) => a.account.hashCode,
|
||||
);
|
||||
Pref.inst()
|
||||
Pref()
|
||||
..setAccounts2(accounts)
|
||||
..setCurrentAccountIndex(
|
||||
accounts.indexWhere((element) => element.account == result));
|
||||
|
|
|
@ -74,7 +74,7 @@ class _SplashState extends State<Splash> {
|
|||
|
||||
void _initTimedExit() {
|
||||
Future.delayed(const Duration(seconds: 1)).then((_) {
|
||||
final account = Pref.inst().getCurrentAccount();
|
||||
final account = Pref().getCurrentAccount();
|
||||
if (isNeedSetup()) {
|
||||
Navigator.pushReplacementNamed(context, Setup.routeName);
|
||||
} else if (account == null) {
|
||||
|
@ -87,13 +87,13 @@ class _SplashState extends State<Splash> {
|
|||
}
|
||||
|
||||
bool _shouldUpgrade() {
|
||||
final lastVersion = Pref.inst().getLastVersionOr(k.version);
|
||||
final lastVersion = Pref().getLastVersionOr(k.version);
|
||||
return lastVersion < k.version;
|
||||
}
|
||||
|
||||
void _handleUpgrade() async {
|
||||
try {
|
||||
final lastVersion = Pref.inst().getLastVersionOr(k.version);
|
||||
final lastVersion = Pref().getLastVersionOr(k.version);
|
||||
await _upgrade(lastVersion);
|
||||
|
||||
final change = _gatherChangelog(lastVersion);
|
||||
|
@ -118,7 +118,7 @@ class _SplashState extends State<Splash> {
|
|||
}
|
||||
} finally {
|
||||
_initTimedExit();
|
||||
Pref.inst().setLastVersion(k.version);
|
||||
Pref().setLastVersion(k.version);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
|
|||
initState() {
|
||||
super.initState();
|
||||
_initBloc();
|
||||
_thumbZoomLevel = Pref.inst().getAlbumBrowserZoomLevelOr(0);
|
||||
_thumbZoomLevel = Pref().getAlbumBrowserZoomLevelOr(0);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -209,7 +209,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
|
|||
setState(() {
|
||||
_thumbZoomLevel = value.round();
|
||||
});
|
||||
Pref.inst().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
Pref().setAlbumBrowserZoomLevel(_thumbZoomLevel);
|
||||
},
|
||||
),
|
||||
PopupMenuButton<_AppBarMenuOption>(
|
||||
|
|
|
@ -481,15 +481,15 @@ class _ViewerState extends State<Viewer>
|
|||
final result = await showDialog<SlideshowConfig>(
|
||||
context: context,
|
||||
builder: (_) => SlideshowDialog(
|
||||
duration: Duration(seconds: Pref.inst().getSlideshowDurationOr(5)),
|
||||
isShuffle: Pref.inst().isSlideshowShuffleOr(false),
|
||||
isRepeat: Pref.inst().isSlideshowRepeatOr(false),
|
||||
duration: Duration(seconds: Pref().getSlideshowDurationOr(5)),
|
||||
isShuffle: Pref().isSlideshowShuffleOr(false),
|
||||
isRepeat: Pref().isSlideshowRepeatOr(false),
|
||||
),
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
Pref.inst()
|
||||
Pref()
|
||||
..setSlideshowDuration(result.duration.inSeconds)
|
||||
..setSlideshowShuffle(result.isShuffle)
|
||||
..setSlideshowRepeat(result.isRepeat);
|
||||
|
|
|
@ -17,7 +17,7 @@ mixin ViewerControllersMixin<T extends StatefulWidget>
|
|||
...super.initDisposables(),
|
||||
if (platform_k.isMobile) _ViewerBrightnessController(),
|
||||
_ViewerSystemUiResetter(),
|
||||
if (platform_k.isMobile && Pref.inst().isViewerForceRotationOr(false))
|
||||
if (platform_k.isMobile && Pref().isViewerForceRotationOr(false))
|
||||
_ViewerOrientationController(
|
||||
onChanged: _onOrientationChanged,
|
||||
),
|
||||
|
@ -57,7 +57,7 @@ mixin ViewerControllersMixin<T extends StatefulWidget>
|
|||
class _ViewerBrightnessController implements Disposable {
|
||||
@override
|
||||
init(State state) {
|
||||
final brightness = Pref.inst().getViewerScreenBrightness();
|
||||
final brightness = Pref().getViewerScreenBrightness();
|
||||
if (brightness != null && brightness >= 0) {
|
||||
ScreenBrightness.setScreenBrightness(brightness / 100.0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue