Merge branch 'dev' 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));
|
||||
|
||||
@@ -49,22 +49,22 @@ Future loginApi({
|
||||
}) async {
|
||||
Provider.of<KretaClient>(context, listen: false).userAgent =
|
||||
Provider.of<SettingsProvider>(context, listen: false).config.userAgent;
|
||||
|
||||
|
||||
Map<String, String> headers = {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
|
||||
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, 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,
|
||||
password: password,
|
||||
instituteCode: instituteCode,
|
||||
));
|
||||
@@ -83,7 +83,7 @@ Future loginApi({
|
||||
.getAPI(KretaAPI.student(instituteCode));
|
||||
Student student = Student.fromJson(studentJson!);
|
||||
var user = User(
|
||||
username: username.replaceAll(' ', '') + ' ',
|
||||
username: username,
|
||||
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';
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ enum LiveCardState {
|
||||
duringBreak,
|
||||
morning,
|
||||
afternoon,
|
||||
night
|
||||
night,
|
||||
summary
|
||||
}
|
||||
|
||||
class LiveCardProvider extends ChangeNotifier {
|
||||
@@ -39,6 +40,8 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
String? _latestActivityId;
|
||||
Map<String, String> _lastActivity = {};
|
||||
|
||||
bool _hasCheckedTimetable = false;
|
||||
|
||||
LiveCardProvider({
|
||||
required TimetableProvider timetable,
|
||||
required SettingsProvider settings,
|
||||
@@ -47,7 +50,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");
|
||||
@@ -105,6 +110,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
switch (currentState) {
|
||||
case LiveCardState.duringLesson:
|
||||
return {
|
||||
"color": _settings.liveActivityColor.toString(),
|
||||
"icon": currentLesson != null
|
||||
? SubjectIcon.resolveName(subject: currentLesson?.subject)
|
||||
: "book",
|
||||
@@ -137,6 +143,7 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
final diff = getFloorDifference();
|
||||
|
||||
return {
|
||||
"color": _settings.liveActivityColor.toString(),
|
||||
"icon": iconFloorMap[diff] ?? "cup.and.saucer",
|
||||
"title": "Szünet",
|
||||
"description": "go $diff".i18n.fill([
|
||||
@@ -195,7 +202,8 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
|
||||
List<Lesson> today = _today(_timetable);
|
||||
|
||||
if (today.isEmpty) {
|
||||
if (today.isEmpty && !_hasCheckedTimetable) {
|
||||
_hasCheckedTimetable = true;
|
||||
await _timetable.fetch(week: Week.current());
|
||||
today = _today(_timetable);
|
||||
}
|
||||
@@ -249,7 +257,10 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLesson != null) {
|
||||
if (now.isBefore(DateTime(now.year, DateTime.august, 31)) &&
|
||||
now.isAfter(DateTime(now.year, DateTime.june, 14))) {
|
||||
currentState = LiveCardState.summary;
|
||||
} else if (currentLesson != null) {
|
||||
currentState = LiveCardState.duringLesson;
|
||||
} else if (nextLesson != null && prevLesson != null) {
|
||||
currentState = LiveCardState.duringBreak;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:filcnaplo/api/client.dart';
|
||||
import 'package:filcnaplo/models/news.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
@@ -11,7 +8,7 @@ import 'package:provider/provider.dart';
|
||||
class NewsProvider extends ChangeNotifier {
|
||||
// Private
|
||||
late List<News> _news;
|
||||
late int _state;
|
||||
//late int _state;
|
||||
late int _fresh;
|
||||
bool show = false;
|
||||
late BuildContext _context;
|
||||
@@ -30,56 +27,83 @@ class NewsProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> restore() async {
|
||||
// Load news state from the database
|
||||
var state_ = Provider.of<SettingsProvider>(_context, listen: false).newsState;
|
||||
var seen_ = Provider.of<SettingsProvider>(_context, listen: false).seenNews;
|
||||
|
||||
if (state_ == -1) {
|
||||
if (seen_.isEmpty) {
|
||||
var news_ = await FilcAPI.getNews();
|
||||
if (news_ != null) {
|
||||
state_ = news_.length;
|
||||
_news = news_;
|
||||
show = true;
|
||||
}
|
||||
}
|
||||
|
||||
_state = state_;
|
||||
Provider.of<SettingsProvider>(_context, listen: false).update(newsState: _state);
|
||||
//_state = seen_;
|
||||
// Provider.of<SettingsProvider>(_context, listen: false)
|
||||
// .update(seenNewsId: news_.id);
|
||||
}
|
||||
|
||||
Future<void> fetch() async {
|
||||
var news_ = await FilcAPI.getNews();
|
||||
if (news_ == null) return;
|
||||
|
||||
show = false;
|
||||
|
||||
_news = news_;
|
||||
_fresh = news_.length - _state;
|
||||
|
||||
if (_fresh < 0) {
|
||||
_state = news_.length;
|
||||
Provider.of<SettingsProvider>(_context, listen: false).update(newsState: _state);
|
||||
for (var news in news_) {
|
||||
if (news.expireDate.isAfter(DateTime.now()) &&
|
||||
Provider.of<SettingsProvider>(_context, listen: false)
|
||||
.seenNews
|
||||
.contains(news.id) ==
|
||||
false) {
|
||||
show = true;
|
||||
Provider.of<SettingsProvider>(_context, listen: false)
|
||||
.update(seenNewsId: news.id);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
// print(news_.length);
|
||||
// print(_state);
|
||||
|
||||
_fresh = max(_fresh, 0);
|
||||
// _news = news_;
|
||||
// _fresh = news_.length - _state;
|
||||
|
||||
if (_fresh > 0) {
|
||||
show = true;
|
||||
notifyListeners();
|
||||
}
|
||||
// if (_fresh < 0) {
|
||||
// _state = news_.length;
|
||||
// Provider.of<SettingsProvider>(_context, listen: false)
|
||||
// .update(newsState: _state);
|
||||
// }
|
||||
|
||||
// _fresh = max(_fresh, 0);
|
||||
|
||||
// if (_fresh > 0) {
|
||||
// show = true;
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
// print(_fresh);
|
||||
// print(_state);
|
||||
// print(show);
|
||||
}
|
||||
|
||||
void lock() => show = false;
|
||||
|
||||
void release() {
|
||||
if (_fresh == 0) return;
|
||||
// if (_fresh == 0) return;
|
||||
|
||||
_fresh--;
|
||||
_state++;
|
||||
// _fresh--;
|
||||
// //_state++;
|
||||
|
||||
Provider.of<SettingsProvider>(_context, listen: false).update(newsState: _state);
|
||||
// // Provider.of<SettingsProvider>(_context, listen: false)
|
||||
// // .update(seenNewsId: _state);
|
||||
|
||||
if (_fresh > 0) {
|
||||
show = true;
|
||||
} else {
|
||||
show = false;
|
||||
}
|
||||
// if (_fresh > 0) {
|
||||
// show = true;
|
||||
// } else {
|
||||
// show = false;
|
||||
// }
|
||||
|
||||
notifyListeners();
|
||||
// notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:filcnaplo/theme/theme.dart';
|
||||
import 'package:filcnaplo_kreta_api/client/client.dart';
|
||||
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:i18n_extension/i18n_widget.dart';
|
||||
@@ -113,7 +114,8 @@ class App extends StatelessWidget {
|
||||
ChangeNotifierProvider<ExamProvider>(
|
||||
create: (context) => ExamProvider(context: context)),
|
||||
ChangeNotifierProvider<HomeworkProvider>(
|
||||
create: (context) => HomeworkProvider(context: context)),
|
||||
create: (context) =>
|
||||
HomeworkProvider(context: context, database: database)),
|
||||
ChangeNotifierProvider<MessageProvider>(
|
||||
create: (context) => MessageProvider(context: context)),
|
||||
ChangeNotifierProvider<NoteProvider>(
|
||||
@@ -194,8 +196,19 @@ class App extends StatelessWidget {
|
||||
}
|
||||
|
||||
Route? rootNavigator(RouteSettings route) {
|
||||
// if platform == android || platform == ios
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (kIsWeb) {
|
||||
switch (route.name) {
|
||||
case "login_back":
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const desktop.LoginScreen(back: true));
|
||||
case "login":
|
||||
return _rootRoute(const desktop.LoginScreen());
|
||||
case "navigation":
|
||||
return _rootRoute(const desktop.NavigationScreen());
|
||||
case "login_to_navigation":
|
||||
return desktop.loginRoute(const desktop.NavigationScreen());
|
||||
}
|
||||
} else if (Platform.isAndroid || Platform.isIOS) {
|
||||
switch (route.name) {
|
||||
case "login_back":
|
||||
return CupertinoPageRoute(
|
||||
|
||||
@@ -5,41 +5,64 @@ 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';
|
||||
import 'package:flutter/foundation.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.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, "seen_news": String,
|
||||
"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, "renamed_teachers_enabled": int,
|
||||
"renamed_teachers_italics": int,
|
||||
"live_activity_color": String,
|
||||
});
|
||||
// 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,
|
||||
// renamed teachers // non kreta data
|
||||
"renamed_teachers": String,
|
||||
// "subject_lesson_count": String, // non kreta data
|
||||
"last_seen_grade": int,
|
||||
// goal planning // non kreta data
|
||||
"goal_plans": String,
|
||||
"goal_averages": String,
|
||||
"goal_befores": String,
|
||||
"goal_pin_dates": String,
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
if (kIsWeb) {
|
||||
db = await databaseFactoryFfiWeb.openDatabase("app.db");
|
||||
} else if (Platform.isLinux || Platform.isWindows) {
|
||||
sqfliteFfiInit();
|
||||
db = await databaseFactoryFfi.openDatabase("app.db");
|
||||
} else {
|
||||
@@ -50,9 +73,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 +85,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,12 +94,20 @@ 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": "{}",
|
||||
// renamed teachers // non kreta data
|
||||
"renamed_teachers": "{}",
|
||||
// "subject_lesson_count": "{}", // non kreta data
|
||||
"last_seen_grade": 0,
|
||||
// goal planning // non kreta data
|
||||
"goal_plans": "{}",
|
||||
"goal_averages": "{}",
|
||||
"goal_befores": "{}",
|
||||
"goal_pin_dates": "{}",
|
||||
});
|
||||
} catch (error) {
|
||||
print("ERROR: migrateDB: $error");
|
||||
@@ -99,7 +133,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) {
|
||||
|
||||
@@ -26,7 +26,8 @@ class DatabaseQuery {
|
||||
|
||||
Future<SettingsProvider> getSettings(DatabaseProvider database) async {
|
||||
Map settingsMap = (await db.query("settings")).elementAt(0);
|
||||
SettingsProvider settings = SettingsProvider.fromMap(settingsMap, database: database);
|
||||
SettingsProvider settings =
|
||||
SettingsProvider.fromMap(settingsMap, database: database);
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -36,7 +37,10 @@ class DatabaseQuery {
|
||||
for (var user in usersMap) {
|
||||
userProvider.addUser(User.fromMap(user));
|
||||
}
|
||||
if (userProvider.getUsers().map((e) => e.id).contains(settings.lastAccountId)) {
|
||||
if (userProvider
|
||||
.getUsers()
|
||||
.map((e) => e.id)
|
||||
.contains(settings.lastAccountId)) {
|
||||
userProvider.setUser(settings.lastAccountId);
|
||||
} else {
|
||||
if (usersMap.isNotEmpty) {
|
||||
@@ -54,100 +58,133 @@ class UserDatabaseQuery {
|
||||
final Database db;
|
||||
|
||||
Future<List<Grade>> getGrades({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? gradesJson = userData.elementAt(0)["grades"] as String?;
|
||||
if (gradesJson == null) return [];
|
||||
List<Grade> grades = (jsonDecode(gradesJson) as List).map((e) => Grade.fromJson(e)).toList();
|
||||
List<Grade> grades =
|
||||
(jsonDecode(gradesJson) as List).map((e) => Grade.fromJson(e)).toList();
|
||||
return grades;
|
||||
}
|
||||
|
||||
Future<Map<Week, List<Lesson>>> getLessons({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? lessonsJson = userData.elementAt(0)["timetable"] as String?;
|
||||
if (lessonsJson == null) return {};
|
||||
if (jsonDecode(lessonsJson) is List) return {};
|
||||
Map<Week, List<Lesson>> lessons = (jsonDecode(lessonsJson) as Map).cast<String, List>().map((key, value) {
|
||||
return MapEntry(Week.fromId(int.parse(key)), value.cast<Map<String, Object?>>().map((e) => Lesson.fromJson(e)).toList());
|
||||
Map<Week, List<Lesson>> lessons =
|
||||
(jsonDecode(lessonsJson) as Map).cast<String, List>().map((key, value) {
|
||||
return MapEntry(
|
||||
Week.fromId(int.parse(key)),
|
||||
value
|
||||
.cast<Map<String, Object?>>()
|
||||
.map((e) => Lesson.fromJson(e))
|
||||
.toList());
|
||||
}).cast();
|
||||
return lessons;
|
||||
}
|
||||
|
||||
Future<List<Exam>> getExams({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? examsJson = userData.elementAt(0)["exams"] as String?;
|
||||
if (examsJson == null) return [];
|
||||
List<Exam> exams = (jsonDecode(examsJson) as List).map((e) => Exam.fromJson(e)).toList();
|
||||
List<Exam> exams =
|
||||
(jsonDecode(examsJson) as List).map((e) => Exam.fromJson(e)).toList();
|
||||
return exams;
|
||||
}
|
||||
|
||||
Future<List<Homework>> getHomework({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? homeworkJson = userData.elementAt(0)["homework"] as String?;
|
||||
if (homeworkJson == null) return [];
|
||||
List<Homework> homework = (jsonDecode(homeworkJson) as List).map((e) => Homework.fromJson(e)).toList();
|
||||
List<Homework> homework = (jsonDecode(homeworkJson) as List)
|
||||
.map((e) => Homework.fromJson(e))
|
||||
.toList();
|
||||
return homework;
|
||||
}
|
||||
|
||||
Future<List<Message>> getMessages({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? messagesJson = userData.elementAt(0)["messages"] as String?;
|
||||
if (messagesJson == null) return [];
|
||||
List<Message> messages = (jsonDecode(messagesJson) as List).map((e) => Message.fromJson(e)).toList();
|
||||
List<Message> messages = (jsonDecode(messagesJson) as List)
|
||||
.map((e) => Message.fromJson(e))
|
||||
.toList();
|
||||
return messages;
|
||||
}
|
||||
|
||||
Future<List<Note>> getNotes({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? notesJson = userData.elementAt(0)["notes"] as String?;
|
||||
if (notesJson == null) return [];
|
||||
List<Note> notes = (jsonDecode(notesJson) as List).map((e) => Note.fromJson(e)).toList();
|
||||
List<Note> notes =
|
||||
(jsonDecode(notesJson) as List).map((e) => Note.fromJson(e)).toList();
|
||||
return notes;
|
||||
}
|
||||
|
||||
Future<List<Event>> getEvents({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? eventsJson = userData.elementAt(0)["events"] as String?;
|
||||
if (eventsJson == null) return [];
|
||||
List<Event> events = (jsonDecode(eventsJson) as List).map((e) => Event.fromJson(e)).toList();
|
||||
List<Event> events =
|
||||
(jsonDecode(eventsJson) as List).map((e) => Event.fromJson(e)).toList();
|
||||
return events;
|
||||
}
|
||||
|
||||
Future<List<Absence>> getAbsences({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? absencesJson = userData.elementAt(0)["absences"] as String?;
|
||||
if (absencesJson == null) return [];
|
||||
List<Absence> absences = (jsonDecode(absencesJson) as List).map((e) => Absence.fromJson(e)).toList();
|
||||
List<Absence> absences = (jsonDecode(absencesJson) as List)
|
||||
.map((e) => Absence.fromJson(e))
|
||||
.toList();
|
||||
return absences;
|
||||
}
|
||||
|
||||
Future<List<GroupAverage>> getGroupAverages({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return [];
|
||||
String? groupAveragesJson = userData.elementAt(0)["group_averages"] as String?;
|
||||
String? groupAveragesJson =
|
||||
userData.elementAt(0)["group_averages"] as String?;
|
||||
if (groupAveragesJson == null) return [];
|
||||
List<GroupAverage> groupAverages = (jsonDecode(groupAveragesJson) as List).map((e) => GroupAverage.fromJson(e)).toList();
|
||||
List<GroupAverage> groupAverages = (jsonDecode(groupAveragesJson) as List)
|
||||
.map((e) => GroupAverage.fromJson(e))
|
||||
.toList();
|
||||
return groupAverages;
|
||||
}
|
||||
|
||||
Future<SubjectLessonCount> getSubjectLessonCount({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
Future<SubjectLessonCount> getSubjectLessonCount(
|
||||
{required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return SubjectLessonCount.fromMap({});
|
||||
String? lessonCountJson = userData.elementAt(0)["subject_lesson_count"] as String?;
|
||||
String? lessonCountJson =
|
||||
userData.elementAt(0)["subject_lesson_count"] as String?;
|
||||
if (lessonCountJson == null) return SubjectLessonCount.fromMap({});
|
||||
SubjectLessonCount lessonCount = SubjectLessonCount.fromMap(jsonDecode(lessonCountJson) as Map);
|
||||
SubjectLessonCount lessonCount =
|
||||
SubjectLessonCount.fromMap(jsonDecode(lessonCountJson) as Map);
|
||||
return lessonCount;
|
||||
}
|
||||
|
||||
Future<DateTime> lastSeenGrade({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return DateTime(0);
|
||||
int? lastSeenDate = userData.elementAt(0)["last_seen_grade"] as int?;
|
||||
if (lastSeenDate == null) return DateTime(0);
|
||||
@@ -155,11 +192,71 @@ class UserDatabaseQuery {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
// renamed things
|
||||
Future<Map<String, String>> renamedSubjects({required String userId}) async {
|
||||
List<Map> userData = await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? renamedSubjectsJson = userData.elementAt(0)["renamed_subjects"] as String?;
|
||||
String? renamedSubjectsJson =
|
||||
userData.elementAt(0)["renamed_subjects"] as String?;
|
||||
if (renamedSubjectsJson == null) return {};
|
||||
return (jsonDecode(renamedSubjectsJson) as Map).map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
return (jsonDecode(renamedSubjectsJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
|
||||
Future<Map<String, String>> renamedTeachers({required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? renamedTeachersJson =
|
||||
userData.elementAt(0)["renamed_teachers"] as String?;
|
||||
if (renamedTeachersJson == null) return {};
|
||||
return (jsonDecode(renamedTeachersJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
|
||||
// goal planner
|
||||
Future<Map<String, String>> subjectGoalPlans({required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? goalPlansJson = userData.elementAt(0)["goal_plans"] as String?;
|
||||
if (goalPlansJson == null) return {};
|
||||
return (jsonDecode(goalPlansJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
|
||||
Future<Map<String, String>> subjectGoalAverages(
|
||||
{required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? goalAvgsJson = userData.elementAt(0)["goal_averages"] as String?;
|
||||
if (goalAvgsJson == null) return {};
|
||||
return (jsonDecode(goalAvgsJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
|
||||
Future<Map<String, String>> subjectGoalBefores(
|
||||
{required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? goalBeforesJson = userData.elementAt(0)["goal_befores"] as String?;
|
||||
if (goalBeforesJson == null) return {};
|
||||
return (jsonDecode(goalBeforesJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
|
||||
Future<Map<String, String>> subjectGoalPinDates(
|
||||
{required String userId}) async {
|
||||
List<Map> userData =
|
||||
await db.query("user_data", where: "id = ?", whereArgs: [userId]);
|
||||
if (userData.isEmpty) return {};
|
||||
String? goalPinDatesJson =
|
||||
userData.elementAt(0)["goal_pin_dates"] as String?;
|
||||
if (goalPinDatesJson == null) return {};
|
||||
return (jsonDecode(goalPinDatesJson) as Map)
|
||||
.map((key, value) => MapEntry(key.toString(), value.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,11 @@ class DatabaseStore {
|
||||
}
|
||||
|
||||
Future<void> storeUser(User user) async {
|
||||
List userRes = await db.query("users", where: "id = ?", whereArgs: [user.id]);
|
||||
List userRes =
|
||||
await db.query("users", where: "id = ?", whereArgs: [user.id]);
|
||||
if (userRes.isNotEmpty) {
|
||||
await db.update("users", user.toMap(), where: "id = ?", whereArgs: [user.id]);
|
||||
await db
|
||||
.update("users", user.toMap(), where: "id = ?", whereArgs: [user.id]);
|
||||
} else {
|
||||
await db.insert("users", user.toMap());
|
||||
await db.insert("user_data", {"id": user.id});
|
||||
@@ -49,64 +51,123 @@ class UserDatabaseStore {
|
||||
|
||||
Future<void> storeGrades(List<Grade> grades, {required String userId}) async {
|
||||
String gradesJson = jsonEncode(grades.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"grades": gradesJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"grades": gradesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeLessons(Map<Week, List<Lesson>?> lessons, {required String userId}) async {
|
||||
Future<void> storeLessons(Map<Week, List<Lesson>?> lessons,
|
||||
{required String userId}) async {
|
||||
final map = lessons.map<String, List<Map<String, Object?>>>(
|
||||
(k, v) => MapEntry(k.id.toString(), v!.where((e) => e.json != null).map((e) => e.json!).toList().cast()),
|
||||
(k, v) => MapEntry(k.id.toString(),
|
||||
v!.where((e) => e.json != null).map((e) => e.json!).toList().cast()),
|
||||
);
|
||||
String lessonsJson = jsonEncode(map);
|
||||
await db.update("user_data", {"timetable": lessonsJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"timetable": lessonsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeExams(List<Exam> exams, {required String userId}) async {
|
||||
String examsJson = jsonEncode(exams.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"exams": examsJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"exams": examsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeHomework(List<Homework> homework, {required String userId}) async {
|
||||
Future<void> storeHomework(List<Homework> homework,
|
||||
{required String userId}) async {
|
||||
String homeworkJson = jsonEncode(homework.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"homework": homeworkJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"homework": homeworkJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeMessages(List<Message> messages, {required String userId}) async {
|
||||
Future<void> storeMessages(List<Message> messages,
|
||||
{required String userId}) async {
|
||||
String messagesJson = jsonEncode(messages.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"messages": messagesJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"messages": messagesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeNotes(List<Note> notes, {required String userId}) async {
|
||||
String notesJson = jsonEncode(notes.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"notes": notesJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"notes": notesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeEvents(List<Event> events, {required String userId}) async {
|
||||
String eventsJson = jsonEncode(events.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"events": eventsJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"events": eventsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeAbsences(List<Absence> absences, {required String userId}) async {
|
||||
Future<void> storeAbsences(List<Absence> absences,
|
||||
{required String userId}) async {
|
||||
String absencesJson = jsonEncode(absences.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"absences": absencesJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"absences": absencesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeGroupAverages(List<GroupAverage> groupAverages, {required String userId}) async {
|
||||
String groupAveragesJson = jsonEncode(groupAverages.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"group_averages": groupAveragesJson}, where: "id = ?", whereArgs: [userId]);
|
||||
Future<void> storeGroupAverages(List<GroupAverage> groupAverages,
|
||||
{required String userId}) async {
|
||||
String groupAveragesJson =
|
||||
jsonEncode(groupAverages.map((e) => e.json).toList());
|
||||
await db.update("user_data", {"group_averages": groupAveragesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeSubjectLessonCount(SubjectLessonCount lessonCount, {required String userId}) async {
|
||||
Future<void> storeSubjectLessonCount(SubjectLessonCount lessonCount,
|
||||
{required String userId}) async {
|
||||
String lessonCountJson = jsonEncode(lessonCount.toMap());
|
||||
await db.update("user_data", {"subject_lesson_count": lessonCountJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"subject_lesson_count": lessonCountJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeLastSeenGrade(DateTime date, {required String userId}) async {
|
||||
Future<void> storeLastSeenGrade(DateTime date,
|
||||
{required String userId}) async {
|
||||
int lastSeenDate = date.millisecondsSinceEpoch;
|
||||
await db.update("user_data", {"last_seen_grade": lastSeenDate}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"last_seen_grade": lastSeenDate},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeRenamedSubjects(Map<String, String> subjects, {required String userId}) async {
|
||||
// renamed things
|
||||
Future<void> storeRenamedSubjects(Map<String, String> subjects,
|
||||
{required String userId}) async {
|
||||
String renamedSubjectsJson = jsonEncode(subjects);
|
||||
await db.update("user_data", {"renamed_subjects": renamedSubjectsJson}, where: "id = ?", whereArgs: [userId]);
|
||||
await db.update("user_data", {"renamed_subjects": renamedSubjectsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeRenamedTeachers(Map<String, String> teachers,
|
||||
{required String userId}) async {
|
||||
String renamedTeachersJson = jsonEncode(teachers);
|
||||
await db.update("user_data", {"renamed_teachers": renamedTeachersJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
// goal planner
|
||||
Future<void> storeSubjectGoalPlans(Map<String, String> plans,
|
||||
{required String userId}) async {
|
||||
String goalPlansJson = jsonEncode(plans);
|
||||
await db.update("user_data", {"goal_plans": goalPlansJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeSubjectGoalAverages(Map<String, String> avgs,
|
||||
{required String userId}) async {
|
||||
String goalAvgsJson = jsonEncode(avgs);
|
||||
await db.update("user_data", {"goal_averages": goalAvgsJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeSubjectGoalBefores(Map<String, String> befores,
|
||||
{required String userId}) async {
|
||||
String goalBeforesJson = jsonEncode(befores);
|
||||
await db.update("user_data", {"goal_befores": goalBeforesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
|
||||
Future<void> storeSubjectGoalPinDates(Map<String, String> dates,
|
||||
{required String userId}) async {
|
||||
String goalPinDatesJson = jsonEncode(dates);
|
||||
await db.update("user_data", {"goal_pin_dates": goalPinDatesJson},
|
||||
where: "id = ?", whereArgs: [userId]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ class NotificationsHelper {
|
||||
@pragma('vm:entry-point')
|
||||
void backgroundJob() async {
|
||||
// initialize providers
|
||||
database = DatabaseProvider();
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
DatabaseProvider database = DatabaseProvider();
|
||||
await database.init();
|
||||
settingsProvider =
|
||||
await database.query.getSettings(database);
|
||||
@@ -54,45 +56,48 @@ class NotificationsHelper {
|
||||
|
||||
// loop through grades and see which hasn't been seen yet
|
||||
for (Grade grade in grades) {
|
||||
// if the grade was added over a week ago, don't show it to avoid notification spam
|
||||
if (grade.seenDate.isAfter(lastSeenGrade) && grade.date.difference(DateTime.now()).inDays * -1 < 7) {
|
||||
// send notificiation about new grade
|
||||
const AndroidNotificationDetails androidNotificationDetails =
|
||||
AndroidNotificationDetails('GRADES', 'Jegyek',
|
||||
channelDescription: 'Értesítés jegyek beírásakor',
|
||||
importance: Importance.max,
|
||||
priority: Priority.max,
|
||||
color: const Color(0xFF3D7BF4),
|
||||
ticker: 'Jegyek');
|
||||
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails);
|
||||
if(userProvider.getUsers().length == 1) {
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
grade.id.hashCode,
|
||||
"title_grade".i18n,
|
||||
"body_grade".i18n.fill([
|
||||
grade.value.value.toString(),
|
||||
grade.subject.isRenamed &&
|
||||
settingsProvider.renamedSubjectsEnabled
|
||||
? grade.subject.renamedTo!
|
||||
: grade.subject.name
|
||||
]),
|
||||
notificationDetails);
|
||||
} else { // multiple users are added, also display student name
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
grade.id.hashCode,
|
||||
"title_grade".i18n,
|
||||
"body_grade_multiuser".i18n.fill([
|
||||
userProvider.displayName!,
|
||||
grade.value.value.toString(),
|
||||
grade.subject.isRenamed &&
|
||||
settingsProvider.renamedSubjectsEnabled
|
||||
? grade.subject.renamedTo!
|
||||
: grade.subject.name
|
||||
]),
|
||||
notificationDetails);
|
||||
}
|
||||
// if grade is not a normal grade (1-5), don't show it
|
||||
if ([1, 2, 3, 4, 5].contains(grade.value.value)) {
|
||||
// if the grade was added over a week ago, don't show it to avoid notification spam
|
||||
if (grade.seenDate.isAfter(lastSeenGrade) && grade.date.difference(DateTime.now()).inDays * -1 < 7) {
|
||||
// send notificiation about new grade
|
||||
const AndroidNotificationDetails androidNotificationDetails =
|
||||
AndroidNotificationDetails('GRADES', 'Jegyek',
|
||||
channelDescription: 'Értesítés jegyek beírásakor',
|
||||
importance: Importance.max,
|
||||
priority: Priority.max,
|
||||
color: const Color(0xFF3D7BF4),
|
||||
ticker: 'Jegyek');
|
||||
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails);
|
||||
if(userProvider.getUsers().length == 1) {
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
grade.id.hashCode,
|
||||
"title_grade".i18n,
|
||||
"body_grade".i18n.fill([
|
||||
grade.value.value.toString(),
|
||||
grade.subject.isRenamed &&
|
||||
settingsProvider.renamedSubjectsEnabled
|
||||
? grade.subject.renamedTo!
|
||||
: grade.subject.name
|
||||
]),
|
||||
notificationDetails);
|
||||
} else { // multiple users are added, also display student name
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
grade.id.hashCode,
|
||||
"title_grade".i18n,
|
||||
"body_grade_multiuser".i18n.fill([
|
||||
userProvider.displayName!,
|
||||
grade.value.value.toString(),
|
||||
grade.subject.isRenamed &&
|
||||
settingsProvider.renamedSubjectsEnabled
|
||||
? grade.subject.renamedTo!
|
||||
: grade.subject.name
|
||||
]),
|
||||
notificationDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set grade seen status
|
||||
gradeProvider.seenAll();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:filcnaplo/api/client.dart';
|
||||
import 'package:filcnaplo/helpers/storage_helper.dart';
|
||||
import 'package:filcnaplo/models/release.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
enum UpdateState { none, preparing, downloading, installing }
|
||||
|
||||
@@ -32,12 +33,17 @@ extension UpdateHelper on Release {
|
||||
|
||||
updateCallback(-1, UpdateState.installing);
|
||||
|
||||
var result = await OpenFile.open(apk.path);
|
||||
var permStatus =
|
||||
(await Permission.manageExternalStorage.request().isGranted &&
|
||||
await Permission.requestInstallPackages.request().isGranted);
|
||||
if (permStatus) {
|
||||
var result = await OpenFile.open(apk.path);
|
||||
|
||||
if (result.type != ResultType.done) {
|
||||
// ignore: avoid_print
|
||||
print("ERROR: installUpdate.openFile: ${result.message}");
|
||||
throw result.message;
|
||||
if (result.type != ResultType.done) {
|
||||
// ignore: avoid_print
|
||||
print("ERROR: installUpdate.openFile: ${result.message}");
|
||||
throw result.message;
|
||||
}
|
||||
}
|
||||
|
||||
updateCallback(-1, UpdateState.none);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:background_fetch/background_fetch.dart';
|
||||
import 'package:filcnaplo/api/providers/user_provider.dart';
|
||||
import 'package:filcnaplo/api/providers/database_provider.dart';
|
||||
@@ -28,9 +30,10 @@ void main() async {
|
||||
|
||||
// Run App
|
||||
runApp(App(
|
||||
database: startup.database,
|
||||
settings: startup.settings,
|
||||
user: startup.user));
|
||||
database: startup.database,
|
||||
settings: startup.settings,
|
||||
user: startup.user,
|
||||
));
|
||||
}
|
||||
|
||||
class Startup {
|
||||
@@ -46,52 +49,68 @@ class Startup {
|
||||
settings = await database.query.getSettings(database);
|
||||
user = await database.query.getUsers(settings);
|
||||
|
||||
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
|
||||
// Notifications setup
|
||||
initPlatformState();
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
if (!kIsWeb) {
|
||||
initPlatformState();
|
||||
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
}
|
||||
|
||||
// Get permission to show notifications
|
||||
flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>()!
|
||||
.requestPermission();
|
||||
await flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
IOSFlutterLocalNotificationsPlugin>()
|
||||
?.requestPermissions(
|
||||
alert: false,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
await flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
MacOSFlutterLocalNotificationsPlugin>()
|
||||
?.requestPermissions(
|
||||
alert: false,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
if (kIsWeb) {
|
||||
// do nothing
|
||||
} else if (Platform.isAndroid) {
|
||||
await flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>()!
|
||||
.requestPermission();
|
||||
} else if (Platform.isIOS) {
|
||||
await flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
IOSFlutterLocalNotificationsPlugin>()
|
||||
?.requestPermissions(
|
||||
alert: false,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
} else if (Platform.isMacOS) {
|
||||
await flutterLocalNotificationsPlugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
MacOSFlutterLocalNotificationsPlugin>()
|
||||
?.requestPermissions(
|
||||
alert: false,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
} else if (Platform.isLinux) {
|
||||
// no permissions are needed on linux
|
||||
}
|
||||
|
||||
// Platform specific settings
|
||||
final DarwinInitializationSettings initializationSettingsDarwin =
|
||||
DarwinInitializationSettings(
|
||||
requestSoundPermission: true,
|
||||
requestBadgePermission: true,
|
||||
requestAlertPermission: false,
|
||||
);
|
||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('ic_notification');
|
||||
final InitializationSettings initializationSettings = InitializationSettings(
|
||||
android: initializationSettingsAndroid,
|
||||
iOS: initializationSettingsDarwin,
|
||||
macOS: initializationSettingsDarwin
|
||||
);
|
||||
if (!kIsWeb) {
|
||||
const DarwinInitializationSettings initializationSettingsDarwin =
|
||||
DarwinInitializationSettings(
|
||||
requestSoundPermission: true,
|
||||
requestBadgePermission: true,
|
||||
requestAlertPermission: false,
|
||||
);
|
||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('ic_notification');
|
||||
const LinuxInitializationSettings initializationSettingsLinux =
|
||||
LinuxInitializationSettings(defaultActionName: 'Open notification');
|
||||
const InitializationSettings initializationSettings =
|
||||
InitializationSettings(
|
||||
android: initializationSettingsAndroid,
|
||||
iOS: initializationSettingsDarwin,
|
||||
macOS: initializationSettingsDarwin,
|
||||
linux: initializationSettingsLinux,
|
||||
);
|
||||
|
||||
// Initialize notifications
|
||||
await flutterLocalNotificationsPlugin.initialize(
|
||||
initializationSettings,
|
||||
);
|
||||
// Initialize notifications
|
||||
await flutterLocalNotificationsPlugin.initialize(
|
||||
initializationSettings,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,47 +139,59 @@ Widget errorBuilder(FlutterErrorDetails details) {
|
||||
return Container();
|
||||
});
|
||||
}
|
||||
Future<void> initPlatformState() async {
|
||||
// Configure BackgroundFetch.
|
||||
int status = await BackgroundFetch.configure(BackgroundFetchConfig(
|
||||
minimumFetchInterval: 15,
|
||||
stopOnTerminate: false,
|
||||
enableHeadless: true,
|
||||
requiresBatteryNotLow: false,
|
||||
requiresCharging: false,
|
||||
requiresStorageNotLow: false,
|
||||
requiresDeviceIdle: false,
|
||||
requiredNetworkType: NetworkType.ANY,
|
||||
startOnBoot: true
|
||||
), (String taskId) async { // <-- Event handler
|
||||
|
||||
Future<void> initPlatformState() async {
|
||||
// Configure BackgroundFetch.
|
||||
int status = await BackgroundFetch.configure(
|
||||
BackgroundFetchConfig(
|
||||
minimumFetchInterval: 15,
|
||||
stopOnTerminate: false,
|
||||
enableHeadless: true,
|
||||
requiresBatteryNotLow: false,
|
||||
requiresCharging: false,
|
||||
requiresStorageNotLow: false,
|
||||
requiresDeviceIdle: false,
|
||||
requiredNetworkType: NetworkType.ANY,
|
||||
startOnBoot: true), (String taskId) async {
|
||||
// <-- Event handler
|
||||
if (kDebugMode) {
|
||||
print("[BackgroundFetch] Event received $taskId");
|
||||
NotificationsHelper().backgroundJob();
|
||||
BackgroundFetch.finish(taskId);
|
||||
}, (String taskId) async { // <-- Task timeout handler.
|
||||
}
|
||||
NotificationsHelper().backgroundJob();
|
||||
BackgroundFetch.finish(taskId);
|
||||
}, (String taskId) async {
|
||||
// <-- Task timeout handler.
|
||||
if (kDebugMode) {
|
||||
print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId");
|
||||
BackgroundFetch.finish(taskId);
|
||||
});
|
||||
}
|
||||
BackgroundFetch.finish(taskId);
|
||||
});
|
||||
if (kDebugMode) {
|
||||
print('[BackgroundFetch] configure success: $status');
|
||||
BackgroundFetch.scheduleTask(TaskConfig(
|
||||
taskId: "com.transistorsoft.refilcnotification",
|
||||
delay: 900000, // 15 minutes
|
||||
periodic: true,
|
||||
forceAlarmManager: true,
|
||||
stopOnTerminate: false,
|
||||
enableHeadless: true
|
||||
));
|
||||
}
|
||||
BackgroundFetch.scheduleTask(TaskConfig(
|
||||
taskId: "com.transistorsoft.refilcnotification",
|
||||
delay: 900000, // 15 minutes
|
||||
periodic: true,
|
||||
forceAlarmManager: true,
|
||||
stopOnTerminate: false,
|
||||
enableHeadless: true));
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,30 +1,36 @@
|
||||
class News {
|
||||
String id;
|
||||
String title;
|
||||
String content;
|
||||
String link;
|
||||
String openLabel;
|
||||
String platform;
|
||||
bool emergency;
|
||||
DateTime expireDate;
|
||||
Map? json;
|
||||
|
||||
News({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.link,
|
||||
required this.openLabel,
|
||||
required this.platform,
|
||||
required this.emergency,
|
||||
required this.expireDate,
|
||||
this.json,
|
||||
});
|
||||
|
||||
factory News.fromJson(Map json) {
|
||||
return News(
|
||||
id: json["id"] ?? "",
|
||||
title: json["title"] ?? "",
|
||||
content: json["content"] ?? "",
|
||||
link: json["link"] ?? "",
|
||||
openLabel: json["open_label"] ?? "",
|
||||
platform: json["platform"] ?? "",
|
||||
emergency: json["emergency"] ?? false,
|
||||
expireDate: DateTime.parse(json["expire_date"] ?? ''),
|
||||
json: json,
|
||||
);
|
||||
}
|
||||
|
||||
21
filcnaplo/lib/models/personality.dart
Normal file
21
filcnaplo/lib/models/personality.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
class Personality {
|
||||
PersonalityType type;
|
||||
|
||||
Personality({
|
||||
this.type = PersonalityType.npc,
|
||||
});
|
||||
}
|
||||
|
||||
enum PersonalityType {
|
||||
geek,
|
||||
sick,
|
||||
late,
|
||||
quitter,
|
||||
healthy,
|
||||
acceptable,
|
||||
fallible,
|
||||
average,
|
||||
diligent,
|
||||
cheater,
|
||||
npc
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
// zero is one, ...
|
||||
List<Color> _gradeColors;
|
||||
bool _newsEnabled;
|
||||
int _newsState;
|
||||
String _seenNews;
|
||||
bool _notificationsEnabled;
|
||||
/*
|
||||
notificationsBitfield values:
|
||||
@@ -69,6 +69,9 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String _lastAccountId;
|
||||
bool _renamedSubjectsEnabled;
|
||||
bool _renamedSubjectsItalics;
|
||||
bool _renamedTeachersEnabled;
|
||||
bool _renamedTeachersItalics;
|
||||
Color _liveActivityColor;
|
||||
|
||||
SettingsProvider({
|
||||
DatabaseProvider? database,
|
||||
@@ -79,7 +82,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
required AccentColor accentColor,
|
||||
required List<Color> gradeColors,
|
||||
required bool newsEnabled,
|
||||
required int newsState,
|
||||
required String seenNews,
|
||||
required bool notificationsEnabled,
|
||||
required int notificationsBitfield,
|
||||
required bool developerMode,
|
||||
@@ -106,6 +109,9 @@ class SettingsProvider extends ChangeNotifier {
|
||||
required String lastAccountId,
|
||||
required bool renameSubjectsEnabled,
|
||||
required bool renameSubjectsItalics,
|
||||
required bool renameTeachersEnabled,
|
||||
required bool renameTeachersItalics,
|
||||
required Color liveActivityColor,
|
||||
}) : _database = database,
|
||||
_language = language,
|
||||
_startPage = startPage,
|
||||
@@ -114,7 +120,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_accentColor = accentColor,
|
||||
_gradeColors = gradeColors,
|
||||
_newsEnabled = newsEnabled,
|
||||
_newsState = newsState,
|
||||
_seenNews = seenNews,
|
||||
_notificationsEnabled = notificationsEnabled,
|
||||
_notificationsBitfield = notificationsBitfield,
|
||||
_developerMode = developerMode,
|
||||
@@ -140,7 +146,10 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_premiumLogin = premiumLogin,
|
||||
_lastAccountId = lastAccountId,
|
||||
_renamedSubjectsEnabled = renameSubjectsEnabled,
|
||||
_renamedSubjectsItalics = renameSubjectsItalics;
|
||||
_renamedSubjectsItalics = renameSubjectsItalics,
|
||||
_renamedTeachersEnabled = renameTeachersEnabled,
|
||||
_renamedTeachersItalics = renameTeachersItalics,
|
||||
_liveActivityColor = liveActivityColor;
|
||||
|
||||
factory SettingsProvider.fromMap(Map map,
|
||||
{required DatabaseProvider database}) {
|
||||
@@ -167,7 +176,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
Color(map["grade_color5"]),
|
||||
],
|
||||
newsEnabled: map["news"] == 1,
|
||||
newsState: map["news_state"],
|
||||
seenNews: map["seen_news"],
|
||||
notificationsEnabled: map["notifications"] == 1,
|
||||
notificationsBitfield: map["notifications_bitfield"],
|
||||
notificationPollInterval: map["notification_poll_interval"],
|
||||
@@ -194,7 +203,10 @@ class SettingsProvider extends ChangeNotifier {
|
||||
premiumLogin: map["premium_login"],
|
||||
lastAccountId: map["last_account_id"],
|
||||
renameSubjectsEnabled: map["renamed_subjects_enabled"] == 1,
|
||||
renameSubjectsItalics: map["renamed_subjects_italics"] == 0,
|
||||
renameSubjectsItalics: map["renamed_subjects_italics"] == 1,
|
||||
renameTeachersEnabled: map["renamed_teachers_enabled"] == 1,
|
||||
renameTeachersItalics: map["renamed_teachers_italics"] == 1,
|
||||
liveActivityColor: Color(map["live_activity_color"]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,7 +218,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
"theme": _theme.index,
|
||||
"accent_color": _accentColor.index,
|
||||
"news": _newsEnabled ? 1 : 0,
|
||||
"news_state": _newsState,
|
||||
"seen_news": _seenNews,
|
||||
"notifications": _notificationsEnabled ? 1 : 0,
|
||||
"notifications_bitfield": _notificationsBitfield,
|
||||
"developer_mode": _developerMode ? 1 : 0,
|
||||
@@ -236,7 +248,10 @@ class SettingsProvider extends ChangeNotifier {
|
||||
"premium_login": _premiumLogin,
|
||||
"last_account_id": _lastAccountId,
|
||||
"renamed_subjects_enabled": _renamedSubjectsEnabled ? 1 : 0,
|
||||
"renamed_subjects_italics": _renamedSubjectsItalics ? 1 : 0
|
||||
"renamed_subjects_italics": _renamedSubjectsItalics ? 1 : 0,
|
||||
"renamed_teachers_enabled": _renamedTeachersEnabled ? 1 : 0,
|
||||
"renamed_teachers_italics": _renamedTeachersItalics ? 1 : 0,
|
||||
"live_activity_color": _liveActivityColor.value,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -256,7 +271,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
DarkMobileAppColors().gradeFive,
|
||||
],
|
||||
newsEnabled: true,
|
||||
newsState: -1,
|
||||
seenNews: '',
|
||||
notificationsEnabled: true,
|
||||
notificationsBitfield: 255,
|
||||
developerMode: false,
|
||||
@@ -283,6 +298,9 @@ class SettingsProvider extends ChangeNotifier {
|
||||
lastAccountId: "",
|
||||
renameSubjectsEnabled: false,
|
||||
renameSubjectsItalics: false,
|
||||
renameTeachersEnabled: false,
|
||||
renameTeachersItalics: false,
|
||||
liveActivityColor: const Color(0xFF676767),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -294,7 +312,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
AccentColor get accentColor => _accentColor;
|
||||
List<Color> get gradeColors => _gradeColors;
|
||||
bool get newsEnabled => _newsEnabled;
|
||||
int get newsState => _newsState;
|
||||
List<String> get seenNews => _seenNews.split(',');
|
||||
bool get notificationsEnabled => _notificationsEnabled;
|
||||
int get notificationsBitfield => _notificationsBitfield;
|
||||
bool get developerMode => _developerMode;
|
||||
@@ -324,6 +342,9 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String get lastAccountId => _lastAccountId;
|
||||
bool get renamedSubjectsEnabled => _renamedSubjectsEnabled;
|
||||
bool get renamedSubjectsItalics => _renamedSubjectsItalics;
|
||||
bool get renamedTeachersEnabled => _renamedTeachersEnabled;
|
||||
bool get renamedTeachersItalics => _renamedTeachersItalics;
|
||||
Color get liveActivityColor => _liveActivityColor;
|
||||
|
||||
Future<void> update({
|
||||
bool store = true,
|
||||
@@ -334,7 +355,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
AccentColor? accentColor,
|
||||
List<Color>? gradeColors,
|
||||
bool? newsEnabled,
|
||||
int? newsState,
|
||||
String? seenNewsId,
|
||||
bool? notificationsEnabled,
|
||||
int? notificationsBitfield,
|
||||
bool? developerMode,
|
||||
@@ -361,71 +382,111 @@ class SettingsProvider extends ChangeNotifier {
|
||||
String? lastAccountId,
|
||||
bool? renamedSubjectsEnabled,
|
||||
bool? renamedSubjectsItalics,
|
||||
bool? renamedTeachersEnabled,
|
||||
bool? renamedTeachersItalics,
|
||||
Color? liveActivityColor,
|
||||
}) async {
|
||||
if (language != null && language != _language) _language = language;
|
||||
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 (seenNewsId != null && !_seenNews.split(',').contains(seenNewsId)) {
|
||||
var tempList = _seenNews.split(',');
|
||||
tempList.add(seenNewsId);
|
||||
_seenNews = tempList.join(',');
|
||||
}
|
||||
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 (renamedTeachersEnabled != null &&
|
||||
renamedTeachersEnabled != _renamedTeachersEnabled) {
|
||||
_renamedTeachersEnabled = renamedTeachersEnabled;
|
||||
}
|
||||
if (renamedTeachersItalics != null &&
|
||||
renamedTeachersItalics != _renamedTeachersItalics) {
|
||||
_renamedTeachersItalics = renamedTeachersItalics;
|
||||
}
|
||||
if (liveActivityColor != null && liveActivityColor != _liveActivityColor) {
|
||||
_liveActivityColor = liveActivityColor;
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -12,7 +12,8 @@ import 'package:filcnaplo_mobile_ui/common/widgets/lesson/changed_lesson_tile.da
|
||||
import 'package:filcnaplo/utils/format.dart';
|
||||
|
||||
// difference.inDays is not reliable
|
||||
bool _sameDate(DateTime a, DateTime b) => (a.year == b.year && a.month == b.month && a.day == b.day);
|
||||
bool _sameDate(DateTime a, DateTime b) =>
|
||||
(a.year == b.year && a.month == b.month && a.day == b.day);
|
||||
|
||||
List<Widget> sortDateWidgets(
|
||||
BuildContext context, {
|
||||
@@ -35,13 +36,16 @@ List<Widget> sortDateWidgets(
|
||||
if (message.conversationId != null) {
|
||||
convMessages.add(w);
|
||||
|
||||
Conversation conv = conversations.firstWhere((e) => e.id == message.conversationId, orElse: () => Conversation(id: message.conversationId!));
|
||||
Conversation conv = conversations.firstWhere(
|
||||
(e) => e.id == message.conversationId,
|
||||
orElse: () => Conversation(id: message.conversationId!));
|
||||
conv.add(message);
|
||||
if (conv.messages.length == 1) conversations.add(conv);
|
||||
}
|
||||
|
||||
if (conversations.any((c) => c.id == message.messageId)) {
|
||||
Conversation conv = conversations.firstWhere((e) => e.id == message.messageId);
|
||||
Conversation conv =
|
||||
conversations.firstWhere((e) => e.id == message.messageId);
|
||||
convMessages.add(w);
|
||||
conv.add(message);
|
||||
}
|
||||
@@ -87,26 +91,41 @@ List<Widget> sortDateWidgets(
|
||||
|
||||
// Group Absence Tiles
|
||||
List<DateWidget> absenceTileWidgets = elements.where((element) {
|
||||
return element.widget is AbsenceViewable && (element.widget as AbsenceViewable).absence.delay == 0;
|
||||
return element.widget is AbsenceViewable &&
|
||||
(element.widget as AbsenceViewable).absence.delay == 0;
|
||||
}).toList();
|
||||
List<AbsenceViewable> absenceTiles = absenceTileWidgets.map((e) => e.widget as AbsenceViewable).toList();
|
||||
List<AbsenceViewable> absenceTiles =
|
||||
absenceTileWidgets.map((e) => e.widget as AbsenceViewable).toList();
|
||||
if (absenceTiles.length > 1) {
|
||||
elements.removeWhere((element) => element.widget.runtimeType == AbsenceViewable && (element.widget as AbsenceViewable).absence.delay == 0);
|
||||
elements.removeWhere((element) =>
|
||||
element.widget.runtimeType == AbsenceViewable &&
|
||||
(element.widget as AbsenceViewable).absence.delay == 0);
|
||||
if (elements.isEmpty) {
|
||||
cst = false;
|
||||
}
|
||||
elements.add(DateWidget(
|
||||
widget: AbsenceGroupTile(absenceTiles, showDate: !cst),
|
||||
date: absenceTileWidgets.first.date,
|
||||
key: "${absenceTileWidgets.first.date.millisecondsSinceEpoch}-absence-group"));
|
||||
elements.add(
|
||||
DateWidget(
|
||||
widget: AbsenceGroupTile(
|
||||
absenceTiles,
|
||||
showDate: !cst,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6.0),
|
||||
),
|
||||
date: absenceTileWidgets.first.date,
|
||||
key:
|
||||
"${absenceTileWidgets.first.date.millisecondsSinceEpoch}-absence-group"),
|
||||
);
|
||||
}
|
||||
|
||||
// Bring Lesson Tiles to front & sort by index asc
|
||||
List<DateWidget> lessonTiles = elements.where((element) {
|
||||
return element.widget.runtimeType == ChangedLessonTile;
|
||||
}).toList();
|
||||
lessonTiles.sort((a, b) => (a.widget as ChangedLessonTile).lesson.lessonIndex.compareTo((b.widget as ChangedLessonTile).lesson.lessonIndex));
|
||||
elements.removeWhere((element) => element.widget.runtimeType == ChangedLessonTile);
|
||||
lessonTiles.sort((a, b) => (a.widget as ChangedLessonTile)
|
||||
.lesson
|
||||
.lessonIndex
|
||||
.compareTo((b.widget as ChangedLessonTile).lesson.lessonIndex));
|
||||
elements.removeWhere(
|
||||
(element) => element.widget.runtimeType == ChangedLessonTile);
|
||||
elements.insertAll(0, lessonTiles);
|
||||
|
||||
final date = (elements + absenceTileWidgets).first.date;
|
||||
@@ -122,7 +141,8 @@ List<Widget> sortDateWidgets(
|
||||
spawnIsolate: false,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (context, animation, item, index) => filterItemBuilder(context, animation, item.widget, index),
|
||||
itemBuilder: (context, animation, item, index) =>
|
||||
filterItemBuilder(context, animation, item.widget, index),
|
||||
items: elements,
|
||||
),
|
||||
),
|
||||
@@ -131,9 +151,12 @@ List<Widget> sortDateWidgets(
|
||||
}
|
||||
|
||||
final nh = DateTime.now();
|
||||
final now = DateTime(nh.year, nh.month, nh.day).subtract(const Duration(seconds: 1));
|
||||
final now =
|
||||
DateTime(nh.year, nh.month, nh.day).subtract(const Duration(seconds: 1));
|
||||
|
||||
if (showDivider && items.any((i) => i.date.isBefore(now)) && items.any((i) => i.date.isAfter(now))) {
|
||||
if (showDivider &&
|
||||
items.any((i) => i.date.isBefore(now)) &&
|
||||
items.any((i) => i.date.isAfter(now))) {
|
||||
items.add(
|
||||
DateWidget(
|
||||
date: now,
|
||||
@@ -153,7 +176,9 @@ List<Widget> sortDateWidgets(
|
||||
}
|
||||
|
||||
// Sort future dates asc, past dates desc
|
||||
items.sort((a, b) => (a.date.isAfter(now) && b.date.isAfter(now) ? 1 : -1) * a.date.compareTo(b.date));
|
||||
items.sort((a, b) =>
|
||||
(a.date.isAfter(now) && b.date.isAfter(now) ? 1 : -1) *
|
||||
a.date.compareTo(b.date));
|
||||
|
||||
return items.map((e) => e.widget).toList();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class LessonTile extends StatelessWidget {
|
||||
bool fill = false;
|
||||
bool fillLeading = false;
|
||||
String lessonIndexTrailing = "";
|
||||
|
||||
|
||||
SettingsProvider settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
|
||||
// Only put a trailing . if its a digit
|
||||
@@ -44,7 +44,7 @@ class LessonTile extends StatelessWidget {
|
||||
fillLeading = true;
|
||||
}
|
||||
|
||||
if (lesson.substituteTeacher != "") {
|
||||
if (lesson.substituteTeacher?.name != "") {
|
||||
fill = true;
|
||||
accent = AppColors.of(context).yellow;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ class LessonTile extends StatelessWidget {
|
||||
if (lesson.isChanged) {
|
||||
if (lesson.status?.name == "Elmaradt") {
|
||||
description = 'cancelled'.i18n;
|
||||
} else if (lesson.substituteTeacher != "") {
|
||||
} else if (lesson.substituteTeacher?.name != "") {
|
||||
description = 'substitution'.i18n;
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,10 @@ class LessonTile extends StatelessWidget {
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(!lesson.isEmpty ? 1.0 : 0.5),
|
||||
fontStyle:
|
||||
lesson.subject.isRenamed && settingsProvider.renamedSubjectsItalics ? FontStyle.italic : null),
|
||||
fontStyle: lesson.subject.isRenamed &&
|
||||
settingsProvider.renamedSubjectsItalics
|
||||
? FontStyle.italic
|
||||
: null),
|
||||
),
|
||||
subtitle: description != ""
|
||||
? Text(
|
||||
|
||||
Reference in New Issue
Block a user