import 'package:hive_flutter/hive_flutter.dart'; import 'package:immich_mobile/constants/hive_box.dart'; enum AppSettingsEnum { loadPreview("loadPreview", true), loadOriginal("loadOriginal", false), themeMode("themeMode", "system"), // "light","dark","system" tilesPerRow("tilesPerRow", 4), uploadErrorNotificationGracePeriod( "uploadErrorNotificationGracePeriod", 2, ), backgroundBackupTotalProgress("backgroundBackupTotalProgress", true), backgroundBackupSingleProgress("backgroundBackupSingleProgress", false), storageIndicator("storageIndicator", true), thumbnailCacheSize("thumbnailCacheSize", 10000), imageCacheSize("imageCacheSize", 350), albumThumbnailCacheSize("albumThumbnailCacheSize", 200), useExperimentalAssetGrid("useExperimentalAssetGrid", false); const AppSettingsEnum(this.hiveKey, this.defaultValue); final String hiveKey; final T defaultValue; } class AppSettingsService { late final Box hiveBox; AppSettingsService() { hiveBox = Hive.box(userSettingInfoBox); } T getSetting(AppSettingsEnum settingType) { if (!hiveBox.containsKey(settingType.hiveKey)) { return _setDefault(settingType); } var result = hiveBox.get(settingType.hiveKey); if (result is! T) { return _setDefault(settingType); } return result; } setSetting(AppSettingsEnum settingType, T value) { hiveBox.put(settingType.hiveKey, value); } T _setDefault(AppSettingsEnum settingType) { hiveBox.put(settingType.hiveKey, settingType.defaultValue); return settingType.defaultValue; } }