veilidchat/lib/old_to_refactor/entities/preferences.dart

43 lines
1.3 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';
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>);
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
}
// 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
}