settings class avg graph

This commit is contained in:
unknown 2022-02-28 17:31:03 +01:00
parent f147ae328e
commit 3ee91e7543
No known key found for this signature in database
GPG Key ID: 1D070E0B09CFB257
3 changed files with 20 additions and 10 deletions

View File

@ -17,13 +17,14 @@ Future<Database> 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<DatabaseStruct> 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

View File

@ -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<void> 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<DatabaseProvider>(context, listen: false);
await database.store.storeSettings(this);

@ -1 +1 @@
Subproject commit 9ffa142eaa414c47d105dd7a027b7f25b0019a18
Subproject commit 866b0f296fb57b5904054d18412521ed3e38fdc8