2023-08-19 18:47:56 +02:00
|
|
|
// ignore_for_file: deprecated_member_use_from_same_package
|
|
|
|
|
2024-07-19 21:34:46 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2023-08-19 18:47:56 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-04-13 17:32:31 +02:00
|
|
|
import 'package:logging/logging.dart';
|
2024-06-19 15:07:18 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
2024-06-13 17:50:40 +02:00
|
|
|
import 'package:nc_photos/entity/collection/util.dart';
|
2023-07-17 09:35:45 +02:00
|
|
|
import 'package:nc_photos/entity/pref.dart';
|
2024-07-19 21:34:46 +02:00
|
|
|
import 'package:nc_photos/json_util.dart';
|
2024-08-17 20:01:59 +02:00
|
|
|
import 'package:nc_photos/k.dart' as k;
|
2024-02-25 05:09:57 +01:00
|
|
|
import 'package:nc_photos/language_util.dart';
|
2024-05-24 21:35:58 +02:00
|
|
|
import 'package:nc_photos/protected_page_handler.dart';
|
2023-08-14 17:07:09 +02:00
|
|
|
import 'package:nc_photos/size.dart';
|
2024-10-26 15:35:48 +02:00
|
|
|
import 'package:nc_photos/widget/home_collections.dart';
|
2024-10-09 14:48:19 +02:00
|
|
|
import 'package:nc_photos/widget/viewer.dart';
|
2023-04-13 17:32:31 +02:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
2024-05-24 21:35:58 +02:00
|
|
|
import 'package:np_common/object_util.dart';
|
2024-10-26 15:35:48 +02:00
|
|
|
import 'package:np_common/type.dart';
|
2023-09-12 18:29:44 +02:00
|
|
|
import 'package:np_gps_map/np_gps_map.dart';
|
2024-05-24 21:35:58 +02:00
|
|
|
import 'package:np_string/np_string.dart';
|
2023-04-13 17:32:31 +02:00
|
|
|
import 'package:rxdart/rxdart.dart';
|
|
|
|
|
|
|
|
part 'pref_controller.g.dart';
|
2024-08-24 13:33:21 +02:00
|
|
|
part 'pref_controller/type.dart';
|
2024-06-17 18:34:18 +02:00
|
|
|
part 'pref_controller/util.dart';
|
2023-04-13 17:32:31 +02:00
|
|
|
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-04-13 17:32:31 +02:00
|
|
|
class PrefController {
|
2024-08-18 12:07:56 +02:00
|
|
|
PrefController(this.pref);
|
2023-04-13 17:32:31 +02:00
|
|
|
|
2024-10-18 19:47:25 +02:00
|
|
|
Future<bool> setAccounts(List<Account>? value) => _setOrRemove<List<Account>>(
|
2024-06-19 15:07:18 +02:00
|
|
|
controller: _accountsController,
|
|
|
|
setter: (pref, value) => pref.setAccounts3(value),
|
2024-10-18 19:47:25 +02:00
|
|
|
remover: (pref) => pref.setAccounts3(null),
|
2024-06-19 15:07:18 +02:00
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: _accountsDefault,
|
2024-06-19 15:07:18 +02:00
|
|
|
);
|
|
|
|
|
2024-08-18 12:07:56 +02:00
|
|
|
Future<bool> setCurrentAccountIndex(int? value) => _setOrRemove<int>(
|
2024-08-17 20:01:59 +02:00
|
|
|
controller: _currentAccountIndexController,
|
|
|
|
setter: (pref, value) => pref.setCurrentAccountIndex(value),
|
|
|
|
remover: (pref) => pref.setCurrentAccountIndex(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-08-17 20:01:59 +02:00
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setAppLanguage(AppLanguage value) => _set<AppLanguage>(
|
2023-08-04 21:14:01 +02:00
|
|
|
controller: _languageController,
|
|
|
|
setter: (pref, value) => pref.setLanguage(value.langId),
|
|
|
|
value: value,
|
|
|
|
);
|
2023-06-06 15:39:58 +02:00
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setHomePhotosZoomLevel(int value) => _set<int>(
|
2024-01-12 19:53:14 +01:00
|
|
|
controller: _homePhotosZoomLevelController,
|
|
|
|
setter: (pref, value) => pref.setHomePhotosZoomLevel(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setAlbumBrowserZoomLevel(int value) => _set<int>(
|
2023-07-27 17:14:50 +02:00
|
|
|
controller: _albumBrowserZoomLevelController,
|
|
|
|
setter: (pref, value) => pref.setAlbumBrowserZoomLevel(value),
|
|
|
|
value: value,
|
|
|
|
);
|
2023-04-13 17:32:31 +02:00
|
|
|
|
2024-06-13 17:50:40 +02:00
|
|
|
Future<bool> setHomeAlbumsSort(CollectionSort value) => _set<CollectionSort>(
|
2023-07-27 17:14:50 +02:00
|
|
|
controller: _homeAlbumsSortController,
|
2024-06-13 17:50:40 +02:00
|
|
|
setter: (pref, value) => pref.setHomeAlbumsSort(value.index),
|
2023-07-27 17:14:50 +02:00
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-11-23 16:04:13 +01:00
|
|
|
Future<bool> setEnableClientExif(bool value) => _set<bool>(
|
|
|
|
controller: _isEnableClientExifController,
|
|
|
|
setter: (pref, value) => pref.setEnableClientExif(value),
|
2023-07-27 17:14:50 +02:00
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setProcessExifWifiOnly(bool value) => _set<bool>(
|
2023-07-27 17:14:50 +02:00
|
|
|
controller: _shouldProcessExifWifiOnlyController,
|
|
|
|
setter: (pref, value) => pref.setProcessExifWifiOnly(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setMemoriesRange(int value) => _set<int>(
|
2023-07-27 18:51:57 +02:00
|
|
|
controller: _memoriesRangeController,
|
|
|
|
setter: (pref, value) => pref.setMemoriesRange(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setViewerScreenBrightness(int value) => _set<int>(
|
2023-08-04 21:11:41 +02:00
|
|
|
controller: _viewerScreenBrightnessController,
|
|
|
|
setter: (pref, value) => pref.setViewerScreenBrightness(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setViewerForceRotation(bool value) => _set<bool>(
|
2023-08-04 21:11:41 +02:00
|
|
|
controller: _isViewerForceRotationController,
|
|
|
|
setter: (pref, value) => pref.setViewerForceRotation(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setGpsMapProvider(GpsMapProvider value) => _set<GpsMapProvider>(
|
2023-08-04 21:11:41 +02:00
|
|
|
controller: _gpsMapProviderController,
|
|
|
|
setter: (pref, value) => pref.setGpsMapProvider(value.index),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setAlbumBrowserShowDate(bool value) => _set<bool>(
|
2023-08-04 21:12:29 +02:00
|
|
|
controller: _isAlbumBrowserShowDateController,
|
|
|
|
setter: (pref, value) => pref.setAlbumBrowserShowDate(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setDoubleTapExit(bool value) => _set<bool>(
|
2023-08-09 16:45:32 +02:00
|
|
|
controller: _isDoubleTapExitController,
|
|
|
|
setter: (pref, value) => pref.setDoubleTapExit(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setSaveEditResultToServer(bool value) => _set<bool>(
|
2023-08-14 17:07:09 +02:00
|
|
|
controller: _isSaveEditResultToServerController,
|
|
|
|
setter: (pref, value) => pref.setSaveEditResultToServer(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setEnhanceMaxSize(SizeInt value) => _set<SizeInt>(
|
2023-08-14 17:07:09 +02:00
|
|
|
controller: _enhanceMaxSizeController,
|
|
|
|
setter: (pref, value) async {
|
|
|
|
return (await Future.wait([
|
|
|
|
pref.setEnhanceMaxWidth(value.width),
|
|
|
|
pref.setEnhanceMaxHeight(value.height),
|
|
|
|
]))
|
|
|
|
.reduce((a, b) => a && b);
|
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setDarkTheme(bool value) => _set<bool>(
|
2023-08-19 18:47:56 +02:00
|
|
|
controller: _isDarkThemeController,
|
|
|
|
setter: (pref, value) => pref.setDarkTheme(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setFollowSystemTheme(bool value) => _set<bool>(
|
2023-08-19 18:47:56 +02:00
|
|
|
controller: _isFollowSystemThemeController,
|
|
|
|
setter: (pref, value) => pref.setFollowSystemTheme(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setUseBlackInDarkTheme(bool value) => _set<bool>(
|
2023-08-19 18:47:56 +02:00
|
|
|
controller: _isUseBlackInDarkThemeController,
|
|
|
|
setter: (pref, value) => pref.setUseBlackInDarkTheme(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setSeedColor(Color? value) => _setOrRemove<Color>(
|
2023-08-19 18:47:56 +02:00
|
|
|
controller: _seedColorController,
|
|
|
|
setter: (pref, value) => pref.setSeedColor(value.withAlpha(0xFF).value),
|
|
|
|
remover: (pref) => pref.setSeedColor(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2023-08-19 18:47:56 +02:00
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setSecondarySeedColor(Color? value) => _setOrRemove<Color>(
|
2024-05-18 16:00:25 +02:00
|
|
|
controller: _secondarySeedColorController,
|
|
|
|
setter: (pref, value) =>
|
|
|
|
pref.setSecondarySeedColor(value.withAlpha(0xFF).value),
|
|
|
|
remover: (pref) => pref.setSecondarySeedColor(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-05-18 16:00:25 +02:00
|
|
|
);
|
|
|
|
|
2024-06-20 18:32:41 +02:00
|
|
|
Future<bool> setDontShowVideoPreviewHint(bool value) => _set<bool>(
|
|
|
|
controller: _isDontShowVideoPreviewHintController,
|
|
|
|
setter: (pref, value) => pref.setDontShowVideoPreviewHint(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-07-22 17:16:26 +02:00
|
|
|
Future<bool> setMapBrowserPrevPosition(MapCoord? value) =>
|
|
|
|
_setOrRemove<MapCoord>(
|
2024-07-19 21:34:46 +02:00
|
|
|
controller: _mapBrowserPrevPositionController,
|
|
|
|
setter: (pref, value) => pref.setMapBrowserPrevPosition(
|
2024-07-22 17:16:26 +02:00
|
|
|
jsonEncode([value.latitude, value.longitude])),
|
|
|
|
remover: (pref) => pref.setMapBrowserPrevPosition(null),
|
2024-07-19 21:34:46 +02:00
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-07-19 21:34:46 +02:00
|
|
|
);
|
|
|
|
|
2024-08-05 19:22:46 +02:00
|
|
|
Future<bool> setNewHttpEngine(bool value) => _set<bool>(
|
|
|
|
controller: _isNewHttpEngineController,
|
|
|
|
setter: (pref, value) => pref.setNewHttpEngine(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-08-17 20:01:59 +02:00
|
|
|
Future<bool> setFirstRunTime(DateTime? value) => _setOrRemove<DateTime>(
|
|
|
|
controller: _firstRunTimeController,
|
|
|
|
setter: (pref, value) =>
|
|
|
|
pref.setFirstRunTime(value.millisecondsSinceEpoch),
|
|
|
|
remover: (pref) => pref.setFirstRunTime(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-08-17 20:01:59 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> setLastVersion(int value) => _set<int>(
|
|
|
|
controller: _lastVersionController,
|
|
|
|
setter: (pref, value) => pref.setLastVersion(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-08-24 13:33:21 +02:00
|
|
|
Future<bool> setMapDefaultRangeType(PrefMapDefaultRangeType value) =>
|
|
|
|
_set<PrefMapDefaultRangeType>(
|
|
|
|
controller: _mapDefaultRangeTypeController,
|
|
|
|
setter: (pref, value) => pref.setMapDefaultRangeType(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-08-24 17:07:25 +02:00
|
|
|
Future<bool> setMapDefaultCustomRange(Duration value) => _set<Duration>(
|
|
|
|
controller: _mapDefaultCustomRangeController,
|
|
|
|
setter: (pref, value) => pref.setMapDefaultCustomRange(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-10-06 19:15:45 +02:00
|
|
|
Future<bool> setSlideshowDuration(Duration value) => _set<Duration>(
|
|
|
|
controller: _slideshowDurationController,
|
|
|
|
setter: (pref, value) => pref.setSlideshowDuration(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> setSlideshowShuffle(bool value) => _set<bool>(
|
|
|
|
controller: _isSlideshowShuffleController,
|
|
|
|
setter: (pref, value) => pref.setSlideshowShuffle(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> setSlideshowRepeat(bool value) => _set<bool>(
|
|
|
|
controller: _isSlideshowRepeatController,
|
|
|
|
setter: (pref, value) => pref.setSlideshowRepeat(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> setSlideshowReverse(bool value) => _set<bool>(
|
|
|
|
controller: _isSlideshowReverseController,
|
|
|
|
setter: (pref, value) => pref.setSlideshowReverse(value),
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
2024-10-20 12:46:35 +02:00
|
|
|
Future<bool> setViewerAppBarButtons(List<ViewerAppBarButtonType>? value) =>
|
|
|
|
_setOrRemove<List<ViewerAppBarButtonType>>(
|
2024-10-09 14:48:19 +02:00
|
|
|
controller: _viewerAppBarButtonsController,
|
|
|
|
setter: (pref, value) => pref.setViewerAppBarButtons(value),
|
2024-10-20 12:46:35 +02:00
|
|
|
remover: (pref) => pref.setViewerAppBarButtons(null),
|
2024-10-09 14:48:19 +02:00
|
|
|
value: value,
|
2024-10-20 12:46:35 +02:00
|
|
|
defaultValue: _viewerAppBarButtonsDefault,
|
2024-10-09 14:48:19 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> setViewerBottomAppBarButtons(
|
2024-10-20 12:46:35 +02:00
|
|
|
List<ViewerAppBarButtonType>? value) =>
|
|
|
|
_setOrRemove<List<ViewerAppBarButtonType>>(
|
2024-10-09 14:48:19 +02:00
|
|
|
controller: _viewerBottomAppBarButtonsController,
|
|
|
|
setter: (pref, value) => pref.setViewerBottomAppBarButtons(value),
|
2024-10-20 12:46:35 +02:00
|
|
|
remover: (pref) => pref.setViewerBottomAppBarButtons(null),
|
2024-10-09 14:48:19 +02:00
|
|
|
value: value,
|
2024-10-20 12:46:35 +02:00
|
|
|
defaultValue: _viewerBottomAppBarButtonsDefault,
|
2024-10-09 14:48:19 +02:00
|
|
|
);
|
|
|
|
|
2024-10-26 15:35:48 +02:00
|
|
|
Future<bool> setHomeCollectionsNavBarButtons(
|
|
|
|
List<PrefHomeCollectionsNavButton>? value) =>
|
|
|
|
_setOrRemove(
|
|
|
|
controller: _homeCollectionsNavBarButtonsController,
|
|
|
|
setter: (pref, value) => pref.setHomeCollectionsNavBarButtonsJson(
|
|
|
|
jsonEncode(value.map((e) => e.toJson()).toList())),
|
|
|
|
remover: (pref) => pref.setHomeCollectionsNavBarButtonsJson(null),
|
|
|
|
value: value,
|
|
|
|
defaultValue: _homeCollectionsNavBarButtonsDefault,
|
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _set<T>({
|
2023-07-27 17:14:50 +02:00
|
|
|
required BehaviorSubject<T> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required T value,
|
2024-05-24 21:35:58 +02:00
|
|
|
}) =>
|
|
|
|
_doSet(
|
2024-08-18 12:07:56 +02:00
|
|
|
pref: pref,
|
2024-05-24 21:35:58 +02:00
|
|
|
controller: controller,
|
|
|
|
setter: setter,
|
|
|
|
value: value,
|
|
|
|
);
|
2023-04-13 17:32:31 +02:00
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _setOrRemove<T>({
|
2023-08-19 18:47:56 +02:00
|
|
|
required BehaviorSubject<T?> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required Future<bool> Function(Pref pref) remover,
|
|
|
|
required T? value,
|
2024-10-20 12:19:07 +02:00
|
|
|
required T? defaultValue,
|
2024-05-24 21:35:58 +02:00
|
|
|
}) =>
|
|
|
|
_doSetOrRemove(
|
2024-08-18 12:07:56 +02:00
|
|
|
pref: pref,
|
2024-05-24 21:35:58 +02:00
|
|
|
controller: controller,
|
|
|
|
setter: setter,
|
|
|
|
remover: remover,
|
|
|
|
value: value,
|
|
|
|
defaultValue: defaultValue,
|
|
|
|
);
|
2023-08-19 18:47:56 +02:00
|
|
|
|
2024-02-25 05:09:57 +01:00
|
|
|
static AppLanguage _langIdToAppLanguage(int langId) {
|
2023-06-06 15:39:58 +02:00
|
|
|
try {
|
2024-02-25 05:09:57 +01:00
|
|
|
return supportedLanguages[langId]!;
|
2023-06-06 15:39:58 +02:00
|
|
|
} catch (_) {
|
2024-02-25 05:09:57 +01:00
|
|
|
return supportedLanguages[0]!;
|
2023-06-06 15:39:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-18 12:07:56 +02:00
|
|
|
final Pref pref;
|
|
|
|
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2024-06-19 15:07:18 +02:00
|
|
|
late final _accountsController =
|
2024-10-20 12:19:07 +02:00
|
|
|
BehaviorSubject.seeded(pref.getAccounts3() ?? _accountsDefault);
|
2024-06-19 15:07:18 +02:00
|
|
|
@npSubjectAccessor
|
2024-08-17 20:01:59 +02:00
|
|
|
late final _currentAccountIndexController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getCurrentAccountIndex());
|
2024-08-17 20:01:59 +02:00
|
|
|
@npSubjectAccessor
|
2023-06-06 15:39:58 +02:00
|
|
|
late final _languageController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(_langIdToAppLanguage(pref.getLanguageOr(0)));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2024-01-12 19:53:14 +01:00
|
|
|
late final _homePhotosZoomLevelController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getHomePhotosZoomLevelOr(0));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-04-13 17:32:31 +02:00
|
|
|
late final _albumBrowserZoomLevelController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getAlbumBrowserZoomLevelOr(0));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2024-06-13 17:50:40 +02:00
|
|
|
late final _homeAlbumsSortController = BehaviorSubject.seeded(
|
2024-08-18 12:07:56 +02:00
|
|
|
CollectionSort.values[pref.getHomeAlbumsSortOr(0)]);
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2024-11-23 16:04:13 +01:00
|
|
|
late final _isEnableClientExifController =
|
|
|
|
BehaviorSubject.seeded(pref.isEnableClientExif() ?? true);
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-07-27 17:14:50 +02:00
|
|
|
late final _shouldProcessExifWifiOnlyController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.shouldProcessExifWifiOnlyOr(true));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-07-27 18:51:57 +02:00
|
|
|
late final _memoriesRangeController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getMemoriesRangeOr(2));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-04 21:11:41 +02:00
|
|
|
late final _viewerScreenBrightnessController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getViewerScreenBrightnessOr(-1));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-04 21:11:41 +02:00
|
|
|
late final _isViewerForceRotationController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isViewerForceRotationOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-04 21:11:41 +02:00
|
|
|
late final _gpsMapProviderController = BehaviorSubject.seeded(
|
2024-08-18 12:07:56 +02:00
|
|
|
GpsMapProvider.values[pref.getGpsMapProviderOr(0)]);
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-04 21:12:29 +02:00
|
|
|
late final _isAlbumBrowserShowDateController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isAlbumBrowserShowDateOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-09 16:45:32 +02:00
|
|
|
late final _isDoubleTapExitController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isDoubleTapExitOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-14 17:07:09 +02:00
|
|
|
late final _isSaveEditResultToServerController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isSaveEditResultToServerOr(true));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-14 17:07:09 +02:00
|
|
|
late final _enhanceMaxSizeController = BehaviorSubject.seeded(
|
2024-08-18 12:07:56 +02:00
|
|
|
SizeInt(pref.getEnhanceMaxWidthOr(), pref.getEnhanceMaxHeightOr()));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-19 18:47:56 +02:00
|
|
|
late final _isDarkThemeController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isDarkThemeOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-19 18:47:56 +02:00
|
|
|
late final _isFollowSystemThemeController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isFollowSystemThemeOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@npSubjectAccessor
|
2023-08-19 18:47:56 +02:00
|
|
|
late final _isUseBlackInDarkThemeController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isUseBlackInDarkThemeOr(false));
|
2024-02-25 05:09:57 +01:00
|
|
|
@NpSubjectAccessor(type: "Color?")
|
2023-09-04 18:28:53 +02:00
|
|
|
late final _seedColorController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject<Color?>.seeded(pref.getSeedColor()?.let(Color.new));
|
2024-05-18 16:00:25 +02:00
|
|
|
@NpSubjectAccessor(type: "Color?")
|
|
|
|
late final _secondarySeedColorController = BehaviorSubject<Color?>.seeded(
|
2024-08-18 12:07:56 +02:00
|
|
|
pref.getSecondarySeedColor()?.let(Color.new));
|
2024-06-20 18:32:41 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _isDontShowVideoPreviewHintController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isDontShowVideoPreviewHintOr(false));
|
2024-07-19 21:34:46 +02:00
|
|
|
@npSubjectAccessor
|
2024-08-18 12:07:56 +02:00
|
|
|
late final _mapBrowserPrevPositionController = BehaviorSubject.seeded(pref
|
2024-07-22 17:16:26 +02:00
|
|
|
.getMapBrowserPrevPosition()
|
|
|
|
?.let(tryJsonDecode)
|
|
|
|
?.let(_tryMapCoordFromJson));
|
2024-08-05 19:22:46 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _isNewHttpEngineController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.isNewHttpEngine() ?? false);
|
2024-08-17 20:01:59 +02:00
|
|
|
@npSubjectAccessor
|
2024-08-18 12:07:56 +02:00
|
|
|
late final _firstRunTimeController = BehaviorSubject.seeded(pref
|
2024-08-17 20:01:59 +02:00
|
|
|
.getFirstRunTime()
|
|
|
|
?.let((v) => DateTime.fromMillisecondsSinceEpoch(v).toUtc()));
|
|
|
|
@npSubjectAccessor
|
|
|
|
late final _lastVersionController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(pref.getLastVersion() ??
|
2024-08-17 20:01:59 +02:00
|
|
|
// v6 is the last version without saving the version number in pref
|
2024-08-18 12:07:56 +02:00
|
|
|
(pref.getSetupProgress() == null ? k.version : 6));
|
2024-08-24 13:33:21 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _mapDefaultRangeTypeController = BehaviorSubject.seeded(
|
|
|
|
pref.getMapDefaultRangeType() ?? PrefMapDefaultRangeType.thisMonth);
|
2024-08-24 17:07:25 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _mapDefaultCustomRangeController = BehaviorSubject.seeded(
|
|
|
|
pref.getMapDefaultCustomRange() ?? const Duration(days: 30));
|
2024-10-06 19:15:45 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _slideshowDurationController = BehaviorSubject.seeded(
|
|
|
|
pref.getSlideshowDuration() ?? const Duration(seconds: 5));
|
|
|
|
@npSubjectAccessor
|
|
|
|
late final _isSlideshowShuffleController =
|
|
|
|
BehaviorSubject.seeded(pref.isSlideshowShuffle() ?? false);
|
|
|
|
@npSubjectAccessor
|
|
|
|
late final _isSlideshowRepeatController =
|
|
|
|
BehaviorSubject.seeded(pref.isSlideshowRepeat() ?? false);
|
|
|
|
@npSubjectAccessor
|
|
|
|
late final _isSlideshowReverseController =
|
|
|
|
BehaviorSubject.seeded(pref.isSlideshowReverse() ?? false);
|
2024-10-09 14:48:19 +02:00
|
|
|
@npSubjectAccessor
|
2024-10-20 12:46:35 +02:00
|
|
|
late final _viewerAppBarButtonsController = BehaviorSubject.seeded(
|
|
|
|
pref.getViewerAppBarButtons() ?? _viewerAppBarButtonsDefault);
|
|
|
|
@npSubjectAccessor
|
|
|
|
late final _viewerBottomAppBarButtonsController = BehaviorSubject.seeded(
|
|
|
|
pref.getViewerBottomAppBarButtons() ?? _viewerBottomAppBarButtonsDefault);
|
2024-10-26 15:35:48 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _homeCollectionsNavBarButtonsController = BehaviorSubject.seeded(
|
|
|
|
pref.getHomeCollectionsNavBarButtonsJson()?.let((s) =>
|
|
|
|
(jsonDecode(s) as List)
|
|
|
|
.cast<JsonObj>()
|
|
|
|
.map(PrefHomeCollectionsNavButton.fromJson)
|
|
|
|
.toList()) ??
|
|
|
|
_homeCollectionsNavBarButtonsDefault);
|
2024-08-17 20:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension PrefControllerExtension on PrefController {
|
|
|
|
Account? get currentAccountValue {
|
|
|
|
try {
|
|
|
|
return accountsValue[currentAccountIndexValue!];
|
|
|
|
} catch (_) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2023-04-13 17:32:31 +02:00
|
|
|
}
|
2024-05-24 21:35:58 +02:00
|
|
|
|
2024-05-25 09:51:42 +02:00
|
|
|
@npSubjectAccessor
|
2024-05-24 21:35:58 +02:00
|
|
|
class SecurePrefController {
|
2024-08-18 12:07:56 +02:00
|
|
|
SecurePrefController(this.securePref);
|
2024-05-24 21:35:58 +02:00
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setProtectedPageAuthType(ProtectedPageAuthType? value) =>
|
2024-05-25 09:51:42 +02:00
|
|
|
_setOrRemove<ProtectedPageAuthType>(
|
|
|
|
controller: _protectedPageAuthTypeController,
|
|
|
|
setter: (pref, value) => pref.setProtectedPageAuthType(value.index),
|
|
|
|
remover: (pref) => pref.setProtectedPageAuthType(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-05-25 09:51:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setProtectedPageAuthPin(CiString? value) =>
|
2024-05-25 09:51:42 +02:00
|
|
|
_setOrRemove<CiString>(
|
|
|
|
controller: _protectedPageAuthPinController,
|
|
|
|
setter: (pref, value) =>
|
|
|
|
pref.setProtectedPageAuthPin(value.toCaseInsensitiveString()),
|
|
|
|
remover: (pref) => pref.setProtectedPageAuthPin(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-05-25 09:51:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> setProtectedPageAuthPassword(CiString? value) =>
|
2024-05-25 09:51:42 +02:00
|
|
|
_setOrRemove<CiString>(
|
|
|
|
controller: _protectedPageAuthPasswordController,
|
|
|
|
setter: (pref, value) =>
|
|
|
|
pref.setProtectedPageAuthPassword(value.toCaseInsensitiveString()),
|
|
|
|
remover: (pref) => pref.setProtectedPageAuthPassword(null),
|
|
|
|
value: value,
|
2024-10-20 12:19:07 +02:00
|
|
|
defaultValue: null,
|
2024-05-25 09:51:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-24 21:35:58 +02:00
|
|
|
// ignore: unused_element
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _set<T>({
|
2024-05-24 21:35:58 +02:00
|
|
|
required BehaviorSubject<T> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required T value,
|
|
|
|
}) =>
|
|
|
|
_doSet(
|
2024-08-18 12:07:56 +02:00
|
|
|
pref: securePref,
|
2024-05-24 21:35:58 +02:00
|
|
|
controller: controller,
|
|
|
|
setter: setter,
|
|
|
|
value: value,
|
|
|
|
);
|
|
|
|
|
|
|
|
// ignore: unused_element
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _setOrRemove<T>({
|
2024-05-24 21:35:58 +02:00
|
|
|
required BehaviorSubject<T?> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required Future<bool> Function(Pref pref) remover,
|
|
|
|
required T? value,
|
2024-10-20 12:19:07 +02:00
|
|
|
required T? defaultValue,
|
2024-05-24 21:35:58 +02:00
|
|
|
}) =>
|
|
|
|
_doSetOrRemove(
|
2024-08-18 12:07:56 +02:00
|
|
|
pref: securePref,
|
2024-05-24 21:35:58 +02:00
|
|
|
controller: controller,
|
|
|
|
setter: setter,
|
|
|
|
remover: remover,
|
|
|
|
value: value,
|
|
|
|
defaultValue: defaultValue,
|
|
|
|
);
|
|
|
|
|
2024-08-18 12:07:56 +02:00
|
|
|
final Pref securePref;
|
|
|
|
|
2024-05-25 09:51:42 +02:00
|
|
|
@npSubjectAccessor
|
2024-08-18 12:07:56 +02:00
|
|
|
late final _protectedPageAuthTypeController = BehaviorSubject.seeded(
|
|
|
|
securePref
|
|
|
|
.getProtectedPageAuthType()
|
|
|
|
?.let((e) => ProtectedPageAuthType.values[e]));
|
2024-05-25 09:51:42 +02:00
|
|
|
@npSubjectAccessor
|
|
|
|
late final _protectedPageAuthPinController =
|
2024-08-18 12:07:56 +02:00
|
|
|
BehaviorSubject.seeded(securePref.getProtectedPageAuthPin()?.toCi());
|
2024-05-25 09:51:42 +02:00
|
|
|
@npSubjectAccessor
|
2024-08-18 12:07:56 +02:00
|
|
|
late final _protectedPageAuthPasswordController =
|
|
|
|
BehaviorSubject.seeded(securePref.getProtectedPageAuthPassword()?.toCi());
|
2024-05-24 21:35:58 +02:00
|
|
|
}
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _doSet<T>({
|
2024-05-24 21:35:58 +02:00
|
|
|
required Pref pref,
|
|
|
|
required BehaviorSubject<T> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required T value,
|
|
|
|
}) async {
|
|
|
|
final backup = controller.value;
|
|
|
|
controller.add(value);
|
|
|
|
try {
|
|
|
|
if (!await setter(pref, value)) {
|
|
|
|
throw StateError("Unknown error");
|
|
|
|
}
|
2024-05-26 12:40:22 +02:00
|
|
|
return true;
|
2024-05-24 21:35:58 +02:00
|
|
|
} catch (e, stackTrace) {
|
|
|
|
_$__NpLog.log.severe("[_doSet] Failed setting preference", e, stackTrace);
|
|
|
|
controller
|
|
|
|
..addError(e, stackTrace)
|
|
|
|
..add(backup);
|
2024-05-26 12:40:22 +02:00
|
|
|
return false;
|
2024-05-24 21:35:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-26 12:40:22 +02:00
|
|
|
Future<bool> _doSetOrRemove<T>({
|
2024-05-24 21:35:58 +02:00
|
|
|
required Pref pref,
|
|
|
|
required BehaviorSubject<T?> controller,
|
|
|
|
required Future<bool> Function(Pref pref, T value) setter,
|
|
|
|
required Future<bool> Function(Pref pref) remover,
|
|
|
|
required T? value,
|
2024-10-20 12:19:07 +02:00
|
|
|
required T? defaultValue,
|
2024-05-24 21:35:58 +02:00
|
|
|
}) async {
|
|
|
|
final backup = controller.value;
|
|
|
|
controller.add(value ?? defaultValue);
|
|
|
|
try {
|
|
|
|
if (value == null) {
|
|
|
|
if (!await remover(pref)) {
|
|
|
|
throw StateError("Unknown error");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!await setter(pref, value)) {
|
|
|
|
throw StateError("Unknown error");
|
|
|
|
}
|
|
|
|
}
|
2024-05-26 12:40:22 +02:00
|
|
|
return true;
|
2024-05-24 21:35:58 +02:00
|
|
|
} catch (e, stackTrace) {
|
|
|
|
_$__NpLog.log
|
|
|
|
.severe("[_doSetOrRemove] Failed setting preference", e, stackTrace);
|
|
|
|
controller
|
|
|
|
..addError(e, stackTrace)
|
|
|
|
..add(backup);
|
2024-05-26 12:40:22 +02:00
|
|
|
return false;
|
2024-05-24 21:35:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-20 12:19:07 +02:00
|
|
|
const _accountsDefault = <Account>[];
|
2024-10-20 12:46:35 +02:00
|
|
|
const _viewerAppBarButtonsDefault = [
|
|
|
|
ViewerAppBarButtonType.livePhoto,
|
|
|
|
ViewerAppBarButtonType.favorite,
|
|
|
|
];
|
|
|
|
const _viewerBottomAppBarButtonsDefault = [
|
|
|
|
ViewerAppBarButtonType.share,
|
|
|
|
ViewerAppBarButtonType.edit,
|
|
|
|
ViewerAppBarButtonType.enhance,
|
|
|
|
ViewerAppBarButtonType.download,
|
|
|
|
ViewerAppBarButtonType.delete,
|
|
|
|
];
|
2024-10-26 15:35:48 +02:00
|
|
|
const _homeCollectionsNavBarButtonsDefault = [
|
2024-10-26 21:31:01 +02:00
|
|
|
PrefHomeCollectionsNavButton(
|
|
|
|
type: HomeCollectionsNavBarButtonType.map,
|
|
|
|
isMinimized: false,
|
|
|
|
),
|
2024-10-26 15:35:48 +02:00
|
|
|
PrefHomeCollectionsNavButton(
|
|
|
|
type: HomeCollectionsNavBarButtonType.sharing,
|
|
|
|
isMinimized: false,
|
|
|
|
),
|
|
|
|
PrefHomeCollectionsNavButton(
|
|
|
|
type: HomeCollectionsNavBarButtonType.edited,
|
|
|
|
isMinimized: false,
|
|
|
|
),
|
|
|
|
PrefHomeCollectionsNavButton(
|
|
|
|
type: HomeCollectionsNavBarButtonType.archive,
|
|
|
|
isMinimized: false,
|
|
|
|
),
|
|
|
|
PrefHomeCollectionsNavButton(
|
|
|
|
type: HomeCollectionsNavBarButtonType.trash,
|
|
|
|
isMinimized: false,
|
|
|
|
),
|
|
|
|
];
|
2024-10-20 12:19:07 +02:00
|
|
|
|
2024-05-24 21:35:58 +02:00
|
|
|
@npLog
|
|
|
|
// ignore: camel_case_types
|
|
|
|
class __ {}
|