forked from firka/firka
feat: refactor settings system
- Rename SettingsStore to SettingsRepository
- Migrate the `data.settings.group("settings").subGroup("customization")["theme"]`
pattern to use `Settings.themeBrightness.value`.
- Move settings definitions to SettingsSchema
- Use annotations for declaring metadata for settings
This commit is contained in:
@@ -10,7 +10,7 @@ import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@@ -55,7 +55,7 @@ class AppInitialization {
|
||||
/// Set by the wear pairing modal; called when watch sends init_done or sync_done to dismiss the sheet.
|
||||
void Function()? dismissWearPairingSheet;
|
||||
Uint8List? profilePicture;
|
||||
SettingsStore settings;
|
||||
SettingsRepository settings;
|
||||
final ThemeCubit themeCubit = ThemeCubit();
|
||||
final SettingsCubit settingsCubit = SettingsCubit();
|
||||
final ProfilePictureCubit profilePictureCubit = ProfilePictureCubit();
|
||||
|
||||
@@ -11,7 +11,9 @@ import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/services/live_activity_service.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_effects.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/l10n/app_localizations_de.dart';
|
||||
import 'package:firka/l10n/app_localizations_en.dart';
|
||||
@@ -28,22 +30,20 @@ import 'package:path_provider/path_provider.dart';
|
||||
Future<void> initLang(AppInitialization data) async {
|
||||
String? languageCode;
|
||||
|
||||
switch ((data.settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex) {
|
||||
case 1: // hu
|
||||
switch (Settings.language.value) {
|
||||
case AppLanguage.hu:
|
||||
data.l10n = AppLocalizationsHu();
|
||||
languageCode = 'hu';
|
||||
break;
|
||||
case 2: // en
|
||||
case AppLanguage.en:
|
||||
data.l10n = AppLocalizationsEn();
|
||||
languageCode = 'en';
|
||||
break;
|
||||
case 3: // de
|
||||
case AppLanguage.de:
|
||||
data.l10n = AppLocalizationsDe();
|
||||
languageCode = 'de';
|
||||
break;
|
||||
default: // auto
|
||||
case AppLanguage.auto:
|
||||
switch (ui.PlatformDispatcher.instance.locale.languageCode) {
|
||||
case 'hu':
|
||||
data.l10n = AppLocalizationsHu();
|
||||
@@ -82,18 +82,16 @@ void initTheme(AppInitialization data) {
|
||||
final brightness =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||
|
||||
switch ((data.settings.group("settings").subGroup("customization")["theme"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex) {
|
||||
case 1:
|
||||
switch (Settings.themeBrightness.value) {
|
||||
case ThemeBrightness.light:
|
||||
appStyle = lightStyle;
|
||||
themeCubit.setLightMode(true);
|
||||
break;
|
||||
case 2:
|
||||
case ThemeBrightness.dark:
|
||||
appStyle = darkStyle;
|
||||
themeCubit.setLightMode(false);
|
||||
break;
|
||||
default:
|
||||
case ThemeBrightness.auto:
|
||||
if (brightness == Brightness.dark) {
|
||||
appStyle = darkStyle;
|
||||
themeCubit.setLightMode(false);
|
||||
@@ -105,11 +103,9 @@ void initTheme(AppInitialization data) {
|
||||
}
|
||||
|
||||
Future<void> _initData(AppInitialization init) async {
|
||||
await init.settings.load(init.isar.appSettingsModels);
|
||||
await init.settings.loadAll();
|
||||
await initLang(init);
|
||||
initTheme(init);
|
||||
init.settings = SettingsStore(init.l10n);
|
||||
await init.settings.load(init.isar.appSettingsModels);
|
||||
|
||||
var dispatcher = SchedulerBinding.instance.platformDispatcher;
|
||||
|
||||
@@ -118,10 +114,7 @@ Future<void> _initData(AppInitialization init) async {
|
||||
};
|
||||
|
||||
dispatcher.onLocaleChanged = () {
|
||||
final languageSetting =
|
||||
init.settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio;
|
||||
final isAutoLanguage = languageSetting.activeIndex == 0;
|
||||
final isAutoLanguage = Settings.language.value == AppLanguage.auto;
|
||||
if (!isAutoLanguage) {
|
||||
return;
|
||||
}
|
||||
@@ -235,10 +228,13 @@ Future<void> initializeApp() async {
|
||||
appDir: await getApplicationDocumentsDirectory(),
|
||||
devInfo: devInfo,
|
||||
packageInfo: await PackageInfo.fromPlatform(),
|
||||
settings: SettingsStore(AppLocalizationsHu()),
|
||||
settings: SettingsRepository(isar),
|
||||
l10n: AppLocalizationsHu(),
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
initData.settings.cubit = initData.settingsCubit;
|
||||
Settings = initData.settings;
|
||||
registerSettingsEffects(initData.settings, initData);
|
||||
|
||||
if (Platform.isIOS) {
|
||||
try {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
45
firka/lib/core/settings/setting.dart
Normal file
45
firka/lib/core/settings/setting.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import "package:isar_community/isar.dart";
|
||||
|
||||
/// A typed key for one persisted setting. Never constructed by hand outside
|
||||
/// settings_schema.gen.dart; settings_schema.dart defines the full registry.
|
||||
sealed class Setting<T> {
|
||||
final Id id;
|
||||
final T defaultValue;
|
||||
|
||||
const Setting({required this.id, required this.defaultValue});
|
||||
}
|
||||
|
||||
class BoolSetting extends Setting<bool> {
|
||||
const BoolSetting({required super.id, required super.defaultValue});
|
||||
}
|
||||
|
||||
class DoubleSetting extends Setting<double> {
|
||||
final double min;
|
||||
final double max;
|
||||
final int precision;
|
||||
final double? step;
|
||||
|
||||
const DoubleSetting({
|
||||
required super.id,
|
||||
required super.defaultValue,
|
||||
required this.min,
|
||||
required this.max,
|
||||
this.precision = 0,
|
||||
this.step,
|
||||
});
|
||||
}
|
||||
|
||||
/// Persisted as the value's index into [values].
|
||||
class EnumSetting<T extends Enum> extends Setting<T> {
|
||||
final List<T> values;
|
||||
|
||||
const EnumSetting({
|
||||
required super.id,
|
||||
required super.defaultValue,
|
||||
required this.values,
|
||||
});
|
||||
}
|
||||
|
||||
class StringSetting extends Setting<String> {
|
||||
const StringSetting({required super.id, required super.defaultValue});
|
||||
}
|
||||
65
firka/lib/core/settings/settings_effects.dart
Normal file
65
firka/lib/core/settings/settings_effects.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:permission_handler/permission_handler.dart";
|
||||
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/app/initialization.dart";
|
||||
import "package:firka/services/live_activity_service.dart";
|
||||
import "package:firka/services/watch_sync_helper.dart";
|
||||
|
||||
import "settings_repository.dart";
|
||||
import "settings_schema.dart";
|
||||
|
||||
/// Registers the side effects that used to live as `postUpdate` closures on
|
||||
/// each SettingsItem. Called once after the repository is loaded at startup.
|
||||
void registerSettingsEffects(
|
||||
SettingsRepository repo,
|
||||
AppInitialization initData,
|
||||
) {
|
||||
repo.onChange(SettingsRegistry.language, (_) async {
|
||||
await initLang(initData);
|
||||
initData.homeRefreshCubit.requestRefresh();
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.themeBrightness, (_) async {
|
||||
initTheme(initData);
|
||||
initData.homeRefreshCubit.requestRefresh();
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.wearOsSupport, (enabled) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
if (enabled && initDone) {
|
||||
final notifStatus = await Permission.notification.status;
|
||||
if (notifStatus.isDenied || notifStatus.isPermanentlyDenied) {
|
||||
await Permission.notification.request();
|
||||
}
|
||||
await WatchSyncHelper.startWearSyncServiceWithFreshCache(
|
||||
initData.client!,
|
||||
initData.appDir.path,
|
||||
);
|
||||
} else {
|
||||
await WatchSyncHelper.stopWearSyncService();
|
||||
}
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.morningNotificationEnabled, (enabled) async {
|
||||
LiveActivityService.onMorningNotificationEnabledChanged(enabled);
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.liveActivityEnabled, (enabled) async {
|
||||
await LiveActivityService.handleEnabledChange(enabled, isManual: true);
|
||||
await LiveActivityService.syncGlobalSettingWithCurrentUser();
|
||||
});
|
||||
|
||||
// These two mirror LiveActivity widgets on iOS only, matching the original
|
||||
// postUpdate wiring that was only attached inside an `if (Platform.isIOS)` block.
|
||||
if (Platform.isIOS) {
|
||||
repo.onChange(SettingsRegistry.bellDelay, (value) async {
|
||||
LiveActivityService.onBellDelayChanged(value);
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.morningNotificationTime, (value) async {
|
||||
LiveActivityService.onMorningNotificationTimeChanged(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
146
firka/lib/core/settings/settings_repository.dart
Normal file
146
firka/lib/core/settings/settings_repository.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
import "package:flutter/widgets.dart";
|
||||
import "package:isar_community/isar.dart";
|
||||
|
||||
import "package:firka/core/bloc/settings_cubit.dart";
|
||||
import "package:firka_common/core/grade_helper.dart" as grade_helper;
|
||||
import "package:firka_common/data/database.dart";
|
||||
import "package:firka_common/data/models/app_settings_model.dart";
|
||||
import "package:firka_common/data/models/token_model.dart";
|
||||
import "package:firka_common/ui/theme/style.dart";
|
||||
|
||||
import "setting.dart";
|
||||
import "settings_schema.dart";
|
||||
|
||||
/// Isar id for the selected Kréta account, kept outside SettingsRegistry since
|
||||
/// it's not a bounded typed value. Distinct from appIcon's id 0 on purpose:
|
||||
/// the original code reused id 0 for both, silently clobbering one another.
|
||||
const _selectedAccountId = 1025;
|
||||
|
||||
/// Live, repository-bound access to every setting, e.g. `Settings.bellDelay.value`.
|
||||
/// Set once at startup once the real SettingsRepository exists. Distinct from
|
||||
/// SettingsRegistry, which only holds the typed key definitions (id, bounds,
|
||||
/// default) and has no notion of a current value.
|
||||
// ignore: non_constant_identifier_names
|
||||
late SettingsRepository Settings;
|
||||
|
||||
/// A single setting bound to its repository. Generated accessors on
|
||||
/// SettingsRepository (see settings_schema.gen.dart) return one of these per
|
||||
/// setting, so callers read `.value` and write via `.set`/`.setSilently`
|
||||
/// instead of the more verbose `repo.get(Settings.x)` / `repo.set(Settings.x, v)`.
|
||||
class SilentlySettable<T> {
|
||||
final SettingsRepository _repo;
|
||||
final Setting<T> _setting;
|
||||
|
||||
const SilentlySettable(this._repo, this._setting);
|
||||
|
||||
T get value => _repo.get(_setting);
|
||||
|
||||
Future<void> set(T value) => _repo.set(_setting, value);
|
||||
|
||||
Future<void> setSilently(T value) => _repo.setSilently(_setting, value);
|
||||
}
|
||||
|
||||
/// Owns every setting's current value and its Isar persistence.
|
||||
/// Replaces the per-item load/save methods that used to live on each SettingsItem subclass.
|
||||
class SettingsRepository {
|
||||
final Isar isar;
|
||||
SettingsCubit? cubit;
|
||||
IsarCollection<AppSettingsModel> get box => isar.appSettingsModels;
|
||||
final _values = <Id, dynamic>{};
|
||||
final _effects = <Id, List<Future<void> Function(dynamic)>>{};
|
||||
|
||||
SettingsRepository(this.isar, [this.cubit]);
|
||||
|
||||
T get<T>(Setting<T> setting) =>
|
||||
(_values[setting.id] ?? setting.defaultValue) as T;
|
||||
|
||||
Future<void> set<T>(Setting<T> setting, T value) async {
|
||||
await setSilently(setting, value);
|
||||
|
||||
for (final effect in _effects[setting.id] ?? const []) {
|
||||
await effect(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// Persists without running registered onChange effects. For code that IS
|
||||
/// itself an effect syncing a setting from an external source (e.g. the
|
||||
/// backend's live activity preferences) and would otherwise recursively
|
||||
/// trigger its own onChange handler.
|
||||
Future<void> setSilently<T>(Setting<T> setting, T value) async {
|
||||
_values[setting.id] = value;
|
||||
|
||||
final row = AppSettingsModel()..id = setting.id;
|
||||
switch (value) {
|
||||
case bool v:
|
||||
row.valueBool = v;
|
||||
case double v:
|
||||
row.valueDouble = v;
|
||||
case Enum v:
|
||||
row.valueIndex = v.index;
|
||||
case String v:
|
||||
row.valueString = v;
|
||||
}
|
||||
await isar.writeTxn(() async {
|
||||
await box.put(row);
|
||||
});
|
||||
|
||||
cubit?.notifyChanged();
|
||||
}
|
||||
|
||||
void onChange<T>(Setting<T> setting, Future<void> Function(T value) effect) {
|
||||
(_effects[setting.id] ??= []).add((value) => effect(value as T));
|
||||
}
|
||||
|
||||
Future<void> loadAll() async {
|
||||
for (final setting in SettingsRegistry.all) {
|
||||
final row = await box.get(setting.id);
|
||||
_values[setting.id] = switch (setting) {
|
||||
BoolSetting() => row?.valueBool ?? setting.defaultValue,
|
||||
DoubleSetting() => row?.valueDouble ?? setting.defaultValue,
|
||||
EnumSetting(:final values) =>
|
||||
row?.valueIndex != null
|
||||
? values[row!.valueIndex!]
|
||||
: setting.defaultValue,
|
||||
StringSetting() => row?.valueString ?? setting.defaultValue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
int roundGrade(num grade) {
|
||||
return grade_helper.roundGrade(
|
||||
grade,
|
||||
t1: get(SettingsRegistry.rounding1),
|
||||
t2: get(SettingsRegistry.rounding2),
|
||||
t3: get(SettingsRegistry.rounding3),
|
||||
t4: get(SettingsRegistry.rounding4),
|
||||
);
|
||||
}
|
||||
|
||||
Color getGradeColor(num grade) {
|
||||
return switch (roundGrade(grade)) {
|
||||
2 => appStyle.colors.grade2,
|
||||
3 => appStyle.colors.grade3,
|
||||
4 => appStyle.colors.grade4,
|
||||
5 => appStyle.colors.grade5,
|
||||
_ => appStyle.colors.grade1,
|
||||
};
|
||||
}
|
||||
|
||||
int get selectedAccountKey =>
|
||||
box.getSync(_selectedAccountId)?.valueIndex ?? 0;
|
||||
|
||||
Future<void> setSelectedAccountKey(int key) async {
|
||||
await isar.writeTxn(() async {
|
||||
await box.put(
|
||||
AppSettingsModel()
|
||||
..id = _selectedAccountId
|
||||
..valueIndex = key,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
TokenModel? getSelectedToken() {
|
||||
return isarInit.tokenModels.getSync(selectedAccountKey) ??
|
||||
isarInit.tokenModels.where().findFirstSync();
|
||||
}
|
||||
}
|
||||
99
firka/lib/core/settings/settings_schema.dart
Normal file
99
firka/lib/core/settings/settings_schema.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import "setting.dart";
|
||||
import "settings_repository.dart";
|
||||
|
||||
part "settings_schema.gen.dart";
|
||||
|
||||
enum AppLanguage { auto, hu, en, de }
|
||||
|
||||
enum ThemeBrightness { auto, light, dark }
|
||||
|
||||
abstract class SettingsSchema {
|
||||
@DoubleSetting(id: 1001, defaultValue: 0, min: 0, max: 120)
|
||||
double get bellDelay;
|
||||
|
||||
@DoubleSetting(id: 1002, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
||||
double get rounding1;
|
||||
|
||||
@DoubleSetting(id: 1003, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
||||
double get rounding2;
|
||||
|
||||
@DoubleSetting(id: 1004, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
||||
double get rounding3;
|
||||
|
||||
@DoubleSetting(id: 1005, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
||||
double get rounding4;
|
||||
|
||||
@BoolSetting(id: 1006, defaultValue: true)
|
||||
bool get classAvgOnGraph;
|
||||
|
||||
@BoolSetting(id: 1007, defaultValue: false)
|
||||
bool get leftHandedMode;
|
||||
|
||||
@EnumSetting(
|
||||
id: 1008,
|
||||
defaultValue: AppLanguage.auto,
|
||||
values: AppLanguage.values,
|
||||
)
|
||||
AppLanguage get language;
|
||||
|
||||
// SettingsAppIconPicker has always persisted under a
|
||||
// hardcoded id of 0 instead of the appIcon constant.
|
||||
@StringSetting(id: 0, defaultValue: "original")
|
||||
String get appIcon;
|
||||
|
||||
@BoolSetting(id: 1010, defaultValue: true)
|
||||
bool get childProtection;
|
||||
|
||||
@BoolSetting(id: 1011, defaultValue: false)
|
||||
bool get betaWarning;
|
||||
|
||||
@BoolSetting(id: 1012, defaultValue: true)
|
||||
bool get ttToastLessonNo;
|
||||
|
||||
@BoolSetting(id: 1013, defaultValue: true)
|
||||
bool get ttToastTestsAndHw;
|
||||
|
||||
@BoolSetting(id: 1014, defaultValue: true)
|
||||
bool get ttToastBreaks;
|
||||
|
||||
@BoolSetting(id: 1015, defaultValue: false)
|
||||
bool get statsForNerds;
|
||||
|
||||
@BoolSetting(id: 1016, defaultValue: false)
|
||||
bool get developerOptsEnabled;
|
||||
|
||||
@EnumSetting(
|
||||
id: 1017,
|
||||
defaultValue: ThemeBrightness.auto,
|
||||
values: ThemeBrightness.values,
|
||||
)
|
||||
ThemeBrightness get themeBrightness;
|
||||
|
||||
@BoolSetting(id: 1018, defaultValue: true)
|
||||
bool get ttToastSubstitution;
|
||||
|
||||
@BoolSetting(id: 1019, defaultValue: false)
|
||||
bool get liveActivityEnabled;
|
||||
|
||||
@BoolSetting(id: 1020, defaultValue: false)
|
||||
bool get liveActivityPrivacyEverDeclined;
|
||||
|
||||
@BoolSetting(id: 1021, defaultValue: true)
|
||||
bool get morningNotificationEnabled;
|
||||
|
||||
@DoubleSetting(
|
||||
id: 1022,
|
||||
defaultValue: 120,
|
||||
min: 30,
|
||||
max: 240,
|
||||
precision: 0,
|
||||
step: 15,
|
||||
)
|
||||
double get morningNotificationTime;
|
||||
|
||||
@BoolSetting(id: 1023, defaultValue: true)
|
||||
bool get ttToastABTimetable;
|
||||
|
||||
@BoolSetting(id: 1024, defaultValue: false)
|
||||
bool get wearOsSupport;
|
||||
}
|
||||
161
firka/lib/core/settings/settings_schema.gen.dart
Normal file
161
firka/lib/core/settings/settings_schema.gen.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of "settings_schema.dart";
|
||||
|
||||
class SettingsRegistry {
|
||||
static const bellDelay = DoubleSetting(
|
||||
id: 1001,
|
||||
defaultValue: 0,
|
||||
min: 0,
|
||||
max: 120,
|
||||
);
|
||||
static const rounding1 = DoubleSetting(
|
||||
id: 1002,
|
||||
defaultValue: 0.5,
|
||||
min: 0.1,
|
||||
max: 0.99,
|
||||
precision: 2,
|
||||
);
|
||||
static const rounding2 = DoubleSetting(
|
||||
id: 1003,
|
||||
defaultValue: 0.5,
|
||||
min: 0.1,
|
||||
max: 0.99,
|
||||
precision: 2,
|
||||
);
|
||||
static const rounding3 = DoubleSetting(
|
||||
id: 1004,
|
||||
defaultValue: 0.5,
|
||||
min: 0.1,
|
||||
max: 0.99,
|
||||
precision: 2,
|
||||
);
|
||||
static const rounding4 = DoubleSetting(
|
||||
id: 1005,
|
||||
defaultValue: 0.5,
|
||||
min: 0.1,
|
||||
max: 0.99,
|
||||
precision: 2,
|
||||
);
|
||||
static const classAvgOnGraph = BoolSetting(id: 1006, defaultValue: true);
|
||||
static const leftHandedMode = BoolSetting(id: 1007, defaultValue: false);
|
||||
static const language = EnumSetting(
|
||||
id: 1008,
|
||||
defaultValue: AppLanguage.auto,
|
||||
values: AppLanguage.values,
|
||||
);
|
||||
static const appIcon = StringSetting(id: 0, defaultValue: "original");
|
||||
static const childProtection = BoolSetting(id: 1010, defaultValue: true);
|
||||
static const betaWarning = BoolSetting(id: 1011, defaultValue: false);
|
||||
static const ttToastLessonNo = BoolSetting(id: 1012, defaultValue: true);
|
||||
static const ttToastTestsAndHw = BoolSetting(id: 1013, defaultValue: true);
|
||||
static const ttToastBreaks = BoolSetting(id: 1014, defaultValue: true);
|
||||
static const statsForNerds = BoolSetting(id: 1015, defaultValue: false);
|
||||
static const developerOptsEnabled = BoolSetting(
|
||||
id: 1016,
|
||||
defaultValue: false,
|
||||
);
|
||||
static const themeBrightness = EnumSetting(
|
||||
id: 1017,
|
||||
defaultValue: ThemeBrightness.auto,
|
||||
values: ThemeBrightness.values,
|
||||
);
|
||||
static const ttToastSubstitution = BoolSetting(id: 1018, defaultValue: true);
|
||||
static const liveActivityEnabled = BoolSetting(id: 1019, defaultValue: false);
|
||||
static const liveActivityPrivacyEverDeclined = BoolSetting(
|
||||
id: 1020,
|
||||
defaultValue: false,
|
||||
);
|
||||
static const morningNotificationEnabled = BoolSetting(
|
||||
id: 1021,
|
||||
defaultValue: true,
|
||||
);
|
||||
static const morningNotificationTime = DoubleSetting(
|
||||
id: 1022,
|
||||
defaultValue: 120,
|
||||
min: 30,
|
||||
max: 240,
|
||||
precision: 0,
|
||||
step: 15,
|
||||
);
|
||||
static const ttToastABTimetable = BoolSetting(id: 1023, defaultValue: true);
|
||||
static const wearOsSupport = BoolSetting(id: 1024, defaultValue: false);
|
||||
|
||||
static const all = <Setting>[
|
||||
bellDelay,
|
||||
rounding1,
|
||||
rounding2,
|
||||
rounding3,
|
||||
rounding4,
|
||||
classAvgOnGraph,
|
||||
leftHandedMode,
|
||||
language,
|
||||
appIcon,
|
||||
childProtection,
|
||||
betaWarning,
|
||||
ttToastLessonNo,
|
||||
ttToastTestsAndHw,
|
||||
ttToastBreaks,
|
||||
statsForNerds,
|
||||
developerOptsEnabled,
|
||||
themeBrightness,
|
||||
ttToastSubstitution,
|
||||
liveActivityEnabled,
|
||||
liveActivityPrivacyEverDeclined,
|
||||
morningNotificationEnabled,
|
||||
morningNotificationTime,
|
||||
ttToastABTimetable,
|
||||
wearOsSupport,
|
||||
];
|
||||
}
|
||||
|
||||
extension SettingsAccessors on SettingsRepository {
|
||||
SilentlySettable<double> get bellDelay =>
|
||||
SilentlySettable(this, SettingsRegistry.bellDelay);
|
||||
SilentlySettable<double> get rounding1 =>
|
||||
SilentlySettable(this, SettingsRegistry.rounding1);
|
||||
SilentlySettable<double> get rounding2 =>
|
||||
SilentlySettable(this, SettingsRegistry.rounding2);
|
||||
SilentlySettable<double> get rounding3 =>
|
||||
SilentlySettable(this, SettingsRegistry.rounding3);
|
||||
SilentlySettable<double> get rounding4 =>
|
||||
SilentlySettable(this, SettingsRegistry.rounding4);
|
||||
SilentlySettable<bool> get classAvgOnGraph =>
|
||||
SilentlySettable(this, SettingsRegistry.classAvgOnGraph);
|
||||
SilentlySettable<bool> get leftHandedMode =>
|
||||
SilentlySettable(this, SettingsRegistry.leftHandedMode);
|
||||
SilentlySettable<AppLanguage> get language =>
|
||||
SilentlySettable(this, SettingsRegistry.language);
|
||||
SilentlySettable<String> get appIcon =>
|
||||
SilentlySettable(this, SettingsRegistry.appIcon);
|
||||
SilentlySettable<bool> get childProtection =>
|
||||
SilentlySettable(this, SettingsRegistry.childProtection);
|
||||
SilentlySettable<bool> get betaWarning =>
|
||||
SilentlySettable(this, SettingsRegistry.betaWarning);
|
||||
SilentlySettable<bool> get ttToastLessonNo =>
|
||||
SilentlySettable(this, SettingsRegistry.ttToastLessonNo);
|
||||
SilentlySettable<bool> get ttToastTestsAndHw =>
|
||||
SilentlySettable(this, SettingsRegistry.ttToastTestsAndHw);
|
||||
SilentlySettable<bool> get ttToastBreaks =>
|
||||
SilentlySettable(this, SettingsRegistry.ttToastBreaks);
|
||||
SilentlySettable<bool> get statsForNerds =>
|
||||
SilentlySettable(this, SettingsRegistry.statsForNerds);
|
||||
SilentlySettable<bool> get developerOptsEnabled =>
|
||||
SilentlySettable(this, SettingsRegistry.developerOptsEnabled);
|
||||
SilentlySettable<ThemeBrightness> get themeBrightness =>
|
||||
SilentlySettable(this, SettingsRegistry.themeBrightness);
|
||||
SilentlySettable<bool> get ttToastSubstitution =>
|
||||
SilentlySettable(this, SettingsRegistry.ttToastSubstitution);
|
||||
SilentlySettable<bool> get liveActivityEnabled =>
|
||||
SilentlySettable(this, SettingsRegistry.liveActivityEnabled);
|
||||
SilentlySettable<bool> get liveActivityPrivacyEverDeclined =>
|
||||
SilentlySettable(this, SettingsRegistry.liveActivityPrivacyEverDeclined);
|
||||
SilentlySettable<bool> get morningNotificationEnabled =>
|
||||
SilentlySettable(this, SettingsRegistry.morningNotificationEnabled);
|
||||
SilentlySettable<double> get morningNotificationTime =>
|
||||
SilentlySettable(this, SettingsRegistry.morningNotificationTime);
|
||||
SilentlySettable<bool> get ttToastABTimetable =>
|
||||
SilentlySettable(this, SettingsRegistry.ttToastABTimetable);
|
||||
SilentlySettable<bool> get wearOsSupport =>
|
||||
SilentlySettable(this, SettingsRegistry.wearOsSupport);
|
||||
}
|
||||
151
firka/lib/core/settings/settings_ui.dart
Normal file
151
firka/lib/core/settings/settings_ui.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import "package:firka/ui/shared/firka_icon.dart";
|
||||
|
||||
import "setting.dart";
|
||||
|
||||
/// UI-only description of a settings screen: icons, titles, grouping, navigation,
|
||||
/// visibility. Holds no values itself, only references to typed [Setting]s whose
|
||||
/// values live in SettingsRepository. Separate from the data schema on purpose:
|
||||
/// see AGENTS.md and the settings redesign plan for why.
|
||||
sealed class SettingsUiNode {
|
||||
final bool Function() visible;
|
||||
|
||||
const SettingsUiNode(this.visible);
|
||||
}
|
||||
|
||||
class SettingsUiGroup extends SettingsUiNode {
|
||||
final List<SettingsUiNode> children;
|
||||
|
||||
const SettingsUiGroup(this.children, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiPadding extends SettingsUiNode {
|
||||
final double padding;
|
||||
|
||||
const SettingsUiPadding(this.padding, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiBackHeader extends SettingsUiNode {
|
||||
final String title;
|
||||
|
||||
const SettingsUiBackHeader(this.title, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiHeader extends SettingsUiNode {
|
||||
final String title;
|
||||
|
||||
const SettingsUiHeader(this.title, bool Function() visible) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiMediumHeader extends SettingsUiNode {
|
||||
final String title;
|
||||
|
||||
const SettingsUiMediumHeader(this.title, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiHeaderSmall extends SettingsUiNode {
|
||||
final String title;
|
||||
|
||||
const SettingsUiHeaderSmall(this.title, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiSubGroup extends SettingsUiNode {
|
||||
final FirkaIconType? iconType;
|
||||
final Object? iconData;
|
||||
final String title;
|
||||
final List<SettingsUiNode> children;
|
||||
final String? redirectTo;
|
||||
|
||||
const SettingsUiSubGroup(
|
||||
this.iconType,
|
||||
this.iconData,
|
||||
this.title,
|
||||
this.children,
|
||||
bool Function() visible, [
|
||||
this.redirectTo,
|
||||
]) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiBoolean extends SettingsUiNode {
|
||||
final FirkaIconType? iconType;
|
||||
final Object? iconData;
|
||||
final String title;
|
||||
final BoolSetting setting;
|
||||
|
||||
const SettingsUiBoolean(
|
||||
this.iconType,
|
||||
this.iconData,
|
||||
this.title,
|
||||
this.setting,
|
||||
bool Function() visible,
|
||||
) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiDouble extends SettingsUiNode {
|
||||
final FirkaIconType? iconType;
|
||||
final Object? iconData;
|
||||
final String title;
|
||||
final DoubleSetting setting;
|
||||
|
||||
const SettingsUiDouble(
|
||||
this.iconType,
|
||||
this.iconData,
|
||||
this.title,
|
||||
this.setting,
|
||||
bool Function() visible,
|
||||
) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiEnum extends SettingsUiNode {
|
||||
final EnumSetting setting;
|
||||
final List<String> optionLabels;
|
||||
|
||||
const SettingsUiEnum(this.setting, this.optionLabels, bool Function() visible)
|
||||
: super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiButton extends SettingsUiNode {
|
||||
final FirkaIconType? iconType;
|
||||
final Object? iconData;
|
||||
final String title;
|
||||
final Future<void> Function() onTap;
|
||||
|
||||
const SettingsUiButton(
|
||||
this.iconType,
|
||||
this.iconData,
|
||||
this.title,
|
||||
bool Function() visible,
|
||||
this.onTap,
|
||||
) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiAppIconPreview extends SettingsUiNode {
|
||||
const SettingsUiAppIconPreview(bool Function() visible) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiAppIconPicker extends SettingsUiNode {
|
||||
final Map<String, List<String>> iconGroups;
|
||||
final SettingsUiBoolean childProtection;
|
||||
|
||||
const SettingsUiAppIconPicker(
|
||||
this.iconGroups,
|
||||
this.childProtection,
|
||||
bool Function() visible,
|
||||
) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiKretaAccountPicker extends SettingsUiNode {
|
||||
const SettingsUiKretaAccountPicker(bool Function() visible) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiLogs extends SettingsUiNode {
|
||||
const SettingsUiLogs(bool Function() visible) : super(visible);
|
||||
}
|
||||
|
||||
class SettingsUiLicensePage extends SettingsUiNode {
|
||||
const SettingsUiLicensePage(bool Function() visible) : super(visible);
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -117,43 +118,37 @@ class WidgetCacheHelper {
|
||||
/// Call this on: app open, user switch, data refresh
|
||||
static Future<void> refreshIOSWidgets(
|
||||
KretaClient client,
|
||||
SettingsStore settings,
|
||||
SettingsRepository settings,
|
||||
) async {
|
||||
if (!Platform.isIOS) return;
|
||||
|
||||
try {
|
||||
final langIndex =
|
||||
(settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex;
|
||||
final language = settings.get(SettingsRegistry.language);
|
||||
String locale;
|
||||
switch (langIndex) {
|
||||
case 1:
|
||||
switch (language) {
|
||||
case AppLanguage.hu:
|
||||
locale = 'hu';
|
||||
break;
|
||||
case 2:
|
||||
case AppLanguage.en:
|
||||
locale = 'en';
|
||||
break;
|
||||
case 3:
|
||||
case AppLanguage.de:
|
||||
locale = 'de';
|
||||
break;
|
||||
default:
|
||||
case AppLanguage.auto:
|
||||
locale = 'hu';
|
||||
}
|
||||
|
||||
final themeIndex =
|
||||
(settings.group("settings").subGroup("customization")["theme"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex;
|
||||
final themeBrightness = settings.get(SettingsRegistry.themeBrightness);
|
||||
String theme;
|
||||
switch (themeIndex) {
|
||||
case 1:
|
||||
switch (themeBrightness) {
|
||||
case ThemeBrightness.light:
|
||||
theme = 'light';
|
||||
break;
|
||||
case 2:
|
||||
case ThemeBrightness.dark:
|
||||
theme = 'dark';
|
||||
break;
|
||||
default:
|
||||
case ThemeBrightness.auto:
|
||||
theme =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.light
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:firka/ui/phone/pages/home/home_omissions.dart';
|
||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/core/settings/settings_ui.dart';
|
||||
import 'package:firka/ui/phone/pages/home/home_grades.dart';
|
||||
import 'package:firka/ui/phone/pages/home/home_grades_subject.dart';
|
||||
import 'package:firka/ui/phone/pages/home/home_main.dart';
|
||||
@@ -87,8 +88,8 @@ GoRouter createAppRouter() {
|
||||
path: '/settings',
|
||||
builder: (context, state) {
|
||||
final items = state.extra != null
|
||||
? state.extra! as LinkedHashMap<String, SettingsItem>
|
||||
: initData.settings.items;
|
||||
? state.extra! as List<SettingsUiNode>
|
||||
: buildSettingsTree(initData.l10n).children;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: SettingsScreen(initData, items, key: state.pageKey),
|
||||
@@ -204,9 +205,7 @@ GoRouter createAppRouter() {
|
||||
String get _initialLocation {
|
||||
if (!initDone) return '/';
|
||||
if (initData.client == null) return '/login';
|
||||
final betaWarning = initData.settings
|
||||
.group('settings')
|
||||
.boolean('beta_warning');
|
||||
final betaWarning = Settings.betaWarning.value;
|
||||
if (!betaWarning) return '/beta';
|
||||
return '/home';
|
||||
}
|
||||
@@ -215,9 +214,7 @@ String? _redirect(BuildContext context, GoRouterState state) {
|
||||
if (!initDone) return null;
|
||||
final location = state.matchedLocation;
|
||||
final hasTokens = initData.client != null;
|
||||
final betaWarning = initData.settings
|
||||
.group('settings')
|
||||
.boolean('beta_warning');
|
||||
final betaWarning = Settings.betaWarning.value;
|
||||
|
||||
if (!hasTokens) {
|
||||
if (location != '/login') return '/login';
|
||||
|
||||
@@ -4,9 +4,9 @@ import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:firka/api/client/live_activity_backend_client.dart';
|
||||
import 'package:firka/data/widget.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka/services/live_activity_manager.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/ui/phone/screens/live_activity/live_activity_consent_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -215,17 +215,8 @@ class LiveActivityService {
|
||||
final userLiveActivityEnabled = await _getUserLiveActivityEnabled(
|
||||
client: client,
|
||||
);
|
||||
final globalLiveActivitySetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["live_activity_enabled"]
|
||||
as SettingsBoolean;
|
||||
|
||||
if (globalLiveActivitySetting.value != userLiveActivityEnabled) {
|
||||
globalLiveActivitySetting.value = userLiveActivityEnabled;
|
||||
await initData.isar.writeTxn(() async {
|
||||
await globalLiveActivitySetting.save(initData.isar.appSettingsModels);
|
||||
});
|
||||
if (Settings.liveActivityEnabled.value != userLiveActivityEnabled) {
|
||||
await Settings.liveActivityEnabled.setSilently(userLiveActivityEnabled);
|
||||
_logger.info(
|
||||
'Global LiveActivity setting synced: $userLiveActivityEnabled for user $studentId',
|
||||
);
|
||||
@@ -234,19 +225,10 @@ class LiveActivityService {
|
||||
final userMorningEnabled = await _getUserMorningNotificationEnabled(
|
||||
client: client,
|
||||
);
|
||||
final globalMorningEnabledSetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_enabled"]
|
||||
as SettingsBoolean;
|
||||
|
||||
if (globalMorningEnabledSetting.value != userMorningEnabled) {
|
||||
globalMorningEnabledSetting.value = userMorningEnabled;
|
||||
await initData.isar.writeTxn(() async {
|
||||
await globalMorningEnabledSetting.save(
|
||||
initData.isar.appSettingsModels,
|
||||
);
|
||||
});
|
||||
if (Settings.morningNotificationEnabled.value != userMorningEnabled) {
|
||||
await Settings.morningNotificationEnabled.setSilently(
|
||||
userMorningEnabled,
|
||||
);
|
||||
_logger.info(
|
||||
'Global morning notification enabled synced: $userMorningEnabled for user $studentId',
|
||||
);
|
||||
@@ -255,34 +237,18 @@ class LiveActivityService {
|
||||
final userMorningTime = await _getUserMorningNotificationTime(
|
||||
client: client,
|
||||
);
|
||||
final globalMorningTimeSetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_time"]
|
||||
as SettingsDouble;
|
||||
|
||||
if (globalMorningTimeSetting.value.toInt() != userMorningTime) {
|
||||
globalMorningTimeSetting.value = userMorningTime.toDouble();
|
||||
await initData.isar.writeTxn(() async {
|
||||
await globalMorningTimeSetting.save(initData.isar.appSettingsModels);
|
||||
});
|
||||
if (Settings.morningNotificationTime.value.toInt() != userMorningTime) {
|
||||
await Settings.morningNotificationTime.setSilently(
|
||||
userMorningTime.toDouble(),
|
||||
);
|
||||
_logger.info(
|
||||
'Global morning notification time synced: $userMorningTime for user $studentId',
|
||||
);
|
||||
}
|
||||
|
||||
final userBellDelay = await _getUserBellDelay(client: client);
|
||||
final globalBellDelaySetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("application")["bell_delay"]
|
||||
as SettingsDouble;
|
||||
|
||||
if (globalBellDelaySetting.value != userBellDelay) {
|
||||
globalBellDelaySetting.value = userBellDelay;
|
||||
await initData.isar.writeTxn(() async {
|
||||
await globalBellDelaySetting.save(initData.isar.appSettingsModels);
|
||||
});
|
||||
if (Settings.bellDelay.value != userBellDelay) {
|
||||
await Settings.bellDelay.setSilently(userBellDelay);
|
||||
_logger.info(
|
||||
'Global bell delay synced: $userBellDelay for user $studentId',
|
||||
);
|
||||
@@ -301,22 +267,14 @@ class LiveActivityService {
|
||||
return 'hu';
|
||||
}
|
||||
|
||||
final languageSetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("application")["language"]
|
||||
as SettingsItemsRadio?;
|
||||
|
||||
if (languageSetting == null) return 'hu';
|
||||
|
||||
switch (languageSetting.activeIndex) {
|
||||
case 1:
|
||||
switch (Settings.language.value) {
|
||||
case AppLanguage.hu:
|
||||
return 'hu';
|
||||
case 2:
|
||||
case AppLanguage.en:
|
||||
return 'en';
|
||||
case 3:
|
||||
case AppLanguage.de:
|
||||
return 'de';
|
||||
default: // auto
|
||||
case AppLanguage.auto:
|
||||
final systemLang = Platform.localeName.split('_').first;
|
||||
if (['hu', 'en', 'de'].contains(systemLang)) {
|
||||
return systemLang;
|
||||
@@ -635,7 +593,7 @@ class LiveActivityService {
|
||||
|
||||
/// Check if LiveActivity is enabled in settings
|
||||
static Future<bool> isEnabled([
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
KretaClient? client,
|
||||
]) async {
|
||||
try {
|
||||
@@ -842,7 +800,7 @@ class LiveActivityService {
|
||||
static Future<void> onUserLogin({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
}) async {
|
||||
_logger.info('onUserLogin: Function called for $studentName');
|
||||
|
||||
@@ -1190,7 +1148,7 @@ class LiveActivityService {
|
||||
static Future<void> checkAndUpdateTimetable({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
bool forceUpdate = false,
|
||||
}) async {
|
||||
if (!Platform.isIOS || !_isInitialized) return;
|
||||
@@ -1473,7 +1431,7 @@ class LiveActivityService {
|
||||
static Future<void> _startTimetableMonitoring({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
}) async {
|
||||
_stopTimetableMonitoring();
|
||||
|
||||
@@ -1938,12 +1896,7 @@ class LiveActivityService {
|
||||
if (!initDone) {
|
||||
return null;
|
||||
}
|
||||
final setting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_enabled"]
|
||||
as SettingsBoolean?;
|
||||
return setting?.value;
|
||||
return Settings.morningNotificationEnabled.value;
|
||||
} catch (e) {
|
||||
_logger.warning('Error getting current morning notification enabled: $e');
|
||||
return null;
|
||||
@@ -1956,12 +1909,7 @@ class LiveActivityService {
|
||||
if (!initDone) {
|
||||
return null;
|
||||
}
|
||||
final setting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_time"]
|
||||
as SettingsDouble?;
|
||||
return setting?.value;
|
||||
return Settings.morningNotificationTime.value;
|
||||
} catch (e) {
|
||||
_logger.warning('Error getting current morning notification time: $e');
|
||||
return null;
|
||||
|
||||
@@ -14,7 +14,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/homework_cache_model.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
@@ -93,10 +94,7 @@ Future<void> showLessonBottomSheet(
|
||||
) async {
|
||||
// we dont like events
|
||||
assert(lesson.type != TimetableConsts.event);
|
||||
final statsForNerdsEnabled = data.settings
|
||||
.group("settings")
|
||||
.subGroup("developer")
|
||||
.boolean("stats_for_nerds");
|
||||
final statsForNerdsEnabled = Settings.statsForNerds.value;
|
||||
|
||||
Widget? statsForNerds;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka_common/ui/components/firka_shadow.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
@@ -122,9 +124,9 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
||||
context.pop();
|
||||
context.push(
|
||||
'/settings',
|
||||
extra: data.settings.items.group(
|
||||
"profile_settings",
|
||||
),
|
||||
extra: buildProfileSettingsTree(
|
||||
data.l10n,
|
||||
).children,
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
@@ -252,24 +254,9 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
||||
if (debugCounter == 10) {
|
||||
final navigator = Navigator.of(context);
|
||||
final router = GoRouter.of(context);
|
||||
data.settings
|
||||
.group("settings")
|
||||
.setBoolean(
|
||||
"developer_enabled",
|
||||
!data.settings
|
||||
.group("settings")
|
||||
.boolean("developer_enabled"),
|
||||
);
|
||||
|
||||
await data.isar.writeTxn(() async {
|
||||
await data.settings
|
||||
.group("settings")["developer_enabled"]!
|
||||
.save(data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await data.settings
|
||||
.group("settings")["developer_enabled"]!
|
||||
.postUpdate();
|
||||
await Settings.developerOptsEnabled.set(
|
||||
!Settings.developerOptsEnabled.value,
|
||||
);
|
||||
|
||||
navigator.pop();
|
||||
router.go('/home');
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'package:isar_community/isar.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/phone/screens/settings/settings_screen.dart';
|
||||
import 'package:firka/ui/phone/widgets/bubble_test.dart';
|
||||
@@ -185,10 +187,7 @@ class _HomeTimetableScreen extends FirkaState<HomeTimetableScreen>
|
||||
Widget _buildContent(BuildContext context) {
|
||||
List<Widget> ttWidgets = [];
|
||||
List<Widget> ttDays = [];
|
||||
final showABTimetable = widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("ab_timetable");
|
||||
final showABTimetable = Settings.ttToastABTimetable.value;
|
||||
// Build navigation icons using original dates
|
||||
var i = 0;
|
||||
for (MapEntry<DateTime, List<LessonCacheModel>> e in dates.entries) {
|
||||
@@ -327,9 +326,7 @@ class _HomeTimetableScreen extends FirkaState<HomeTimetableScreen>
|
||||
context,
|
||||
MediaQuery.of(context).size.height * 0.4,
|
||||
widget.data,
|
||||
widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast"),
|
||||
timetableToastTree(widget.data.l10n),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -313,9 +313,7 @@ class _HomeTimetableMonthlyScreen
|
||||
context,
|
||||
MediaQuery.of(context).size.height * 0.4,
|
||||
widget.data,
|
||||
widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast"),
|
||||
timetableToastTree(widget.data.l10n),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -2,7 +2,8 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/ui/components/firka_button.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -109,19 +110,7 @@ class _BetaScreenState extends FirkaState<BetaScreen> {
|
||||
),
|
||||
onTap: () async {
|
||||
if (counter != 0) return;
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
widget.data.settings
|
||||
.group("settings")
|
||||
.setBoolean("beta_warning", true);
|
||||
|
||||
await widget.data.settings
|
||||
.group("settings")["beta_warning"]!
|
||||
.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await widget.data.settings
|
||||
.group("settings")["beta_warning"]!
|
||||
.postUpdate();
|
||||
await Settings.betaWarning.set(true);
|
||||
if (!context.mounted) return;
|
||||
context.go('/home');
|
||||
},
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/services/live_activity_service.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
@@ -164,8 +166,7 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
prefetch();
|
||||
_preloadImages();
|
||||
|
||||
if (Platform.isIOS &&
|
||||
initData.settings.group("settings").boolean("beta_warning")) {
|
||||
if (Platform.isIOS && Settings.betaWarning.value) {
|
||||
Future.delayed(Duration(seconds: 3), () async {
|
||||
await LiveActivityService.showConsentScreenIfNeeded();
|
||||
});
|
||||
@@ -178,9 +179,9 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
}
|
||||
|
||||
void _preloadImages() async {
|
||||
final imagePaths = initData.settings.appIcons.keys
|
||||
.map((icon) => "assets/images/icons/$icon.webp")
|
||||
.toList();
|
||||
final imagePaths = appIconLabels(
|
||||
initData.l10n,
|
||||
).keys.map((icon) => "assets/images/icons/$icon.webp").toList();
|
||||
imagePaths.add("assets/images/background.webp");
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
import 'package:firka_common/data/database.dart';
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/core/image_preloader.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/setting.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/core/settings/settings_ui.dart';
|
||||
import 'package:firka/ui/components/firka_button.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
@@ -23,14 +24,15 @@ import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/app/initialization.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/services/live_activity_service.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import '../../widgets/login_webview.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
final LinkedHashMap<String, SettingsItem> items;
|
||||
final List<SettingsUiNode> items;
|
||||
|
||||
const SettingsScreen(this.data, this.items, {super.key});
|
||||
|
||||
@@ -49,34 +51,92 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
activeIcon = widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("customization")
|
||||
.subGroup("icon_picker")
|
||||
.iconString("icon_picker");
|
||||
activeIcon = Settings.appIcon.value;
|
||||
tokens = isarInit.tokenModels.where().sortByUpdatedAtMsDesc().findAllSync();
|
||||
}
|
||||
|
||||
String _roundedDoubleString(double value, DoubleSetting setting) {
|
||||
return setting.precision == 0
|
||||
? value.toString().split(".")[0]
|
||||
: value.toStringAsPrecision(setting.precision) == "0.0"
|
||||
? "0"
|
||||
: value.toStringAsPrecision(setting.precision);
|
||||
}
|
||||
|
||||
Widget _boolRow(SettingsUiBoolean item, SettingsRepository settings) {
|
||||
final value = settings.get(item.setting);
|
||||
|
||||
return FirkaCard(
|
||||
height: 52 + 12,
|
||||
left: [
|
||||
item.iconType != null
|
||||
? Row(
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
item.iconType!,
|
||||
item.iconData!,
|
||||
color: appStyle.colors.accent,
|
||||
package:
|
||||
item.iconType == FirkaIconType.icons ||
|
||||
item.iconType == FirkaIconType.majesticonsLocal
|
||||
? 'firka'
|
||||
: null,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
],
|
||||
)
|
||||
: SizedBox(),
|
||||
Text(
|
||||
item.title,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Switch(
|
||||
value: value,
|
||||
thumbColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.buttonSecondaryFill,
|
||||
WidgetState.any: appStyle.colors.accent,
|
||||
}),
|
||||
trackColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.accent,
|
||||
WidgetState.any: appStyle.colors.a10p,
|
||||
}),
|
||||
trackOutlineColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.accent,
|
||||
WidgetState.any: appStyle.colors.a15p,
|
||||
}),
|
||||
onChanged: (v) async {
|
||||
await settings.set(item.setting, v);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> createWidgetTree(
|
||||
Iterable<SettingsItem> items,
|
||||
SettingsStore settings, {
|
||||
Iterable<SettingsUiNode> items,
|
||||
SettingsRepository settings, {
|
||||
bool forceRender = false,
|
||||
}) {
|
||||
var widgets = List<Widget>.empty(growable: true);
|
||||
|
||||
for (var item in items) {
|
||||
if (!forceRender && !item.visibilityProvider()) continue;
|
||||
if (item is SettingsGroup) {
|
||||
widgets.addAll(createWidgetTree(item.children.values, settings));
|
||||
if (!forceRender && !item.visible()) continue;
|
||||
if (item is SettingsUiGroup) {
|
||||
widgets.addAll(createWidgetTree(item.children, settings));
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsPadding) {
|
||||
if (item is SettingsUiPadding) {
|
||||
widgets.add(SizedBox(width: item.padding, height: item.padding));
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsBackHeader) {
|
||||
if (item is SettingsUiBackHeader) {
|
||||
widgets.add(
|
||||
Column(
|
||||
children: [
|
||||
@@ -113,7 +173,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsHeader) {
|
||||
if (item is SettingsUiHeader) {
|
||||
widgets.add(
|
||||
Text(
|
||||
item.title,
|
||||
@@ -125,7 +185,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsMediumHeader) {
|
||||
if (item is SettingsUiMediumHeader) {
|
||||
widgets.add(
|
||||
Text(
|
||||
item.title,
|
||||
@@ -137,7 +197,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsHeaderSmall) {
|
||||
if (item is SettingsUiHeaderSmall) {
|
||||
widgets.add(
|
||||
Text(
|
||||
item.title,
|
||||
@@ -149,7 +209,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsSubGroup) {
|
||||
if (item is SettingsUiSubGroup) {
|
||||
List<Widget> cardWidgets = [];
|
||||
|
||||
if (item.iconType != null && item.iconData != null) {
|
||||
@@ -215,8 +275,9 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item is SettingsDouble) {
|
||||
var v = item.toRoundedString();
|
||||
if (item is SettingsUiDouble) {
|
||||
final value = settings.get(item.setting);
|
||||
var v = _roundedDoubleString(value, item.setting);
|
||||
|
||||
widgets.add(
|
||||
GestureDetector(
|
||||
@@ -258,82 +319,24 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
showSetDoubleSheet(context, item, widget.data, setState);
|
||||
showSetDoubleSheet(context, item, value, widget.data, setState);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsBoolean) {
|
||||
widgets.add(
|
||||
FirkaCard(
|
||||
height: 52 + 12,
|
||||
left: [
|
||||
item.iconType != null
|
||||
? Row(
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
item.iconType!,
|
||||
item.iconData!,
|
||||
color: appStyle.colors.accent,
|
||||
package:
|
||||
item.iconType == FirkaIconType.icons ||
|
||||
item.iconType ==
|
||||
FirkaIconType.majesticonsLocal
|
||||
? 'firka'
|
||||
: null,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
],
|
||||
)
|
||||
: SizedBox(),
|
||||
Text(
|
||||
item.title,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Switch(
|
||||
value: item.value,
|
||||
// activeColor: appStyle.colors.accent,
|
||||
thumbColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.buttonSecondaryFill,
|
||||
WidgetState.any: appStyle.colors.accent,
|
||||
}),
|
||||
trackColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.accent,
|
||||
WidgetState.any: appStyle.colors.a10p,
|
||||
}),
|
||||
trackOutlineColor: WidgetStateProperty.fromMap({
|
||||
WidgetState.selected: appStyle.colors.accent,
|
||||
WidgetState.any: appStyle.colors.a15p,
|
||||
}),
|
||||
onChanged: (v) async {
|
||||
setState(() {
|
||||
item.value = v;
|
||||
});
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await item.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await item.postUpdate();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (item is SettingsUiBoolean) {
|
||||
widgets.add(_boolRow(item, settings));
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsItemsRadio) {
|
||||
for (var i = 0; i < item.values.length; i++) {
|
||||
var k = item.values[i];
|
||||
if (item is SettingsUiEnum) {
|
||||
final activeIndex = settings.get(item.setting).index;
|
||||
for (var i = 0; i < item.optionLabels.length; i++) {
|
||||
var k = item.optionLabels[i];
|
||||
|
||||
if (item.values[item.activeIndex] == k) {
|
||||
if (i == activeIndex) {
|
||||
widgets.add(
|
||||
FirkaCard(
|
||||
height: 52 + 12,
|
||||
@@ -357,13 +360,10 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
return appStyle.colors.secondary;
|
||||
}),
|
||||
onChanged: (_) async {
|
||||
item.activeIndex = i;
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await item.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await item.postUpdate();
|
||||
await settings.set(
|
||||
item.setting,
|
||||
item.setting.values[i],
|
||||
);
|
||||
setState(() {});
|
||||
logger.finest('Settings saved');
|
||||
},
|
||||
@@ -389,14 +389,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
right: [SizedBox(height: 16 + 8)],
|
||||
),
|
||||
onTap: () async {
|
||||
item.activeIndex = i;
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await item.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await item.postUpdate();
|
||||
|
||||
await settings.set(item.setting, item.setting.values[i]);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
@@ -406,7 +399,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is ShowLicensePage) {
|
||||
if (item is SettingsUiLicensePage) {
|
||||
widgets.add(
|
||||
FutureBuilder<List<LicenseEntry>>(
|
||||
future: LicenseRegistry.licenses.toList(),
|
||||
@@ -515,7 +508,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item is SettingsAppIconPreview) {
|
||||
if (item is SettingsUiAppIconPreview) {
|
||||
widgets.add(
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -549,7 +542,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
settings.appIcons[activeIcon]!,
|
||||
appIconLabels(widget.data.l10n)[activeIcon]!,
|
||||
style: appStyle.fonts.H_12px.apply(
|
||||
color: appStyle.colors.card,
|
||||
),
|
||||
@@ -564,15 +557,11 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsAppIconPicker) {
|
||||
if (item is SettingsUiAppIconPicker) {
|
||||
List<Widget> pWidgets = [];
|
||||
|
||||
for (var group in item.iconGroups.keys) {
|
||||
if (widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("customization")
|
||||
.subGroup("icon_picker")
|
||||
.boolean("child_protection")) {
|
||||
if (Settings.childProtection.value) {
|
||||
if (group == widget.data.l10n.s_ci_icon_g7) {
|
||||
continue;
|
||||
}
|
||||
@@ -636,7 +625,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
},
|
||||
),
|
||||
Text(
|
||||
settings.appIcons[icon]!,
|
||||
appIconLabels(widget.data.l10n)[icon]!,
|
||||
style: appStyle.fonts.B_12R.apply(
|
||||
color: active
|
||||
? appStyle.colors.textPrimary
|
||||
@@ -671,22 +660,8 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
if (group == widget.data.l10n.s_ci_icon_g7 ||
|
||||
group == widget.data.l10n.s_ci_icon_g8) {
|
||||
var settingsWidgets = createWidgetTree(
|
||||
[
|
||||
widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("customization")
|
||||
.subGroup("icon_picker")["child_protection"]
|
||||
as SettingsBoolean,
|
||||
],
|
||||
settings,
|
||||
forceRender: true,
|
||||
);
|
||||
|
||||
pWidgets.add(SizedBox(height: 12));
|
||||
for (var w in settingsWidgets) {
|
||||
pWidgets.add(w);
|
||||
}
|
||||
pWidgets.add(_boolRow(item.childProtection, settings));
|
||||
}
|
||||
|
||||
pWidgets.add(SizedBox(height: 12));
|
||||
@@ -742,24 +717,14 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
if (settingAppIcon) return;
|
||||
settingAppIcon = true;
|
||||
|
||||
widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("customization")
|
||||
.subGroup("icon_picker")
|
||||
.setIconString("icon_picker", activeIcon);
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await widget.data.settings.save(
|
||||
widget.data.isar.appSettingsModels,
|
||||
);
|
||||
});
|
||||
await Settings.appIcon.set(activeIcon);
|
||||
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
|
||||
logger.info(
|
||||
settings.appIcons.keys
|
||||
.where((e) => e != "original")
|
||||
.join(","),
|
||||
appIconLabels(
|
||||
widget.data.l10n,
|
||||
).keys.where((e) => e != "original").join(","),
|
||||
);
|
||||
|
||||
logger.info(activeIcon);
|
||||
@@ -768,9 +733,9 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
logger.info(
|
||||
await channel.invokeMethod('set_icon', {
|
||||
"icon": activeIcon == "original" ? null : activeIcon,
|
||||
"icons": settings.appIcons.keys
|
||||
.where((e) => e != "original")
|
||||
.join(","),
|
||||
"icons": appIconLabels(
|
||||
widget.data.l10n,
|
||||
).keys.where((e) => e != "original").join(","),
|
||||
}),
|
||||
);
|
||||
},
|
||||
@@ -781,7 +746,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsKretenAccountPicker) {
|
||||
if (item is SettingsUiKretaAccountPicker) {
|
||||
for (TokenModel token in tokens) {
|
||||
final jwt = JWT.decode(token.idToken!);
|
||||
final payload = jwt.payload as Map<String, dynamic>;
|
||||
@@ -812,7 +777,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
),
|
||||
],
|
||||
right: [
|
||||
token.key != item.accountKey
|
||||
token.key != widget.data.settings.selectedAccountKey
|
||||
? SizedBox()
|
||||
: Checkbox(
|
||||
value: true,
|
||||
@@ -822,17 +787,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
return appStyle.colors.secondary;
|
||||
}),
|
||||
onChanged: (_) async {
|
||||
setState(() {
|
||||
// item.activeIndex = i;
|
||||
});
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await item.save(
|
||||
widget.data.isar.appSettingsModels,
|
||||
);
|
||||
});
|
||||
|
||||
await item.postUpdate();
|
||||
setState(() {});
|
||||
logger.finest('Settings saved');
|
||||
},
|
||||
),
|
||||
@@ -840,7 +795,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
if (token.key == item.accountKey) {
|
||||
if (token.key == widget.data.settings.selectedAccountKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -867,13 +822,8 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
item.accountKey = token.key;
|
||||
|
||||
await item.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await item.postUpdate();
|
||||
await widget.data.settings.setSelectedAccountKey(token.key);
|
||||
await initializeApp();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
var watchReachable = false;
|
||||
@@ -995,10 +945,8 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
await widget.data.isar.writeTxn(() async {
|
||||
await widget.data.isar.tokenModels.delete(active);
|
||||
|
||||
item.accountKey = 0;
|
||||
await item.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
await widget.data.settings.setSelectedAccountKey(0);
|
||||
|
||||
final accounts = await widget.data.isar.tokenModels
|
||||
.where()
|
||||
@@ -1078,7 +1026,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsButton) {
|
||||
if (item is SettingsUiButton) {
|
||||
widgets.add(
|
||||
GestureDetector(
|
||||
child: FirkaCard(
|
||||
@@ -1117,7 +1065,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
continue;
|
||||
}
|
||||
if (item is SettingsLogs) {
|
||||
if (item is SettingsUiLogs) {
|
||||
final logFileRegex = RegExp(r'^(\d{4})_(\d{2})_(\d{2})\.log$');
|
||||
|
||||
for (final entity in widget.data.appDir.listSync()) {
|
||||
@@ -1207,7 +1155,7 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var body = createWidgetTree(widget.items.values, widget.data.settings);
|
||||
var body = createWidgetTree(widget.items, widget.data.settings);
|
||||
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
@@ -1238,10 +1186,14 @@ class _SettingsScreenState extends FirkaState<SettingsScreen> {
|
||||
|
||||
void showSetDoubleSheet(
|
||||
BuildContext context,
|
||||
SettingsDouble setting,
|
||||
SettingsUiDouble item,
|
||||
double initialValue,
|
||||
AppInitialization data,
|
||||
void Function(VoidCallback fn) setStateOuter,
|
||||
) {
|
||||
final setting = item.setting;
|
||||
double currentValue = initialValue;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
@@ -1281,7 +1233,7 @@ void showSetDoubleSheet(
|
||||
children: [
|
||||
Center(
|
||||
child: Text(
|
||||
setting.title,
|
||||
item.title,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
@@ -1298,11 +1250,11 @@ void showSetDoubleSheet(
|
||||
Expanded(
|
||||
// TODO: Make a firka slider
|
||||
child: Slider(
|
||||
min: setting.minValue,
|
||||
value: setting.value,
|
||||
max: setting.maxValue,
|
||||
min: setting.min,
|
||||
value: currentValue,
|
||||
max: setting.max,
|
||||
divisions: setting.step != null
|
||||
? ((setting.maxValue - setting.minValue) /
|
||||
? ((setting.max - setting.min) /
|
||||
setting.step!)
|
||||
.round()
|
||||
: null,
|
||||
@@ -1310,30 +1262,43 @@ void showSetDoubleSheet(
|
||||
activeColor: appStyle.colors.secondary,
|
||||
inactiveColor: appStyle.colors.a15p,
|
||||
onChanged: (v) async {
|
||||
var next = setting.step != null
|
||||
? (v / setting.step!).round() *
|
||||
setting.step!
|
||||
: v;
|
||||
next = double.parse(
|
||||
setting.precision == 0
|
||||
? next.toString().split(".")[0]
|
||||
: next.toStringAsPrecision(
|
||||
setting.precision,
|
||||
) ==
|
||||
"0.0"
|
||||
? "0"
|
||||
: next.toStringAsPrecision(
|
||||
setting.precision,
|
||||
),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
if (setting.step != null) {
|
||||
setting.value =
|
||||
(v / setting.step!).round() *
|
||||
setting.step!;
|
||||
} else {
|
||||
setting.value = v;
|
||||
}
|
||||
setting.value = setting.toRoundedDouble();
|
||||
currentValue = next;
|
||||
});
|
||||
|
||||
await data.isar.writeTxn(() async {
|
||||
await setting.save(
|
||||
data.isar.appSettingsModels,
|
||||
);
|
||||
|
||||
setStateOuter(() {});
|
||||
});
|
||||
await setting.postUpdate();
|
||||
await data.settings.set(setting, next);
|
||||
setStateOuter(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
Text(
|
||||
setting.toRoundedString(),
|
||||
setting.precision == 0
|
||||
? currentValue.toString().split(".")[0]
|
||||
: currentValue.toStringAsPrecision(
|
||||
setting.precision,
|
||||
) ==
|
||||
"0.0"
|
||||
? "0"
|
||||
: currentValue.toStringAsPrecision(
|
||||
setting.precision,
|
||||
),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
@@ -1357,7 +1322,7 @@ void showSettingsSheet(
|
||||
BuildContext context,
|
||||
double height,
|
||||
AppInitialization data,
|
||||
LinkedHashMap<String, SettingsItem> items,
|
||||
List<SettingsUiNode> items,
|
||||
) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
@@ -28,24 +29,14 @@ class LessonWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
// we dont like events
|
||||
assert(lesson.type != TimetableConsts.event);
|
||||
final showTests = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("tests_and_homework");
|
||||
final showTests = Settings.ttToastTestsAndHw.value;
|
||||
|
||||
final test = lesson.test.loadAndGet();
|
||||
|
||||
final isSubstituted = lesson.substituteTeacher != null;
|
||||
final showSubstitutions =
|
||||
isSubstituted &&
|
||||
data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("substitution");
|
||||
final showLessonNos = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("lesson_no");
|
||||
isSubstituted && Settings.ttToastSubstitution.value;
|
||||
final showLessonNos = Settings.ttToastLessonNo.value;
|
||||
final isDismissed = lesson.type == "UresOra";
|
||||
|
||||
var accent = appStyle.colors.accent;
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka_common/data/models/app_settings_model.dart';
|
||||
import 'package:firka/services/live_activity_service.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/app/initialization.dart';
|
||||
@@ -10,7 +9,6 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
@@ -18,7 +16,6 @@ import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/api/token_grant.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class LoginWebviewWidget extends StatefulWidget {
|
||||
@@ -113,22 +110,14 @@ class _LoginWebviewWidgetState extends FirkaState<LoginWebviewWidget>
|
||||
|
||||
var tokenModel = TokenModel.fromResp(resp);
|
||||
|
||||
final accountPicker =
|
||||
(widget.data.settings.group(
|
||||
"profile_settings",
|
||||
)["e_kreta_account_picker"]
|
||||
as SettingsKretenAccountPicker);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.tokenModels.put(tokenModel);
|
||||
});
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
accountPicker.accountKey = tokenModel.key;
|
||||
await accountPicker.save(widget.data.isar.appSettingsModels);
|
||||
});
|
||||
|
||||
await accountPicker.postUpdate();
|
||||
await widget.data.settings.setSelectedAccountKey(
|
||||
tokenModel.key,
|
||||
);
|
||||
await initializeApp();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
final watchInstalled =
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka_common/core/debug_helper.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
@@ -114,10 +115,7 @@ class TimeTableDayWidget extends StatelessWidget {
|
||||
ttLessons.add(SizedBox());
|
||||
}
|
||||
|
||||
var showBreak = initData.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("breaks");
|
||||
var showBreak = Settings.ttToastBreaks.value;
|
||||
|
||||
for (var i = 0; i < lessons.length; i++) {
|
||||
var lesson = lessons[i];
|
||||
|
||||
@@ -66,6 +66,8 @@ dev_dependencies:
|
||||
flutter_lints: ^6.0.0
|
||||
yaml: ^3.1.2
|
||||
isar_community_generator: 3.3.0
|
||||
firka_settings_gen:
|
||||
path: ../firka_settings_gen
|
||||
android_notification_icons: ^0.0.1
|
||||
integration_test:
|
||||
sdk: flutter
|
||||
|
||||
7
firka_settings_gen/build.yaml
Normal file
7
firka_settings_gen/build.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
builders:
|
||||
settings_schema:
|
||||
import: "package:firka_settings_gen/builder.dart"
|
||||
builder_factories: ["settingsSchemaBuilder"]
|
||||
build_extensions: {"settings_schema.dart": ["settings_schema.gen.dart"]}
|
||||
auto_apply: dependents
|
||||
build_to: source
|
||||
84
firka_settings_gen/lib/builder.dart
Normal file
84
firka_settings_gen/lib/builder.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import "package:analyzer/dart/analysis/utilities.dart";
|
||||
import "package:analyzer/dart/ast/ast.dart";
|
||||
import "package:build/build.dart";
|
||||
|
||||
Builder settingsSchemaBuilder(BuilderOptions options) =>
|
||||
SettingsSchemaBuilder();
|
||||
|
||||
const _settingAnnotations = {
|
||||
"BoolSetting",
|
||||
"DoubleSetting",
|
||||
"EnumSetting",
|
||||
"StringSetting",
|
||||
};
|
||||
|
||||
/// Reads the @BoolSetting/@DoubleSetting/@EnumSetting/@StringSetting-annotated
|
||||
/// getters on SettingsSchema and emits the typed Settings registry.
|
||||
/// Parses settings_schema.dart syntactically (no resolution needed: the
|
||||
/// annotation's source text is copied verbatim into the generated literal).
|
||||
class SettingsSchemaBuilder implements Builder {
|
||||
@override
|
||||
Map<String, List<String>> get buildExtensions => {
|
||||
"settings_schema.dart": ["settings_schema.gen.dart"],
|
||||
};
|
||||
|
||||
@override
|
||||
Future<void> build(BuildStep buildStep) async {
|
||||
final source = await buildStep.readAsString(buildStep.inputId);
|
||||
final unit = parseString(content: source).unit;
|
||||
final schemaClass = unit.declarations
|
||||
.whereType<ClassDeclaration>()
|
||||
.firstWhere((c) => c.name.lexeme == "SettingsSchema");
|
||||
|
||||
final entries = <(String name, String dartType, String annotationClass, String args)>[];
|
||||
for (final member in schemaClass.members) {
|
||||
if (member is! MethodDeclaration || !member.isGetter) continue;
|
||||
|
||||
final annotation = member.metadata
|
||||
.where((a) => _settingAnnotations.contains(a.name.name))
|
||||
.firstOrNull;
|
||||
if (annotation == null) continue;
|
||||
|
||||
entries.add((
|
||||
member.name.lexeme,
|
||||
member.returnType!.toSource(),
|
||||
annotation.name.name,
|
||||
annotation.arguments!.toSource(),
|
||||
));
|
||||
}
|
||||
|
||||
final buffer = StringBuffer()
|
||||
..writeln("// GENERATED CODE - DO NOT MODIFY BY HAND")
|
||||
..writeln()
|
||||
..writeln('part of "settings_schema.dart";')
|
||||
..writeln()
|
||||
..writeln("class SettingsRegistry {");
|
||||
|
||||
for (final (name, _, annotationClass, args) in entries) {
|
||||
buffer.writeln(" static const $name = $annotationClass$args;");
|
||||
}
|
||||
|
||||
buffer
|
||||
..writeln()
|
||||
..writeln(" static const all = <Setting>[")
|
||||
..writeln(" ${entries.map((e) => e.$1).join(', ')},")
|
||||
..writeln(" ];")
|
||||
..writeln("}")
|
||||
..writeln()
|
||||
..writeln("extension SettingsAccessors on SettingsRepository {");
|
||||
|
||||
for (final (name, dartType, _, _) in entries) {
|
||||
buffer.writeln(
|
||||
" SilentlySettable<$dartType> get $name => "
|
||||
"SilentlySettable(this, SettingsRegistry.$name);",
|
||||
);
|
||||
}
|
||||
|
||||
buffer.writeln("}");
|
||||
|
||||
await buildStep.writeAsString(
|
||||
buildStep.inputId.changeExtension(".gen.dart"),
|
||||
buffer.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
10
firka_settings_gen/pubspec.yaml
Normal file
10
firka_settings_gen/pubspec.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: firka_settings_gen
|
||||
description: Code generator for firka's annotated settings_schema.dart.
|
||||
publish_to: "none"
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.0
|
||||
|
||||
dependencies:
|
||||
analyzer: ^8.2.0
|
||||
build: ^3.0.0
|
||||
Reference in New Issue
Block a user