2022-08-13 22:51:09 +02:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
enum AppSettingsEnum<T> {
|
2022-12-02 22:55:10 +02:00
|
|
|
loadPreview<bool>("loadPreview", true),
|
|
|
|
loadOriginal<bool>("loadOriginal", false),
|
2022-08-20 23:19:40 +02:00
|
|
|
themeMode<String>("themeMode", "system"), // "light","dark","system"
|
|
|
|
tilesPerRow<int>("tilesPerRow", 4),
|
2023-02-09 19:35:44 +02:00
|
|
|
dynamicLayout<bool>("dynamicLayout", false),
|
|
|
|
groupAssetsBy<int>("groupBy", 0),
|
2022-08-21 18:29:24 +02:00
|
|
|
uploadErrorNotificationGracePeriod<int>(
|
2022-10-05 16:59:35 +02:00
|
|
|
"uploadErrorNotificationGracePeriod",
|
|
|
|
2,
|
|
|
|
),
|
|
|
|
backgroundBackupTotalProgress<bool>("backgroundBackupTotalProgress", true),
|
|
|
|
backgroundBackupSingleProgress<bool>("backgroundBackupSingleProgress", false),
|
2022-08-30 05:44:43 +02:00
|
|
|
storageIndicator<bool>("storageIndicator", true),
|
|
|
|
thumbnailCacheSize<int>("thumbnailCacheSize", 10000),
|
|
|
|
imageCacheSize<int>("imageCacheSize", 350),
|
2022-09-28 18:30:38 +02:00
|
|
|
albumThumbnailCacheSize<int>("albumThumbnailCacheSize", 200),
|
|
|
|
useExperimentalAssetGrid<bool>("useExperimentalAssetGrid", false);
|
2022-08-20 23:19:40 +02:00
|
|
|
|
|
|
|
const AppSettingsEnum(this.hiveKey, this.defaultValue);
|
|
|
|
|
|
|
|
final String hiveKey;
|
|
|
|
final T defaultValue;
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class AppSettingsService {
|
|
|
|
late final Box hiveBox;
|
|
|
|
|
|
|
|
AppSettingsService() {
|
|
|
|
hiveBox = Hive.box(userSettingInfoBox);
|
|
|
|
}
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
T getSetting<T>(AppSettingsEnum<T> settingType) {
|
|
|
|
if (!hiveBox.containsKey(settingType.hiveKey)) {
|
|
|
|
return _setDefault(settingType);
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
var result = hiveBox.get(settingType.hiveKey);
|
2022-08-13 22:51:09 +02:00
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
if (result is! T) {
|
|
|
|
return _setDefault(settingType);
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
return result;
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
setSetting<T>(AppSettingsEnum<T> settingType, T value) {
|
|
|
|
hiveBox.put(settingType.hiveKey, value);
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-20 23:19:40 +02:00
|
|
|
T _setDefault<T>(AppSettingsEnum<T> settingType) {
|
|
|
|
hiveBox.put(settingType.hiveKey, settingType.defaultValue);
|
|
|
|
return settingType.defaultValue;
|
2022-08-13 22:51:09 +02:00
|
|
|
}
|
|
|
|
}
|