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)';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user