From 3ee91e7543d67a79a137a591f9bfb46c87f33a4a Mon Sep 17 00:00:00 2001 From: unknown <55nknown@pm.me> Date: Mon, 28 Feb 2022 17:31:03 +0100 Subject: [PATCH] settings class avg graph --- filcnaplo/lib/database/init.dart | 7 ++++--- filcnaplo/lib/models/settings.dart | 21 +++++++++++++++------ filcnaplo_mobile_ui | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/filcnaplo/lib/database/init.dart b/filcnaplo/lib/database/init.dart index 170553f..36e5864 100644 --- a/filcnaplo/lib/database/init.dart +++ b/filcnaplo/lib/database/init.dart @@ -17,13 +17,14 @@ Future initDB() async { db = await openDatabase("app.db"); } - var settingsDB = await createSettingsTable(db); - // Create table Users var usersDB = await createUsersTable(db); await db.execute("CREATE TABLE IF NOT EXISTS user_data (" "id TEXT NOT NULL, grades TEXT, timetable TEXT, exams TEXT, homework TEXT, messages TEXT, notes TEXT, events TEXT, absences TEXT)"); + // Create table Settings + var settingsDB = await createSettingsTable(db); + if ((await db.rawQuery("SELECT COUNT(*) FROM settings"))[0].values.first == 0) { // Set default values for table Settings await db.insert("settings", SettingsProvider.defaultSettings().toMap()); @@ -43,7 +44,7 @@ Future createSettingsTable(Database db) async { "grade_color1": int, "grade_color2": int, "grade_color3": int, "grade_color4": int, "grade_color5": int, // grade colors "vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int, "notifications": int, "notifications_bitfield": int, "notification_poll_interval": int, // notifications - "x_filc_id": String, + "x_filc_id": String, "graph_class_avg": int, }); // Create table Settings diff --git a/filcnaplo/lib/models/settings.dart b/filcnaplo/lib/models/settings.dart index ffb2666..7b81750 100644 --- a/filcnaplo/lib/models/settings.dart +++ b/filcnaplo/lib/models/settings.dart @@ -46,6 +46,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel _updateChannel; Config _config; String _xFilcId; + bool _graphClassAvg; SettingsProvider({ required String language, @@ -66,6 +67,7 @@ class SettingsProvider extends ChangeNotifier { required UpdateChannel updateChannel, required Config config, required String xFilcId, + required bool graphClassAvg, }) : _language = language, _startPage = startPage, _rounding = rounding, @@ -83,7 +85,8 @@ class SettingsProvider extends ChangeNotifier { _swapABweeks = swapABweeks, _updateChannel = updateChannel, _config = config, - _xFilcId = xFilcId; + _xFilcId = xFilcId, + _graphClassAvg = graphClassAvg; factory SettingsProvider.fromMap(Map map) { return SettingsProvider( @@ -99,18 +102,19 @@ class SettingsProvider extends ChangeNotifier { Color(map["grade_color4"]), Color(map["grade_color5"]), ], - newsEnabled: map["news"] == 1 ? true : false, + newsEnabled: map["news"] == 1, newsState: map["news_state"], - notificationsEnabled: map["notifications"] == 1 ? true : false, + notificationsEnabled: map["notifications"] == 1, notificationsBitfield: map["notifications_bitfield"], notificationPollInterval: map["notification_poll_interval"], - developerMode: map["developer_mode"] == 1 ? true : false, + developerMode: map["developer_mode"] == 1, vibrate: VibrationStrength.values[map["vibration_strength"]], - abWeeks: map["ab_weeks"] == 1 ? true : false, - swapABweeks: map["swap_ab_weeks"] == 1 ? true : false, + abWeeks: map["ab_weeks"] == 1, + swapABweeks: map["swap_ab_weeks"] == 1, updateChannel: UpdateChannel.values[map["update_channel"]], config: Config.fromJson(jsonDecode(map["config"] ?? "{}")), xFilcId: map["x_filc_id"], + graphClassAvg: map["graph_class_avg"] == 1, ); } @@ -138,6 +142,7 @@ class SettingsProvider extends ChangeNotifier { "notification_poll_interval": _notificationPollInterval, "config": jsonEncode(config.json), "x_filc_id": _xFilcId, + "graph_class_avg": _graphClassAvg ? 1 : 0, }; } @@ -167,6 +172,7 @@ class SettingsProvider extends ChangeNotifier { updateChannel: UpdateChannel.stable, config: Config.fromJson({}), xFilcId: const Uuid().v4(), + graphClassAvg: false, ); } @@ -189,6 +195,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel get updateChannel => _updateChannel; Config get config => _config; String get xFilcId => _xFilcId; + bool get graphClassAvg => _graphClassAvg; Future update( BuildContext context, { @@ -211,6 +218,7 @@ class SettingsProvider extends ChangeNotifier { UpdateChannel? updateChannel, Config? config, String? xFilcId, + bool? graphClassAvg, }) async { if (language != null && language != _language) _language = language; if (startPage != null && startPage != _startPage) _startPage = startPage; @@ -232,6 +240,7 @@ class SettingsProvider extends ChangeNotifier { if (updateChannel != null && updateChannel != _updateChannel) _updateChannel = updateChannel; if (config != null && config != _config) _config = config; if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId; + if (graphClassAvg != null && graphClassAvg != _graphClassAvg) _graphClassAvg = graphClassAvg; database ??= Provider.of(context, listen: false); await database.store.storeSettings(this); diff --git a/filcnaplo_mobile_ui b/filcnaplo_mobile_ui index 9ffa142..866b0f2 160000 --- a/filcnaplo_mobile_ui +++ b/filcnaplo_mobile_ui @@ -1 +1 @@ -Subproject commit 9ffa142eaa414c47d105dd7a027b7f25b0019a18 +Subproject commit 866b0f296fb57b5904054d18412521ed3e38fdc8