ente/mobile/lib/utils/local_settings.dart

94 lines
2.7 KiB
Dart
Raw Normal View History

import 'package:photos/core/constants.dart';
import 'package:shared_preferences/shared_preferences.dart';
enum AlbumSortKey {
albumName,
2022-04-28 13:08:27 +00:00
newestPhoto,
2021-09-08 20:19:25 +00:00
lastUpdated,
}
class LocalSettings {
LocalSettings._privateConstructor();
static final LocalSettings instance = LocalSettings._privateConstructor();
static const kCollectionSortPref = "collection_sort_pref";
2022-12-07 03:18:41 +00:00
static const kPhotoGridSize = "photo_grid_size";
2023-10-13 07:46:56 +00:00
static const kEnableMagicSearch = "enable_magic_search";
static const kEnableFaceIndexing = "enable_face_indexing";
static const kEnableFaceClustering = "enable_face_clustering";
2023-11-14 21:30:21 +00:00
static const kRateUsShownCount = "rate_us_shown_count";
static const kRateUsPromptThreshold = 2;
2022-09-20 13:13:55 +00:00
late SharedPreferences _prefs;
void init(SharedPreferences preferences) {
_prefs = preferences;
}
AlbumSortKey albumSortKey() {
2022-09-20 13:13:55 +00:00
return AlbumSortKey.values[_prefs.getInt(kCollectionSortPref) ?? 0];
}
2021-09-11 07:01:47 +00:00
Future<bool> setAlbumSortKey(AlbumSortKey key) {
return _prefs.setInt(kCollectionSortPref, key.index);
}
2022-12-07 03:18:41 +00:00
int getPhotoGridSize() {
if (_prefs.containsKey(kPhotoGridSize)) {
return _prefs.getInt(kPhotoGridSize)!;
} else {
2022-12-07 05:20:41 +00:00
return photoGridSizeDefault;
}
}
2022-12-07 03:18:41 +00:00
Future<void> setPhotoGridSize(int value) async {
await _prefs.setInt(kPhotoGridSize, value);
}
2023-10-13 07:46:56 +00:00
bool hasEnabledMagicSearch() {
// TODO: change this back by uncommenting the line below
// if (_prefs.containsKey(kEnableMagicSearch)) {
// return _prefs.getBool(kEnableMagicSearch)!;
// }
2023-11-14 13:56:45 +00:00
return false;
2023-10-13 07:46:56 +00:00
}
Future<void> setShouldEnableMagicSearch(bool value) async {
await _prefs.setBool(kEnableMagicSearch, value);
}
2023-11-16 13:30:32 +00:00
2023-11-14 21:30:21 +00:00
int getRateUsShownCount() {
if (_prefs.containsKey(kRateUsShownCount)) {
return _prefs.getInt(kRateUsShownCount)!;
} else {
return 0;
}
}
Future<void> setRateUsShownCount(int value) async {
await _prefs.setInt(kRateUsShownCount, value);
}
bool shouldPromptToRateUs() {
return getRateUsShownCount() < kRateUsPromptThreshold;
}
bool get isFaceIndexingEnabled =>
_prefs.getBool(kEnableFaceIndexing) ?? false;
bool get isFaceClusteringEnabled =>
_prefs.getBool(kEnableFaceIndexing) ?? false;
/// toggleFaceIndexing toggles the face indexing setting and returns the new value
Future<bool> toggleFaceIndexing() async {
await _prefs.setBool(kEnableFaceIndexing, !isFaceIndexingEnabled);
return isFaceIndexingEnabled;
}
/// toggleFaceClustering toggles the face clustering setting and returns the new value
Future<bool> toggleFaceClustering() async {
await _prefs.setBool(kEnableFaceClustering, !isFaceClusteringEnabled);
return isFaceClusteringEnabled;
}
}