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> {
|
|
|
|
threeStageLoading<bool>("threeStageLoading", false),
|
|
|
|
themeMode<String>("themeMode", "system"), // "light","dark","system"
|
|
|
|
tilesPerRow<int>("tilesPerRow", 4),
|
2022-08-21 18:29:24 +02:00
|
|
|
uploadErrorNotificationGracePeriod<int>(
|
|
|
|
"uploadErrorNotificationGracePeriod", 2),
|
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
|
|
|
}
|
|
|
|
}
|