mirror of https://github.com/immich-app/immich.git
refactor(mobile): migrate all Hive boxes to Isar database (#2036)
parent
0616a66b05
commit
eccde8fa07
@ -1,59 +1,63 @@
|
|||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:immich_mobile/shared/models/store.dart';
|
||||||
import 'package:immich_mobile/constants/hive_box.dart';
|
|
||||||
|
|
||||||
enum AppSettingsEnum<T> {
|
enum AppSettingsEnum<T> {
|
||||||
loadPreview<bool>("loadPreview", true),
|
loadPreview<bool>(StoreKey.loadPreview, "loadPreview", true),
|
||||||
loadOriginal<bool>("loadOriginal", false),
|
loadOriginal<bool>(StoreKey.loadOriginal, "loadOriginal", false),
|
||||||
themeMode<String>("themeMode", "system"), // "light","dark","system"
|
themeMode<String>(
|
||||||
tilesPerRow<int>("tilesPerRow", 4),
|
StoreKey.themeMode,
|
||||||
dynamicLayout<bool>("dynamicLayout", false),
|
"themeMode",
|
||||||
groupAssetsBy<int>("groupBy", 0),
|
"system",
|
||||||
|
), // "light","dark","system"
|
||||||
|
tilesPerRow<int>(StoreKey.tilesPerRow, "tilesPerRow", 4),
|
||||||
|
dynamicLayout<bool>(StoreKey.dynamicLayout, "dynamicLayout", false),
|
||||||
|
groupAssetsBy<int>(StoreKey.groupAssetsBy, "groupBy", 0),
|
||||||
uploadErrorNotificationGracePeriod<int>(
|
uploadErrorNotificationGracePeriod<int>(
|
||||||
|
StoreKey.uploadErrorNotificationGracePeriod,
|
||||||
"uploadErrorNotificationGracePeriod",
|
"uploadErrorNotificationGracePeriod",
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
backgroundBackupTotalProgress<bool>("backgroundBackupTotalProgress", true),
|
backgroundBackupTotalProgress<bool>(
|
||||||
backgroundBackupSingleProgress<bool>("backgroundBackupSingleProgress", false),
|
StoreKey.backgroundBackupTotalProgress,
|
||||||
storageIndicator<bool>("storageIndicator", true),
|
"backgroundBackupTotalProgress",
|
||||||
thumbnailCacheSize<int>("thumbnailCacheSize", 10000),
|
true,
|
||||||
imageCacheSize<int>("imageCacheSize", 350),
|
),
|
||||||
albumThumbnailCacheSize<int>("albumThumbnailCacheSize", 200),
|
backgroundBackupSingleProgress<bool>(
|
||||||
useExperimentalAssetGrid<bool>("useExperimentalAssetGrid", false),
|
StoreKey.backgroundBackupSingleProgress,
|
||||||
selectedAlbumSortOrder<int>("selectedAlbumSortOrder", 0);
|
"backgroundBackupSingleProgress",
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
storageIndicator<bool>(StoreKey.storageIndicator, "storageIndicator", true),
|
||||||
|
thumbnailCacheSize<int>(
|
||||||
|
StoreKey.thumbnailCacheSize,
|
||||||
|
"thumbnailCacheSize",
|
||||||
|
10000,
|
||||||
|
),
|
||||||
|
imageCacheSize<int>(StoreKey.imageCacheSize, "imageCacheSize", 350),
|
||||||
|
albumThumbnailCacheSize<int>(
|
||||||
|
StoreKey.albumThumbnailCacheSize,
|
||||||
|
"albumThumbnailCacheSize",
|
||||||
|
200,
|
||||||
|
),
|
||||||
|
selectedAlbumSortOrder<int>(
|
||||||
|
StoreKey.selectedAlbumSortOrder,
|
||||||
|
"selectedAlbumSortOrder",
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
;
|
||||||
|
|
||||||
const AppSettingsEnum(this.hiveKey, this.defaultValue);
|
const AppSettingsEnum(this.storeKey, this.hiveKey, this.defaultValue);
|
||||||
|
|
||||||
|
final StoreKey<T> storeKey;
|
||||||
final String hiveKey;
|
final String hiveKey;
|
||||||
final T defaultValue;
|
final T defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppSettingsService {
|
class AppSettingsService {
|
||||||
late final Box hiveBox;
|
T getSetting<T>(AppSettingsEnum<T> setting) {
|
||||||
|
return Store.get(setting.storeKey, setting.defaultValue);
|
||||||
AppSettingsService() {
|
|
||||||
hiveBox = Hive.box(userSettingInfoBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
T getSetting<T>(AppSettingsEnum<T> 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<T>(AppSettingsEnum<T> settingType, T value) {
|
|
||||||
hiveBox.put(settingType.hiveKey, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T _setDefault<T>(AppSettingsEnum<T> settingType) {
|
void setSetting<T>(AppSettingsEnum<T> setting, T value) {
|
||||||
hiveBox.put(settingType.hiveKey, settingType.defaultValue);
|
Store.put(setting.storeKey, value);
|
||||||
return settingType.defaultValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
// ignore_for_file: constant_identifier_names
|
||||||
|
|
||||||
|
import 'package:isar/isar.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
|
part 'logger_message.model.g.dart';
|
||||||
|
|
||||||
|
@Collection(inheritance: false)
|
||||||
|
class LoggerMessage {
|
||||||
|
Id id = Isar.autoIncrement;
|
||||||
|
String message;
|
||||||
|
@Enumerated(EnumType.ordinal)
|
||||||
|
LogLevel level = LogLevel.INFO;
|
||||||
|
DateTime createdAt;
|
||||||
|
String? context1;
|
||||||
|
String? context2;
|
||||||
|
|
||||||
|
LoggerMessage({
|
||||||
|
required this.message,
|
||||||
|
required this.level,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.context1,
|
||||||
|
required this.context2,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'InAppLoggerMessage(message: $message, level: $level, createdAt: $createdAt)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Log levels according to dart logging [Level]
|
||||||
|
enum LogLevel {
|
||||||
|
ALL,
|
||||||
|
FINEST,
|
||||||
|
FINER,
|
||||||
|
FINE,
|
||||||
|
CONFIG,
|
||||||
|
INFO,
|
||||||
|
WARNING,
|
||||||
|
SEVERE,
|
||||||
|
SHOUT,
|
||||||
|
OFF,
|
||||||
|
}
|
||||||
|
|
||||||
|
extension LevelExtension on Level {
|
||||||
|
LogLevel toLogLevel() => LogLevel.values[Level.LEVELS.indexOf(this)];
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue