2023-07-07 19:33:28 -04:00
|
|
|
import 'package:change_case/change_case.dart';
|
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
|
|
|
|
part 'preferences.freezed.dart';
|
|
|
|
part 'preferences.g.dart';
|
|
|
|
|
|
|
|
// Theme supports light and dark mode, optionally selected by the
|
|
|
|
// operating system
|
2023-07-28 20:36:05 -04:00
|
|
|
enum BrightnessPreference {
|
2023-07-07 19:33:28 -04:00
|
|
|
system,
|
|
|
|
light,
|
|
|
|
dark;
|
|
|
|
|
2023-07-28 20:36:05 -04:00
|
|
|
factory BrightnessPreference.fromJson(dynamic j) =>
|
|
|
|
BrightnessPreference.values.byName((j as String).toCamelCase());
|
2023-07-26 17:42:11 -04:00
|
|
|
|
|
|
|
String toJson() => name.toPascalCase();
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lock preference changes how frequently the messenger locks its
|
|
|
|
// interface and requires the identitySecretKey to be entered (pin/password/etc)
|
|
|
|
@freezed
|
|
|
|
class LockPreference with _$LockPreference {
|
|
|
|
const factory LockPreference({
|
|
|
|
required int inactivityLockSecs,
|
|
|
|
required bool lockWhenSwitching,
|
|
|
|
required bool lockWithSystemLock,
|
|
|
|
}) = _LockPreference;
|
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory LockPreference.fromJson(dynamic json) =>
|
|
|
|
_$LockPreferenceFromJson(json as Map<String, dynamic>);
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Theme supports multiple color variants based on 'Radix'
|
|
|
|
enum ColorPreference {
|
2023-07-28 20:36:05 -04:00
|
|
|
// Radix Colors
|
|
|
|
scarlet,
|
|
|
|
babydoll,
|
|
|
|
vapor,
|
2023-07-07 19:33:28 -04:00
|
|
|
gold,
|
2023-07-28 20:36:05 -04:00
|
|
|
garden,
|
|
|
|
forest,
|
|
|
|
arctic,
|
|
|
|
lapis,
|
|
|
|
eggplant,
|
2023-07-07 19:33:28 -04:00
|
|
|
lime,
|
2023-07-28 20:36:05 -04:00
|
|
|
grim,
|
|
|
|
// Accessible Colors
|
|
|
|
contrast;
|
2023-07-07 19:33:28 -04:00
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory ColorPreference.fromJson(dynamic j) =>
|
|
|
|
ColorPreference.values.byName((j as String).toCamelCase());
|
2023-07-26 17:42:11 -04:00
|
|
|
String toJson() => name.toPascalCase();
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Theme supports multiple translations
|
|
|
|
enum LanguagePreference {
|
|
|
|
englishUS;
|
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory LanguagePreference.fromJson(dynamic j) =>
|
|
|
|
LanguagePreference.values.byName((j as String).toCamelCase());
|
2023-07-26 17:42:11 -04:00
|
|
|
String toJson() => name.toPascalCase();
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|
|
|
|
|
2023-07-28 20:36:05 -04:00
|
|
|
@freezed
|
|
|
|
class ThemePreferences with _$ThemePreferences {
|
|
|
|
const factory ThemePreferences({
|
|
|
|
required BrightnessPreference brightnessPreference,
|
|
|
|
required ColorPreference colorPreference,
|
|
|
|
required double displayScale,
|
|
|
|
}) = _ThemePreferences;
|
|
|
|
|
|
|
|
factory ThemePreferences.fromJson(dynamic json) =>
|
|
|
|
_$ThemePreferencesFromJson(json as Map<String, dynamic>);
|
|
|
|
}
|
|
|
|
|
2023-07-07 19:33:28 -04:00
|
|
|
// Preferences are stored in a table locally and globally affect all
|
|
|
|
// accounts imported/added and the app in general
|
|
|
|
@freezed
|
|
|
|
class Preferences with _$Preferences {
|
|
|
|
const factory Preferences({
|
2023-07-28 20:36:05 -04:00
|
|
|
required ThemePreferences themePreferences,
|
2023-07-07 19:33:28 -04:00
|
|
|
required LanguagePreference language,
|
|
|
|
required LockPreference locking,
|
|
|
|
}) = _Preferences;
|
|
|
|
|
2023-07-25 01:04:34 -04:00
|
|
|
factory Preferences.fromJson(dynamic json) =>
|
|
|
|
_$PreferencesFromJson(json as Map<String, dynamic>);
|
2023-07-07 19:33:28 -04:00
|
|
|
}
|