mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor to per row store
This commit is contained in:
@@ -1,33 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/domain/models/config/theme_config.dart';
|
||||
import 'package:immich_mobile/domain/models/metadata_value.dart';
|
||||
import 'package:immich_mobile/extensions/json_extensions.dart';
|
||||
|
||||
class AppConfig implements MetadataValue {
|
||||
static const String name = 'app-config';
|
||||
|
||||
class AppConfig {
|
||||
final ThemeConfig theme;
|
||||
|
||||
const AppConfig({this.theme = const ThemeConfig()});
|
||||
|
||||
factory AppConfig.fromJson(Map<String, Object?> json) {
|
||||
final themeJson = json.nested(ThemeConfig.name);
|
||||
return AppConfig(
|
||||
theme: ThemeConfig(
|
||||
mode: ThemeMode.values.firstWhere(
|
||||
(e) => e.name == themeJson[ThemeConfig.keys.mode],
|
||||
orElse: () => ThemeMode.system,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Object?> toJson() => {
|
||||
ThemeConfig.name: {ThemeConfig.keys.mode: theme.mode.name},
|
||||
};
|
||||
|
||||
AppConfig copyWith({ThemeMode? themeMode}) => AppConfig(theme: ThemeConfig(mode: themeMode ?? theme.mode));
|
||||
AppConfig copyWith({ThemeConfig? theme}) => .new(theme: theme ?? this.theme);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || (other is AppConfig && other.theme == theme);
|
||||
@@ -36,5 +14,5 @@ class AppConfig implements MetadataValue {
|
||||
int get hashCode => theme.hashCode;
|
||||
|
||||
@override
|
||||
String toString() => '$name: { $theme }';
|
||||
String toString() => 'AppConfig(theme: $theme)';
|
||||
}
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
import 'package:immich_mobile/domain/models/log.model.dart';
|
||||
|
||||
class _Keys {
|
||||
const _Keys();
|
||||
|
||||
final level = 'level';
|
||||
}
|
||||
|
||||
class LogConfig {
|
||||
static const String name = 'log';
|
||||
|
||||
// ignore: library_private_types_in_public_api
|
||||
static const _Keys keys = _Keys();
|
||||
|
||||
final LogLevel level;
|
||||
|
||||
const LogConfig({this.level = LogLevel.info});
|
||||
const LogConfig({this.level = .info});
|
||||
|
||||
LogConfig copyWith({LogLevel? level}) => .new(level: level ?? this.level);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || (other is LogConfig && other.level == level);
|
||||
@@ -23,5 +14,5 @@ class LogConfig {
|
||||
int get hashCode => level.hashCode;
|
||||
|
||||
@override
|
||||
String toString() => '$name: {${keys.level}: $level}';
|
||||
String toString() => 'LogConfig(level: $level)';
|
||||
}
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
import 'package:immich_mobile/domain/models/config/log_config.dart';
|
||||
import 'package:immich_mobile/domain/models/log.model.dart';
|
||||
import 'package:immich_mobile/domain/models/metadata_value.dart';
|
||||
import 'package:immich_mobile/extensions/json_extensions.dart';
|
||||
|
||||
class SystemConfig implements MetadataValue {
|
||||
static const String name = 'system-config';
|
||||
|
||||
class SystemConfig {
|
||||
final LogConfig log;
|
||||
|
||||
const SystemConfig({this.log = const LogConfig()});
|
||||
const SystemConfig({this.log = const .new()});
|
||||
|
||||
factory SystemConfig.fromJson(Map<String, Object?> json) {
|
||||
final logJson = json.nested(LogConfig.name);
|
||||
return SystemConfig(
|
||||
log: LogConfig(
|
||||
level: LogLevel.values.firstWhere((e) => e.name == logJson[LogConfig.keys.level], orElse: () => LogLevel.info),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Object?> toJson() => {
|
||||
LogConfig.name: {LogConfig.keys.level: log.level.name},
|
||||
};
|
||||
|
||||
SystemConfig copyWith({LogLevel? logLevel}) => SystemConfig(log: LogConfig(level: logLevel ?? log.level));
|
||||
SystemConfig copyWith({LogConfig? log}) => .new(log: log ?? this.log);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || (other is SystemConfig && other.log == log);
|
||||
@@ -33,5 +14,5 @@ class SystemConfig implements MetadataValue {
|
||||
int get hashCode => log.hashCode;
|
||||
|
||||
@override
|
||||
String toString() => '$name: { $log }';
|
||||
String toString() => 'SystemConfig(log: $log)';
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class _Keys {
|
||||
const _Keys();
|
||||
|
||||
final mode = 'mode';
|
||||
}
|
||||
|
||||
class ThemeConfig {
|
||||
static const String name = 'theme';
|
||||
// ignore: library_private_types_in_public_api
|
||||
static const _Keys keys = _Keys();
|
||||
|
||||
final ThemeMode mode;
|
||||
|
||||
const ThemeConfig({this.mode = ThemeMode.system});
|
||||
const ThemeConfig({this.mode = .system});
|
||||
|
||||
ThemeConfig copyWith({ThemeMode? mode}) => .new(mode: mode ?? this.mode);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || (other is ThemeConfig && other.mode == mode);
|
||||
@@ -22,5 +14,5 @@ class ThemeConfig {
|
||||
int get hashCode => mode.hashCode;
|
||||
|
||||
@override
|
||||
String toString() => '$name: {${keys.mode}: $mode}';
|
||||
String toString() => 'ThemeConfig(mode: $mode)';
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import 'package:immich_mobile/domain/models/metadata_value.dart';
|
||||
|
||||
class SystemMetadata implements MetadataValue {
|
||||
static const String name = 'system-metadata';
|
||||
|
||||
const SystemMetadata();
|
||||
|
||||
factory SystemMetadata.fromJson(Map<String, Object?> json) => const SystemMetadata();
|
||||
|
||||
@override
|
||||
Map<String, Object?> toJson() => const {};
|
||||
|
||||
SystemMetadata copyWith() => this;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is SystemMetadata;
|
||||
|
||||
@override
|
||||
int get hashCode => 0;
|
||||
|
||||
@override
|
||||
String toString() => '$name: {}';
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/domain/models/log.model.dart';
|
||||
|
||||
enum MetadataDomain {
|
||||
appConfig('app-config'),
|
||||
systemConfig('system-config');
|
||||
|
||||
final String prefix;
|
||||
const MetadataDomain(this.prefix);
|
||||
}
|
||||
|
||||
enum MetadataKey<T extends Object> {
|
||||
themeMode<ThemeMode>(.appConfig, 'theme.mode', .system, ThemeMode.values),
|
||||
logLevel<LogLevel>(.systemConfig, 'log.level', .info, LogLevel.values);
|
||||
|
||||
final MetadataDomain domain;
|
||||
final String name;
|
||||
final T defaultValue;
|
||||
final List<T>? enumValues;
|
||||
|
||||
const MetadataKey(this.domain, this.name, this.defaultValue, [this.enumValues]);
|
||||
|
||||
String get key => '${domain.prefix}.$name';
|
||||
|
||||
static MetadataKey<Object>? fromKey(String key) {
|
||||
for (final m in MetadataKey.values) {
|
||||
if (m.key == key) return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import 'package:immich_mobile/domain/models/config/app_config.dart';
|
||||
import 'package:immich_mobile/domain/models/config/system_config.dart';
|
||||
import 'package:immich_mobile/domain/models/metadata/system_metadata.dart';
|
||||
import 'package:immich_mobile/domain/models/metadata_value.dart';
|
||||
|
||||
enum MetadataKind<T extends MetadataValue> {
|
||||
appConfig<AppConfig>(AppConfig.name, AppConfig.fromJson, AppConfig()),
|
||||
systemConfig<SystemConfig>(SystemConfig.name, SystemConfig.fromJson, SystemConfig()),
|
||||
systemMetadata<SystemMetadata>(SystemMetadata.name, SystemMetadata.fromJson, SystemMetadata());
|
||||
|
||||
final String key;
|
||||
final T Function(Map<String, Object?>) fromJson;
|
||||
final T defaultValue;
|
||||
|
||||
const MetadataKind(this.key, this.fromJson, this.defaultValue);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
abstract class MetadataValue {
|
||||
const MetadataValue();
|
||||
|
||||
Map<String, Object?> toJson();
|
||||
}
|
||||
Reference in New Issue
Block a user