Merge branch 'master' into notifications
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:filcnaplo/models/release.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/models/supporter.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/school.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
|
||||
@@ -68,7 +69,9 @@ class FilcAPI {
|
||||
http.Response res = await http.get(Uri.parse(config), headers: headers);
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
print(jsonDecode(res.body));
|
||||
if (kDebugMode) {
|
||||
print(jsonDecode(res.body));
|
||||
}
|
||||
return Config.fromJson(jsonDecode(res.body));
|
||||
} else if (res.statusCode == 429) {
|
||||
res = await http.get(Uri.parse(config));
|
||||
|
||||
@@ -57,14 +57,15 @@ Future loginApi({
|
||||
String nonceStr = await Provider.of<KretaClient>(context, listen: false)
|
||||
.getAPI(KretaAPI.nonce, json: false);
|
||||
|
||||
Nonce nonce = getNonce(nonceStr, username.replaceAll(' ', '') + ' ', instituteCode);
|
||||
Nonce nonce =
|
||||
getNonce(nonceStr, '${username.replaceAll(' ', '')} ', instituteCode);
|
||||
headers.addAll(nonce.header());
|
||||
|
||||
Map? res = await Provider.of<KretaClient>(context, listen: false)
|
||||
.postAPI(KretaAPI.login,
|
||||
headers: headers,
|
||||
body: User.loginBody(
|
||||
username: username.replaceAll(' ', '') + ' ',
|
||||
username: '${username.replaceAll(' ', '')} ',
|
||||
password: password,
|
||||
instituteCode: instituteCode,
|
||||
));
|
||||
@@ -83,7 +84,7 @@ Future loginApi({
|
||||
.getAPI(KretaAPI.student(instituteCode));
|
||||
Student student = Student.fromJson(studentJson!);
|
||||
var user = User(
|
||||
username: username.replaceAll(' ', '') + ' ',
|
||||
username: '${username.replaceAll(' ', '')} ',
|
||||
password: password,
|
||||
instituteCode: instituteCode,
|
||||
name: student.name,
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:io';
|
||||
|
||||
import 'package:filcnaplo/database/query.dart';
|
||||
import 'package:filcnaplo/database/store.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
// Check if live card is enabled .areActivitiesEnabled()
|
||||
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||
// Console log
|
||||
print("Live card enabled: $value");
|
||||
if (kDebugMode) {
|
||||
print("Live card enabled: $value");
|
||||
}
|
||||
|
||||
if (value) {
|
||||
_liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard");
|
||||
|
||||
@@ -5,28 +5,36 @@ import 'dart:io';
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
import 'package:filcnaplo/database/struct.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
|
||||
const settingsDB = DatabaseStruct("settings", {
|
||||
"language": String, "start_page": int, "rounding": int, "theme": int, "accent_color": int, "news": int, "news_state": int, "developer_mode": int,
|
||||
"update_channel": int, "config": String, "custom_accent_color": int, "custom_background_color": int, "custom_highlight_color": int, // general
|
||||
"grade_color1": int, "grade_color2": int, "grade_color3": int, "grade_color4": int, "grade_color5": int, // grade colors
|
||||
"language": String, "start_page": int, "rounding": int, "theme": int,
|
||||
"accent_color": int, "news": int, "news_state": int, "developer_mode": int,
|
||||
"update_channel": int, "config": String, "custom_accent_color": int,
|
||||
"custom_background_color": int, "custom_highlight_color": int, // general
|
||||
"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, "graph_class_avg": int, "presentation_mode": int, "bell_delay": int, "bell_delay_enabled": int,
|
||||
"grade_opening_fun": int, "icon_pack": String, "premium_scopes": String, "premium_token": String, "premium_login": String,
|
||||
"last_account_id": String, "renamed_subjects_enabled": int, "renamed_subjects_italics":int,
|
||||
"notifications": int, "notifications_bitfield": int,
|
||||
"notification_poll_interval": int, // notifications
|
||||
"x_filc_id": String, "graph_class_avg": int, "presentation_mode": int,
|
||||
"bell_delay": int, "bell_delay_enabled": int,
|
||||
"grade_opening_fun": int, "icon_pack": String, "premium_scopes": String,
|
||||
"premium_token": String, "premium_login": String,
|
||||
"last_account_id": String, "renamed_subjects_enabled": int,
|
||||
"renamed_subjects_italics": int,
|
||||
});
|
||||
// DON'T FORGET TO UPDATE DEFAULT VALUES IN `initDB` MIGRATION OR ELSE PARENTS WILL COMPLAIN ABOUT THEIR CHILDREN MISSING
|
||||
// YOU'VE BEEN WARNED!!!
|
||||
const usersDB = DatabaseStruct("users", {
|
||||
"id": String, "name": String, "username": String, "password": String, "institute_code": String, "student": String, "role": int,
|
||||
"id": String, "name": String, "username": String, "password": String,
|
||||
"institute_code": String, "student": String, "role": int,
|
||||
"nickname": String, "picture": String // premium only
|
||||
});
|
||||
const userDataDB = DatabaseStruct("user_data", {
|
||||
"id": String, "grades": String, "timetable": String, "exams": String, "homework": String, "messages": String, "notes": String,
|
||||
"id": String, "grades": String, "timetable": String, "exams": String,
|
||||
"homework": String, "messages": String, "notes": String,
|
||||
"events": String, "absences": String, "group_averages": String,
|
||||
// renamed subjects // non kreta data
|
||||
"renamed_subjects": String,
|
||||
@@ -34,7 +42,8 @@ const userDataDB = DatabaseStruct("user_data", {
|
||||
"last_seen_grade": int,
|
||||
});
|
||||
|
||||
Future<void> createTable(Database db, DatabaseStruct struct) => db.execute("CREATE TABLE IF NOT EXISTS ${struct.table} ($struct)");
|
||||
Future<void> createTable(Database db, DatabaseStruct struct) =>
|
||||
db.execute("CREATE TABLE IF NOT EXISTS ${struct.table} ($struct)");
|
||||
|
||||
Future<Database> initDB(DatabaseProvider database) async {
|
||||
Database db;
|
||||
@@ -50,9 +59,11 @@ Future<Database> initDB(DatabaseProvider database) async {
|
||||
await createTable(db, usersDB);
|
||||
await createTable(db, userDataDB);
|
||||
|
||||
if ((await db.rawQuery("SELECT COUNT(*) FROM settings"))[0].values.first == 0) {
|
||||
if ((await db.rawQuery("SELECT COUNT(*) FROM settings"))[0].values.first ==
|
||||
0) {
|
||||
// Set default values for table Settings
|
||||
await db.insert("settings", SettingsProvider.defaultSettings(database: database).toMap());
|
||||
await db.insert("settings",
|
||||
SettingsProvider.defaultSettings(database: database).toMap());
|
||||
}
|
||||
|
||||
// Migrate Databases
|
||||
@@ -60,7 +71,8 @@ Future<Database> initDB(DatabaseProvider database) async {
|
||||
await migrateDB(
|
||||
db,
|
||||
struct: settingsDB,
|
||||
defaultValues: SettingsProvider.defaultSettings(database: database).toMap(),
|
||||
defaultValues:
|
||||
SettingsProvider.defaultSettings(database: database).toMap(),
|
||||
);
|
||||
await migrateDB(
|
||||
db,
|
||||
@@ -68,7 +80,8 @@ Future<Database> initDB(DatabaseProvider database) async {
|
||||
defaultValues: {"role": 0, "nickname": "", "picture": ""},
|
||||
);
|
||||
await migrateDB(db, struct: userDataDB, defaultValues: {
|
||||
"grades": "[]", "timetable": "[]", "exams": "[]", "homework": "[]", "messages": "[]", "notes": "[]", "events": "[]", "absences": "[]",
|
||||
"grades": "[]", "timetable": "[]", "exams": "[]", "homework": "[]",
|
||||
"messages": "[]", "notes": "[]", "events": "[]", "absences": "[]",
|
||||
"group_averages": "[]",
|
||||
// renamed subjects // non kreta data
|
||||
"renamed_subjects": "{}",
|
||||
@@ -99,7 +112,8 @@ Future<void> migrateDB(
|
||||
|
||||
// go through each row and add missing keys or delete non existing keys
|
||||
await Future.forEach<Map<String, Object?>>(originalRows, (original) async {
|
||||
bool migrationRequired = struct.struct.keys.any((key) => !original.containsKey(key) || original[key] == null) ||
|
||||
bool migrationRequired = struct.struct.keys.any(
|
||||
(key) => !original.containsKey(key) || original[key] == null) ||
|
||||
original.keys.any((key) => !struct.struct.containsKey(key));
|
||||
|
||||
if (migrationRequired) {
|
||||
|
||||
@@ -157,11 +157,15 @@ void backgroundHeadlessTask(HeadlessTask task) {
|
||||
String taskId = task.taskId;
|
||||
bool isTimeout = task.timeout;
|
||||
if (isTimeout) {
|
||||
print("[BackgroundFetch] Headless task timed-out: $taskId");
|
||||
if (kDebugMode) {
|
||||
print("[BackgroundFetch] Headless task timed-out: $taskId");
|
||||
}
|
||||
BackgroundFetch.finish(taskId);
|
||||
return;
|
||||
}
|
||||
print('[BackgroundFetch] Headless event received.');
|
||||
if (kDebugMode) {
|
||||
print('[BackgroundFetch] Headless event received.');
|
||||
}
|
||||
NotificationsHelper().backgroundJob();
|
||||
BackgroundFetch.finish(task.taskId);
|
||||
}
|
||||
|
||||
@@ -366,66 +366,88 @@ class SettingsProvider extends ChangeNotifier {
|
||||
if (startPage != null && startPage != _startPage) _startPage = startPage;
|
||||
if (rounding != null && rounding != _rounding) _rounding = rounding;
|
||||
if (theme != null && theme != _theme) _theme = theme;
|
||||
if (accentColor != null && accentColor != _accentColor)
|
||||
if (accentColor != null && accentColor != _accentColor) {
|
||||
_accentColor = accentColor;
|
||||
if (gradeColors != null && gradeColors != _gradeColors)
|
||||
}
|
||||
if (gradeColors != null && gradeColors != _gradeColors) {
|
||||
_gradeColors = gradeColors;
|
||||
if (newsEnabled != null && newsEnabled != _newsEnabled)
|
||||
}
|
||||
if (newsEnabled != null && newsEnabled != _newsEnabled) {
|
||||
_newsEnabled = newsEnabled;
|
||||
}
|
||||
if (newsState != null && newsState != _newsState) _newsState = newsState;
|
||||
if (notificationsEnabled != null &&
|
||||
notificationsEnabled != _notificationsEnabled)
|
||||
notificationsEnabled != _notificationsEnabled) {
|
||||
_notificationsEnabled = notificationsEnabled;
|
||||
}
|
||||
if (notificationsBitfield != null &&
|
||||
notificationsBitfield != _notificationsBitfield)
|
||||
notificationsBitfield != _notificationsBitfield) {
|
||||
_notificationsBitfield = notificationsBitfield;
|
||||
if (developerMode != null && developerMode != _developerMode)
|
||||
}
|
||||
if (developerMode != null && developerMode != _developerMode) {
|
||||
_developerMode = developerMode;
|
||||
}
|
||||
if (notificationPollInterval != null &&
|
||||
notificationPollInterval != _notificationPollInterval) {
|
||||
_notificationPollInterval = notificationPollInterval;
|
||||
}
|
||||
if (vibrate != null && vibrate != _vibrate) _vibrate = vibrate;
|
||||
if (abWeeks != null && abWeeks != _abWeeks) _abWeeks = abWeeks;
|
||||
if (swapABweeks != null && swapABweeks != _swapABweeks)
|
||||
if (swapABweeks != null && swapABweeks != _swapABweeks) {
|
||||
_swapABweeks = swapABweeks;
|
||||
if (updateChannel != null && updateChannel != _updateChannel)
|
||||
}
|
||||
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)
|
||||
if (graphClassAvg != null && graphClassAvg != _graphClassAvg) {
|
||||
_graphClassAvg = graphClassAvg;
|
||||
}
|
||||
if (goodStudent != null) _goodStudent = goodStudent;
|
||||
if (presentationMode != null && presentationMode != _presentationMode)
|
||||
if (presentationMode != null && presentationMode != _presentationMode) {
|
||||
_presentationMode = presentationMode;
|
||||
}
|
||||
if (bellDelay != null && bellDelay != _bellDelay) _bellDelay = bellDelay;
|
||||
if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled)
|
||||
if (bellDelayEnabled != null && bellDelayEnabled != _bellDelayEnabled) {
|
||||
_bellDelayEnabled = bellDelayEnabled;
|
||||
if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun)
|
||||
}
|
||||
if (gradeOpeningFun != null && gradeOpeningFun != _gradeOpeningFun) {
|
||||
_gradeOpeningFun = gradeOpeningFun;
|
||||
}
|
||||
if (iconPack != null && iconPack != _iconPack) _iconPack = iconPack;
|
||||
if (customAccentColor != null && customAccentColor != _customAccentColor)
|
||||
if (customAccentColor != null && customAccentColor != _customAccentColor) {
|
||||
_customAccentColor = customAccentColor;
|
||||
}
|
||||
if (customBackgroundColor != null &&
|
||||
customBackgroundColor != _customBackgroundColor)
|
||||
customBackgroundColor != _customBackgroundColor) {
|
||||
_customBackgroundColor = customBackgroundColor;
|
||||
}
|
||||
if (customHighlightColor != null &&
|
||||
customHighlightColor != _customHighlightColor)
|
||||
customHighlightColor != _customHighlightColor) {
|
||||
_customHighlightColor = customHighlightColor;
|
||||
if (premiumScopes != null && premiumScopes != _premiumScopes)
|
||||
}
|
||||
if (premiumScopes != null && premiumScopes != _premiumScopes) {
|
||||
_premiumScopes = premiumScopes;
|
||||
if (premiumAccessToken != null && premiumAccessToken != _premiumAccessToken)
|
||||
}
|
||||
if (premiumAccessToken != null &&
|
||||
premiumAccessToken != _premiumAccessToken) {
|
||||
_premiumAccessToken = premiumAccessToken;
|
||||
if (premiumLogin != null && premiumLogin != _premiumLogin)
|
||||
}
|
||||
if (premiumLogin != null && premiumLogin != _premiumLogin) {
|
||||
_premiumLogin = premiumLogin;
|
||||
if (lastAccountId != null && lastAccountId != _lastAccountId)
|
||||
}
|
||||
if (lastAccountId != null && lastAccountId != _lastAccountId) {
|
||||
_lastAccountId = lastAccountId;
|
||||
}
|
||||
if (renamedSubjectsEnabled != null &&
|
||||
renamedSubjectsEnabled != _renamedSubjectsEnabled)
|
||||
renamedSubjectsEnabled != _renamedSubjectsEnabled) {
|
||||
_renamedSubjectsEnabled = renamedSubjectsEnabled;
|
||||
if (renamedSubjectsItalics != null &&
|
||||
renamedSubjectsItalics != _renamedSubjectsItalics)
|
||||
}
|
||||
if (renamedSubjectsItalics != null &&
|
||||
renamedSubjectsItalics != _renamedSubjectsItalics) {
|
||||
_renamedSubjectsItalics = renamedSubjectsItalics;
|
||||
}
|
||||
if (store) await _database?.store.storeSettings(this);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class DarkMobileAppColors implements ThemeAppColors {
|
||||
final gradeTwo = const Color(0xFFAE3DF4);
|
||||
@override
|
||||
final gradeOne = const Color(0xFFF43DAB);
|
||||
@override
|
||||
final purple = const Color(0xffBF5AF2);
|
||||
@override
|
||||
final pink = const Color(0xffFF375F);
|
||||
|
||||
Reference in New Issue
Block a user