forked from firka/firka
Compare commits
2 Commits
feat/themi
...
notificati
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7242437231 | ||
|
|
50f0332842 |
48
cache.md
48
cache.md
@@ -1,48 +0,0 @@
|
|||||||
# Cache
|
|
||||||
|
|
||||||
Entry:
|
|
||||||
|
|
||||||
név|típus|
|
|
||||||
-|-|
|
|
||||||
latestElement|idő|
|
|
||||||
createdAt|idő|
|
|
||||||
response|Json|
|
|
||||||
|
|
||||||
Legutóbbi = Legutóbbi sikeres adatlekérdezés listájának legfrissebb elemének ideje.
|
|
||||||
|
|
||||||
## Timetable
|
|
||||||
|
|
||||||
TimetableDay entry.
|
|
||||||
|
|
||||||
Frissíteni|Korábbi|Múlt hét|Jelenlegi hét|Jövő hét|Későbbi|
|
|
||||||
-|-|-|-|-|-|
|
|
||||||
belépéskor?|✖️|✖️|✔️|✔️|✖️|
|
|
||||||
kijelzéskor?|✖️|✖️|✖️|✖️|✔️|
|
|
||||||
|
|
||||||
Új mulasztáskor a mulasztás napját MINDIG frissíti.
|
|
||||||
|
|
||||||
## Értékelések/Tesztek/Faliújság/Feljegyzések/Házi feladatok
|
|
||||||
|
|
||||||
Frissíteni|Korábbi|Legutóbbi létrehozástól|
|
|
||||||
-|-|-|
|
|
||||||
belépéskor?|✖️|✔️|
|
|
||||||
kijelzéskor?|✖️|✖️|
|
|
||||||
|
|
||||||
## Mulasztások
|
|
||||||
|
|
||||||
Összes
|
|
||||||
|
|
||||||
## Egyéb
|
|
||||||
|
|
||||||
Belépéskor
|
|
||||||
|
|
||||||
--------
|
|
||||||
# IMPL
|
|
||||||
|
|
||||||
### GenericCache
|
|
||||||
Entry:
|
|
||||||
név|típus|
|
|
||||||
-|-|
|
|
||||||
userId|id|
|
|
||||||
createdAt|idő|
|
|
||||||
response|Json|
|
|
||||||
@@ -12,6 +12,7 @@ android {
|
|||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
ndkVersion = flutter.ndkVersion
|
ndkVersion = flutter.ndkVersion
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
@@ -71,6 +72,7 @@ configurations.all {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
|
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
|
||||||
implementation("androidx.glance:glance-appwidget:1.1.1")
|
implementation("androidx.glance:glance-appwidget:1.1.1")
|
||||||
implementation("com.google.android.gms:play-services-wearable:18.1.0")
|
implementation("com.google.android.gms:play-services-wearable:18.1.0")
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,16 +1,15 @@
|
|||||||
icons:
|
icons:
|
||||||
"flutter_launcher_icons.yaml": "c600507ca0df7cebd0f708124842512a14ed3d597b779176200d6ba25b1335b1"
|
"flutter_launcher_icons.yaml": "c600507ca0df7cebd0f708124842512a14ed3d597b779176200d6ba25b1335b1"
|
||||||
"pubspec.yaml": "d0f795bcffd597e260202b29476fc99caa3bb4aac5abd48a210cadb9f45c19e7"
|
"pubspec.yaml": "a6ae0bd67a2b6226bec2dfd55437b3db2b7ca4a03f315c1a0a8c2f4b505c7c87"
|
||||||
"assets/images/logos/colored_logo.webp": "4b4fa99d144fe6694aa4487ba1b26aeecafae41e3c877836cd7da28d61a77983"
|
"assets/images/logos/colored_logo.webp": "4b4fa99d144fe6694aa4487ba1b26aeecafae41e3c877836cd7da28d61a77983"
|
||||||
"assets/images/logos/monochrome_logo.png": "188d2b0a64c70323b09bcee721663d6698fb557066f20ddaec97bba6869c1c6c"
|
"assets/images/logos/monochrome_logo.png": "188d2b0a64c70323b09bcee721663d6698fb557066f20ddaec97bba6869c1c6c"
|
||||||
"assets/images/logos/colored_logo_without_mustache.png": "d11cff9f38985885873bfdd2d84e61f8fab03803eada94d4caac1545ef3685f3"
|
"assets/images/logos/colored_logo_without_mustache.png": "d11cff9f38985885873bfdd2d84e61f8fab03803eada94d4caac1545ef3685f3"
|
||||||
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
||||||
l10n:
|
l10n:
|
||||||
"l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082"
|
"l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082"
|
||||||
"lib/l10n/app_hu.arb": "e11b8fe4d4fd239584792971c341f1e329fb91f5f49fa6baa664c98b06fc5176"
|
"lib/l10n/app_de.arb": "c6a12eaadf03b012a6a377b3efa4e606bd985355e76e6351956a017f4cfdadc1"
|
||||||
"lib/l10n/app_de.arb": "5114c70b506f290217161881336d6118c975d59f32347bbdc94a51c1a25293e7"
|
"lib/l10n/app_hu.arb": "a63aace8d129dbc054c4996dd9ef7d54aad96888241ce1310518b10a9a7b561d"
|
||||||
"lib/l10n/app_en.arb": "a5417b2de058a67db40fa7bfb3526d800fd2f82349dfbc895cff8b298069e707"
|
"lib/l10n/app_en.arb": "b2d72778fedb46155f41eb210906ed8ffba8b12744a2800b039951e0a2a88133"
|
||||||
"lib/l10n/app_pl.arb": "36cad0796cf8bd20fe969d5fd8443430d25fa932028c0177917ecef6964a08dd"
|
|
||||||
isar:
|
isar:
|
||||||
"lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723"
|
"lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723"
|
||||||
"lib/data/models/token_model.dart": "8c957cd07e473827d78fd8fd4fb6c1336b636a69c25c93618e1e7f94b7cf0683"
|
"lib/data/models/token_model.dart": "8c957cd07e473827d78fd8fd4fb6c1336b636a69c25c93618e1e7f94b7cf0683"
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
169
firka/lib/api/client/kreta_stream.dart
Normal file
169
firka/lib/api/client/kreta_stream.dart
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
|
||||||
|
import 'kreta_client.dart';
|
||||||
|
|
||||||
|
bool getStudentFL = false;
|
||||||
|
bool getClassGroupsFL = false;
|
||||||
|
bool getNoticeBoardStreamFL = false;
|
||||||
|
bool getInfoBoardStreamFL = false;
|
||||||
|
bool getGradesStreamFL = false;
|
||||||
|
bool getSubjectAverageStreamFL = false;
|
||||||
|
bool getHomeworkStreamFL = false;
|
||||||
|
bool getTimeTableStreamFL = false;
|
||||||
|
bool getTestsStreamFL = false;
|
||||||
|
bool getOmissionsStreamFL = false;
|
||||||
|
|
||||||
|
extension KretaStream on KretaClient {
|
||||||
|
Stream<ApiResponse<Student>> getStudentStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getStudentFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getStudentFL = true;
|
||||||
|
yield await getStudent(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getStudent(forceCache: false);
|
||||||
|
}
|
||||||
|
getStudentFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<ClassGroup>>> getClassGroupsStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getClassGroupsFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getClassGroupsFL = true;
|
||||||
|
yield await getClassGroups(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getClassGroups(forceCache: false);
|
||||||
|
}
|
||||||
|
getClassGroupsFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<NoticeBoardItem>>> getNoticeBoardStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getNoticeBoardStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getNoticeBoardStreamFL = true;
|
||||||
|
yield await getNoticeBoard(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getNoticeBoard(forceCache: false);
|
||||||
|
}
|
||||||
|
getNoticeBoardStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<InfoBoardItem>>> getInfoBoardStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getInfoBoardStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getInfoBoardStreamFL = true;
|
||||||
|
yield await getInfoBoard(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getInfoBoard(forceCache: false);
|
||||||
|
}
|
||||||
|
getInfoBoardStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<Grade>>> getGradesStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getGradesStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getGradesStreamFL = true;
|
||||||
|
yield await getGrades(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getGrades(forceCache: false);
|
||||||
|
}
|
||||||
|
getGradesStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<SubjectAverage>>> getSubjectAverageStream(
|
||||||
|
ClassGroup classGroup, {
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getSubjectAverageStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getSubjectAverageStreamFL = true;
|
||||||
|
yield await getSubjectAverage(classGroup, forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getSubjectAverage(classGroup, forceCache: false);
|
||||||
|
}
|
||||||
|
getSubjectAverageStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<Homework>>> getHomeworkStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getHomeworkStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getHomeworkStreamFL = true;
|
||||||
|
yield await getHomework(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getHomework(forceCache: false);
|
||||||
|
}
|
||||||
|
getHomeworkStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<Lesson>>> getTimeTableStream(
|
||||||
|
DateTime from,
|
||||||
|
DateTime to, {
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getTimeTableStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getTimeTableStreamFL = true;
|
||||||
|
yield await getTimeTable(from, to, forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getTimeTable(from, to, forceCache: false);
|
||||||
|
}
|
||||||
|
getTimeTableStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<Test>>> getTestsStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getTestsStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getTestsStreamFL = true;
|
||||||
|
yield await getTests(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getTests(forceCache: false);
|
||||||
|
}
|
||||||
|
getTestsStreamFL = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<ApiResponse<List<Omission>>> getOmissionsStream({
|
||||||
|
bool cacheOnly = true,
|
||||||
|
}) async* {
|
||||||
|
while (getOmissionsStreamFL) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
getOmissionsStreamFL = true;
|
||||||
|
yield await getOmissions(forceCache: true);
|
||||||
|
|
||||||
|
if (!cacheOnly) {
|
||||||
|
yield await getOmissions(forceCache: false);
|
||||||
|
}
|
||||||
|
getOmissionsStreamFL = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,7 +55,8 @@ class LiveActivityBackendClient {
|
|||||||
'roomName': lesson.roomName,
|
'roomName': lesson.roomName,
|
||||||
'isSubstitution': lesson.substituteTeacher != null,
|
'isSubstitution': lesson.substituteTeacher != null,
|
||||||
'substituteTeacher': lesson.substituteTeacher,
|
'substituteTeacher': lesson.substituteTeacher,
|
||||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
'isCancelled':
|
||||||
|
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||||
'lastModified': validLastModified.toIso8601String(),
|
'lastModified': validLastModified.toIso8601String(),
|
||||||
};
|
};
|
||||||
}).toList();
|
}).toList();
|
||||||
@@ -140,7 +141,8 @@ class LiveActivityBackendClient {
|
|||||||
'roomName': lesson.roomName,
|
'roomName': lesson.roomName,
|
||||||
'isSubstitution': lesson.substituteTeacher != null,
|
'isSubstitution': lesson.substituteTeacher != null,
|
||||||
'substituteTeacher': lesson.substituteTeacher,
|
'substituteTeacher': lesson.substituteTeacher,
|
||||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
'isCancelled':
|
||||||
|
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||||
'lastModified': validLastModified.toIso8601String(),
|
'lastModified': validLastModified.toIso8601String(),
|
||||||
};
|
};
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'dart:math';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:firka/app/app_state.dart';
|
||||||
|
|
||||||
class Constants {
|
class Constants {
|
||||||
static String get clientId {
|
static String get clientId {
|
||||||
@@ -16,6 +17,17 @@ class Constants {
|
|||||||
|
|
||||||
static const applicationId = "hu.ekreta.student";
|
static const applicationId = "hu.ekreta.student";
|
||||||
static const applicationVersion = "5.15.0";
|
static const applicationVersion = "5.15.0";
|
||||||
|
|
||||||
|
static String get userAgent {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
return "$applicationId/$applicationVersion"
|
||||||
|
"/${initData.devInfo.model}"
|
||||||
|
"/${initData.devInfo.versionRelease}"
|
||||||
|
"/${initData.devInfo.versionSdkInt}";
|
||||||
|
} else {
|
||||||
|
return "eKretaStudent/264745 CFNetwork/1494.0.7 Darwin/23.4.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OmissionConsts {
|
class OmissionConsts {
|
||||||
@@ -26,7 +38,6 @@ class OmissionConsts {
|
|||||||
|
|
||||||
class TimetableConsts {
|
class TimetableConsts {
|
||||||
static const event = "TanevRendjeEsemeny";
|
static const event = "TanevRendjeEsemeny";
|
||||||
static const lastDay = "Utolsó tanítási nap";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class KretaLoginEndpoints {
|
class KretaLoginEndpoints {
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:firka_common/core/consts.dart';
|
import 'package:firka/data/models/token_model.dart';
|
||||||
import 'package:firka_common/data/models/token_model.dart';
|
|
||||||
|
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
import 'consts.dart';
|
||||||
|
|
||||||
Future<TokenGrantResponse> getAccessToken(String code) async {
|
Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||||
final headers = <String, String>{
|
final headers = <String, String>{
|
||||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
"accept": "*/*",
|
"accept": "*/*",
|
||||||
"user-agent": initData.userAgent,
|
"user-agent": Constants.userAgent,
|
||||||
};
|
};
|
||||||
|
|
||||||
final formData = <String, String>{
|
final formData = <String, String>{
|
||||||
@@ -47,18 +47,18 @@ const _tokenRefreshRetryDelays = [1000, 3000, 5000];
|
|||||||
|
|
||||||
Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Extending token for user: ${model.username}, institute: ${model.iss}",
|
"Extending token for user: ${model.studentId}, institute: ${model.iss}",
|
||||||
);
|
);
|
||||||
|
|
||||||
final headers = <String, String>{
|
final headers = <String, String>{
|
||||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
"accept": "*/*",
|
"accept": "*/*",
|
||||||
"user-agent": initData.userAgent,
|
"user-agent": Constants.userAgent,
|
||||||
};
|
};
|
||||||
|
|
||||||
final formData = <String, String>{
|
final formData = <String, String>{
|
||||||
"institute_code": model.iss,
|
"institute_code": model.iss!,
|
||||||
"refresh_token": model.refreshToken,
|
"refresh_token": model.refreshToken!,
|
||||||
"grant_type": "refresh_token",
|
"grant_type": "refresh_token",
|
||||||
"client_id": Constants.clientId,
|
"client_id": Constants.clientId,
|
||||||
};
|
};
|
||||||
@@ -84,20 +84,20 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
|||||||
switch (response.statusCode) {
|
switch (response.statusCode) {
|
||||||
case 200:
|
case 200:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Token extended successfully for user: ${model.username}",
|
"Token extended successfully for user: ${model.studentId}",
|
||||||
);
|
);
|
||||||
return TokenGrantResponse.fromJson(response.data);
|
return TokenGrantResponse.fromJson(response.data);
|
||||||
case 400:
|
case 400:
|
||||||
case 401:
|
case 401:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Token refresh failed (${response.statusCode}) - refresh token invalid for user: ${model.username}",
|
"Token refresh failed (${response.statusCode}) - refresh token invalid for user: ${model.studentId}",
|
||||||
);
|
);
|
||||||
throw response.statusCode == 400
|
throw response.statusCode == 400
|
||||||
? TokenExpiredException()
|
? TokenExpiredException()
|
||||||
: InvalidGrantException();
|
: InvalidGrantException();
|
||||||
default:
|
default:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Token refresh failed (${response.statusCode}) for user: ${model.username}, attempt ${attempt + 1}",
|
"Token refresh failed (${response.statusCode}) for user: ${model.studentId}, attempt ${attempt + 1}",
|
||||||
);
|
);
|
||||||
lastError = Exception(
|
lastError = Exception(
|
||||||
"Failed to get access token, response code: ${response.statusCode}",
|
"Failed to get access token, response code: ${response.statusCode}",
|
||||||
@@ -111,19 +111,19 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
|||||||
rethrow;
|
rethrow;
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Token refresh network error for user: ${model.username}, attempt ${attempt + 1}: $e",
|
"Token refresh network error for user: ${model.studentId}, attempt ${attempt + 1}: $e",
|
||||||
);
|
);
|
||||||
lastError = e;
|
lastError = e;
|
||||||
continue;
|
continue;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.severe("Token refresh exception for user: ${model.username}: $e");
|
logger.severe("Token refresh exception for user: ${model.studentId}: $e");
|
||||||
lastError = e is Exception ? e : Exception(e.toString());
|
lastError = e is Exception ? e : Exception(e.toString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.severe(
|
logger.severe(
|
||||||
"All token refresh attempts failed for user: ${model.username}",
|
"All token refresh attempts failed for user: ${model.studentId}",
|
||||||
);
|
);
|
||||||
throw lastError ?? Exception("Token refresh failed after all retries");
|
throw lastError ?? Exception("Token refresh failed after all retries");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:firka_common/core/consts.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/data/models/token_model.dart';
|
||||||
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/l10n/app_localizations.dart';
|
import 'package:firka/l10n/app_localizations.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
@@ -17,6 +18,7 @@ import 'package:isar_community/isar.dart';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
late final Logger logger;
|
late final Logger logger;
|
||||||
|
late final FlutterLocalNotificationsPlugin flnp;
|
||||||
|
|
||||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
late AppInitialization initData;
|
late AppInitialization initData;
|
||||||
@@ -48,20 +50,20 @@ class AppInitialization {
|
|||||||
final Directory appDir;
|
final Directory appDir;
|
||||||
final PackageInfo packageInfo;
|
final PackageInfo packageInfo;
|
||||||
final DeviceInfo devInfo;
|
final DeviceInfo devInfo;
|
||||||
KretaClient? client;
|
late KretaClient client;
|
||||||
|
List<TokenModel> tokens;
|
||||||
bool hasWatchListener = false;
|
bool hasWatchListener = false;
|
||||||
|
|
||||||
/// Set by the wear pairing modal; called when watch sends init_done or sync_done to dismiss the sheet.
|
/// Set by the wear pairing modal; called when watch sends init_done or sync_done to dismiss the sheet.
|
||||||
void Function()? dismissWearPairingSheet;
|
void Function()? dismissWearPairingSheet;
|
||||||
Uint8List? profilePicture;
|
Uint8List? profilePicture;
|
||||||
SettingsRepository settings;
|
SettingsStore settings;
|
||||||
final ThemeCubit themeCubit = ThemeCubit();
|
ThemeCubit? themeCubit;
|
||||||
final SettingsCubit settingsCubit = SettingsCubit();
|
SettingsCubit? settingsCubit;
|
||||||
final ProfilePictureCubit profilePictureCubit = ProfilePictureCubit();
|
ProfilePictureCubit? profilePictureCubit;
|
||||||
final ToastCubit toastCubit = ToastCubit();
|
ReauthCubit? reauthCubit;
|
||||||
final HomeRefreshCubit homeRefreshCubit = HomeRefreshCubit();
|
HomeRefreshCubit? homeRefreshCubit;
|
||||||
AppLocalizations l10n;
|
AppLocalizations l10n;
|
||||||
String userAgent;
|
|
||||||
final GlobalKey<NavigatorState> navigatorKey;
|
final GlobalKey<NavigatorState> navigatorKey;
|
||||||
|
|
||||||
AppInitialization({
|
AppInitialization({
|
||||||
@@ -69,13 +71,9 @@ class AppInitialization {
|
|||||||
required this.appDir,
|
required this.appDir,
|
||||||
required this.devInfo,
|
required this.devInfo,
|
||||||
required this.packageInfo,
|
required this.packageInfo,
|
||||||
|
required this.tokens,
|
||||||
required this.settings,
|
required this.settings,
|
||||||
required this.l10n,
|
required this.l10n,
|
||||||
required this.navigatorKey,
|
required this.navigatorKey,
|
||||||
}) : userAgent = Platform.isAndroid
|
});
|
||||||
? "${Constants.applicationId}/${Constants.applicationVersion}"
|
|
||||||
"/${devInfo.model}"
|
|
||||||
"/${devInfo.versionRelease}"
|
|
||||||
"/${devInfo.versionSdkInt}"
|
|
||||||
: "eKretaStudent/264745 CFNetwork/1494.0.7 Darwin/23.4.0";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,83 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
import 'package:firka_common/data/database.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
|
import 'package:firka/api/consts.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
|
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||||
|
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||||
|
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||||
|
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||||
|
import 'package:firka/services/active_account_helper.dart';
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka_common/data/models/token_model.dart';
|
import 'package:firka/data/models/app_settings_model.dart';
|
||||||
|
import 'package:firka/data/models/generic_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/homework_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/timetable_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/token_model.dart';
|
||||||
import 'package:firka/services/live_activity_service.dart';
|
import 'package:firka/services/live_activity_service.dart';
|
||||||
import 'package:firka/core/settings/settings_effects.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
|
||||||
import 'package:firka/core/settings/title_font.dart';
|
|
||||||
import 'package:firka/services/watch_sync_helper.dart';
|
import 'package:firka/services/watch_sync_helper.dart';
|
||||||
import 'package:firka/l10n/app_localizations_de.dart';
|
import 'package:firka/l10n/app_localizations_de.dart';
|
||||||
import 'package:firka/l10n/app_localizations_en.dart';
|
import 'package:firka/l10n/app_localizations_en.dart';
|
||||||
import 'package:firka/l10n/app_localizations_hu.dart';
|
import 'package:firka/l10n/app_localizations_hu.dart';
|
||||||
import 'package:firka/core/swear_generator.dart';
|
import 'package:firka/core/swear_generator.dart';
|
||||||
import 'package:firka/ui/phone/screens/themes/builtin_theme_id.dart';
|
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:isar_community/isar.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
Isar? isarInit;
|
||||||
|
|
||||||
|
Future<Isar> initDB() async {
|
||||||
|
if (isarInit != null) return isarInit!;
|
||||||
|
final dir = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
|
isarInit = await Isar.open(
|
||||||
|
[
|
||||||
|
TokenModelSchema,
|
||||||
|
GenericCacheModelSchema,
|
||||||
|
TimetableCacheModelSchema,
|
||||||
|
HomeworkCacheModelSchema,
|
||||||
|
AppSettingsModelSchema,
|
||||||
|
HomeworkDoneModelSchema,
|
||||||
|
],
|
||||||
|
inspector: true,
|
||||||
|
directory: dir.path,
|
||||||
|
);
|
||||||
|
|
||||||
|
return isarInit!;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> initLang(AppInitialization data) async {
|
Future<void> initLang(AppInitialization data) async {
|
||||||
String? languageCode;
|
String? languageCode;
|
||||||
|
|
||||||
switch (Settings.language.value) {
|
switch ((data.settings.group("settings").subGroup("application")["language"]
|
||||||
case AppLanguage.hu:
|
as SettingsItemsRadio)
|
||||||
|
.activeIndex) {
|
||||||
|
case 1: // hu
|
||||||
data.l10n = AppLocalizationsHu();
|
data.l10n = AppLocalizationsHu();
|
||||||
languageCode = 'hu';
|
languageCode = 'hu';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.en:
|
case 2: // en
|
||||||
data.l10n = AppLocalizationsEn();
|
data.l10n = AppLocalizationsEn();
|
||||||
languageCode = 'en';
|
languageCode = 'en';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.de:
|
case 3: // de
|
||||||
data.l10n = AppLocalizationsDe();
|
data.l10n = AppLocalizationsDe();
|
||||||
languageCode = 'de';
|
languageCode = 'de';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.auto:
|
default: // auto
|
||||||
switch (ui.PlatformDispatcher.instance.locale.languageCode) {
|
switch (ui.PlatformDispatcher.instance.locale.languageCode) {
|
||||||
case 'hu':
|
case 'hu':
|
||||||
data.l10n = AppLocalizationsHu();
|
data.l10n = AppLocalizationsHu();
|
||||||
@@ -78,77 +112,44 @@ Future<void> initLang(AppInitialization data) async {
|
|||||||
|
|
||||||
void initTheme(AppInitialization data) {
|
void initTheme(AppInitialization data) {
|
||||||
final themeCubit = data.themeCubit;
|
final themeCubit = data.themeCubit;
|
||||||
|
if (themeCubit == null) return;
|
||||||
|
|
||||||
final brightness =
|
final brightness =
|
||||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||||
|
|
||||||
final titleFont = Settings.titleFont.value;
|
switch ((data.settings.group("settings").subGroup("customization")["theme"]
|
||||||
final titleWeight = Settings.titleWeight.value;
|
as SettingsItemsRadio)
|
||||||
final fonts = buildAppFonts(
|
.activeIndex) {
|
||||||
headingFamily: titleFont.fontFamily,
|
case 1:
|
||||||
headingWeight: titleWeight,
|
appStyle = lightStyle;
|
||||||
supportsWeight: titleFont.supportsWeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
appHeadingTextCase = switch (Settings.titleCapitalization.value) {
|
|
||||||
TitleCapitalization.lower => HeadingTextCase.lower,
|
|
||||||
TitleCapitalization.upper => HeadingTextCase.upper,
|
|
||||||
TitleCapitalization.normal => HeadingTextCase.normal,
|
|
||||||
};
|
|
||||||
|
|
||||||
FirkaStyle baseStyle;
|
|
||||||
final coreId = Settings.selectedCoreThemeId.value;
|
|
||||||
final gradeId = Settings.selectedGradeThemeId.value;
|
|
||||||
switch (Settings.themeBrightness.value) {
|
|
||||||
case ThemeBrightness.light:
|
|
||||||
baseStyle = styleFor(
|
|
||||||
coreId: coreId,
|
|
||||||
gradeId: gradeId,
|
|
||||||
isLight: true,
|
|
||||||
fonts: fonts,
|
|
||||||
);
|
|
||||||
themeCubit.setLightMode(true);
|
themeCubit.setLightMode(true);
|
||||||
break;
|
break;
|
||||||
case ThemeBrightness.dark:
|
case 2:
|
||||||
baseStyle = styleFor(
|
appStyle = darkStyle;
|
||||||
coreId: coreId,
|
|
||||||
gradeId: gradeId,
|
|
||||||
isLight: false,
|
|
||||||
fonts: fonts,
|
|
||||||
);
|
|
||||||
themeCubit.setLightMode(false);
|
themeCubit.setLightMode(false);
|
||||||
break;
|
break;
|
||||||
case ThemeBrightness.auto:
|
default:
|
||||||
if (brightness == Brightness.dark) {
|
if (brightness == Brightness.dark) {
|
||||||
baseStyle = styleFor(
|
appStyle = darkStyle;
|
||||||
coreId: coreId,
|
|
||||||
gradeId: gradeId,
|
|
||||||
isLight: false,
|
|
||||||
fonts: fonts,
|
|
||||||
);
|
|
||||||
themeCubit.setLightMode(false);
|
themeCubit.setLightMode(false);
|
||||||
} else {
|
} else {
|
||||||
baseStyle = styleFor(
|
appStyle = lightStyle;
|
||||||
coreId: coreId,
|
|
||||||
gradeId: gradeId,
|
|
||||||
isLight: true,
|
|
||||||
fonts: fonts,
|
|
||||||
);
|
|
||||||
themeCubit.setLightMode(true);
|
themeCubit.setLightMode(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appStyle = baseStyle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initData(AppInitialization init) async {
|
Future<void> _initData(AppInitialization init) async {
|
||||||
await init.settings.loadAll();
|
init.themeCubit ??= ThemeCubit();
|
||||||
final selectedThemeId = Settings.selectedThemeId.value;
|
init.settingsCubit ??= SettingsCubit();
|
||||||
final normalized = normalizeSelectedThemeId(selectedThemeId);
|
init.profilePictureCubit ??= ProfilePictureCubit();
|
||||||
if (normalized != selectedThemeId) {
|
init.reauthCubit ??= ReauthCubit();
|
||||||
await Settings.selectedThemeId.set(normalized);
|
init.homeRefreshCubit ??= HomeRefreshCubit();
|
||||||
}
|
await init.settings.load(init.isar.appSettingsModels);
|
||||||
await initLang(init);
|
await initLang(init);
|
||||||
initTheme(init);
|
initTheme(init);
|
||||||
|
init.settings = SettingsStore(init.l10n);
|
||||||
|
await init.settings.load(init.isar.appSettingsModels);
|
||||||
|
|
||||||
var dispatcher = SchedulerBinding.instance.platformDispatcher;
|
var dispatcher = SchedulerBinding.instance.platformDispatcher;
|
||||||
|
|
||||||
@@ -157,7 +158,10 @@ Future<void> _initData(AppInitialization init) async {
|
|||||||
};
|
};
|
||||||
|
|
||||||
dispatcher.onLocaleChanged = () {
|
dispatcher.onLocaleChanged = () {
|
||||||
final isAutoLanguage = Settings.language.value == AppLanguage.auto;
|
final languageSetting =
|
||||||
|
init.settings.group("settings").subGroup("application")["language"]
|
||||||
|
as SettingsItemsRadio;
|
||||||
|
final isAutoLanguage = languageSetting.activeIndex == 0;
|
||||||
if (!isAutoLanguage) {
|
if (!isAutoLanguage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -171,10 +175,13 @@ Future<void> _initData(AppInitialization init) async {
|
|||||||
"[Init] System locale changed in auto mode: $previousLocale -> $nextLocale",
|
"[Init] System locale changed in auto mode: $previousLocale -> $nextLocale",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
init.themeCubit.refresh();
|
init.themeCubit?.refresh();
|
||||||
}());
|
}());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resetOldTimeTableCache(init.isar);
|
||||||
|
resetOldHomeworkCache(init.isar);
|
||||||
|
|
||||||
var didRunFreshInstallCleanup = false;
|
var didRunFreshInstallCleanup = false;
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
try {
|
try {
|
||||||
@@ -185,57 +192,50 @@ Future<void> _initData(AppInitialization init) async {
|
|||||||
'[Init] Fresh-install cleanup completed; skipping startup iCloud recovery on this launch',
|
'[Init] Fresh-install cleanup completed; skipping startup iCloud recovery on this launch',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await WatchSyncHelper.checkAndRecoverFromiCloud(isar: init.isar);
|
await WatchSyncHelper.checkAndRecoverFromiCloud(
|
||||||
|
isar: init.isar,
|
||||||
|
tokens: init.tokens,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warning('[Init] iCloud bootstrap/recovery failed: $e');
|
logger.warning('[Init] iCloud bootstrap/recovery failed: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final token = init.settings.getSelectedToken();
|
final allTokens = await init.isar.tokenModels.where().findAll();
|
||||||
if (token == null) {
|
init.tokens = allTokens;
|
||||||
logger.warning("[Init] No token available!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logger.fine("Initializing kréta client as: ${token.username}");
|
|
||||||
init.client = KretaClient(token);
|
|
||||||
|
|
||||||
// Don't block first paint on the network: render whatever is already
|
if (allTokens.isNotEmpty) {
|
||||||
// cached, then stream in student/timetable/grades/etc. as they arrive.
|
final token = pickActiveToken(tokens: allTokens, settings: init.settings);
|
||||||
unawaited(() async {
|
if (token == null) {
|
||||||
try {
|
logger.warning(
|
||||||
await init.client!.init();
|
"[Init] Tokens disappeared during initialization; skipping client setup",
|
||||||
} catch (e) {
|
);
|
||||||
logger.warning("[Init] Failed to initialize KretaClient: $e");
|
return;
|
||||||
if (!isTokenExpired(e)) {
|
|
||||||
init.toastCubit.setActiveToast(.error, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
init.homeRefreshCubit.requestRefresh();
|
logger.fine("Initializing kréta client as: ${token.studentId}");
|
||||||
|
init.client = KretaClient(token, init.isar, init.reauthCubit!);
|
||||||
|
|
||||||
await init.client!.renewCache(reInit: false);
|
if (Platform.isIOS) {
|
||||||
init.homeRefreshCubit.requestRefresh();
|
final expiryDate = token.expiryDate;
|
||||||
}());
|
if (expiryDate != null && expiryDate.isAfter(DateTime.now())) {
|
||||||
|
init.reauthCubit?.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
unawaited(() async {
|
||||||
final expiryDate = token.expiryDate;
|
try {
|
||||||
if (expiryDate.isAfter(DateTime.now())) {
|
await WatchSyncHelper.saveTokenToiCloud(token);
|
||||||
init.toastCubit.clear();
|
} catch (e) {
|
||||||
|
logger.warning('[Init] Failed to sync active token to iCloud: $e');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await WatchSyncHelper.sendTokenModelToWatch(token);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warning('[Init] Failed to sync active token to Watch: $e');
|
||||||
|
}
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
unawaited(() async {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.saveTokenToiCloud(token);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning('[Init] Failed to sync active token to iCloud: $e');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.sendTokenModelToWatch(token);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning('[Init] Failed to sync active token to Watch: $e');
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final dataDir = await getApplicationDocumentsDirectory();
|
final dataDir = await getApplicationDocumentsDirectory();
|
||||||
@@ -244,14 +244,12 @@ Future<void> _initData(AppInitialization init) async {
|
|||||||
if (await pfpFile.exists()) {
|
if (await pfpFile.exists()) {
|
||||||
init.profilePicture = await pfpFile.readAsBytes();
|
init.profilePicture = await pfpFile.readAsBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
init.homeRefreshCubit.requestRefresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initializeApp() async {
|
Future<AppInitialization> initializeApp() async {
|
||||||
if (initDone) {
|
if (initDone) {
|
||||||
await _initData(initData);
|
await _initData(initData);
|
||||||
return;
|
return initData;
|
||||||
}
|
}
|
||||||
final isar = await initDB();
|
final isar = await initDB();
|
||||||
final tokens = await isar.tokenModels.where().findAll();
|
final tokens = await isar.tokenModels.where().findAll();
|
||||||
@@ -281,18 +279,16 @@ Future<void> initializeApp() async {
|
|||||||
logger.fine("Fetched device info: ${devInfoFetched ? "yes" : "no"}");
|
logger.fine("Fetched device info: ${devInfoFetched ? "yes" : "no"}");
|
||||||
logger.fine("Using device info: ${devInfo.toString()}");
|
logger.fine("Using device info: ${devInfo.toString()}");
|
||||||
|
|
||||||
initData = AppInitialization(
|
var init = AppInitialization(
|
||||||
isar: isar,
|
isar: isar,
|
||||||
appDir: await getApplicationDocumentsDirectory(),
|
appDir: await getApplicationDocumentsDirectory(),
|
||||||
devInfo: devInfo,
|
devInfo: devInfo,
|
||||||
packageInfo: await PackageInfo.fromPlatform(),
|
packageInfo: await PackageInfo.fromPlatform(),
|
||||||
settings: SettingsRepository(isar),
|
tokens: tokens,
|
||||||
|
settings: SettingsStore(AppLocalizationsHu()),
|
||||||
l10n: AppLocalizationsHu(),
|
l10n: AppLocalizationsHu(),
|
||||||
navigatorKey: navigatorKey,
|
navigatorKey: navigatorKey,
|
||||||
);
|
);
|
||||||
initData.settings.cubit = initData.settingsCubit;
|
|
||||||
Settings = initData.settings;
|
|
||||||
registerSettingsEffects(initData.settings, initData);
|
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
try {
|
try {
|
||||||
@@ -306,9 +302,52 @@ Future<void> initializeApp() async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _initData(initData);
|
await _initData(init);
|
||||||
|
|
||||||
|
initData = init;
|
||||||
initDone = true;
|
initDone = true;
|
||||||
|
|
||||||
|
flnp = FlutterLocalNotificationsPlugin();
|
||||||
|
const DarwinInitializationSettings initializationSettingsDarwin =
|
||||||
|
DarwinInitializationSettings(
|
||||||
|
requestSoundPermission: true,
|
||||||
|
requestBadgePermission: true,
|
||||||
|
requestAlertPermission: false,
|
||||||
|
);
|
||||||
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||||
|
AndroidInitializationSettings('ic_notification');
|
||||||
|
const InitializationSettings initializationSettings = InitializationSettings(
|
||||||
|
android: initializationSettingsAndroid,
|
||||||
|
iOS: initializationSettingsDarwin,
|
||||||
|
macOS: initializationSettingsDarwin,
|
||||||
|
);
|
||||||
|
await flnp.initialize(settings: initializationSettings);
|
||||||
|
|
||||||
|
Future<void> updateToken([String? fcm]) async {
|
||||||
|
TokenModel? token = pickActiveToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (token == null) return;
|
||||||
|
try {
|
||||||
|
await initData.client.mutexCallback(() async {
|
||||||
|
if (!await initData.client.refreshTokenProactively()) {
|
||||||
|
throw TokenExpiredException();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FirebaseMessaging.instance.onTokenRefresh.listen(
|
||||||
|
(token) => unawaited(updateToken(token)),
|
||||||
|
);
|
||||||
|
|
||||||
|
await updateToken();
|
||||||
|
|
||||||
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setupLogging() async {
|
Future<void> setupLogging() async {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import 'package:firka/app/initialization.dart';
|
|||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
import 'package:firka/core/settings.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||||
import 'package:firka/core/firka_bundle.dart';
|
import 'package:firka/core/firka_bundle.dart';
|
||||||
@@ -31,7 +31,9 @@ class InitializationScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _InitializationScreenState extends State<InitializationScreen> {
|
class _InitializationScreenState extends State<InitializationScreen> {
|
||||||
GoRouter? _router;
|
GoRouter? _router;
|
||||||
final Future<void> _init = initializeApp();
|
final Future<AppInitialization> _init = initializeApp().timeout(
|
||||||
|
const Duration(seconds: 20),
|
||||||
|
);
|
||||||
|
|
||||||
ThemeData _buildTheme(FirkaStyle style) {
|
ThemeData _buildTheme(FirkaStyle style) {
|
||||||
return ThemeData(
|
return ThemeData(
|
||||||
@@ -43,6 +45,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
seedColor: style.colors.accent,
|
seedColor: style.colors.accent,
|
||||||
brightness: style.isLight ? Brightness.light : Brightness.dark,
|
brightness: style.isLight ? Brightness.light : Brightness.dark,
|
||||||
|
background: style.colors.background,
|
||||||
surface: style.colors.card,
|
surface: style.colors.card,
|
||||||
),
|
),
|
||||||
useMaterial3: false,
|
useMaterial3: false,
|
||||||
@@ -51,13 +54,11 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<void>(
|
return FutureBuilder<AppInitialization>(
|
||||||
future: _init,
|
future: _init,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
initDone = false;
|
|
||||||
|
|
||||||
logger.shout(
|
logger.shout(
|
||||||
"Error in InitializationScreen",
|
"Error in InitializationScreen",
|
||||||
snapshot.error.toString(),
|
snapshot.error.toString(),
|
||||||
@@ -82,6 +83,10 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(snapshot.data != null);
|
||||||
|
initData = snapshot.data!;
|
||||||
|
initDone = true;
|
||||||
|
|
||||||
FlutterNativeSplash.remove();
|
FlutterNativeSplash.remove();
|
||||||
|
|
||||||
WatchSyncHelper.initialize();
|
WatchSyncHelper.initialize();
|
||||||
@@ -108,20 +113,24 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
|
|
||||||
switch (msg["id"]) {
|
switch (msg["id"]) {
|
||||||
case "ping":
|
case "ping":
|
||||||
logger.finest("WatchOS IPC [Phone -> Watch]: pong");
|
if (initData.tokens.isNotEmpty) {
|
||||||
unawaited(WatchSyncHelper.sendMessageToWatch({'id': 'pong'}));
|
logger.finest("WatchOS IPC [Phone -> Watch]: pong");
|
||||||
_router?.go('/home');
|
unawaited(
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WatchSyncHelper.sendMessageToWatch({'id': 'pong'}),
|
||||||
final ctx = navigatorKey.currentContext;
|
);
|
||||||
if (ctx != null && ctx.mounted) {
|
_router?.go('/home');
|
||||||
logger.info('Watch init_data: ${jsonEncode(msg)}');
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
showWearBottomSheet(
|
final ctx = navigatorKey.currentContext;
|
||||||
ctx,
|
if (ctx != null && ctx.mounted) {
|
||||||
initData,
|
logger.info('Watch init_data: ${jsonEncode(msg)}');
|
||||||
Platform.isAndroid ? msg['model'] : 'Apple Watch',
|
showWearBottomSheet(
|
||||||
);
|
ctx,
|
||||||
}
|
initData,
|
||||||
});
|
Platform.isAndroid ? msg['model'] : 'Apple Watch',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "init_done":
|
case "init_done":
|
||||||
case "sync_done":
|
case "sync_done":
|
||||||
@@ -148,7 +157,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
await WatchSyncHelper.runWearSyncInForeground(
|
await WatchSyncHelper.runWearSyncInForeground(
|
||||||
initData.client!,
|
initData.client,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -156,7 +165,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
unawaited(() async {
|
unawaited(() async {
|
||||||
try {
|
try {
|
||||||
await WatchSyncHelper.startWearSyncServiceWithFreshCache(
|
await WatchSyncHelper.startWearSyncServiceWithFreshCache(
|
||||||
initData.client!,
|
initData.client,
|
||||||
initData.appDir.path,
|
initData.appDir.path,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -174,11 +183,11 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
appRouter = _router;
|
appRouter = _router;
|
||||||
}
|
}
|
||||||
|
|
||||||
final themeCubit = initData.themeCubit;
|
final themeCubit = initData.themeCubit!;
|
||||||
final settingsCubit = initData.settingsCubit;
|
final settingsCubit = initData.settingsCubit!;
|
||||||
final profilePictureCubit = initData.profilePictureCubit;
|
final profilePictureCubit = initData.profilePictureCubit!;
|
||||||
final reauthCubit = initData.toastCubit;
|
final reauthCubit = initData.reauthCubit!;
|
||||||
final homeRefreshCubit = initData.homeRefreshCubit;
|
final homeRefreshCubit = initData.homeRefreshCubit!;
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider<ThemeCubit>.value(value: themeCubit),
|
BlocProvider<ThemeCubit>.value(value: themeCubit),
|
||||||
@@ -186,7 +195,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
BlocProvider<ProfilePictureCubit>.value(
|
BlocProvider<ProfilePictureCubit>.value(
|
||||||
value: profilePictureCubit,
|
value: profilePictureCubit,
|
||||||
),
|
),
|
||||||
BlocProvider<ToastCubit>.value(value: reauthCubit),
|
BlocProvider<ReauthCubit>.value(value: reauthCubit),
|
||||||
BlocProvider<HomeRefreshCubit>.value(value: homeRefreshCubit),
|
BlocProvider<HomeRefreshCubit>.value(value: homeRefreshCubit),
|
||||||
],
|
],
|
||||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||||
@@ -194,16 +203,15 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
|||||||
final isLight = themeState.isLightMode;
|
final isLight = themeState.isLightMode;
|
||||||
final overlay = SystemUiOverlayStyle(
|
final overlay = SystemUiOverlayStyle(
|
||||||
statusBarColor: Colors.transparent,
|
statusBarColor: Colors.transparent,
|
||||||
statusBarIconBrightness: isLight
|
statusBarIconBrightness:
|
||||||
? Brightness.dark
|
isLight ? Brightness.dark : Brightness.light,
|
||||||
: Brightness.light,
|
statusBarBrightness:
|
||||||
statusBarBrightness: isLight
|
isLight ? Brightness.light : Brightness.dark,
|
||||||
? Brightness.light
|
|
||||||
: Brightness.dark,
|
|
||||||
systemStatusBarContrastEnforced: false,
|
systemStatusBarContrastEnforced: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
final themeMode = isLight ? ThemeMode.light : ThemeMode.dark;
|
final themeMode =
|
||||||
|
isLight ? ThemeMode.light : ThemeMode.dark;
|
||||||
|
|
||||||
final fallbackBg = isLight
|
final fallbackBg = isLight
|
||||||
? lightStyle.colors.background
|
? lightStyle.colors.background
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import "package:flutter/services.dart";
|
|
||||||
import "package:flutter_bloc/flutter_bloc.dart";
|
|
||||||
import "package:logging/logging.dart";
|
|
||||||
|
|
||||||
import "package:firka/core/settings/settings_repository.dart";
|
|
||||||
import "package:firka/core/settings/settings_schema.dart";
|
|
||||||
|
|
||||||
final Logger _logger = Logger('AppIconPickerCubit');
|
|
||||||
|
|
||||||
class AppIconPickerState {
|
|
||||||
final String activeIcon;
|
|
||||||
final bool saving;
|
|
||||||
|
|
||||||
const AppIconPickerState({required this.activeIcon, this.saving = false});
|
|
||||||
|
|
||||||
AppIconPickerState copyWith({String? activeIcon, bool? saving}) =>
|
|
||||||
AppIconPickerState(
|
|
||||||
activeIcon: activeIcon ?? this.activeIcon,
|
|
||||||
saving: saving ?? this.saving,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class AppIconPickerCubit extends Cubit<AppIconPickerState> {
|
|
||||||
AppIconPickerCubit(String initialIcon)
|
|
||||||
: super(AppIconPickerState(activeIcon: initialIcon));
|
|
||||||
|
|
||||||
void select(String icon) {
|
|
||||||
if (state.saving) return;
|
|
||||||
emit(state.copyWith(activeIcon: icon));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Persists the selected icon and swaps the platform's launcher icon.
|
|
||||||
Future<void> save(List<String> allIconKeys) async {
|
|
||||||
if (state.saving) return;
|
|
||||||
emit(state.copyWith(saving: true));
|
|
||||||
|
|
||||||
await Settings.appIcon.set(state.activeIcon);
|
|
||||||
|
|
||||||
await Future.delayed(Duration(seconds: 1));
|
|
||||||
|
|
||||||
_logger.info(allIconKeys.join(","));
|
|
||||||
_logger.info(state.activeIcon);
|
|
||||||
|
|
||||||
const channel = MethodChannel('firka.app/main');
|
|
||||||
_logger.info(
|
|
||||||
await channel.invokeMethod('set_icon', {
|
|
||||||
"icon": state.activeIcon == "original" ? null : state.activeIcon,
|
|
||||||
"icons": allIconKeys.join(","),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
19
firka/lib/core/bloc/reauth_cubit.dart
Normal file
19
firka/lib/core/bloc/reauth_cubit.dart
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
class ReauthState {
|
||||||
|
final bool needsReauth;
|
||||||
|
|
||||||
|
const ReauthState({this.needsReauth = false});
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReauthCubit extends Cubit<ReauthState> {
|
||||||
|
ReauthCubit() : super(const ReauthState());
|
||||||
|
|
||||||
|
void setNeedsReauth(bool value) {
|
||||||
|
emit(ReauthState(needsReauth: value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
emit(const ReauthState(needsReauth: false));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import 'package:firka/ui/phone/pages/extras/firka_toast.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
|
|
||||||
enum ActiveToastType { fetching, error, reauth, none }
|
|
||||||
|
|
||||||
class ToastState {
|
|
||||||
final ActiveToastType type;
|
|
||||||
final Object? extra;
|
|
||||||
|
|
||||||
const ToastState(this.type, [this.extra]);
|
|
||||||
|
|
||||||
Widget? buildWidget(BuildContext context) {
|
|
||||||
switch (type) {
|
|
||||||
case .fetching:
|
|
||||||
return FirkaToastWidget.fetching(context);
|
|
||||||
case .error:
|
|
||||||
return FirkaToastWidget.error(context, extra!);
|
|
||||||
case .reauth:
|
|
||||||
return FirkaToastWidget.reauth(context);
|
|
||||||
case .none:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ToastCubit extends Cubit<ToastState> {
|
|
||||||
ToastCubit() : super(const ToastState(ActiveToastType.none));
|
|
||||||
|
|
||||||
void setActiveToast(ActiveToastType type, [Object? extra]) {
|
|
||||||
emit(ToastState(type, extra));
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear() {
|
|
||||||
setActiveToast(ActiveToastType.none);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -209,12 +209,16 @@ extension DateExtension on DateTime {
|
|||||||
return subtract(Duration(days: weekday - 1));
|
return subtract(Duration(days: weekday - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime getMonthFirstDay() {
|
DateTime getMidnight() {
|
||||||
return DateTime(year, month, 1);
|
return subtract(
|
||||||
}
|
Duration(
|
||||||
|
hours: hour,
|
||||||
DateTime getMonthLastDay() {
|
minutes: minute,
|
||||||
return DateTime(year, month + 1, 1).subtract(Duration(days: 1));
|
seconds: second,
|
||||||
|
milliseconds: millisecond,
|
||||||
|
microseconds: microsecond,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cycle getDayCycle() {
|
Cycle getDayCycle() {
|
||||||
@@ -234,11 +238,6 @@ extension DateExtension on DateTime {
|
|||||||
|
|
||||||
return Cycle.night;
|
return Cycle.night;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime getFirstSchoolDay() {
|
|
||||||
DateTime start = copyWith(month: 9, day: 1);
|
|
||||||
return isBefore(start) ? start.copyWith(year: start.year - 1) : start;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DateGrouper<T> on Iterable<T> {
|
extension DateGrouper<T> on Iterable<T> {
|
||||||
@@ -317,16 +316,4 @@ extension StringExtension on String {
|
|||||||
"${string[0]}.",
|
"${string[0]}.",
|
||||||
).shortenName(index - string.length + 2 + 1);
|
).shortenName(index - string.length + 2 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes CSS font-feature-settings. flutter_html passes values like
|
|
||||||
/// `normal` into FontFeature, which requires a 4-character OpenType tag.
|
|
||||||
String withoutFontFeatureSettings() {
|
|
||||||
return replaceAll(
|
|
||||||
RegExp(
|
|
||||||
r'''font-feature-settings\s*:\s*[^;}"']+;?''',
|
|
||||||
caseSensitive: false,
|
|
||||||
),
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class FirkaBundle extends CachingAssetBundle {
|
class FirkaBundle extends CachingAssetBundle {
|
||||||
@override
|
@override
|
||||||
Future<ByteData> load(String key) async {
|
Future<ByteData> load(String key) async {
|
||||||
|
logger.finest(
|
||||||
|
"Loading asset from root bundle: assets/flutter_assets/$key",
|
||||||
|
);
|
||||||
return rootBundle.load(key);
|
return rootBundle.load(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -98,6 +99,7 @@ class ImagePreloader {
|
|||||||
AssetBundle bundle,
|
AssetBundle bundle,
|
||||||
String assetPath,
|
String assetPath,
|
||||||
) async {
|
) async {
|
||||||
|
logger.finest("Caching: $assetPath");
|
||||||
final ByteData data = await bundle.load(assetPath);
|
final ByteData data = await bundle.load(assetPath);
|
||||||
final Uint8List bytes = data.buffer.asUint8List();
|
final Uint8List bytes = data.buffer.asUint8List();
|
||||||
return await _decodeImageFromBytes(bytes);
|
return await _decodeImageFromBytes(bytes);
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ Future<void> pickProfilePicture(
|
|||||||
await File(p.join(dataDir.path, "profile.webp")).writeAsBytes(bytes);
|
await File(p.join(dataDir.path, "profile.webp")).writeAsBytes(bytes);
|
||||||
|
|
||||||
data.profilePicture = bytes;
|
data.profilePicture = bytes;
|
||||||
data.profilePictureCubit.notifyChanged();
|
data.profilePictureCubit?.notifyChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,45 +0,0 @@
|
|||||||
import "package:isar_community/isar.dart";
|
|
||||||
|
|
||||||
/// A typed key for one persisted setting. Never constructed by hand outside
|
|
||||||
/// settings_schema.gen.dart; settings_schema.dart defines the full registry.
|
|
||||||
sealed class Setting<T> {
|
|
||||||
final Id id;
|
|
||||||
final T defaultValue;
|
|
||||||
|
|
||||||
const Setting({required this.id, required this.defaultValue});
|
|
||||||
}
|
|
||||||
|
|
||||||
class BoolSetting extends Setting<bool> {
|
|
||||||
const BoolSetting({required super.id, required super.defaultValue});
|
|
||||||
}
|
|
||||||
|
|
||||||
class DoubleSetting extends Setting<double> {
|
|
||||||
final double min;
|
|
||||||
final double max;
|
|
||||||
final int precision;
|
|
||||||
final double? step;
|
|
||||||
|
|
||||||
const DoubleSetting({
|
|
||||||
required super.id,
|
|
||||||
required super.defaultValue,
|
|
||||||
required this.min,
|
|
||||||
required this.max,
|
|
||||||
this.precision = 0,
|
|
||||||
this.step,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Persisted as the value's index into [values].
|
|
||||||
class EnumSetting<T extends Enum> extends Setting<T> {
|
|
||||||
final List<T> values;
|
|
||||||
|
|
||||||
const EnumSetting({
|
|
||||||
required super.id,
|
|
||||||
required super.defaultValue,
|
|
||||||
required this.values,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class StringSetting extends Setting<String> {
|
|
||||||
const StringSetting({required super.id, required super.defaultValue});
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
import "dart:io";
|
|
||||||
|
|
||||||
import "package:permission_handler/permission_handler.dart";
|
|
||||||
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/app/initialization.dart";
|
|
||||||
import "package:firka/services/live_activity_service.dart";
|
|
||||||
import "package:firka/services/watch_sync_helper.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
|
||||||
|
|
||||||
import "settings_repository.dart";
|
|
||||||
import "settings_schema.dart";
|
|
||||||
|
|
||||||
/// Registers the side effects that used to live as `postUpdate` closures on
|
|
||||||
/// each SettingsItem. Called once after the repository is loaded at startup.
|
|
||||||
void registerSettingsEffects(
|
|
||||||
SettingsRepository repo,
|
|
||||||
AppInitialization initData,
|
|
||||||
) {
|
|
||||||
repo.onChange(SettingsRegistry.language, (_) async {
|
|
||||||
await initLang(initData);
|
|
||||||
initData.homeRefreshCubit.requestRefresh();
|
|
||||||
});
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.themeBrightness, (_) async {
|
|
||||||
initTheme(initData);
|
|
||||||
initData.themeCubit.refresh();
|
|
||||||
initData.homeRefreshCubit.requestRefresh();
|
|
||||||
});
|
|
||||||
|
|
||||||
Future<void> refreshTitleStyle(_) async {
|
|
||||||
initTheme(initData);
|
|
||||||
initData.themeCubit.refresh();
|
|
||||||
initData.homeRefreshCubit.requestRefresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.titleFont, refreshTitleStyle);
|
|
||||||
repo.onChange(SettingsRegistry.titleWeight, refreshTitleStyle);
|
|
||||||
repo.onChange(SettingsRegistry.titleCapitalization, refreshTitleStyle);
|
|
||||||
|
|
||||||
Future<void> refreshPresetTheme(_) async {
|
|
||||||
if (isBuiltinThemeId(Settings.selectedThemeId.value)) {
|
|
||||||
final next = composeBuiltinThemeId(
|
|
||||||
Settings.selectedCoreThemeId.value,
|
|
||||||
Settings.selectedGradeThemeId.value,
|
|
||||||
);
|
|
||||||
if (next != Settings.selectedThemeId.value) {
|
|
||||||
await Settings.selectedThemeId.setSilently(next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
initTheme(initData);
|
|
||||||
initData.themeCubit.refresh();
|
|
||||||
initData.homeRefreshCubit.requestRefresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.selectedCoreThemeId, refreshPresetTheme);
|
|
||||||
repo.onChange(SettingsRegistry.selectedGradeThemeId, refreshPresetTheme);
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.wearOsSupport, (enabled) async {
|
|
||||||
if (!Platform.isAndroid) return;
|
|
||||||
if (enabled && initDone) {
|
|
||||||
final notifStatus = await Permission.notification.status;
|
|
||||||
if (notifStatus.isDenied || notifStatus.isPermanentlyDenied) {
|
|
||||||
await Permission.notification.request();
|
|
||||||
}
|
|
||||||
await WatchSyncHelper.startWearSyncServiceWithFreshCache(
|
|
||||||
initData.client!,
|
|
||||||
initData.appDir.path,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await WatchSyncHelper.stopWearSyncService();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.morningNotificationEnabled, (enabled) async {
|
|
||||||
LiveActivityService.onMorningNotificationEnabledChanged(enabled);
|
|
||||||
});
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.liveActivityEnabled, (enabled) async {
|
|
||||||
await LiveActivityService.handleEnabledChange(enabled, isManual: true);
|
|
||||||
await LiveActivityService.syncGlobalSettingWithCurrentUser();
|
|
||||||
});
|
|
||||||
|
|
||||||
// These two mirror LiveActivity widgets on iOS only, matching the original
|
|
||||||
// postUpdate wiring that was only attached inside an `if (Platform.isIOS)` block.
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
repo.onChange(SettingsRegistry.bellDelay, (value) async {
|
|
||||||
LiveActivityService.onBellDelayChanged(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
repo.onChange(SettingsRegistry.morningNotificationTime, (value) async {
|
|
||||||
LiveActivityService.onMorningNotificationTimeChanged(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
import "package:flutter/widgets.dart";
|
|
||||||
import "package:isar_community/isar.dart";
|
|
||||||
|
|
||||||
import "package:firka/core/bloc/settings_cubit.dart";
|
|
||||||
import "package:firka_common/core/grade_helper.dart" as grade_helper;
|
|
||||||
import "package:firka_common/data/database.dart";
|
|
||||||
import "package:firka_common/data/models/app_settings_model.dart";
|
|
||||||
import "package:firka_common/data/models/token_model.dart";
|
|
||||||
import "package:firka_common/ui/theme/style.dart";
|
|
||||||
|
|
||||||
import "setting.dart";
|
|
||||||
import "settings_schema.dart";
|
|
||||||
|
|
||||||
/// Isar id for the selected Kréta account, kept outside SettingsRegistry since
|
|
||||||
/// it's not a bounded typed value. Distinct from appIcon's id 0 on purpose:
|
|
||||||
/// the original code reused id 0 for both, silently clobbering one another.
|
|
||||||
const _selectedAccountId = 1025;
|
|
||||||
|
|
||||||
/// Live, repository-bound access to every setting, e.g. `Settings.bellDelay.value`.
|
|
||||||
/// Set once at startup once the real SettingsRepository exists. Distinct from
|
|
||||||
/// SettingsRegistry, which only holds the typed key definitions (id, bounds,
|
|
||||||
/// default) and has no notion of a current value.
|
|
||||||
// ignore: non_constant_identifier_names
|
|
||||||
late SettingsRepository Settings;
|
|
||||||
|
|
||||||
/// A single setting bound to its repository. Generated accessors on
|
|
||||||
/// SettingsRepository (see settings_schema.gen.dart) return one of these per
|
|
||||||
/// setting, so callers read `.value` and write via `.set`/`.setSilently`
|
|
||||||
/// instead of the more verbose `repo.get(Settings.x)` / `repo.set(Settings.x, v)`.
|
|
||||||
class SilentlySettable<T> {
|
|
||||||
final SettingsRepository _repo;
|
|
||||||
final Setting<T> _setting;
|
|
||||||
|
|
||||||
const SilentlySettable(this._repo, this._setting);
|
|
||||||
|
|
||||||
T get value => _repo.get(_setting);
|
|
||||||
|
|
||||||
Future<void> set(T value) => _repo.set(_setting, value);
|
|
||||||
|
|
||||||
Future<void> setSilently(T value) => _repo.setSilently(_setting, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Owns every setting's current value and its Isar persistence.
|
|
||||||
/// Replaces the per-item load/save methods that used to live on each SettingsItem subclass.
|
|
||||||
class SettingsRepository {
|
|
||||||
final Isar isar;
|
|
||||||
SettingsCubit? cubit;
|
|
||||||
IsarCollection<AppSettingsModel> get box => isar.appSettingsModels;
|
|
||||||
final _values = <Id, dynamic>{};
|
|
||||||
final _effects = <Id, List<Future<void> Function(dynamic)>>{};
|
|
||||||
|
|
||||||
SettingsRepository(this.isar, [this.cubit]);
|
|
||||||
|
|
||||||
T get<T>(Setting<T> setting) =>
|
|
||||||
(_values[setting.id] ?? setting.defaultValue) as T;
|
|
||||||
|
|
||||||
Future<void> set<T>(Setting<T> setting, T value) async {
|
|
||||||
await setSilently(setting, value);
|
|
||||||
|
|
||||||
for (final effect in _effects[setting.id] ?? const []) {
|
|
||||||
await effect(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Persists without running registered onChange effects. For code that IS
|
|
||||||
/// itself an effect syncing a setting from an external source (e.g. the
|
|
||||||
/// backend's live activity preferences) and would otherwise recursively
|
|
||||||
/// trigger its own onChange handler.
|
|
||||||
Future<void> setSilently<T>(Setting<T> setting, T value) async {
|
|
||||||
_values[setting.id] = value;
|
|
||||||
|
|
||||||
final row = AppSettingsModel()..id = setting.id;
|
|
||||||
switch (value) {
|
|
||||||
case bool v:
|
|
||||||
row.valueBool = v;
|
|
||||||
case double v:
|
|
||||||
row.valueDouble = v;
|
|
||||||
case Enum v:
|
|
||||||
row.valueIndex = v.index;
|
|
||||||
case String v:
|
|
||||||
row.valueString = v;
|
|
||||||
}
|
|
||||||
await isar.writeTxn(() async {
|
|
||||||
await box.put(row);
|
|
||||||
});
|
|
||||||
|
|
||||||
cubit?.notifyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChange<T>(Setting<T> setting, Future<void> Function(T value) effect) {
|
|
||||||
(_effects[setting.id] ??= []).add((value) => effect(value as T));
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> loadAll() async {
|
|
||||||
for (final setting in SettingsRegistry.all) {
|
|
||||||
final row = await box.get(setting.id);
|
|
||||||
_values[setting.id] = switch (setting) {
|
|
||||||
BoolSetting() => row?.valueBool ?? setting.defaultValue,
|
|
||||||
DoubleSetting() => row?.valueDouble ?? setting.defaultValue,
|
|
||||||
EnumSetting(:final values) =>
|
|
||||||
row?.valueIndex != null
|
|
||||||
? values[row!.valueIndex!]
|
|
||||||
: setting.defaultValue,
|
|
||||||
StringSetting() => row?.valueString ?? setting.defaultValue,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int roundGrade(num grade) {
|
|
||||||
return grade_helper.roundGrade(
|
|
||||||
grade,
|
|
||||||
t1: get(SettingsRegistry.rounding1),
|
|
||||||
t2: get(SettingsRegistry.rounding2),
|
|
||||||
t3: get(SettingsRegistry.rounding3),
|
|
||||||
t4: get(SettingsRegistry.rounding4),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color getGradeColor(num grade) {
|
|
||||||
return switch (roundGrade(grade)) {
|
|
||||||
2 => appStyle.colors.grade2,
|
|
||||||
3 => appStyle.colors.grade3,
|
|
||||||
4 => appStyle.colors.grade4,
|
|
||||||
5 => appStyle.colors.grade5,
|
|
||||||
_ => appStyle.colors.grade1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
int get selectedAccountKey =>
|
|
||||||
box.getSync(_selectedAccountId)?.valueIndex ?? 0;
|
|
||||||
|
|
||||||
Future<void> setSelectedAccountKey(int key) async {
|
|
||||||
await isar.writeTxn(() async {
|
|
||||||
await box.put(
|
|
||||||
AppSettingsModel()
|
|
||||||
..id = _selectedAccountId
|
|
||||||
..valueIndex = key,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TokenModel? getSelectedToken() {
|
|
||||||
return isarInit.tokenModels.getSync(selectedAccountKey) ??
|
|
||||||
isarInit.tokenModels.where().findFirstSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import "setting.dart";
|
|
||||||
import "settings_repository.dart";
|
|
||||||
|
|
||||||
part "settings_schema.gen.dart";
|
|
||||||
|
|
||||||
enum AppLanguage { auto, hu, en, de }
|
|
||||||
|
|
||||||
enum ThemeBrightness { auto, light, dark }
|
|
||||||
|
|
||||||
enum TitleFont {
|
|
||||||
montserrat,
|
|
||||||
monoton,
|
|
||||||
pirataOne,
|
|
||||||
justMeAgainDownHere,
|
|
||||||
figtree,
|
|
||||||
firaCode,
|
|
||||||
vollkorn,
|
|
||||||
}
|
|
||||||
|
|
||||||
enum TitleCapitalization { lower, normal, upper }
|
|
||||||
|
|
||||||
abstract class SettingsSchema {
|
|
||||||
@DoubleSetting(id: 1001, defaultValue: 0, min: 0, max: 120)
|
|
||||||
double get bellDelay;
|
|
||||||
|
|
||||||
@DoubleSetting(id: 1002, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
|
||||||
double get rounding1;
|
|
||||||
|
|
||||||
@DoubleSetting(id: 1003, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
|
||||||
double get rounding2;
|
|
||||||
|
|
||||||
@DoubleSetting(id: 1004, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
|
||||||
double get rounding3;
|
|
||||||
|
|
||||||
@DoubleSetting(id: 1005, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2)
|
|
||||||
double get rounding4;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1006, defaultValue: true)
|
|
||||||
bool get classAvgOnGraph;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1007, defaultValue: false)
|
|
||||||
bool get leftHandedMode;
|
|
||||||
|
|
||||||
@EnumSetting(
|
|
||||||
id: 1008,
|
|
||||||
defaultValue: AppLanguage.auto,
|
|
||||||
values: AppLanguage.values,
|
|
||||||
)
|
|
||||||
AppLanguage get language;
|
|
||||||
|
|
||||||
// SettingsAppIconPicker has always persisted under a
|
|
||||||
// hardcoded id of 0 instead of the appIcon constant.
|
|
||||||
@StringSetting(id: 0, defaultValue: "original")
|
|
||||||
String get appIcon;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1010, defaultValue: true)
|
|
||||||
bool get childProtection;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1011, defaultValue: false)
|
|
||||||
bool get betaWarning;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1012, defaultValue: true)
|
|
||||||
bool get ttToastLessonNo;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1013, defaultValue: true)
|
|
||||||
bool get ttToastTestsAndHw;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1014, defaultValue: true)
|
|
||||||
bool get ttToastBreaks;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1015, defaultValue: false)
|
|
||||||
bool get statsForNerds;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1016, defaultValue: false)
|
|
||||||
bool get developerOptsEnabled;
|
|
||||||
|
|
||||||
@EnumSetting(
|
|
||||||
id: 1017,
|
|
||||||
defaultValue: ThemeBrightness.auto,
|
|
||||||
values: ThemeBrightness.values,
|
|
||||||
)
|
|
||||||
ThemeBrightness get themeBrightness;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1018, defaultValue: true)
|
|
||||||
bool get ttToastSubstitution;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1019, defaultValue: false)
|
|
||||||
bool get liveActivityEnabled;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1020, defaultValue: false)
|
|
||||||
bool get liveActivityPrivacyEverDeclined;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1021, defaultValue: true)
|
|
||||||
bool get morningNotificationEnabled;
|
|
||||||
|
|
||||||
@DoubleSetting(
|
|
||||||
id: 1022,
|
|
||||||
defaultValue: 120,
|
|
||||||
min: 30,
|
|
||||||
max: 240,
|
|
||||||
precision: 0,
|
|
||||||
step: 15,
|
|
||||||
)
|
|
||||||
double get morningNotificationTime;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1023, defaultValue: true)
|
|
||||||
bool get ttToastABTimetable;
|
|
||||||
|
|
||||||
@BoolSetting(id: 1024, defaultValue: false)
|
|
||||||
bool get wearOsSupport;
|
|
||||||
|
|
||||||
// 1025 is reserved for the selected Kréta account outside SettingsRegistry.
|
|
||||||
@EnumSetting(
|
|
||||||
id: 1026,
|
|
||||||
defaultValue: TitleFont.montserrat,
|
|
||||||
values: TitleFont.values,
|
|
||||||
)
|
|
||||||
TitleFont get titleFont;
|
|
||||||
|
|
||||||
@DoubleSetting(
|
|
||||||
id: 1027,
|
|
||||||
defaultValue: 700,
|
|
||||||
min: 100,
|
|
||||||
max: 900,
|
|
||||||
precision: 0,
|
|
||||||
step: 100,
|
|
||||||
)
|
|
||||||
double get titleWeight;
|
|
||||||
|
|
||||||
@EnumSetting(
|
|
||||||
id: 1028,
|
|
||||||
defaultValue: TitleCapitalization.normal,
|
|
||||||
values: TitleCapitalization.values,
|
|
||||||
)
|
|
||||||
TitleCapitalization get titleCapitalization;
|
|
||||||
|
|
||||||
@StringSetting(id: 1029, defaultValue: "builtin-firka-firka")
|
|
||||||
String get selectedThemeId;
|
|
||||||
|
|
||||||
@StringSetting(id: 1030, defaultValue: "firka")
|
|
||||||
String get selectedCoreThemeId;
|
|
||||||
|
|
||||||
@StringSetting(id: 1031, defaultValue: "firka")
|
|
||||||
String get selectedGradeThemeId;
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of "settings_schema.dart";
|
|
||||||
|
|
||||||
class SettingsRegistry {
|
|
||||||
static const bellDelay = DoubleSetting(id: 1001, defaultValue: 0, min: 0, max: 120);
|
|
||||||
static const rounding1 = DoubleSetting(id: 1002, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2);
|
|
||||||
static const rounding2 = DoubleSetting(id: 1003, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2);
|
|
||||||
static const rounding3 = DoubleSetting(id: 1004, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2);
|
|
||||||
static const rounding4 = DoubleSetting(id: 1005, defaultValue: 0.5, min: 0.1, max: 0.99, precision: 2);
|
|
||||||
static const classAvgOnGraph = BoolSetting(id: 1006, defaultValue: true);
|
|
||||||
static const leftHandedMode = BoolSetting(id: 1007, defaultValue: false);
|
|
||||||
static const language = EnumSetting(id: 1008, defaultValue: AppLanguage.auto, values: AppLanguage.values);
|
|
||||||
static const appIcon = StringSetting(id: 0, defaultValue: "original");
|
|
||||||
static const childProtection = BoolSetting(id: 1010, defaultValue: true);
|
|
||||||
static const betaWarning = BoolSetting(id: 1011, defaultValue: false);
|
|
||||||
static const ttToastLessonNo = BoolSetting(id: 1012, defaultValue: true);
|
|
||||||
static const ttToastTestsAndHw = BoolSetting(id: 1013, defaultValue: true);
|
|
||||||
static const ttToastBreaks = BoolSetting(id: 1014, defaultValue: true);
|
|
||||||
static const statsForNerds = BoolSetting(id: 1015, defaultValue: false);
|
|
||||||
static const developerOptsEnabled = BoolSetting(id: 1016, defaultValue: false);
|
|
||||||
static const themeBrightness = EnumSetting(id: 1017, defaultValue: ThemeBrightness.auto, values: ThemeBrightness.values);
|
|
||||||
static const ttToastSubstitution = BoolSetting(id: 1018, defaultValue: true);
|
|
||||||
static const liveActivityEnabled = BoolSetting(id: 1019, defaultValue: false);
|
|
||||||
static const liveActivityPrivacyEverDeclined = BoolSetting(id: 1020, defaultValue: false);
|
|
||||||
static const morningNotificationEnabled = BoolSetting(id: 1021, defaultValue: true);
|
|
||||||
static const morningNotificationTime = DoubleSetting(id: 1022, defaultValue: 120, min: 30, max: 240, precision: 0, step: 15);
|
|
||||||
static const ttToastABTimetable = BoolSetting(id: 1023, defaultValue: true);
|
|
||||||
static const wearOsSupport = BoolSetting(id: 1024, defaultValue: false);
|
|
||||||
static const titleFont = EnumSetting(id: 1026, defaultValue: TitleFont.montserrat, values: TitleFont.values);
|
|
||||||
static const titleWeight = DoubleSetting(id: 1027, defaultValue: 700, min: 100, max: 900, precision: 0, step: 100);
|
|
||||||
static const titleCapitalization = EnumSetting(id: 1028, defaultValue: TitleCapitalization.normal, values: TitleCapitalization.values);
|
|
||||||
static const selectedThemeId = StringSetting(id: 1029, defaultValue: "builtin-firka-firka");
|
|
||||||
static const selectedCoreThemeId = StringSetting(id: 1030, defaultValue: "firka");
|
|
||||||
static const selectedGradeThemeId = StringSetting(id: 1031, defaultValue: "firka");
|
|
||||||
|
|
||||||
static const all = <Setting>[
|
|
||||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, liveActivityEnabled, liveActivityPrivacyEverDeclined, morningNotificationEnabled, morningNotificationTime, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
extension SettingsAccessors on SettingsRepository {
|
|
||||||
SilentlySettable<double> get bellDelay => SilentlySettable(this, SettingsRegistry.bellDelay);
|
|
||||||
SilentlySettable<double> get rounding1 => SilentlySettable(this, SettingsRegistry.rounding1);
|
|
||||||
SilentlySettable<double> get rounding2 => SilentlySettable(this, SettingsRegistry.rounding2);
|
|
||||||
SilentlySettable<double> get rounding3 => SilentlySettable(this, SettingsRegistry.rounding3);
|
|
||||||
SilentlySettable<double> get rounding4 => SilentlySettable(this, SettingsRegistry.rounding4);
|
|
||||||
SilentlySettable<bool> get classAvgOnGraph => SilentlySettable(this, SettingsRegistry.classAvgOnGraph);
|
|
||||||
SilentlySettable<bool> get leftHandedMode => SilentlySettable(this, SettingsRegistry.leftHandedMode);
|
|
||||||
SilentlySettable<AppLanguage> get language => SilentlySettable(this, SettingsRegistry.language);
|
|
||||||
SilentlySettable<String> get appIcon => SilentlySettable(this, SettingsRegistry.appIcon);
|
|
||||||
SilentlySettable<bool> get childProtection => SilentlySettable(this, SettingsRegistry.childProtection);
|
|
||||||
SilentlySettable<bool> get betaWarning => SilentlySettable(this, SettingsRegistry.betaWarning);
|
|
||||||
SilentlySettable<bool> get ttToastLessonNo => SilentlySettable(this, SettingsRegistry.ttToastLessonNo);
|
|
||||||
SilentlySettable<bool> get ttToastTestsAndHw => SilentlySettable(this, SettingsRegistry.ttToastTestsAndHw);
|
|
||||||
SilentlySettable<bool> get ttToastBreaks => SilentlySettable(this, SettingsRegistry.ttToastBreaks);
|
|
||||||
SilentlySettable<bool> get statsForNerds => SilentlySettable(this, SettingsRegistry.statsForNerds);
|
|
||||||
SilentlySettable<bool> get developerOptsEnabled => SilentlySettable(this, SettingsRegistry.developerOptsEnabled);
|
|
||||||
SilentlySettable<ThemeBrightness> get themeBrightness => SilentlySettable(this, SettingsRegistry.themeBrightness);
|
|
||||||
SilentlySettable<bool> get ttToastSubstitution => SilentlySettable(this, SettingsRegistry.ttToastSubstitution);
|
|
||||||
SilentlySettable<bool> get liveActivityEnabled => SilentlySettable(this, SettingsRegistry.liveActivityEnabled);
|
|
||||||
SilentlySettable<bool> get liveActivityPrivacyEverDeclined => SilentlySettable(this, SettingsRegistry.liveActivityPrivacyEverDeclined);
|
|
||||||
SilentlySettable<bool> get morningNotificationEnabled => SilentlySettable(this, SettingsRegistry.morningNotificationEnabled);
|
|
||||||
SilentlySettable<double> get morningNotificationTime => SilentlySettable(this, SettingsRegistry.morningNotificationTime);
|
|
||||||
SilentlySettable<bool> get ttToastABTimetable => SilentlySettable(this, SettingsRegistry.ttToastABTimetable);
|
|
||||||
SilentlySettable<bool> get wearOsSupport => SilentlySettable(this, SettingsRegistry.wearOsSupport);
|
|
||||||
SilentlySettable<TitleFont> get titleFont => SilentlySettable(this, SettingsRegistry.titleFont);
|
|
||||||
SilentlySettable<double> get titleWeight => SilentlySettable(this, SettingsRegistry.titleWeight);
|
|
||||||
SilentlySettable<TitleCapitalization> get titleCapitalization => SilentlySettable(this, SettingsRegistry.titleCapitalization);
|
|
||||||
SilentlySettable<String> get selectedThemeId => SilentlySettable(this, SettingsRegistry.selectedThemeId);
|
|
||||||
SilentlySettable<String> get selectedCoreThemeId => SilentlySettable(this, SettingsRegistry.selectedCoreThemeId);
|
|
||||||
SilentlySettable<String> get selectedGradeThemeId => SilentlySettable(this, SettingsRegistry.selectedGradeThemeId);
|
|
||||||
}
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
|
|
||||||
import "setting.dart";
|
|
||||||
|
|
||||||
/// UI-only description of a settings screen: icons, titles, grouping, navigation,
|
|
||||||
/// visibility. Holds no values itself, only references to typed [Setting]s whose
|
|
||||||
/// values live in SettingsRepository. Separate from the data schema on purpose:
|
|
||||||
/// see AGENTS.md and the settings redesign plan for why.
|
|
||||||
sealed class SettingsUiNode {
|
|
||||||
final bool Function() visible;
|
|
||||||
|
|
||||||
const SettingsUiNode(this.visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiGroup extends SettingsUiNode {
|
|
||||||
final List<SettingsUiNode> children;
|
|
||||||
|
|
||||||
const SettingsUiGroup(this.children, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiPadding extends SettingsUiNode {
|
|
||||||
final double padding;
|
|
||||||
|
|
||||||
const SettingsUiPadding(this.padding, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiBackHeader extends SettingsUiNode {
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
const SettingsUiBackHeader(this.title, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiHeader extends SettingsUiNode {
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
const SettingsUiHeader(this.title, bool Function() visible) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiMediumHeader extends SettingsUiNode {
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
const SettingsUiMediumHeader(this.title, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiHeaderSmall extends SettingsUiNode {
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
const SettingsUiHeaderSmall(this.title, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiSubGroup extends SettingsUiNode {
|
|
||||||
final FirkaIconType? iconType;
|
|
||||||
final Object? iconData;
|
|
||||||
final String title;
|
|
||||||
final List<SettingsUiNode> children;
|
|
||||||
final String? redirectTo;
|
|
||||||
|
|
||||||
const SettingsUiSubGroup(
|
|
||||||
this.iconType,
|
|
||||||
this.iconData,
|
|
||||||
this.title,
|
|
||||||
this.children,
|
|
||||||
bool Function() visible, [
|
|
||||||
this.redirectTo,
|
|
||||||
]) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiBoolean extends SettingsUiNode {
|
|
||||||
final FirkaIconType? iconType;
|
|
||||||
final Object? iconData;
|
|
||||||
final String title;
|
|
||||||
final BoolSetting setting;
|
|
||||||
|
|
||||||
const SettingsUiBoolean(
|
|
||||||
this.iconType,
|
|
||||||
this.iconData,
|
|
||||||
this.title,
|
|
||||||
this.setting,
|
|
||||||
bool Function() visible,
|
|
||||||
) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiDouble extends SettingsUiNode {
|
|
||||||
final FirkaIconType? iconType;
|
|
||||||
final Object? iconData;
|
|
||||||
final String title;
|
|
||||||
final DoubleSetting setting;
|
|
||||||
|
|
||||||
const SettingsUiDouble(
|
|
||||||
this.iconType,
|
|
||||||
this.iconData,
|
|
||||||
this.title,
|
|
||||||
this.setting,
|
|
||||||
bool Function() visible,
|
|
||||||
) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiEnum extends SettingsUiNode {
|
|
||||||
final EnumSetting setting;
|
|
||||||
final List<String> optionLabels;
|
|
||||||
|
|
||||||
const SettingsUiEnum(this.setting, this.optionLabels, bool Function() visible)
|
|
||||||
: super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiButton extends SettingsUiNode {
|
|
||||||
final FirkaIconType? iconType;
|
|
||||||
final Object? iconData;
|
|
||||||
final String title;
|
|
||||||
final Future<void> Function() onTap;
|
|
||||||
|
|
||||||
const SettingsUiButton(
|
|
||||||
this.iconType,
|
|
||||||
this.iconData,
|
|
||||||
this.title,
|
|
||||||
bool Function() visible,
|
|
||||||
this.onTap,
|
|
||||||
) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiAppIconPreview extends SettingsUiNode {
|
|
||||||
const SettingsUiAppIconPreview(super.visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiPersonalization extends SettingsUiNode {
|
|
||||||
final List<SettingsUiNode> appIconPickerChildren;
|
|
||||||
|
|
||||||
const SettingsUiPersonalization(
|
|
||||||
this.appIconPickerChildren,
|
|
||||||
bool Function() visible,
|
|
||||||
) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiAppIconPicker extends SettingsUiNode {
|
|
||||||
final Map<String, List<String>> iconGroups;
|
|
||||||
final SettingsUiBoolean childProtection;
|
|
||||||
|
|
||||||
const SettingsUiAppIconPicker(
|
|
||||||
this.iconGroups,
|
|
||||||
this.childProtection,
|
|
||||||
bool Function() visible,
|
|
||||||
) : super(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiKretaAccountPicker extends SettingsUiNode {
|
|
||||||
const SettingsUiKretaAccountPicker(super.visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiLogs extends SettingsUiNode {
|
|
||||||
const SettingsUiLogs(super.visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsUiLicensePage extends SettingsUiNode {
|
|
||||||
const SettingsUiLicensePage(super.visible);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import "package:firka/core/settings/settings_schema.dart";
|
|
||||||
|
|
||||||
extension TitleFontInfo on TitleFont {
|
|
||||||
String get fontFamily => switch (this) {
|
|
||||||
TitleFont.montserrat => "Montserrat",
|
|
||||||
TitleFont.monoton => "Monoton",
|
|
||||||
TitleFont.pirataOne => "Pirata One",
|
|
||||||
TitleFont.justMeAgainDownHere => "Just Me Again Down Here",
|
|
||||||
TitleFont.figtree => "Figtree",
|
|
||||||
TitleFont.firaCode => "Fira Code",
|
|
||||||
TitleFont.vollkorn => "Vollkorn",
|
|
||||||
};
|
|
||||||
|
|
||||||
String get displayName => fontFamily;
|
|
||||||
|
|
||||||
bool get supportsWeight => switch (this) {
|
|
||||||
TitleFont.montserrat ||
|
|
||||||
TitleFont.figtree ||
|
|
||||||
TitleFont.firaCode ||
|
|
||||||
TitleFont.vollkorn => true,
|
|
||||||
TitleFont.monoton ||
|
|
||||||
TitleFont.pirataOne ||
|
|
||||||
TitleFont.justMeAgainDownHere => false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import "dart:math";
|
|
||||||
|
|
||||||
/// Local Twitter-style snowflake IDs (64-bit, decimal string).
|
|
||||||
class Snowflake {
|
|
||||||
static const int _epochMs = 1704067200000; // 2024-01-01 UTC
|
|
||||||
static final int _workerId = Random().nextInt(1 << 10);
|
|
||||||
static int _sequence = 0;
|
|
||||||
static int _lastTimestamp = -1;
|
|
||||||
|
|
||||||
static String nextId() {
|
|
||||||
var ts = DateTime.now().millisecondsSinceEpoch;
|
|
||||||
if (ts < _lastTimestamp) {
|
|
||||||
ts = _lastTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ts == _lastTimestamp) {
|
|
||||||
_sequence = (_sequence + 1) & 0xFFF;
|
|
||||||
if (_sequence == 0) {
|
|
||||||
while (ts <= _lastTimestamp) {
|
|
||||||
ts = DateTime.now().millisecondsSinceEpoch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_sequence = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastTimestamp = ts;
|
|
||||||
final id = ((ts - _epochMs) << 22) | (_workerId << 12) | _sequence;
|
|
||||||
return id.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -141,7 +141,7 @@ class IOSWidgetHelper {
|
|||||||
'description': subject.category.description,
|
'description': subject.category.description,
|
||||||
},
|
},
|
||||||
'sortIndex': subject.sortIndex,
|
'sortIndex': subject.sortIndex,
|
||||||
'teacherName': null,
|
'teacherName': subject.teacherName,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
'uid': '',
|
'uid': '',
|
||||||
@@ -152,7 +152,8 @@ class IOSWidgetHelper {
|
|||||||
},
|
},
|
||||||
'theme': lesson.theme,
|
'theme': lesson.theme,
|
||||||
'roomName': lesson.roomName,
|
'roomName': lesson.roomName,
|
||||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
'isCancelled':
|
||||||
|
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||||
'isSubstitution': lesson.substituteTeacher != null,
|
'isSubstitution': lesson.substituteTeacher != null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
25
firka/lib/data/models/generic_cache_model.dart
Normal file
25
firka/lib/data/models/generic_cache_model.dart
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import 'package:isar_community/isar.dart';
|
||||||
|
|
||||||
|
part 'generic_cache_model.g.dart';
|
||||||
|
|
||||||
|
enum CacheId {
|
||||||
|
getStudent,
|
||||||
|
getNoticeBoard,
|
||||||
|
getInfoBoard,
|
||||||
|
getGrades,
|
||||||
|
getOmissions,
|
||||||
|
getTests,
|
||||||
|
getClassGroup,
|
||||||
|
getSubjectAvg,
|
||||||
|
getLessons,
|
||||||
|
getHomework,
|
||||||
|
getClassGroupAvg,
|
||||||
|
}
|
||||||
|
|
||||||
|
@collection
|
||||||
|
class GenericCacheModel {
|
||||||
|
Id? cacheKey;
|
||||||
|
String? cacheData;
|
||||||
|
|
||||||
|
GenericCacheModel();
|
||||||
|
}
|
||||||
68
firka/lib/data/models/homework_cache_model.dart
Normal file
68
firka/lib/data/models/homework_cache_model.dart
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import 'package:isar_community/isar.dart';
|
||||||
|
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
|
import 'package:firka/data/util.dart';
|
||||||
|
|
||||||
|
part 'homework_cache_model.g.dart';
|
||||||
|
|
||||||
|
@collection
|
||||||
|
class HomeworkCacheModel extends DatedCacheEntry {
|
||||||
|
HomeworkCacheModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> resetOldHomeworkCache(Isar isar) async {
|
||||||
|
var now = timeNow();
|
||||||
|
var weeks = await isar.homeworkCacheModels.where().findAll();
|
||||||
|
var weeksToRemove = List<Id>.empty(growable: true);
|
||||||
|
|
||||||
|
for (var week in weeks) {
|
||||||
|
var date = getDate(week.cacheKey!);
|
||||||
|
|
||||||
|
if (date.millisecondsSinceEpoch <
|
||||||
|
now.subtract(Duration(days: 120)).millisecondsSinceEpoch) {
|
||||||
|
weeksToRemove.add(week.cacheKey!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await isar.writeTxn(() async {
|
||||||
|
await isar.homeworkCacheModels.deleteAll(weeksToRemove);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@collection
|
||||||
|
class HomeworkDoneModel {
|
||||||
|
Id? id;
|
||||||
|
|
||||||
|
late String homeworkId;
|
||||||
|
late DateTime doneAt;
|
||||||
|
|
||||||
|
HomeworkDoneModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> markAsDone(Isar isar, String homeWorkUid) async {
|
||||||
|
await isar.writeTxn(() async {
|
||||||
|
await isar.homeworkDoneModels.put(
|
||||||
|
HomeworkDoneModel()
|
||||||
|
..homeworkId = homeWorkUid
|
||||||
|
..doneAt = DateTime.now(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> markAsNotDone(Isar isar, String homeWorkUid) async {
|
||||||
|
await isar.writeTxn(() async {
|
||||||
|
final idsToDelete = await isar.homeworkDoneModels
|
||||||
|
.filter()
|
||||||
|
.homeworkIdEqualTo(homeWorkUid)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
|
await isar.homeworkDoneModels.deleteAll(idsToDelete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> isHomeworkDone(Isar isar, String homeWorkUid) async {
|
||||||
|
var existing = await isar.homeworkDoneModels
|
||||||
|
.filter()
|
||||||
|
.homeworkIdEqualTo(homeWorkUid)
|
||||||
|
.findFirst();
|
||||||
|
return existing != null;
|
||||||
|
}
|
||||||
29
firka/lib/data/models/timetable_cache_model.dart
Normal file
29
firka/lib/data/models/timetable_cache_model.dart
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import 'package:isar_community/isar.dart';
|
||||||
|
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
|
import 'package:firka/data/util.dart';
|
||||||
|
|
||||||
|
part 'timetable_cache_model.g.dart';
|
||||||
|
|
||||||
|
@collection
|
||||||
|
class TimetableCacheModel extends DatedCacheEntry {
|
||||||
|
TimetableCacheModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> resetOldTimeTableCache(Isar isar) async {
|
||||||
|
var now = timeNow();
|
||||||
|
var weeks = await isar.timetableCacheModels.where().findAll();
|
||||||
|
var weeksToRemove = List<Id>.empty(growable: true);
|
||||||
|
|
||||||
|
for (var week in weeks) {
|
||||||
|
var date = getDate(week.cacheKey!);
|
||||||
|
|
||||||
|
if (date.millisecondsSinceEpoch <
|
||||||
|
now.subtract(Duration(days: 120)).millisecondsSinceEpoch) {
|
||||||
|
weeksToRemove.add(week.cacheKey!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await isar.writeTxn(() async {
|
||||||
|
await isar.timetableCacheModels.deleteAll(weeksToRemove);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,19 +1,25 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
import 'package:firka/core/extensions.dart';
|
||||||
|
import 'package:firka_common/core/debug_helper.dart';
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:isar_community/isar.dart';
|
||||||
|
|
||||||
part 'token_model.g.dart';
|
part 'token_model.g.dart';
|
||||||
|
|
||||||
@collection
|
@collection
|
||||||
class TokenModel {
|
class TokenModel {
|
||||||
late Id key; // Custom unique student identifier with "G0" removed
|
Id? studentIdNorm; // Custom unique student identifier with "G0" removed
|
||||||
late int studentId;
|
String? studentId; // Custom unique student identifier
|
||||||
late String username; // Custom unique student identifier
|
String? iss; // Institution id for student
|
||||||
late String iss; // Institution id for student
|
String? idToken; // Unique identifier for the token if needed
|
||||||
late String idToken; // Unique identifier for the token if needed
|
String? accessToken; // The main auth token
|
||||||
late String accessToken; // The main auth token
|
String? refreshToken; // Token used to refresh the access token
|
||||||
late String refreshToken; // Token used to refresh the access token
|
String? registrationId;
|
||||||
late DateTime expiryDate;
|
String? fcmToken;
|
||||||
|
DateTime? expiryDate;
|
||||||
int? tokenVersion;
|
int? tokenVersion;
|
||||||
int? updatedAtMs;
|
int? updatedAtMs;
|
||||||
|
|
||||||
@@ -21,7 +27,7 @@ class TokenModel {
|
|||||||
|
|
||||||
factory TokenModel.fromValues(
|
factory TokenModel.fromValues(
|
||||||
Id studentIdNorm,
|
Id studentIdNorm,
|
||||||
String studentId,
|
studentId,
|
||||||
String iss,
|
String iss,
|
||||||
String idToken,
|
String idToken,
|
||||||
String accessToken,
|
String accessToken,
|
||||||
@@ -32,8 +38,8 @@ class TokenModel {
|
|||||||
}) {
|
}) {
|
||||||
var m = TokenModel();
|
var m = TokenModel();
|
||||||
|
|
||||||
m.key = studentIdNorm;
|
m.studentIdNorm = studentIdNorm;
|
||||||
m.username = studentId;
|
m.studentId = studentId;
|
||||||
m.iss = iss;
|
m.iss = iss;
|
||||||
m.idToken = idToken;
|
m.idToken = idToken;
|
||||||
m.accessToken = accessToken;
|
m.accessToken = accessToken;
|
||||||
@@ -50,18 +56,30 @@ class TokenModel {
|
|||||||
final jwt = JWT.decode(resp.idToken);
|
final jwt = JWT.decode(resp.idToken);
|
||||||
|
|
||||||
final payload = jwt.payload as Map<String, dynamic>;
|
final payload = jwt.payload as Map<String, dynamic>;
|
||||||
m.key = int.tryParse(
|
final username = payload["kreta:user_name"].toString();
|
||||||
"${payload["kreta:institute_code"].hashCode}${payload["kreta:institute_user_id"]}",
|
if (username.isNumeric() ||
|
||||||
)!;
|
(username.contains("G0") &&
|
||||||
m.studentId =
|
username.substring(0, username.length - 3).isNumeric())) {
|
||||||
int.tryParse(payload["kreta:student_id"] ?? "") ?? // parent only field
|
m.studentIdNorm = int.parse(username.toString().replaceAll("G0", ""));
|
||||||
int.tryParse(payload["kreta:institute_user_id"])!;
|
} else {
|
||||||
m.username = payload["kreta:user_name"];
|
// you would expect all usernames to be numeric
|
||||||
|
// and for them be the student's student id, but NO
|
||||||
|
final hash = sha256.convert(utf8.encode(username));
|
||||||
|
final value =
|
||||||
|
((hash.bytes[0] << 24) |
|
||||||
|
(hash.bytes[1] << 16) |
|
||||||
|
(hash.bytes[2] << 8) |
|
||||||
|
(hash.bytes[3])) >>>
|
||||||
|
0;
|
||||||
|
|
||||||
|
m.studentIdNorm = value & 0x3FFFFFFF;
|
||||||
|
}
|
||||||
|
m.studentId = payload["kreta:user_name"];
|
||||||
m.iss = payload["kreta:institute_code"];
|
m.iss = payload["kreta:institute_code"];
|
||||||
m.idToken = resp.idToken;
|
m.idToken = resp.idToken;
|
||||||
m.accessToken = resp.accessToken;
|
m.accessToken = resp.accessToken;
|
||||||
m.refreshToken = resp.refreshToken;
|
m.refreshToken = resp.refreshToken;
|
||||||
m.expiryDate = DateTime.now()
|
m.expiryDate = timeNow()
|
||||||
.add(Duration(seconds: resp.expiresIn))
|
.add(Duration(seconds: resp.expiresIn))
|
||||||
.subtract(Duration(minutes: 1)); // just to be safe
|
.subtract(Duration(minutes: 1)); // just to be safe
|
||||||
final iat = payload["iat"];
|
final iat = payload["iat"];
|
||||||
24
firka/lib/data/util.dart
Normal file
24
firka/lib/data/util.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:isar_community/isar.dart';
|
||||||
|
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
|
|
||||||
|
class DatedCacheEntry {
|
||||||
|
Id? cacheKey;
|
||||||
|
late List<String> values;
|
||||||
|
}
|
||||||
|
|
||||||
|
int genCacheKey(DateTime date, int studentId) {
|
||||||
|
var md = date.month * pow(10, 2) + date.day;
|
||||||
|
|
||||||
|
return (md * pow(10, 11) + studentId) as int;
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime getDate(int key) {
|
||||||
|
var md = key ~/ pow(10, 11);
|
||||||
|
var month = md ~/ pow(10, 2);
|
||||||
|
var day = (md - month * pow(10, 2)) as int;
|
||||||
|
|
||||||
|
return DateTime(timeNow().year, month, day);
|
||||||
|
}
|
||||||
@@ -3,12 +3,11 @@ import 'dart:convert';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka/data/ios_widget_helper.dart';
|
import 'package:firka_common/ui/components/grade_helpers.dart';
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/core/debug_helper.dart';
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/data/ios_widget_helper.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@@ -17,12 +16,13 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|
||||||
class WidgetCacheHelper {
|
class WidgetCacheHelper {
|
||||||
static Map<String, dynamic> toJson(
|
static Map<String, dynamic> toJson(FirkaStyle style, List<Lesson> timetable) {
|
||||||
FirkaStyle style,
|
|
||||||
List<LessonCacheModel> timetable,
|
|
||||||
) {
|
|
||||||
List<Map<String, dynamic>> timetableJson = [];
|
List<Map<String, dynamic>> timetableJson = [];
|
||||||
|
|
||||||
|
for (var lesson in timetable) {
|
||||||
|
timetableJson.add(lesson.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
return {'colors': _colorsMap(style), 'timetable': timetableJson};
|
return {'colors': _colorsMap(style), 'timetable': timetableJson};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,13 +86,20 @@ class WidgetCacheHelper {
|
|||||||
|
|
||||||
final start = now.subtract(Duration(days: 7));
|
final start = now.subtract(Duration(days: 7));
|
||||||
final end = now.add(Duration(days: 14));
|
final end = now.add(Duration(days: 14));
|
||||||
final lessons = await client.getLessons(start, end);
|
final lessons = await client.getTimeTable(start, end, forceCache: false);
|
||||||
|
|
||||||
final widgetFile = File(p.join(dataDir.path, "widget_state.json"));
|
final widgetFile = File(p.join(dataDir.path, "widget_state.json"));
|
||||||
|
|
||||||
widgetFile.writeAsString(
|
if (lessons.response != null) {
|
||||||
jsonEncode(WidgetCacheHelper.toJson(style, lessons)),
|
debugPrint(
|
||||||
);
|
'Android widget cache: ${lessons.response!.length} lessons (cached: ${lessons.cached})',
|
||||||
|
);
|
||||||
|
widgetFile.writeAsString(
|
||||||
|
jsonEncode(WidgetCacheHelper.toJson(style, lessons.response!)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
debugPrint('Android widget cache: No lessons to cache');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> generateWidgetStateForDate(
|
static Future<void> generateWidgetStateForDate(
|
||||||
@@ -101,8 +108,16 @@ class WidgetCacheHelper {
|
|||||||
KretaClient client,
|
KretaClient client,
|
||||||
) async {
|
) async {
|
||||||
final dataDir = await getApplicationDocumentsDirectory();
|
final dataDir = await getApplicationDocumentsDirectory();
|
||||||
|
final dayStart = DateTime(date.year, date.month, date.day);
|
||||||
|
final dayEnd = dayStart.add(Duration(hours: 23, minutes: 59));
|
||||||
|
final lessons = await client.getTimeTable(
|
||||||
|
dayStart,
|
||||||
|
dayEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
final dayLessons = lessons.response ?? [];
|
||||||
|
|
||||||
final json = toJson(style, []);
|
final json = toJson(style, dayLessons);
|
||||||
json['displayDate'] =
|
json['displayDate'] =
|
||||||
'${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
'${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||||
|
|
||||||
@@ -110,41 +125,73 @@ class WidgetCacheHelper {
|
|||||||
await widgetFile.writeAsString(jsonEncode(json));
|
await widgetFile.writeAsString(jsonEncode(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> updateIOSWidgets({
|
||||||
|
required String locale,
|
||||||
|
required String theme,
|
||||||
|
required List<Lesson> todayLessons,
|
||||||
|
required List<Lesson> tomorrowLessons,
|
||||||
|
List<Lesson> nextSchoolDayLessons = const [],
|
||||||
|
DateTime? nextSchoolDayDate,
|
||||||
|
required List<Grade> grades,
|
||||||
|
required Map<String, double> subjectAverages,
|
||||||
|
required double? overallAverage,
|
||||||
|
WidgetBreakInfo? currentBreak,
|
||||||
|
}) async {
|
||||||
|
await IOSWidgetHelper.updateWidgetData(
|
||||||
|
locale: locale,
|
||||||
|
theme: theme,
|
||||||
|
todayLessons: todayLessons,
|
||||||
|
tomorrowLessons: tomorrowLessons,
|
||||||
|
nextSchoolDayLessons: nextSchoolDayLessons,
|
||||||
|
nextSchoolDayDate: nextSchoolDayDate,
|
||||||
|
grades: grades,
|
||||||
|
subjectAverages: subjectAverages,
|
||||||
|
overallAverage: overallAverage,
|
||||||
|
currentBreak: currentBreak,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Comprehensive iOS widget refresh that collects all necessary data
|
/// Comprehensive iOS widget refresh that collects all necessary data
|
||||||
/// Call this on: app open, user switch, data refresh
|
/// Call this on: app open, user switch, data refresh
|
||||||
static Future<void> refreshIOSWidgets(
|
static Future<void> refreshIOSWidgets(
|
||||||
KretaClient client,
|
KretaClient client,
|
||||||
SettingsRepository settings,
|
SettingsStore settings,
|
||||||
) async {
|
) async {
|
||||||
if (!Platform.isIOS) return;
|
if (!Platform.isIOS) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final language = settings.get(SettingsRegistry.language);
|
final langIndex =
|
||||||
|
(settings.group("settings").subGroup("application")["language"]
|
||||||
|
as SettingsItemsRadio)
|
||||||
|
.activeIndex;
|
||||||
String locale;
|
String locale;
|
||||||
switch (language) {
|
switch (langIndex) {
|
||||||
case AppLanguage.hu:
|
case 1:
|
||||||
locale = 'hu';
|
locale = 'hu';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.en:
|
case 2:
|
||||||
locale = 'en';
|
locale = 'en';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.de:
|
case 3:
|
||||||
locale = 'de';
|
locale = 'de';
|
||||||
break;
|
break;
|
||||||
case AppLanguage.auto:
|
default:
|
||||||
locale = 'hu';
|
locale = 'hu';
|
||||||
}
|
}
|
||||||
|
|
||||||
final themeBrightness = settings.get(SettingsRegistry.themeBrightness);
|
final themeIndex =
|
||||||
|
(settings.group("settings").subGroup("customization")["theme"]
|
||||||
|
as SettingsItemsRadio)
|
||||||
|
.activeIndex;
|
||||||
String theme;
|
String theme;
|
||||||
switch (themeBrightness) {
|
switch (themeIndex) {
|
||||||
case ThemeBrightness.light:
|
case 1:
|
||||||
theme = 'light';
|
theme = 'light';
|
||||||
break;
|
break;
|
||||||
case ThemeBrightness.dark:
|
case 2:
|
||||||
theme = 'dark';
|
theme = 'dark';
|
||||||
break;
|
break;
|
||||||
case ThemeBrightness.auto:
|
default:
|
||||||
theme =
|
theme =
|
||||||
SchedulerBinding.instance.platformDispatcher.platformBrightness ==
|
SchedulerBinding.instance.platformDispatcher.platformBrightness ==
|
||||||
Brightness.light
|
Brightness.light
|
||||||
@@ -156,17 +203,19 @@ class WidgetCacheHelper {
|
|||||||
final todayMidnight = DateTime(now.year, now.month, now.day);
|
final todayMidnight = DateTime(now.year, now.month, now.day);
|
||||||
final tomorrowMidnight = todayMidnight.add(Duration(days: 1));
|
final tomorrowMidnight = todayMidnight.add(Duration(days: 1));
|
||||||
|
|
||||||
await client.getLessons(
|
final todayResponse = await client.getTimeTable(
|
||||||
todayMidnight,
|
todayMidnight,
|
||||||
todayMidnight.add(Duration(hours: 23, minutes: 59)),
|
todayMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||||
|
forceCache: false,
|
||||||
);
|
);
|
||||||
await client.getLessons(
|
final tomorrowResponse = await client.getTimeTable(
|
||||||
tomorrowMidnight,
|
tomorrowMidnight,
|
||||||
tomorrowMidnight.add(Duration(hours: 23, minutes: 59)),
|
tomorrowMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||||
|
forceCache: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
final todayLessons = [];
|
final todayLessons = todayResponse.response ?? [];
|
||||||
final tomorrowLessons = [];
|
final tomorrowLessons = tomorrowResponse.response ?? [];
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'iOS widget refresh: ${todayLessons.length} today lessons, ${tomorrowLessons.length} tomorrow lessons',
|
'iOS widget refresh: ${todayLessons.length} today lessons, ${tomorrowLessons.length} tomorrow lessons',
|
||||||
@@ -177,11 +226,12 @@ class WidgetCacheHelper {
|
|||||||
if (tomorrowLessons.isEmpty) {
|
if (tomorrowLessons.isEmpty) {
|
||||||
for (int i = 2; i <= 7; i++) {
|
for (int i = 2; i <= 7; i++) {
|
||||||
final dayMidnight = todayMidnight.add(Duration(days: i));
|
final dayMidnight = todayMidnight.add(Duration(days: i));
|
||||||
await client.getLessons(
|
final dayResponse = await client.getTimeTable(
|
||||||
dayMidnight,
|
dayMidnight,
|
||||||
dayMidnight.add(Duration(hours: 23, minutes: 59)),
|
dayMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||||
|
forceCache: false,
|
||||||
);
|
);
|
||||||
final dayLessons = <Lesson>[];
|
final dayLessons = dayResponse.response ?? [];
|
||||||
if (dayLessons.isNotEmpty) {
|
if (dayLessons.isNotEmpty) {
|
||||||
nextSchoolDayLessons = dayLessons;
|
nextSchoolDayLessons = dayLessons;
|
||||||
nextSchoolDayDate = dayMidnight;
|
nextSchoolDayDate = dayMidnight;
|
||||||
@@ -193,11 +243,11 @@ class WidgetCacheHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final gradesResponse = await client.getGrades();
|
final gradesResponse = await client.getGrades(forceCache: false);
|
||||||
final grades = [];
|
final grades = gradesResponse.response ?? [];
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'iOS widget refresh: ${grades.length} grades fetched (cached: $gradesResponse)',
|
'iOS widget refresh: ${grades.length} grades fetched (cached: ${gradesResponse.cached})',
|
||||||
);
|
);
|
||||||
|
|
||||||
final Map<String, double> subjectAverages = {};
|
final Map<String, double> subjectAverages = {};
|
||||||
@@ -208,18 +258,25 @@ class WidgetCacheHelper {
|
|||||||
|
|
||||||
subjects.addAll(grades.map((g) => g.subject));
|
subjects.addAll(grades.map((g) => g.subject));
|
||||||
|
|
||||||
|
for (var subject in subjects) {
|
||||||
|
final average = grades.getAverageBySubject(subject);
|
||||||
|
if (average != null) {
|
||||||
|
subjectAverages[subject.uid] = average;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WidgetBreakInfo? currentBreak;
|
WidgetBreakInfo? currentBreak;
|
||||||
|
|
||||||
await IOSWidgetHelper.updateWidgetData(
|
await updateIOSWidgets(
|
||||||
locale: locale,
|
locale: locale,
|
||||||
theme: theme,
|
theme: theme,
|
||||||
todayLessons: [],
|
todayLessons: todayLessons,
|
||||||
tomorrowLessons: [],
|
tomorrowLessons: tomorrowLessons,
|
||||||
nextSchoolDayLessons: nextSchoolDayLessons,
|
nextSchoolDayLessons: nextSchoolDayLessons,
|
||||||
nextSchoolDayDate: nextSchoolDayDate,
|
nextSchoolDayDate: nextSchoolDayDate,
|
||||||
grades: [],
|
grades: grades,
|
||||||
subjectAverages: subjectAverages,
|
subjectAverages: subjectAverages,
|
||||||
overallAverage: 0.0,
|
overallAverage: grades.getSubjectAverage(),
|
||||||
currentBreak: currentBreak,
|
currentBreak: currentBreak,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -234,7 +291,7 @@ class WidgetCacheHelper {
|
|||||||
if (!Platform.isIOS) return;
|
if (!Platform.isIOS) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await IOSWidgetHelper.updateWidgetData(
|
await updateIOSWidgets(
|
||||||
locale: 'hu',
|
locale: 'hu',
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
todayLessons: [],
|
todayLessons: [],
|
||||||
|
|||||||
Submodule firka/lib/l10n updated: f4812ec3b3...32bea9c6be
@@ -1,5 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
@@ -7,16 +10,38 @@ import 'package:firka/app/app_state.dart';
|
|||||||
import 'package:firka/app/initialization.dart';
|
import 'package:firka/app/initialization.dart';
|
||||||
import 'package:firka/app/initialization_screen.dart';
|
import 'package:firka/app/initialization_screen.dart';
|
||||||
|
|
||||||
|
Future<void> ertesites(String title, String message) async {
|
||||||
|
logger.info("REMOTE Title: $title");
|
||||||
|
logger.info("REMOTE Message: $message");
|
||||||
|
const NotificationDetails notificationDetails = NotificationDetails(
|
||||||
|
android: AndroidNotificationDetails(
|
||||||
|
'teszt',
|
||||||
|
'Értesítés',
|
||||||
|
channelDescription: 'Értesítés a Krétától.',
|
||||||
|
importance: Importance.max,
|
||||||
|
ticker: 'ticker',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await flnp.show(
|
||||||
|
id: 0,
|
||||||
|
title: title,
|
||||||
|
body: message,
|
||||||
|
notificationDetails: notificationDetails,
|
||||||
|
payload: "szia",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||||
|
await ertesites(message.data["Title"], message.data["Message"]);
|
||||||
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
logger = Logger("Firka");
|
logger = Logger("Firka");
|
||||||
|
|
||||||
dio.options.connectTimeout = Duration(seconds: 5);
|
dio.options.connectTimeout = Duration(seconds: 5);
|
||||||
dio.options.receiveTimeout = Duration(seconds: 3);
|
dio.options.receiveTimeout = Duration(seconds: 3);
|
||||||
dio.options.validateStatus = (status) => status != null && status < 500;
|
dio.options.validateStatus = (status) => status != null && status < 500;
|
||||||
|
|
||||||
FlutterError.onError = (details) {
|
|
||||||
FlutterError.presentError(details);
|
|
||||||
};
|
|
||||||
|
|
||||||
runZonedGuarded(
|
runZonedGuarded(
|
||||||
() async {
|
() async {
|
||||||
logger.finest("Initializing app");
|
logger.finest("Initializing app");
|
||||||
@@ -32,6 +57,26 @@ void main() async {
|
|||||||
|
|
||||||
await setupLogging();
|
await setupLogging();
|
||||||
|
|
||||||
|
await Firebase.initializeApp(
|
||||||
|
name: defaultFirebaseAppName,
|
||||||
|
options: FirebaseOptions(
|
||||||
|
apiKey: "AIzaSyA_SnXigQkSvFuB5ECpgz8pZ1SjKzuKiFo",
|
||||||
|
appId: "1:694136934013:android:2d6873f63e005250",
|
||||||
|
androidClientId:
|
||||||
|
"694136934013-6e2jmrbqume6lt92d2ceb5se6uru4uvm.apps.googleusercontent.com",
|
||||||
|
projectId: "ellenorzo-v2",
|
||||||
|
messagingSenderId: "694136934013",
|
||||||
|
storageBucket: "ellenorzo-v2.appspot.com",
|
||||||
|
databaseURL: "https://ellenorzo-v2.firebaseio.com",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
FirebaseMessaging.instance.setAutoInitEnabled(true);
|
||||||
|
|
||||||
|
FirebaseMessaging.onBackgroundMessage(
|
||||||
|
_firebaseMessagingBackgroundHandler,
|
||||||
|
);
|
||||||
|
|
||||||
runApp(InitializationScreen());
|
runApp(InitializationScreen());
|
||||||
},
|
},
|
||||||
(error, stackTrace) {
|
(error, stackTrace) {
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
import 'package:firka/ui/phone/pages/home/home_omissions.dart';
|
import 'package:firka/ui/phone/pages/home/home_omissions.dart';
|
||||||
import 'package:firka_common/data/models/message_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:firka/core/firka_bundle.dart';
|
import 'package:firka/core/firka_bundle.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/settings.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
|
||||||
import 'package:firka/core/settings/settings_ui.dart';
|
|
||||||
import 'package:firka/ui/phone/pages/home/home_grades.dart';
|
import 'package:firka/ui/phone/pages/home/home_grades.dart';
|
||||||
import 'package:firka/ui/phone/pages/home/home_grades_subject.dart';
|
import 'package:firka/ui/phone/pages/home/home_grades_subject.dart';
|
||||||
import 'package:firka/ui/phone/pages/home/home_main.dart';
|
import 'package:firka/ui/phone/pages/home/home_main.dart';
|
||||||
@@ -20,23 +17,20 @@ import 'package:firka/ui/phone/screens/login/login_screen.dart';
|
|||||||
import 'package:firka/ui/phone/screens/message/message_screen.dart';
|
import 'package:firka/ui/phone/screens/message/message_screen.dart';
|
||||||
import 'package:firka/ui/phone/screens/home/home_screen.dart';
|
import 'package:firka/ui/phone/screens/home/home_screen.dart';
|
||||||
import 'package:firka/ui/phone/screens/settings/settings_screen.dart';
|
import 'package:firka/ui/phone/screens/settings/settings_screen.dart';
|
||||||
import 'package:firka/ui/phone/screens/themes/theme_screen.dart';
|
|
||||||
import 'package:firka/ui/phone/screens/themes/themes_screen.dart';
|
|
||||||
import 'package:firka/ui/phone/screens/themes/user_theme.dart';
|
|
||||||
import 'package:firka/routing/chart_interaction_scope.dart';
|
import 'package:firka/routing/chart_interaction_scope.dart';
|
||||||
import 'package:firka/routing/shell_with_nav_bar.dart';
|
import 'package:firka/routing/shell_with_nav_bar.dart';
|
||||||
import 'package:firka/routing/swipable_navigator_container.dart';
|
import 'package:firka/routing/swipable_navigator_container.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
|
||||||
GoRouter createAppRouter() {
|
GoRouter createAppRouter() {
|
||||||
final subjectRoute = GoRoute(
|
final subjectRoute = GoRoute(
|
||||||
path: 'subject',
|
path: 'subject',
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return DefaultAssetBundle(
|
return DefaultAssetBundle(
|
||||||
bundle: FirkaBundle(),
|
bundle: FirkaBundle(),
|
||||||
child: HomeGradesSubjectScreen.subject(
|
child: HomeGradesSubjectScreen(state.extra as Subject, initData),
|
||||||
state.extra as SubjectCacheModel,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -90,35 +84,18 @@ GoRouter createAppRouter() {
|
|||||||
path: '/settings',
|
path: '/settings',
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final items = state.extra != null
|
final items = state.extra != null
|
||||||
? state.extra! as List<SettingsUiNode>
|
? state.extra! as LinkedHashMap<String, SettingsItem>
|
||||||
: buildSettingsTree(initData.l10n).children;
|
: initData.settings.items;
|
||||||
return DefaultAssetBundle(
|
return DefaultAssetBundle(
|
||||||
bundle: FirkaBundle(),
|
bundle: FirkaBundle(),
|
||||||
child: SettingsScreen(initData, items, key: state.pageKey),
|
child: SettingsScreen(initData, items, key: state.pageKey),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
GoRoute(
|
|
||||||
path: '/themes',
|
|
||||||
builder: (context, state) => DefaultAssetBundle(
|
|
||||||
bundle: FirkaBundle(),
|
|
||||||
child: ThemesScreen(initData, key: state.pageKey),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/theme',
|
|
||||||
builder: (context, state) {
|
|
||||||
final args = state.extra as ThemeScreenArgs;
|
|
||||||
return DefaultAssetBundle(
|
|
||||||
bundle: FirkaBundle(),
|
|
||||||
child: ThemeScreen(initData, args, key: state.pageKey),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/message',
|
path: '/message',
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final info = state.extra as MessageCacheModel?;
|
final info = state.extra as MessageItem?;
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
@@ -191,12 +168,9 @@ GoRouter createAppRouter() {
|
|||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'monthly',
|
path: 'monthly',
|
||||||
pageBuilder: (context, state) => _viewSwitchPage(
|
builder: (context, state) => DefaultAssetBundle(
|
||||||
key: state.pageKey,
|
bundle: FirkaBundle(),
|
||||||
child: DefaultAssetBundle(
|
child: HomeTimetableMonthlyScreen(initData),
|
||||||
bundle: FirkaBundle(),
|
|
||||||
child: HomeTimetableMonthlyScreen(initData),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
subjectRoute,
|
subjectRoute,
|
||||||
@@ -226,8 +200,10 @@ GoRouter createAppRouter() {
|
|||||||
|
|
||||||
String get _initialLocation {
|
String get _initialLocation {
|
||||||
if (!initDone) return '/';
|
if (!initDone) return '/';
|
||||||
if (initData.client == null) return '/login';
|
if (initData.tokens.isEmpty) return '/login';
|
||||||
final betaWarning = Settings.betaWarning.value;
|
final betaWarning = initData.settings
|
||||||
|
.group('settings')
|
||||||
|
.boolean('beta_warning');
|
||||||
if (!betaWarning) return '/beta';
|
if (!betaWarning) return '/beta';
|
||||||
return '/home';
|
return '/home';
|
||||||
}
|
}
|
||||||
@@ -235,8 +211,10 @@ String get _initialLocation {
|
|||||||
String? _redirect(BuildContext context, GoRouterState state) {
|
String? _redirect(BuildContext context, GoRouterState state) {
|
||||||
if (!initDone) return null;
|
if (!initDone) return null;
|
||||||
final location = state.matchedLocation;
|
final location = state.matchedLocation;
|
||||||
final hasTokens = initData.client != null;
|
final hasTokens = initData.tokens.isNotEmpty;
|
||||||
final betaWarning = Settings.betaWarning.value;
|
final betaWarning = initData.settings
|
||||||
|
.group('settings')
|
||||||
|
.boolean('beta_warning');
|
||||||
|
|
||||||
if (!hasTokens) {
|
if (!hasTokens) {
|
||||||
if (location != '/login') return '/login';
|
if (location != '/login') return '/login';
|
||||||
@@ -261,33 +239,3 @@ String? _redirect(BuildContext context, GoRouterState state) {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomTransitionPage<void> _viewSwitchPage({
|
|
||||||
required LocalKey key,
|
|
||||||
required Widget child,
|
|
||||||
}) {
|
|
||||||
return CustomTransitionPage<void>(
|
|
||||||
key: key,
|
|
||||||
opaque: false,
|
|
||||||
transitionDuration: const Duration(milliseconds: 300),
|
|
||||||
reverseTransitionDuration: const Duration(milliseconds: 250),
|
|
||||||
child: child,
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
final curved = CurvedAnimation(
|
|
||||||
parent: animation,
|
|
||||||
curve: Curves.easeOut,
|
|
||||||
reverseCurve: Curves.easeIn,
|
|
||||||
);
|
|
||||||
return FadeTransition(
|
|
||||||
opacity: curved,
|
|
||||||
child: SlideTransition(
|
|
||||||
position: Tween<Offset>(
|
|
||||||
begin: const Offset(0, 0.04),
|
|
||||||
end: Offset.zero,
|
|
||||||
).animate(curved),
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ShellWithNavBar extends StatelessWidget {
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
|
padding: const EdgeInsets.fromLTRB(55, 16, 55, 12),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
37
firka/lib/services/active_account_helper.dart
Normal file
37
firka/lib/services/active_account_helper.dart
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import 'package:firka/data/models/token_model.dart';
|
||||||
|
|
||||||
|
int resolveActiveAccountIndex(dynamic settings) {
|
||||||
|
try {
|
||||||
|
final dynamic profileSettings = settings.group("profile_settings");
|
||||||
|
final dynamic accountPicker = profileSettings["e_kreta_account_picker"];
|
||||||
|
final dynamic accountIndex = accountPicker.accountIndex;
|
||||||
|
if (accountIndex is int && accountIndex >= 0) {
|
||||||
|
return accountIndex;
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TokenModel? pickActiveToken({
|
||||||
|
required List<TokenModel> tokens,
|
||||||
|
required dynamic settings,
|
||||||
|
int? preferredStudentIdNorm,
|
||||||
|
}) {
|
||||||
|
if (tokens.isEmpty) return null;
|
||||||
|
|
||||||
|
if (preferredStudentIdNorm != null) {
|
||||||
|
for (final token in tokens) {
|
||||||
|
if (token.studentIdNorm == preferredStudentIdNorm) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final accountIndex = resolveActiveAccountIndex(settings);
|
||||||
|
if (accountIndex < tokens.length) {
|
||||||
|
return tokens[accountIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens.first;
|
||||||
|
}
|
||||||
@@ -242,7 +242,8 @@ class LiveActivityManager {
|
|||||||
'nextRoomName': isBeforeSchool ? null : nextLesson?.roomName,
|
'nextRoomName': isBeforeSchool ? null : nextLesson?.roomName,
|
||||||
'nextStartTime': nextStartTimeForActivity?.toUtc().toIso8601String(),
|
'nextStartTime': nextStartTimeForActivity?.toUtc().toIso8601String(),
|
||||||
'isSubstitution': currentLesson.substituteTeacher != null,
|
'isSubstitution': currentLesson.substituteTeacher != null,
|
||||||
'isCancelled': currentLesson.state.name.toLowerCase().contains('elmarad'),
|
'isCancelled':
|
||||||
|
currentLesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||||
'substituteTeacher': currentLesson.substituteTeacher,
|
'substituteTeacher': currentLesson.substituteTeacher,
|
||||||
'currentTime': now.toUtc().toIso8601String(),
|
'currentTime': now.toUtc().toIso8601String(),
|
||||||
'mode': mode,
|
'mode': mode,
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import 'dart:async';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka/api/client/live_activity_backend_client.dart';
|
import 'package:firka/api/client/live_activity_backend_client.dart';
|
||||||
import 'package:firka/data/widget.dart';
|
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
import 'package:firka/data/models/app_settings_model.dart';
|
||||||
|
import 'package:firka/data/widget.dart';
|
||||||
import 'package:firka/services/live_activity_manager.dart';
|
import 'package:firka/services/live_activity_manager.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/services/active_account_helper.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/ui/phone/screens/live_activity/live_activity_consent_screen.dart';
|
import 'package:firka/ui/phone/screens/live_activity/live_activity_consent_screen.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -60,12 +61,12 @@ class LiveActivityService {
|
|||||||
static String? _getCurrentStudentId({KretaClient? client}) {
|
static String? _getCurrentStudentId({KretaClient? client}) {
|
||||||
try {
|
try {
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
return client.cache.token.username;
|
return client.model.studentId;
|
||||||
}
|
}
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return initData.client!.cache.token.username;
|
return initData.client.model.studentId;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning('Error getting current studentId: $e');
|
_logger.warning('Error getting current studentId: $e');
|
||||||
return null;
|
return null;
|
||||||
@@ -215,8 +216,17 @@ class LiveActivityService {
|
|||||||
final userLiveActivityEnabled = await _getUserLiveActivityEnabled(
|
final userLiveActivityEnabled = await _getUserLiveActivityEnabled(
|
||||||
client: client,
|
client: client,
|
||||||
);
|
);
|
||||||
if (Settings.liveActivityEnabled.value != userLiveActivityEnabled) {
|
final globalLiveActivitySetting =
|
||||||
await Settings.liveActivityEnabled.setSilently(userLiveActivityEnabled);
|
initData.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("notifications")["live_activity_enabled"]
|
||||||
|
as SettingsBoolean;
|
||||||
|
|
||||||
|
if (globalLiveActivitySetting.value != userLiveActivityEnabled) {
|
||||||
|
globalLiveActivitySetting.value = userLiveActivityEnabled;
|
||||||
|
await initData.isar.writeTxn(() async {
|
||||||
|
await globalLiveActivitySetting.save(initData.isar.appSettingsModels);
|
||||||
|
});
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'Global LiveActivity setting synced: $userLiveActivityEnabled for user $studentId',
|
'Global LiveActivity setting synced: $userLiveActivityEnabled for user $studentId',
|
||||||
);
|
);
|
||||||
@@ -225,10 +235,19 @@ class LiveActivityService {
|
|||||||
final userMorningEnabled = await _getUserMorningNotificationEnabled(
|
final userMorningEnabled = await _getUserMorningNotificationEnabled(
|
||||||
client: client,
|
client: client,
|
||||||
);
|
);
|
||||||
if (Settings.morningNotificationEnabled.value != userMorningEnabled) {
|
final globalMorningEnabledSetting =
|
||||||
await Settings.morningNotificationEnabled.setSilently(
|
initData.settings
|
||||||
userMorningEnabled,
|
.group("settings")
|
||||||
);
|
.subGroup("notifications")["morning_notification_enabled"]
|
||||||
|
as SettingsBoolean;
|
||||||
|
|
||||||
|
if (globalMorningEnabledSetting.value != userMorningEnabled) {
|
||||||
|
globalMorningEnabledSetting.value = userMorningEnabled;
|
||||||
|
await initData.isar.writeTxn(() async {
|
||||||
|
await globalMorningEnabledSetting.save(
|
||||||
|
initData.isar.appSettingsModels,
|
||||||
|
);
|
||||||
|
});
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'Global morning notification enabled synced: $userMorningEnabled for user $studentId',
|
'Global morning notification enabled synced: $userMorningEnabled for user $studentId',
|
||||||
);
|
);
|
||||||
@@ -237,24 +256,40 @@ class LiveActivityService {
|
|||||||
final userMorningTime = await _getUserMorningNotificationTime(
|
final userMorningTime = await _getUserMorningNotificationTime(
|
||||||
client: client,
|
client: client,
|
||||||
);
|
);
|
||||||
if (Settings.morningNotificationTime.value.toInt() != userMorningTime) {
|
final globalMorningTimeSetting =
|
||||||
await Settings.morningNotificationTime.setSilently(
|
initData.settings
|
||||||
userMorningTime.toDouble(),
|
.group("settings")
|
||||||
);
|
.subGroup("notifications")["morning_notification_time"]
|
||||||
|
as SettingsDouble;
|
||||||
|
|
||||||
|
if (globalMorningTimeSetting.value.toInt() != userMorningTime) {
|
||||||
|
globalMorningTimeSetting.value = userMorningTime.toDouble();
|
||||||
|
await initData.isar.writeTxn(() async {
|
||||||
|
await globalMorningTimeSetting.save(initData.isar.appSettingsModels);
|
||||||
|
});
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'Global morning notification time synced: $userMorningTime for user $studentId',
|
'Global morning notification time synced: $userMorningTime for user $studentId',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final userBellDelay = await _getUserBellDelay(client: client);
|
final userBellDelay = await _getUserBellDelay(client: client);
|
||||||
if (Settings.bellDelay.value != userBellDelay) {
|
final globalBellDelaySetting =
|
||||||
await Settings.bellDelay.setSilently(userBellDelay);
|
initData.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("application")["bell_delay"]
|
||||||
|
as SettingsDouble;
|
||||||
|
|
||||||
|
if (globalBellDelaySetting.value != userBellDelay) {
|
||||||
|
globalBellDelaySetting.value = userBellDelay;
|
||||||
|
await initData.isar.writeTxn(() async {
|
||||||
|
await globalBellDelaySetting.save(initData.isar.appSettingsModels);
|
||||||
|
});
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'Global bell delay synced: $userBellDelay for user $studentId',
|
'Global bell delay synced: $userBellDelay for user $studentId',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
initData.themeCubit.refresh();
|
initData.themeCubit?.refresh();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning('Error syncing global settings: $e');
|
_logger.warning('Error syncing global settings: $e');
|
||||||
}
|
}
|
||||||
@@ -267,14 +302,22 @@ class LiveActivityService {
|
|||||||
return 'hu';
|
return 'hu';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Settings.language.value) {
|
final languageSetting =
|
||||||
case AppLanguage.hu:
|
initData.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("application")["language"]
|
||||||
|
as SettingsItemsRadio?;
|
||||||
|
|
||||||
|
if (languageSetting == null) return 'hu';
|
||||||
|
|
||||||
|
switch (languageSetting.activeIndex) {
|
||||||
|
case 1:
|
||||||
return 'hu';
|
return 'hu';
|
||||||
case AppLanguage.en:
|
case 2:
|
||||||
return 'en';
|
return 'en';
|
||||||
case AppLanguage.de:
|
case 3:
|
||||||
return 'de';
|
return 'de';
|
||||||
case AppLanguage.auto:
|
default: // auto
|
||||||
final systemLang = Platform.localeName.split('_').first;
|
final systemLang = Platform.localeName.split('_').first;
|
||||||
if (['hu', 'en', 'de'].contains(systemLang)) {
|
if (['hu', 'en', 'de'].contains(systemLang)) {
|
||||||
return systemLang;
|
return systemLang;
|
||||||
@@ -401,7 +444,7 @@ class LiveActivityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final client = initData.client!;
|
final client = initData.client;
|
||||||
|
|
||||||
final enabled = await isEnabled(initData.settings, client);
|
final enabled = await isEnabled(initData.settings, client);
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
@@ -422,23 +465,39 @@ class LiveActivityService {
|
|||||||
_logger.info(
|
_logger.info(
|
||||||
'Background fetch: attempting to fetch fresh data from KRÉTA API',
|
'Background fetch: attempting to fetch fresh data from KRÉTA API',
|
||||||
);
|
);
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final timetableResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
allLessons = <Lesson>[];
|
endOfWeek,
|
||||||
_logger.info(
|
forceCache: false,
|
||||||
'Background fetch: successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (timetableResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(timetableResponse.response!);
|
||||||
|
_logger.info(
|
||||||
|
'Background fetch: successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw Exception('KRÉTA API returned null response');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
'Background fetch: KRÉTA API failed ($e), falling back to cache',
|
'Background fetch: KRÉTA API failed ($e), falling back to cache',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final cachedResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
allLessons = <Lesson>[];
|
endOfWeek,
|
||||||
_logger.info(
|
forceCache: true,
|
||||||
'Background fetch: successfully loaded ${allLessons.length} lessons from cache',
|
|
||||||
);
|
);
|
||||||
|
if (cachedResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(cachedResponse.response!);
|
||||||
|
_logger.info(
|
||||||
|
'Background fetch: successfully loaded ${allLessons.length} lessons from cache',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_logger.severe('Background fetch: both API and cache failed');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (cacheError) {
|
} catch (cacheError) {
|
||||||
_logger.severe(
|
_logger.severe(
|
||||||
'Background fetch: cache fallback also failed: $cacheError',
|
'Background fetch: cache fallback also failed: $cacheError',
|
||||||
@@ -466,10 +525,14 @@ class LiveActivityService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||||
await client.getLessons(candidateDay, candidateDayEnd);
|
final response = await client.getTimeTable(
|
||||||
|
candidateDay,
|
||||||
|
candidateDayEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (response.response != null && response.response!.isNotEmpty) {
|
||||||
final schoolLessons = [].where((lesson) {
|
final schoolLessons = response.response!.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
return uid.contains('orarendiora') ||
|
return uid.contains('orarendiora') ||
|
||||||
uid.contains('tanitasiora') ||
|
uid.contains('tanitasiora') ||
|
||||||
@@ -576,7 +639,7 @@ class LiveActivityService {
|
|||||||
|
|
||||||
/// Check if LiveActivity is enabled in settings
|
/// Check if LiveActivity is enabled in settings
|
||||||
static Future<bool> isEnabled([
|
static Future<bool> isEnabled([
|
||||||
SettingsRepository? settingsStore,
|
SettingsStore? settingsStore,
|
||||||
KretaClient? client,
|
KretaClient? client,
|
||||||
]) async {
|
]) async {
|
||||||
try {
|
try {
|
||||||
@@ -597,7 +660,7 @@ class LiveActivityService {
|
|||||||
if (!Platform.isIOS) return;
|
if (!Platform.isIOS) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final effectiveClient = initData.client!;
|
final effectiveClient = client ?? initData.client;
|
||||||
final studentId = _getCurrentStudentId(client: effectiveClient);
|
final studentId = _getCurrentStudentId(client: effectiveClient);
|
||||||
if (studentId == null) {
|
if (studentId == null) {
|
||||||
_logger.warning('Cannot change LiveActivity state: no current user');
|
_logger.warning('Cannot change LiveActivity state: no current user');
|
||||||
@@ -651,9 +714,14 @@ class LiveActivityService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await effectiveClient.getStudent();
|
final studentResp = await effectiveClient.getStudent();
|
||||||
final activeToken = initData.client!.cache.token;
|
final activeToken = pickActiveToken(
|
||||||
final studentName = activeToken.username;
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
preferredStudentIdNorm: effectiveClient.model.studentIdNorm,
|
||||||
|
);
|
||||||
|
final studentName =
|
||||||
|
studentResp.response?.name ?? activeToken?.studentId ?? "Student";
|
||||||
|
|
||||||
await onUserLogin(
|
await onUserLogin(
|
||||||
client: effectiveClient,
|
client: effectiveClient,
|
||||||
@@ -783,7 +851,7 @@ class LiveActivityService {
|
|||||||
static Future<void> onUserLogin({
|
static Future<void> onUserLogin({
|
||||||
required KretaClient client,
|
required KretaClient client,
|
||||||
required String studentName,
|
required String studentName,
|
||||||
SettingsRepository? settingsStore,
|
SettingsStore? settingsStore,
|
||||||
}) async {
|
}) async {
|
||||||
_logger.info('onUserLogin: Function called for $studentName');
|
_logger.info('onUserLogin: Function called for $studentName');
|
||||||
|
|
||||||
@@ -821,23 +889,39 @@ class LiveActivityService {
|
|||||||
_logger.info(
|
_logger.info(
|
||||||
'onUserLogin: Attempting to fetch fresh timetable from KRÉTA API',
|
'onUserLogin: Attempting to fetch fresh timetable from KRÉTA API',
|
||||||
);
|
);
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final timetableResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
allLessons = <Lesson>[];
|
endOfWeek,
|
||||||
_logger.info(
|
forceCache: false,
|
||||||
'onUserLogin: Successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (timetableResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(timetableResponse.response!);
|
||||||
|
_logger.info(
|
||||||
|
'onUserLogin: Successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw Exception('KRÉTA API returned null response');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
'onUserLogin: KRÉTA API failed ($e), falling back to cache',
|
'onUserLogin: KRÉTA API failed ($e), falling back to cache',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final cachedResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
allLessons = <Lesson>[];
|
endOfWeek,
|
||||||
_logger.info(
|
forceCache: true,
|
||||||
'onUserLogin: Successfully loaded ${allLessons.length} lessons from cache',
|
|
||||||
);
|
);
|
||||||
|
if (cachedResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(cachedResponse.response!);
|
||||||
|
_logger.info(
|
||||||
|
'onUserLogin: Successfully loaded ${allLessons.length} lessons from cache',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_logger.severe('onUserLogin: Both API and cache failed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (cacheError) {
|
} catch (cacheError) {
|
||||||
_logger.severe(
|
_logger.severe(
|
||||||
'onUserLogin: Cache fallback also failed: $cacheError',
|
'onUserLogin: Cache fallback also failed: $cacheError',
|
||||||
@@ -860,10 +944,14 @@ class LiveActivityService {
|
|||||||
|
|
||||||
List<Lesson> nextWeekBreakEvents = [];
|
List<Lesson> nextWeekBreakEvents = [];
|
||||||
try {
|
try {
|
||||||
await client.getLessons(nextWeekStart, nextWeekEnd);
|
final nextWeekResponse = await client.getTimeTable(
|
||||||
|
nextWeekStart,
|
||||||
|
nextWeekEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (nextWeekResponse.response != null) {
|
||||||
nextWeekBreakEvents = <Lesson>[].where((lesson) {
|
nextWeekBreakEvents = nextWeekResponse.response!.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
final name = lesson.name.toLowerCase();
|
final name = lesson.name.toLowerCase();
|
||||||
return uid.contains('tanevrendjeesemeny') &&
|
return uid.contains('tanevrendjeesemeny') &&
|
||||||
@@ -961,10 +1049,14 @@ class LiveActivityService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||||
await client.getLessons(candidateDay, candidateDayEnd);
|
final response = await client.getTimeTable(
|
||||||
|
candidateDay,
|
||||||
|
candidateDayEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (response.response != null && response.response!.isNotEmpty) {
|
||||||
final schoolLessons = [].where((lesson) {
|
final schoolLessons = response.response!.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
return uid.contains('orarendiora') ||
|
return uid.contains('orarendiora') ||
|
||||||
uid.contains('tanitasiora') ||
|
uid.contains('tanitasiora') ||
|
||||||
@@ -1111,7 +1203,7 @@ class LiveActivityService {
|
|||||||
static Future<void> checkAndUpdateTimetable({
|
static Future<void> checkAndUpdateTimetable({
|
||||||
required KretaClient client,
|
required KretaClient client,
|
||||||
required String studentName,
|
required String studentName,
|
||||||
SettingsRepository? settingsStore,
|
SettingsStore? settingsStore,
|
||||||
bool forceUpdate = false,
|
bool forceUpdate = false,
|
||||||
}) async {
|
}) async {
|
||||||
if (!Platform.isIOS || !_isInitialized) return;
|
if (!Platform.isIOS || !_isInitialized) return;
|
||||||
@@ -1136,17 +1228,35 @@ class LiveActivityService {
|
|||||||
List<Lesson> allLessons = [];
|
List<Lesson> allLessons = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final timetableResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
|
endOfWeek,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
allLessons = List<Lesson>.from([]);
|
if (timetableResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(timetableResponse.response!);
|
||||||
|
} else {
|
||||||
|
throw Exception('KRÉTA API returned null response');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
'checkAndUpdateTimetable: KRÉTA API failed ($e), falling back to cache',
|
'checkAndUpdateTimetable: KRÉTA API failed ($e), falling back to cache',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await client.getLessons(startOfWeek, endOfWeek);
|
final cachedResponse = await client.getTimeTable(
|
||||||
|
startOfWeek,
|
||||||
allLessons = <Lesson>[];
|
endOfWeek,
|
||||||
|
forceCache: true,
|
||||||
|
);
|
||||||
|
if (cachedResponse.response != null) {
|
||||||
|
allLessons = List<Lesson>.from(cachedResponse.response!);
|
||||||
|
} else {
|
||||||
|
_logger.severe(
|
||||||
|
'checkAndUpdateTimetable: Both API and cache failed',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (cacheError) {
|
} catch (cacheError) {
|
||||||
_logger.severe(
|
_logger.severe(
|
||||||
'checkAndUpdateTimetable: Cache fallback also failed: $cacheError',
|
'checkAndUpdateTimetable: Cache fallback also failed: $cacheError',
|
||||||
@@ -1164,10 +1274,14 @@ class LiveActivityService {
|
|||||||
|
|
||||||
List<Lesson> nextWeekBreakEvents = [];
|
List<Lesson> nextWeekBreakEvents = [];
|
||||||
try {
|
try {
|
||||||
await client.getLessons(nextWeekStart, nextWeekEnd);
|
final nextWeekResponse = await client.getTimeTable(
|
||||||
|
nextWeekStart,
|
||||||
|
nextWeekEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (nextWeekResponse.response != null) {
|
||||||
nextWeekBreakEvents = <Lesson>[].where((lesson) {
|
nextWeekBreakEvents = nextWeekResponse.response!.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
final name = lesson.name.toLowerCase();
|
final name = lesson.name.toLowerCase();
|
||||||
return uid.contains('tanevrendjeesemeny') &&
|
return uid.contains('tanevrendjeesemeny') &&
|
||||||
@@ -1261,10 +1375,14 @@ class LiveActivityService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||||
await client.getLessons(candidateDay, candidateDayEnd);
|
final response = await client.getTimeTable(
|
||||||
|
candidateDay,
|
||||||
|
candidateDayEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (response.response != null && response.response!.isNotEmpty) {
|
||||||
final schoolLessons = [].where((lesson) {
|
final schoolLessons = response.response!.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
return uid.contains('orarendiora') ||
|
return uid.contains('orarendiora') ||
|
||||||
uid.contains('tanitasiora') ||
|
uid.contains('tanitasiora') ||
|
||||||
@@ -1372,7 +1490,7 @@ class LiveActivityService {
|
|||||||
static Future<void> _startTimetableMonitoring({
|
static Future<void> _startTimetableMonitoring({
|
||||||
required KretaClient client,
|
required KretaClient client,
|
||||||
required String studentName,
|
required String studentName,
|
||||||
SettingsRepository? settingsStore,
|
SettingsStore? settingsStore,
|
||||||
}) async {
|
}) async {
|
||||||
_stopTimetableMonitoring();
|
_stopTimetableMonitoring();
|
||||||
|
|
||||||
@@ -1775,11 +1893,14 @@ class LiveActivityService {
|
|||||||
'Morning notifications re-enabled, fetching timetable to recreate notifications',
|
'Morning notifications re-enabled, fetching timetable to recreate notifications',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
final client = initData.client!;
|
final client = initData.client;
|
||||||
final settingsStore = initData.settings;
|
final settingsStore = initData.settings;
|
||||||
|
|
||||||
final studentResp = await client.getStudent();
|
final studentResp = await client.getStudent();
|
||||||
final studentName = studentResp.name;
|
final studentName =
|
||||||
|
studentResp.response?.name ??
|
||||||
|
client.model.studentId ??
|
||||||
|
'Student';
|
||||||
|
|
||||||
await checkAndUpdateTimetable(
|
await checkAndUpdateTimetable(
|
||||||
client: client,
|
client: client,
|
||||||
@@ -1836,7 +1957,12 @@ class LiveActivityService {
|
|||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Settings.morningNotificationEnabled.value;
|
final setting =
|
||||||
|
initData.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("notifications")["morning_notification_enabled"]
|
||||||
|
as SettingsBoolean?;
|
||||||
|
return setting?.value;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning('Error getting current morning notification enabled: $e');
|
_logger.warning('Error getting current morning notification enabled: $e');
|
||||||
return null;
|
return null;
|
||||||
@@ -1849,7 +1975,12 @@ class LiveActivityService {
|
|||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Settings.morningNotificationTime.value;
|
final setting =
|
||||||
|
initData.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("notifications")["morning_notification_time"]
|
||||||
|
as SettingsDouble?;
|
||||||
|
return setting?.value;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.warning('Error getting current morning notification time: $e');
|
_logger.warning('Error getting current morning notification time: $e');
|
||||||
return null;
|
return null;
|
||||||
@@ -1883,10 +2014,16 @@ class LiveActivityService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.getLessons(weekStart, weekEnd);
|
final response = await client.getTimeTable(
|
||||||
|
weekStart,
|
||||||
|
weekEnd,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (response.response != null && response.response!.isNotEmpty) {
|
||||||
final breakEvents = [].where((lesson) {
|
final weekLessons = response.response!;
|
||||||
|
|
||||||
|
final breakEvents = weekLessons.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
final name = lesson.name.toLowerCase();
|
final name = lesson.name.toLowerCase();
|
||||||
return uid.contains('tanevrendjeesemeny') &&
|
return uid.contains('tanevrendjeesemeny') &&
|
||||||
@@ -1898,26 +2035,26 @@ class LiveActivityService {
|
|||||||
name.contains('nem órarendi nap'));
|
name.contains('nem órarendi nap'));
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final schoolLessons = [].where((lesson) {
|
final schoolLessons = weekLessons.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
return uid.contains('orarendiora') ||
|
return uid.contains('orarendiora') ||
|
||||||
uid.contains('tanitasiora') ||
|
uid.contains('tanitasiora') ||
|
||||||
uid.contains('uresora');
|
uid.contains('uresora');
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
allLessons.addAll([]);
|
allLessons.addAll(weekLessons);
|
||||||
|
|
||||||
if (breakEvents.isNotEmpty) {
|
if (breakEvents.isNotEmpty) {
|
||||||
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
||||||
lastBreakDay = breakEvents.last;
|
lastBreakDay = breakEvents.last;
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in week ${weeksSearched + 1}, last: $lastBreakDay on $lastBreakDay',
|
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in week ${weeksSearched + 1}, last: ${lastBreakDay.name} on ${lastBreakDay.date.split('T')[0]}',
|
||||||
);
|
);
|
||||||
} else if (schoolLessons.isNotEmpty) {
|
} else if (schoolLessons.isNotEmpty) {
|
||||||
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
||||||
firstSchoolDayAfterBreak = schoolLessons.first;
|
firstSchoolDayAfterBreak = schoolLessons.first;
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'[GlobalBreakSearcher] Found first school day after break: $firstSchoolDayAfterBreak on $firstSchoolDayAfterBreak',
|
'[GlobalBreakSearcher] Found first school day after break: ${firstSchoolDayAfterBreak.name} on ${firstSchoolDayAfterBreak.date.split('T')[0]}',
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -1925,6 +2062,10 @@ class LiveActivityService {
|
|||||||
'[GlobalBreakSearcher] Week ${weeksSearched + 1} is empty, continuing search...',
|
'[GlobalBreakSearcher] Week ${weeksSearched + 1} is empty, continuing search...',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_logger.info(
|
||||||
|
'[GlobalBreakSearcher] Week ${weeksSearched + 1} returned no data, continuing search...',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
final isTokenError =
|
final isTokenError =
|
||||||
@@ -1943,10 +2084,15 @@ class LiveActivityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.getLessons(weekStart, weekEnd);
|
final cachedResponse = await client.getTimeTable(
|
||||||
|
weekStart,
|
||||||
|
weekEnd,
|
||||||
|
forceCache: true,
|
||||||
|
);
|
||||||
|
|
||||||
if (true) {
|
if (cachedResponse.response != null &&
|
||||||
final weekLessons = [];
|
cachedResponse.response!.isNotEmpty) {
|
||||||
|
final weekLessons = cachedResponse.response!;
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'[GlobalBreakSearcher] Loaded ${weekLessons.length} lessons from cache for week ${weeksSearched + 1}',
|
'[GlobalBreakSearcher] Loaded ${weekLessons.length} lessons from cache for week ${weeksSearched + 1}',
|
||||||
);
|
);
|
||||||
@@ -1963,29 +2109,33 @@ class LiveActivityService {
|
|||||||
name.contains('nem órarendi nap'));
|
name.contains('nem órarendi nap'));
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final schoolLessons = [].where((lesson) {
|
final schoolLessons = weekLessons.where((lesson) {
|
||||||
final uid = lesson.uid.toLowerCase();
|
final uid = lesson.uid.toLowerCase();
|
||||||
return uid.contains('orarendiora') ||
|
return uid.contains('orarendiora') ||
|
||||||
uid.contains('tanitasiora') ||
|
uid.contains('tanitasiora') ||
|
||||||
uid.contains('uresora');
|
uid.contains('uresora');
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
allLessons.addAll([]);
|
allLessons.addAll(weekLessons);
|
||||||
|
|
||||||
if (breakEvents.isNotEmpty) {
|
if (breakEvents.isNotEmpty) {
|
||||||
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
||||||
lastBreakDay = breakEvents.last;
|
lastBreakDay = breakEvents.last;
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in cached week ${weeksSearched + 1}, last: $lastBreakDay on $lastBreakDay',
|
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in cached week ${weeksSearched + 1}, last: ${lastBreakDay.name} on ${lastBreakDay.date.split('T')[0]}',
|
||||||
);
|
);
|
||||||
} else if (schoolLessons.isNotEmpty) {
|
} else if (schoolLessons.isNotEmpty) {
|
||||||
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
||||||
firstSchoolDayAfterBreak = schoolLessons.first;
|
firstSchoolDayAfterBreak = schoolLessons.first;
|
||||||
_logger.info(
|
_logger.info(
|
||||||
'[GlobalBreakSearcher] Found first school day after break in cache: $firstSchoolDayAfterBreak on $firstSchoolDayAfterBreak',
|
'[GlobalBreakSearcher] Found first school day after break in cache: ${firstSchoolDayAfterBreak.name} on ${firstSchoolDayAfterBreak.date.split('T')[0]}',
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
_logger.info(
|
||||||
|
'[GlobalBreakSearcher] No cache available for week ${weeksSearched + 1}',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (cacheError) {
|
} catch (cacheError) {
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firka_common/data/database.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:isar_community/isar.dart';
|
||||||
@@ -10,9 +9,10 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||||
|
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
|
import 'package:firka/services/active_account_helper.dart';
|
||||||
import 'package:firka/services/wear_sync_cache.dart';
|
import 'package:firka/services/wear_sync_cache.dart';
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka_common/data/models/token_model.dart';
|
import 'package:firka/data/models/token_model.dart';
|
||||||
|
|
||||||
/// Helper class for Watch ↔ iPhone token sync (iOS) and Wear OS sync (Android).
|
/// Helper class for Watch ↔ iPhone token sync (iOS) and Wear OS sync (Android).
|
||||||
class WatchSyncHelper {
|
class WatchSyncHelper {
|
||||||
@@ -60,6 +60,42 @@ class WatchSyncHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TokenModel? _resolveCurrentToken({
|
||||||
|
List<TokenModel>? tokens,
|
||||||
|
KretaClient? client,
|
||||||
|
}) {
|
||||||
|
final effectiveTokens = tokens ?? (initDone ? initData.tokens : null);
|
||||||
|
if (effectiveTokens == null || effectiveTokens.isEmpty) return null;
|
||||||
|
|
||||||
|
final preferredStudentIdNorm = client?.model.studentIdNorm;
|
||||||
|
if (preferredStudentIdNorm != null) {
|
||||||
|
for (final token in effectiveTokens) {
|
||||||
|
if (token.studentIdNorm == preferredStudentIdNorm) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initDone) {
|
||||||
|
return pickActiveToken(
|
||||||
|
tokens: effectiveTokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
preferredStudentIdNorm: preferredStudentIdNorm,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return effectiveTokens.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int? _resolveExpectedStudentIdNorm({
|
||||||
|
List<TokenModel>? tokens,
|
||||||
|
KretaClient? client,
|
||||||
|
}) {
|
||||||
|
final fromClient = client?.model.studentIdNorm;
|
||||||
|
if (fromClient != null) return fromClient;
|
||||||
|
return _resolveCurrentToken(tokens: tokens, client: client)?.studentIdNorm;
|
||||||
|
}
|
||||||
|
|
||||||
static int? _asInt(dynamic value) {
|
static int? _asInt(dynamic value) {
|
||||||
if (value is int) return value;
|
if (value is int) return value;
|
||||||
if (value is double) return value.toInt();
|
if (value is double) return value.toInt();
|
||||||
@@ -116,6 +152,9 @@ class WatchSyncHelper {
|
|||||||
required TokenModel currentToken,
|
required TokenModel currentToken,
|
||||||
}) {
|
}) {
|
||||||
final currentExpiry = currentToken.expiryDate;
|
final currentExpiry = currentToken.expiryDate;
|
||||||
|
if (currentExpiry == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
final incomingVersion =
|
final incomingVersion =
|
||||||
incomingTokenVersion ??
|
incomingTokenVersion ??
|
||||||
@@ -157,6 +196,7 @@ class WatchSyncHelper {
|
|||||||
|
|
||||||
final currentRefresh = currentToken.refreshToken;
|
final currentRefresh = currentToken.refreshToken;
|
||||||
if (incomingRefreshToken != null &&
|
if (incomingRefreshToken != null &&
|
||||||
|
currentRefresh != null &&
|
||||||
incomingRefreshToken != currentRefresh) {
|
incomingRefreshToken != currentRefresh) {
|
||||||
if (incomingIdToken != null && incomingIdToken != currentToken.idToken) {
|
if (incomingIdToken != null && incomingIdToken != currentToken.idToken) {
|
||||||
return true;
|
return true;
|
||||||
@@ -185,13 +225,13 @@ class WatchSyncHelper {
|
|||||||
? token.updatedAtMs!
|
? token.updatedAtMs!
|
||||||
: nowMs;
|
: nowMs;
|
||||||
final payload = <String, dynamic>{
|
final payload = <String, dynamic>{
|
||||||
'studentId': token.username,
|
'studentId': token.studentId,
|
||||||
'studentIdNorm': token.key,
|
'studentIdNorm': token.studentIdNorm,
|
||||||
'iss': token.iss,
|
'iss': token.iss,
|
||||||
'idToken': token.idToken,
|
'idToken': token.idToken,
|
||||||
'accessToken': token.accessToken,
|
'accessToken': token.accessToken,
|
||||||
'refreshToken': token.refreshToken,
|
'refreshToken': token.refreshToken,
|
||||||
'expiryDate': token.expiryDate.millisecondsSinceEpoch,
|
'expiryDate': token.expiryDate!.millisecondsSinceEpoch,
|
||||||
'tokenVersion': tokenVersion,
|
'tokenVersion': tokenVersion,
|
||||||
'updatedAtMs': updatedAtMs,
|
'updatedAtMs': updatedAtMs,
|
||||||
};
|
};
|
||||||
@@ -408,7 +448,10 @@ class WatchSyncHelper {
|
|||||||
await isar.tokenModels.clear();
|
await isar.tokenModels.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (initDone) initData.toastCubit.clear();
|
if (initDone) {
|
||||||
|
initData.tokens = [];
|
||||||
|
}
|
||||||
|
if (initDone) initData.reauthCubit?.clear();
|
||||||
|
|
||||||
await prefs.setBool(_iosFreshInstallHandledKey, true);
|
await prefs.setBool(_iosFreshInstallHandledKey, true);
|
||||||
return true;
|
return true;
|
||||||
@@ -480,6 +523,7 @@ class WatchSyncHelper {
|
|||||||
try {
|
try {
|
||||||
final recovered = await checkAndRecoverFromiCloud(
|
final recovered = await checkAndRecoverFromiCloud(
|
||||||
isar: initData.isar,
|
isar: initData.isar,
|
||||||
|
tokens: initData.tokens,
|
||||||
client: initData.client,
|
client: initData.client,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -488,10 +532,13 @@ class WatchSyncHelper {
|
|||||||
'[WatchSync] Token recovered from iCloud, reauth flag cleared',
|
'[WatchSync] Token recovered from iCloud, reauth flag cleared',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
final token = initData.client!.cache.token;
|
final token = pickActiveToken(
|
||||||
final expiryDate = token.expiryDate;
|
tokens: initData.tokens,
|
||||||
if (expiryDate.isAfter(DateTime.now())) {
|
settings: initData.settings,
|
||||||
if (initDone) initData.toastCubit.clear();
|
);
|
||||||
|
final expiryDate = token?.expiryDate;
|
||||||
|
if (expiryDate != null && expiryDate.isAfter(DateTime.now())) {
|
||||||
|
if (initDone) initData.reauthCubit?.clear();
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] Cleared reauth flag after iCloud notification (token is valid)',
|
'[WatchSync] Cleared reauth flag after iCloud notification (token is valid)',
|
||||||
);
|
);
|
||||||
@@ -503,14 +550,28 @@ class WatchSyncHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, dynamic>? _getTokenForWatch() {
|
static Map<String, dynamic>? _getTokenForWatch() {
|
||||||
if (!initDone) {
|
if (!initDone || initData.tokens.isEmpty) {
|
||||||
debugPrint('[WatchSync] No token available');
|
debugPrint('[WatchSync] No token available');
|
||||||
return {'error': 'no_token'};
|
return {'error': 'no_token'};
|
||||||
}
|
}
|
||||||
|
|
||||||
final token = initData.client!.cache.token;
|
final token = pickActiveToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
);
|
||||||
|
if (token == null) {
|
||||||
|
debugPrint('[WatchSync] No active token available');
|
||||||
|
return {'error': 'no_token'};
|
||||||
|
}
|
||||||
|
|
||||||
if (initData.client!.needsReauth) {
|
if (token.accessToken == null ||
|
||||||
|
token.refreshToken == null ||
|
||||||
|
token.expiryDate == null) {
|
||||||
|
debugPrint('[WatchSync] Token incomplete');
|
||||||
|
return {'error': 'token_incomplete'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initData.client.needsReauth) {
|
||||||
debugPrint('[WatchSync] iPhone needs reauth');
|
debugPrint('[WatchSync] iPhone needs reauth');
|
||||||
return {'error': 'needsReauth'};
|
return {'error': 'needsReauth'};
|
||||||
}
|
}
|
||||||
@@ -669,8 +730,14 @@ class WatchSyncHelper {
|
|||||||
return {'success': false, 'error': 'no_student_id_norm'};
|
return {'success': false, 'error': 'no_student_id_norm'};
|
||||||
}
|
}
|
||||||
|
|
||||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||||
final currentToken = initData.client!.cache.token;
|
tokens: initData.tokens,
|
||||||
|
client: initData.client,
|
||||||
|
);
|
||||||
|
final currentToken = _resolveCurrentToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
client: initData.client,
|
||||||
|
);
|
||||||
|
|
||||||
final watchExpiryDate = DateTime.fromMillisecondsSinceEpoch(watchExpiry);
|
final watchExpiryDate = DateTime.fromMillisecondsSinceEpoch(watchExpiry);
|
||||||
if (!_isAccessTokenUsable(watchExpiryDate, skew: const Duration())) {
|
if (!_isAccessTokenUsable(watchExpiryDate, skew: const Duration())) {
|
||||||
@@ -684,8 +751,12 @@ class WatchSyncHelper {
|
|||||||
final watchIdToken = tokenData['idToken'] as String?;
|
final watchIdToken = tokenData['idToken'] as String?;
|
||||||
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
||||||
|
|
||||||
final isForActiveAccount = watchStudentIdNorm == expectedStudentIdNorm;
|
final isForActiveAccount =
|
||||||
if (isForActiveAccount && currentToken.key == watchStudentIdNorm) {
|
expectedStudentIdNorm == null ||
|
||||||
|
watchStudentIdNorm == expectedStudentIdNorm;
|
||||||
|
if (isForActiveAccount &&
|
||||||
|
currentToken != null &&
|
||||||
|
currentToken.studentIdNorm == watchStudentIdNorm) {
|
||||||
if (!_isIncomingTokenNewerThanCurrent(
|
if (!_isIncomingTokenNewerThanCurrent(
|
||||||
incomingExpiry: watchExpiryDate,
|
incomingExpiry: watchExpiryDate,
|
||||||
incomingIdToken: watchIdToken,
|
incomingIdToken: watchIdToken,
|
||||||
@@ -721,9 +792,10 @@ class WatchSyncHelper {
|
|||||||
await initData.isar.tokenModels.put(newToken);
|
await initData.isar.tokenModels.put(newToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
initData.tokens = await initData.isar.tokenModels.where().findAll();
|
||||||
if (isForActiveAccount) {
|
if (isForActiveAccount) {
|
||||||
initData.client!.cache.token = newToken;
|
initData.client.model = newToken;
|
||||||
if (initDone) initData.toastCubit.clear();
|
if (initDone) initData.reauthCubit?.clear();
|
||||||
} else {
|
} else {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] Stored token for inactive account ($watchStudentIdNorm), active is $expectedStudentIdNorm',
|
'[WatchSync] Stored token for inactive account ($watchStudentIdNorm), active is $expectedStudentIdNorm',
|
||||||
@@ -749,6 +821,13 @@ class WatchSyncHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (token.accessToken == null ||
|
||||||
|
token.refreshToken == null ||
|
||||||
|
token.expiryDate == null) {
|
||||||
|
debugPrint('[WatchSync] Token incomplete, not sending to Watch');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final accessExpired = !_isAccessTokenUsable(
|
final accessExpired = !_isAccessTokenUsable(
|
||||||
token.expiryDate,
|
token.expiryDate,
|
||||||
skew: const Duration(),
|
skew: const Duration(),
|
||||||
@@ -815,6 +894,7 @@ class WatchSyncHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final effectiveIsar = isar ?? (initDone ? initData.isar : null);
|
final effectiveIsar = isar ?? (initDone ? initData.isar : null);
|
||||||
|
final effectiveTokens = tokens ?? (initDone ? initData.tokens : null);
|
||||||
final effectiveClient = client ?? (initDone ? initData.client : null);
|
final effectiveClient = client ?? (initDone ? initData.client : null);
|
||||||
|
|
||||||
if (effectiveIsar == null) {
|
if (effectiveIsar == null) {
|
||||||
@@ -841,10 +921,14 @@ class WatchSyncHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||||
|
tokens: effectiveTokens,
|
||||||
|
client: effectiveClient,
|
||||||
|
);
|
||||||
|
|
||||||
final iCloudStudentIdNorm = tokenData['studentIdNorm'] as int?;
|
final iCloudStudentIdNorm = tokenData['studentIdNorm'] as int?;
|
||||||
if (iCloudStudentIdNorm != expectedStudentIdNorm) {
|
if (expectedStudentIdNorm != null &&
|
||||||
|
iCloudStudentIdNorm != expectedStudentIdNorm) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] iCloud token belongs to different account ($iCloudStudentIdNorm), active is $expectedStudentIdNorm - ignoring',
|
'[WatchSync] iCloud token belongs to different account ($iCloudStudentIdNorm), active is $expectedStudentIdNorm - ignoring',
|
||||||
);
|
);
|
||||||
@@ -875,16 +959,21 @@ class WatchSyncHelper {
|
|||||||
final iCloudIdToken = tokenData['idToken'] as String?;
|
final iCloudIdToken = tokenData['idToken'] as String?;
|
||||||
final iCloudRefreshToken = tokenData['refreshToken'] as String?;
|
final iCloudRefreshToken = tokenData['refreshToken'] as String?;
|
||||||
|
|
||||||
final currentToken = initData.client!.cache.token;
|
final currentToken = _resolveCurrentToken(
|
||||||
final localExpiry = currentToken.expiryDate;
|
tokens: effectiveTokens,
|
||||||
final shouldAccept = _isIncomingTokenNewerThanCurrent(
|
client: effectiveClient,
|
||||||
incomingExpiry: iCloudExpiryDate,
|
|
||||||
incomingIdToken: iCloudIdToken,
|
|
||||||
incomingRefreshToken: iCloudRefreshToken,
|
|
||||||
incomingTokenVersion: iCloudTokenVersion,
|
|
||||||
incomingUpdatedAtMs: iCloudUpdatedAtMs,
|
|
||||||
currentToken: currentToken,
|
|
||||||
);
|
);
|
||||||
|
final localExpiry = currentToken?.expiryDate;
|
||||||
|
final shouldAccept = currentToken == null
|
||||||
|
? true
|
||||||
|
: _isIncomingTokenNewerThanCurrent(
|
||||||
|
incomingExpiry: iCloudExpiryDate,
|
||||||
|
incomingIdToken: iCloudIdToken,
|
||||||
|
incomingRefreshToken: iCloudRefreshToken,
|
||||||
|
incomingTokenVersion: iCloudTokenVersion,
|
||||||
|
incomingUpdatedAtMs: iCloudUpdatedAtMs,
|
||||||
|
currentToken: currentToken,
|
||||||
|
);
|
||||||
|
|
||||||
if (shouldAccept) {
|
if (shouldAccept) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
@@ -908,14 +997,24 @@ class WatchSyncHelper {
|
|||||||
await effectiveIsar.tokenModels.put(newToken);
|
await effectiveIsar.tokenModels.put(newToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (effectiveClient != null && newToken.key == expectedStudentIdNorm) {
|
final updatedTokens = await effectiveIsar.tokenModels.where().findAll();
|
||||||
effectiveClient.cache.token = newToken;
|
|
||||||
|
if (initDone) {
|
||||||
|
initData.tokens = updatedTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectiveClient != null &&
|
||||||
|
(expectedStudentIdNorm == null ||
|
||||||
|
newToken.studentIdNorm == expectedStudentIdNorm)) {
|
||||||
|
effectiveClient.model = newToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
final shouldClearReauth =
|
final shouldClearReauth =
|
||||||
!iCloudAccessExpired && newToken.key == expectedStudentIdNorm;
|
!iCloudAccessExpired &&
|
||||||
|
(expectedStudentIdNorm == null ||
|
||||||
|
newToken.studentIdNorm == expectedStudentIdNorm);
|
||||||
if (shouldClearReauth) {
|
if (shouldClearReauth) {
|
||||||
if (initDone) initData.toastCubit.clear();
|
if (initDone) initData.reauthCubit?.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
@@ -941,6 +1040,13 @@ class WatchSyncHelper {
|
|||||||
}) async {
|
}) async {
|
||||||
if (!Platform.isIOS) return;
|
if (!Platform.isIOS) return;
|
||||||
|
|
||||||
|
if (token.accessToken == null ||
|
||||||
|
token.refreshToken == null ||
|
||||||
|
token.expiryDate == null) {
|
||||||
|
debugPrint('[WatchSync] Token incomplete, not saving to iCloud');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final watchInstalled = await isWatchAppInstalled();
|
final watchInstalled = await isWatchAppInstalled();
|
||||||
if (!watchInstalled) {
|
if (!watchInstalled) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
@@ -965,7 +1071,16 @@ class WatchSyncHelper {
|
|||||||
List<TokenModel>? tokens,
|
List<TokenModel>? tokens,
|
||||||
KretaClient? client,
|
KretaClient? client,
|
||||||
}) async {
|
}) async {
|
||||||
if (!Platform.isIOS || !initDone) return;
|
if (!Platform.isIOS) return;
|
||||||
|
|
||||||
|
final effectiveIsar = isar ?? (initDone ? initData.isar : null);
|
||||||
|
final effectiveTokens = tokens ?? (initDone ? initData.tokens : null);
|
||||||
|
final effectiveClient = client ?? (initDone ? initData.client : null);
|
||||||
|
|
||||||
|
if (effectiveIsar == null || effectiveTokens == null) {
|
||||||
|
debugPrint('[WatchSync] Cannot sync: no isar or tokens available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debugPrint('[WatchSync] Requesting token from Watch...');
|
debugPrint('[WatchSync] Requesting token from Watch...');
|
||||||
@@ -974,12 +1089,22 @@ class WatchSyncHelper {
|
|||||||
null,
|
null,
|
||||||
const Duration(seconds: 10),
|
const Duration(seconds: 10),
|
||||||
);
|
);
|
||||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||||
final currentToken = initData.client!.cache.token;
|
tokens: effectiveTokens,
|
||||||
|
client: effectiveClient,
|
||||||
|
);
|
||||||
|
final currentToken = _resolveCurrentToken(
|
||||||
|
tokens: effectiveTokens,
|
||||||
|
client: effectiveClient,
|
||||||
|
);
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
debugPrint('[WatchSync] No response from Watch');
|
debugPrint('[WatchSync] No response from Watch');
|
||||||
if (!initData.client!.needsReauth) {
|
if (currentToken != null &&
|
||||||
|
currentToken.accessToken != null &&
|
||||||
|
currentToken.refreshToken != null &&
|
||||||
|
currentToken.expiryDate != null &&
|
||||||
|
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||||
debugPrint('[WatchSync] Sending iPhone token to Watch (no response)');
|
debugPrint('[WatchSync] Sending iPhone token to Watch (no response)');
|
||||||
await _sendTokenToWatchInternal(
|
await _sendTokenToWatchInternal(
|
||||||
currentToken,
|
currentToken,
|
||||||
@@ -992,7 +1117,11 @@ class WatchSyncHelper {
|
|||||||
final tokenData = result as Map<dynamic, dynamic>;
|
final tokenData = result as Map<dynamic, dynamic>;
|
||||||
if (tokenData.containsKey('error')) {
|
if (tokenData.containsKey('error')) {
|
||||||
debugPrint('[WatchSync] Watch returned error: ${tokenData['error']}');
|
debugPrint('[WatchSync] Watch returned error: ${tokenData['error']}');
|
||||||
if (!initData.client!.needsReauth) {
|
if (currentToken != null &&
|
||||||
|
currentToken.accessToken != null &&
|
||||||
|
currentToken.refreshToken != null &&
|
||||||
|
currentToken.expiryDate != null &&
|
||||||
|
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] Sending iPhone token to Watch (Watch has no token)',
|
'[WatchSync] Sending iPhone token to Watch (Watch has no token)',
|
||||||
);
|
);
|
||||||
@@ -1016,11 +1145,16 @@ class WatchSyncHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (watchStudentIdNorm != expectedStudentIdNorm) {
|
if (expectedStudentIdNorm != null &&
|
||||||
|
watchStudentIdNorm != expectedStudentIdNorm) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] Watch token belongs to different account ($watchStudentIdNorm), active is $expectedStudentIdNorm - keeping active account',
|
'[WatchSync] Watch token belongs to different account ($watchStudentIdNorm), active is $expectedStudentIdNorm - keeping active account',
|
||||||
);
|
);
|
||||||
if (!(initData.client!.needsReauth)) {
|
if (currentToken != null &&
|
||||||
|
currentToken.accessToken != null &&
|
||||||
|
currentToken.refreshToken != null &&
|
||||||
|
currentToken.expiryDate != null &&
|
||||||
|
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||||
await _sendTokenToWatchInternal(
|
await _sendTokenToWatchInternal(
|
||||||
currentToken,
|
currentToken,
|
||||||
allowExpiredAccessToken: true,
|
allowExpiredAccessToken: true,
|
||||||
@@ -1034,11 +1168,15 @@ class WatchSyncHelper {
|
|||||||
debugPrint(
|
debugPrint(
|
||||||
'[WatchSync] Watch provided expired token, ignoring and keeping iPhone token',
|
'[WatchSync] Watch provided expired token, ignoring and keeping iPhone token',
|
||||||
);
|
);
|
||||||
if (_isAccessTokenUsable(
|
if (currentToken != null &&
|
||||||
|
currentToken.accessToken != null &&
|
||||||
|
currentToken.refreshToken != null &&
|
||||||
|
currentToken.expiryDate != null &&
|
||||||
|
_isAccessTokenUsable(
|
||||||
currentToken.expiryDate,
|
currentToken.expiryDate,
|
||||||
skew: const Duration(),
|
skew: const Duration(),
|
||||||
) &&
|
) &&
|
||||||
!initData.client!.needsReauth) {
|
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||||
await _sendTokenToWatchInternal(
|
await _sendTokenToWatchInternal(
|
||||||
currentToken,
|
currentToken,
|
||||||
allowExpiredAccessToken: true,
|
allowExpiredAccessToken: true,
|
||||||
@@ -1050,14 +1188,16 @@ class WatchSyncHelper {
|
|||||||
final watchUpdatedAtMs = _asInt(tokenData['updatedAtMs']);
|
final watchUpdatedAtMs = _asInt(tokenData['updatedAtMs']);
|
||||||
final watchIdToken = tokenData['idToken'] as String?;
|
final watchIdToken = tokenData['idToken'] as String?;
|
||||||
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
||||||
final shouldAccept = _isIncomingTokenNewerThanCurrent(
|
final shouldAccept = currentToken == null
|
||||||
incomingExpiry: watchExpiryDate,
|
? true
|
||||||
incomingIdToken: watchIdToken,
|
: _isIncomingTokenNewerThanCurrent(
|
||||||
incomingRefreshToken: watchRefreshToken,
|
incomingExpiry: watchExpiryDate,
|
||||||
incomingTokenVersion: watchTokenVersion,
|
incomingIdToken: watchIdToken,
|
||||||
incomingUpdatedAtMs: watchUpdatedAtMs,
|
incomingRefreshToken: watchRefreshToken,
|
||||||
currentToken: currentToken,
|
incomingTokenVersion: watchTokenVersion,
|
||||||
);
|
incomingUpdatedAtMs: watchUpdatedAtMs,
|
||||||
|
currentToken: currentToken,
|
||||||
|
);
|
||||||
if (shouldAccept) {
|
if (shouldAccept) {
|
||||||
debugPrint('[WatchSync] Watch has newer token, updating iPhone');
|
debugPrint('[WatchSync] Watch has newer token, updating iPhone');
|
||||||
final newToken = TokenModel.fromValues(
|
final newToken = TokenModel.fromValues(
|
||||||
@@ -1073,14 +1213,25 @@ class WatchSyncHelper {
|
|||||||
watchUpdatedAtMs ?? DateTime.now().millisecondsSinceEpoch,
|
watchUpdatedAtMs ?? DateTime.now().millisecondsSinceEpoch,
|
||||||
);
|
);
|
||||||
|
|
||||||
await isarInit.writeTxn(() async {
|
await effectiveIsar.writeTxn(() async {
|
||||||
await isarInit.tokenModels.put(newToken);
|
await effectiveIsar.tokenModels.put(newToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
initData.client!.cache.token = newToken;
|
final updatedTokens = await effectiveIsar.tokenModels.where().findAll();
|
||||||
|
|
||||||
if (newToken.key == expectedStudentIdNorm) {
|
if (initDone) {
|
||||||
if (initDone) initData.toastCubit.clear();
|
initData.tokens = updatedTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectiveClient != null &&
|
||||||
|
(expectedStudentIdNorm == null ||
|
||||||
|
newToken.studentIdNorm == expectedStudentIdNorm)) {
|
||||||
|
effectiveClient.model = newToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expectedStudentIdNorm == null ||
|
||||||
|
newToken.studentIdNorm == expectedStudentIdNorm) {
|
||||||
|
if (initDone) initData.reauthCubit?.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firka_common/data/database.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:isar_community/isar.dart';
|
||||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||||
|
|
||||||
import 'package:firka/api/client/kreta_client.dart';
|
import 'package:firka/api/client/kreta_client.dart';
|
||||||
import 'package:firka_common/data/models/token_model.dart';
|
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||||
|
import 'package:firka/data/models/app_settings_model.dart';
|
||||||
|
import 'package:firka/data/models/generic_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/homework_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/timetable_cache_model.dart';
|
||||||
|
import 'package:firka/data/models/token_model.dart';
|
||||||
import 'package:firka/services/wear_sync_cache.dart';
|
import 'package:firka/services/wear_sync_cache.dart';
|
||||||
|
|
||||||
/// Background isolate entrypoint for Wear sync (Android).
|
/// Background isolate entrypoint for Wear sync (Android).
|
||||||
@@ -25,12 +29,30 @@ void wearSyncBackgroundEntrypoint() {
|
|||||||
final appDirPath = args?['appDirPath'] as String?;
|
final appDirPath = args?['appDirPath'] as String?;
|
||||||
if (cachePath == null || appDirPath == null) return null;
|
if (cachePath == null || appDirPath == null) return null;
|
||||||
try {
|
try {
|
||||||
await initDB();
|
final isar = await Isar.open([
|
||||||
final tokens = await isarInit.tokenModels.where().findAll();
|
TokenModelSchema,
|
||||||
|
GenericCacheModelSchema,
|
||||||
|
TimetableCacheModelSchema,
|
||||||
|
HomeworkCacheModelSchema,
|
||||||
|
AppSettingsModelSchema,
|
||||||
|
HomeworkDoneModelSchema,
|
||||||
|
], directory: appDirPath);
|
||||||
|
final tokens = await isar.tokenModels.where().findAll();
|
||||||
|
await isar.close();
|
||||||
if (tokens.isEmpty) return null;
|
if (tokens.isEmpty) return null;
|
||||||
final token = tokens.first;
|
final token = tokens.first;
|
||||||
final client = KretaClient(token);
|
final isar2 = await Isar.open([
|
||||||
|
TokenModelSchema,
|
||||||
|
GenericCacheModelSchema,
|
||||||
|
TimetableCacheModelSchema,
|
||||||
|
HomeworkCacheModelSchema,
|
||||||
|
AppSettingsModelSchema,
|
||||||
|
HomeworkDoneModelSchema,
|
||||||
|
], directory: appDirPath);
|
||||||
|
final reauthCubit = ReauthCubit();
|
||||||
|
final client = KretaClient(token, isar2, reauthCubit);
|
||||||
final payload = await buildWearSyncPayload(client);
|
final payload = await buildWearSyncPayload(client);
|
||||||
|
await isar2.close();
|
||||||
if (payload == null) return null;
|
if (payload == null) return null;
|
||||||
await writeWearSyncCache(cachePath, payload);
|
await writeWearSyncCache(cachePath, payload);
|
||||||
final wc = WatchConnectivity();
|
final wc = WatchConnectivity();
|
||||||
|
|||||||
@@ -28,11 +28,25 @@ const String wearSyncCacheFileName = 'wear_sync_cache.json';
|
|||||||
/// Builds the sync payload (same shape as init_data / sync_data): timetable (2 weeks), grades, lastSyncAt.
|
/// Builds the sync payload (same shape as init_data / sync_data): timetable (2 weeks), grades, lastSyncAt.
|
||||||
Future<Map<String, dynamic>?> buildWearSyncPayload(KretaClient client) async {
|
Future<Map<String, dynamic>?> buildWearSyncPayload(KretaClient client) async {
|
||||||
final (start, end) = getWearSyncTimetableRange();
|
final (start, end) = getWearSyncTimetableRange();
|
||||||
await client.getLessons(start, end);
|
final timetableResp = await client.getTimeTable(
|
||||||
await client.getGrades();
|
start,
|
||||||
|
end,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
if (timetableResp.err != null && timetableResp.response == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final gradesResp = await client.getGrades(forceCache: false);
|
||||||
|
if (gradesResp.err != null && gradesResp.response == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final now = timeNow();
|
final now = timeNow();
|
||||||
final timetable = (<Lesson>[]).map((l) => l.toJson()).toList();
|
final timetable = (timetableResp.response ?? <Lesson>[])
|
||||||
final grades = (<Grade>[]).map((g) => g.toJson()).toList();
|
.map((l) => l.toJson())
|
||||||
|
.toList();
|
||||||
|
final grades = (gradesResp.response ?? <Grade>[])
|
||||||
|
.map((g) => g.toJson())
|
||||||
|
.toList();
|
||||||
return {
|
return {
|
||||||
'lastSyncAt': now.toUtc().toIso8601String(),
|
'lastSyncAt': now.toUtc().toIso8601String(),
|
||||||
'timetable': timetable,
|
'timetable': timetable,
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
import 'package:firka_common/core/consts.dart';
|
|
||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
import 'package:firka_common/core/grade_helper.dart';
|
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/test_cache_model.dart';
|
|
||||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
import 'package:firka_common/ui/shared/grade_small_card.dart';
|
import 'package:firka_common/ui/shared/grade_small_card.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:firka_common/data/models/homework_cache_model.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
import 'package:firka/data/models/homework_cache_model.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_html/flutter_html.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
@@ -27,8 +19,9 @@ import 'package:firka/ui/theme/style.dart';
|
|||||||
import 'package:firka/ui/phone/widgets/lesson.dart';
|
import 'package:firka/ui/phone/widgets/lesson.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:firka/ui/shared/class_icon.dart';
|
import 'package:firka/ui/shared/class_icon.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka_common/ui/components/grade.dart';
|
import 'package:firka/ui/components/grade.dart';
|
||||||
|
import 'package:firka/ui/components/grade_helpers.dart';
|
||||||
|
|
||||||
Future<void> showFirkaBottomSheet(
|
Future<void> showFirkaBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
@@ -52,30 +45,28 @@ Future<void> showFirkaBottomSheet(
|
|||||||
color: appStyle.colors.background,
|
color: appStyle.colors.background,
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||||
),
|
),
|
||||||
child: SelectionArea(
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: [
|
||||||
children: [
|
Align(
|
||||||
Align(
|
heightFactor: 0,
|
||||||
heightFactor: 0,
|
alignment: Alignment.topCenter,
|
||||||
alignment: Alignment.topCenter,
|
child: Container(
|
||||||
child: Container(
|
margin: EdgeInsets.only(top: 18),
|
||||||
margin: EdgeInsets.only(top: 18),
|
width: 40,
|
||||||
width: 40,
|
height: 4,
|
||||||
height: 4,
|
foregroundDecoration: ShapeDecoration(
|
||||||
foregroundDecoration: ShapeDecoration(
|
shape: RoundedRectangleBorder(
|
||||||
shape: RoundedRectangleBorder(
|
borderRadius: BorderRadiusGeometry.circular(2),
|
||||||
borderRadius: BorderRadiusGeometry.circular(2),
|
|
||||||
),
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
),
|
),
|
||||||
|
color: appStyle.colors.shadowColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 40),
|
),
|
||||||
...children,
|
SizedBox(height: 40),
|
||||||
],
|
...children,
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -87,14 +78,16 @@ Future<void> showFirkaBottomSheet(
|
|||||||
Future<void> showLessonBottomSheet(
|
Future<void> showLessonBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
LessonCacheModel lesson,
|
Lesson lesson,
|
||||||
Color accent,
|
Color accent,
|
||||||
Color secondary,
|
Color secondary,
|
||||||
Color bgColor,
|
Color bgColor,
|
||||||
|
Test? test,
|
||||||
) async {
|
) async {
|
||||||
// we dont like events
|
final statsForNerdsEnabled = data.settings
|
||||||
assert(lesson.type != TimetableConsts.event);
|
.group("settings")
|
||||||
final statsForNerdsEnabled = Settings.statsForNerds.value;
|
.subGroup("developer")
|
||||||
|
.boolean("stats_for_nerds");
|
||||||
|
|
||||||
Widget? statsForNerds;
|
Widget? statsForNerds;
|
||||||
|
|
||||||
@@ -103,8 +96,8 @@ Future<void> showLessonBottomSheet(
|
|||||||
if (statsForNerdsEnabled) {
|
if (statsForNerdsEnabled) {
|
||||||
final stats =
|
final stats =
|
||||||
"${data.l10n.stats_date}: ${lesson.start.isAfter(y2k) ? lesson.start.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
"${data.l10n.stats_date}: ${lesson.start.isAfter(y2k) ? lesson.start.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||||
"${data.l10n.stats_created_at}: ${lesson.createdAt.isAfter(y2k) ? lesson.createdAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n";
|
"${data.l10n.stats_created_at}: ${lesson.createdAt.isAfter(y2k) ? lesson.createdAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}\n"
|
||||||
//"${data.l10n.stats_last_mod}: ${lesson.lastModifiedAt.isAfter(y2k) ? lesson.lastModifiedAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}";
|
"${data.l10n.stats_last_mod}: ${lesson.lastModifiedAt.isAfter(y2k) ? lesson.lastModifiedAt.format(data.l10n, FormatMode.yyyymmddhhmmss) : "N/A"}";
|
||||||
statsForNerds = Text(
|
statsForNerds = Text(
|
||||||
stats,
|
stats,
|
||||||
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
||||||
@@ -113,62 +106,65 @@ Future<void> showLessonBottomSheet(
|
|||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
lesson.lessonNumber == null
|
||||||
width: 24,
|
? SizedBox()
|
||||||
height: 24,
|
: SizedBox(
|
||||||
child: Stack(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
SvgPicture.asset(
|
|
||||||
"assets/icons/subtract.svg",
|
|
||||||
color: bgColor,
|
|
||||||
width: 24,
|
width: 24,
|
||||||
height: 24,
|
height: 24,
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
"assets/icons/subtract.svg",
|
||||||
|
color: bgColor,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
lesson.lessonNumber!.toString(),
|
||||||
|
style: appStyle.fonts.B_16R.apply(color: secondary),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Text(
|
|
||||||
lesson.dailyNth.toString(),
|
|
||||||
style: appStyle.fonts.B_16R.apply(color: secondary),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FilledCircle(
|
FilledCircle(
|
||||||
diameter: 40,
|
diameter: 40,
|
||||||
color: bgColor,
|
color: bgColor,
|
||||||
child: ClassIconWidget(
|
child: ClassIconWidget.subject(
|
||||||
subject: lesson.subject.loadAndGet()!,
|
subject: lesson.subject!,
|
||||||
color: accent,
|
color: accent,
|
||||||
size: 26,
|
size: 26,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 6),
|
SizedBox(width: 6),
|
||||||
Card(
|
if (lesson.roomName != null)
|
||||||
shadowColor: Colors.transparent,
|
Card(
|
||||||
color: appStyle.colors.a15p,
|
shadowColor: Colors.transparent,
|
||||||
margin: EdgeInsets.all(0),
|
color: appStyle.colors.a15p,
|
||||||
shape: RoundedRectangleBorder(
|
margin: EdgeInsets.all(0),
|
||||||
borderRadius: BorderRadius.circular(10),
|
shape: RoundedRectangleBorder(
|
||||||
),
|
borderRadius: BorderRadius.circular(10),
|
||||||
child: Padding(
|
),
|
||||||
padding: EdgeInsets.symmetric(horizontal: 6),
|
child: Padding(
|
||||||
child: Text(
|
padding: EdgeInsets.symmetric(horizontal: 6),
|
||||||
lesson.roomName!,
|
child: Text(
|
||||||
style: appStyle.fonts.B_14R.apply(
|
lesson.roomName!,
|
||||||
color: appStyle.colors.secondary,
|
style: appStyle.fonts.B_14R.apply(
|
||||||
|
color: appStyle.colors.secondary,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"${lesson.name} ${statsForNerdsEnabled ? "(${lesson.subject.loadAndGet()!.name})" : ""}",
|
"${lesson.name} ${statsForNerdsEnabled ? "(${lesson.classGroup?.name ?? ''})" : ""}",
|
||||||
style: appStyle.fonts.H_18px.apply(
|
style: appStyle.fonts.H_18px.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -177,7 +173,7 @@ Future<void> showLessonBottomSheet(
|
|||||||
),
|
),
|
||||||
SizedBox(height: 2),
|
SizedBox(height: 2),
|
||||||
Text(
|
Text(
|
||||||
lesson.teacher!,
|
lesson.teacher ?? 'N/A',
|
||||||
style: appStyle.fonts.B_14R.apply(
|
style: appStyle.fonts.B_14R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
decoration: lesson.substituteTeacher != null
|
decoration: lesson.substituteTeacher != null
|
||||||
@@ -212,7 +208,7 @@ Future<void> showLessonBottomSheet(
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: MediaQuery.of(context).size.width * 0.7,
|
width: MediaQuery.of(context).size.width * 0.7,
|
||||||
child: Text(
|
child: Text(
|
||||||
lesson.topic ?? 'N/A',
|
lesson.theme ?? 'N/A',
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -226,8 +222,7 @@ Future<void> showLessonBottomSheet(
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 6),
|
SizedBox(height: 6),
|
||||||
if (lesson.test.loadAndGet() != null)
|
if (test != null) InfoCard.testDesc(test),
|
||||||
InfoCard.testDesc(lesson.test.loadAndGet()!),
|
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
child: FirkaCard(
|
child: FirkaCard(
|
||||||
@@ -254,11 +249,11 @@ Future<void> showOmissionBottomSheet(
|
|||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
String description,
|
String description,
|
||||||
List<OmissionCacheModel> omissions,
|
List<Omission> omissions,
|
||||||
) async {
|
) async {
|
||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
Text(
|
Text(
|
||||||
omissions.first.createdAt.format(data.l10n, FormatMode.yyyymmdd),
|
omissions.first.date.format(data.l10n, FormatMode.yyyymmdd),
|
||||||
style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary),
|
style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary),
|
||||||
),
|
),
|
||||||
SizedBox(height: 2),
|
SizedBox(height: 2),
|
||||||
@@ -269,14 +264,94 @@ Future<void> showOmissionBottomSheet(
|
|||||||
SizedBox(height: 2),
|
SizedBox(height: 2),
|
||||||
LimitedBox(
|
LimitedBox(
|
||||||
maxHeight: 336,
|
maxHeight: 336,
|
||||||
child: ListView.separated(
|
child: ListView.builder(
|
||||||
itemCount: omissions.length,
|
itemCount: omissions.length,
|
||||||
separatorBuilder: (ctx, i) {
|
|
||||||
return const SizedBox(height: 10);
|
|
||||||
},
|
|
||||||
itemBuilder: (b, i) {
|
itemBuilder: (b, i) {
|
||||||
final o = omissions[i];
|
final o = omissions[i];
|
||||||
return LessonWidget(data, o.lesson.loadAndGet()!);
|
return FirkaCard.single(
|
||||||
|
height: 64,
|
||||||
|
margin: EdgeInsets.only(bottom: 10),
|
||||||
|
padding: EdgeInsets.only(left: 14, right: 16),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
"assets/icons/subtract.svg",
|
||||||
|
color: appStyle.colors.a15p,
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
o.lesson!.classNo?.toString() ?? "-",
|
||||||
|
style: appStyle.fonts.B_14SB.apply(
|
||||||
|
color: appStyle.colors.secondary,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
FilledCircle(
|
||||||
|
diameter: 36,
|
||||||
|
color: appStyle.colors.a15p,
|
||||||
|
child: ClassIconWidget(
|
||||||
|
uid: o.subject.uid,
|
||||||
|
className: o.subject.name,
|
||||||
|
category: o.subject.name,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
o.subject.name,
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
o.teacher,
|
||||||
|
style: appStyle.fonts.B_14R.apply(
|
||||||
|
color: appStyle.colors.textSecondary,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
o.lesson!.start.format(data.l10n, FormatMode.hmm),
|
||||||
|
style: appStyle.fonts.B_14R.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
o.lesson!.end.format(data.l10n, FormatMode.hmm),
|
||||||
|
style: appStyle.fonts.B_14R.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -286,11 +361,9 @@ Future<void> showOmissionBottomSheet(
|
|||||||
Future<void> showTestBottomSheet(
|
Future<void> showTestBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
TestCacheModel test,
|
Test test,
|
||||||
) async {
|
) async {
|
||||||
final lesson = test.lesson.loadAndGet()!;
|
final date = test.date;
|
||||||
final subject = lesson.subject.loadAndGet()!;
|
|
||||||
final date = lesson.start;
|
|
||||||
final formattedDate =
|
final formattedDate =
|
||||||
"${date.format(data.l10n, FormatMode.yearly).firstUpper()}, ${DateFormat.EEEE(data.l10n.localeName).format(date).firstUpper()}";
|
"${date.format(data.l10n, FormatMode.yearly).firstUpper()}, ${DateFormat.EEEE(data.l10n.localeName).format(date).firstUpper()}";
|
||||||
|
|
||||||
@@ -312,13 +385,13 @@ Future<void> showTestBottomSheet(
|
|||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
test.topic ?? test.method,
|
"${test.theme}",
|
||||||
style: appStyle.fonts.H_18px.apply(
|
style: appStyle.fonts.H_18px.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
test.method,
|
test.method.description,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
@@ -365,7 +438,7 @@ Future<void> showTestBottomSheet(
|
|||||||
height: 18,
|
height: 18,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
lesson.dailyNth.toString(),
|
test.lessonNumber.toString(),
|
||||||
style: appStyle.fonts.B_14SB.apply(
|
style: appStyle.fonts.B_14SB.apply(
|
||||||
color: appStyle.colors.secondary,
|
color: appStyle.colors.secondary,
|
||||||
),
|
),
|
||||||
@@ -378,7 +451,9 @@ Future<void> showTestBottomSheet(
|
|||||||
diameter: 36,
|
diameter: 36,
|
||||||
color: appStyle.colors.a15p,
|
color: appStyle.colors.a15p,
|
||||||
child: ClassIconWidget(
|
child: ClassIconWidget(
|
||||||
subject: subject,
|
uid: test.uid,
|
||||||
|
className: test.subjectName,
|
||||||
|
category: test.subject.name,
|
||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 24,
|
size: 24,
|
||||||
),
|
),
|
||||||
@@ -386,7 +461,7 @@ Future<void> showTestBottomSheet(
|
|||||||
SizedBox(width: 12),
|
SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
subject.name,
|
test.subject.name,
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -402,7 +477,7 @@ Future<void> showTestBottomSheet(
|
|||||||
Future<void> showGradeBottomSheet(
|
Future<void> showGradeBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
GradeCacheModel grade,
|
Grade grade,
|
||||||
) async {
|
) async {
|
||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
grade.numericValue == null
|
grade.numericValue == null
|
||||||
@@ -419,7 +494,7 @@ Future<void> showGradeBottomSheet(
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
grade.textValue,
|
grade.strValue,
|
||||||
style: appStyle.fonts.H_18px.apply(
|
style: appStyle.fonts.H_18px.apply(
|
||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
),
|
),
|
||||||
@@ -430,12 +505,12 @@ Future<void> showGradeBottomSheet(
|
|||||||
: GradeWidget(grade, size: 40),
|
: GradeWidget(grade, size: 40),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
(grade.topic ?? grade.type).firstUpper(),
|
(grade.topic ?? grade.type.description).firstUpper(),
|
||||||
style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary),
|
style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary),
|
||||||
),
|
),
|
||||||
grade.mode != null
|
grade.mode != null
|
||||||
? Text(
|
? Text(
|
||||||
grade.mode!,
|
grade.mode!.description,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
@@ -443,11 +518,11 @@ Future<void> showGradeBottomSheet(
|
|||||||
: SizedBox(),
|
: SizedBox(),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
grade.writtenAt.format(data.l10n, FormatMode.yyyymmdd),
|
grade.recordDate.format(data.l10n, FormatMode.yyyymmdd),
|
||||||
style: appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary),
|
style: appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
GradeSmallCard(null, null, grade.subject.loadAndGet()!),
|
GradeSmallCard([], null, grade.subject),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
FirkaCard(
|
FirkaCard(
|
||||||
margin: EdgeInsets.all(0),
|
margin: EdgeInsets.all(0),
|
||||||
@@ -456,13 +531,13 @@ Future<void> showGradeBottomSheet(
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"${data.l10n.grade_teacherName}${grade.teacherName}",
|
"${data.l10n.grade_teacherName}${grade.teacher}",
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"${data.l10n.tt_added}${grade.createdAt.format(data.l10n, FormatMode.yyyymmdd)}",
|
"${data.l10n.tt_added}${grade.creationDate.format(data.l10n, FormatMode.yyyymmdd)}",
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -487,7 +562,7 @@ Future<void> showGradeBottomSheet(
|
|||||||
color: appStyle.colors.buttonSecondaryFill,
|
color: appStyle.colors.buttonSecondaryFill,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.go('/grades/subject', extra: grade.subject.loadAndGet());
|
context.go('/grades/subject', extra: grade.subject);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
@@ -496,9 +571,8 @@ Future<void> showGradeBottomSheet(
|
|||||||
Future<void> showHomeworkBottomSheet(
|
Future<void> showHomeworkBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
HomeworkCacheModel homework,
|
Homework homework,
|
||||||
) async {
|
) async {
|
||||||
final subject = homework.subject.loadAndGet()!;
|
|
||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
Text(
|
Text(
|
||||||
data.l10n.homework,
|
data.l10n.homework,
|
||||||
@@ -510,7 +584,7 @@ Future<void> showHomeworkBottomSheet(
|
|||||||
style: appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary),
|
style: appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
GradeSmallCard(null, null, subject),
|
GradeSmallCard([], null, homework.subject),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Flexible(
|
Flexible(
|
||||||
fit: FlexFit.loose,
|
fit: FlexFit.loose,
|
||||||
@@ -518,7 +592,7 @@ Future<void> showHomeworkBottomSheet(
|
|||||||
margin: EdgeInsets.all(0),
|
margin: EdgeInsets.all(0),
|
||||||
padding: EdgeInsets.all(12),
|
padding: EdgeInsets.all(12),
|
||||||
child: Html(
|
child: Html(
|
||||||
data: homework.description.withoutFontFeatureSettings(),
|
data: homework.description,
|
||||||
style: {
|
style: {
|
||||||
"*": Style.fromTextStyle(
|
"*": Style.fromTextStyle(
|
||||||
appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
||||||
@@ -528,34 +602,42 @@ Future<void> showHomeworkBottomSheet(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Column(
|
FutureBuilder<bool>(
|
||||||
children: [
|
future: isHomeworkDone(data.isar, homework.uid),
|
||||||
GestureDetector(
|
builder: (context, snapshot) {
|
||||||
child: FirkaCard(
|
if (!snapshot.hasData) {
|
||||||
margin: EdgeInsets.all(0),
|
return SizedBox(); // or a loading indicator
|
||||||
left: [],
|
}
|
||||||
center: [
|
|
||||||
Text(
|
final done = snapshot.data!;
|
||||||
!homework.isDone
|
|
||||||
? data.l10n.mark_as_done
|
return Column(
|
||||||
: data.l10n.mark_as_not_done,
|
children: [
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
GestureDetector(
|
||||||
color: appStyle.colors.textPrimaryLight,
|
child: FirkaCard(
|
||||||
),
|
margin: EdgeInsets.all(0),
|
||||||
|
left: [],
|
||||||
|
center: [
|
||||||
|
Text(
|
||||||
|
!done ? data.l10n.mark_as_done : data.l10n.mark_as_not_done,
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimaryLight,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
color: appStyle.colors.accent,
|
||||||
),
|
),
|
||||||
],
|
onTap: () {
|
||||||
color: appStyle.colors.accent,
|
context.read<HomeRefreshCubit>().requestRefresh();
|
||||||
),
|
Navigator.pop(context);
|
||||||
onTap: () {
|
!done
|
||||||
data.isar.writeTxnSync(() {
|
? markAsDone(data.isar, homework.uid)
|
||||||
homework.isDone = true;
|
: markAsNotDone(data.isar, homework.uid);
|
||||||
data.isar.homeworkCacheModels.putSync(homework);
|
},
|
||||||
});
|
),
|
||||||
context.read<HomeRefreshCubit>().requestRefresh();
|
],
|
||||||
Navigator.pop(context);
|
);
|
||||||
},
|
},
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
@@ -573,7 +655,7 @@ Future<void> showHomeworkBottomSheet(
|
|||||||
color: appStyle.colors.buttonSecondaryFill,
|
color: appStyle.colors.buttonSecondaryFill,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.go('/home/subject', extra: subject);
|
context.go('/home/subject', extra: homework.subject);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
@@ -582,7 +664,7 @@ Future<void> showHomeworkBottomSheet(
|
|||||||
Future<void> showGradeCalculatorBottomSheet(
|
Future<void> showGradeCalculatorBottomSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
SubjectCacheModel subject, {
|
Subject subject, {
|
||||||
void Function(int grade, int weight)? onAdd,
|
void Function(int grade, int weight)? onAdd,
|
||||||
}) async {
|
}) async {
|
||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
@@ -592,7 +674,7 @@ Future<void> showGradeCalculatorBottomSheet(
|
|||||||
|
|
||||||
class _GradeCalculatorSheetContent extends StatefulWidget {
|
class _GradeCalculatorSheetContent extends StatefulWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
final SubjectCacheModel subject;
|
final Subject subject;
|
||||||
final void Function(int grade, int weight)? onAdd;
|
final void Function(int grade, int weight)? onAdd;
|
||||||
|
|
||||||
const _GradeCalculatorSheetContent({
|
const _GradeCalculatorSheetContent({
|
||||||
@@ -726,7 +808,7 @@ class _GradeCalculatorSheetContentState
|
|||||||
min: 0,
|
min: 0,
|
||||||
max: (_snapPoints.length - 1).toDouble(),
|
max: (_snapPoints.length - 1).toDouble(),
|
||||||
divisions: _snapPoints.length - 1,
|
divisions: _snapPoints.length - 1,
|
||||||
label: '$weightPercent%',
|
label: '${weightPercent}%',
|
||||||
onChanged: (v) => setState(() => weightIndex = v.round()),
|
onChanged: (v) => setState(() => weightIndex = v.round()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -780,7 +862,7 @@ class _GradeCalculatorSheetContentState
|
|||||||
Future<void> showSubjectBottomSheetSettings(
|
Future<void> showSubjectBottomSheetSettings(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
SubjectCacheModel subject, {
|
Subject subject, {
|
||||||
void Function(int grade, int weight)? onAddFromCalculator,
|
void Function(int grade, int weight)? onAddFromCalculator,
|
||||||
}) async {
|
}) async {
|
||||||
showFirkaBottomSheet(context, [
|
showFirkaBottomSheet(context, [
|
||||||
|
|||||||
1
firka/lib/ui/components/firka_card.dart
Normal file
1
firka/lib/ui/components/firka_card.dart
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export 'package:firka_common/ui/components/firka_card.dart';
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
|
|
||||||
class FirkaIconButton extends StatelessWidget {
|
|
||||||
final Widget child;
|
|
||||||
final VoidCallback? onTap;
|
|
||||||
final Color? color;
|
|
||||||
|
|
||||||
const FirkaIconButton({
|
|
||||||
required this.child,
|
|
||||||
this.onTap,
|
|
||||||
this.color,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final button = Container(
|
|
||||||
width: 32,
|
|
||||||
height: 32,
|
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: color ?? appStyle.colors.buttonSecondaryFill,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
blurRadius: appStyle.colors.shadowBlur.toDouble(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (onTap == null) return button;
|
|
||||||
|
|
||||||
return GestureDetector(onTap: onTap, child: button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
firka/lib/ui/components/firka_shadow.dart
Normal file
1
firka/lib/ui/components/firka_shadow.dart
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export 'package:firka_common/ui/components/firka_shadow.dart';
|
||||||
0
firka/lib/ui/components/firka_webview.dart
Normal file
0
firka/lib/ui/components/firka_webview.dart
Normal file
1
firka/lib/ui/components/grade.dart
Normal file
1
firka/lib/ui/components/grade.dart
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export 'package:firka_common/ui/components/grade.dart';
|
||||||
1
firka/lib/ui/components/grade_helpers.dart
Normal file
1
firka/lib/ui/components/grade_helpers.dart
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export 'package:firka_common/ui/components/grade_helpers.dart';
|
||||||
@@ -1,47 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
|
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||||
import 'package:firka/core/settings.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/data/models/app_settings_model.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
import 'package:firka/ui/components/firka_shadow.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
Widget _extrasActionTile({
|
|
||||||
required double width,
|
|
||||||
required VoidCallback onTap,
|
|
||||||
required Widget icon,
|
|
||||||
required String label,
|
|
||||||
}) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: FirkaCard.single(
|
|
||||||
width: width,
|
|
||||||
height: 60,
|
|
||||||
margin: EdgeInsets.zero,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
icon,
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Flexible(
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
textAlign: TextAlign.right,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
||||||
Widget Function(double) debugBtn = (_) => const SizedBox();
|
Widget Function(double) debugBtn = (_) => const SizedBox();
|
||||||
@@ -49,20 +17,49 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
|||||||
logger.finest("showExtrasBottomSheet() developer mode: ${isDeveloper()}");
|
logger.finest("showExtrasBottomSheet() developer mode: ${isDeveloper()}");
|
||||||
|
|
||||||
if (isDeveloper()) {
|
if (isDeveloper()) {
|
||||||
debugBtn = (double itemWidth) => _extrasActionTile(
|
debugBtn = (double itemWidth) => GestureDetector(
|
||||||
// Fejlesztői menü
|
// Fejlesztői menü
|
||||||
width: itemWidth,
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
context.push('/debug');
|
context.push('/debug');
|
||||||
},
|
},
|
||||||
icon: FirkaIconWidget(
|
child: SizedBox(
|
||||||
FirkaIconType.majesticons,
|
height: 60,
|
||||||
Majesticon.bug2Solid,
|
width: itemWidth,
|
||||||
size: 22.0,
|
child: FirkaShadow(
|
||||||
color: appStyle.colors.accent,
|
shadow: true,
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.card,
|
||||||
|
shadowColor: context.watch<ThemeCubit>().state.isLightMode
|
||||||
|
? null
|
||||||
|
: Colors.transparent,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.bug2Solid,
|
||||||
|
size: 22.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
data.l10n.debug_screen,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
style: appStyle.fonts.B_16R.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
label: data.l10n.debug_screen,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,44 +112,120 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
|||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
final itemWidth = (constraints.maxWidth - 8) / 2;
|
final itemWidth = (constraints.maxWidth - 8) / 2;
|
||||||
return Wrap(
|
return Wrap(
|
||||||
spacing: 8,
|
spacing: 2,
|
||||||
runSpacing: 8,
|
runSpacing: 2,
|
||||||
children: [
|
children: [
|
||||||
debugBtn(itemWidth),
|
debugBtn(itemWidth),
|
||||||
_extrasActionTile(
|
GestureDetector(
|
||||||
// Fiókod
|
// Fiókod
|
||||||
width: itemWidth,
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
context.push(
|
context.push(
|
||||||
'/settings',
|
'/settings',
|
||||||
extra: buildProfileSettingsTree(
|
extra: data.settings.items.group(
|
||||||
data.l10n,
|
"profile_settings",
|
||||||
).children,
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: FirkaIconWidget(
|
child: SizedBox(
|
||||||
FirkaIconType.majesticons,
|
height: 60,
|
||||||
Majesticon.userSolid,
|
width: itemWidth,
|
||||||
size: 22.0,
|
child: FirkaShadow(
|
||||||
color: appStyle.colors.accent,
|
shadow: true,
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.card,
|
||||||
|
shadowColor:
|
||||||
|
context
|
||||||
|
.watch<ThemeCubit>()
|
||||||
|
.state
|
||||||
|
.isLightMode
|
||||||
|
? null
|
||||||
|
: Colors.transparent,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12.0,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.userSolid,
|
||||||
|
size: 22.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
data.l10n.s_your_account,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
style: appStyle.fonts.B_16R
|
||||||
|
.apply(
|
||||||
|
color: appStyle
|
||||||
|
.colors
|
||||||
|
.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
label: data.l10n.s_your_account,
|
|
||||||
),
|
),
|
||||||
_extrasActionTile(
|
GestureDetector(
|
||||||
// Beállítás
|
// Beállítás
|
||||||
width: itemWidth,
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
context.push('/settings');
|
context.push('/settings');
|
||||||
},
|
},
|
||||||
icon: FirkaIconWidget(
|
child: SizedBox(
|
||||||
FirkaIconType.majesticons,
|
height: 60,
|
||||||
Majesticon.settingsCogSolid,
|
width: itemWidth,
|
||||||
size: 22.0,
|
child: FirkaShadow(
|
||||||
color: appStyle.colors.accent,
|
shadow: true,
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.card,
|
||||||
|
shadowColor:
|
||||||
|
context
|
||||||
|
.watch<ThemeCubit>()
|
||||||
|
.state
|
||||||
|
.isLightMode
|
||||||
|
? null
|
||||||
|
: Colors.transparent,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12.0,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.settingsCogSolid,
|
||||||
|
size: 22.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
data.l10n.settings_screen,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
style: appStyle.fonts.B_16R
|
||||||
|
.apply(
|
||||||
|
color: appStyle
|
||||||
|
.colors
|
||||||
|
.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
label: data.l10n.settings_screen,
|
|
||||||
),
|
),
|
||||||
// Ide jön a többi gomb majd
|
// Ide jön a többi gomb majd
|
||||||
],
|
],
|
||||||
@@ -179,9 +252,24 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
|||||||
if (debugCounter == 10) {
|
if (debugCounter == 10) {
|
||||||
final navigator = Navigator.of(context);
|
final navigator = Navigator.of(context);
|
||||||
final router = GoRouter.of(context);
|
final router = GoRouter.of(context);
|
||||||
await Settings.developerOptsEnabled.set(
|
data.settings
|
||||||
!Settings.developerOptsEnabled.value,
|
.group("settings")
|
||||||
);
|
.setBoolean(
|
||||||
|
"developer_enabled",
|
||||||
|
!data.settings
|
||||||
|
.group("settings")
|
||||||
|
.boolean("developer_enabled"),
|
||||||
|
);
|
||||||
|
|
||||||
|
await data.isar.writeTxn(() async {
|
||||||
|
await data.settings
|
||||||
|
.group("settings")["developer_enabled"]!
|
||||||
|
.save(data.isar.appSettingsModels);
|
||||||
|
});
|
||||||
|
|
||||||
|
await data.settings
|
||||||
|
.group("settings")["developer_enabled"]!
|
||||||
|
.postUpdate();
|
||||||
|
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
router.go('/home');
|
router.go('/home');
|
||||||
|
|||||||
@@ -1,152 +0,0 @@
|
|||||||
import 'package:firka/app/app_state.dart';
|
|
||||||
import 'package:firka/ui/phone/pages/extras/main_error.dart';
|
|
||||||
import 'package:firka/ui/theme/style.dart';
|
|
||||||
import 'package:firka/ui/phone/pages/extras/main_reauth.dart';
|
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
|
||||||
|
|
||||||
class FirkaToastWidget extends StatefulWidget {
|
|
||||||
final Function()? onTap;
|
|
||||||
final Function()? onDismiss;
|
|
||||||
final List<Widget> children;
|
|
||||||
final Color backgroundColor;
|
|
||||||
|
|
||||||
const FirkaToastWidget({
|
|
||||||
super.key,
|
|
||||||
required this.backgroundColor,
|
|
||||||
this.onTap,
|
|
||||||
this.onDismiss,
|
|
||||||
required this.children,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory FirkaToastWidget.fetching(BuildContext context) {
|
|
||||||
return FirkaToastWidget(
|
|
||||||
backgroundColor: appStyle.colors.card,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(color: appStyle.colors.accent),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
initData.l10n.refreshing,
|
|
||||||
style: appStyle.fonts.B_16SB.copyWith(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
factory FirkaToastWidget.error(BuildContext context, Object e) {
|
|
||||||
return FirkaToastWidget(
|
|
||||||
backgroundColor: appStyle.colors.errorCard,
|
|
||||||
onDismiss: () {
|
|
||||||
initData.toastCubit.clear();
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
initData.l10n.api_error,
|
|
||||||
style: appStyle.fonts.B_16SB.copyWith(
|
|
||||||
color: appStyle.colors.errorText,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
GestureDetector(
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.questionCircleSolid,
|
|
||||||
color: appStyle.colors.errorAccent,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
showErrorBottomSheet(
|
|
||||||
context,
|
|
||||||
"$e\n${e is Error ? e.stackTrace ?? '' : ''}",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
factory FirkaToastWidget.reauth(BuildContext context) {
|
|
||||||
return FirkaToastWidget(
|
|
||||||
backgroundColor: appStyle.colors.errorCard,
|
|
||||||
onTap: () {
|
|
||||||
showReauthBottomSheet(context, initData, initData.l10n.reauth);
|
|
||||||
},
|
|
||||||
onDismiss: () {
|
|
||||||
initData.toastCubit.clear();
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
initData.l10n.reauth,
|
|
||||||
style: appStyle.fonts.B_16SB.copyWith(
|
|
||||||
color: appStyle.colors.errorText,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.loginSolid,
|
|
||||||
color: appStyle.colors.errorAccent,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<FirkaToastWidget> createState() => _FirkaToastWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FirkaToastWidgetState extends State<FirkaToastWidget> {
|
|
||||||
double _dragOffset = 0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Positioned(
|
|
||||||
top: MediaQuery.of(context).size.height / 1.6 + _dragOffset,
|
|
||||||
left: 0.0,
|
|
||||||
right: 0.0,
|
|
||||||
bottom: 0,
|
|
||||||
child: Center(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: widget.onTap,
|
|
||||||
onVerticalDragUpdate: (details) {
|
|
||||||
setState(() {
|
|
||||||
if (widget.onDismiss != null) _dragOffset += details.delta.dy;
|
|
||||||
if (_dragOffset < 0) _dragOffset = 0;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onVerticalDragEnd: (details) {
|
|
||||||
if (_dragOffset > 50) {
|
|
||||||
widget.onDismiss!();
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
_dragOffset = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Card(
|
|
||||||
color: appStyle.colors.errorCard,
|
|
||||||
shadowColor: Colors.transparent,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: widget.children,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,9 +31,7 @@ void showErrorBottomSheet(BuildContext context, String err) {
|
|||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: SelectionArea(
|
child: Center(child: Text(err, style: appStyle.fonts.B_16R)),
|
||||||
child: Center(child: Text(err, style: appStyle.fonts.B_16R)),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka/ui/phone/widgets/login_webview.dart';
|
import 'package:firka/ui/phone/widgets/login_webview.dart';
|
||||||
@@ -8,6 +9,18 @@ void showReauthBottomSheet(
|
|||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
String message,
|
String message,
|
||||||
) {
|
) {
|
||||||
|
final accountPicker =
|
||||||
|
(data.settings.group("profile_settings")["e_kreta_account_picker"]
|
||||||
|
as SettingsKretenAccountPicker);
|
||||||
|
|
||||||
|
final currentToken =
|
||||||
|
data.tokens.isNotEmpty && accountPicker.accountIndex < data.tokens.length
|
||||||
|
? data.tokens[accountPicker.accountIndex]
|
||||||
|
: null;
|
||||||
|
|
||||||
|
final username = currentToken?.studentId;
|
||||||
|
final schoolId = currentToken?.iss;
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
elevation: 100,
|
elevation: 100,
|
||||||
@@ -41,8 +54,8 @@ void showReauthBottomSheet(
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: LoginWebviewWidget(
|
child: LoginWebviewWidget(
|
||||||
data,
|
data,
|
||||||
username: data.client!.cache.token.username,
|
username: username,
|
||||||
schoolId: data.client!.cache.token.iss,
|
schoolId: schoolId,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:firka/services/wear_sync_cache.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|
||||||
void showWearBottomSheet(
|
void showWearBottomSheet(
|
||||||
@@ -12,7 +12,7 @@ void showWearBottomSheet(
|
|||||||
AppInitialization data,
|
AppInitialization data,
|
||||||
String model,
|
String model,
|
||||||
) async {
|
) async {
|
||||||
final payload = await buildWearSyncPayload(data.client!);
|
final payload = await buildWearSyncPayload(data.client);
|
||||||
if (payload == null) return;
|
if (payload == null) return;
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
@@ -66,17 +66,17 @@ class _WearPairSheetContentState extends State<_WearPairSheetContent> {
|
|||||||
|
|
||||||
void _onPairTap() {
|
void _onPairTap() {
|
||||||
setState(() => _syncing = true);
|
setState(() => _syncing = true);
|
||||||
final m = widget.data.client!.cache.token;
|
final m = widget.data.client.model;
|
||||||
WatchSyncHelper.sendMessageToWatch({
|
WatchSyncHelper.sendMessageToWatch({
|
||||||
'id': 'init_data',
|
'id': 'init_data',
|
||||||
'auth': {
|
'auth': {
|
||||||
'studentId': m.username,
|
'studentId': m.studentId,
|
||||||
'studentIdNorm': m.key,
|
'studentIdNorm': m.studentIdNorm,
|
||||||
'iss': m.iss,
|
'iss': m.iss,
|
||||||
'idToken': m.idToken,
|
'idToken': m.idToken,
|
||||||
'accessToken': m.accessToken,
|
'accessToken': m.accessToken,
|
||||||
'refreshToken': m.refreshToken,
|
'refreshToken': m.refreshToken,
|
||||||
'expiryDate': m.expiryDate.millisecondsSinceEpoch,
|
'expiryDate': m.expiryDate!.millisecondsSinceEpoch,
|
||||||
},
|
},
|
||||||
'lastSyncAt': widget.payload['lastSyncAt'],
|
'lastSyncAt': widget.payload['lastSyncAt'],
|
||||||
'timetable': widget.payload['timetable'],
|
'timetable': widget.payload['timetable'],
|
||||||
|
|||||||
96
firka/lib/ui/phone/pages/extras/reauth_toast.dart
Normal file
96
firka/lib/ui/phone/pages/extras/reauth_toast.dart
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import 'package:firka/app/app_state.dart';
|
||||||
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/phone/pages/extras/main_reauth.dart';
|
||||||
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
|
class ReauthToastWidget extends StatefulWidget {
|
||||||
|
final AppInitialization data;
|
||||||
|
final Function() onDismiss;
|
||||||
|
|
||||||
|
const ReauthToastWidget({
|
||||||
|
super.key,
|
||||||
|
required this.data,
|
||||||
|
required this.onDismiss,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ReauthToastWidget> createState() => _ReauthToastWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ReauthToastWidgetState extends State<ReauthToastWidget> {
|
||||||
|
double _dragOffset = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Positioned(
|
||||||
|
top: MediaQuery.of(context).size.height / 1.6 + _dragOffset,
|
||||||
|
left: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
bottom: 0,
|
||||||
|
child: Center(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
showReauthBottomSheet(
|
||||||
|
context,
|
||||||
|
widget.data,
|
||||||
|
widget.data.l10n.reauth,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onVerticalDragUpdate: (details) {
|
||||||
|
setState(() {
|
||||||
|
_dragOffset += details.delta.dy;
|
||||||
|
if (_dragOffset < 0) _dragOffset = 0;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onVerticalDragEnd: (details) {
|
||||||
|
if (_dragOffset > 50) {
|
||||||
|
widget.onDismiss();
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_dragOffset = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.errorCard,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(200)),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
widget.data.l10n.reauth,
|
||||||
|
style: appStyle.fonts.B_16SB.copyWith(
|
||||||
|
color: appStyle.colors.errorText,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.loginSolid,
|
||||||
|
color: appStyle.colors.errorAccent,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildReauthToast(
|
||||||
|
BuildContext context,
|
||||||
|
AppInitialization data,
|
||||||
|
Function() onDismiss,
|
||||||
|
) {
|
||||||
|
return ReauthToastWidget(data: data, onDismiss: onDismiss);
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
import 'dart:collection';
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka_common/core/grade_helper.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
|
import 'package:firka/ui/components/grade_helpers.dart';
|
||||||
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
||||||
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||||
import 'package:firka/ui/shared/grade_small_card.dart';
|
import 'package:firka/ui/shared/grade_small_card.dart';
|
||||||
@@ -10,10 +11,14 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import 'package:firka/api/consts.dart';
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
|
|
||||||
class HomeGradesScreen extends StatefulWidget {
|
class HomeGradesScreen extends StatefulWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
@@ -25,230 +30,297 @@ class HomeGradesScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||||
|
ApiResponse<List<Grade>>? grades;
|
||||||
|
ApiResponse<List<Lesson>>? week;
|
||||||
|
ApiResponse<List<ClassGroup>>? classGroups;
|
||||||
|
ApiResponse<List<SubjectAverage>>? lessons;
|
||||||
|
ApiResponse<List<ClassGroupSubjectAverage>>? classAvgs;
|
||||||
|
|
||||||
|
void _onRefreshRequested(BuildContext context) async {
|
||||||
|
final cubit = context.read<HomeRefreshCubit>();
|
||||||
|
var now = timeNow();
|
||||||
|
var start = now.subtract(Duration(days: now.weekday - 1));
|
||||||
|
var end = start.add(Duration(days: 6));
|
||||||
|
|
||||||
|
grades = await widget.data.client.getGrades(forceCache: false);
|
||||||
|
week = await widget.data.client.getTimeTable(start, end, forceCache: false);
|
||||||
|
classGroups = await widget.data.client.getClassGroups(forceCache: false);
|
||||||
|
if (classGroups?.response?.isNotEmpty ?? false) {
|
||||||
|
var group = classGroups!.response!.first;
|
||||||
|
lessons = await widget.data.client.getSubjectAverage(
|
||||||
|
group,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
classAvgs = await widget.data.client.getClassGroupAverages(
|
||||||
|
group,
|
||||||
|
forceCache: false,
|
||||||
|
);
|
||||||
|
await Future.delayed(Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
cubit.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
(() async {
|
||||||
|
var now = timeNow();
|
||||||
|
var start = now.subtract(Duration(days: now.weekday - 1));
|
||||||
|
var end = start.add(Duration(days: 6));
|
||||||
|
|
||||||
|
grades = await widget.data.client.getGrades();
|
||||||
|
week = await widget.data.client.getTimeTable(start, end);
|
||||||
|
classGroups = await widget.data.client.getClassGroups();
|
||||||
|
if (classGroups?.response?.isNotEmpty ?? false) {
|
||||||
|
var group = classGroups!.response!.first;
|
||||||
|
lessons = await widget.data.client.getSubjectAverage(group);
|
||||||
|
classAvgs = await widget.data.client.getClassGroupAverages(group);
|
||||||
|
await Future.delayed(Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
current.refreshTrigger != previous.refreshTrigger,
|
current.refreshTrigger != previous.refreshTrigger,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
setState(() {});
|
_onRefreshRequested(context);
|
||||||
},
|
},
|
||||||
child: _buildContent(context),
|
child: _buildContent(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContent(BuildContext context) {
|
Widget _buildContent(BuildContext context) {
|
||||||
final allGrades = widget.data.client!.cache.getGrades().findAllSync();
|
if (grades == null ||
|
||||||
|
lessons == null ||
|
||||||
final subjectAverage = allGrades.getSubjectAverage();
|
classAvgs == null ||
|
||||||
final roundedSubjectAverage = allGrades.getRoundedSubjectAverage();
|
week == null) {
|
||||||
final classAverages = widget.data.client!.cache
|
return SizedBox(
|
||||||
.getClassAverages()
|
height: MediaQuery.of(context).size.height / 1.35,
|
||||||
.findAllSync();
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
double? classAverage = classAverages.isNotEmpty
|
children: [SizedBox(), DelayedSpinnerWidget(), SizedBox()],
|
||||||
? classAverages.map((c) => c.classAverage).reduce((f, s) => f + s) /
|
|
||||||
classAverages.length
|
|
||||||
: null;
|
|
||||||
|
|
||||||
final List<SubjectCacheModel> subjects = widget.data.client!.cache
|
|
||||||
.getSubjects()
|
|
||||||
.findAllSync();
|
|
||||||
final List<Widget> gradeCards = [];
|
|
||||||
|
|
||||||
for (var subject
|
|
||||||
in subjects.toList()..sort((s1, s2) => s1.name.compareTo(s2.name))) {
|
|
||||||
gradeCards.add(
|
|
||||||
GestureDetector(
|
|
||||||
child: GradeSmallCard(
|
|
||||||
allGrades.getAverageBySubject(subject),
|
|
||||||
subject.classAverage.loadAndGet()?.classAverage,
|
|
||||||
subject,
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
context.go('/grades/subject', extra: subject);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
|
final allGrades = grades!.response!;
|
||||||
|
final allLessons = lessons!.response!;
|
||||||
|
|
||||||
return Padding(
|
final subjectAverage = allGrades.getSubjectAverage();
|
||||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
final roundedSubjectAverage = allGrades.getRoundedSubjectAverage();
|
||||||
child: Column(
|
final classAverages = classAvgs!.response!
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
.map((c) => c.classGroupAverage)
|
||||||
children: [
|
.nonNulls;
|
||||||
Row(
|
|
||||||
children: [
|
double? classAverage = classAverages.isNotEmpty
|
||||||
Text(
|
? classAverages.reduce((f, s) => f + s) / classAverages.length
|
||||||
headingText(widget.data.l10n.subjects),
|
: null;
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
final Set<Subject> subjects = HashSet(
|
||||||
),
|
hashCode: (s) => s.uid.hashCode,
|
||||||
),
|
equals: (s, s2) => s.uid == s2.uid,
|
||||||
],
|
);
|
||||||
|
final List<Widget> gradeCards = [];
|
||||||
|
|
||||||
|
allGrades.map((g) => g.subject).forEach(subjects.add);
|
||||||
|
allLessons.map((l) => l.subject).forEach(subjects.add);
|
||||||
|
|
||||||
|
for (var subject
|
||||||
|
in subjects.toList()..sort((s1, s2) => s1.name.compareTo(s2.name))) {
|
||||||
|
gradeCards.add(
|
||||||
|
GestureDetector(
|
||||||
|
child: GradeSmallCard(
|
||||||
|
allGrades,
|
||||||
|
classAvgs!.response!
|
||||||
|
.firstWhereOrNull((s) => s.subject.uid == subject.uid)
|
||||||
|
?.classGroupAverage,
|
||||||
|
subject,
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
context.go('/grades/subject', extra: subject);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
);
|
||||||
GradeChartWithInteraction(grades: allGrades),
|
}
|
||||||
SizedBox(height: 10),
|
|
||||||
GradeSummaryBar(grades: allGrades, l10n: widget.data.l10n),
|
return Padding(
|
||||||
SizedBox(height: 20),
|
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
||||||
Expanded(
|
child: Column(
|
||||||
child: RefreshIndicator(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
onRefresh: () => widget.data.client!.pullRefresh(
|
children: [
|
||||||
() => widget.data.client!.getGrades(),
|
Row(
|
||||||
),
|
children: [
|
||||||
|
Text(
|
||||||
|
widget.data.l10n.subjects,
|
||||||
|
style: appStyle.fonts.H_H2.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
GradeChartWithInteraction(grades: allGrades),
|
||||||
|
SizedBox(height: 10),
|
||||||
|
GradeSummaryBar(grades: allGrades, l10n: widget.data.l10n),
|
||||||
|
SizedBox(height: 20),
|
||||||
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.data.l10n.your_subjects,
|
widget.data.l10n.your_subjects,
|
||||||
style: appStyle.fonts.H_14px.apply(
|
style: appStyle.fonts.H_14px.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Column(
|
|
||||||
spacing: 16,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: gradeCards,
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
widget.data.l10n.data,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
widget.data.l10n.subject_avg,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
right: [
|
SizedBox(height: 16),
|
||||||
if (subjectAverage != null)
|
Column(
|
||||||
Container(
|
spacing: 16,
|
||||||
width: 48,
|
mainAxisSize: MainAxisSize.min,
|
||||||
height: 26,
|
children: gradeCards,
|
||||||
decoration: ShapeDecoration(
|
),
|
||||||
color: getGradeColor(subjectAverage).withAlpha(38),
|
SizedBox(height: 16),
|
||||||
shape: RoundedRectangleBorder(
|
Text(
|
||||||
borderRadius: BorderRadius.circular(12),
|
widget.data.l10n.data,
|
||||||
),
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
),
|
color: appStyle.colors.textSecondary,
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
subjectAverage.toStringAsFixed(2),
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: getGradeColor(subjectAverage),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
widget.data.l10n.subject_avg_rounded,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
right: [
|
SizedBox(height: 16),
|
||||||
if (roundedSubjectAverage != null)
|
|
||||||
Container(
|
|
||||||
width: 48,
|
|
||||||
height: 26,
|
|
||||||
decoration: ShapeDecoration(
|
|
||||||
color: getGradeColor(
|
|
||||||
roundedSubjectAverage,
|
|
||||||
).withAlpha(38),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
roundedSubjectAverage.toStringAsFixed(2),
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: getGradeColor(roundedSubjectAverage),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (classAverage != null)
|
|
||||||
FirkaCard(
|
FirkaCard(
|
||||||
left: [
|
left: [
|
||||||
Text(
|
Text(
|
||||||
widget.data.l10n.class_avg,
|
widget.data.l10n.subject_avg,
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
Container(
|
if (subjectAverage != null)
|
||||||
width: 48,
|
Container(
|
||||||
height: 26,
|
width: 48,
|
||||||
decoration: ShapeDecoration(
|
height: 26,
|
||||||
color: Colors.transparent,
|
decoration: ShapeDecoration(
|
||||||
shape: RoundedRectangleBorder(
|
color: getGradeColor(subjectAverage).withAlpha(38),
|
||||||
side: BorderSide(
|
shape: RoundedRectangleBorder(
|
||||||
color: getGradeColor(classAverage),
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
subjectAverage.toStringAsFixed(2),
|
||||||
|
style: appStyle.fonts.B_16R.apply(
|
||||||
|
color: getGradeColor(subjectAverage),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
],
|
||||||
child: Text(
|
),
|
||||||
classAverage.toStringAsFixed(2),
|
FirkaCard(
|
||||||
style: appStyle.fonts.B_16R.apply(
|
left: [
|
||||||
color: getGradeColor(classAverage),
|
Text(
|
||||||
|
widget.data.l10n.subject_avg_rounded,
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
right: [
|
||||||
|
if (roundedSubjectAverage != null)
|
||||||
|
Container(
|
||||||
|
width: 48,
|
||||||
|
height: 26,
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
color: getGradeColor(
|
||||||
|
roundedSubjectAverage,
|
||||||
|
).withAlpha(38),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
roundedSubjectAverage.toStringAsFixed(2),
|
||||||
|
style: appStyle.fonts.B_16R.apply(
|
||||||
|
color: getGradeColor(roundedSubjectAverage),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (classAverage != null)
|
||||||
|
FirkaCard(
|
||||||
|
left: [
|
||||||
|
Text(
|
||||||
|
widget.data.l10n.class_avg,
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
right: [
|
||||||
|
Container(
|
||||||
|
width: 48,
|
||||||
|
height: 26,
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
color: Colors.transparent,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
side: BorderSide(
|
||||||
|
color: getGradeColor(classAverage),
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
classAverage.toStringAsFixed(2),
|
||||||
|
style: appStyle.fonts.B_16R.apply(
|
||||||
|
color: getGradeColor(classAverage),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
FirkaCard(
|
||||||
|
left: [
|
||||||
|
Text(
|
||||||
|
widget.data.l10n.class_n,
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
right: [
|
||||||
|
Text(
|
||||||
|
week!.response!
|
||||||
|
.where(
|
||||||
|
(lesson) =>
|
||||||
|
lesson.type.name != TimetableConsts.event,
|
||||||
|
)
|
||||||
|
.length
|
||||||
|
.toString(),
|
||||||
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
/*
|
],
|
||||||
FirkaCard(
|
),
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
widget.data.l10n.class_n,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: [
|
|
||||||
Text(
|
|
||||||
week!.response!
|
|
||||||
.where(
|
|
||||||
(lesson) =>
|
|
||||||
lesson.type.name != TimetableConsts.event,
|
|
||||||
)
|
|
||||||
.length
|
|
||||||
.toString(),
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),*/
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
),
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||||
import 'package:firka/ui/components/firka_icon_button.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
|
import 'package:firka/ui/components/grade.dart';
|
||||||
|
import 'package:firka/ui/phone/pages/home/home_grades.dart';
|
||||||
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
||||||
import 'package:firka/ui/shared/class_icon.dart';
|
import 'package:firka/ui/shared/class_icon.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
@@ -14,7 +14,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:isar_community/isar.dart';
|
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
@@ -23,56 +22,77 @@ import 'package:firka/core/state/firka_state.dart';
|
|||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|
||||||
class HomeGradesSubjectScreen extends StatefulWidget {
|
class HomeGradesSubjectScreen extends StatefulWidget {
|
||||||
final SubjectCacheModel subject;
|
final AppInitialization data;
|
||||||
final String teacherName;
|
final Subject subject;
|
||||||
final Iterable<GradeCacheModel> grades;
|
|
||||||
|
|
||||||
factory HomeGradesSubjectScreen.subject(SubjectCacheModel subject) {
|
const HomeGradesSubjectScreen(this.subject, this.data, {super.key});
|
||||||
return HomeGradesSubjectScreen(
|
|
||||||
subject,
|
|
||||||
initData.client!.cache
|
|
||||||
.getGrades()
|
|
||||||
.subject((s) => s.cacheKeyEqualTo(subject.cacheKey))
|
|
||||||
.sortByCreatedAtDesc()
|
|
||||||
.findAllSync(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
HomeGradesSubjectScreen(this.subject, this.grades, {super.key})
|
|
||||||
: teacherName = subject.teachers
|
|
||||||
.loadAndGet()
|
|
||||||
.map((t) => "${t.name} (${t.classGroup.loadAndGet()!.type})")
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _HomeGradesSubjectScreen();
|
State<StatefulWidget> createState() => _HomeGradesSubjectScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||||
|
Iterable<Grade>? grades;
|
||||||
final List<(int grade, int weight)> _ghostEntries = [];
|
final List<(int grade, int weight)> _ghostEntries = [];
|
||||||
|
|
||||||
List<GradeCacheModel> _gradesWithGhosts() {
|
void _onRefreshRequested(BuildContext context) async {
|
||||||
final real = widget.grades.toList();
|
final cubit = context.read<HomeRefreshCubit>();
|
||||||
|
grades = (await widget.data.client.getGrades(
|
||||||
|
forceCache: false,
|
||||||
|
)).response!.where((grade) => grade.subject.uid == widget.subject.uid);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
cubit.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
(() async {
|
||||||
|
grades = (await widget.data.client.getGrades()).response!.where(
|
||||||
|
(grade) => grade.subject.uid == widget.subject.uid,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Grade> _gradesWithGhosts(Subject subject) {
|
||||||
|
final real = grades?.toList() ?? [];
|
||||||
if (_ghostEntries.isEmpty) return real;
|
if (_ghostEntries.isEmpty) return real;
|
||||||
final baseDate = real.isEmpty
|
final baseDate = real.isEmpty
|
||||||
? DateTime.now()
|
? DateTime.now()
|
||||||
: real.map((g) => g.createdAt).reduce((a, b) => a.isAfter(b) ? a : b);
|
: real
|
||||||
|
.map((g) => g.creationDate)
|
||||||
|
.reduce((a, b) => a.isAfter(b) ? a : b);
|
||||||
|
final osztalyzat = NameUidDesc(
|
||||||
|
uid: '1,Osztalyzat',
|
||||||
|
name: 'Osztalyzat',
|
||||||
|
description: '',
|
||||||
|
);
|
||||||
|
final ghostGrades = <Grade>[];
|
||||||
for (var i = 0; i < _ghostEntries.length; i++) {
|
for (var i = 0; i < _ghostEntries.length; i++) {
|
||||||
final e = _ghostEntries[i];
|
final e = _ghostEntries[i];
|
||||||
real.add(
|
ghostGrades.add(
|
||||||
GradeCacheModel()
|
Grade(
|
||||||
..type = "Ertekeles"
|
uid: 'ghost-$i-${e.$1}-${e.$2}',
|
||||||
..valueType = "Osztalyzat"
|
recordDate: baseDate.add(Duration(seconds: i)),
|
||||||
..writtenAt = baseDate.add(Duration(seconds: i))
|
creationDate: baseDate.add(Duration(seconds: i)),
|
||||||
..numericValue = e.$1
|
subject: subject,
|
||||||
..weightPercentage = e.$2
|
type: osztalyzat,
|
||||||
..textValue = e.$1.toString()
|
valueType: osztalyzat,
|
||||||
..teacherName = widget
|
teacher: '',
|
||||||
.teacherName // TODO: teacher name
|
strValue: '${e.$1}',
|
||||||
..subject.value = widget.subject,
|
sortIndex: 0,
|
||||||
|
numericValue: e.$1,
|
||||||
|
weightPercentage: e.$2,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return real;
|
return [...real, ...ghostGrades];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -81,14 +101,14 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
current.refreshTrigger != previous.refreshTrigger,
|
current.refreshTrigger != previous.refreshTrigger,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
setState(() => {});
|
_onRefreshRequested(context);
|
||||||
},
|
},
|
||||||
child: _buildContent(context),
|
child: _buildContent(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContent(BuildContext context) {
|
Widget _buildContent(BuildContext context) {
|
||||||
if (widget.grades.isEmpty) {
|
if (grades == null || grades!.isEmpty) {
|
||||||
return Container(
|
return Container(
|
||||||
color: appStyle.colors.background,
|
color: appStyle.colors.background,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
@@ -113,7 +133,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
Transform.translate(
|
Transform.translate(
|
||||||
offset: const Offset(-4, 1),
|
offset: const Offset(-4, 1),
|
||||||
child: Text(
|
child: Text(
|
||||||
initData.l10n.subjects,
|
widget.data.l10n.subjects,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -134,7 +154,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsetsGeometry.all(6),
|
padding: EdgeInsetsGeometry.all(6),
|
||||||
child: ClassIconWidget(
|
child: ClassIconWidget.subject(
|
||||||
subject: widget.subject,
|
subject: widget.subject,
|
||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
),
|
),
|
||||||
@@ -149,7 +169,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 2),
|
SizedBox(height: 2),
|
||||||
Text(
|
Text(
|
||||||
initData.l10n.unknown_teacher,
|
widget.data.l10n.unknown_teacher,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
@@ -166,7 +186,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
Text(
|
Text(
|
||||||
initData.l10n.no_grades,
|
widget.data.l10n.no_grades,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
@@ -182,6 +202,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
var aGrade = grades!.first;
|
||||||
|
|
||||||
final ghostGradeWidgets = _ghostEntries.indexed
|
final ghostGradeWidgets = _ghostEntries.indexed
|
||||||
.map((e) {
|
.map((e) {
|
||||||
@@ -225,7 +246,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
Transform.translate(
|
Transform.translate(
|
||||||
offset: const Offset(-4, 0),
|
offset: const Offset(-4, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
initData.l10n.subjects,
|
widget.data.l10n.subjects,
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -233,23 +254,29 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
FirkaIconButton(
|
GestureDetector(
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.buttonSecondaryFill,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.menuSolid,
|
||||||
|
size: 26.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showSubjectBottomSheetSettings(
|
showSubjectBottomSheetSettings(
|
||||||
context,
|
context,
|
||||||
initData,
|
widget.data,
|
||||||
widget.subject,
|
aGrade.subject,
|
||||||
onAddFromCalculator: (g, w) {
|
onAddFromCalculator: (g, w) {
|
||||||
setState(() => _ghostEntries.add((g, w)));
|
setState(() => _ghostEntries.add((g, w)));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.menuSolid,
|
|
||||||
size: 20.0,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -263,23 +290,22 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
FilledCircle(
|
FilledCircle(
|
||||||
diameter: 36,
|
diameter: 36,
|
||||||
color: appStyle.colors.a15p,
|
color: appStyle.colors.a15p,
|
||||||
child: ClassIconWidget(
|
child: ClassIconWidget.subject(
|
||||||
subject: widget.subject,
|
subject: aGrade.subject,
|
||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 24,
|
size: 24,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
widget.subject.name,
|
aGrade.subject.name,
|
||||||
style: appStyle.fonts.H_H2.apply(
|
style: appStyle.fonts.H_H2.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
widget.teacherName,
|
aGrade.teacher,
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
@@ -287,11 +313,13 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 24),
|
SizedBox(height: 24),
|
||||||
GradeChartWithInteraction(grades: _gradesWithGhosts()),
|
GradeChartWithInteraction(
|
||||||
|
grades: _gradesWithGhosts(aGrade.subject),
|
||||||
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
GradeSummaryBar(
|
GradeSummaryBar(
|
||||||
grades: _gradesWithGhosts(),
|
grades: _gradesWithGhosts(aGrade.subject),
|
||||||
l10n: initData.l10n,
|
l10n: widget.data.l10n,
|
||||||
showAverage: ghostGradeWidgets.isNotEmpty,
|
showAverage: ghostGradeWidgets.isNotEmpty,
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
@@ -313,8 +341,8 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
...ghostGradeWidgets,
|
...ghostGradeWidgets,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
...widget.grades
|
...grades!
|
||||||
.groupList((e) => e.writtenAt)
|
.groupList((e) => e.recordDate)
|
||||||
.entries
|
.entries
|
||||||
.map(
|
.map(
|
||||||
(e) => Column(
|
(e) => Column(
|
||||||
@@ -322,7 +350,7 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
e.key.format(initData.l10n, FormatMode.main),
|
e.key.format(widget.data.l10n, FormatMode.main),
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
import 'dart:async';
|
||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
|
import 'package:carousel_slider/carousel_slider.dart';
|
||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
|
import 'package:firka/api/client/kreta_stream.dart';
|
||||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||||
|
import 'package:firka/ui/phone/widgets/lesson.dart';
|
||||||
import 'package:firka/ui/phone/widgets/lesson_slider.dart';
|
import 'package:firka/ui/phone/widgets/lesson_slider.dart';
|
||||||
import 'package:firka_common/data/util.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
import 'package:isar_community/isar.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
|
import 'package:firka/ui/phone/widgets/home_main_starting_soon.dart';
|
||||||
|
import 'package:firka/ui/phone/widgets/lesson_small.dart';
|
||||||
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
import 'package:firka/core/debug_helper.dart';
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
|
||||||
import 'package:firka/ui/shared/delayed_spinner.dart';
|
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import '../../widgets/home_main_welcome.dart';
|
import '../../widgets/home_main_welcome.dart';
|
||||||
|
import '../../widgets/lesson_big.dart';
|
||||||
|
|
||||||
class HomeMainScreen extends StatefulWidget {
|
class HomeMainScreen extends StatefulWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
@@ -28,24 +41,164 @@ class HomeMainScreen extends StatefulWidget {
|
|||||||
class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||||
_HomeMainScreen();
|
_HomeMainScreen();
|
||||||
|
|
||||||
// After the first frame, newly inserted notice groups fade in.
|
List<Lesson>? lessons;
|
||||||
// Groups present on the initial paint (warm cache) stay instant.
|
List<NoticeBoardItem>? noticeBoard;
|
||||||
bool _fadeNewInserts = false;
|
List<RemoteMessage> notifications = [];
|
||||||
|
List<InfoBoardItem>? infoBoard;
|
||||||
|
List<Test>? tests;
|
||||||
|
List<Grade>? grades;
|
||||||
|
List<Homework>? homework;
|
||||||
|
List<Omission>? omissions;
|
||||||
|
Student? student;
|
||||||
|
Timer? timer;
|
||||||
|
|
||||||
|
void _onRefreshRequested(BuildContext context) async {
|
||||||
|
final cubit = context.read<HomeRefreshCubit>();
|
||||||
|
setState(() {});
|
||||||
|
if (mounted) {
|
||||||
|
cubit.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> fetchData({bool cacheOnly = false}) async {
|
||||||
|
final midnight = timeNow().getMidnight();
|
||||||
|
|
||||||
|
var lessonsFetched = 0;
|
||||||
|
var noticeBoardFetched = 0;
|
||||||
|
var infoBoardFetched = 0;
|
||||||
|
var studentFetched = 0;
|
||||||
|
var testsFetched = 0;
|
||||||
|
var gradesFetched = 0;
|
||||||
|
var homeworkFetched = 0;
|
||||||
|
var omissionFetched = 0;
|
||||||
|
|
||||||
|
widget.data.client
|
||||||
|
.getTimeTableStream(
|
||||||
|
midnight,
|
||||||
|
midnight.add(Duration(hours: 23, minutes: 59)),
|
||||||
|
cacheOnly: cacheOnly,
|
||||||
|
)
|
||||||
|
.forEach((lessons) {
|
||||||
|
lessonsFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.lessons = lessons.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getNoticeBoardStream(cacheOnly: cacheOnly).forEach((
|
||||||
|
items,
|
||||||
|
) {
|
||||||
|
noticeBoardFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
noticeBoard = items.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getInfoBoardStream(cacheOnly: cacheOnly).forEach((
|
||||||
|
items,
|
||||||
|
) {
|
||||||
|
infoBoardFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
infoBoard = items.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getStudentStream(cacheOnly: cacheOnly).forEach((
|
||||||
|
student,
|
||||||
|
) {
|
||||||
|
studentFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.student = student.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getTestsStream(cacheOnly: cacheOnly).forEach((tests) {
|
||||||
|
testsFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.tests = tests.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getGradesStream(cacheOnly: cacheOnly).forEach((grades) {
|
||||||
|
gradesFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.grades = grades.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getOmissionsStream(cacheOnly: cacheOnly).forEach((
|
||||||
|
omission,
|
||||||
|
) {
|
||||||
|
omissionFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.omissions = omission.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.data.client.getHomeworkStream(cacheOnly: cacheOnly).forEach((
|
||||||
|
homework,
|
||||||
|
) {
|
||||||
|
homeworkFetched++;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.homework = homework.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final r = cacheOnly ? 1 : 2;
|
||||||
|
final startTime = DateTime.now();
|
||||||
|
const maxWaitTime = Duration(seconds: 30);
|
||||||
|
|
||||||
|
while (lessonsFetched < r ||
|
||||||
|
noticeBoardFetched < r ||
|
||||||
|
infoBoardFetched < r ||
|
||||||
|
studentFetched < r ||
|
||||||
|
testsFetched < r ||
|
||||||
|
gradesFetched < r ||
|
||||||
|
homeworkFetched < r ||
|
||||||
|
omissionFetched < r) {
|
||||||
|
if (DateTime.now().difference(startTime) > maxWaitTime) {
|
||||||
|
debugPrint('[HomeMain] Data fetch timed out after 30s');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
if (mounted) setState(() => _fadeNewInserts = true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onRefreshRequested(BuildContext context) async {
|
FirebaseMessaging.onMessage.listen((event) {
|
||||||
final cubit = context.read<HomeRefreshCubit>();
|
notifications.add(event);
|
||||||
if (mounted) {
|
}, onError: (e) => logger.info(e));
|
||||||
setState(() {});
|
|
||||||
cubit.onRefreshComplete();
|
(() async {
|
||||||
}
|
await fetchData();
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -56,116 +209,115 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
|||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
_onRefreshRequested(context);
|
_onRefreshRequested(context);
|
||||||
},
|
},
|
||||||
child: BlocBuilder<ToastCubit, ToastState>(
|
child: _buildContent(context),
|
||||||
buildWhen: (previous, current) => previous.type != current.type,
|
|
||||||
builder: (context, toastState) => _buildContent(context, toastState),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContent(BuildContext context, ToastState toastState) {
|
Widget _buildContent(BuildContext context) {
|
||||||
final now = timeNow();
|
if (student != null && lessons != null) {
|
||||||
final student = widget.data.client!.cache.findStudentOrNull();
|
final now = timeNow();
|
||||||
final infoItems = widget.data.client!.cache.getMessages().findAllSync();
|
final infoItems = [...(infoBoard ?? []), ...(noticeBoard ?? [])];
|
||||||
final gradeItems = widget.data.client!.cache.getGrades().findAllSync();
|
final gradeItems = grades ?? [];
|
||||||
final testItems = widget.data.client!.cache.getTests().findAllSync();
|
final testItems = tests ?? [];
|
||||||
final homeworkItems = widget.data.client!.cache
|
final homeworkItems = homework ?? [];
|
||||||
.getHomeworks()
|
final omissionItems = omissions?.groupList((o) => o.date).values ?? [];
|
||||||
.findAllSync();
|
final noticeBoardWidgets = <(Widget, DateTime)>[];
|
||||||
final omissionItems = widget.data.client!.cache
|
|
||||||
.getOmissions()
|
|
||||||
.findAllSync()
|
|
||||||
.groupList((o) => o.lesson.loadAndGet()!.start);
|
|
||||||
final noticeBoardWidgets = <(Widget, DateTime)>[];
|
|
||||||
final todayLesson = widget.data.client!.cache
|
|
||||||
.getClassLessons()
|
|
||||||
.on(now)
|
|
||||||
.findAllSync();
|
|
||||||
|
|
||||||
for (final item in infoItems) {
|
for (final n in notifications) {
|
||||||
noticeBoardWidgets.add((InfoCard.messageItem(item), item.createdAt));
|
noticeBoardWidgets.add((
|
||||||
}
|
InfoCard.messageItem(
|
||||||
|
InfoBoardItem(
|
||||||
for (final test in testItems) {
|
uid: "",
|
||||||
noticeBoardWidgets.add((InfoCard.test(test), test.createdAt));
|
title: "Értesítés",
|
||||||
}
|
author: "Kréta",
|
||||||
|
type: NameUidDesc(
|
||||||
for (final grade in gradeItems) {
|
uid: "notificaiton",
|
||||||
noticeBoardWidgets.add((InfoCard.gradeSubj(grade), grade.createdAt));
|
name: "notification",
|
||||||
}
|
description: "notification",
|
||||||
|
|
||||||
for (final entry in homeworkItems) {
|
|
||||||
noticeBoardWidgets.add((InfoCard.homework(entry), entry.createdAt));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final entry in omissionItems.entries) {
|
|
||||||
noticeBoardWidgets.add((InfoCard.omission(entry.value), entry.key));
|
|
||||||
}
|
|
||||||
|
|
||||||
noticeBoardWidgets.sort(
|
|
||||||
(item1, item2) => item2.$2.difference(item1.$2).inMilliseconds,
|
|
||||||
);
|
|
||||||
|
|
||||||
int testsTomorrow = testItems
|
|
||||||
.where(
|
|
||||||
(test) =>
|
|
||||||
test.lesson.loadAndGet() != null &&
|
|
||||||
test.lesson.loadAndGet()!.start.isAfter(
|
|
||||||
now.getMidnight().add(Duration(hours: 23, minutes: 59)),
|
|
||||||
) &&
|
|
||||||
test.lesson.loadAndGet()!.start.isBefore(
|
|
||||||
now.getMidnight().add(Duration(days: 2)),
|
|
||||||
),
|
),
|
||||||
)
|
contentHTML:
|
||||||
.length;
|
"<code>${n.data}</code><code>${n.notification}<br/>${n.notification?.title}<br/>${n.notification?.body}<br/>${n.notification?.android}",
|
||||||
|
contentText: "",
|
||||||
final bodyEmpty = todayLesson.isEmpty && noticeBoardWidgets.isEmpty;
|
date: now,
|
||||||
final showInnerSpinner =
|
createdAt: now,
|
||||||
toastState.type == ActiveToastType.fetching && bodyEmpty;
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
||||||
child: RefreshIndicator(
|
|
||||||
onRefresh: () => widget.data.client!.refreshHomeFeed(),
|
|
||||||
notificationPredicate: (ScrollNotification notification) {
|
|
||||||
return notification.depth == 0;
|
|
||||||
},
|
|
||||||
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
|
||||||
child: ListView(
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
clipBehavior: Clip.none,
|
|
||||||
children: [
|
|
||||||
SizedBox(height: 24),
|
|
||||||
_FadeInWhenLoaded(
|
|
||||||
loaded: student != null,
|
|
||||||
child: student != null
|
|
||||||
? WelcomeWidget(
|
|
||||||
widget.data.l10n,
|
|
||||||
now,
|
|
||||||
student,
|
|
||||||
todayLesson,
|
|
||||||
)
|
|
||||||
: const SizedBox.shrink(),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: 48),
|
),
|
||||||
if (showInnerSpinner)
|
now,
|
||||||
SizedBox(
|
));
|
||||||
height: MediaQuery.sizeOf(context).height * 0.35,
|
}
|
||||||
child: const Center(child: DelayedSpinnerWidget()),
|
|
||||||
),
|
for (final item in infoItems) {
|
||||||
_FadeInWhenLoaded(
|
noticeBoardWidgets.add((InfoCard.messageItem(item), item.date));
|
||||||
loaded: todayLesson.isNotEmpty,
|
}
|
||||||
child: LessonSlider(todayLesson, testsTomorrow),
|
|
||||||
|
for (final test in testItems) {
|
||||||
|
noticeBoardWidgets.add((InfoCard.test(test), test.reportDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final grade in gradeItems) {
|
||||||
|
noticeBoardWidgets.add((InfoCard.gradeSubj(grade), grade.creationDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final entry in homeworkItems) {
|
||||||
|
noticeBoardWidgets.add((InfoCard.homework(entry), entry.creationDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final omission in omissionItems) {
|
||||||
|
noticeBoardWidgets.add((
|
||||||
|
InfoCard.omission(omission),
|
||||||
|
omission.first.date,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
noticeBoardWidgets.sort(
|
||||||
|
(item1, item2) => item2.$2.difference(item1.$2).inMilliseconds,
|
||||||
|
);
|
||||||
|
|
||||||
|
LinkedHashMap<Lesson, Test?> lessonTestMap = LinkedHashMap.fromEntries(
|
||||||
|
lessons!.indexed.map(
|
||||||
|
(i) => MapEntry(
|
||||||
|
i.$2,
|
||||||
|
testItems.firstWhereOrNull(
|
||||||
|
(t) =>
|
||||||
|
t.date.getMidnight() == i.$2.start.getMidnight() &&
|
||||||
|
(i.$2.lessonNumber ?? i.$1) == t.lessonNumber,
|
||||||
),
|
),
|
||||||
SizedBox(height: 24),
|
),
|
||||||
...noticeBoardWidgets
|
),
|
||||||
.groupList((e) => e.$2)
|
);
|
||||||
.entries
|
|
||||||
.map(
|
int testsTomorrow = testItems
|
||||||
(e) => _FadeInOnInsert(
|
.where(
|
||||||
key: ValueKey(e.key),
|
(test) =>
|
||||||
animate: _fadeNewInserts,
|
test.date.isAfter(
|
||||||
child: Column(
|
now.getMidnight().add(Duration(hours: 23, minutes: 59)),
|
||||||
|
) &&
|
||||||
|
test.date.isBefore(now.getMidnight().add(Duration(days: 2))),
|
||||||
|
)
|
||||||
|
.length;
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||||
|
child: RefreshIndicator(
|
||||||
|
onRefresh: () => fetchData(),
|
||||||
|
notificationPredicate: (ScrollNotification notification) {
|
||||||
|
return notification.depth == 0;
|
||||||
|
},
|
||||||
|
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
||||||
|
displacement: 0,
|
||||||
|
child: ListView(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 24),
|
||||||
|
WelcomeWidget(widget.data.l10n, now, student!, lessons!),
|
||||||
|
SizedBox(height: 48),
|
||||||
|
LessonSlider(lessonTestMap, testsTomorrow),
|
||||||
|
SizedBox(height: 24),
|
||||||
|
...noticeBoardWidgets
|
||||||
|
.groupList((e) => e.$2)
|
||||||
|
.entries
|
||||||
|
.map(
|
||||||
|
(e) => Column(
|
||||||
spacing: 10,
|
spacing: 10,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -180,99 +332,23 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: appStyle.colors.background,
|
||||||
|
body: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [DelayedSpinnerWidget()],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fades in when [loaded] flips from false to true. First paint with data is instant.
|
|
||||||
class _FadeInWhenLoaded extends StatelessWidget {
|
|
||||||
const _FadeInWhenLoaded({
|
|
||||||
required this.loaded,
|
|
||||||
required this.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
final bool loaded;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
static const _duration = Duration(milliseconds: 300);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AnimatedSwitcher(
|
|
||||||
duration: _duration,
|
|
||||||
switchInCurve: Curves.easeOut,
|
|
||||||
transitionBuilder: (child, animation) => FadeTransition(
|
|
||||||
opacity: animation,
|
|
||||||
child: SlideTransition(
|
|
||||||
position: Tween<Offset>(
|
|
||||||
begin: const Offset(0, 0.04),
|
|
||||||
end: Offset.zero,
|
|
||||||
).animate(animation),
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: loaded
|
|
||||||
? KeyedSubtree(key: const ValueKey("content"), child: child)
|
|
||||||
: const SizedBox.shrink(key: ValueKey("empty")),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fades newly inserted list sections. Skips animation when [animate] is false (warm cache).
|
|
||||||
class _FadeInOnInsert extends StatefulWidget {
|
|
||||||
const _FadeInOnInsert({
|
|
||||||
super.key,
|
|
||||||
required this.animate,
|
|
||||||
required this.child,
|
|
||||||
});
|
|
||||||
|
|
||||||
final bool animate;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<_FadeInOnInsert> createState() => _FadeInOnInsertState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FadeInOnInsertState extends State<_FadeInOnInsert>
|
|
||||||
with SingleTickerProviderStateMixin {
|
|
||||||
late final AnimationController _controller;
|
|
||||||
late final Animation<double> _opacity;
|
|
||||||
late final Animation<Offset> _slide;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_controller = AnimationController(
|
|
||||||
vsync: this,
|
|
||||||
duration: const Duration(milliseconds: 300),
|
|
||||||
value: widget.animate ? 0 : 1,
|
|
||||||
);
|
|
||||||
final curved = CurvedAnimation(parent: _controller, curve: Curves.easeOut);
|
|
||||||
_opacity = curved;
|
|
||||||
_slide = Tween<Offset>(
|
|
||||||
begin: const Offset(0, 0.04),
|
|
||||||
end: Offset.zero,
|
|
||||||
).animate(curved);
|
|
||||||
if (widget.animate) {
|
|
||||||
_controller.forward();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return FadeTransition(
|
|
||||||
opacity: _opacity,
|
|
||||||
child: SlideTransition(position: _slide, child: widget.child),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
|
||||||
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||||
import 'package:firka/ui/phone/widgets/omission_bar.dart';
|
import 'package:firka/ui/phone/widgets/omission_bar.dart';
|
||||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
import 'package:firka_common/firka_common.dart';
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:firka_common/ui/shared/firka_icon.dart';
|
|
||||||
import 'package:isar_community/isar.dart';
|
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
|
import 'package:firka/ui/components/grade_helpers.dart';
|
||||||
|
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
||||||
|
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||||
|
import 'package:firka/ui/shared/grade_small_card.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
|
import 'package:firka/api/consts.dart';
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
class HomeOmissionsScreen extends StatefulWidget {
|
class HomeOmissionsScreen extends StatefulWidget {
|
||||||
@@ -28,22 +34,45 @@ class HomeOmissionsScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
||||||
|
ApiResponse<List<Omission>>? omissions;
|
||||||
|
|
||||||
|
void _onRefreshRequested(BuildContext context) async {
|
||||||
|
final cubit = context.read<HomeRefreshCubit>();
|
||||||
|
omissions = await widget.data.client.getOmissions(forceCache: false);
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
cubit.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
(() async {
|
||||||
|
omissions = await widget.data.client.getOmissions(forceCache: false);
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
current.refreshTrigger != previous.refreshTrigger,
|
current.refreshTrigger != previous.refreshTrigger,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
setState(() {});
|
_onRefreshRequested(context);
|
||||||
},
|
},
|
||||||
child: _buildContent(context),
|
child: _buildContent(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContent(BuildContext context) {
|
Widget _buildContent(BuildContext context) {
|
||||||
final omissionItems = widget.data.client!.cache
|
if (omissions == null) {
|
||||||
.getOmissions()
|
return Center(child: DelayedSpinnerWidget());
|
||||||
.findAllSync();
|
}
|
||||||
|
|
||||||
|
final omissionItems = omissions!.response ?? [];
|
||||||
|
|
||||||
final overallExcused = omissionItems
|
final overallExcused = omissionItems
|
||||||
.where((o) => o.state == OmissionState.excused)
|
.where((o) => o.state == OmissionState.excused)
|
||||||
@@ -63,7 +92,7 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
headingText(widget.data.l10n.omissions),
|
widget.data.l10n.omissions,
|
||||||
style: appStyle.fonts.H_H2.apply(
|
style: appStyle.fonts.H_H2.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -174,18 +203,13 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
OmissionBar(),
|
OmissionBar(omissions: omissions!.response!),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: RefreshIndicator(
|
child: ListView(
|
||||||
onRefresh: () => widget.data.client!.pullRefresh(
|
children: [
|
||||||
() => widget.data.client!.getOmissions(),
|
Text(
|
||||||
),
|
initData.l10n.subjects,
|
||||||
child: ListView(
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
initData.l10n.subjects,
|
|
||||||
style: appStyle.fonts.B_16SB.copyWith(
|
style: appStyle.fonts.B_16SB.copyWith(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
@@ -193,18 +217,13 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
|||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
...omissionItems
|
...omissionItems
|
||||||
.fold(
|
.fold(
|
||||||
LinkedHashMap<
|
LinkedHashMap<Subject, List<Omission>>(
|
||||||
SubjectCacheModel,
|
equals: (a, b) => a.uid == b.uid,
|
||||||
List<OmissionCacheModel>
|
hashCode: (a) => a.uid.hashCode,
|
||||||
>(
|
|
||||||
equals: (a, b) => a.cacheKey == b.cacheKey,
|
|
||||||
hashCode: (a) => a.cacheKey,
|
|
||||||
),
|
),
|
||||||
(map, o) => map
|
(map, o) =>
|
||||||
..putIfAbsent(
|
map
|
||||||
o.lesson.loadAndGet()!.subject.loadAndGet()!,
|
..putIfAbsent(o.subject, () => <Omission>[]).add(o),
|
||||||
() => [],
|
|
||||||
).add(o),
|
|
||||||
)
|
)
|
||||||
.entries
|
.entries
|
||||||
.map((entry) {
|
.map((entry) {
|
||||||
@@ -298,7 +317,6 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,14 @@
|
|||||||
import 'package:firka/ui/components/firka_icon_button.dart';
|
import 'package:firka/api/consts.dart';
|
||||||
import 'package:firka/ui/phone/screens/settings/settings_screen.dart';
|
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:isar_community/isar.dart';
|
|
||||||
import 'package:kreta_api/kreta_api.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/core/debug_helper.dart';
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/core/settings.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
import 'package:transparent_pointer/transparent_pointer.dart';
|
import 'package:transparent_pointer/transparent_pointer.dart';
|
||||||
|
|
||||||
@@ -18,6 +16,7 @@ import 'package:firka/app/app_state.dart';
|
|||||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
|
import '../../screens/settings/settings_screen.dart';
|
||||||
|
|
||||||
class HomeTimetableMonthlyScreen extends StatefulWidget {
|
class HomeTimetableMonthlyScreen extends StatefulWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
@@ -33,19 +32,68 @@ enum ActiveFilter { lessonNo, tests, omissions }
|
|||||||
|
|
||||||
class _HomeTimetableMonthlyScreen
|
class _HomeTimetableMonthlyScreen
|
||||||
extends FirkaState<HomeTimetableMonthlyScreen> {
|
extends FirkaState<HomeTimetableMonthlyScreen> {
|
||||||
List<DateTime> dates = [];
|
List<Lesson>? lessons;
|
||||||
late DateTime now;
|
List<Test>? tests;
|
||||||
|
List<DateTime>? dates;
|
||||||
|
List<Omission>? omissions;
|
||||||
|
DateTime? now;
|
||||||
int active = 0;
|
int active = 0;
|
||||||
ActiveFilter activeFilter = ActiveFilter.lessonNo;
|
ActiveFilter activeFilter = ActiveFilter.lessonNo;
|
||||||
|
|
||||||
_HomeTimetableMonthlyScreen();
|
_HomeTimetableMonthlyScreen();
|
||||||
|
|
||||||
void updateDates() {
|
Future<void> initForMonth(DateTime now, {bool forceCache = true}) async {
|
||||||
DateTime from = now.getMidnight().getMonthFirstDay().getMonday().subtract(
|
final monthStart = DateTime.utc(now.year, now.month, 1);
|
||||||
Duration(days: 7),
|
final monthEnd = DateTime.utc(
|
||||||
);
|
now.year,
|
||||||
|
now.month + 1,
|
||||||
|
).subtract(Duration(days: 1));
|
||||||
|
|
||||||
dates = List.generate(49, (i) => from.add(Duration(days: i)));
|
final start = monthStart.subtract(Duration(days: 7)).getMonday();
|
||||||
|
var end = monthEnd
|
||||||
|
.add(Duration(days: 7))
|
||||||
|
.getMonday()
|
||||||
|
.add(Duration(days: 7));
|
||||||
|
|
||||||
|
var days = end.difference(start).inDays;
|
||||||
|
|
||||||
|
var lessonsResp = await widget.data.client.getTimeTable(
|
||||||
|
monthStart,
|
||||||
|
monthEnd,
|
||||||
|
forceCache: forceCache,
|
||||||
|
);
|
||||||
|
var testsResp = await widget.data.client.getTests(forceCache: forceCache);
|
||||||
|
var omissionsResp = await widget.data.client.getOmissions(forceCache: true);
|
||||||
|
List<DateTime> dates = List.empty(growable: true);
|
||||||
|
|
||||||
|
for (var i = 0; i < days; i++) {
|
||||||
|
dates.add(start.add(Duration(days: i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lessonsResp.response != null) {
|
||||||
|
lessons = lessonsResp.response
|
||||||
|
?.where((lesson) => lesson.type.name != TimetableConsts.event)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
tests = testsResp.response;
|
||||||
|
omissions = omissionsResp.response;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
this.dates = dates;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onRefreshRequested(BuildContext context) async {
|
||||||
|
final cubit = context.read<HomeRefreshCubit>();
|
||||||
|
if (now != null) {
|
||||||
|
await initForMonth(now!, forceCache: false);
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
cubit.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -53,8 +101,7 @@ class _HomeTimetableMonthlyScreen
|
|||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
now = timeNow();
|
now = timeNow();
|
||||||
|
initForMonth(now!);
|
||||||
updateDates();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -63,65 +110,80 @@ class _HomeTimetableMonthlyScreen
|
|||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
current.refreshTrigger != previous.refreshTrigger,
|
current.refreshTrigger != previous.refreshTrigger,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
setState(() {});
|
_onRefreshRequested(context);
|
||||||
},
|
},
|
||||||
child: _buildContent(context),
|
child: _buildContent(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildContent(BuildContext context) {
|
Widget _buildContent(BuildContext context) {
|
||||||
|
if (lessons == null ||
|
||||||
|
omissions == null ||
|
||||||
|
tests == null ||
|
||||||
|
dates == null) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: appStyle.colors.background,
|
||||||
|
body: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [DelayedSpinnerWidget()],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
List<Widget> ttDays = [];
|
List<Widget> ttDays = [];
|
||||||
|
|
||||||
updateDates();
|
final meow = dates![20];
|
||||||
|
final currentMonthStart = DateTime.utc(meow.year, meow.month, 1);
|
||||||
final currentMonthStart = now.getMidnight().getMonthFirstDay();
|
final currentMonthEnd = DateTime.utc(
|
||||||
final currentMonthEnd = now
|
meow.year,
|
||||||
.getMonthLastDay()
|
meow.month + 1,
|
||||||
.add(Duration(days: 1))
|
).subtract(Duration(days: 1));
|
||||||
.getMidnight()
|
|
||||||
.subtract(Duration(microseconds: 1));
|
|
||||||
|
|
||||||
// column-major -> row-major
|
// column-major -> row-major
|
||||||
for (var week = 0; week < 7; week++) {
|
for (var week = 0; week < 7; week++) {
|
||||||
for (var day = 0; day < 7; day++) {
|
for (var day = 0; day < 7; day++) {
|
||||||
final d = dates[week * 7 + day];
|
final d = dates![week * 7 + day];
|
||||||
|
|
||||||
bool outOfRange =
|
bool outOfRange =
|
||||||
d.isBefore(currentMonthStart) || d.isAfter(currentMonthEnd);
|
d.isBefore(currentMonthStart) || d.isAfter(currentMonthEnd);
|
||||||
bool isToday =
|
bool isToday =
|
||||||
!outOfRange &&
|
!outOfRange && timeNow().day == d.day && timeNow().month == d.month;
|
||||||
timeNow().year == d.year &&
|
|
||||||
timeNow().day == d.day &&
|
|
||||||
timeNow().month == d.month;
|
|
||||||
|
|
||||||
Widget body = SizedBox();
|
Widget body = SizedBox();
|
||||||
Color? todayAccent = isToday ? appStyle.colors.textPrimaryLight : null;
|
Color? todayAccent = isToday ? appStyle.colors.textPrimaryLight : null;
|
||||||
Color bodyBgColor = appStyle.colors.a15p;
|
Color bodyBgColor = appStyle.colors.a15p;
|
||||||
|
|
||||||
var lessonsToday = widget.data.client!.cache.getClassLessons().on(d);
|
var lessonsToday = lessons!.where(
|
||||||
|
(lesson) =>
|
||||||
|
lesson.start.isAfter(d.getMidnight()) &&
|
||||||
|
lesson.end.isBefore(
|
||||||
|
d.getMidnight().add(Duration(hours: 23, minutes: 59)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
int lessonCountToday = lessonsToday.countSync();
|
var omittedLesson = lessonsToday.firstWhereOrNull(
|
||||||
|
(lesson) =>
|
||||||
|
lesson.studentPresence != null &&
|
||||||
|
lesson.studentPresence?.name != OmissionConsts.na &&
|
||||||
|
lesson.studentPresence?.name != OmissionConsts.present,
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Nézze meg a többi órát is
|
if (lessonsToday.isNotEmpty) {
|
||||||
var omittedLesson = lessonsToday
|
|
||||||
.and()
|
|
||||||
.not()
|
|
||||||
.omissionIsNull()
|
|
||||||
.findFirstSync();
|
|
||||||
|
|
||||||
if (lessonCountToday > 0) {
|
|
||||||
switch (activeFilter) {
|
switch (activeFilter) {
|
||||||
case ActiveFilter.lessonNo:
|
case ActiveFilter.lessonNo:
|
||||||
body = Center(
|
body = Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
lessonCountToday.toString(),
|
lessonsToday.length.toString(),
|
||||||
style: appStyle.fonts.H_16px.apply(
|
style: appStyle.fonts.H_16px.apply(
|
||||||
color:
|
color:
|
||||||
(todayAccent ??
|
todayAccent ??
|
||||||
(omittedLesson != null
|
(omittedLesson != null
|
||||||
? appStyle.colors.errorText
|
? appStyle.colors.errorText
|
||||||
: appStyle.colors.secondary))
|
: appStyle.colors.secondary),
|
||||||
.withAlpha(outOfRange ? 77 : 255),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -131,7 +193,19 @@ class _HomeTimetableMonthlyScreen
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActiveFilter.tests:
|
case ActiveFilter.tests:
|
||||||
if (lessonsToday.not().testIsNull().isNotEmptySync()) {
|
if (lessonsToday.firstWhereOrNull(
|
||||||
|
(lesson) => tests!.any(
|
||||||
|
(test) =>
|
||||||
|
test.lessonNumber == lesson.lessonNumber &&
|
||||||
|
lesson.start.isAfter(test.date.getMidnight()) &&
|
||||||
|
lesson.end.isBefore(
|
||||||
|
test.date.getMidnight().add(
|
||||||
|
Duration(hours: 23, minutes: 59),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) !=
|
||||||
|
null) {
|
||||||
body = Center(
|
body = Center(
|
||||||
child: FirkaIconWidget(
|
child: FirkaIconWidget(
|
||||||
FirkaIconType.majesticons,
|
FirkaIconType.majesticons,
|
||||||
@@ -147,41 +221,50 @@ class _HomeTimetableMonthlyScreen
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var omissionState = omittedLesson.omission.loadAndGet()!.state;
|
// TODO: Nézze meg a többi órát is
|
||||||
switch (omissionState) {
|
final omission = omissions!.firstWhereOrNull((omission) {
|
||||||
case OmissionState.excused:
|
return omission.date.getMidnight().millisecondsSinceEpoch ==
|
||||||
body = Center(
|
omittedLesson.start
|
||||||
child: FirkaIconWidget(
|
.getMidnight()
|
||||||
FirkaIconType.majesticons,
|
.millisecondsSinceEpoch &&
|
||||||
Majesticon.multiplySolid,
|
omission.subject.uid == omittedLesson.subject?.uid;
|
||||||
size: 20.0,
|
});
|
||||||
color: todayAccent ?? appStyle.colors.accent,
|
|
||||||
),
|
if (omission?.state == OmissionState.excused) {
|
||||||
);
|
body = Center(
|
||||||
break;
|
child: FirkaIconWidget(
|
||||||
case OmissionState.pending:
|
FirkaIconType.majesticons,
|
||||||
body = Center(
|
Majesticon.multiplySolid,
|
||||||
child: FirkaIconWidget(
|
size: 20.0,
|
||||||
FirkaIconType.majesticons,
|
color: todayAccent ?? appStyle.colors.accent,
|
||||||
Majesticon.timerLine,
|
),
|
||||||
size: 20.0,
|
);
|
||||||
color: todayAccent ?? appStyle.colors.warningAccent,
|
break;
|
||||||
),
|
|
||||||
);
|
|
||||||
bodyBgColor = appStyle.colors.warning15p;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
body = Center(
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.restrictedSolid,
|
|
||||||
size: 20.0,
|
|
||||||
color: todayAccent ?? appStyle.colors.errorAccent,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
bodyBgColor = appStyle.colors.error15p;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (omission?.state == OmissionState.pending) {
|
||||||
|
body = Center(
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.timerLine,
|
||||||
|
size: 20.0,
|
||||||
|
color: todayAccent ?? appStyle.colors.warningAccent,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyBgColor = appStyle.colors.warning15p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
body = Center(
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.restrictedSolid,
|
||||||
|
size: 20.0,
|
||||||
|
color: todayAccent ?? appStyle.colors.errorAccent,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bodyBgColor = appStyle.colors.error15p;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,7 +277,7 @@ class _HomeTimetableMonthlyScreen
|
|||||||
bodyBgColor = appStyle.colors.cardTranslucent;
|
bodyBgColor = appStyle.colors.cardTranslucent;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWeekend = d.weekday > 5 && lessonCountToday == 0;
|
bool isWeekend = d.weekday > 5 && lessonsToday.isEmpty;
|
||||||
Color textColor = (isWeekend
|
Color textColor = (isWeekend
|
||||||
? appStyle.colors.errorText
|
? appStyle.colors.errorText
|
||||||
: isToday
|
: isToday
|
||||||
@@ -235,11 +318,6 @@ class _HomeTimetableMonthlyScreen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final lessonsInMonth = widget.data.client!.cache.getClassLessons().between(
|
|
||||||
currentMonthStart,
|
|
||||||
currentMonthEnd,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: appStyle.colors.background,
|
backgroundColor: appStyle.colors.background,
|
||||||
body: Stack(
|
body: Stack(
|
||||||
@@ -255,49 +333,66 @@ class _HomeTimetableMonthlyScreen
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
headingText(widget.data.l10n.timetable),
|
widget.data.l10n.timetable,
|
||||||
style: appStyle.fonts.H_H2.apply(
|
style: appStyle.fonts.H_H2.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
spacing: 8,
|
|
||||||
children: [
|
children: [
|
||||||
FirkaIconButton(
|
GestureDetector(
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.buttonSecondaryFill,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.tableSolid,
|
||||||
|
size: 26.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
},
|
},
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.tableSolid,
|
|
||||||
size: 20.0,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
// Nincs elkészítve jelenleg: Dolgozat stb hozzáadása(?)
|
// Nincs elkészítve jelenleg: Dolgozat stb hozzáadása(?)
|
||||||
// FirkaIconButton(
|
// Card(
|
||||||
// child: FirkaIconWidget(
|
// color: appStyle.colors.buttonSecondaryFill,
|
||||||
// FirkaIconType.majesticons,
|
// child: Padding(
|
||||||
// Majesticon.plusLine,
|
// padding: const EdgeInsets.all(4),
|
||||||
// size: 20.0,
|
// child: FirkaIconWidget(
|
||||||
// color: appStyle.colors.accent,
|
// FirkaIconType.majesticons,
|
||||||
|
// Majesticon.plusLine,
|
||||||
|
// size: 32.0,
|
||||||
|
// color: appStyle.colors.accent,
|
||||||
|
// ),
|
||||||
// ),
|
// ),
|
||||||
// ),
|
// ),
|
||||||
FirkaIconButton(
|
GestureDetector(
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.buttonSecondaryFill,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.settingsCogSolid,
|
||||||
|
size: 26.0,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showSettingsSheet(
|
showSettingsSheet(
|
||||||
context,
|
context,
|
||||||
MediaQuery.of(context).size.height * 0.4,
|
MediaQuery.of(context).size.height * 0.4,
|
||||||
widget.data,
|
widget.data,
|
||||||
timetableToastTree(widget.data.l10n),
|
widget.data.settings
|
||||||
|
.group("settings")
|
||||||
|
.subGroup("timetable_toast"),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.settingsCogSolid,
|
|
||||||
size: 20.0,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -320,13 +415,20 @@ class _HomeTimetableMonthlyScreen
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
var newNow = DateTime(now!.year, now!.month - 1);
|
||||||
setState(() {
|
setState(() {
|
||||||
now = DateTime(now.year, now.month - 1);
|
now = newNow;
|
||||||
|
lessons = null;
|
||||||
|
dates = null;
|
||||||
|
});
|
||||||
|
await initForMonth(newNow);
|
||||||
|
setState(() {
|
||||||
|
now = newNow;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
now
|
now!
|
||||||
.format(widget.data.l10n, FormatMode.yyyymmmm)
|
.format(widget.data.l10n, FormatMode.yyyymmmm)
|
||||||
.toLowerCase(),
|
.toLowerCase(),
|
||||||
style: appStyle.fonts.B_16R.apply(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
@@ -341,8 +443,15 @@ class _HomeTimetableMonthlyScreen
|
|||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
var newNow = DateTime(now!.year, now!.month + 1);
|
||||||
setState(() {
|
setState(() {
|
||||||
now = DateTime(now.year, now.month + 1);
|
now = newNow;
|
||||||
|
lessons = null;
|
||||||
|
dates = null;
|
||||||
|
});
|
||||||
|
await initForMonth(newNow);
|
||||||
|
setState(() {
|
||||||
|
now = newNow;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -359,20 +468,11 @@ class _HomeTimetableMonthlyScreen
|
|||||||
left: 20,
|
left: 20,
|
||||||
right: 20,
|
right: 20,
|
||||||
),
|
),
|
||||||
child: RefreshIndicator(
|
child: GridView.count(
|
||||||
onRefresh: () => widget.data.client!.pullRefresh(
|
crossAxisCount: 7,
|
||||||
() => widget.data.client!.getLessonsCovering(
|
mainAxisSpacing: 16,
|
||||||
currentMonthStart,
|
mainAxisExtent: 62,
|
||||||
currentMonthEnd,
|
children: ttDays,
|
||||||
),
|
|
||||||
),
|
|
||||||
child: GridView.count(
|
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
crossAxisCount: 7,
|
|
||||||
mainAxisSpacing: 16,
|
|
||||||
mainAxisExtent: 62,
|
|
||||||
children: ttDays,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -390,7 +490,13 @@ class _HomeTimetableMonthlyScreen
|
|||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 16,
|
size: 16,
|
||||||
),
|
),
|
||||||
lessonsInMonth.countSync(),
|
lessons!
|
||||||
|
.where(
|
||||||
|
(lesson) =>
|
||||||
|
lesson.start.isAfter(currentMonthStart) &&
|
||||||
|
lesson.end.isBefore(currentMonthEnd),
|
||||||
|
)
|
||||||
|
.length,
|
||||||
activeFilter == ActiveFilter.lessonNo,
|
activeFilter == ActiveFilter.lessonNo,
|
||||||
() {
|
() {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -405,7 +511,20 @@ class _HomeTimetableMonthlyScreen
|
|||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 16,
|
size: 16,
|
||||||
),
|
),
|
||||||
lessonsInMonth.and().not().testIsNull().countSync(),
|
lessons!
|
||||||
|
.where(
|
||||||
|
(lesson) => tests!.any(
|
||||||
|
(test) =>
|
||||||
|
test.lessonNumber == lesson.lessonNumber &&
|
||||||
|
lesson.start.isAfter(test.date.getMidnight()) &&
|
||||||
|
lesson.end.isBefore(
|
||||||
|
test.date.getMidnight().add(
|
||||||
|
Duration(hours: 23, minutes: 59),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.length,
|
||||||
activeFilter == ActiveFilter.tests,
|
activeFilter == ActiveFilter.tests,
|
||||||
() {
|
() {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -420,7 +539,18 @@ class _HomeTimetableMonthlyScreen
|
|||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 16,
|
size: 16,
|
||||||
),
|
),
|
||||||
lessonsInMonth.and().not().omissionIsNull().countSync(),
|
lessons!
|
||||||
|
.where(
|
||||||
|
(lesson) =>
|
||||||
|
lesson.start.isAfter(currentMonthStart) &&
|
||||||
|
lesson.end.isBefore(currentMonthEnd) &&
|
||||||
|
lesson.studentPresence != null &&
|
||||||
|
lesson.studentPresence?.name !=
|
||||||
|
OmissionConsts.na &&
|
||||||
|
lesson.studentPresence?.name !=
|
||||||
|
OmissionConsts.present,
|
||||||
|
)
|
||||||
|
.length,
|
||||||
activeFilter == ActiveFilter.omissions,
|
activeFilter == ActiveFilter.omissions,
|
||||||
() {
|
() {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firka_common/data/models/class_average_cache_model.dart';
|
import 'package:firka/data/models/generic_cache_model.dart';
|
||||||
import 'package:firka_common/data/models/class_group_cache_model.dart';
|
import 'package:firka/data/models/homework_cache_model.dart';
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
import 'package:firka/data/models/timetable_cache_model.dart';
|
||||||
import 'package:firka_common/data/models/homework_cache_model.dart';
|
import 'package:firka/data/models/token_model.dart';
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/message_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/teacher_model.dart';
|
|
||||||
import 'package:firka_common/data/models/test_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/token_model.dart';
|
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/core/icon_helper.dart';
|
import 'package:firka/core/icon_helper.dart';
|
||||||
import 'package:firka/core/profile_picture.dart';
|
import 'package:firka/core/profile_picture.dart';
|
||||||
@@ -21,9 +14,9 @@ import 'package:image_picker/image_picker.dart';
|
|||||||
|
|
||||||
import 'package:firka/core/debug_helper.dart';
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
|
import 'package:firka/data/widget.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:home_widget/home_widget.dart';
|
import 'package:home_widget/home_widget.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@@ -149,6 +142,11 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
);
|
);
|
||||||
if (!context.mounted || d == null) return;
|
if (!context.mounted || d == null) return;
|
||||||
try {
|
try {
|
||||||
|
await WidgetCacheHelper.generateWidgetStateForDate(
|
||||||
|
d,
|
||||||
|
appStyle,
|
||||||
|
widget.data.client,
|
||||||
|
);
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
await HomeWidget.updateWidget(
|
await HomeWidget.updateWidget(
|
||||||
qualifiedAndroidName:
|
qualifiedAndroidName:
|
||||||
@@ -189,7 +187,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getStudent(): ${await widget.data.client!.getStudent()}",
|
"getStudent(): ${await widget.data.client.getStudent(forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getStudent()'),
|
child: const Text('getStudent()'),
|
||||||
@@ -197,7 +195,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getNoticeBoard(): ${await widget.data.client!.getNoticeBoard()}",
|
"getNoticeBoard(): ${await widget.data.client.getNoticeBoard(forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getNoticeBoard()'),
|
child: const Text('getNoticeBoard()'),
|
||||||
@@ -205,15 +203,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getInfoBoard(): ${await widget.data.client!.getInfoBoard(from: timeNow())}",
|
"getGrades(): ${await widget.data.client.getGrades(forceCache: useCache)}",
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text('getInfoBoard()'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
logger.finest(
|
|
||||||
"getGrades(): ${await widget.data.client!.getGrades()}",
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getGrades()'),
|
child: const Text('getGrades()'),
|
||||||
@@ -226,7 +216,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
var end = now.add(Duration(days: 7));
|
var end = now.add(Duration(days: 7));
|
||||||
|
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getLessons(): ${await widget.data.client!.getLessons(start, end)}",
|
"getLessons(): ${await widget.data.client.getTimeTable(start, end, forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getLessons()'),
|
child: const Text('getLessons()'),
|
||||||
@@ -234,7 +224,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getHomework(): ${await widget.data.client!.getHomework(from: timeNow())}",
|
"getHomework(): ${await widget.data.client.getHomework(forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getHomework()'),
|
child: const Text('getHomework()'),
|
||||||
@@ -242,7 +232,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getTests(): ${await widget.data.client!.getTests(from: timeNow())}",
|
"getTests(): ${await widget.data.client.getTests(forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getTests()'),
|
child: const Text('getTests()'),
|
||||||
@@ -250,7 +240,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
logger.finest(
|
logger.finest(
|
||||||
"getOmissions(): ${await widget.data.client!.getOmissions()}",
|
"getOmissions(): ${await widget.data.client.getOmissions(forceCache: useCache)}",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('getOmissions()'),
|
child: const Text('getOmissions()'),
|
||||||
@@ -272,18 +262,13 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final isar = widget.data.isar;
|
final isar = widget.data.isar;
|
||||||
await isar.writeTxn(() async {
|
await isar.writeTxn(() async {
|
||||||
await isar.subjectCacheModels.clear();
|
await isar.genericCacheModels.clear();
|
||||||
await isar.testCacheModels.clear();
|
await isar.timetableCacheModels.clear();
|
||||||
await isar.gradeCacheModels.clear();
|
|
||||||
await isar.omissionCacheModels.clear();
|
|
||||||
await isar.messageCacheModels.clear();
|
|
||||||
await isar.classGroupCacheModels.clear();
|
|
||||||
await isar.classAverageCacheModels.clear();
|
|
||||||
await isar.lessonCacheModels.clear();
|
|
||||||
await isar.teacherModels.clear();
|
|
||||||
await isar.homeworkCacheModels.clear();
|
await isar.homeworkCacheModels.clear();
|
||||||
});
|
});
|
||||||
|
widget.data.client.evictMemCache();
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
|
await WidgetCacheHelper.clearIOSWidgets();
|
||||||
} else {
|
} else {
|
||||||
final dataDir = await getApplicationDocumentsDirectory();
|
final dataDir = await getApplicationDocumentsDirectory();
|
||||||
final widgetFile = File(
|
final widgetFile = File(
|
||||||
@@ -315,21 +300,13 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
await isar.tokenModels.clear();
|
await isar.tokenModels.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
widget.data.tokens = List.empty(growable: true);
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
context.go('/login');
|
context.go('/login');
|
||||||
},
|
},
|
||||||
child: const Text('wipe users'),
|
child: const Text('wipe users'),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
|
||||||
Wrap(
|
|
||||||
alignment: WrapAlignment.center,
|
|
||||||
spacing: 16,
|
|
||||||
runSpacing: 16,
|
|
||||||
children: [
|
|
||||||
for (final entry in _themeColorSwatches())
|
|
||||||
_themeColorSwatch(context, entry.$1, entry.$2),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 600,
|
height: 600,
|
||||||
child: GridView.count(
|
child: GridView.count(
|
||||||
@@ -347,7 +324,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
child: FirkaIconWidget(
|
child: FirkaIconWidget(
|
||||||
FirkaIconType.majesticons,
|
FirkaIconType.majesticons,
|
||||||
getIconData(e),
|
getIconData(e),
|
||||||
color: appStyle.colors.textPrimary,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -373,70 +350,3 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<(String, Color)> _themeColorSwatches() {
|
|
||||||
final c = appStyle.colors;
|
|
||||||
return [
|
|
||||||
("background", c.background),
|
|
||||||
("backgroundAmoled", c.backgroundAmoled),
|
|
||||||
("background0p", c.background0p),
|
|
||||||
("success", c.success),
|
|
||||||
("textPrimary", c.textPrimary),
|
|
||||||
("textSecondary", c.textSecondary),
|
|
||||||
("textTertiary", c.textTertiary),
|
|
||||||
if (c.textTeritary != null) ("textTeritary", c.textTeritary!),
|
|
||||||
("textPrimaryLight", c.textPrimaryLight),
|
|
||||||
("textSecondaryLight", c.textSecondaryLight),
|
|
||||||
("textTertiaryLight", c.textTertiaryLight),
|
|
||||||
("card", c.card),
|
|
||||||
("cardTranslucent", c.cardTranslucent),
|
|
||||||
("buttonSecondaryFill", c.buttonSecondaryFill),
|
|
||||||
("buttonDisabledIcon", c.buttonDisabledIcon),
|
|
||||||
("accent", c.accent),
|
|
||||||
("secondary", c.secondary),
|
|
||||||
("shadowColor", c.shadowColor),
|
|
||||||
("a10p", c.a10p),
|
|
||||||
("a15p", c.a15p),
|
|
||||||
("warningAccent", c.warningAccent),
|
|
||||||
("warningText", c.warningText),
|
|
||||||
("warning15p", c.warning15p),
|
|
||||||
("warningCard", c.warningCard),
|
|
||||||
("errorAccent", c.errorAccent),
|
|
||||||
("errorText", c.errorText),
|
|
||||||
("error15p", c.error15p),
|
|
||||||
("errorCard", c.errorCard),
|
|
||||||
("grade5", c.grade5),
|
|
||||||
("grade4", c.grade4),
|
|
||||||
("grade3", c.grade3),
|
|
||||||
("grade2", c.grade2),
|
|
||||||
("grade1", c.grade1),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _themeColorSwatch(BuildContext context, String name, Color color) {
|
|
||||||
final darkBg = color.computeLuminance() > 0.5;
|
|
||||||
final bg = darkBg ? const Color(0xFF121212) : const Color(0xFFF2F2F2);
|
|
||||||
final labelColor = darkBg ? const Color(0xFFF2F2F2) : const Color(0xFF121212);
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: bg,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
name,
|
|
||||||
style: TextTheme.of(context).bodySmall?.copyWith(color: labelColor),
|
|
||||||
),
|
|
||||||
FilledCircle(
|
|
||||||
diameter: 40,
|
|
||||||
color: color,
|
|
||||||
child: const SizedBox(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/data/models/app_settings_model.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/ui/components/firka_button.dart';
|
import 'package:firka/ui/components/firka_button.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -109,7 +109,19 @@ class _BetaScreenState extends FirkaState<BetaScreen> {
|
|||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (counter != 0) return;
|
if (counter != 0) return;
|
||||||
await Settings.betaWarning.set(true);
|
await widget.data.isar.writeTxn(() async {
|
||||||
|
widget.data.settings
|
||||||
|
.group("settings")
|
||||||
|
.setBoolean("beta_warning", true);
|
||||||
|
|
||||||
|
await widget.data.settings
|
||||||
|
.group("settings")["beta_warning"]!
|
||||||
|
.save(widget.data.isar.appSettingsModels);
|
||||||
|
});
|
||||||
|
|
||||||
|
await widget.data.settings
|
||||||
|
.group("settings")["beta_warning"]!
|
||||||
|
.postUpdate();
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
context.go('/home');
|
context.go('/home');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,24 +1,37 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
import 'package:firka/api/client/kreta_stream.dart';
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/core/firka_bundle.dart';
|
import 'package:firka/core/firka_bundle.dart';
|
||||||
|
import 'package:firka/services/active_account_helper.dart';
|
||||||
import 'package:firka/services/live_activity_service.dart';
|
import 'package:firka/services/live_activity_service.dart';
|
||||||
import 'package:firka/core/settings.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka/core/settings/settings_repository.dart';
|
import 'package:firka/services/watch_sync_helper.dart';
|
||||||
import 'package:firka/core/settings/settings_schema.dart';
|
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
import 'package:firka/ui/phone/pages/extras/reauth_toast.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:home_widget/home_widget.dart';
|
import 'package:home_widget/home_widget.dart';
|
||||||
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
|
import 'package:firka/data/widget.dart';
|
||||||
|
import 'package:firka/core/debug_helper.dart';
|
||||||
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||||
|
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||||
import 'package:firka/core/state/firka_state.dart';
|
import 'package:firka/core/state/firka_state.dart';
|
||||||
import 'package:firka/core/image_preloader.dart';
|
import 'package:firka/core/image_preloader.dart';
|
||||||
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
|
import '../../pages/extras/main_error.dart';
|
||||||
|
|
||||||
bool _fetching = false;
|
enum ActiveToastType { fetching, error, reauth, none }
|
||||||
|
|
||||||
|
bool _fetching = true;
|
||||||
bool _prefetched = false;
|
bool _prefetched = false;
|
||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
@@ -32,10 +45,16 @@ class HomeScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _HomeScreenState extends FirkaState<HomeScreen>
|
class _HomeScreenState extends FirkaState<HomeScreen>
|
||||||
with WidgetsBindingObserver {
|
with WidgetsBindingObserver {
|
||||||
|
Widget? toast;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
bool _preloadDone = false;
|
||||||
|
bool _didRunSecondaryICloudRecovery = false;
|
||||||
|
bool _prefetchInProgress = false;
|
||||||
bool _didRunLiveActivityLogin = false;
|
bool _didRunLiveActivityLogin = false;
|
||||||
bool _hasCompletedFirstPrefetch = false;
|
bool _hasCompletedFirstPrefetch = false;
|
||||||
|
|
||||||
|
ActiveToastType activeToast = ActiveToastType.none;
|
||||||
|
|
||||||
void _setupNotificationListener() {
|
void _setupNotificationListener() {
|
||||||
final notificationChannel = MethodChannel('firka.app/notifications');
|
final notificationChannel = MethodChannel('firka.app/notifications');
|
||||||
|
|
||||||
@@ -90,8 +109,63 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _runSecondaryICloudRecoveryIfNeeded() async {
|
||||||
|
if (!Platform.isIOS || _didRunSecondaryICloudRecovery) return;
|
||||||
|
_didRunSecondaryICloudRecovery = true;
|
||||||
|
|
||||||
|
final activeToken = pickActiveToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
preferredStudentIdNorm: initData.client.model.studentIdNorm,
|
||||||
|
);
|
||||||
|
|
||||||
|
final now = DateTime.now();
|
||||||
|
final shouldRunRecovery =
|
||||||
|
initData.client.needsReauth ||
|
||||||
|
activeToken == null ||
|
||||||
|
activeToken.expiryDate == null ||
|
||||||
|
activeToken.expiryDate!.isBefore(now.add(const Duration(seconds: 60)));
|
||||||
|
|
||||||
|
if (!shouldRunRecovery) return;
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
'[Home] Secondary iCloud recovery scheduled (5s delay, startup safety pass)',
|
||||||
|
);
|
||||||
|
await Future.delayed(const Duration(seconds: 5));
|
||||||
|
if (_disposed) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final recovered = await WatchSyncHelper.checkAndRecoverFromiCloud(
|
||||||
|
isar: initData.isar,
|
||||||
|
tokens: initData.tokens,
|
||||||
|
client: initData.client,
|
||||||
|
);
|
||||||
|
if (!recovered) {
|
||||||
|
logger.info('[Home] Secondary iCloud recovery found no fresher token');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final refreshedTokens = initDone ? initData.tokens : initData.tokens;
|
||||||
|
initData.tokens = refreshedTokens;
|
||||||
|
|
||||||
|
final selectedToken = pickActiveToken(
|
||||||
|
tokens: refreshedTokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
preferredStudentIdNorm: initData.client.model.studentIdNorm,
|
||||||
|
);
|
||||||
|
if (selectedToken != null) {
|
||||||
|
initData.client.model = selectedToken;
|
||||||
|
}
|
||||||
|
initData.reauthCubit?.clear();
|
||||||
|
logger.info('[Home] Secondary iCloud recovery applied a fresher token');
|
||||||
|
} catch (e) {
|
||||||
|
logger.warning('[Home] Secondary iCloud recovery failed: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void prefetch() async {
|
void prefetch() async {
|
||||||
if (_prefetched || _fetching) return;
|
if (_prefetched) return;
|
||||||
|
if (_prefetchInProgress) return;
|
||||||
|
|
||||||
final lifecycle = WidgetsBinding.instance.lifecycleState;
|
final lifecycle = WidgetsBinding.instance.lifecycleState;
|
||||||
if (lifecycle != null && lifecycle != AppLifecycleState.resumed) {
|
if (lifecycle != null && lifecycle != AppLifecycleState.resumed) {
|
||||||
@@ -101,13 +175,28 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
_prefetchInProgress = true;
|
||||||
_fetching = true;
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
await initData.client!.renewCache(reInit: true);
|
_prefetched = true;
|
||||||
|
|
||||||
|
await _runSecondaryICloudRecoveryIfNeeded();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await initData.client.refreshTokenProactively().timeout(
|
||||||
|
const Duration(seconds: 60),
|
||||||
|
onTimeout: () {
|
||||||
|
logger.warning('[Home] Token refresh/recovery timed out after 60s');
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warning('[Home] Token refresh/recovery failed: $e');
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetchData();
|
||||||
|
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
|
await WidgetCacheHelper.updateWidgetCache(appStyle, initData.client);
|
||||||
await HomeWidget.updateWidget(
|
await HomeWidget.updateWidget(
|
||||||
qualifiedAndroidName:
|
qualifiedAndroidName:
|
||||||
"app.firka.naplo.glance.TimetableWidgetReceiver",
|
"app.firka.naplo.glance.TimetableWidgetReceiver",
|
||||||
@@ -115,12 +204,20 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
|
await WidgetCacheHelper.refreshIOSWidgets(
|
||||||
|
initData.client,
|
||||||
|
initData.settings,
|
||||||
|
);
|
||||||
|
|
||||||
if (!_didRunLiveActivityLogin) {
|
if (!_didRunLiveActivityLogin) {
|
||||||
_didRunLiveActivityLogin = true;
|
_didRunLiveActivityLogin = true;
|
||||||
final token = initData.client!.cache.token;
|
final token = pickActiveToken(
|
||||||
final studentName = token.username;
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
);
|
||||||
|
final studentName = token?.studentId ?? "Student";
|
||||||
LiveActivityService.onUserLogin(
|
LiveActivityService.onUserLogin(
|
||||||
client: initData.client!,
|
client: initData.client,
|
||||||
studentName: studentName,
|
studentName: studentName,
|
||||||
settingsStore: initData.settings,
|
settingsStore: initData.settings,
|
||||||
).catchError((e, st) {
|
).catchError((e, st) {
|
||||||
@@ -128,20 +225,173 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_disposed &&
|
||||||
|
(LiveActivityService.isTokenExpired || initData.client.needsReauth)) {
|
||||||
|
activeToast = ActiveToastType.reauth;
|
||||||
|
setState(() {
|
||||||
|
toast = buildReauthToast(context, initData, () {
|
||||||
|
if (!_disposed) {
|
||||||
|
setState(() {
|
||||||
|
activeToast = ActiveToastType.none;
|
||||||
|
toast = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e is TokenExpiredException || e is InvalidGrantException) {
|
||||||
|
activeToast = ActiveToastType.reauth;
|
||||||
|
if (_disposed) return;
|
||||||
|
setState(() {
|
||||||
|
toast = buildReauthToast(context, initData, () {
|
||||||
|
if (!_disposed) {
|
||||||
|
setState(() {
|
||||||
|
activeToast = ActiveToastType.none;
|
||||||
|
toast = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
activeToast = ActiveToastType.error;
|
||||||
|
var dismissDelay = 120;
|
||||||
|
if (kDebugMode) dismissDelay = 2;
|
||||||
|
Timer(Duration(seconds: dismissDelay), () {
|
||||||
|
if (_disposed) return;
|
||||||
|
setState(() {
|
||||||
|
activeToast = ActiveToastType.none;
|
||||||
|
toast = null;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (_disposed) return;
|
if (_disposed) return;
|
||||||
(context);
|
setState(() {
|
||||||
|
toast = Positioned(
|
||||||
|
top: MediaQuery.of(context).size.height / 1.6,
|
||||||
|
left: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
bottom: 0,
|
||||||
|
child: Center(
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.errorCard,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(200)),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
initData.l10n.api_error,
|
||||||
|
style: appStyle.fonts.B_16SB.copyWith(
|
||||||
|
color: appStyle.colors.errorText,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
GestureDetector(
|
||||||
|
child: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.questionCircleSolid,
|
||||||
|
color: appStyle.colors.errorAccent,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
var stackTrace = "";
|
||||||
|
if (e is Error && e.stackTrace != null) {
|
||||||
|
stackTrace = e.stackTrace.toString();
|
||||||
|
}
|
||||||
|
showErrorBottomSheet(context, "$e\n$stackTrace");
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
_prefetchInProgress = false;
|
||||||
_hasCompletedFirstPrefetch = true;
|
_hasCompletedFirstPrefetch = true;
|
||||||
if (!_disposed) {
|
if (!_disposed) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_prefetched = true;
|
|
||||||
_fetching = false;
|
_fetching = false;
|
||||||
|
if (activeToast == ActiveToastType.fetching) toast = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> fetchData() async {
|
||||||
|
var lessonsFetched = 0;
|
||||||
|
var noticeBoardFetched = 0;
|
||||||
|
var infoBoardFetched = 0;
|
||||||
|
var studentFetched = 0;
|
||||||
|
var testsFetched = 0;
|
||||||
|
var gradesFetched = 0;
|
||||||
|
var homeworkFetched = 0;
|
||||||
|
|
||||||
|
final midnight = timeNow().getMidnight();
|
||||||
|
|
||||||
|
initData.client
|
||||||
|
.getTimeTableStream(
|
||||||
|
midnight,
|
||||||
|
midnight.add(Duration(hours: 23, minutes: 59)),
|
||||||
|
cacheOnly: false,
|
||||||
|
)
|
||||||
|
.forEach((lessons) {
|
||||||
|
lessonsFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getNoticeBoardStream(cacheOnly: false).forEach((items) {
|
||||||
|
noticeBoardFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getInfoBoardStream(cacheOnly: false).forEach((items) {
|
||||||
|
infoBoardFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getStudentStream(cacheOnly: false).forEach((student) {
|
||||||
|
studentFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getTestsStream(cacheOnly: false).forEach((tests) {
|
||||||
|
testsFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getGradesStream(cacheOnly: false).forEach((grades) {
|
||||||
|
gradesFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
initData.client.getHomeworkStream(cacheOnly: false).forEach((homework) {
|
||||||
|
homeworkFetched++;
|
||||||
|
});
|
||||||
|
|
||||||
|
final startTime = DateTime.now();
|
||||||
|
const maxWaitTime = Duration(seconds: 30);
|
||||||
|
|
||||||
|
while (lessonsFetched < 2 ||
|
||||||
|
noticeBoardFetched < 2 ||
|
||||||
|
infoBoardFetched < 2 ||
|
||||||
|
studentFetched < 2 ||
|
||||||
|
testsFetched < 2 ||
|
||||||
|
gradesFetched < 2 ||
|
||||||
|
homeworkFetched < 2) {
|
||||||
|
if (DateTime.now().difference(startTime) > maxWaitTime) {
|
||||||
|
logger.warning('[Home] fetchData timed out after 30s');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -154,7 +404,8 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
prefetch();
|
prefetch();
|
||||||
_preloadImages();
|
_preloadImages();
|
||||||
|
|
||||||
if (Platform.isIOS && Settings.betaWarning.value) {
|
if (Platform.isIOS &&
|
||||||
|
initData.settings.group("settings").boolean("beta_warning")) {
|
||||||
Future.delayed(Duration(seconds: 3), () async {
|
Future.delayed(Duration(seconds: 3), () async {
|
||||||
await LiveActivityService.showConsentScreenIfNeeded();
|
await LiveActivityService.showConsentScreenIfNeeded();
|
||||||
});
|
});
|
||||||
@@ -166,21 +417,83 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _preloadImages() async {
|
Future<void> _preloadImages() async {
|
||||||
final imagePaths = appIconLabels(
|
final imagePaths = initData.settings.appIcons.keys
|
||||||
initData.l10n,
|
.map((icon) => "assets/images/icons/$icon.webp")
|
||||||
).keys.map((icon) => "assets/images/icons/$icon.webp").toList();
|
.toList();
|
||||||
imagePaths.add("assets/images/background.webp");
|
imagePaths.add("assets/images/background.webp");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ImagePreloader.preloadMultipleAssets(FirkaBundle(), imagePaths);
|
await ImagePreloader.preloadMultipleAssets(FirkaBundle(), imagePaths);
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _preloadDone = true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.severe('Home: error preloading images: $e');
|
logger.severe('Home: error preloading images: $e');
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _preloadDone = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (!_preloadDone) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: appStyle.colors.background,
|
||||||
|
body: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
SizedBox(),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [SizedBox(), DelayedSpinnerWidget(), SizedBox()],
|
||||||
|
),
|
||||||
|
SizedBox(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fetching) {
|
||||||
|
if (_disposed) return const SizedBox.shrink();
|
||||||
|
setState(() {
|
||||||
|
activeToast = ActiveToastType.fetching;
|
||||||
|
toast = Positioned(
|
||||||
|
top: MediaQuery.of(context).size.height / 1.6,
|
||||||
|
left: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
bottom: 0,
|
||||||
|
child: Center(
|
||||||
|
child: Card(
|
||||||
|
color: appStyle.colors.card,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
initData.l10n.refreshing,
|
||||||
|
style: appStyle.fonts.B_16SB.copyWith(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
return BlocListener<SettingsCubit, SettingsState>(
|
return BlocListener<SettingsCubit, SettingsState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
@@ -190,11 +503,14 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (mounted) setState(() {});
|
if (mounted) setState(() {});
|
||||||
},
|
},
|
||||||
child: BlocListener<ToastCubit, ToastState>(
|
child: BlocListener<ReauthCubit, ReauthState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (mounted) setState(() {});
|
if (!mounted || _disposed) return;
|
||||||
if (state.type == .none) {
|
if (!state.needsReauth && activeToast == ActiveToastType.reauth) {
|
||||||
initData.homeRefreshCubit.requestRefresh();
|
setState(() {
|
||||||
|
activeToast = ActiveToastType.none;
|
||||||
|
toast = null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
@@ -203,10 +519,7 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: MediaQuery.of(context).size.height,
|
height: MediaQuery.of(context).size.height,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [widget.child, toast ?? SizedBox.shrink()],
|
||||||
widget.child,
|
|
||||||
?(_toastOverlay(context)),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -216,22 +529,14 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget? _toastOverlay(BuildContext context) {
|
|
||||||
final toast = context.watch<ToastCubit>().state;
|
|
||||||
if (toast.type == .fetching && !_hasCompletedFirstPrefetch) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return toast.buildWidget(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
super.didChangeAppLifecycleState(state);
|
super.didChangeAppLifecycleState(state);
|
||||||
if (state == AppLifecycleState.resumed && !_disposed) {
|
if (state == AppLifecycleState.resumed && !_disposed) {
|
||||||
logger.info('[Home] App resumed to foreground, re-running prefetch');
|
logger.info('[Home] App resumed to foreground, re-running prefetch');
|
||||||
_prefetched = false;
|
_prefetched = false;
|
||||||
|
_didRunSecondaryICloudRecovery = false;
|
||||||
prefetch();
|
prefetch();
|
||||||
setState(() {});
|
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
_refreshLiveActivityOnResume();
|
_refreshLiveActivityOnResume();
|
||||||
@@ -247,9 +552,14 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
Future.delayed(const Duration(milliseconds: 500), () async {
|
Future.delayed(const Duration(milliseconds: 500), () async {
|
||||||
if (_disposed || _didRunLiveActivityLogin) return;
|
if (_disposed || _didRunLiveActivityLogin) return;
|
||||||
_didRunLiveActivityLogin = true;
|
_didRunLiveActivityLogin = true;
|
||||||
final studentName = initData.client!.cache.token.username;
|
final token = pickActiveToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
preferredStudentIdNorm: initData.client.model.studentIdNorm,
|
||||||
|
);
|
||||||
|
final studentName = token?.studentId ?? 'Student';
|
||||||
LiveActivityService.onUserLogin(
|
LiveActivityService.onUserLogin(
|
||||||
client: initData.client!,
|
client: initData.client,
|
||||||
studentName: studentName,
|
studentName: studentName,
|
||||||
settingsStore: initData.settings,
|
settingsStore: initData.settings,
|
||||||
).catchError((e, st) {
|
).catchError((e, st) {
|
||||||
@@ -262,9 +572,13 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
void _refreshLiveActivityOnResume() async {
|
void _refreshLiveActivityOnResume() async {
|
||||||
if (!_hasCompletedFirstPrefetch) return;
|
if (!_hasCompletedFirstPrefetch) return;
|
||||||
try {
|
try {
|
||||||
final studentName = initData.client!.cache.token.username;
|
final token = pickActiveToken(
|
||||||
|
tokens: initData.tokens,
|
||||||
|
settings: initData.settings,
|
||||||
|
);
|
||||||
|
final studentName = token?.studentId ?? "Student";
|
||||||
await LiveActivityService.checkAndUpdateTimetable(
|
await LiveActivityService.checkAndUpdateTimetable(
|
||||||
client: initData.client!,
|
client: initData.client,
|
||||||
studentName: studentName,
|
studentName: studentName,
|
||||||
settingsStore: initData.settings,
|
settingsStore: initData.settings,
|
||||||
);
|
);
|
||||||
@@ -282,6 +596,7 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
|||||||
_disposed = true;
|
_disposed = true;
|
||||||
_fetching = false;
|
_fetching = false;
|
||||||
_prefetched = false;
|
_prefetched = false;
|
||||||
|
activeToast = ActiveToastType.none;
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:firka/ui/components/firka_button.dart';
|
import 'package:firka/ui/components/firka_button.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka/ui/phone/screens/live_activity/full_privacy_policy_screen.dart';
|
import 'package:firka/ui/phone/screens/live_activity/full_privacy_policy_screen.dart';
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ import 'package:firka/core/image_preloader.dart';
|
|||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka/ui/shared/delayed_spinner.dart';
|
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||||
|
|
||||||
|
const String _privacyUrlHungarian = 'https://firka.app/privacy-policy';
|
||||||
|
const String _privacyUrlOther = 'https://firka.app/privacy-policy';
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
class LoginScreen extends StatefulWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
const LoginScreen(this.data, {super.key});
|
const LoginScreen(this.data, {super.key});
|
||||||
@@ -41,7 +44,7 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _getPrivacyPolicyUrl() {
|
String _getPrivacyPolicyUrl() {
|
||||||
return "https://firka.app/privacy";
|
return "https://firka.app/privacy";
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showPrivacyPolicyWebview() async {
|
Future<void> _showPrivacyPolicyWebview() async {
|
||||||
@@ -55,7 +58,10 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: MediaQuery.sizeOf(context).height,
|
height: MediaQuery.sizeOf(context).height,
|
||||||
child: DomainBrowserWebviewWidget(data: widget.data, url: url),
|
child: DomainBrowserWebviewWidget(
|
||||||
|
data: widget.data,
|
||||||
|
url: url,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -289,8 +295,7 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 8,
|
horizontal: 8),
|
||||||
),
|
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
builder: (ctx, constraints) =>
|
builder: (ctx, constraints) =>
|
||||||
_FloatingCardsSlide(
|
_FloatingCardsSlide(
|
||||||
@@ -656,7 +661,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
|||||||
double _sceneWidth = 0;
|
double _sceneWidth = 0;
|
||||||
double _sceneHeight = 0;
|
double _sceneHeight = 0;
|
||||||
|
|
||||||
//we needed a cooldown, so that again, the phone doesn't turn into a bomb | EDIT: actually this was fixed by the minimum speed, so we don't need it anymore
|
//we needed a cooldown, so that again, the phone doesn't turn into a bomb | EDIT: actually this was fixed by the minimum speed, so we don't need it anymore
|
||||||
// DateTime? _lastVibration;
|
// DateTime? _lastVibration;
|
||||||
|
|
||||||
Offset _clampVel(Offset v) => Offset(
|
Offset _clampVel(Offset v) => Offset(
|
||||||
@@ -899,7 +904,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
|||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: appStyle.colors.buttonSecondaryFill, //button color xdddd
|
color: appStyle.colors.buttonSecondaryFill, //button color xdddd
|
||||||
borderRadius: BorderRadius.only(
|
borderRadius: BorderRadius.only(
|
||||||
topLeft: Radius.circular(32),
|
topLeft: Radius.circular(32),
|
||||||
topRight: Radius.circular(32),
|
topRight: Radius.circular(32),
|
||||||
@@ -947,7 +952,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black.withValues(alpha: 0.55),
|
color: Colors.black.withOpacity(0.55),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
width: math.min(260, _sceneWidth - 24),
|
width: math.min(260, _sceneWidth - 24),
|
||||||
@@ -968,14 +973,10 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
|||||||
'accel: (${accel.x.toStringAsFixed(2)}, ${accel.y.toStringAsFixed(2)}, ${accel.z.toStringAsFixed(2)})',
|
'accel: (${accel.x.toStringAsFixed(2)}, ${accel.y.toStringAsFixed(2)}, ${accel.z.toStringAsFixed(2)})',
|
||||||
),
|
),
|
||||||
Text('baseline set: ${_baseline != null}'),
|
Text('baseline set: ${_baseline != null}'),
|
||||||
Text(
|
Text('scene: ${_sceneWidth.toStringAsFixed(0)} x ${_sceneHeight.toStringAsFixed(0)}'),
|
||||||
'scene: ${_sceneWidth.toStringAsFixed(0)} x ${_sceneHeight.toStringAsFixed(0)}',
|
|
||||||
),
|
|
||||||
Text('center: ${formatOffset(center)}'),
|
Text('center: ${formatOffset(center)}'),
|
||||||
Text('card[0] pos: ${formatOffset(firstPos)}'),
|
Text('card[0] pos: ${formatOffset(firstPos)}'),
|
||||||
Text(
|
Text('card[0] vel: ${formatOffset(firstVel)} | |v|=${speed.toStringAsFixed(2)}'),
|
||||||
'card[0] vel: ${formatOffset(firstVel)} | |v|=${speed.toStringAsFixed(2)}',
|
|
||||||
),
|
|
||||||
Text('cards: ${_cards.length}'),
|
Text('cards: ${_cards.length}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka_common/data/models/message_cache_model.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_html/flutter_html.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/core/firka_bundle.dart';
|
import 'package:firka/core/firka_bundle.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
@@ -12,7 +12,7 @@ import 'package:url_launcher/url_launcher_string.dart';
|
|||||||
|
|
||||||
class MessageScreen extends StatelessWidget {
|
class MessageScreen extends StatelessWidget {
|
||||||
final AppInitialization data;
|
final AppInitialization data;
|
||||||
final MessageCacheModel message;
|
final MessageItem message;
|
||||||
|
|
||||||
const MessageScreen(this.data, this.message, {super.key});
|
const MessageScreen(this.data, this.message, {super.key});
|
||||||
|
|
||||||
@@ -34,150 +34,143 @@ class MessageScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: SelectionArea(
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Row(
|
||||||
Row(
|
children: [
|
||||||
children: [
|
Transform.translate(
|
||||||
Transform.translate(
|
offset: const Offset(-4, 0),
|
||||||
offset: const Offset(-4, 0),
|
child: GestureDetector(
|
||||||
child: GestureDetector(
|
child: FirkaIconWidget(
|
||||||
child: FirkaIconWidget(
|
FirkaIconType.majesticons,
|
||||||
FirkaIconType.majesticons,
|
Majesticon.chevronLeftLine,
|
||||||
Majesticon.chevronLeftLine,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 1),
|
|
||||||
child: Text(
|
|
||||||
data.l10n.s_a,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 56),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width * 0.85,
|
|
||||||
child: Text(
|
|
||||||
message.title,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
message.createdAt.format(
|
|
||||||
data.l10n,
|
|
||||||
FormatMode.yyyymmdd,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
color: appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
Transform.translate(
|
||||||
SizedBox(height: 56),
|
offset: const Offset(-4, 1),
|
||||||
Row(
|
child: Text(
|
||||||
children: [
|
data.l10n.s_a,
|
||||||
Container(
|
style: appStyle.fonts.B_16R.apply(
|
||||||
decoration: ShapeDecoration(
|
color: appStyle.colors.textPrimary,
|
||||||
color: appStyle.colors.accent,
|
|
||||||
shape: CircleBorder(eccentricity: 1),
|
|
||||||
),
|
),
|
||||||
child: SizedBox(
|
),
|
||||||
width: 28,
|
),
|
||||||
height: 28,
|
],
|
||||||
child: Row(
|
),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
SizedBox(height: 56),
|
||||||
children: [
|
Row(
|
||||||
Padding(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
padding: const EdgeInsets.only(bottom: 6),
|
children: [
|
||||||
child: Text(
|
SizedBox(
|
||||||
message.author[0],
|
width: MediaQuery.of(context).size.width * 0.85,
|
||||||
style: appStyle.fonts.H_18px.copyWith(
|
child: Text(
|
||||||
fontSize: 20,
|
message.title,
|
||||||
color: appStyle.colors.textPrimary,
|
textAlign: TextAlign.center,
|
||||||
),
|
style: appStyle.fonts.H_H2.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
message.date.format(data.l10n, FormatMode.yyyymmdd),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: appStyle.fonts.B_16R.apply(
|
||||||
|
color: appStyle.colors.textSecondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 56),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
shape: CircleBorder(eccentricity: 1),
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 28,
|
||||||
|
height: 28,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 6),
|
||||||
|
child: Text(
|
||||||
|
message.author[0],
|
||||||
|
style: appStyle.fonts.H_18px.copyWith(
|
||||||
|
fontSize: 20,
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
),
|
||||||
Column(
|
SizedBox(width: 8),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
SizedBox(
|
children: [
|
||||||
width:
|
SizedBox(
|
||||||
MediaQuery.of(context).size.width / 1.4,
|
width: MediaQuery.of(context).size.width / 1.4,
|
||||||
child: Text(
|
child: Text(
|
||||||
message.author,
|
message.author,
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
style: appStyle.fonts.B_16SB.apply(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SizedBox(height: 20),
|
|
||||||
Flexible(
|
|
||||||
fit: FlexFit.loose,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.card,
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(16),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Padding(
|
],
|
||||||
padding: const EdgeInsets.all(12),
|
),
|
||||||
child: SingleChildScrollView(
|
],
|
||||||
child: Html(
|
),
|
||||||
data: message.contentHtml
|
SizedBox(height: 20),
|
||||||
.withoutFontFeatureSettings(),
|
Flexible(
|
||||||
onLinkTap: (url, map, element) => {
|
fit: FlexFit.loose,
|
||||||
if (url != null) launchUrlString(url),
|
child: Padding(
|
||||||
},
|
padding: const EdgeInsets.all(4),
|
||||||
style: {
|
child: Container(
|
||||||
"*": Style.fromTextStyle(
|
decoration: BoxDecoration(
|
||||||
appStyle.fonts.B_16R.apply(
|
color: appStyle.colors.card,
|
||||||
color: appStyle.colors.textPrimary,
|
borderRadius: BorderRadius.all(
|
||||||
),
|
Radius.circular(16),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Html(
|
||||||
|
data: message.contentHTML,
|
||||||
|
onLinkTap: (url, map, element) => {
|
||||||
|
if (url != null) launchUrlString(url),
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
"*": Style.fromTextStyle(
|
||||||
|
appStyle.fonts.B_16R.apply(
|
||||||
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
},
|
),
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,307 +0,0 @@
|
|||||||
import "dart:io";
|
|
||||||
|
|
||||||
import "package:dart_jsonwebtoken/dart_jsonwebtoken.dart";
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/app/initialization.dart";
|
|
||||||
import "package:firka/services/live_activity_service.dart";
|
|
||||||
import "package:firka/services/watch_sync_helper.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka/ui/phone/widgets/login_webview.dart";
|
|
||||||
import "package:firka_common/data/models/token_model.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:isar_community/isar.dart";
|
|
||||||
|
|
||||||
class SettingsAccountPickerView extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
final List<TokenModel> tokens;
|
|
||||||
final void Function(VoidCallback fn) setStateOuter;
|
|
||||||
|
|
||||||
const SettingsAccountPickerView({
|
|
||||||
required this.data,
|
|
||||||
required this.tokens,
|
|
||||||
required this.setStateOuter,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
for (final token in tokens) ...[
|
|
||||||
_accountRow(context, token),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
GestureDetector(
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
data.l10n.s_acc_add,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
showModalBottomSheet<void>(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
enableDrag: false,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return LoginWebviewWidget(data);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
SizedBox(height: 20),
|
|
||||||
GestureDetector(
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
FirkaIconWidget(
|
|
||||||
FirkaIconType.icons,
|
|
||||||
"group",
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
data.l10n.s_acc_logout,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onTap: () => _logout(context),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _accountRow(BuildContext context, TokenModel token) {
|
|
||||||
final jwt = JWT.decode(token.idToken);
|
|
||||||
final payload = jwt.payload as Map<String, dynamic>;
|
|
||||||
String studentRole = payload["role"];
|
|
||||||
if (studentRole == "Tanulo") {
|
|
||||||
studentRole = "Tanuló";
|
|
||||||
} else if (studentRole == "Gondviselo") {
|
|
||||||
studentRole = "Gondviselő";
|
|
||||||
}
|
|
||||||
|
|
||||||
return GestureDetector(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 52,
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
payload["name"],
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
studentRole,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textTertiary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: [
|
|
||||||
token.key != data.settings.selectedAccountKey
|
|
||||||
? SizedBox()
|
|
||||||
: Checkbox(
|
|
||||||
value: true,
|
|
||||||
fillColor: WidgetStateProperty.resolveWith<Color>((
|
|
||||||
Set<WidgetState> states,
|
|
||||||
) {
|
|
||||||
return appStyle.colors.secondary;
|
|
||||||
}),
|
|
||||||
onChanged: (_) async {
|
|
||||||
setStateOuter(() {});
|
|
||||||
logger.finest('Settings saved');
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () => _switchAccount(context, token),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _switchAccount(BuildContext context, TokenModel token) async {
|
|
||||||
if (token.key == data.settings.selectedAccountKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final previousAccountId = data.client!.cache.token.key;
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
await LiveActivityService.onUserLogout();
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.clearSharedLanguageState();
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to clear shared language state on account switch: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.clearRefreshLeaseForAccount(previousAccountId);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to clear refresh lease on account switch: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await data.settings.setSelectedAccountKey(token.key);
|
|
||||||
await initializeApp();
|
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
var watchReachable = false;
|
|
||||||
try {
|
|
||||||
watchReachable = await WatchSyncHelper.isWatchReachable(
|
|
||||||
forceRefreshInstall: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to query Watch reachability on account switch: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (watchReachable) {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.sendTokenModelToWatch(
|
|
||||||
token,
|
|
||||||
allowExpiredAccessToken: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to send switched account token to reachable Watch: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.saveTokenToiCloud(
|
|
||||||
token,
|
|
||||||
forceAccountSwitch: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to sync switched account token to iCloud: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!context.mounted) return;
|
|
||||||
final nav = Navigator.of(context);
|
|
||||||
if (nav.canPop()) nav.pop();
|
|
||||||
appRouter?.go('/home');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _logout(BuildContext context) async {
|
|
||||||
try {
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
await LiveActivityService.onUserLogout();
|
|
||||||
}
|
|
||||||
|
|
||||||
final active = data.client!.cache.token.key;
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.clearRefreshLeaseForAccount(active);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to clear refresh lease for active account: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.clearSharedLanguageState();
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to clear shared language state on logout: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await data.isar.writeTxn(() async {
|
|
||||||
await data.isar.tokenModels.delete(active);
|
|
||||||
});
|
|
||||||
await data.settings.setSelectedAccountKey(0);
|
|
||||||
|
|
||||||
final accounts = await data.isar.tokenModels.where().findAll();
|
|
||||||
|
|
||||||
if (accounts.isEmpty) {
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.clearICloudToken(notifyWatch: true);
|
|
||||||
await WatchSyncHelper.clearAllRefreshLeases();
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning('[Settings] Failed to clear iCloud token: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
final nextToken = accounts.first;
|
|
||||||
var watchReachable = false;
|
|
||||||
try {
|
|
||||||
watchReachable = await WatchSyncHelper.isWatchReachable(
|
|
||||||
forceRefreshInstall: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to query Watch reachability after logout: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (watchReachable) {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.sendTokenModelToWatch(
|
|
||||||
nextToken,
|
|
||||||
allowExpiredAccessToken: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to send next account token to reachable Watch after logout: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
await WatchSyncHelper.saveTokenToiCloud(
|
|
||||||
nextToken,
|
|
||||||
forceAccountSwitch: true,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
logger.warning(
|
|
||||||
'[Settings] Failed to sync next account token to iCloud after logout: $e',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await initializeApp();
|
|
||||||
|
|
||||||
if (!context.mounted) return;
|
|
||||||
final nav = Navigator.of(context);
|
|
||||||
if (nav.canPop()) nav.pop();
|
|
||||||
if (accounts.isEmpty) {
|
|
||||||
appRouter?.go('/login');
|
|
||||||
} else {
|
|
||||||
appRouter?.go('/home');
|
|
||||||
}
|
|
||||||
} catch (e, st) {
|
|
||||||
logger.shout('[Settings] Logout failed: $e', e, st);
|
|
||||||
if (context.mounted) {
|
|
||||||
final nav = Navigator.of(context);
|
|
||||||
if (nav.canPop()) nav.pop();
|
|
||||||
}
|
|
||||||
appRouter?.go('/login');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/core/bloc/app_icon_picker_cubit.dart";
|
|
||||||
import "package:firka/core/image_preloader.dart";
|
|
||||||
import "package:firka/core/settings.dart";
|
|
||||||
import "package:firka/core/settings/settings_repository.dart";
|
|
||||||
import "package:firka/core/settings/settings_schema.dart";
|
|
||||||
import "package:firka/core/settings/settings_ui.dart";
|
|
||||||
import "package:firka/core/firka_bundle.dart";
|
|
||||||
import "package:firka/ui/components/firka_button.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:flutter_bloc/flutter_bloc.dart";
|
|
||||||
|
|
||||||
import "settings_bool_row.dart";
|
|
||||||
|
|
||||||
class SettingsAppIconPreviewView extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
|
|
||||||
const SettingsAppIconPreviewView({required this.data, super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final activeIcon = context.watch<AppIconPickerCubit>().state.activeIcon;
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
image: DecorationImage(
|
|
||||||
image: PreloadedImageProvider(
|
|
||||||
FirkaBundle(),
|
|
||||||
('assets/images/background.webp'),
|
|
||||||
),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
||||||
),
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
|
||||||
child: Image(
|
|
||||||
image: PreloadedImageProvider(
|
|
||||||
FirkaBundle(),
|
|
||||||
"assets/images/icons/$activeIcon.webp",
|
|
||||||
),
|
|
||||||
width: 74,
|
|
||||||
height: 74,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
appIconLabels(data.l10n)[activeIcon]!,
|
|
||||||
style: appStyle.fonts.H_12px.apply(
|
|
||||||
color: appStyle.colors.card,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsAppIconPickerView extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
final SettingsUiAppIconPicker item;
|
|
||||||
final SettingsRepository settings;
|
|
||||||
final void Function(VoidCallback fn) setStateOuter;
|
|
||||||
|
|
||||||
const SettingsAppIconPickerView({
|
|
||||||
required this.data,
|
|
||||||
required this.item,
|
|
||||||
required this.settings,
|
|
||||||
required this.setStateOuter,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final cubit = context.watch<AppIconPickerCubit>();
|
|
||||||
final activeIcon = cubit.state.activeIcon;
|
|
||||||
final saving = cubit.state.saving;
|
|
||||||
|
|
||||||
List<Widget> pWidgets = [];
|
|
||||||
|
|
||||||
for (var group in item.iconGroups.keys) {
|
|
||||||
if (Settings.childProtection.value) {
|
|
||||||
if (group == data.l10n.s_ci_icon_g7) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (group == data.l10n.s_ci_icon_g8) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<Widget> groupIcons = [];
|
|
||||||
for (var icon in item.iconGroups[group]!) {
|
|
||||||
var active = icon == activeIcon;
|
|
||||||
|
|
||||||
groupIcons.add(
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
child: active
|
|
||||||
? Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: const BorderRadius.all(
|
|
||||||
Radius.circular(12.0),
|
|
||||||
),
|
|
||||||
child: Image(
|
|
||||||
image: PreloadedImageProvider(
|
|
||||||
FirkaBundle(),
|
|
||||||
"assets/images/icons/$icon.webp",
|
|
||||||
),
|
|
||||||
width: 48,
|
|
||||||
height: 48,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: ClipRRect(
|
|
||||||
borderRadius: const BorderRadius.all(
|
|
||||||
Radius.circular(16.0),
|
|
||||||
),
|
|
||||||
child: Image(
|
|
||||||
image: PreloadedImageProvider(
|
|
||||||
FirkaBundle(),
|
|
||||||
"assets/images/icons/$icon.webp",
|
|
||||||
),
|
|
||||||
width: 54,
|
|
||||||
height: 54,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
if (saving) return;
|
|
||||||
|
|
||||||
cubit.select(icon);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
appIconLabels(data.l10n)[icon]!,
|
|
||||||
style: appStyle.fonts.B_12R.apply(
|
|
||||||
color: active
|
|
||||||
? appStyle.colors.textPrimary
|
|
||||||
: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pWidgets.add(
|
|
||||||
Text(
|
|
||||||
group,
|
|
||||||
style: appStyle.fonts.H_14px.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (group == data.l10n.s_ci_icon_g6) {
|
|
||||||
pWidgets.add(
|
|
||||||
Text(
|
|
||||||
data.l10n.s_ci_icon_g6_desc,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group == data.l10n.s_ci_icon_g7 || group == data.l10n.s_ci_icon_g8) {
|
|
||||||
pWidgets.add(SizedBox(height: 12));
|
|
||||||
pWidgets.add(
|
|
||||||
buildBoolRow(item.childProtection, settings, setStateOuter),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pWidgets.add(SizedBox(height: 12));
|
|
||||||
pWidgets.add(
|
|
||||||
SizedBox(
|
|
||||||
height: (groupIcons.length / 4).ceil() * 100,
|
|
||||||
child: GridView.count(
|
|
||||||
crossAxisCount: 4,
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
children: groupIcons,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: MediaQuery.of(context).size.height / 1.7,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: pWidgets,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
child: FirkaButton(
|
|
||||||
text: data.l10n.cancel,
|
|
||||||
bgColor: appStyle.colors.buttonSecondaryFill,
|
|
||||||
fontStyle: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
GestureDetector(
|
|
||||||
child: FirkaButton(
|
|
||||||
text: data.l10n.save,
|
|
||||||
bgColor: appStyle.colors.accent,
|
|
||||||
fontStyle: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textSecondaryLight,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () async {
|
|
||||||
if (saving) return;
|
|
||||||
|
|
||||||
await cubit.save(
|
|
||||||
appIconLabels(
|
|
||||||
data.l10n,
|
|
||||||
).keys.where((e) => e != "original").toList(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import "package:firka/core/settings/settings_repository.dart";
|
|
||||||
import "package:firka/core/settings/settings_ui.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
Widget buildBoolRow(
|
|
||||||
SettingsUiBoolean item,
|
|
||||||
SettingsRepository settings,
|
|
||||||
void Function(VoidCallback fn) setStateOuter,
|
|
||||||
) {
|
|
||||||
final value = settings.get(item.setting);
|
|
||||||
|
|
||||||
return FirkaCard(
|
|
||||||
height: 52 + 12,
|
|
||||||
left: [
|
|
||||||
item.iconType != null
|
|
||||||
? Row(
|
|
||||||
children: [
|
|
||||||
FirkaIconWidget(
|
|
||||||
item.iconType!,
|
|
||||||
item.iconData!,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
SizedBox(width: 4),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: SizedBox(),
|
|
||||||
Text(
|
|
||||||
item.title,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: [
|
|
||||||
Switch(
|
|
||||||
value: value,
|
|
||||||
thumbColor: WidgetStateProperty.fromMap({
|
|
||||||
WidgetState.selected: appStyle.colors.buttonSecondaryFill,
|
|
||||||
WidgetState.any: appStyle.colors.accent,
|
|
||||||
}),
|
|
||||||
trackColor: WidgetStateProperty.fromMap({
|
|
||||||
WidgetState.selected: appStyle.colors.accent,
|
|
||||||
WidgetState.any: appStyle.colors.a10p,
|
|
||||||
}),
|
|
||||||
trackOutlineColor: WidgetStateProperty.fromMap({
|
|
||||||
WidgetState.selected: appStyle.colors.accent,
|
|
||||||
WidgetState.any: appStyle.colors.a15p,
|
|
||||||
}),
|
|
||||||
onChanged: (v) async {
|
|
||||||
await settings.set(item.setting, v);
|
|
||||||
setStateOuter(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
import "package:flutter/foundation.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
class SettingsLicensePageView extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
|
|
||||||
const SettingsLicensePageView({required this.data, super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return FutureBuilder<List<LicenseEntry>>(
|
|
||||||
future: LicenseRegistry.licenses.toList(),
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<List<LicenseEntry>> snapshot) {
|
|
||||||
if (!snapshot.hasData) {
|
|
||||||
return Center(
|
|
||||||
child: CircularProgressIndicator(color: appStyle.colors.accent),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final licenses = snapshot.data!;
|
|
||||||
final shownPackages = <String>{};
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: licenses
|
|
||||||
.where(
|
|
||||||
(license) => license.packages.any(
|
|
||||||
(pkg) => !shownPackages.contains(pkg),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.map((license) {
|
|
||||||
final packageName = license.packages.firstWhere(
|
|
||||||
(pkg) => !shownPackages.contains(pkg),
|
|
||||||
orElse: () => license.packages.first,
|
|
||||||
);
|
|
||||||
shownPackages.add(packageName);
|
|
||||||
final paragraphs = license.paragraphs
|
|
||||||
.map((p) => p.text)
|
|
||||||
.join('\n\n');
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
backgroundColor: appStyle.colors.card,
|
|
||||||
title: Text(
|
|
||||||
packageName,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
content: SingleChildScrollView(
|
|
||||||
child: Text(
|
|
||||||
paragraphs,
|
|
||||||
style: appStyle.fonts.B_15SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
child: Text(
|
|
||||||
data.l10n.close,
|
|
||||||
style: appStyle.fonts.B_14R.apply(
|
|
||||||
color:
|
|
||||||
appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
packageName,
|
|
||||||
style: appStyle.fonts.B_14R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import "dart:io";
|
|
||||||
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
import "package:path/path.dart" as p;
|
|
||||||
import "package:share_plus/share_plus.dart";
|
|
||||||
|
|
||||||
class SettingsLogsView extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
|
|
||||||
const SettingsLogsView({required this.data, super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final logFileRegex = RegExp(r'^(\d{4})_(\d{2})_(\d{2})\.log$');
|
|
||||||
final entries = data.appDir
|
|
||||||
.listSync()
|
|
||||||
.whereType<File>()
|
|
||||||
.where((entity) => logFileRegex.hasMatch(entity.uri.pathSegments.last))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
for (final entity in entries) ...[
|
|
||||||
GestureDetector(
|
|
||||||
child: SizedBox(
|
|
||||||
height: 52,
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.noteTextSolid,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
entity.uri.pathSegments.last,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () => _shareLog(entity),
|
|
||||||
),
|
|
||||||
SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _shareLog(File entity) async {
|
|
||||||
final name = entity.uri.pathSegments.last;
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.info("Compressing log file: ${entity.path}");
|
|
||||||
final originalBytes = await entity.readAsBytes();
|
|
||||||
final gzBytes = GZipCodec().encode(originalBytes);
|
|
||||||
final tempDir = await Directory.systemTemp.createTemp('firka');
|
|
||||||
final gzPath = p.join(tempDir.path, '${p.basename(entity.path)}.gz');
|
|
||||||
final gzFile = await File(gzPath).writeAsBytes(gzBytes, flush: true);
|
|
||||||
|
|
||||||
final params = ShareParams(
|
|
||||||
text: name,
|
|
||||||
files: [XFile(gzFile.path, mimeType: 'application/gzip')],
|
|
||||||
);
|
|
||||||
|
|
||||||
await SharePlus.instance.share(params);
|
|
||||||
|
|
||||||
await gzFile.delete();
|
|
||||||
await tempDir.delete();
|
|
||||||
} catch (ex) {
|
|
||||||
if (ex is Error) {
|
|
||||||
logger.shout(
|
|
||||||
"Failed to compress log file",
|
|
||||||
ex.toString(),
|
|
||||||
ex.stackTrace,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
logger.shout("Failed to compress log file", ex.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Sharing regular log file instead: ${entity.path}");
|
|
||||||
final params = ShareParams(
|
|
||||||
text: name,
|
|
||||||
files: [XFile(entity.path, mimeType: 'text/plain')],
|
|
||||||
);
|
|
||||||
|
|
||||||
await SharePlus.instance.share(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,797 +0,0 @@
|
|||||||
import "dart:io";
|
|
||||||
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/core/bloc/theme_cubit.dart";
|
|
||||||
import "package:firka/core/settings/settings_repository.dart";
|
|
||||||
import "package:firka/core/settings/settings_schema.dart";
|
|
||||||
import "package:firka/core/settings/settings_ui.dart";
|
|
||||||
import "package:firka/core/settings/title_font.dart";
|
|
||||||
import "package:firka/l10n/app_localizations.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
import "package:firka_common/ui/theme/core_theme.dart";
|
|
||||||
import "package:firka_common/ui/theme/grade_theme.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:flutter_bloc/flutter_bloc.dart";
|
|
||||||
import "package:go_router/go_router.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
|
|
||||||
class SettingsPersonalizationView extends StatefulWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
final SettingsUiPersonalization item;
|
|
||||||
|
|
||||||
const SettingsPersonalizationView({
|
|
||||||
required this.data,
|
|
||||||
required this.item,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SettingsPersonalizationView> createState() =>
|
|
||||||
_SettingsPersonalizationViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SettingsPersonalizationViewState
|
|
||||||
extends State<SettingsPersonalizationView> {
|
|
||||||
bool _fontPickerExpanded = false;
|
|
||||||
|
|
||||||
SettingsRepository get _settings => widget.data.settings;
|
|
||||||
AppLocalizations get _l10n => widget.data.l10n;
|
|
||||||
|
|
||||||
Color get _mutedCardColor => appStyle.isLight
|
|
||||||
? const Color(0xFFE4EBC8)
|
|
||||||
: appStyle.colors.buttonSecondaryFill;
|
|
||||||
|
|
||||||
Color get _selectedSurface => appStyle.colors.buttonSecondaryFill;
|
|
||||||
|
|
||||||
Widget _sectionLabel(String text) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 16),
|
|
||||||
child: Text(
|
|
||||||
text,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _externalArrow() {
|
|
||||||
return RotationTransition(
|
|
||||||
turns: const AlwaysStoppedAnimation(-45 / 360),
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.arrowRightLine,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _shortcutRow({
|
|
||||||
required String title,
|
|
||||||
FirkaIconType? iconType,
|
|
||||||
Object? iconData,
|
|
||||||
VoidCallback? onTap,
|
|
||||||
}) {
|
|
||||||
final left = <Widget>[];
|
|
||||||
if (iconType != null && iconData != null) {
|
|
||||||
left.add(
|
|
||||||
FirkaIconWidget(
|
|
||||||
iconType,
|
|
||||||
iconData,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
left.add(const SizedBox(width: 8));
|
|
||||||
}
|
|
||||||
left.add(
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: FirkaCard(
|
|
||||||
left: left,
|
|
||||||
right: [_externalArrow()],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _chip(String label, {required bool selected}) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: selected ? _selectedSurface : appStyle.colors.card,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
blurRadius: appStyle.isLight ? 2 : 0,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: (selected ? appStyle.fonts.B_16SB : appStyle.fonts.B_16R).apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Color> _coreSwatch(CoreThemeColors colors) {
|
|
||||||
return [
|
|
||||||
colors.secondary,
|
|
||||||
colors.accent,
|
|
||||||
colors.background,
|
|
||||||
colors.card,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Color> _gradeSwatch(GradeThemeColors colors) {
|
|
||||||
return [
|
|
||||||
colors.grade5,
|
|
||||||
colors.grade4,
|
|
||||||
colors.grade3,
|
|
||||||
colors.grade2,
|
|
||||||
colors.grade1,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _coreThemePager() {
|
|
||||||
final cores = coreThemes.values.toList(growable: false);
|
|
||||||
final selectedId = _settings.get(SettingsRegistry.selectedCoreThemeId);
|
|
||||||
var selectedIndex = cores.indexWhere((theme) => theme.id == selectedId);
|
|
||||||
if (selectedIndex < 0) selectedIndex = 0;
|
|
||||||
|
|
||||||
return _PresetSwatchPager(
|
|
||||||
key: const ValueKey("core-themes"),
|
|
||||||
swatches: [
|
|
||||||
for (final core in cores)
|
|
||||||
_coreSwatch(core.forBrightness(appStyle.isLight)),
|
|
||||||
],
|
|
||||||
selectedIndex: selectedIndex,
|
|
||||||
onSelected: (index) async {
|
|
||||||
await _settings.set(
|
|
||||||
SettingsRegistry.selectedCoreThemeId,
|
|
||||||
cores[index].id,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _gradeThemePager() {
|
|
||||||
final grades = gradeThemes.values.toList(growable: false);
|
|
||||||
final selectedId = _settings.get(SettingsRegistry.selectedGradeThemeId);
|
|
||||||
var selectedIndex = grades.indexWhere((theme) => theme.id == selectedId);
|
|
||||||
if (selectedIndex < 0) selectedIndex = 0;
|
|
||||||
|
|
||||||
return _PresetSwatchPager(
|
|
||||||
key: const ValueKey("grade-themes"),
|
|
||||||
swatches: [
|
|
||||||
for (final grade in grades)
|
|
||||||
_gradeSwatch(grade.forBrightness(appStyle.isLight)),
|
|
||||||
],
|
|
||||||
selectedIndex: selectedIndex,
|
|
||||||
onSelected: (index) async {
|
|
||||||
await _settings.set(
|
|
||||||
SettingsRegistry.selectedGradeThemeId,
|
|
||||||
grades[index].id,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _stubCustomizeButton() {
|
|
||||||
return FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
_l10n.s_c_customize,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _checkMark() {
|
|
||||||
return SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: Checkbox(
|
|
||||||
value: true,
|
|
||||||
fillColor: WidgetStateProperty.resolveWith<Color>((_) {
|
|
||||||
return appStyle.colors.secondary;
|
|
||||||
}),
|
|
||||||
onChanged: (_) {},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _themeOption(String label, ThemeBrightness value) {
|
|
||||||
final selected = _settings.get(SettingsRegistry.themeBrightness) == value;
|
|
||||||
|
|
||||||
final card = FirkaCard(
|
|
||||||
height: 52 + 12,
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: selected
|
|
||||||
? [_checkMark(), const SizedBox(width: 8)]
|
|
||||||
: [const SizedBox(height: 16 + 8)],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (selected) return card;
|
|
||||||
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
await _settings.set(SettingsRegistry.themeBrightness, value);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: card,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _fontCard(TitleFont font, {required bool selected}) {
|
|
||||||
final style = TextStyle(
|
|
||||||
fontFamily: font.fontFamily,
|
|
||||||
fontSize: 16,
|
|
||||||
fontVariations: font.supportsWeight
|
|
||||||
? [FontVariation("wght", _settings.get(SettingsRegistry.titleWeight))]
|
|
||||||
: null,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
);
|
|
||||||
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: selected
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
await _settings.set(SettingsRegistry.titleFont, font);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: FirkaCard(
|
|
||||||
color: selected ? _selectedSurface : _mutedCardColor,
|
|
||||||
left: [
|
|
||||||
Text(font.displayName, style: style),
|
|
||||||
],
|
|
||||||
right: selected
|
|
||||||
? [_checkMark(), const SizedBox(width: 8)]
|
|
||||||
: const [],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _changeRow() {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
setState(() => _fontPickerExpanded = !_fontPickerExpanded);
|
|
||||||
},
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
Text(
|
|
||||||
_l10n.s_c_change,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: [
|
|
||||||
FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
_fontPickerExpanded
|
|
||||||
? Majesticon.chevronUpLine
|
|
||||||
: Majesticon.chevronDownLine,
|
|
||||||
size: 24,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _fontPicker(TitleFont selected) {
|
|
||||||
if (!_fontPickerExpanded) {
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
_fontCard(selected, selected: true),
|
|
||||||
_changeRow(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
for (final font in TitleFont.values)
|
|
||||||
_fontCard(font, selected: font == selected),
|
|
||||||
_changeRow(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
double _textWidth(String text, TextStyle style) {
|
|
||||||
final painter = TextPainter(
|
|
||||||
text: TextSpan(text: text, style: style),
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
maxLines: 1,
|
|
||||||
)..layout();
|
|
||||||
return painter.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _weightEndDot() {
|
|
||||||
return Container(
|
|
||||||
width: 12,
|
|
||||||
height: 12,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: appStyle.colors.textTertiary.withValues(alpha: 0.22),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _weightThumb({required double size}) {
|
|
||||||
return Container(
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
border: Border.all(
|
|
||||||
color: appStyle.colors.buttonSecondaryFill,
|
|
||||||
width: 3,
|
|
||||||
),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
blurRadius: appStyle.isLight ? 3 : 0,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _weightSlider() {
|
|
||||||
final setting = SettingsRegistry.titleWeight;
|
|
||||||
final value = _settings.get(setting);
|
|
||||||
const trackHeight = 52.0;
|
|
||||||
const thumbSize = 28.0;
|
|
||||||
const thumbRadius = thumbSize / 2;
|
|
||||||
const edgePad = 16.0;
|
|
||||||
const gap = 8.0;
|
|
||||||
const endDotSize = 12.0;
|
|
||||||
|
|
||||||
final labelStyle = appStyle.fonts.B_14R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
);
|
|
||||||
final thinLabel = _l10n.s_c_title_weight_thin;
|
|
||||||
final thickLabel = _l10n.s_c_title_weight_thick;
|
|
||||||
final thinWidth = _textWidth(thinLabel, labelStyle);
|
|
||||||
final thickWidth = _textWidth(thickLabel, labelStyle);
|
|
||||||
|
|
||||||
Future<void> setFromLocalX(double localX, double width) async {
|
|
||||||
final start = edgePad + thumbRadius;
|
|
||||||
final end = width - edgePad - thumbRadius;
|
|
||||||
if (end <= start) return;
|
|
||||||
|
|
||||||
final t = ((localX - start) / (end - start)).clamp(0.0, 1.0);
|
|
||||||
final raw = setting.min + t * (setting.max - setting.min);
|
|
||||||
final stepped = (raw / setting.step!).round() * setting.step!;
|
|
||||||
final clamped = stepped.clamp(setting.min, setting.max).toDouble();
|
|
||||||
if (clamped == value) return;
|
|
||||||
|
|
||||||
await _settings.set(setting, clamped);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
_sectionLabel(_l10n.s_c_title_weight_header),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 4, bottom: 8),
|
|
||||||
child: Text(
|
|
||||||
_l10n.s_c_title_weight_subtitle,
|
|
||||||
style: appStyle.fonts.B_14R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FirkaCard.single(
|
|
||||||
width: double.infinity,
|
|
||||||
height: trackHeight,
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
|
||||||
final width = constraints.maxWidth;
|
|
||||||
final start = edgePad + thumbRadius;
|
|
||||||
final end = width - edgePad - thumbRadius;
|
|
||||||
final t = ((value - setting.min) / (setting.max - setting.min))
|
|
||||||
.clamp(0.0, 1.0);
|
|
||||||
final thumbCenterX = start + t * (end - start);
|
|
||||||
final thumbLeft = thumbCenterX - thumbRadius;
|
|
||||||
final thumbRight = thumbCenterX + thumbRadius;
|
|
||||||
|
|
||||||
final thinLeft = edgePad + endDotSize + gap;
|
|
||||||
final thinRight = thinLeft + thinWidth;
|
|
||||||
final thickRight = width - edgePad - endDotSize - gap;
|
|
||||||
final thickLeft = thickRight - thickWidth;
|
|
||||||
|
|
||||||
final showThin = thumbRight < thinLeft || thumbLeft > thinRight;
|
|
||||||
final showThick = thumbRight < thickLeft || thumbLeft > thickRight;
|
|
||||||
|
|
||||||
return GestureDetector(
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
onTapDown: (details) {
|
|
||||||
setFromLocalX(details.localPosition.dx, width);
|
|
||||||
},
|
|
||||||
onHorizontalDragUpdate: (details) {
|
|
||||||
setFromLocalX(details.localPosition.dx, width);
|
|
||||||
},
|
|
||||||
child: Stack(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: edgePad),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
_weightEndDot(),
|
|
||||||
const SizedBox(width: gap),
|
|
||||||
Opacity(
|
|
||||||
opacity: showThin ? 1 : 0,
|
|
||||||
child: Text(thinLabel, style: labelStyle),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
Opacity(
|
|
||||||
opacity: showThick ? 1 : 0,
|
|
||||||
child: Text(thickLabel, style: labelStyle),
|
|
||||||
),
|
|
||||||
const SizedBox(width: gap),
|
|
||||||
_weightEndDot(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
left: thumbLeft,
|
|
||||||
child: _weightThumb(size: thumbSize),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _capitalizationControl() {
|
|
||||||
final selected = _settings.get(SettingsRegistry.titleCapitalization);
|
|
||||||
final options = [
|
|
||||||
(TitleCapitalization.lower, _l10n.s_c_capitalization_lower),
|
|
||||||
(TitleCapitalization.normal, _l10n.s_c_capitalization_normal),
|
|
||||||
(TitleCapitalization.upper, _l10n.s_c_capitalization_upper),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
_sectionLabel(_l10n.s_c_capitalization_header),
|
|
||||||
FirkaCard.single(
|
|
||||||
width: double.infinity,
|
|
||||||
color: appStyle.colors.card,
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
for (final (value, label) in options)
|
|
||||||
Expanded(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
await _settings.set(
|
|
||||||
SettingsRegistry.titleCapitalization,
|
|
||||||
value,
|
|
||||||
);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: AnimatedContainer(
|
|
||||||
duration: const Duration(milliseconds: 150),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: selected == value
|
|
||||||
? _selectedSurface
|
|
||||||
: Colors.transparent,
|
|
||||||
borderRadius: BorderRadius.circular(14),
|
|
||||||
boxShadow: selected == value
|
|
||||||
? [
|
|
||||||
BoxShadow(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
blurRadius: appStyle.isLight ? 2 : 0,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.B_14R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BlocProvider<ThemeCubit>.value(
|
|
||||||
value: widget.data.themeCubit,
|
|
||||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
|
||||||
builder: (context, _) {
|
|
||||||
final selectedFont = _settings.get(SettingsRegistry.titleFont);
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 0),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => Navigator.of(context).pop(),
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.chevronLeftLine,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 1),
|
|
||||||
child: Text(
|
|
||||||
headingText(_l10n.s_customization),
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
_chip(_l10n.s_c_tab_appearance, selected: true),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
_chip(_l10n.s_c_tab_subjects, selected: false),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
_chip(_l10n.s_c_tab_fonts, selected: false),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_shortcutRow(
|
|
||||||
title: _l10n.s_c_my_themes,
|
|
||||||
iconType: FirkaIconType.majesticons,
|
|
||||||
iconData: Majesticon.editPen4Solid,
|
|
||||||
onTap: () => context.push("/themes"),
|
|
||||||
),
|
|
||||||
_shortcutRow(
|
|
||||||
title: _l10n.s_c_manage_subjects,
|
|
||||||
iconType: FirkaIconType.majesticons,
|
|
||||||
iconData: Majesticon.bookmarkSolid,
|
|
||||||
),
|
|
||||||
if (Platform.isAndroid)
|
|
||||||
_shortcutRow(
|
|
||||||
title: _l10n.s_c_change_app_icon,
|
|
||||||
onTap: () {
|
|
||||||
context.push("/settings", extra: [
|
|
||||||
SettingsUiBackHeader(_l10n.s_customization, () => true),
|
|
||||||
...widget.item.appIconPickerChildren,
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
_sectionLabel(_l10n.s_c_colors_header),
|
|
||||||
_coreThemePager(),
|
|
||||||
_stubCustomizeButton(),
|
|
||||||
_sectionLabel(_l10n.s_c_theme_header),
|
|
||||||
_themeOption(_l10n.s_c_theme_auto, ThemeBrightness.auto),
|
|
||||||
_themeOption(_l10n.s_c_theme_light, ThemeBrightness.light),
|
|
||||||
_themeOption(_l10n.s_c_theme_dark, ThemeBrightness.dark),
|
|
||||||
_sectionLabel(_l10n.s_c_grade_colors_header),
|
|
||||||
_gradeThemePager(),
|
|
||||||
_stubCustomizeButton(),
|
|
||||||
_sectionLabel(_l10n.s_c_title_style_header),
|
|
||||||
_fontPicker(selectedFont),
|
|
||||||
_weightSlider(),
|
|
||||||
_capitalizationControl(),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PresetSwatchPager extends StatefulWidget {
|
|
||||||
final List<List<Color>> swatches;
|
|
||||||
final int selectedIndex;
|
|
||||||
final ValueChanged<int> onSelected;
|
|
||||||
|
|
||||||
const _PresetSwatchPager({
|
|
||||||
super.key,
|
|
||||||
required this.swatches,
|
|
||||||
required this.selectedIndex,
|
|
||||||
required this.onSelected,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<_PresetSwatchPager> createState() => _PresetSwatchPagerState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PresetSwatchPagerState extends State<_PresetSwatchPager> {
|
|
||||||
late final PageController _controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_controller = PageController(initialPage: widget.selectedIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(_PresetSwatchPager oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (!_controller.hasClients) return;
|
|
||||||
if (widget.selectedIndex == oldWidget.selectedIndex) return;
|
|
||||||
if (_controller.page?.round() == widget.selectedIndex) return;
|
|
||||||
_controller.animateToPage(
|
|
||||||
widget.selectedIndex,
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
curve: Curves.easeOut,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Color _accentFor(double page) {
|
|
||||||
final index = page.round().clamp(0, widget.swatches.length - 1);
|
|
||||||
final swatch = widget.swatches[index];
|
|
||||||
if (swatch.length > 1) return swatch[1];
|
|
||||||
return appStyle.colors.accent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return FirkaCard.single(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 88,
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
child: Stack(
|
|
||||||
fit: StackFit.expand,
|
|
||||||
children: [
|
|
||||||
PageView.builder(
|
|
||||||
controller: _controller,
|
|
||||||
itemCount: widget.swatches.length,
|
|
||||||
physics: widget.swatches.length <= 1
|
|
||||||
? const NeverScrollableScrollPhysics()
|
|
||||||
: null,
|
|
||||||
onPageChanged: (index) {
|
|
||||||
if (index == widget.selectedIndex) return;
|
|
||||||
widget.onSelected(index);
|
|
||||||
},
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
for (final color in widget.swatches[index])
|
|
||||||
Expanded(child: ColoredBox(color: color)),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (widget.swatches.length > 1)
|
|
||||||
Positioned(
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 8,
|
|
||||||
child: IgnorePointer(
|
|
||||||
child: AnimatedBuilder(
|
|
||||||
animation: _controller,
|
|
||||||
builder: (context, _) {
|
|
||||||
final page = _controller.hasClients
|
|
||||||
? (_controller.page ??
|
|
||||||
widget.selectedIndex.toDouble())
|
|
||||||
: widget.selectedIndex.toDouble();
|
|
||||||
return Center(
|
|
||||||
child: _SwatchPageDots(
|
|
||||||
count: widget.swatches.length,
|
|
||||||
page: page,
|
|
||||||
accent: _accentFor(page),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SwatchPageDots extends StatelessWidget {
|
|
||||||
final int count;
|
|
||||||
final double page;
|
|
||||||
final Color accent;
|
|
||||||
|
|
||||||
const _SwatchPageDots({
|
|
||||||
required this.count,
|
|
||||||
required this.page,
|
|
||||||
required this.accent,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xCCFFFFFF),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
for (var i = 0; i < count; i++) ...[
|
|
||||||
if (i > 0) const SizedBox(width: 5),
|
|
||||||
_dot(i),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _dot(int index) {
|
|
||||||
final t = (1 - (index - page).abs()).clamp(0.0, 1.0);
|
|
||||||
final size = 5.0 + 3.0 * t;
|
|
||||||
return Container(
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: Color.lerp(
|
|
||||||
accent.withValues(alpha: 0.28),
|
|
||||||
accent,
|
|
||||||
t,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
|||||||
import "package:firka_common/ui/theme/core_theme.dart";
|
|
||||||
import "package:firka_common/ui/theme/grade_theme.dart";
|
|
||||||
|
|
||||||
const defaultCoreThemeId = "firka";
|
|
||||||
const defaultGradeThemeId = "firka";
|
|
||||||
const defaultBuiltinThemeId = "builtin-firka-firka";
|
|
||||||
|
|
||||||
String composeBuiltinThemeId(String coreId, String gradeId) {
|
|
||||||
return "builtin-$coreId-$gradeId";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isBuiltinThemeId(String id) {
|
|
||||||
return id == "builtin" || id.startsWith("builtin-");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses `builtin-{core}-{grade}`. Legacy `builtin` and malformed ids
|
|
||||||
/// fall back to firka / firka. Map lookup fallback happens at resolve sites.
|
|
||||||
(String coreId, String gradeId) parseBuiltinThemeId(String id) {
|
|
||||||
if (id == "builtin" || id == defaultBuiltinThemeId) {
|
|
||||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
|
||||||
}
|
|
||||||
if (!id.startsWith("builtin-")) {
|
|
||||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
|
||||||
}
|
|
||||||
final rest = id.substring("builtin-".length);
|
|
||||||
final sep = rest.indexOf("-");
|
|
||||||
if (sep <= 0 || sep >= rest.length - 1) {
|
|
||||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
|
||||||
}
|
|
||||||
final coreId = rest.substring(0, sep);
|
|
||||||
final gradeId = rest.substring(sep + 1);
|
|
||||||
if (coreId.isEmpty || gradeId.isEmpty) {
|
|
||||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
coreThemes.containsKey(coreId) ? coreId : defaultCoreThemeId,
|
|
||||||
gradeThemes.containsKey(gradeId) ? gradeId : defaultGradeThemeId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String normalizeSelectedThemeId(String id) {
|
|
||||||
if (id == "builtin") return defaultBuiltinThemeId;
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
@@ -1,206 +0,0 @@
|
|||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/core/firka_bundle.dart";
|
|
||||||
import "package:firka/ui/phone/widgets/bottom_nav_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:intl/intl.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
|
|
||||||
/// Which bottom-nav tab is highlighted inside a theme page preview.
|
|
||||||
enum ThemePreviewNavTab { home, grades, timetable, omissions, other }
|
|
||||||
|
|
||||||
/// Phone-shaped frame that downscales a full-size home page for the theme carousel.
|
|
||||||
class ThemePagePreview extends StatelessWidget {
|
|
||||||
static const double designWidth = 390;
|
|
||||||
static const double designHeight = 844;
|
|
||||||
|
|
||||||
final Widget body;
|
|
||||||
final ThemePreviewNavTab activeTab;
|
|
||||||
final AppInitialization data;
|
|
||||||
|
|
||||||
const ThemePagePreview({
|
|
||||||
super.key,
|
|
||||||
required this.body,
|
|
||||||
required this.activeTab,
|
|
||||||
required this.data,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.background,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
offset: const Offset(0, 1),
|
|
||||||
blurRadius: 2,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: LayoutBuilder(
|
|
||||||
builder: (context, constraints) {
|
|
||||||
return FittedBox(
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
child: SizedBox(
|
|
||||||
width: designWidth,
|
|
||||||
height: designHeight,
|
|
||||||
child: MediaQuery(
|
|
||||||
data: MediaQuery.of(context).copyWith(
|
|
||||||
size: const Size(designWidth, designHeight),
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
viewPadding: EdgeInsets.zero,
|
|
||||||
viewInsets: EdgeInsets.zero,
|
|
||||||
),
|
|
||||||
child: IgnorePointer(
|
|
||||||
child: DefaultAssetBundle(
|
|
||||||
bundle: FirkaBundle(),
|
|
||||||
child: ColoredBox(
|
|
||||||
color: appStyle.colors.background,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
_PreviewStatusBar(),
|
|
||||||
Expanded(child: body),
|
|
||||||
_PreviewBottomNav(
|
|
||||||
data: data,
|
|
||||||
activeTab: activeTab,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PreviewStatusBar extends StatelessWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final time = DateFormat("H:mm").format(DateTime.now());
|
|
||||||
return SizedBox(
|
|
||||||
height: 28,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
time,
|
|
||||||
style: appStyle.fonts.B_12SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
Icon(
|
|
||||||
Icons.signal_cellular_alt,
|
|
||||||
size: 12,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Icon(
|
|
||||||
Icons.wifi,
|
|
||||||
size: 12,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Icon(
|
|
||||||
Icons.battery_full,
|
|
||||||
size: 12,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PreviewBottomNav extends StatelessWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
final ThemePreviewNavTab activeTab;
|
|
||||||
|
|
||||||
const _PreviewBottomNav({
|
|
||||||
required this.data,
|
|
||||||
required this.activeTab,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = data.l10n;
|
|
||||||
final tabs = <(ThemePreviewNavTab, String, Object, Object)>[
|
|
||||||
(
|
|
||||||
ThemePreviewNavTab.home,
|
|
||||||
l10n.home,
|
|
||||||
Majesticon.homeSolid,
|
|
||||||
Majesticon.homeLine,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
ThemePreviewNavTab.grades,
|
|
||||||
l10n.grades,
|
|
||||||
Majesticon.bookmarkSolid,
|
|
||||||
Majesticon.bookmarkLine,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
ThemePreviewNavTab.timetable,
|
|
||||||
l10n.timetable,
|
|
||||||
Majesticon.calendarSolid,
|
|
||||||
Majesticon.calendarLine,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
ThemePreviewNavTab.omissions,
|
|
||||||
l10n.omissions,
|
|
||||||
Majesticon.timerSolid,
|
|
||||||
Majesticon.timerLine,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
gradient: LinearGradient(
|
|
||||||
begin: Alignment.bottomCenter,
|
|
||||||
end: Alignment.topCenter,
|
|
||||||
colors: [
|
|
||||||
appStyle.colors.background,
|
|
||||||
appStyle.colors.background.withValues(alpha: 0.0),
|
|
||||||
],
|
|
||||||
stops: const [0.0, 1.0],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
...tabs.map((nav) {
|
|
||||||
final active = activeTab == nav.$1;
|
|
||||||
return BottomNavIconWidget(
|
|
||||||
() {},
|
|
||||||
active,
|
|
||||||
active ? nav.$3 : nav.$4,
|
|
||||||
nav.$2,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
BottomNavIconWidget(
|
|
||||||
() {},
|
|
||||||
activeTab == ThemePreviewNavTab.other,
|
|
||||||
data.profilePicture != null
|
|
||||||
? data.profilePicture!
|
|
||||||
: Majesticon.menuLine,
|
|
||||||
l10n.other,
|
|
||||||
isProfilePicture: data.profilePicture != null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,457 +0,0 @@
|
|||||||
import "package:firka_common/core/debug_helper.dart";
|
|
||||||
import "package:firka_common/data/models/grade_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/lesson_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/message_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/omission_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/student_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/subject_cache_model.dart";
|
|
||||||
import "package:firka_common/data/models/test_cache_model.dart";
|
|
||||||
import "package:kreta_api/kreta_api.dart";
|
|
||||||
|
|
||||||
/// In-memory placeholder models for theme page previews (Figma sample content).
|
|
||||||
class ThemePreviewData {
|
|
||||||
ThemePreviewData._({
|
|
||||||
required this.now,
|
|
||||||
required this.student,
|
|
||||||
required this.subjects,
|
|
||||||
required this.homeLessons,
|
|
||||||
required this.timetableLessons,
|
|
||||||
required this.messages,
|
|
||||||
required this.tests,
|
|
||||||
required this.grades,
|
|
||||||
required this.chartGrades,
|
|
||||||
required this.omissions,
|
|
||||||
required this.omissionBarSegments,
|
|
||||||
required this.omissionExcusedCount,
|
|
||||||
required this.omissionPendingCount,
|
|
||||||
required this.omissionUnexcusedCount,
|
|
||||||
required this.monthDayMeta,
|
|
||||||
required this.subjectDetailSubject,
|
|
||||||
required this.subjectDetailGrades,
|
|
||||||
required this.subjectDetailTeacher,
|
|
||||||
});
|
|
||||||
|
|
||||||
final DateTime now;
|
|
||||||
final StudentCacheModel student;
|
|
||||||
final List<SubjectCacheModel> subjects;
|
|
||||||
final List<LessonCacheModel> homeLessons;
|
|
||||||
final List<LessonCacheModel> timetableLessons;
|
|
||||||
final List<MessageCacheModel> messages;
|
|
||||||
final List<TestCacheModel> tests;
|
|
||||||
final List<GradeCacheModel> grades;
|
|
||||||
final List<GradeCacheModel> chartGrades;
|
|
||||||
final List<OmissionCacheModel> omissions;
|
|
||||||
final List<OmissionState?> omissionBarSegments;
|
|
||||||
final int omissionExcusedCount;
|
|
||||||
final int omissionPendingCount;
|
|
||||||
final int omissionUnexcusedCount;
|
|
||||||
final Map<DateTime, ThemePreviewMonthDay> monthDayMeta;
|
|
||||||
final SubjectCacheModel subjectDetailSubject;
|
|
||||||
final List<GradeCacheModel> subjectDetailGrades;
|
|
||||||
final String subjectDetailTeacher;
|
|
||||||
|
|
||||||
SubjectCacheModel get matematika => subjects[0];
|
|
||||||
SubjectCacheModel get angol => subjects[1];
|
|
||||||
SubjectCacheModel get tortenelem => subjects[2];
|
|
||||||
SubjectCacheModel get nemet => subjects[3];
|
|
||||||
SubjectCacheModel get informatika => subjects[4];
|
|
||||||
SubjectCacheModel get fizika => subjects[5];
|
|
||||||
|
|
||||||
static ThemePreviewData build([DateTime? clock]) {
|
|
||||||
final now = clock ?? timeNow();
|
|
||||||
// Anchor to real time so LessonSlider / LessonBigWidget (which call
|
|
||||||
// timeNow()) keep Matematika as the active lesson with ~35 min left.
|
|
||||||
final midnight = DateTime(now.year, now.month, now.day);
|
|
||||||
final day = now;
|
|
||||||
|
|
||||||
final subjects = [
|
|
||||||
_subject(1, "Matematika"),
|
|
||||||
_subject(2, "Angol nyelv"),
|
|
||||||
_subject(3, "Történelem"),
|
|
||||||
_subject(4, "Német"),
|
|
||||||
_subject(5, "Informatika"),
|
|
||||||
_subject(6, "Fizika"),
|
|
||||||
];
|
|
||||||
final matematika = subjects[0];
|
|
||||||
final angol = subjects[1];
|
|
||||||
final tortenelem = subjects[2];
|
|
||||||
final nemet = subjects[3];
|
|
||||||
final informatika = subjects[4];
|
|
||||||
final fizika = subjects[5];
|
|
||||||
|
|
||||||
final student = StudentCacheModel()
|
|
||||||
..cacheKey = 1
|
|
||||||
..createdAt = midnight
|
|
||||||
..name = "Kovács Ádám"
|
|
||||||
..birthday = DateTime(2008, 3, 15);
|
|
||||||
|
|
||||||
// Active lesson: started 10 min ago, ends in 34 min => "35 perc" via timeLeft.
|
|
||||||
final homeLessons = [
|
|
||||||
_lesson(
|
|
||||||
id: 101,
|
|
||||||
subject: matematika,
|
|
||||||
dailyNth: 1,
|
|
||||||
start: now.subtract(const Duration(minutes: 10)),
|
|
||||||
end: now.add(const Duration(minutes: 34)),
|
|
||||||
roomName: "123",
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 102,
|
|
||||||
subject: angol,
|
|
||||||
dailyNth: 2,
|
|
||||||
start: now.add(const Duration(minutes: 45)),
|
|
||||||
end: now.add(const Duration(minutes: 90)),
|
|
||||||
roomName: "123",
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 103,
|
|
||||||
subject: tortenelem,
|
|
||||||
dailyNth: 3,
|
|
||||||
start: now.add(const Duration(minutes: 100)),
|
|
||||||
end: now.add(const Duration(minutes: 145)),
|
|
||||||
roomName: "201",
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
final testLektion = TestCacheModel()
|
|
||||||
..cacheKey = 201
|
|
||||||
..createdAt = midnight
|
|
||||||
..topic = "Lektion 14"
|
|
||||||
..method = "Írásbeli"
|
|
||||||
..teacherName = "Müller Anna";
|
|
||||||
|
|
||||||
final testBinaris = TestCacheModel()
|
|
||||||
..cacheKey = 202
|
|
||||||
..createdAt = midnight
|
|
||||||
..topic = "Bináris fák"
|
|
||||||
..method = "Írásbeli"
|
|
||||||
..teacherName = "Nagy Péter";
|
|
||||||
|
|
||||||
final ttBase = DateTime(day.year, day.month, day.day, 8, 0);
|
|
||||||
final timetableLessons = [
|
|
||||||
_lesson(
|
|
||||||
id: 301,
|
|
||||||
subject: nemet,
|
|
||||||
dailyNth: 1,
|
|
||||||
start: ttBase,
|
|
||||||
end: ttBase.add(const Duration(minutes: 45)),
|
|
||||||
roomName: "12",
|
|
||||||
substituteTeacher: "Kiss Éva",
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 302,
|
|
||||||
subject: matematika,
|
|
||||||
dailyNth: 2,
|
|
||||||
start: ttBase.add(const Duration(minutes: 55)),
|
|
||||||
end: ttBase.add(const Duration(minutes: 100)),
|
|
||||||
roomName: "123",
|
|
||||||
type: "UresOra",
|
|
||||||
test: testLektion,
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 303,
|
|
||||||
subject: matematika,
|
|
||||||
dailyNth: 3,
|
|
||||||
start: ttBase.add(const Duration(minutes: 110)),
|
|
||||||
end: ttBase.add(const Duration(minutes: 155)),
|
|
||||||
roomName: "123",
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 304,
|
|
||||||
subject: informatika,
|
|
||||||
dailyNth: 4,
|
|
||||||
start: ttBase.add(const Duration(minutes: 165)),
|
|
||||||
end: ttBase.add(const Duration(minutes: 210)),
|
|
||||||
roomName: "Inf1",
|
|
||||||
test: testBinaris,
|
|
||||||
),
|
|
||||||
_lesson(
|
|
||||||
id: 305,
|
|
||||||
subject: informatika,
|
|
||||||
dailyNth: 5,
|
|
||||||
start: ttBase.add(const Duration(minutes: 220)),
|
|
||||||
end: ttBase.add(const Duration(minutes: 265)),
|
|
||||||
roomName: "Inf1",
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
final homeTest = TestCacheModel()
|
|
||||||
..cacheKey = 203
|
|
||||||
..createdAt = midnight.subtract(const Duration(days: 1))
|
|
||||||
..topic = "Függvények"
|
|
||||||
..method = "Írásbeli"
|
|
||||||
..teacherName = "Szabó Gábor";
|
|
||||||
homeTest.lesson.value = homeLessons[0];
|
|
||||||
|
|
||||||
final messages = [
|
|
||||||
MessageCacheModel()
|
|
||||||
..cacheKey = 401
|
|
||||||
..createdAt = midnight.subtract(const Duration(days: 2))
|
|
||||||
..author = "Pálfy Zoltán"
|
|
||||||
..title = "2023 novemberi programok"
|
|
||||||
..contentHtml = "",
|
|
||||||
MessageCacheModel()
|
|
||||||
..cacheKey = 402
|
|
||||||
..createdAt = midnight.subtract(const Duration(days: 2))
|
|
||||||
..author = ":3"
|
|
||||||
..title = "Mrrp mrrp meow meow"
|
|
||||||
..contentHtml = "",
|
|
||||||
];
|
|
||||||
|
|
||||||
final grades = [
|
|
||||||
_grade(501, matematika, 5, midnight.subtract(const Duration(days: 3))),
|
|
||||||
_grade(502, matematika, 4, midnight.subtract(const Duration(days: 10))),
|
|
||||||
_grade(503, angol, 5, midnight.subtract(const Duration(days: 4))),
|
|
||||||
_grade(504, angol, 3, midnight.subtract(const Duration(days: 12))),
|
|
||||||
_grade(505, tortenelem, 4, midnight.subtract(const Duration(days: 5))),
|
|
||||||
_grade(506, nemet, 5, midnight.subtract(const Duration(days: 6))),
|
|
||||||
_grade(507, informatika, 5, midnight.subtract(const Duration(days: 7))),
|
|
||||||
_grade(508, fizika, 4, midnight.subtract(const Duration(days: 8))),
|
|
||||||
_grade(509, matematika, 5, midnight.subtract(const Duration(days: 15))),
|
|
||||||
];
|
|
||||||
|
|
||||||
final sept = DateTime(
|
|
||||||
day.month >= DateTime.september ? day.year : day.year - 1,
|
|
||||||
DateTime.september,
|
|
||||||
15,
|
|
||||||
);
|
|
||||||
final chartSpanDays = day.difference(sept).inDays.clamp(1, 365);
|
|
||||||
const chartValues = [
|
|
||||||
1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
|
|
||||||
3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
|
|
||||||
4, 4, 3, 3, 4, 4, 4, 4, 5, 5,
|
|
||||||
5, 4, 4, 5, 5, 5, 5, 5, 5, 5,
|
|
||||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
||||||
];
|
|
||||||
final chartGrades = [
|
|
||||||
for (var i = 0; i < chartValues.length; i++)
|
|
||||||
_grade(
|
|
||||||
700 + i,
|
|
||||||
matematika,
|
|
||||||
chartValues[i],
|
|
||||||
sept.add(
|
|
||||||
Duration(days: (i * chartSpanDays / (chartValues.length - 1)).round()),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
final omissions = [
|
|
||||||
_omission(
|
|
||||||
601,
|
|
||||||
homeLessons[1],
|
|
||||||
OmissionState.excused,
|
|
||||||
midnight.subtract(const Duration(days: 20)),
|
|
||||||
),
|
|
||||||
_omission(
|
|
||||||
602,
|
|
||||||
homeLessons[2],
|
|
||||||
OmissionState.pending,
|
|
||||||
midnight.subtract(const Duration(days: 14)),
|
|
||||||
),
|
|
||||||
_omission(
|
|
||||||
603,
|
|
||||||
timetableLessons[0],
|
|
||||||
OmissionState.unexcused,
|
|
||||||
midnight.subtract(const Duration(days: 9)),
|
|
||||||
),
|
|
||||||
_omission(
|
|
||||||
604,
|
|
||||||
timetableLessons[3],
|
|
||||||
OmissionState.excused,
|
|
||||||
midnight.subtract(const Duration(days: 3)),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
// School-year style bar: mostly present days, sparse marks, a few clusters
|
|
||||||
// for thicker ticks (matches the design "barcode" look).
|
|
||||||
final omissionBarSegments = List<OmissionState?>.filled(132, null);
|
|
||||||
const excusedClusters = <List<int>>[
|
|
||||||
[2],
|
|
||||||
[7, 8],
|
|
||||||
[14],
|
|
||||||
[19],
|
|
||||||
[24, 25, 26],
|
|
||||||
[33],
|
|
||||||
[38],
|
|
||||||
[44, 45],
|
|
||||||
[52],
|
|
||||||
[58],
|
|
||||||
[64, 65],
|
|
||||||
[71],
|
|
||||||
[77],
|
|
||||||
[83, 84, 85],
|
|
||||||
[92],
|
|
||||||
[104, 105],
|
|
||||||
[112],
|
|
||||||
[118],
|
|
||||||
[124, 125],
|
|
||||||
];
|
|
||||||
for (final cluster in excusedClusters) {
|
|
||||||
for (final i in cluster) {
|
|
||||||
omissionBarSegments[i] = OmissionState.excused;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Pending (orange) ticks, including a short cluster.
|
|
||||||
for (final i in [16, 48, 49, 88, 110]) {
|
|
||||||
omissionBarSegments[i] = OmissionState.pending;
|
|
||||||
}
|
|
||||||
// Unexcused (red/pink) ticks.
|
|
||||||
for (final i in [61, 96, 127]) {
|
|
||||||
omissionBarSegments[i] = OmissionState.unexcused;
|
|
||||||
}
|
|
||||||
|
|
||||||
final monthStart = DateTime(day.year, day.month, 1);
|
|
||||||
final gridStart = monthStart
|
|
||||||
.subtract(Duration(days: monthStart.weekday - 1))
|
|
||||||
.subtract(const Duration(days: 7));
|
|
||||||
final monthDayMeta = <DateTime, ThemePreviewMonthDay>{};
|
|
||||||
for (var i = 0; i < 49; i++) {
|
|
||||||
final d = DateTime(
|
|
||||||
gridStart.year,
|
|
||||||
gridStart.month,
|
|
||||||
gridStart.day,
|
|
||||||
).add(Duration(days: i));
|
|
||||||
final key = DateTime(d.year, d.month, d.day);
|
|
||||||
final inMonth = d.month == day.month;
|
|
||||||
final weekday = d.weekday;
|
|
||||||
final lessonCount = !inMonth
|
|
||||||
? 0
|
|
||||||
: weekday > 5
|
|
||||||
? 0
|
|
||||||
: 5 - ((d.day + weekday) % 3);
|
|
||||||
OmissionState? omission;
|
|
||||||
if (inMonth && weekday <= 5 && d.day % 9 == 0) {
|
|
||||||
omission = OmissionState.pending;
|
|
||||||
} else if (inMonth && weekday <= 5 && d.day % 13 == 0) {
|
|
||||||
omission = OmissionState.unexcused;
|
|
||||||
}
|
|
||||||
monthDayMeta[key] = ThemePreviewMonthDay(
|
|
||||||
lessonCount: lessonCount.clamp(0, 7),
|
|
||||||
hasTest: inMonth && weekday <= 5 && d.day % 7 == 0,
|
|
||||||
omission: omission,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final subjectDetailGrades = grades
|
|
||||||
.where((g) => g.subject.value?.cacheKey == matematika.cacheKey)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return ThemePreviewData._(
|
|
||||||
now: day,
|
|
||||||
student: student,
|
|
||||||
subjects: subjects,
|
|
||||||
homeLessons: homeLessons,
|
|
||||||
timetableLessons: timetableLessons,
|
|
||||||
messages: messages,
|
|
||||||
tests: [homeTest],
|
|
||||||
grades: grades,
|
|
||||||
chartGrades: chartGrades,
|
|
||||||
omissions: omissions,
|
|
||||||
omissionBarSegments: omissionBarSegments,
|
|
||||||
omissionExcusedCount: 2,
|
|
||||||
omissionPendingCount: 1,
|
|
||||||
omissionUnexcusedCount: 1,
|
|
||||||
monthDayMeta: monthDayMeta,
|
|
||||||
subjectDetailSubject: matematika,
|
|
||||||
subjectDetailGrades: subjectDetailGrades,
|
|
||||||
subjectDetailTeacher: "Szabó Gábor (Osztály)",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static SubjectCacheModel _subject(int id, String name) {
|
|
||||||
final subject = SubjectCacheModel()
|
|
||||||
..cacheKey = id
|
|
||||||
..createdAt = DateTime(2024, 9, 1)
|
|
||||||
..name = name;
|
|
||||||
subject.classAverage.value = null;
|
|
||||||
return subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
static LessonCacheModel _lesson({
|
|
||||||
required int id,
|
|
||||||
required SubjectCacheModel subject,
|
|
||||||
required int dailyNth,
|
|
||||||
required DateTime start,
|
|
||||||
required DateTime end,
|
|
||||||
required String roomName,
|
|
||||||
String? substituteTeacher,
|
|
||||||
String type = "OrarendiOra",
|
|
||||||
TestCacheModel? test,
|
|
||||||
}) {
|
|
||||||
final lesson = LessonCacheModel()
|
|
||||||
..cacheKey = id
|
|
||||||
..createdAt = start
|
|
||||||
..start = start
|
|
||||||
..end = end
|
|
||||||
..dailyNth = dailyNth
|
|
||||||
..yearlyNth = dailyNth
|
|
||||||
..name = subject.name
|
|
||||||
..roomName = roomName
|
|
||||||
..state = "Naplozott"
|
|
||||||
..type = type
|
|
||||||
..teacher = "Tanár"
|
|
||||||
..substituteTeacher = substituteTeacher;
|
|
||||||
lesson.subject.value = subject;
|
|
||||||
// Mark optional links loaded so loadAndGet() does not call loadSync on
|
|
||||||
// unmanaged (non-Isar) preview objects.
|
|
||||||
lesson.test.value = test;
|
|
||||||
lesson.homework.value = null;
|
|
||||||
lesson.classGroup.value = null;
|
|
||||||
lesson.omission.value = null;
|
|
||||||
if (test != null) {
|
|
||||||
test.lesson.value = lesson;
|
|
||||||
}
|
|
||||||
return lesson;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GradeCacheModel _grade(
|
|
||||||
int id,
|
|
||||||
SubjectCacheModel subject,
|
|
||||||
int value,
|
|
||||||
DateTime at, {
|
|
||||||
int? weightPercentage = 100,
|
|
||||||
}) {
|
|
||||||
final grade = GradeCacheModel()
|
|
||||||
..cacheKey = id
|
|
||||||
..createdAt = at
|
|
||||||
..mode = "Írásbeli"
|
|
||||||
..topic = subject.name
|
|
||||||
..type = "Értékelés"
|
|
||||||
..valueType = "Osztalyzat"
|
|
||||||
..writtenAt = at
|
|
||||||
..numericValue = value
|
|
||||||
..weightPercentage = weightPercentage
|
|
||||||
..textValue = value.toString()
|
|
||||||
..teacherName = "Tanár";
|
|
||||||
grade.subject.value = subject;
|
|
||||||
grade.classGroup.value = null;
|
|
||||||
return grade;
|
|
||||||
}
|
|
||||||
|
|
||||||
static OmissionCacheModel _omission(
|
|
||||||
int id,
|
|
||||||
LessonCacheModel lesson,
|
|
||||||
OmissionState state,
|
|
||||||
DateTime at,
|
|
||||||
) {
|
|
||||||
final omission = OmissionCacheModel()
|
|
||||||
..cacheKey = id
|
|
||||||
..createdAt = at
|
|
||||||
..state = state
|
|
||||||
..teacherName = "Tanár";
|
|
||||||
omission.lesson.value = lesson;
|
|
||||||
return omission;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ThemePreviewMonthDay {
|
|
||||||
const ThemePreviewMonthDay({
|
|
||||||
required this.lessonCount,
|
|
||||||
required this.hasTest,
|
|
||||||
this.omission,
|
|
||||||
});
|
|
||||||
|
|
||||||
final int lessonCount;
|
|
||||||
final bool hasTest;
|
|
||||||
final OmissionState? omission;
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,368 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:go_router/go_router.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
|
|
||||||
import "package:firka/l10n/app_localizations.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
|
|
||||||
Future<String?> showThemeNameSheet(
|
|
||||||
BuildContext context,
|
|
||||||
AppLocalizations l10n,
|
|
||||||
) {
|
|
||||||
return _showCenteredInputSheet(
|
|
||||||
context: context,
|
|
||||||
l10n: l10n,
|
|
||||||
icon: Majesticon.plusLine,
|
|
||||||
title: l10n.s_c_themes_create_title,
|
|
||||||
subtitle: l10n.s_c_themes_create_subtitle,
|
|
||||||
placeholder: l10n.s_c_themes_create_placeholder,
|
|
||||||
confirmLabel: l10n.s_c_themes_continue,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> showThemeDeleteSheet(
|
|
||||||
BuildContext context,
|
|
||||||
AppLocalizations l10n,
|
|
||||||
) async {
|
|
||||||
final result = await showModalBottomSheet<bool>(
|
|
||||||
context: context,
|
|
||||||
elevation: 100,
|
|
||||||
isScrollControlled: true,
|
|
||||||
enableDrag: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
barrierColor: appStyle.colors.a15p,
|
|
||||||
builder: (context) {
|
|
||||||
return _ThemeConfirmSheet(
|
|
||||||
icon: Majesticon.deleteBinLine,
|
|
||||||
title: l10n.s_c_themes_delete_title,
|
|
||||||
subtitle: l10n.s_c_themes_delete_subtitle,
|
|
||||||
confirmLabel: l10n.s_c_themes_delete_confirm,
|
|
||||||
cancelLabel: l10n.cancel,
|
|
||||||
confirmColor: appStyle.colors.accent,
|
|
||||||
onConfirm: () => context.pop(true),
|
|
||||||
onCancel: () => context.pop(false),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return result ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String?> _showCenteredInputSheet({
|
|
||||||
required BuildContext context,
|
|
||||||
required AppLocalizations l10n,
|
|
||||||
required Object icon,
|
|
||||||
required String title,
|
|
||||||
required String subtitle,
|
|
||||||
required String placeholder,
|
|
||||||
required String confirmLabel,
|
|
||||||
}) {
|
|
||||||
return showModalBottomSheet<String>(
|
|
||||||
context: context,
|
|
||||||
elevation: 100,
|
|
||||||
isScrollControlled: true,
|
|
||||||
enableDrag: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
barrierColor: appStyle.colors.a15p,
|
|
||||||
builder: (context) {
|
|
||||||
return Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
|
||||||
),
|
|
||||||
child: _ThemeNameInputSheet(
|
|
||||||
icon: icon,
|
|
||||||
title: title,
|
|
||||||
subtitle: subtitle,
|
|
||||||
placeholder: placeholder,
|
|
||||||
confirmLabel: confirmLabel,
|
|
||||||
cancelLabel: l10n.cancel,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeNameInputSheet extends StatefulWidget {
|
|
||||||
final Object icon;
|
|
||||||
final String title;
|
|
||||||
final String subtitle;
|
|
||||||
final String placeholder;
|
|
||||||
final String confirmLabel;
|
|
||||||
final String cancelLabel;
|
|
||||||
|
|
||||||
const _ThemeNameInputSheet({
|
|
||||||
required this.icon,
|
|
||||||
required this.title,
|
|
||||||
required this.subtitle,
|
|
||||||
required this.placeholder,
|
|
||||||
required this.confirmLabel,
|
|
||||||
required this.cancelLabel,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<_ThemeNameInputSheet> createState() => _ThemeNameInputSheetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeNameInputSheetState extends State<_ThemeNameInputSheet> {
|
|
||||||
late final TextEditingController _controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_controller = TextEditingController();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _submit() {
|
|
||||||
final value = _controller.text.trim();
|
|
||||||
if (value.isEmpty) return;
|
|
||||||
context.pop(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return _ThemeSheetShell(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
_sheetIcon(widget.icon),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
widget.title,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
widget.subtitle,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.card,
|
|
||||||
borderRadius: BorderRadius.circular(24),
|
|
||||||
),
|
|
||||||
child: TextField(
|
|
||||||
controller: _controller,
|
|
||||||
autofocus: true,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
textInputAction: TextInputAction.done,
|
|
||||||
onSubmitted: (_) => _submit(),
|
|
||||||
cursorColor: appStyle.colors.accent,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: widget.placeholder,
|
|
||||||
hintStyle: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textTertiary,
|
|
||||||
),
|
|
||||||
border: InputBorder.none,
|
|
||||||
enabledBorder: InputBorder.none,
|
|
||||||
focusedBorder: InputBorder.none,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_sheetButton(
|
|
||||||
label: widget.confirmLabel,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
onTap: _submit,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
_sheetButton(
|
|
||||||
label: widget.cancelLabel,
|
|
||||||
color: appStyle.colors.buttonSecondaryFill,
|
|
||||||
onTap: () => context.pop(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeConfirmSheet extends StatelessWidget {
|
|
||||||
final Object icon;
|
|
||||||
final String title;
|
|
||||||
final String subtitle;
|
|
||||||
final String confirmLabel;
|
|
||||||
final String cancelLabel;
|
|
||||||
final Color confirmColor;
|
|
||||||
final VoidCallback onConfirm;
|
|
||||||
final VoidCallback onCancel;
|
|
||||||
|
|
||||||
const _ThemeConfirmSheet({
|
|
||||||
required this.icon,
|
|
||||||
required this.title,
|
|
||||||
required this.subtitle,
|
|
||||||
required this.confirmLabel,
|
|
||||||
required this.cancelLabel,
|
|
||||||
required this.confirmColor,
|
|
||||||
required this.onConfirm,
|
|
||||||
required this.onCancel,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return _ThemeSheetShell(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
_sheetIcon(icon),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
subtitle,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
_sheetButton(
|
|
||||||
label: confirmLabel,
|
|
||||||
color: confirmColor,
|
|
||||||
onTap: onConfirm,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
_sheetButton(
|
|
||||||
label: cancelLabel,
|
|
||||||
color: appStyle.colors.buttonSecondaryFill,
|
|
||||||
onTap: onCancel,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeSheetShell extends StatelessWidget {
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const _ThemeSheetShell({required this.child});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Positioned.fill(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => context.pop(),
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
child: const ColoredBox(color: Colors.transparent),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.background,
|
|
||||||
borderRadius: const BorderRadius.vertical(
|
|
||||||
top: Radius.circular(24),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Align(
|
|
||||||
heightFactor: 0,
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.only(top: 18),
|
|
||||||
width: 40,
|
|
||||||
height: 4,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.shadowColor,
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 40),
|
|
||||||
child,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _sheetIcon(Object icon) {
|
|
||||||
return Container(
|
|
||||||
width: 56,
|
|
||||||
height: 56,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.accent.withValues(alpha: 0.25),
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Container(
|
|
||||||
width: 36,
|
|
||||||
height: 36,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
icon,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.textPrimaryLight,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _sheetButton({
|
|
||||||
required String label,
|
|
||||||
required Color color,
|
|
||||||
required VoidCallback onTap,
|
|
||||||
}) {
|
|
||||||
return SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: FirkaCard(
|
|
||||||
color: color,
|
|
||||||
left: const [],
|
|
||||||
center: [
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
import "package:carousel_slider/carousel_slider.dart";
|
|
||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:go_router/go_router.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/ui/components/firka_icon_button.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_data.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_pages.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/sheets/theme_sheets.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/user_theme.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/widgets/theme_name_label.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/widgets/theme_swatch_icon.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
|
|
||||||
class ThemeScreen extends StatefulWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
final ThemeScreenArgs args;
|
|
||||||
|
|
||||||
const ThemeScreen(this.data, this.args, {super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ThemeScreen> createState() => _ThemeScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeScreenState extends State<ThemeScreen> {
|
|
||||||
late final ThemePreviewData _preview;
|
|
||||||
|
|
||||||
UserTheme get _theme => widget.args.theme;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_preview = ThemePreviewData.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
String get _originLabel {
|
|
||||||
final l10n = widget.data.l10n;
|
|
||||||
switch (_theme.origin) {
|
|
||||||
case ThemeOrigin.builtin:
|
|
||||||
return l10n.s_c_themes_builtin_label;
|
|
||||||
case ThemeOrigin.own:
|
|
||||||
return l10n.s_c_themes_own_label;
|
|
||||||
case ThemeOrigin.downloaded:
|
|
||||||
return l10n.s_c_themes_imported_label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _delete() async {
|
|
||||||
final confirmed = await showThemeDeleteSheet(context, widget.data.l10n);
|
|
||||||
if (!confirmed || !mounted) return;
|
|
||||||
await widget.args.onDelete(_theme.id);
|
|
||||||
if (!mounted) return;
|
|
||||||
context.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = widget.data.l10n;
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: appStyle.colors.background,
|
|
||||||
body: SafeArea(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 0),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => context.pop(),
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.chevronLeftLine,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 1),
|
|
||||||
child: Text(
|
|
||||||
l10n.s_c_theme_header,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
ThemeSwatchIcon(swatch: _theme.swatch, size: 48),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
ThemeNameLabel(
|
|
||||||
name: _theme.name,
|
|
||||||
editable: _theme.canRename,
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() => _theme.name = value);
|
|
||||||
widget.args.onChanged();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
_originLabel,
|
|
||||||
style: appStyle.fonts.B_14R.apply(
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
if (_theme.isOwn) ...[
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: () {},
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.editPen4Line,
|
|
||||||
size: 18,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: () {},
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.shareLine,
|
|
||||||
size: 18,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (_theme.canDelete)
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: _delete,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.deleteBinLine,
|
|
||||||
size: 18,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 28),
|
|
||||||
Expanded(
|
|
||||||
child: CarouselSlider(
|
|
||||||
options: CarouselOptions(
|
|
||||||
height: double.infinity,
|
|
||||||
viewportFraction: 0.72,
|
|
||||||
enableInfiniteScroll: false,
|
|
||||||
enlargeCenterPage: false,
|
|
||||||
padEnds: false,
|
|
||||||
),
|
|
||||||
items: buildThemePreviewCarouselItems(
|
|
||||||
data: widget.data,
|
|
||||||
preview: _preview,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
await widget.args.onUse(_theme.id);
|
|
||||||
if (!context.mounted) return;
|
|
||||||
context.pop();
|
|
||||||
},
|
|
||||||
child: FirkaCard(
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
left: const [],
|
|
||||||
center: [
|
|
||||||
Text(
|
|
||||||
l10n.s_c_themes_use,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,372 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
import "package:go_router/go_router.dart";
|
|
||||||
import "package:isar_community/isar.dart";
|
|
||||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
|
||||||
|
|
||||||
import "package:firka/app/app_state.dart";
|
|
||||||
import "package:firka/core/settings/settings_repository.dart";
|
|
||||||
import "package:firka/core/settings/settings_schema.dart";
|
|
||||||
import "package:firka/core/snowflake.dart";
|
|
||||||
import "package:firka/ui/components/firka_icon_button.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/sheets/theme_sheets.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/user_theme.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/widgets/theme_name_label.dart";
|
|
||||||
import "package:firka/ui/phone/screens/themes/widgets/theme_swatch_icon.dart";
|
|
||||||
import "package:firka/ui/shared/firka_icon.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
import "package:firka_common/data/database.dart";
|
|
||||||
import "package:firka_common/data/models/user_theme_model.dart";
|
|
||||||
import "package:firka_common/ui/components/firka_card.dart";
|
|
||||||
|
|
||||||
class ThemesScreen extends StatefulWidget {
|
|
||||||
final AppInitialization data;
|
|
||||||
|
|
||||||
const ThemesScreen(this.data, {super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ThemesScreen> createState() => _ThemesScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemesScreenState extends State<ThemesScreen> {
|
|
||||||
late List<UserTheme> _storedThemes;
|
|
||||||
late String _selectedId;
|
|
||||||
bool _loading = true;
|
|
||||||
|
|
||||||
UserTheme get _builtin => UserTheme.builtin(
|
|
||||||
widget.data.l10n.s_c_themes_builtin_name,
|
|
||||||
coreId: Settings.selectedCoreThemeId.value,
|
|
||||||
gradeId: Settings.selectedGradeThemeId.value,
|
|
||||||
isLight: appStyle.isLight,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_storedThemes = [];
|
|
||||||
_selectedId = normalizeSelectedThemeId(Settings.selectedThemeId.value);
|
|
||||||
_loadThemes();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadThemes() async {
|
|
||||||
final stored = await isarInit.userThemeModels.where().findAll();
|
|
||||||
if (!mounted) return;
|
|
||||||
|
|
||||||
final normalized = normalizeSelectedThemeId(Settings.selectedThemeId.value);
|
|
||||||
if (normalized != Settings.selectedThemeId.value) {
|
|
||||||
await Settings.selectedThemeId.set(normalized);
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_storedThemes = stored.map(UserTheme.fromModel).toList();
|
|
||||||
_selectedId = normalized;
|
|
||||||
final knownIds = {
|
|
||||||
_builtin.id,
|
|
||||||
..._storedThemes.map((t) => t.id),
|
|
||||||
};
|
|
||||||
if (isBuiltinThemeId(_selectedId)) {
|
|
||||||
// Always use the composed builtin id for the current core/grade.
|
|
||||||
_selectedId = _builtin.id;
|
|
||||||
} else if (!knownIds.contains(_selectedId)) {
|
|
||||||
_selectedId = _builtin.id;
|
|
||||||
}
|
|
||||||
_loading = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isBuiltinThemeId(_selectedId) &&
|
|
||||||
Settings.selectedThemeId.value != _builtin.id) {
|
|
||||||
await Settings.selectedThemeId.set(_builtin.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UserTheme get _selected {
|
|
||||||
if (isBuiltinThemeId(_selectedId)) {
|
|
||||||
return _builtin;
|
|
||||||
}
|
|
||||||
return _storedThemes.firstWhere(
|
|
||||||
(t) => t.id == _selectedId,
|
|
||||||
orElse: () => _builtin,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<UserTheme> get _ownThemes =>
|
|
||||||
_storedThemes.where((t) => t.isOwn).toList(growable: false);
|
|
||||||
|
|
||||||
List<UserTheme> get _downloadedThemes =>
|
|
||||||
_storedThemes.where((t) => t.isDownloaded).toList(growable: false);
|
|
||||||
|
|
||||||
Future<void> _persistTheme(UserTheme theme) async {
|
|
||||||
if (theme.isBuiltin) return;
|
|
||||||
await isarInit.writeTxn(() async {
|
|
||||||
await isarInit.userThemeModels.putByThemeId(theme.toModel());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _deleteTheme(String id) async {
|
|
||||||
await isarInit.writeTxn(() async {
|
|
||||||
await isarInit.userThemeModels.deleteByThemeId(id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _setSelected(String id) async {
|
|
||||||
final next = isBuiltinThemeId(id) ? _builtin.id : id;
|
|
||||||
if (isBuiltinThemeId(next)) {
|
|
||||||
final (coreId, gradeId) = parseBuiltinThemeId(next);
|
|
||||||
await Settings.selectedCoreThemeId.set(coreId);
|
|
||||||
await Settings.selectedGradeThemeId.set(gradeId);
|
|
||||||
}
|
|
||||||
setState(() => _selectedId = next);
|
|
||||||
await Settings.selectedThemeId.set(next);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _selectBuiltin() async {
|
|
||||||
final id = composeBuiltinThemeId(
|
|
||||||
Settings.selectedCoreThemeId.value,
|
|
||||||
Settings.selectedGradeThemeId.value,
|
|
||||||
);
|
|
||||||
await _setSelected(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _createTheme() async {
|
|
||||||
final name = await showThemeNameSheet(context, widget.data.l10n);
|
|
||||||
if (name == null || !mounted) return;
|
|
||||||
|
|
||||||
final theme = UserTheme(
|
|
||||||
id: Snowflake.nextId(),
|
|
||||||
name: name,
|
|
||||||
origin: ThemeOrigin.own,
|
|
||||||
swatch: UserTheme.swatchFromAppStyle(),
|
|
||||||
);
|
|
||||||
await _persistTheme(theme);
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() => _storedThemes.add(theme));
|
|
||||||
await _openTheme(theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _renameTheme(UserTheme theme, String name) async {
|
|
||||||
setState(() => theme.name = name);
|
|
||||||
await _persistTheme(theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _openTheme(UserTheme theme) async {
|
|
||||||
final openTheme = theme.isBuiltin ? _builtin : theme;
|
|
||||||
await context.push(
|
|
||||||
"/theme",
|
|
||||||
extra: ThemeScreenArgs(
|
|
||||||
theme: openTheme,
|
|
||||||
onUse: (id) => _setSelected(id),
|
|
||||||
onDelete: (id) async {
|
|
||||||
await _deleteTheme(id);
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_storedThemes.removeWhere((t) => t.id == id);
|
|
||||||
if (_selectedId == id) {
|
|
||||||
_selectedId = _builtin.id;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (isBuiltinThemeId(_selectedId)) {
|
|
||||||
await _selectBuiltin();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onChanged: () {
|
|
||||||
_persistTheme(theme);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (mounted) setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _sectionLabel(String text) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 16),
|
|
||||||
child: Text(
|
|
||||||
text,
|
|
||||||
style: appStyle.fonts.B_16R.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _checkMark() {
|
|
||||||
return SizedBox(
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
child: Checkbox(
|
|
||||||
value: true,
|
|
||||||
fillColor: WidgetStateProperty.resolveWith<Color>((_) {
|
|
||||||
return appStyle.colors.secondary;
|
|
||||||
}),
|
|
||||||
onChanged: (_) {},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _themeRow(UserTheme theme, {required bool selected}) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => _openTheme(theme),
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
ThemeSwatchIcon(swatch: theme.swatch, size: 36),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
ThemeNameLabel(
|
|
||||||
name: theme.name,
|
|
||||||
editable: theme.canRename,
|
|
||||||
onChanged: (value) => _renameTheme(theme, value),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
right: selected
|
|
||||||
? [_checkMark(), const SizedBox(width: 4)]
|
|
||||||
: const [SizedBox(width: 20)],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _actionRow({
|
|
||||||
required Object icon,
|
|
||||||
required String label,
|
|
||||||
required VoidCallback onTap,
|
|
||||||
}) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: FirkaCard(
|
|
||||||
left: [
|
|
||||||
FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
icon,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: appStyle.fonts.B_16SB.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final l10n = widget.data.l10n;
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: appStyle.colors.background,
|
|
||||||
body: SafeArea(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 0),
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => context.pop(),
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.chevronLeftLine,
|
|
||||||
color: appStyle.colors.textSecondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Transform.translate(
|
|
||||||
offset: const Offset(-4, 1),
|
|
||||||
child: Text(
|
|
||||||
l10n.s_c_my_themes,
|
|
||||||
style: appStyle.fonts.H_H2.apply(
|
|
||||||
color: appStyle.colors.textPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: _createTheme,
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.plusLine,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: () {},
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.shareLine,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FirkaIconButton(
|
|
||||||
onTap: () {},
|
|
||||||
child: FirkaIconWidget(
|
|
||||||
FirkaIconType.majesticons,
|
|
||||||
Majesticon.arrowDownCircleLine,
|
|
||||||
size: 20,
|
|
||||||
color: appStyle.colors.accent,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: _loading
|
|
||||||
? const Center(child: CircularProgressIndicator())
|
|
||||||
: ListView(
|
|
||||||
children: [
|
|
||||||
_sectionLabel(l10n.s_c_themes_current),
|
|
||||||
_themeRow(_selected, selected: true),
|
|
||||||
if (!_selected.isBuiltin)
|
|
||||||
_actionRow(
|
|
||||||
icon: Majesticon.shareLine,
|
|
||||||
label: l10n.s_c_themes_share_current,
|
|
||||||
onTap: () {},
|
|
||||||
),
|
|
||||||
_sectionLabel(l10n.s_c_themes_own),
|
|
||||||
for (final theme in _ownThemes)
|
|
||||||
_themeRow(
|
|
||||||
theme,
|
|
||||||
selected: theme.id == _selectedId,
|
|
||||||
),
|
|
||||||
_actionRow(
|
|
||||||
icon: Majesticon.plusLine,
|
|
||||||
label: l10n.s_c_themes_create_new,
|
|
||||||
onTap: _createTheme,
|
|
||||||
),
|
|
||||||
_sectionLabel(l10n.s_c_themes_downloaded),
|
|
||||||
for (final theme in _downloadedThemes)
|
|
||||||
_themeRow(
|
|
||||||
theme,
|
|
||||||
selected: theme.id == _selectedId,
|
|
||||||
),
|
|
||||||
_actionRow(
|
|
||||||
icon: Majesticon.arrowDownCircleLine,
|
|
||||||
label: l10n.s_c_themes_import,
|
|
||||||
onTap: () {},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
import "package:firka_common/data/models/user_theme_model.dart";
|
|
||||||
import "package:firka_common/ui/theme/core_theme.dart";
|
|
||||||
import "package:firka_common/ui/theme/grade_theme.dart";
|
|
||||||
|
|
||||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
|
|
||||||
enum ThemeOrigin { builtin, own, downloaded }
|
|
||||||
|
|
||||||
class UserTheme {
|
|
||||||
final String id;
|
|
||||||
String name;
|
|
||||||
final ThemeOrigin origin;
|
|
||||||
final List<Color> swatch;
|
|
||||||
|
|
||||||
UserTheme({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
required this.origin,
|
|
||||||
required this.swatch,
|
|
||||||
});
|
|
||||||
|
|
||||||
bool get isBuiltin =>
|
|
||||||
origin == ThemeOrigin.builtin || isBuiltinThemeId(id);
|
|
||||||
bool get isOwn => origin == ThemeOrigin.own && !isBuiltinThemeId(id);
|
|
||||||
bool get isDownloaded => origin == ThemeOrigin.downloaded;
|
|
||||||
bool get canRename => isOwn;
|
|
||||||
bool get canDelete => !isBuiltin;
|
|
||||||
|
|
||||||
static List<Color> swatchFromCore(CoreTheme core, {bool isLight = true}) {
|
|
||||||
final colors = core.forBrightness(isLight);
|
|
||||||
return [colors.accent, colors.textPrimary, colors.background];
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<Color> swatchFromAppStyle() {
|
|
||||||
return [
|
|
||||||
appStyle.colors.accent,
|
|
||||||
appStyle.colors.textPrimary,
|
|
||||||
appStyle.colors.background,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
static UserTheme builtin(
|
|
||||||
String displayName, {
|
|
||||||
String coreId = defaultCoreThemeId,
|
|
||||||
String gradeId = defaultGradeThemeId,
|
|
||||||
bool isLight = true,
|
|
||||||
}) {
|
|
||||||
final core = resolveCore(coreId);
|
|
||||||
final grade = resolveGrade(gradeId);
|
|
||||||
return UserTheme(
|
|
||||||
id: composeBuiltinThemeId(core.id, grade.id),
|
|
||||||
name: displayName,
|
|
||||||
origin: ThemeOrigin.builtin,
|
|
||||||
swatch: swatchFromCore(core, isLight: isLight),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
factory UserTheme.fromModel(UserThemeModel model) {
|
|
||||||
return UserTheme(
|
|
||||||
id: model.themeId,
|
|
||||||
name: model.name,
|
|
||||||
origin: switch (model.origin) {
|
|
||||||
"downloaded" => ThemeOrigin.downloaded,
|
|
||||||
_ => ThemeOrigin.own,
|
|
||||||
},
|
|
||||||
swatch: model.swatchArgb.map(Color.new).toList(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserThemeModel toModel() {
|
|
||||||
return UserThemeModel()
|
|
||||||
..themeId = id
|
|
||||||
..name = name
|
|
||||||
..origin = switch (origin) {
|
|
||||||
ThemeOrigin.downloaded => "downloaded",
|
|
||||||
ThemeOrigin.own || ThemeOrigin.builtin => "own",
|
|
||||||
}
|
|
||||||
..swatchArgb = swatch.map((c) => c.toARGB32()).toList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ThemeScreenArgs {
|
|
||||||
final UserTheme theme;
|
|
||||||
final Future<void> Function(String id) onUse;
|
|
||||||
final Future<void> Function(String id) onDelete;
|
|
||||||
final VoidCallback onChanged;
|
|
||||||
|
|
||||||
const ThemeScreenArgs({
|
|
||||||
required this.theme,
|
|
||||||
required this.onUse,
|
|
||||||
required this.onDelete,
|
|
||||||
required this.onChanged,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
import "package:firka/ui/theme/style.dart";
|
|
||||||
|
|
||||||
/// Plain-looking theme name that becomes an undecorated text field when tapped
|
|
||||||
/// (own themes only).
|
|
||||||
class ThemeNameLabel extends StatefulWidget {
|
|
||||||
final String name;
|
|
||||||
final bool editable;
|
|
||||||
final ValueChanged<String>? onChanged;
|
|
||||||
final TextStyle? style;
|
|
||||||
|
|
||||||
const ThemeNameLabel({
|
|
||||||
required this.name,
|
|
||||||
required this.editable,
|
|
||||||
this.onChanged,
|
|
||||||
this.style,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ThemeNameLabel> createState() => _ThemeNameLabelState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ThemeNameLabelState extends State<ThemeNameLabel> {
|
|
||||||
late final TextEditingController _controller;
|
|
||||||
late final FocusNode _focusNode;
|
|
||||||
bool _editing = false;
|
|
||||||
late String _committed;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_committed = widget.name;
|
|
||||||
_controller = TextEditingController(text: widget.name);
|
|
||||||
_focusNode = FocusNode();
|
|
||||||
_focusNode.addListener(_onFocusChange);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(covariant ThemeNameLabel oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (!_editing && widget.name != _committed) {
|
|
||||||
_committed = widget.name;
|
|
||||||
_controller.text = widget.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_focusNode.removeListener(_onFocusChange);
|
|
||||||
_focusNode.dispose();
|
|
||||||
_controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
TextStyle get _style =>
|
|
||||||
widget.style ??
|
|
||||||
appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary);
|
|
||||||
|
|
||||||
void _onFocusChange() {
|
|
||||||
if (!_focusNode.hasFocus && _editing) {
|
|
||||||
_commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _startEditing() {
|
|
||||||
if (!widget.editable) return;
|
|
||||||
setState(() {
|
|
||||||
_editing = true;
|
|
||||||
_controller.text = _committed;
|
|
||||||
_controller.selection = TextSelection(
|
|
||||||
baseOffset: 0,
|
|
||||||
extentOffset: _controller.text.length,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
_focusNode.requestFocus();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _commit() {
|
|
||||||
final next = _controller.text.trim();
|
|
||||||
final value = next.isEmpty ? _committed : next;
|
|
||||||
_controller.text = value;
|
|
||||||
if (value != _committed) {
|
|
||||||
_committed = value;
|
|
||||||
widget.onChanged?.call(value);
|
|
||||||
}
|
|
||||||
setState(() => _editing = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (!widget.editable) {
|
|
||||||
return Text(widget.name, style: _style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_editing) {
|
|
||||||
return GestureDetector(
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
onTap: _startEditing,
|
|
||||||
child: Text(_committed, style: _style),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TextField(
|
|
||||||
controller: _controller,
|
|
||||||
focusNode: _focusNode,
|
|
||||||
style: _style,
|
|
||||||
cursorColor: appStyle.colors.accent,
|
|
||||||
textInputAction: TextInputAction.done,
|
|
||||||
onSubmitted: (_) => _commit(),
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
isDense: true,
|
|
||||||
border: InputBorder.none,
|
|
||||||
enabledBorder: InputBorder.none,
|
|
||||||
focusedBorder: InputBorder.none,
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import "package:flutter/material.dart";
|
|
||||||
|
|
||||||
class ThemeSwatchIcon extends StatelessWidget {
|
|
||||||
final List<Color> swatch;
|
|
||||||
final double size;
|
|
||||||
|
|
||||||
const ThemeSwatchIcon({
|
|
||||||
required this.swatch,
|
|
||||||
this.size = 40,
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final colors = swatch.length >= 3
|
|
||||||
? swatch.take(3).toList()
|
|
||||||
: [
|
|
||||||
...swatch,
|
|
||||||
...List.filled(3 - swatch.length, Colors.grey),
|
|
||||||
];
|
|
||||||
|
|
||||||
return SizedBox(
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
child: CustomPaint(
|
|
||||||
painter: _SwatchPainter(colors: colors),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SwatchPainter extends CustomPainter {
|
|
||||||
final List<Color> colors;
|
|
||||||
|
|
||||||
_SwatchPainter({required this.colors});
|
|
||||||
|
|
||||||
@override
|
|
||||||
void paint(Canvas canvas, Size size) {
|
|
||||||
final r = size.shortestSide * 0.29;
|
|
||||||
final cx = size.width / 2;
|
|
||||||
final cy = size.height / 2;
|
|
||||||
final d = r * 1.5;
|
|
||||||
final left = Offset(cx - d / 2, cy - d * 0.29);
|
|
||||||
final right = Offset(cx + d / 2, cy - d * 0.29);
|
|
||||||
final bottom = Offset(cx, cy + d * 0.58);
|
|
||||||
final centers = [left, right, bottom];
|
|
||||||
|
|
||||||
// Soft per-circle halo.
|
|
||||||
for (var i = 0; i < 3; i++) {
|
|
||||||
canvas.drawCircle(
|
|
||||||
centers[i],
|
|
||||||
r,
|
|
||||||
Paint()
|
|
||||||
..color = colors[i].withValues(alpha: 0.4)
|
|
||||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 2.5),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Union blend: no white backdrop (that was leaking). First SrcOver, then
|
|
||||||
// Multiply so overlaps mix; bottom on top with opacity to lighten.
|
|
||||||
final bounds = Offset.zero & size;
|
|
||||||
canvas.saveLayer(bounds, Paint());
|
|
||||||
canvas.drawCircle(left, r, Paint()..color = colors[0]);
|
|
||||||
canvas.drawCircle(
|
|
||||||
right,
|
|
||||||
r,
|
|
||||||
Paint()
|
|
||||||
..color = colors[1]
|
|
||||||
..blendMode = BlendMode.multiply,
|
|
||||||
);
|
|
||||||
canvas.restore();
|
|
||||||
|
|
||||||
canvas.drawCircle(
|
|
||||||
bottom,
|
|
||||||
r,
|
|
||||||
Paint()..color = colors[2].withValues(alpha: 0.75),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldRepaint(covariant _SwatchPainter oldDelegate) {
|
|
||||||
return oldDelegate.colors != colors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -55,9 +55,7 @@ class BottomNavIconWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
FittedBox(
|
FittedBox(
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
clipBehavior: Clip.none,
|
|
||||||
child: Text(
|
child: Text(
|
||||||
text,
|
text,
|
||||||
style: appStyle.fonts.B_14R.apply(
|
style: appStyle.fonts.B_14R.apply(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/l10n/app_localizations.dart';
|
import 'package:firka/l10n/app_localizations.dart';
|
||||||
|
import 'package:firka_common/ui/components/firka_card.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ class DomainBrowserWebviewWidget extends StatefulWidget {
|
|||||||
final AppInitialization? data;
|
final AppInitialization? data;
|
||||||
final String? url;
|
final String? url;
|
||||||
|
|
||||||
const DomainBrowserWebviewWidget({super.key, this.data, this.url});
|
const DomainBrowserWebviewWidget({
|
||||||
|
super.key,
|
||||||
|
this.data,
|
||||||
|
this.url,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DomainBrowserWebviewWidget> createState() =>
|
State<DomainBrowserWebviewWidget> createState() =>
|
||||||
@@ -47,10 +51,8 @@ class _DomainBrowserWebviewWidgetState
|
|||||||
end: 0.0,
|
end: 0.0,
|
||||||
).animate(_fadeAnimationController!);
|
).animate(_fadeAnimationController!);
|
||||||
|
|
||||||
assert(
|
assert(widget.data != null && widget.url != null,
|
||||||
widget.data != null && widget.url != null,
|
'DomainBrowserWebviewWidget requires non-null data and url');
|
||||||
'DomainBrowserWebviewWidget requires non-null data and url',
|
|
||||||
);
|
|
||||||
|
|
||||||
_webViewController = WebViewController()
|
_webViewController = WebViewController()
|
||||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||||
@@ -91,12 +93,10 @@ class _DomainBrowserWebviewWidgetState
|
|||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final data = widget.data!;
|
||||||
final mediaQuery = MediaQuery.of(context);
|
final mediaQuery = MediaQuery.of(context);
|
||||||
final safePadding = mediaQuery.padding;
|
final safePadding = mediaQuery.padding;
|
||||||
final displayUrl = (widget.url ?? '').replaceFirst(
|
final displayUrl = (widget.url ?? '').replaceFirst(RegExp(r'^https?://'), '');
|
||||||
RegExp(r'^https?://'),
|
|
||||||
'',
|
|
||||||
);
|
|
||||||
final displayParts = displayUrl.split('/');
|
final displayParts = displayUrl.split('/');
|
||||||
final host = displayParts.isNotEmpty ? displayParts.first : displayUrl;
|
final host = displayParts.isNotEmpty ? displayParts.first : displayUrl;
|
||||||
final path = displayParts.length > 1
|
final path = displayParts.length > 1
|
||||||
@@ -158,7 +158,7 @@ class _DomainBrowserWebviewWidgetState
|
|||||||
color: appStyle.colors.accent,
|
color: appStyle.colors.accent,
|
||||||
size: 16,
|
size: 16,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -186,8 +186,8 @@ class _DomainBrowserWebviewWidgetState
|
|||||||
opacity: _isLoading
|
opacity: _isLoading
|
||||||
? 1.0
|
? 1.0
|
||||||
: _fadeAnimationController!.isAnimating
|
: _fadeAnimationController!.isAnimating
|
||||||
? _fadeAnimation!.value
|
? _fadeAnimation!.value
|
||||||
: 0.0,
|
: 0.0,
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
child: Container(
|
child: Container(
|
||||||
color: appStyle.colors.background,
|
color: appStyle.colors.background,
|
||||||
@@ -232,8 +232,7 @@ class _DomainBrowserWebviewWidgetState
|
|||||||
text: path,
|
text: path,
|
||||||
style: appStyle.fonts.B_14R.copyWith(
|
style: appStyle.fonts.B_14R.copyWith(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color:
|
color: appStyle.colors.textTeritary ??
|
||||||
appStyle.colors.textTeritary ??
|
|
||||||
appStyle.colors.textSecondary,
|
appStyle.colors.textSecondary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka_common/core/grade_helper.dart';
|
import 'package:firka/core/settings.dart';
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
import 'package:firka_common/firka_common.dart';
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
|
||||||
import 'package:firka_common/ui/theme/style.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/routing/chart_interaction_scope.dart';
|
import 'package:firka/routing/chart_interaction_scope.dart';
|
||||||
import 'package:fl_chart/fl_chart.dart';
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class GradeChart extends StatefulWidget {
|
class GradeChart extends StatefulWidget {
|
||||||
final List<GradeCacheModel> grades;
|
final List<Grade> grades;
|
||||||
final bool halfYearFallback;
|
final bool halfYearFallback;
|
||||||
final bool plotRawValues;
|
|
||||||
GradeChart({
|
GradeChart({
|
||||||
super.key,
|
super.key,
|
||||||
required List<GradeCacheModel> grades,
|
required List<Grade> grades,
|
||||||
this.halfYearFallback = true,
|
this.halfYearFallback = true,
|
||||||
this.plotRawValues = false,
|
|
||||||
}) : grades = grades.where((g) => g.hasClassicValue()).toList()
|
}) : grades = grades.where((g) => g.hasClassicValue()).toList()
|
||||||
..sort((a, b) => a.writtenAt.compareTo(b.writtenAt));
|
..sort((a, b) => a.recordDate.compareTo(b.recordDate));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GradeChart> createState() => _GradeChartState();
|
State<GradeChart> createState() => _GradeChartState();
|
||||||
@@ -51,21 +48,19 @@ class _GradeChartState extends State<GradeChart> {
|
|||||||
|
|
||||||
void _computeSpots() {
|
void _computeSpots() {
|
||||||
spots = [];
|
spots = [];
|
||||||
if (!widget.plotRawValues) {
|
for (var i = 0; i < widget.grades.length; i++) {
|
||||||
for (var i = 0; i < widget.grades.length; i++) {
|
final grade = widget.grades[i];
|
||||||
final grade = widget.grades[i];
|
if (!grade.shouldIncludeInAverage()) {
|
||||||
if (!grade.shouldIncludeInAverage()) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final partialAvg = widget.grades
|
|
||||||
.take(i + 1)
|
|
||||||
.getSubjectAverage(halfYearFallback: widget.halfYearFallback);
|
|
||||||
|
|
||||||
spots.add(
|
|
||||||
DateSpot(spots.length.toDouble(), partialAvg!, grade.writtenAt),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final partialAvg = widget.grades
|
||||||
|
.take(i + 1)
|
||||||
|
.getSubjectAverage(halfYearFallback: widget.halfYearFallback);
|
||||||
|
|
||||||
|
spots.add(
|
||||||
|
DateSpot(spots.length.toDouble(), partialAvg!, grade.recordDate),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spots.isEmpty) {
|
if (spots.isEmpty) {
|
||||||
@@ -75,7 +70,7 @@ class _GradeChartState extends State<GradeChart> {
|
|||||||
DateSpot(
|
DateSpot(
|
||||||
spots.length.toDouble(),
|
spots.length.toDouble(),
|
||||||
grade.numericValue!.toDouble(),
|
grade.numericValue!.toDouble(),
|
||||||
grade.writtenAt,
|
grade.recordDate,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -362,7 +357,7 @@ class _GradeChartState extends State<GradeChart> {
|
|||||||
/// Wraps [GradeChart] with a [Listener] that updates [ChartInteractionScope]
|
/// Wraps [GradeChart] with a [Listener] that updates [ChartInteractionScope]
|
||||||
/// so the navigator does not intercept touch/drag (e.g. for swipe back).
|
/// so the navigator does not intercept touch/drag (e.g. for swipe back).
|
||||||
class GradeChartWithInteraction extends StatelessWidget {
|
class GradeChartWithInteraction extends StatelessWidget {
|
||||||
final List<GradeCacheModel> grades;
|
final List<Grade> grades;
|
||||||
final bool halfYearFallback;
|
final bool halfYearFallback;
|
||||||
|
|
||||||
const GradeChartWithInteraction({
|
const GradeChartWithInteraction({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka_common/core/grade_helper.dart';
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
import 'package:firka/ui/components/grade.dart';
|
||||||
import 'package:firka_common/ui/components/grade.dart';
|
import 'package:firka/ui/components/grade_helpers.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
@@ -10,7 +10,7 @@ import 'package:firka/l10n/app_localizations.dart';
|
|||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|
||||||
class GradeSummaryBar extends StatefulWidget {
|
class GradeSummaryBar extends StatefulWidget {
|
||||||
final List<GradeCacheModel> grades;
|
final List<Grade> grades;
|
||||||
final AppLocalizations l10n;
|
final AppLocalizations l10n;
|
||||||
final bool showAverage;
|
final bool showAverage;
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka/l10n/app_localizations.dart';
|
import 'package:firka/l10n/app_localizations.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka/ui/shared/counter_digit.dart';
|
import 'package:firka/ui/shared/counter_digit.dart';
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
import 'package:firka_common/firka_common.dart';
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
|
||||||
import 'package:firka_common/ui/shared/firka_icon.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
|
|
||||||
class StartingSoonWidget extends StatelessWidget {
|
class StartingSoonWidget extends StatelessWidget {
|
||||||
final AppLocalizations l10n;
|
final AppLocalizations l10n;
|
||||||
final List<LessonCacheModel> lessons;
|
final List<Lesson> lessons;
|
||||||
final DateTime now;
|
final DateTime now;
|
||||||
|
|
||||||
const StartingSoonWidget(this.l10n, this.now, this.lessons, {super.key});
|
const StartingSoonWidget(this.l10n, this.now, this.lessons, {super.key});
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import 'package:confetti/confetti.dart';
|
import 'package:confetti/confetti.dart';
|
||||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/student_cache_model.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka/l10n/app_localizations.dart';
|
import 'package:firka/l10n/app_localizations.dart';
|
||||||
@@ -8,12 +6,13 @@ import 'package:firka/ui/shared/firka_icon.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||||
|
|
||||||
|
import 'package:kreta_api/kreta_api.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
|
|
||||||
class WelcomeWidget extends StatefulWidget {
|
class WelcomeWidget extends StatefulWidget {
|
||||||
final AppLocalizations l10n;
|
final AppLocalizations l10n;
|
||||||
final StudentCacheModel student;
|
final Student student;
|
||||||
final List<LessonCacheModel> lessons;
|
final List<Lesson> lessons;
|
||||||
final DateTime now;
|
final DateTime now;
|
||||||
|
|
||||||
const WelcomeWidget(
|
const WelcomeWidget(
|
||||||
@@ -38,7 +37,7 @@ class _WelcomeWidgetState extends State<WelcomeWidget> {
|
|||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
);
|
);
|
||||||
|
|
||||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthday);
|
final birthDate = DateFormat("MM-dd").format(widget.student.birthdate);
|
||||||
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
||||||
_controllerCenter.play();
|
_controllerCenter.play();
|
||||||
}
|
}
|
||||||
@@ -101,7 +100,7 @@ class _WelcomeWidgetState extends State<WelcomeWidget> {
|
|||||||
name = widget.student.name;
|
name = widget.student.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthday);
|
final birthDate = DateFormat("MM-dd").format(widget.student.birthdate);
|
||||||
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
||||||
return widget.l10n.happy_birthday(name);
|
return widget.l10n.happy_birthday(name);
|
||||||
} else if (widget.lessons.length > 1 &&
|
} else if (widget.lessons.length > 1 &&
|
||||||
@@ -160,7 +159,7 @@ class _WelcomeWidgetState extends State<WelcomeWidget> {
|
|||||||
getIconForCycle(dayCycle),
|
getIconForCycle(dayCycle),
|
||||||
const SizedBox(height: 16.0),
|
const SizedBox(height: 16.0),
|
||||||
Text(
|
Text(
|
||||||
headingText(getTitle(dayCycle)),
|
getTitle(dayCycle),
|
||||||
style: appStyle.fonts.H_H2.copyWith(
|
style: appStyle.fonts.H_H2.copyWith(
|
||||||
color: appStyle.colors.textPrimary,
|
color: appStyle.colors.textPrimary,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
import 'package:firka/app/app_state.dart';
|
import 'package:firka/app/app_state.dart';
|
||||||
import 'package:firka/core/extensions.dart';
|
import 'package:firka/core/extensions.dart';
|
||||||
import 'package:firka_common/core/grade_helper.dart';
|
import 'package:firka/data/models/homework_cache_model.dart';
|
||||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/homework_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/message_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
|
||||||
import 'package:firka_common/data/models/test_cache_model.dart';
|
|
||||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||||
import 'package:firka_common/ui/components/firka_card.dart';
|
import 'package:firka/ui/components/firka_card.dart';
|
||||||
import 'package:firka_common/ui/components/grade.dart';
|
import 'package:firka/ui/components/grade.dart';
|
||||||
|
import 'package:firka/ui/components/grade_helpers.dart';
|
||||||
import 'package:firka/ui/shared/class_icon.dart';
|
import 'package:firka/ui/shared/class_icon.dart';
|
||||||
import 'package:firka/ui/shared/firka_icon.dart';
|
import 'package:firka/ui/shared/firka_icon.dart';
|
||||||
import 'package:firka/ui/theme/style.dart';
|
import 'package:firka/ui/theme/style.dart';
|
||||||
import 'package:firka_common/data/util.dart';
|
|
||||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -41,19 +35,17 @@ class InfoCard extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
static Widget buildSubject(Color color, SubjectCacheModel subject) {
|
static Widget buildSubject(Color color, Subject subject) {
|
||||||
return FilledCircle(
|
return FilledCircle(
|
||||||
diameter: 32,
|
diameter: 32,
|
||||||
color: color.withAlpha(38),
|
color: color.withAlpha(38),
|
||||||
child: ClassIconWidget(subject: subject, color: color, size: 20),
|
child: ClassIconWidget.subject(subject: subject, color: color, size: 20),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.test(TestCacheModel test) {
|
factory InfoCard.test(Test test) {
|
||||||
final color = appStyle.colors.accent;
|
final color = appStyle.colors.accent;
|
||||||
|
|
||||||
final subject = test.lesson.loadAndGet()!.subject.loadAndGet()!;
|
|
||||||
|
|
||||||
return InfoCard(
|
return InfoCard(
|
||||||
icon: FilledCircle(
|
icon: FilledCircle(
|
||||||
diameter: 36,
|
diameter: 36,
|
||||||
@@ -66,21 +58,19 @@ class InfoCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
texts: [
|
texts: [
|
||||||
test.topic?.firstUpper() ?? test.method,
|
test.theme?.firstUpper() ?? test.method.description,
|
||||||
subject.name.firstUpper(),
|
test.subject.name.firstUpper(),
|
||||||
],
|
],
|
||||||
right: [buildSubject(color, subject)],
|
right: [buildSubject(color, test.subject)],
|
||||||
onTap: (context) => showTestBottomSheet(context, initData, test),
|
onTap: (context) => showTestBottomSheet(context, initData, test),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.testDesc(TestCacheModel test) {
|
factory InfoCard.testDesc(Test test) {
|
||||||
if (test.topic == null) {
|
if (test.theme == null) {
|
||||||
return InfoCard.test(test);
|
return InfoCard.test(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
final subject = test.lesson.loadAndGet()!.subject.loadAndGet()!;
|
|
||||||
|
|
||||||
final color = appStyle.colors.accent;
|
final color = appStyle.colors.accent;
|
||||||
|
|
||||||
return InfoCard(
|
return InfoCard(
|
||||||
@@ -94,13 +84,13 @@ class InfoCard extends StatelessWidget {
|
|||||||
size: 24,
|
size: 24,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
texts: [test.topic!.firstUpper(), test.method.firstUpper()],
|
texts: [test.theme!.firstUpper(), test.method.description.firstUpper()],
|
||||||
right: [buildSubject(color, subject)],
|
right: [buildSubject(color, test.subject)],
|
||||||
onTap: (context) => showTestBottomSheet(context, initData, test),
|
onTap: (context) => showTestBottomSheet(context, initData, test),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.messageItem(MessageCacheModel item) {
|
factory InfoCard.messageItem(MessageItem item) {
|
||||||
return InfoCard(
|
return InfoCard(
|
||||||
icon: FilledCircle(
|
icon: FilledCircle(
|
||||||
diameter: 36,
|
diameter: 36,
|
||||||
@@ -115,7 +105,7 @@ class InfoCard extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.omission(List<OmissionCacheModel> omissions) {
|
factory InfoCard.omission(List<Omission> omissions) {
|
||||||
String title = "-";
|
String title = "-";
|
||||||
Color color = appStyle.colors.accent;
|
Color color = appStyle.colors.accent;
|
||||||
FirkaIconType iconType = FirkaIconType.majesticons;
|
FirkaIconType iconType = FirkaIconType.majesticons;
|
||||||
@@ -162,56 +152,68 @@ class InfoCard extends StatelessWidget {
|
|||||||
title,
|
title,
|
||||||
DateFormat.MMMMd(
|
DateFormat.MMMMd(
|
||||||
initData.l10n.localeName,
|
initData.l10n.localeName,
|
||||||
).format(omissions.first.createdAt).firstUpper(),
|
).format(omissions.first.date).firstUpper(),
|
||||||
],
|
],
|
||||||
onTap: (context) =>
|
onTap: (context) =>
|
||||||
showOmissionBottomSheet(context, initData, title, omissions),
|
showOmissionBottomSheet(context, initData, title, omissions),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.homework(HomeworkCacheModel homework) {
|
factory InfoCard.homework(Homework homework) {
|
||||||
final subject = homework.subject.loadAndGet()!;
|
|
||||||
return InfoCard(
|
return InfoCard(
|
||||||
icon: FilledCircle(
|
icon: FilledCircle(
|
||||||
diameter: 36,
|
diameter: 36,
|
||||||
color: appStyle.colors.accent.withAlpha(38),
|
color: appStyle.colors.accent.withAlpha(38),
|
||||||
child: homework.isDone
|
child: FutureBuilder<bool>(
|
||||||
? FirkaIconWidget(
|
future: isHomeworkDone(initData.isar, homework.uid),
|
||||||
FirkaIconType.majesticonsLocal,
|
builder: (context, snapshot) {
|
||||||
"homeWithMark",
|
if (!snapshot.hasData) {
|
||||||
color: appStyle.colors.accent,
|
return SizedBox();
|
||||||
size: 24,
|
}
|
||||||
)
|
final done = snapshot.data!;
|
||||||
: FirkaIconWidget(
|
return done
|
||||||
FirkaIconType.majesticons,
|
? FirkaIconWidget(
|
||||||
Majesticon.homeSolid,
|
FirkaIconType.majesticonsLocal,
|
||||||
color: appStyle.colors.accent,
|
"homeWithMark",
|
||||||
size: 24,
|
color: appStyle.colors.accent,
|
||||||
),
|
size: 24,
|
||||||
|
)
|
||||||
|
: FirkaIconWidget(
|
||||||
|
FirkaIconType.majesticons,
|
||||||
|
Majesticon.homeSolid,
|
||||||
|
color: appStyle.colors.accent,
|
||||||
|
size: 24,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
texts: [initData.l10n.homework, subject.name],
|
texts: [initData.l10n.homework, homework.subjectName],
|
||||||
right: [buildSubject(appStyle.colors.accent, subject)],
|
right: [buildSubject(appStyle.colors.accent, homework.subject)],
|
||||||
onTap: (context) => showHomeworkBottomSheet(context, initData, homework),
|
onTap: (context) => showHomeworkBottomSheet(context, initData, homework),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.gradeSubj(
|
factory InfoCard.gradeSubj(
|
||||||
GradeCacheModel grade, {
|
Grade grade, {
|
||||||
void Function(BuildContext)? onTap,
|
void Function(BuildContext)? onTap,
|
||||||
}) {
|
}) {
|
||||||
String? value = grade.numericValue == null ? grade.textValue : null;
|
String? value = grade.numericValue == null ? grade.strValue : null;
|
||||||
return InfoCard(
|
return InfoCard(
|
||||||
icon: GradeWidget(grade),
|
icon: GradeWidget(grade),
|
||||||
texts: [
|
texts: [
|
||||||
(value ?? grade.topic ?? grade.mode ?? grade.type).firstUpper(),
|
(value ??
|
||||||
grade.subject.loadAndGet()!.name.firstUpper(),
|
grade.topic ??
|
||||||
|
grade.mode?.description ??
|
||||||
|
grade.type.description!)
|
||||||
|
.firstUpper(),
|
||||||
|
grade.subject.name.firstUpper(),
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
buildSubject(
|
buildSubject(
|
||||||
grade.numericValue != null
|
grade.numericValue != null
|
||||||
? getGradeColor(grade.numericValue!)
|
? getGradeColor(grade.numericValue!)
|
||||||
: appStyle.colors.accent,
|
: appStyle.colors.accent,
|
||||||
grade.subject.loadAndGet()!,
|
grade.subject,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
onTap:
|
onTap:
|
||||||
@@ -233,10 +235,12 @@ class InfoCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
factory InfoCard.gradeDesc(
|
factory InfoCard.gradeDesc(
|
||||||
GradeCacheModel grade, {
|
Grade grade, {
|
||||||
void Function(BuildContext)? onTap,
|
void Function(BuildContext)? onTap,
|
||||||
}) {
|
}) {
|
||||||
List<String> texts = [(grade.mode ?? grade.type).firstUpper()];
|
List<String> texts = [
|
||||||
|
(grade.mode?.description ?? grade.type.description!).firstUpper(),
|
||||||
|
];
|
||||||
|
|
||||||
if (grade.topic != null) {
|
if (grade.topic != null) {
|
||||||
texts = [grade.topic!.firstUpper(), ...texts];
|
texts = [grade.topic!.firstUpper(), ...texts];
|
||||||
@@ -245,9 +249,7 @@ class InfoCard extends StatelessWidget {
|
|||||||
return InfoCard(
|
return InfoCard(
|
||||||
icon: GradeWidget(grade),
|
icon: GradeWidget(grade),
|
||||||
texts: texts,
|
texts: texts,
|
||||||
right: [
|
right: [buildSubject(appStyle.colors.accent, grade.subject)],
|
||||||
buildSubject(appStyle.colors.accent, grade.subject.loadAndGet()!),
|
|
||||||
],
|
|
||||||
onTap:
|
onTap:
|
||||||
onTap ?? (context) => showGradeBottomSheet(context, initData, grade),
|
onTap ?? (context) => showGradeBottomSheet(context, initData, grade),
|
||||||
);
|
);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user