veilidchat/lib/settings/models/preferences.dart

58 lines
1.8 KiB
Dart
Raw Normal View History

2023-07-07 19:33:28 -04:00
import 'package:change_case/change_case.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
2024-01-08 21:37:08 -05:00
import '../../theme/theme.dart';
2023-07-07 19:33:28 -04:00
part 'preferences.freezed.dart';
part 'preferences.g.dart';
// 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>);
2024-01-08 21:37:08 -05:00
static const LockPreference defaults = LockPreference(
inactivityLockSecs: 0,
lockWhenSwitching: false,
lockWithSystemLock: false,
);
2023-07-07 19:33:28 -04:00
}
// Theme supports multiple translations
enum LanguagePreference {
2024-02-12 22:30:09 -05:00
englishUs;
2023-07-07 19:33:28 -04:00
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();
2024-01-08 21:37:08 -05:00
2024-02-12 22:30:09 -05:00
static const LanguagePreference defaults = LanguagePreference.englishUs;
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>);
2024-01-08 21:37:08 -05:00
static const Preferences defaults = Preferences(
themePreferences: ThemePreferences.defaults,
language: LanguagePreference.defaults,
locking: LockPreference.defaults);
2023-07-07 19:33:28 -04:00
}