forked from firka/firka
Compare commits
163 Commits
fix/ignore
...
backup/ios
| Author | SHA1 | Date | |
|---|---|---|---|
| 05c1cce469 | |||
| 0b1313d0be | |||
| 5a79c48e6d | |||
| 7bf9351b22 | |||
|
|
368ad86f71 | ||
|
|
46a508cc33 | ||
|
|
2923d868e6 | ||
|
|
7f33b50822 | ||
|
|
54d792eb01 | ||
|
|
c8b402118c | ||
|
|
c0f3e61b90 | ||
|
|
9aaf43892f | ||
|
|
a64a7f7509 | ||
|
|
1225e6763f | ||
|
|
b159530de9 | ||
|
|
5fb1f6cc30 | ||
|
|
670968247a | ||
| 5847301e70 | |||
|
|
6342f16d80 | ||
|
|
7167bf8da4 | ||
|
|
7747e5d90b | ||
|
|
49ec23c18e | ||
| 37e7cac61e | |||
| d64ea1d2d6 | |||
| d010544ff2 | |||
| 20d0cf9736 | |||
| c8c299ba36 | |||
| f3414499a7 | |||
| 4b1d113918 | |||
| 0e965a87b9 | |||
| ead4dcd7b6 | |||
| 155d42d4d9 | |||
| caa4db3254 | |||
| 4e64dd9959 | |||
| 07f6a5c562 | |||
| f74ddb4c88 | |||
| 97b06044a4 | |||
| 2311556309 | |||
| 7a2bfb2cd8 | |||
| 39f683a0bf | |||
| 3576a3ab1e | |||
| 04af2c0402 | |||
| 70ff3ae8b9 | |||
| 5a42884d20 | |||
| 3fb0fd55de | |||
| 4c06daf02f | |||
| 3d07b2b2ce | |||
| 9a45c5c456 | |||
|
|
858d558cc3 | ||
|
|
76f345cd6b | ||
|
|
e211d64ffb | ||
|
|
c67ce7472a | ||
|
|
2b9ac14d6e | ||
|
|
eea10a4878 | ||
|
|
1ef6ae6e87 | ||
|
|
141431f378 | ||
|
|
f0114e3976 | ||
|
|
414a1ad254 | ||
|
|
d858c38bb1 | ||
|
|
87e3331428 | ||
|
|
1d912abc7d | ||
| 3a2cdfce05 | |||
| c5ba318c3b | |||
| fe9a2b36f1 | |||
| 80b05c1500 | |||
| 2ed6a04bf5 | |||
| 2d5ff89cad | |||
| 16b11564cc | |||
| 1ca975f0bd | |||
| 7985a11f99 | |||
| 2cf95375cb | |||
| 163b3a3135 | |||
| e839b8fa70 | |||
| c6378c9d46 | |||
| 51456b3b6e | |||
|
|
28f8f1d6f8 | ||
| d51c9d6411 | |||
| 4ef2f479d6 | |||
| d81d261c52 | |||
| 5baec2e65f | |||
| 48ea97ecef | |||
|
|
1154997531 | ||
|
|
dde05ce1db | ||
| 99ab6c07f7 | |||
|
|
40c6b83627 | ||
|
|
f4f6ddac72 | ||
|
|
938f2a56c6 | ||
|
|
e1b571afa0 | ||
|
|
729c281f1e | ||
|
|
a61a41e677 | ||
|
|
e8f1f18725 | ||
|
|
613b66bc22 | ||
|
|
1807d96895 | ||
|
|
e06d2168c0 | ||
|
|
91603923bc | ||
|
|
67e9ded2ed | ||
|
|
e9aaa26e26 | ||
|
|
56f15a681c | ||
|
|
178ebf7271 | ||
|
|
70c1397262 | ||
|
|
a334901f84 | ||
|
|
ddba6ad888 | ||
|
|
780aaee1dd | ||
|
|
09c408a6be | ||
|
|
7847878551 | ||
|
|
09ef386eab | ||
|
|
c19dd2f7eb | ||
|
|
39d4f49e99 | ||
|
|
bbdbf406d4 | ||
|
|
b17509f9db | ||
|
|
9ec164daac | ||
|
|
08f691d559 | ||
|
|
ad9e2c6676 | ||
|
|
55dbf12a2f | ||
|
|
4fc13efc52 | ||
|
|
5f16128bb0 | ||
|
|
4c8d73aa06 | ||
|
|
e4629d8489 | ||
|
|
f806dd8143 | ||
|
|
f653dc9fb4 | ||
|
|
06249bfc3d | ||
|
|
607f49bafc | ||
|
|
251e8de446 | ||
|
|
21845f89a8 | ||
|
|
25b1d06c06 | ||
|
|
dd20aa6138 | ||
|
|
9aa84c6fa1 | ||
|
|
6c75acad66 | ||
|
|
6311cafd51 | ||
|
|
1de32a35a4 | ||
|
|
f8a69a7561 | ||
|
|
f73c1127e7 | ||
|
|
a369e4ab14 | ||
|
|
8b04b77327 | ||
|
|
d56db4fe3a | ||
|
|
e7c0a95638 | ||
|
|
fa66d9af14 | ||
|
|
90c334d859 | ||
|
|
cc9ebcf6b0 | ||
|
|
ac914aa02e | ||
|
|
061f803f93 | ||
|
|
57c5e17b1c | ||
|
|
fa6f5390b1 | ||
|
|
21ff8f082f | ||
|
|
3b09d072f0 | ||
|
|
84f8e75694 | ||
|
|
1a05cce49b | ||
|
|
e732168a1b | ||
|
|
68035140b9 | ||
|
|
e004b7ee35 | ||
|
|
34718ed8ae | ||
|
|
03a5b5e767 | ||
|
|
d30dc67626 | ||
|
|
d0a517ae1e | ||
| 32a6452c1b | |||
| 579bf6bcad | |||
| 4ecf0d1a3f | |||
| 0675a5109a | |||
| bfb06d3e5f | |||
| 71b4b6aec7 | |||
| be6d28cfe3 | |||
| 8cfca13d1a | |||
| 632bb81408 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,6 +1,8 @@
|
||||
[submodule "firka/lib/l10n"]
|
||||
path = firka/lib/l10n
|
||||
url = https://github.com/QwIT-Development/firka-localization
|
||||
url = https://git.firka.app/firka/firka-localization
|
||||
branch = weblate
|
||||
[submodule "firka_wear/lib/l10n"]
|
||||
path = firka_wear/lib/l10n
|
||||
url = https://github.com/qwit-development/firka-localization
|
||||
url = https://git.firka.app/firka/firka-localization
|
||||
branch = weblate
|
||||
|
||||
35
CONTRIBUTING_de.md
Normal file
35
CONTRIBUTING_de.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Flutter installieren
|
||||
|
||||
Die Dokumentation zur Installation von Flutter findest du [hier](https://docs.flutter.dev/get-started/install).
|
||||
Das Projekt verwendet derzeit das Flutter SDK 3.41.2.
|
||||
|
||||
# Keystore
|
||||
|
||||
[Dokumentation zu Secrets](secrets/README.md)
|
||||
|
||||
# Dateien generieren
|
||||
|
||||
Flutter-L10N-Dateien und andere Dateien generieren
|
||||
|
||||
```shell
|
||||
$ cd firka # oder firka_wear
|
||||
$ dart run scripts/codegen.dart
|
||||
```
|
||||
|
||||
# Android-Debug-Build
|
||||
|
||||
Für den Dev-Build ist kein Keystore erforderlich
|
||||
```shell
|
||||
$ cd firka
|
||||
$ flutter build apk --debug --target-platform android-arm,android-arm64,android-x64
|
||||
```
|
||||
|
||||
# Android-Release-Build
|
||||
|
||||
Der Release-Build erfordert die Verwendung eines Keystores.
|
||||
|
||||
## Erstellen des Release-Appbundles (firka und firka_wear)
|
||||
|
||||
```shell
|
||||
$ ./build.sh
|
||||
```
|
||||
195
Jenkinsfile
vendored
195
Jenkinsfile
vendored
@@ -1,167 +1,66 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'ubuntu'
|
||||
}
|
||||
agent any
|
||||
environment {
|
||||
PATH = "/home/jenkins/development/flutter/bin:${env.PATH}"
|
||||
FLUTTER_ROOT = "/opt/flutter"
|
||||
FLUTTER = "/opt/flutter/bin/flutter"
|
||||
DART = "/opt/flutter/bin/dart"
|
||||
ANDROID_SDK_ROOT = "/opt/android-sdk"
|
||||
ANDROID_HOME = "/opt/android-sdk"
|
||||
}
|
||||
stages {
|
||||
stage('Pre-build Cleanup') {
|
||||
stage('Clone Submodules') {
|
||||
steps {
|
||||
script {
|
||||
sh '''#!/bin/sh
|
||||
set -x
|
||||
fusermount -u secrets || true
|
||||
'''
|
||||
}
|
||||
sh 'git submodule update --init --recursive'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Decrypt main keys') {
|
||||
when {
|
||||
branch 'main'
|
||||
}
|
||||
stage('Dependencies') {
|
||||
steps {
|
||||
script {
|
||||
def userInput = input(
|
||||
id: 'signaturePassword',
|
||||
message: 'Please enter the signing key password:',
|
||||
parameters: [
|
||||
password(
|
||||
defaultValue: '',
|
||||
description: 'Enter the signing key password',
|
||||
name: 'password'
|
||||
)
|
||||
]
|
||||
)
|
||||
env.PASSWORD = userInput.toString()
|
||||
}
|
||||
sh '''#!/bin/sh
|
||||
echo \$PASSWORD | gocryptfs $HOME/android_secrets secrets/ -nonempty
|
||||
sh '''
|
||||
cd firka
|
||||
$FLUTTER pub get
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Clone submodules') {
|
||||
stage('Setup') {
|
||||
steps {
|
||||
sh '''
|
||||
cp -r /opt/secrets ./
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Codegen') {
|
||||
steps {
|
||||
script {
|
||||
sh 'git submodule update --init --recursive'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build firka') {
|
||||
steps {
|
||||
sh 'bash -c "./tools/linux/build_apk.sh ' + env.BRANCH_NAME + '"'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Rename Release APKs') {
|
||||
when {
|
||||
branch 'main'
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
sh '''#!/bin/sh
|
||||
set -e
|
||||
|
||||
APK_DIR="firka/build/app/outputs/flutter-apk"
|
||||
|
||||
# Find all release APKs and rename them
|
||||
for apk_file in $APK_DIR/app-*-release.apk; do
|
||||
if [ -f "$apk_file" ]; then
|
||||
# Extract ABI from filename (e.g., app-arm64-v8a-release.apk -> arm64-v8a)
|
||||
basename_file=$(basename "$apk_file")
|
||||
abi=$(echo "$basename_file" | sed 's/app-//; s/-release.apk//')
|
||||
|
||||
# Create new filename
|
||||
new_name="app.firka.naplo_${abi}.apk"
|
||||
new_path="$APK_DIR/$new_name"
|
||||
|
||||
echo "Renaming $apk_file to $new_path"
|
||||
mv "$apk_file" "$new_path"
|
||||
fi
|
||||
done
|
||||
|
||||
ls -la $APK_DIR/app.firka.naplo_*.apk || echo "APK files not found"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Calculate Version Code') {
|
||||
steps {
|
||||
script {
|
||||
sh '''#!/bin/sh
|
||||
set -e
|
||||
sh '''
|
||||
cd firka
|
||||
|
||||
# Calculate version code based on git commits (same logic as build script)
|
||||
COMMIT_COUNT=$(git rev-list --count HEAD)
|
||||
BASE_BUILD_NUMBER=$((1300 + COMMIT_COUNT))
|
||||
|
||||
if [ "$BRANCH_NAME" = "main" ]; then
|
||||
# For main branch, highest version code is BASE + 3000 (x64 build)
|
||||
VERSION_CODE=$((BASE_BUILD_NUMBER + 3000))
|
||||
else
|
||||
# For debug builds, version code is BASE + 0
|
||||
VERSION_CODE=$BASE_BUILD_NUMBER
|
||||
fi
|
||||
|
||||
echo "Calculated version code: $VERSION_CODE"
|
||||
echo "$VERSION_CODE" > ../version_code.txt
|
||||
'''
|
||||
|
||||
env.VERSION_CODE = readFile('version_code.txt').trim()
|
||||
echo "Setting VERSION_CODE environment variable to: ${env.VERSION_CODE}"
|
||||
}
|
||||
PATH="/opt/flutter/bin:$PATH" $DART run scripts/codegen.dart
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish debug artifacts') {
|
||||
when {
|
||||
not {
|
||||
branch 'main'
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh '''
|
||||
cd firka
|
||||
echo "--- Checking secrets path ---"
|
||||
ls android/app/
|
||||
ls android/app/../../../ || echo "no parent"
|
||||
ls android/app/../../../secrets/ || echo "secrets not found at expected path"
|
||||
$FLUTTER config --android-sdk /opt/android-sdk
|
||||
$FLUTTER build apk --release
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
steps {
|
||||
archiveArtifacts artifacts: 'firka/build/app/outputs/flutter-apk/app-debug.apk', fingerprint: true
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish release AABs artifacts') {
|
||||
when {
|
||||
branch 'main'
|
||||
}
|
||||
steps {
|
||||
archiveArtifacts artifacts: 'firka/build/app/outputs/bundle/release/*.aab', fingerprint: true
|
||||
sh 'rm firka/build/app/outputs/bundle/release/*.aab'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish release APKs artifacts') {
|
||||
when {
|
||||
branch 'main'
|
||||
}
|
||||
steps {
|
||||
archiveArtifacts artifacts: 'firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk', fingerprint: true
|
||||
sh 'rm firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Post Cleanup') {
|
||||
steps {
|
||||
script {
|
||||
sh '''
|
||||
rm firka/build/app/outputs/bundle/release/*.aab || true
|
||||
rm firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk || true
|
||||
rm firka/build/app/outputs/flutter-apk/app-debug.apk || true
|
||||
rm version_code.txt || true
|
||||
git checkout -- firka/pubspec.yaml || true
|
||||
git checkout -- firka/lib/helpers/firka_bundle.dart || true
|
||||
'''
|
||||
}
|
||||
archiveArtifacts(
|
||||
artifacts: 'firka/build/app/outputs/flutter-apk/app-debug.apk,firka/build/app/outputs/flutter-apk/app-release.apk',
|
||||
fingerprint: true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
}
|
||||
52
README.md
52
README.md
@@ -1,13 +1,49 @@
|
||||
# Firka Napló
|
||||
# <img src="https://git.firka.app/firka/readme-files/raw/branch/main/dave.png" height="40" /> Firka
|
||||
|
||||
| <sub>HU</sub> [Magyar](README.md) | <sub>EN</sub> [English](README_en.md) |
|
||||
|-----------------------------------|---------------------------------------|
|
||||
| <sub>HU</sub> [Magyar](README.md) | <sub>EN</sub> [English](README_en.md) | <sub>DE</sub> [Deutsch](README_de.md) |
|
||||
|-----------------------------------|---------------------------------------|---------------------------------------|
|
||||
|
||||
[](https://crowdin.com/project/firka)
|
||||
<a href="https://translate.firka.app/engage/firka-naplo/"><img src="https://translate.firka.app/widget/firka-naplo/firka-app/en/svg-badge.svg" alt="Fordítás állapota"></a>
|
||||
<a href="https://status.firka.app/"><img src="https://status.firka.app/api/badge/1/uptime/24?label=Üzemidő&suffix=%" alt="Üzemidő"></a>
|
||||
<a href="https://builds.firka.app/job/Firka%20Beta/"><img src="https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fbuilds.firka.app%2Fjob%2FFirka%2520Beta%2F&label=Build" alt="Build állapota"></a>
|
||||
|
||||
## A projektről
|
||||
### Azért kezdtünk neki ennek a projektnek, mert úgy véltük, hogy a hivatalos alkalmazás nem volt elég jó. A Firka egy teljesen nyílt forráskódú, közösség által karbantartott alternatíva, és ez még csak a kezdet. Minden verzióval gyorsabb, testreszabhatóbb és felhasználóbarátabb lesz.
|
||||
|
||||
Firka egy alternatív [megnevezetlen naplóra] egy kliens alkalmazás. Az alkalmazás célja
|
||||
egy modern, felhasználóbarát felület biztosítása a(z) [megnevezetlen napló] rendszerhez.
|
||||
<img src="https://git.firka.app/firka/readme-files/raw/branch/main/firka_features.png" width="100%" />
|
||||
|
||||
A [fejlesztői környezet beállítsa](CONTRIBUTING.md)
|
||||
<br />
|
||||
|
||||
## Mik egyáltalán az alkalmazás funkciói?
|
||||
### Lásd előre, mi vár rád
|
||||
|
||||
A főképernyő megmutatja a közelgő óráidat, hogy soha ne érjen meglepetés. Szűrj tantárgy, dolgozatok, vagy bármi más alapján, ami számodra fontos. Az alsó sáv teljesen testreszabható – tedd oda, amit használsz, és rejtsd el, amit nem.
|
||||
|
||||
|
||||
### Jegyek, a te feltételeid szerint
|
||||
|
||||
Nem vagy felkészülve a jegyeidre? Ez a beállítás elrejti őket, amíg egyesével meg nem nyitod őket, így kényelmes tempóban dolgozhatod fel minden kudarcodat.
|
||||
|
||||
|
||||
### Pontosan mennyire vagy rossz matekból?
|
||||
|
||||
A jegyek oldalon grafikon mutatja az összesített átlagodat, így végig követheted, ahogyan lassan süllyed a félév során. Minden tantárgyhoz külön grafikon is tartozik, ha pontosan tudni akarod melyik a tettes.
|
||||
|
||||
|
||||
### Szabj testre mindent
|
||||
|
||||
A beállítások képernyőn olyan lehetőségek is vannak, amelyekről nem is tudtad, hogy szükséged van rájuk. Állítsd be a csengő eltolását, hogy másodpercre pontosan tudd, mikor ér véget az óra.
|
||||
Balkezes mód is van, mert úgy tűnik, van, aki nem volt szerencsés az életben.
|
||||
|
||||
|
||||
## Mit támogattok?
|
||||
|
||||
Jelenleg **Androidot** és **iOS-t** támogatunk.
|
||||
<br />
|
||||
Tervezzük a böngészős támogatást is!
|
||||
|
||||
## Contribution
|
||||
Az első lépéseket a [közreműködési útmutatóban](CONTRIBUTING_en.md) találod.
|
||||
|
||||
## Közösség
|
||||
|
||||
[Discord](https://discord.gg/xTspd3zzRZ)
|
||||
51
README_de.md
Normal file
51
README_de.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# <img src="https://git.firka.app/firka/readme-files/raw/branch/main/dave.png" height="40" /> Firka
|
||||
|
||||
| <sub>HU</sub> [Magyar](README.md) | <sub>EN</sub> [English](README_en.md) | <sub>DE</sub> [Deutsch](README_de.md) |
|
||||
|-----------------------------------|---------------------------------------|---------------------------------------|
|
||||
|
||||
<a href="https://translate.firka.app/engage/firka-naplo/"><img src="https://translate.firka.app/widget/firka-naplo/firka-app/en/svg-badge.svg" alt="Translation status"></a>
|
||||
<a href="https://status.firka.app/"><img src="https://status.firka.app/api/badge/1/uptime/24?label=Uptime&suffix=%" alt="Uptime"></a>
|
||||
<a href="https://builds.firka.app/job/Firka%20Beta/"><img src="https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fbuilds.firka.app%2Fjob%2FFirka%2520Beta%2F&label=Build" alt="Build status"></a>
|
||||
|
||||
### Wir haben diese App entwickelt, weil die offizielle App viel zu wünschen übrig ließ. Firka ist eine vollständig open-source, von der Community gepflegte Alternative, und wir stehen erst am Anfang. Mit jedem Release wird sie schneller, anpassbarer und benutzerfreundlicher.
|
||||
|
||||
|
||||
|
||||
<img src="https://git.firka.app/firka/readme-files/raw/branch/main/firka_features.png" width="100%" />
|
||||
|
||||
<br />
|
||||
|
||||
## Was sind überhaupt die Funktionen der App?
|
||||
### Sieh, was ansteht
|
||||
|
||||
Der Startbildschirm zeigt deine anstehenden Lektionen an, damit du nie unvorbereitet bist. Filtere nach Fach, Prüfungen oder was auch immer dir gerade wichtig ist. Die untere Leiste ist vollständig anpassbar: Zeige an was du nutzt und verstecke was du nicht brauchst.
|
||||
|
||||
|
||||
### Noten, ganz nach deinen Vorstellungen
|
||||
|
||||
Emotional nicht bereit für deine eigenen Noten? Diese Einstellung hält sie verborgen, bis du jede einzelne antippst, damit du deine Misserfolge in einem angenehmen Tempo verarbeiten kannst.
|
||||
|
||||
|
||||
### Wie schlecht bist du eigentlich in Mathe?
|
||||
|
||||
Die Noten-Seite enthält ein Diagramm deines Gesamtdurchschnitts, sodass du beobachten kannst, wie er im Laufe des Semesters langsam sinkt. Jedes Fach hat zudem ein eigenes Diagramm, falls du genau wissen möchtest, welches dafür verantwortlich ist.
|
||||
|
||||
|
||||
### Alles anpassen
|
||||
|
||||
Der Einstellungsbildschirm bietet Optionen, von denen du nicht wusstest, dass du sie brauchst. Passe die Glockenverzögerung an, damit du auf die Sekunde genau weißt, wann der Unterricht endet. Es gibt auch einen Linkshänder-Modus, denn anscheinend benutzen manche Leute ihr Handy falsch.
|
||||
|
||||
|
||||
## Was wird unterstützt?
|
||||
|
||||
Derzeit unterstützen wir **Android** und **iOS**.
|
||||
<br />
|
||||
Wir planen, auch deinen Browser zu unterstützen!
|
||||
|
||||
## Mitwirken
|
||||
Wir würden uns sehr über deine Hilfe freuen.
|
||||
Du kannst im [Leitfaden zum unterstützen](CONTRIBUTING_de.md) loslegen.
|
||||
|
||||
## Community
|
||||
|
||||
[Discord](https://discord.gg/xTspd3zzRZ)
|
||||
54
README_en.md
54
README_en.md
@@ -1,13 +1,51 @@
|
||||
# Firka
|
||||
# <img src="https://git.firka.app/firka/readme-files/raw/branch/main/dave.png" height="40" /> Firka
|
||||
|
||||
| <sub>HU</sub> [Magyar](README.md) | <sub>EN</sub> [English](README_en.md) |
|
||||
|-----------------------------------|---------------------------------------|
|
||||
| <sub>HU</sub> [Magyar](README.md) | <sub>EN</sub> [English](README_en.md) | <sub>DE</sub> [Deutsch](README_de.md) |
|
||||
|-----------------------------------|---------------------------------------|---------------------------------------|
|
||||
|
||||
[](https://crowdin.com/project/firka)
|
||||
<a href="https://translate.firka.app/engage/firka-naplo/"><img src="https://translate.firka.app/widget/firka-naplo/firka-app/en/svg-badge.svg" alt="Translation status"></a>
|
||||
<a href="https://status.firka.app/"><img src="https://status.firka.app/api/badge/1/uptime/24?label=Uptime&suffix=%" alt="Uptime"></a>
|
||||
<a href="https://builds.firka.app/job/Firka%20Beta/"><img src="https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fbuilds.firka.app%2Fjob%2FFirka%2520Beta%2F&label=Build" alt="Build status"></a>
|
||||
|
||||
## The project
|
||||
### We built this because the official app left a lot to be desired. Firka is a fully open source, community maintained alternative and we're just getting started. Faster, more customizable, and more user friendly with every release.
|
||||
|
||||
Firka is an alternative client for [an application to be named]. The app's goal is to be a modern
|
||||
user friendly app for the [to be named] system.
|
||||
|
||||
[Contribution guide](CONTRIBUTING_en.md)
|
||||
|
||||
<img src="https://git.firka.app/firka/readme-files/raw/branch/main/firka_features.png" width="100%" />
|
||||
|
||||
<br />
|
||||
|
||||
## What even are the app's features?
|
||||
### See what's coming
|
||||
|
||||
The home screen shows your upcoming lessons so you're never caught off guard. Filter by subject, exams, or whatever you actually care about. The bottom bar is fully customizable, put what you use, hide what you don't.
|
||||
|
||||
|
||||
### Grades, on your terms
|
||||
|
||||
Emotionally unprepared for your own grades? This setting keeps them hidden until you tap each one open, so you can process your failures at a comfortable pace.
|
||||
|
||||
|
||||
### How bad are you at maths, exactly?
|
||||
|
||||
The grades page has a graph of your overall average, so you can watch it slowly decline over the semester. Each subject also gets its own graph, in case you wanted to know exactly which one is responsible.
|
||||
|
||||
|
||||
### Customize everything
|
||||
|
||||
The settings screen has options you didn't know you needed. Adjust the bell offset so you know exactly when class ends down to the second. Left-handed mode exists too, because apparently some people use their phones wrong.
|
||||
|
||||
|
||||
## What do you support?
|
||||
|
||||
Currently, we support **Android** and **iOS**.
|
||||
<br />
|
||||
We're planning on supporting your browser also!
|
||||
|
||||
## Contribution
|
||||
We would really appriciate your help.
|
||||
You can get started at the [contribution guide](CONTRIBUTING_en.md).
|
||||
|
||||
## Community
|
||||
|
||||
[Discord](https://discord.gg/xTspd3zzRZ)
|
||||
48
cache.md
Normal file
48
cache.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# 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|
|
||||
@@ -1,32 +1,23 @@
|
||||
import java.io.FileInputStream
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("kotlin-android")
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "app.firka.naplo"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "app.firka.naplo"
|
||||
// You can update the following values to match your application needs.
|
||||
@@ -36,14 +27,11 @@ android {
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
val secretsDir = File(projectDir.absolutePath, "../../../secrets/")
|
||||
val propsFile = File(secretsDir, "keystore.properties")
|
||||
|
||||
if (propsFile.exists()) {
|
||||
val props = Properties().apply { FileInputStream(propsFile).use { load(it) } }
|
||||
val store = File(secretsDir, props["storeFile"].toString())
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
storeFile = store
|
||||
@@ -57,7 +45,6 @@ android {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
getByName("debug") {
|
||||
applicationIdSuffix = ".debug"
|
||||
@@ -65,20 +52,28 @@ android {
|
||||
}
|
||||
release {
|
||||
val config = signingConfigs.findByName("release")
|
||||
|
||||
if (config != null) {
|
||||
signingConfig = config
|
||||
}
|
||||
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||
compilerOptions {
|
||||
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
force("androidx.test.espresso:espresso-core:3.6.1")
|
||||
force("androidx.test.espresso:espresso-idling-resource:3.6.1")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation("androidx.glance:glance-appwidget:1.1.1")
|
||||
implementation("com.google.android.gms:play-services-wearable:18.1.0")
|
||||
}
|
||||
|
||||
// Ensure .env exists before Flutter bundles assets (copy from .env.example if missing)
|
||||
val envFile = file("${project.projectDir}/../../.env")
|
||||
val envExampleFile = file("${project.projectDir}/../../.env.example")
|
||||
@@ -93,7 +88,6 @@ tasks.register("ensureEnv") {
|
||||
tasks.matching { it.name.startsWith("compileFlutterBuild") }.configureEach {
|
||||
dependsOn("ensureEnv")
|
||||
}
|
||||
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application android:label="Firka Debug"
|
||||
<application android:name="app.firka.naplo.AppMain"
|
||||
android:label="Firka Debug"
|
||||
android:usesCleartextTraffic="true" />
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -16,6 +16,7 @@ import androidx.glance.layout.padding
|
||||
import androidx.glance.layout.width
|
||||
import androidx.glance.text.FontWeight
|
||||
import androidx.glance.text.Text
|
||||
import androidx.glance.text.TextAlign
|
||||
import androidx.glance.text.TextStyle
|
||||
import app.firka.naplo.model.Colors
|
||||
import app.firka.naplo.glance.WidgetLesson
|
||||
@@ -31,6 +32,7 @@ fun LessonCard(
|
||||
colors: Colors,
|
||||
modifier: GlanceModifier = GlanceModifier,
|
||||
roomBadgeWidthDp: Float = 48f,
|
||||
subjectColumnWidthDp: Float = 226f,
|
||||
) {
|
||||
Box(modifier =
|
||||
modifier
|
||||
@@ -49,17 +51,21 @@ fun LessonCard(
|
||||
|
||||
|
||||
Box(modifier = GlanceModifier.padding(12.dp)) {
|
||||
Row {
|
||||
Row(modifier = GlanceModifier.fillMaxWidth()) {
|
||||
val badgeStyle = TextStyle(
|
||||
color = ColorProvider(colors.textSecondary, colors.textSecondary),
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
val badgePadding = GlanceModifier.padding(8.dp, 4.dp)
|
||||
val lessonNumberBadgeModifier = GlanceModifier.cornerRadius(16.dp).width(24.dp)
|
||||
val roomBadgeModifier = GlanceModifier.cornerRadius(16.dp).width(roomBadgeWidthDp.dp)
|
||||
|
||||
Row(modifier = GlanceModifier.width(226.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(
|
||||
modifier = GlanceModifier.width(subjectColumnWidthDp.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (lesson.lessonNumber != null) {
|
||||
Box(
|
||||
modifier = lessonNumberBadgeModifier.background(bgColor),
|
||||
@@ -79,12 +85,14 @@ fun LessonCard(
|
||||
}
|
||||
// TODO: Add subject icons
|
||||
Text(
|
||||
lesson.name,
|
||||
text = lesson.name,
|
||||
style = TextStyle(
|
||||
color = ColorProvider(colors.textPrimary, colors.textPrimary),
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
),
|
||||
maxLines = 1,
|
||||
modifier = GlanceModifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -98,15 +106,18 @@ fun LessonCard(
|
||||
),
|
||||
)
|
||||
Spacer(modifier = GlanceModifier.width(8.dp))
|
||||
val roomName = (lesson.roomName ?: "N/A").take(5)
|
||||
val roomName = lesson.roomName ?: "N/A"
|
||||
Box(
|
||||
modifier = roomBadgeModifier.background(colors.a15p),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
roomName,
|
||||
text = roomName,
|
||||
style = badgeStyle,
|
||||
modifier = GlanceModifier.padding(4.dp, 4.dp),
|
||||
maxLines = 1,
|
||||
modifier = GlanceModifier
|
||||
.fillMaxWidth()
|
||||
.padding(4.dp, 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +116,10 @@ class TimetableWidget : GlanceAppWidget() {
|
||||
val displayLessons = data.lessons.take(maxLessons)
|
||||
val lessonChunks = displayLessons.chunked(2)
|
||||
val showDate = maxLessons > 1
|
||||
val maxRoomNameLen = displayLessons.maxOfOrNull { (it.roomName ?: "N/A").take(5).length } ?: 0
|
||||
val roomBadgeWidthDp = if (maxRoomNameLen <= 3) 28f else 48f
|
||||
val roomBadgeWidthDp = 48f
|
||||
val minWidthForTimeAndChipDp = 8f + 40f + roomBadgeWidthDp
|
||||
val subjectColumnWidthDp = (size.width.value - 2 * paddingDp - 32f - minWidthForTimeAndChipDp)
|
||||
.coerceIn(80f, 226f)
|
||||
val dateSectionHeight = if (showDate) headerHeightDp + spacerDp else 0f
|
||||
val lessonListHeight = when (val n = displayLessons.size) {
|
||||
0 -> 0f
|
||||
@@ -148,7 +150,12 @@ class TimetableWidget : GlanceAppWidget() {
|
||||
for (chunk in lessonChunks) {
|
||||
Column {
|
||||
for (lesson in chunk) {
|
||||
LessonCard(lesson, data.colors, roomBadgeWidthDp = roomBadgeWidthDp)
|
||||
LessonCard(
|
||||
lesson,
|
||||
data.colors,
|
||||
roomBadgeWidthDp = roomBadgeWidthDp,
|
||||
subjectColumnWidthDp = subjectColumnWidthDp,
|
||||
)
|
||||
Spacer(modifier = GlanceModifier.height(spacerDp.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import com.android.build.api.dsl.LibraryExtension
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
@@ -14,33 +14,26 @@ rootProject.layout.buildDirectory.value(newBuildDir)
|
||||
subprojects {
|
||||
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
|
||||
|
||||
// fix for verifyReleaseResources
|
||||
|
||||
// note(4831c0): taken from https://github.com/isar/isar/issues/1662
|
||||
// note(4831c0): and adapted to kotlin
|
||||
afterEvaluate {
|
||||
if (plugins.hasPlugin("com.android.application") || plugins.hasPlugin("com.android.library")) {
|
||||
val androidExtension = extensions.getByName("android") as BaseExtension
|
||||
androidExtension.apply {
|
||||
compileSdkVersion(36)
|
||||
buildToolsVersion = "36.1.0"
|
||||
}
|
||||
}
|
||||
if (hasProperty("android")) {
|
||||
val androidExtension = extensions.getByName("android") as BaseExtension
|
||||
androidExtension.apply {
|
||||
// Set namespace if it's not already set
|
||||
if (!extraProperties.has("namespace")) {
|
||||
extraProperties["namespace"] = project.group.toString()
|
||||
if (plugins.hasPlugin("com.android.application")) {
|
||||
extensions.configure<ApplicationExtension> {
|
||||
compileSdk = 37
|
||||
defaultConfig {
|
||||
// buildToolsVersion can be set here if needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plugins.hasPlugin("com.android.library")) {
|
||||
extensions.configure<LibraryExtension> {
|
||||
compileSdk = 37
|
||||
}
|
||||
}
|
||||
}
|
||||
// ===============================
|
||||
|
||||
project.layout.buildDirectory.value(newSubprojectBuildDir)
|
||||
}
|
||||
|
||||
tasks.register<Delete>("clean") {
|
||||
delete(rootProject.layout.buildDirectory)
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,7 @@ org.gradle.parallel=true
|
||||
org.gradle.daemon=true
|
||||
# Better Kotlin incremental compilation (warm builds)
|
||||
kotlin.incremental.useClasspathSnapshot=true
|
||||
# This builtInKotlin flag was added automatically by Flutter migrator
|
||||
android.builtInKotlin=false
|
||||
|
||||
android.newDsl=false
|
||||
|
||||
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-all.zip
|
||||
|
||||
@@ -18,9 +18,9 @@ pluginManagement {
|
||||
|
||||
plugins {
|
||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||
id("com.android.application") version "8.11.1" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
|
||||
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
|
||||
id("com.android.application") version "9.2.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.3.10" apply false
|
||||
id("org.jetbrains.kotlin.plugin.compose") version "2.3.10" apply false
|
||||
}
|
||||
|
||||
include(":app")
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 3.4 KiB |
3
firka/assets/majesticons/check.svg
Normal file
3
firka/assets/majesticons/check.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.7069 7.70643C19.8891 7.51783 19.9899 7.26523 19.9876 7.00303C19.9853 6.74083 19.8801 6.49002 19.6947 6.30461C19.5093 6.1192 19.2585 6.01403 18.9963 6.01176C18.7341 6.00948 18.4815 6.11027 18.2929 6.29243L8.99992 15.5854L5.70692 12.2924C5.51832 12.1103 5.26571 12.0095 5.00352 12.0118C4.74132 12.014 4.49051 12.1192 4.3051 12.3046C4.11969 12.49 4.01452 12.7408 4.01224 13.003C4.00997 13.2652 4.11076 13.5178 4.29292 13.7064L8.29292 17.7064C8.48045 17.8939 8.73476 17.9992 8.99992 17.9992C9.26508 17.9992 9.51939 17.8939 9.70692 17.7064L19.7069 7.70643Z" fill="#A7DC22"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 726 B |
10
firka/assets/majesticons/checkSolid.svg
Normal file
10
firka/assets/majesticons/checkSolid.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_2679_4048)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.5 0.5C1.96957 0.5 1.46086 0.710714 1.08579 1.08579C0.710714 1.46086 0.5 1.96957 0.5 2.5V9.5C0.5 10.0304 0.710714 10.5391 1.08579 10.9142C1.46086 11.2893 1.96957 11.5 2.5 11.5H9.5C10.0304 11.5 10.5391 11.2893 10.9142 10.9142C11.2893 10.5391 11.5 10.0304 11.5 9.5V2.5C11.5 1.96957 11.2893 1.46086 10.9142 1.08579C10.5391 0.710714 10.0304 0.5 9.5 0.5H2.5ZM9.8535 3.8535C9.94458 3.7592 9.99498 3.6329 9.99384 3.5018C9.9927 3.3707 9.94011 3.24529 9.84741 3.15259C9.75471 3.05989 9.6293 3.0073 9.4982 3.00616C9.3671 3.00502 9.2408 3.05542 9.1465 3.1465L4.5 7.793L2.8535 6.1465C2.7592 6.05542 2.6329 6.00502 2.5018 6.00616C2.3707 6.0073 2.24529 6.05989 2.15259 6.15259C2.05989 6.24529 2.0073 6.3707 2.00616 6.5018C2.00502 6.6329 2.05542 6.7592 2.1465 6.8535L4.1465 8.8535C4.24026 8.94724 4.36742 8.99989 4.5 8.99989C4.63258 8.99989 4.75974 8.94724 4.8535 8.8535L9.8535 3.8535Z" fill="#A7DC22"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_2679_4048">
|
||||
<rect width="12" height="12" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -1,3 +1,3 @@
|
||||
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.5 3C13.5 2.73478 13.3946 2.48043 13.2071 2.29289C13.0196 2.10536 12.7652 2 12.5 2C12.2348 2 11.9804 2.10536 11.7929 2.29289C11.6054 2.48043 11.5 2.73478 11.5 3V4C11.5 4.26522 11.6054 4.51957 11.7929 4.70711C11.9804 4.89464 12.2348 5 12.5 5C12.7652 5 13.0196 4.89464 13.2071 4.70711C13.3946 4.51957 13.5 4.26522 13.5 4V3ZM6.207 4.293C6.0184 4.11084 5.7658 4.01005 5.5036 4.01233C5.2414 4.0146 4.99059 4.11977 4.80518 4.30518C4.61977 4.49059 4.5146 4.7414 4.51233 5.0036C4.51005 5.2658 4.61084 5.5184 4.793 5.707L5.793 6.707C5.9816 6.88916 6.2342 6.98995 6.4964 6.98767C6.7586 6.9854 7.00941 6.88023 7.19482 6.69482C7.38023 6.50941 7.4854 6.2586 7.48767 5.9964C7.48995 5.7342 7.38916 5.4816 7.207 5.293L6.207 4.293ZM20.207 4.293C20.0195 4.10553 19.7652 4.00021 19.5 4.00021C19.2348 4.00021 18.9805 4.10553 18.793 4.293L17.793 5.293C17.6108 5.4816 17.51 5.7342 17.5123 5.9964C17.5146 6.2586 17.6198 6.50941 17.8052 6.69482C17.9906 6.88023 18.2414 6.9854 18.5036 6.98767C18.7658 6.98995 19.0184 6.88916 19.207 6.707L20.207 5.707C20.3945 5.51947 20.4998 5.26516 20.4998 5C20.4998 4.73484 20.3945 4.48053 20.207 4.293ZM12.5 7C11.1739 7 9.90215 7.52678 8.96447 8.46447C8.02678 9.40215 7.5 10.6739 7.5 12C7.5 13.3261 8.02678 14.5979 8.96447 15.5355C9.90215 16.4732 11.1739 17 12.5 17C13.8261 17 15.0979 16.4732 16.0355 15.5355C16.9732 14.5979 17.5 13.3261 17.5 12C17.5 10.6739 16.9732 9.40215 16.0355 8.46447C15.0979 7.52678 13.8261 7 12.5 7ZM3.5 11C3.23478 11 2.98043 11.1054 2.79289 11.2929C2.60536 11.4804 2.5 11.7348 2.5 12C2.5 12.2652 2.60536 12.5196 2.79289 12.7071C2.98043 12.8946 3.23478 13 3.5 13H4.5C4.76522 13 5.01957 12.8946 5.20711 12.7071C5.39464 12.5196 5.5 12.2652 5.5 12C5.5 11.7348 5.39464 11.4804 5.20711 11.2929C5.01957 11.1054 4.76522 11 4.5 11H3.5ZM20.5 11C20.2348 11 19.9804 11.1054 19.7929 11.2929C19.6054 11.4804 19.5 11.7348 19.5 12C19.5 12.2652 19.6054 12.5196 19.7929 12.7071C19.9804 12.8946 20.2348 13 20.5 13H21.5C21.7652 13 22.0196 12.8946 22.2071 12.7071C22.3946 12.5196 22.5 12.2652 22.5 12C22.5 11.7348 22.3946 11.4804 22.2071 11.2929C22.0196 11.1054 21.7652 11 21.5 11H20.5ZM7.207 18.707C7.30251 18.6148 7.37869 18.5044 7.4311 18.3824C7.48351 18.2604 7.5111 18.1292 7.51225 17.9964C7.5134 17.8636 7.4881 17.7319 7.43782 17.609C7.38754 17.4862 7.31329 17.3745 7.2194 17.2806C7.1255 17.1867 7.01385 17.1125 6.89095 17.0622C6.76806 17.0119 6.63638 16.9866 6.5036 16.9877C6.37082 16.9889 6.2396 17.0165 6.1176 17.0689C5.99559 17.1213 5.88525 17.1975 5.793 17.293L4.793 18.293C4.69749 18.3852 4.62131 18.4956 4.5689 18.6176C4.51649 18.7396 4.4889 18.8708 4.48775 19.0036C4.4866 19.1364 4.5119 19.2681 4.56218 19.391C4.61246 19.5138 4.68671 19.6255 4.7806 19.7194C4.8745 19.8133 4.98615 19.8875 5.10905 19.9378C5.23194 19.9881 5.36362 20.0134 5.4964 20.0123C5.62918 20.0111 5.7604 19.9835 5.8824 19.9311C6.00441 19.8787 6.11475 19.8025 6.207 19.707L7.207 18.707ZM19.207 17.293C19.0184 17.1108 18.7658 17.01 18.5036 17.0123C18.2414 17.0146 17.9906 17.1198 17.8052 17.3052C17.6198 17.4906 17.5146 17.7414 17.5123 18.0036C17.51 18.2658 17.6108 18.5184 17.793 18.707L18.793 19.707C18.9816 19.8892 19.2342 19.99 19.4964 19.9877C19.7586 19.9854 20.0094 19.8802 20.1948 19.6948C20.3802 19.5094 20.4854 19.2586 20.4877 18.9964C20.49 18.7342 20.3892 18.4816 20.207 18.293L19.207 17.293ZM13.5 20C13.5 19.7348 13.3946 19.4804 13.2071 19.2929C13.0196 19.1054 12.7652 19 12.5 19C12.2348 19 11.9804 19.1054 11.7929 19.2929C11.6054 19.4804 11.5 19.7348 11.5 20V21C11.5 21.2652 11.6054 21.5196 11.7929 21.7071C11.9804 21.8946 12.2348 22 12.5 22C12.7652 22 13.0196 21.8946 13.2071 21.7071C13.3946 21.5196 13.5 21.2652 13.5 21V20Z" fill="#FFFFFF"/>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 3C13 2.73478 12.8946 2.48043 12.7071 2.29289C12.5196 2.10536 12.2652 2 12 2C11.7348 2 11.4804 2.10536 11.2929 2.29289C11.1054 2.48043 11 2.73478 11 3V4C11 4.26522 11.1054 4.51957 11.2929 4.70711C11.4804 4.89464 11.7348 5 12 5C12.2652 5 12.5196 4.89464 12.7071 4.70711C12.8946 4.51957 13 4.26522 13 4V3ZM5.707 4.293C5.5184 4.11084 5.2658 4.01005 5.0036 4.01233C4.7414 4.0146 4.49059 4.11977 4.30518 4.30518C4.11977 4.49059 4.0146 4.7414 4.01233 5.0036C4.01005 5.2658 4.11084 5.5184 4.293 5.707L5.293 6.707C5.4816 6.88916 5.7342 6.98995 5.9964 6.98767C6.2586 6.9854 6.50941 6.88023 6.69482 6.69482C6.88023 6.50941 6.9854 6.2586 6.98767 5.9964C6.98995 5.7342 6.88916 5.4816 6.707 5.293L5.707 4.293ZM19.707 4.293C19.5195 4.10553 19.2652 4.00021 19 4.00021C18.7348 4.00021 18.4805 4.10553 18.293 4.293L17.293 5.293C17.1108 5.4816 17.01 5.7342 17.0123 5.9964C17.0146 6.2586 17.1198 6.50941 17.3052 6.69482C17.4906 6.88023 17.7414 6.9854 18.0036 6.98767C18.2658 6.98995 18.5184 6.88916 18.707 6.707L19.707 5.707C19.8945 5.51947 19.9998 5.26516 19.9998 5C19.9998 4.73484 19.8945 4.48053 19.707 4.293ZM12 7C10.6739 7 9.40215 7.52678 8.46447 8.46447C7.52678 9.40215 7 10.6739 7 12C7 13.3261 7.52678 14.5979 8.46447 15.5355C9.40215 16.4732 10.6739 17 12 17C13.3261 17 14.5979 16.4732 15.5355 15.5355C16.4732 14.5979 17 13.3261 17 12C17 10.6739 16.4732 9.40215 15.5355 8.46447C14.5979 7.52678 13.3261 7 12 7ZM3 11C2.73478 11 2.48043 11.1054 2.29289 11.2929C2.10536 11.4804 2 11.7348 2 12C2 12.2652 2.10536 12.5196 2.29289 12.7071C2.48043 12.8946 2.73478 13 3 13H4C4.26522 13 4.51957 12.8946 4.70711 12.7071C4.89464 12.5196 5 12.2652 5 12C5 11.7348 4.89464 11.4804 4.70711 11.2929C4.51957 11.1054 4.26522 11 4 11H3ZM20 11C19.7348 11 19.4804 11.1054 19.2929 11.2929C19.1054 11.4804 19 11.7348 19 12C19 12.2652 19.1054 12.5196 19.2929 12.7071C19.4804 12.8946 19.7348 13 20 13H21C21.2652 13 21.5196 12.8946 21.7071 12.7071C21.8946 12.5196 22 12.2652 22 12C22 11.7348 21.8946 11.4804 21.7071 11.2929C21.5196 11.1054 21.2652 11 21 11H20ZM6.707 18.707C6.80251 18.6148 6.87869 18.5044 6.9311 18.3824C6.98351 18.2604 7.0111 18.1292 7.01225 17.9964C7.0134 17.8636 6.9881 17.7319 6.93782 17.609C6.88754 17.4862 6.81329 17.3745 6.7194 17.2806C6.6255 17.1867 6.51385 17.1125 6.39095 17.0622C6.26806 17.0119 6.13638 16.9866 6.0036 16.9877C5.87082 16.9889 5.7396 17.0165 5.6176 17.0689C5.49559 17.1213 5.38525 17.1975 5.293 17.293L4.293 18.293C4.19749 18.3852 4.12131 18.4956 4.0689 18.6176C4.01649 18.7396 3.9889 18.8708 3.98775 19.0036C3.9866 19.1364 4.0119 19.2681 4.06218 19.391C4.11246 19.5138 4.18671 19.6255 4.2806 19.7194C4.3745 19.8133 4.48615 19.8875 4.60905 19.9378C4.73194 19.9881 4.86362 20.0134 4.9964 20.0123C5.12918 20.0111 5.2604 19.9835 5.3824 19.9311C5.50441 19.8787 5.61475 19.8025 5.707 19.707L6.707 18.707ZM18.707 17.293C18.5184 17.1108 18.2658 17.01 18.0036 17.0123C17.7414 17.0146 17.4906 17.1198 17.3052 17.3052C17.1198 17.4906 17.0146 17.7414 17.0123 18.0036C17.01 18.2658 17.1108 18.5184 17.293 18.707L18.293 19.707C18.4816 19.8892 18.7342 19.99 18.9964 19.9877C19.2586 19.9854 19.5094 19.8802 19.6948 19.6948C19.8802 19.5094 19.9854 19.2586 19.9877 18.9964C19.99 18.7342 19.8892 18.4816 19.707 18.293L18.707 17.293ZM13 20C13 19.7348 12.8946 19.4804 12.7071 19.2929C12.5196 19.1054 12.2652 19 12 19C11.7348 19 11.4804 19.1054 11.2929 19.2929C11.1054 19.4804 11 19.7348 11 20V21C11 21.2652 11.1054 21.5196 11.2929 21.7071C11.4804 21.8946 11.7348 22 12 22C12.2652 22 12.5196 21.8946 12.7071 21.7071C12.8946 21.5196 13 21.2652 13 21V20Z" fill="#FFFFFF"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.6 KiB |
@@ -7,15 +7,15 @@ icons:
|
||||
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
||||
l10n:
|
||||
"l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082"
|
||||
"lib/l10n/app_de.arb": "ecfbf13bd33be9d27a2b54bfd8fb61e46c1a1dce905869d3f30cd05b4aecf258"
|
||||
"lib/l10n/app_en.arb": "8bb0064984deb02eefaec24c13ee019eb38758e115b678ce85335fd4d1b6b6d9"
|
||||
"lib/l10n/app_hu.arb": "2d2c568a3767a5b0bcfde7d27f221fd74b653256bbe41789756c78422a159e4d"
|
||||
"lib/l10n/app_de.arb": "c6a12eaadf03b012a6a377b3efa4e606bd985355e76e6351956a017f4cfdadc1"
|
||||
"lib/l10n/app_hu.arb": "a63aace8d129dbc054c4996dd9ef7d54aad96888241ce1310518b10a9a7b561d"
|
||||
"lib/l10n/app_en.arb": "b2d72778fedb46155f41eb210906ed8ffba8b12744a2800b039951e0a2a88133"
|
||||
isar:
|
||||
"lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723"
|
||||
"lib/data/models/generic_cache_model.dart": "79151d0467fb5d40c532eaaa08ad7c7e24a34304199280fbf49cf6e5adcce6bc"
|
||||
"lib/data/models/homework_cache_model.dart": "45789970b27d5790cdc54c292ef2f5feaa5f4e293b8a8862fd676d5eb3e25d29"
|
||||
"lib/data/models/timetable_cache_model.dart": "b972bf51e399f8d20d4f9ad660082d4cc4a9798df9ac9d6ec9ef6ac640205572"
|
||||
"lib/data/models/token_model.dart": "8c957cd07e473827d78fd8fd4fb6c1336b636a69c25c93618e1e7f94b7cf0683"
|
||||
"lib/data/models/homework_cache_model.dart": "45789970b27d5790cdc54c292ef2f5feaa5f4e293b8a8862fd676d5eb3e25d29"
|
||||
"lib/data/models/generic_cache_model.dart": "62003ec1fd73a0fa6786d337acdef42b9a6eb9efaa78d17eaf4fe091504b8490"
|
||||
"lib/data/models/timetable_cache_model.dart": "b972bf51e399f8d20d4f9ad660082d4cc4a9798df9ac9d6ec9ef6ac640205572"
|
||||
splash:
|
||||
"flutter_native_splash.yaml": "0fd4a85d6f950d97298e99916927649940ffcfdadfc136ceee126fed0dbaa9f2"
|
||||
"assets/images/logos/splash.png": "88fbebc3d686cb9095bcce362029b69978b1b14270e465e91d962b1425db1152"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,169 +0,0 @@
|
||||
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,8 +55,7 @@ class LiveActivityBackendClient {
|
||||
'roomName': lesson.roomName,
|
||||
'isSubstitution': lesson.substituteTeacher != null,
|
||||
'substituteTeacher': lesson.substituteTeacher,
|
||||
'isCancelled':
|
||||
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
||||
'lastModified': validLastModified.toIso8601String(),
|
||||
};
|
||||
}).toList();
|
||||
@@ -141,8 +140,7 @@ class LiveActivityBackendClient {
|
||||
'roomName': lesson.roomName,
|
||||
'isSubstitution': lesson.substituteTeacher != null,
|
||||
'substituteTeacher': lesson.substituteTeacher,
|
||||
'isCancelled':
|
||||
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
||||
'lastModified': validLastModified.toIso8601String(),
|
||||
};
|
||||
}).toList();
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firka/data/models/token_model.dart';
|
||||
import 'package:kreta_api/kreta_api.dart' hide KretaEndpoints;
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'consts.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||
final headers = <String, String>{
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"accept": "*/*",
|
||||
"user-agent": Constants.userAgent,
|
||||
"user-agent": initData.userAgent,
|
||||
};
|
||||
|
||||
final formData = <String, String>{
|
||||
"code": code,
|
||||
"code_verifier": KretaEndpoints.codeVerifier,
|
||||
"code_verifier": KretaLoginEndpoints.codeVerifier,
|
||||
"redirect_uri":
|
||||
"https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect",
|
||||
"client_id": Constants.clientId,
|
||||
@@ -23,7 +23,7 @@ Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||
|
||||
try {
|
||||
final response = await dio.post(
|
||||
KretaEndpoints.tokenGrantUrl,
|
||||
KretaLoginEndpoints.tokenGrantUrl,
|
||||
options: Options(headers: headers),
|
||||
data: formData,
|
||||
);
|
||||
@@ -47,18 +47,18 @@ const _tokenRefreshRetryDelays = [1000, 3000, 5000];
|
||||
|
||||
Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||
logger.info(
|
||||
"Extending token for user: ${model.studentId}, institute: ${model.iss}",
|
||||
"Extending token for user: ${model.username}, institute: ${model.iss}",
|
||||
);
|
||||
|
||||
final headers = <String, String>{
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"accept": "*/*",
|
||||
"user-agent": Constants.userAgent,
|
||||
"user-agent": initData.userAgent,
|
||||
};
|
||||
|
||||
final formData = <String, String>{
|
||||
"institute_code": model.iss!,
|
||||
"refresh_token": model.refreshToken!,
|
||||
"institute_code": model.iss,
|
||||
"refresh_token": model.refreshToken,
|
||||
"grant_type": "refresh_token",
|
||||
"client_id": Constants.clientId,
|
||||
};
|
||||
@@ -76,7 +76,7 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||
}
|
||||
|
||||
final response = await dio.post(
|
||||
KretaEndpoints.tokenGrantUrl,
|
||||
KretaLoginEndpoints.tokenGrantUrl,
|
||||
options: Options(headers: headers),
|
||||
data: formData,
|
||||
);
|
||||
@@ -84,20 +84,20 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
logger.info(
|
||||
"Token extended successfully for user: ${model.studentId}",
|
||||
"Token extended successfully for user: ${model.username}",
|
||||
);
|
||||
return TokenGrantResponse.fromJson(response.data);
|
||||
case 400:
|
||||
case 401:
|
||||
logger.warning(
|
||||
"Token refresh failed (${response.statusCode}) - refresh token invalid for user: ${model.studentId}",
|
||||
"Token refresh failed (${response.statusCode}) - refresh token invalid for user: ${model.username}",
|
||||
);
|
||||
throw response.statusCode == 400
|
||||
? TokenExpiredException()
|
||||
: InvalidGrantException();
|
||||
default:
|
||||
logger.warning(
|
||||
"Token refresh failed (${response.statusCode}) for user: ${model.studentId}, attempt ${attempt + 1}",
|
||||
"Token refresh failed (${response.statusCode}) for user: ${model.username}, attempt ${attempt + 1}",
|
||||
);
|
||||
lastError = Exception(
|
||||
"Failed to get access token, response code: ${response.statusCode}",
|
||||
@@ -111,19 +111,19 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||
rethrow;
|
||||
} on DioException catch (e) {
|
||||
logger.warning(
|
||||
"Token refresh network error for user: ${model.studentId}, attempt ${attempt + 1}: $e",
|
||||
"Token refresh network error for user: ${model.username}, attempt ${attempt + 1}: $e",
|
||||
);
|
||||
lastError = e;
|
||||
continue;
|
||||
} catch (e) {
|
||||
logger.severe("Token refresh exception for user: ${model.studentId}: $e");
|
||||
logger.severe("Token refresh exception for user: ${model.username}: $e");
|
||||
lastError = e is Exception ? e : Exception(e.toString());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
logger.severe(
|
||||
"All token refresh attempts failed for user: ${model.studentId}",
|
||||
"All token refresh attempts failed for user: ${model.username}",
|
||||
);
|
||||
throw lastError ?? Exception("Token refresh failed after all retries");
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:firka/api/client/kreta_client.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/toast_cubit.dart';
|
||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/data/models/token_model.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@@ -48,20 +48,20 @@ class AppInitialization {
|
||||
final Directory appDir;
|
||||
final PackageInfo packageInfo;
|
||||
final DeviceInfo devInfo;
|
||||
late KretaClient client;
|
||||
List<TokenModel> tokens;
|
||||
KretaClient? client;
|
||||
bool hasWatchListener = false;
|
||||
|
||||
/// Set by the wear pairing modal; called when watch sends init_done or sync_done to dismiss the sheet.
|
||||
void Function()? dismissWearPairingSheet;
|
||||
Uint8List? profilePicture;
|
||||
SettingsStore settings;
|
||||
ThemeCubit? themeCubit;
|
||||
SettingsCubit? settingsCubit;
|
||||
ProfilePictureCubit? profilePictureCubit;
|
||||
ReauthCubit? reauthCubit;
|
||||
HomeRefreshCubit? homeRefreshCubit;
|
||||
SettingsRepository settings;
|
||||
final ThemeCubit themeCubit = ThemeCubit();
|
||||
final SettingsCubit settingsCubit = SettingsCubit();
|
||||
final ProfilePictureCubit profilePictureCubit = ProfilePictureCubit();
|
||||
final ToastCubit toastCubit = ToastCubit();
|
||||
final HomeRefreshCubit homeRefreshCubit = HomeRefreshCubit();
|
||||
AppLocalizations l10n;
|
||||
String userAgent;
|
||||
final GlobalKey<NavigatorState> navigatorKey;
|
||||
|
||||
AppInitialization({
|
||||
@@ -69,9 +69,13 @@ class AppInitialization {
|
||||
required this.appDir,
|
||||
required this.devInfo,
|
||||
required this.packageInfo,
|
||||
required this.tokens,
|
||||
required this.settings,
|
||||
required this.l10n,
|
||||
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,24 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:firka_common/data/database.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.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/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_common/data/models/token_model.dart';
|
||||
import 'package:firka/services/live_activity_service.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/core/settings/settings_effects.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/l10n/app_localizations_de.dart';
|
||||
import 'package:firka/l10n/app_localizations_en.dart';
|
||||
@@ -32,47 +25,23 @@ import 'package:isar_community/isar.dart';
|
||||
import 'package:package_info_plus/package_info_plus.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 {
|
||||
String? languageCode;
|
||||
|
||||
switch ((data.settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex) {
|
||||
case 1: // hu
|
||||
switch (Settings.language.value) {
|
||||
case AppLanguage.hu:
|
||||
data.l10n = AppLocalizationsHu();
|
||||
languageCode = 'hu';
|
||||
break;
|
||||
case 2: // en
|
||||
case AppLanguage.en:
|
||||
data.l10n = AppLocalizationsEn();
|
||||
languageCode = 'en';
|
||||
break;
|
||||
case 3: // de
|
||||
case AppLanguage.de:
|
||||
data.l10n = AppLocalizationsDe();
|
||||
languageCode = 'de';
|
||||
break;
|
||||
default: // auto
|
||||
case AppLanguage.auto:
|
||||
switch (ui.PlatformDispatcher.instance.locale.languageCode) {
|
||||
case 'hu':
|
||||
data.l10n = AppLocalizationsHu();
|
||||
@@ -107,23 +76,20 @@ Future<void> initLang(AppInitialization data) async {
|
||||
|
||||
void initTheme(AppInitialization data) {
|
||||
final themeCubit = data.themeCubit;
|
||||
if (themeCubit == null) return;
|
||||
|
||||
final brightness =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||
|
||||
switch ((data.settings.group("settings").subGroup("customization")["theme"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex) {
|
||||
case 1:
|
||||
switch (Settings.themeBrightness.value) {
|
||||
case ThemeBrightness.light:
|
||||
appStyle = lightStyle;
|
||||
themeCubit.setLightMode(true);
|
||||
break;
|
||||
case 2:
|
||||
case ThemeBrightness.dark:
|
||||
appStyle = darkStyle;
|
||||
themeCubit.setLightMode(false);
|
||||
break;
|
||||
default:
|
||||
case ThemeBrightness.auto:
|
||||
if (brightness == Brightness.dark) {
|
||||
appStyle = darkStyle;
|
||||
themeCubit.setLightMode(false);
|
||||
@@ -135,16 +101,9 @@ void initTheme(AppInitialization data) {
|
||||
}
|
||||
|
||||
Future<void> _initData(AppInitialization init) async {
|
||||
init.themeCubit ??= ThemeCubit();
|
||||
init.settingsCubit ??= SettingsCubit();
|
||||
init.profilePictureCubit ??= ProfilePictureCubit();
|
||||
init.reauthCubit ??= ReauthCubit();
|
||||
init.homeRefreshCubit ??= HomeRefreshCubit();
|
||||
await init.settings.load(init.isar.appSettingsModels);
|
||||
await init.settings.loadAll();
|
||||
await initLang(init);
|
||||
initTheme(init);
|
||||
init.settings = SettingsStore(init.l10n);
|
||||
await init.settings.load(init.isar.appSettingsModels);
|
||||
|
||||
var dispatcher = SchedulerBinding.instance.platformDispatcher;
|
||||
|
||||
@@ -153,10 +112,7 @@ Future<void> _initData(AppInitialization init) async {
|
||||
};
|
||||
|
||||
dispatcher.onLocaleChanged = () {
|
||||
final languageSetting =
|
||||
init.settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio;
|
||||
final isAutoLanguage = languageSetting.activeIndex == 0;
|
||||
final isAutoLanguage = Settings.language.value == AppLanguage.auto;
|
||||
if (!isAutoLanguage) {
|
||||
return;
|
||||
}
|
||||
@@ -170,13 +126,10 @@ Future<void> _initData(AppInitialization init) async {
|
||||
"[Init] System locale changed in auto mode: $previousLocale -> $nextLocale",
|
||||
);
|
||||
}
|
||||
init.themeCubit?.refresh();
|
||||
init.themeCubit.refresh();
|
||||
}());
|
||||
};
|
||||
|
||||
resetOldTimeTableCache(init.isar);
|
||||
resetOldHomeworkCache(init.isar);
|
||||
|
||||
var didRunFreshInstallCleanup = false;
|
||||
if (Platform.isIOS) {
|
||||
try {
|
||||
@@ -187,50 +140,42 @@ Future<void> _initData(AppInitialization init) async {
|
||||
'[Init] Fresh-install cleanup completed; skipping startup iCloud recovery on this launch',
|
||||
);
|
||||
} else {
|
||||
await WatchSyncHelper.checkAndRecoverFromiCloud(
|
||||
isar: init.isar,
|
||||
tokens: init.tokens,
|
||||
);
|
||||
await WatchSyncHelper.checkAndRecoverFromiCloud(isar: init.isar);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warning('[Init] iCloud bootstrap/recovery failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
final allTokens = await init.isar.tokenModels.where().findAll();
|
||||
init.tokens = allTokens;
|
||||
final token = init.settings.getSelectedToken();
|
||||
if (token == null) {
|
||||
logger.warning("[Init] No token available!");
|
||||
return;
|
||||
}
|
||||
logger.fine("Initializing kréta client as: ${token.username}");
|
||||
init.client = KretaClient(token);
|
||||
await init.client!.init();
|
||||
init.client!.renewCache(reInit: false);
|
||||
|
||||
if (allTokens.isNotEmpty) {
|
||||
final token = pickActiveToken(tokens: allTokens, settings: init.settings);
|
||||
if (token == null) {
|
||||
logger.warning(
|
||||
"[Init] Tokens disappeared during initialization; skipping client setup",
|
||||
);
|
||||
return;
|
||||
if (Platform.isIOS) {
|
||||
final expiryDate = token.expiryDate;
|
||||
if (expiryDate.isAfter(DateTime.now())) {
|
||||
init.toastCubit.clear();
|
||||
}
|
||||
logger.fine("Initializing kréta client as: ${token.studentId}");
|
||||
init.client = KretaClient(token, init.isar, init.reauthCubit!);
|
||||
|
||||
if (Platform.isIOS) {
|
||||
final expiryDate = token.expiryDate;
|
||||
if (expiryDate != null && expiryDate.isAfter(DateTime.now())) {
|
||||
init.reauthCubit?.clear();
|
||||
unawaited(() async {
|
||||
try {
|
||||
await WatchSyncHelper.saveTokenToiCloud(token);
|
||||
} catch (e) {
|
||||
logger.warning('[Init] Failed to sync active token to iCloud: $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');
|
||||
}
|
||||
}());
|
||||
}
|
||||
try {
|
||||
await WatchSyncHelper.sendTokenModelToWatch(token);
|
||||
} catch (e) {
|
||||
logger.warning('[Init] Failed to sync active token to Watch: $e');
|
||||
}
|
||||
}());
|
||||
}
|
||||
|
||||
final dataDir = await getApplicationDocumentsDirectory();
|
||||
@@ -239,12 +184,14 @@ Future<void> _initData(AppInitialization init) async {
|
||||
if (await pfpFile.exists()) {
|
||||
init.profilePicture = await pfpFile.readAsBytes();
|
||||
}
|
||||
|
||||
init.homeRefreshCubit.requestRefresh();
|
||||
}
|
||||
|
||||
Future<AppInitialization> initializeApp() async {
|
||||
Future<void> initializeApp() async {
|
||||
if (initDone) {
|
||||
await _initData(initData);
|
||||
return initData;
|
||||
return;
|
||||
}
|
||||
final isar = await initDB();
|
||||
final tokens = await isar.tokenModels.where().findAll();
|
||||
@@ -274,16 +221,18 @@ Future<AppInitialization> initializeApp() async {
|
||||
logger.fine("Fetched device info: ${devInfoFetched ? "yes" : "no"}");
|
||||
logger.fine("Using device info: ${devInfo.toString()}");
|
||||
|
||||
var init = AppInitialization(
|
||||
initData = AppInitialization(
|
||||
isar: isar,
|
||||
appDir: await getApplicationDocumentsDirectory(),
|
||||
devInfo: devInfo,
|
||||
packageInfo: await PackageInfo.fromPlatform(),
|
||||
tokens: tokens,
|
||||
settings: SettingsStore(AppLocalizationsHu()),
|
||||
settings: SettingsRepository(isar),
|
||||
l10n: AppLocalizationsHu(),
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
initData.settings.cubit = initData.settingsCubit;
|
||||
Settings = initData.settings;
|
||||
registerSettingsEffects(initData.settings, initData);
|
||||
|
||||
if (Platform.isIOS) {
|
||||
try {
|
||||
@@ -297,9 +246,9 @@ Future<AppInitialization> initializeApp() async {
|
||||
}
|
||||
}
|
||||
|
||||
await _initData(init);
|
||||
await _initData(initData);
|
||||
|
||||
return init;
|
||||
initDone = true;
|
||||
}
|
||||
|
||||
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/settings.dart';
|
||||
import 'package:firka/core/bloc/profile_picture_cubit.dart';
|
||||
import 'package:firka/core/bloc/reauth_cubit.dart';
|
||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
@@ -31,9 +31,7 @@ class InitializationScreen extends StatefulWidget {
|
||||
|
||||
class _InitializationScreenState extends State<InitializationScreen> {
|
||||
GoRouter? _router;
|
||||
final Future<AppInitialization> _init = initializeApp().timeout(
|
||||
const Duration(seconds: 20),
|
||||
);
|
||||
final Future<void> _init = initializeApp();
|
||||
|
||||
ThemeData _buildTheme(FirkaStyle style) {
|
||||
return ThemeData(
|
||||
@@ -45,7 +43,6 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: style.colors.accent,
|
||||
brightness: style.isLight ? Brightness.light : Brightness.dark,
|
||||
background: style.colors.background,
|
||||
surface: style.colors.card,
|
||||
),
|
||||
useMaterial3: false,
|
||||
@@ -54,11 +51,13 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<AppInitialization>(
|
||||
return FutureBuilder<void>(
|
||||
future: _init,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.hasError) {
|
||||
initDone = false;
|
||||
|
||||
logger.shout(
|
||||
"Error in InitializationScreen",
|
||||
snapshot.error.toString(),
|
||||
@@ -83,10 +82,6 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
assert(snapshot.data != null);
|
||||
initData = snapshot.data!;
|
||||
initDone = true;
|
||||
|
||||
FlutterNativeSplash.remove();
|
||||
|
||||
WatchSyncHelper.initialize();
|
||||
@@ -113,24 +108,20 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
|
||||
switch (msg["id"]) {
|
||||
case "ping":
|
||||
if (initData.tokens.isNotEmpty) {
|
||||
logger.finest("WatchOS IPC [Phone -> Watch]: pong");
|
||||
unawaited(
|
||||
WatchSyncHelper.sendMessageToWatch({'id': 'pong'}),
|
||||
);
|
||||
_router?.go('/home');
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final ctx = navigatorKey.currentContext;
|
||||
if (ctx != null && ctx.mounted) {
|
||||
logger.info('Watch init_data: ${jsonEncode(msg)}');
|
||||
showWearBottomSheet(
|
||||
ctx,
|
||||
initData,
|
||||
Platform.isAndroid ? msg['model'] : 'Apple Watch',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
logger.finest("WatchOS IPC [Phone -> Watch]: pong");
|
||||
unawaited(WatchSyncHelper.sendMessageToWatch({'id': 'pong'}));
|
||||
_router?.go('/home');
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final ctx = navigatorKey.currentContext;
|
||||
if (ctx != null && ctx.mounted) {
|
||||
logger.info('Watch init_data: ${jsonEncode(msg)}');
|
||||
showWearBottomSheet(
|
||||
ctx,
|
||||
initData,
|
||||
Platform.isAndroid ? msg['model'] : 'Apple Watch',
|
||||
);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "init_done":
|
||||
case "sync_done":
|
||||
@@ -157,7 +148,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
);
|
||||
}
|
||||
await WatchSyncHelper.runWearSyncInForeground(
|
||||
initData.client,
|
||||
initData.client!,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -165,7 +156,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
unawaited(() async {
|
||||
try {
|
||||
await WatchSyncHelper.startWearSyncServiceWithFreshCache(
|
||||
initData.client,
|
||||
initData.client!,
|
||||
initData.appDir.path,
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -183,11 +174,11 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
appRouter = _router;
|
||||
}
|
||||
|
||||
final themeCubit = initData.themeCubit!;
|
||||
final settingsCubit = initData.settingsCubit!;
|
||||
final profilePictureCubit = initData.profilePictureCubit!;
|
||||
final reauthCubit = initData.reauthCubit!;
|
||||
final homeRefreshCubit = initData.homeRefreshCubit!;
|
||||
final themeCubit = initData.themeCubit;
|
||||
final settingsCubit = initData.settingsCubit;
|
||||
final profilePictureCubit = initData.profilePictureCubit;
|
||||
final reauthCubit = initData.toastCubit;
|
||||
final homeRefreshCubit = initData.homeRefreshCubit;
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<ThemeCubit>.value(value: themeCubit),
|
||||
@@ -195,7 +186,7 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
BlocProvider<ProfilePictureCubit>.value(
|
||||
value: profilePictureCubit,
|
||||
),
|
||||
BlocProvider<ReauthCubit>.value(value: reauthCubit),
|
||||
BlocProvider<ToastCubit>.value(value: reauthCubit),
|
||||
BlocProvider<HomeRefreshCubit>.value(value: homeRefreshCubit),
|
||||
],
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
@@ -203,15 +194,16 @@ class _InitializationScreenState extends State<InitializationScreen> {
|
||||
final isLight = themeState.isLightMode;
|
||||
final overlay = SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness:
|
||||
isLight ? Brightness.dark : Brightness.light,
|
||||
statusBarBrightness:
|
||||
isLight ? Brightness.light : Brightness.dark,
|
||||
statusBarIconBrightness: isLight
|
||||
? Brightness.dark
|
||||
: Brightness.light,
|
||||
statusBarBrightness: isLight
|
||||
? Brightness.light
|
||||
: Brightness.dark,
|
||||
systemStatusBarContrastEnforced: false,
|
||||
);
|
||||
|
||||
final themeMode =
|
||||
isLight ? ThemeMode.light : ThemeMode.dark;
|
||||
final themeMode = isLight ? ThemeMode.light : ThemeMode.dark;
|
||||
|
||||
final fallbackBg = isLight
|
||||
? lightStyle.colors.background
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
bool _isPercentageGrade(Grade grade) {
|
||||
final name = grade.valueType.name?.toLowerCase() ?? '';
|
||||
return name.contains('szazalek') || name.contains('percent');
|
||||
}
|
||||
|
||||
double calculateAverage(List<Grade> sortedGrades) {
|
||||
double totalWeight = 0.0;
|
||||
double weightedSum = 0.0;
|
||||
|
||||
for (final grade in sortedGrades) {
|
||||
if (_isPercentageGrade(grade)) continue;
|
||||
|
||||
final value = grade.numericValue;
|
||||
final weight = grade.weightPercentage;
|
||||
|
||||
if (value != null && weight != null) {
|
||||
weightedSum += value * weight;
|
||||
totalWeight += weight;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalWeight == 0) {
|
||||
return double.parse(0.0.toStringAsFixed(2));
|
||||
}
|
||||
|
||||
final avg = weightedSum / totalWeight;
|
||||
return double.parse(avg.toStringAsFixed(2));
|
||||
}
|
||||
52
firka/lib/core/bloc/app_icon_picker_cubit.dart
Normal file
52
firka/lib/core/bloc/app_icon_picker_cubit.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
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(","),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
37
firka/lib/core/bloc/toast_cubit.dart
Normal file
37
firka/lib/core/bloc/toast_cubit.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,9 @@ extension TimetableExtension on Iterable<Lesson> {
|
||||
for (var lesson in this) {
|
||||
if (lesson.lessonNumber == null) continue;
|
||||
|
||||
if (lessons.firstWhereOrNull(
|
||||
(lesson2) => lesson.lessonNumber == lesson2.lessonNumber,
|
||||
) ==
|
||||
null) {
|
||||
if (!lessons.any(
|
||||
(lesson2) => lesson.lessonNumber == lesson2.lessonNumber,
|
||||
)) {
|
||||
final ref = reference.start;
|
||||
final newStart = DateTime(
|
||||
ref.year,
|
||||
@@ -69,10 +68,20 @@ extension DurationExtension on Duration {
|
||||
String seconds = inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||
return "$hours:$minutes:$seconds";
|
||||
}
|
||||
|
||||
String? timeLeft(AppLocalizations l10n) {
|
||||
return inMinutes > 0
|
||||
? "${inMinutes + 1} ${l10n.starting_min_plural}"
|
||||
: inSeconds > 0
|
||||
? "$inSeconds ${inSeconds == 1 ? l10n.starting_sec : l10n.starting_sec_plural}"
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
enum FormatMode {
|
||||
yearly,
|
||||
mmmd,
|
||||
main,
|
||||
grades,
|
||||
welcome,
|
||||
hmm,
|
||||
@@ -87,8 +96,22 @@ enum FormatMode {
|
||||
|
||||
enum Cycle { morning, day, afternoon, night }
|
||||
|
||||
extension ComparableExtension<T extends Comparable<T>> on Comparable<T> {
|
||||
T min(T other) {
|
||||
return compareTo(other) < 0 ? this as T : other;
|
||||
}
|
||||
|
||||
bool isBetween(T from, T to) {
|
||||
return compareTo(from) > 0 && compareTo(to) < 0;
|
||||
}
|
||||
|
||||
T max(T other) {
|
||||
return compareTo(other) > 0 ? this as T : other;
|
||||
}
|
||||
}
|
||||
|
||||
extension DateExtension on DateTime {
|
||||
String format(AppLocalizations l10n, FormatMode mode) {
|
||||
String? translatedDay(AppLocalizations l10n) {
|
||||
var today = timeNow().getMidnight();
|
||||
|
||||
var tomorrowLim = today.add(Duration(days: 2));
|
||||
@@ -96,32 +119,43 @@ extension DateExtension on DateTime {
|
||||
var yesterday = today.subtract(Duration(days: 1));
|
||||
var yesterdayLim = today.subtract(Duration(days: 2));
|
||||
|
||||
var weekStart = subtract(Duration(days: weekday - 1));
|
||||
if (isAfter(yesterdayLim) && isBefore(today)) {
|
||||
return l10n.yesterday;
|
||||
}
|
||||
if (isAfter(yesterday) && isBefore(tomorrow)) {
|
||||
return l10n.today;
|
||||
}
|
||||
if (isAfter(today) && isBefore(tomorrowLim)) {
|
||||
return l10n.tomorrow;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
String format(AppLocalizations l10n, FormatMode mode) {
|
||||
var weekStart = getMonday();
|
||||
var weekEnd = weekStart.add(Duration(days: 6));
|
||||
|
||||
switch (mode) {
|
||||
case FormatMode.main:
|
||||
var lastWeek = timeNow().getMidnight().subtract(Duration(days: 8));
|
||||
var isLastWeek =
|
||||
lastWeek.millisecondsSinceEpoch <
|
||||
getMidnight().millisecondsSinceEpoch;
|
||||
final dayName = DateFormat(
|
||||
'EEEE',
|
||||
l10n.localeName,
|
||||
).format(this).firstUpper();
|
||||
return translatedDay(l10n) ??
|
||||
(isLastWeek
|
||||
? "$dayName (${format(l10n, FormatMode.mmmd).firstUpper()})"
|
||||
: "${format(l10n, FormatMode.yearly).firstUpper()} ($dayName)");
|
||||
case FormatMode.grades:
|
||||
if (isBefore(yesterdayLim)) {
|
||||
final month = DateFormat(
|
||||
'MMMM',
|
||||
l10n.localeName,
|
||||
).format(this).firstUpper();
|
||||
final day = DateFormat('d', l10n.localeName).format(this);
|
||||
return "$month $day";
|
||||
}
|
||||
if (isAfter(yesterdayLim) && isBefore(today)) {
|
||||
return l10n.yesterday;
|
||||
}
|
||||
if (isAfter(yesterday) && isBefore(tomorrow)) {
|
||||
return l10n.today;
|
||||
}
|
||||
if (isAfter(today) && isBefore(tomorrowLim)) {
|
||||
return l10n.tomorrow;
|
||||
}
|
||||
|
||||
return format(l10n, FormatMode.yearly);
|
||||
return translatedDay(l10n) ?? format(l10n, FormatMode.yearly);
|
||||
case FormatMode.yearly:
|
||||
return DateFormat('MMMM dd', l10n.localeName).format(this);
|
||||
return DateFormat('MMMM d', l10n.localeName).format(this);
|
||||
case FormatMode.mmmd:
|
||||
return DateFormat('MMM d', l10n.localeName).format(this);
|
||||
case FormatMode.hmm:
|
||||
return DateFormat('H:mm', l10n.localeName).format(this);
|
||||
case FormatMode.welcome:
|
||||
@@ -155,7 +189,10 @@ extension DateExtension on DateTime {
|
||||
case FormatMode.yyyymmdd:
|
||||
return DateFormat('yyyy. MM. dd.', l10n.localeName).format(this);
|
||||
case FormatMode.yyyymmddhhmmss:
|
||||
return DateFormat('yyyy-MM-dd hh:mm:ss', l10n.localeName).format(this);
|
||||
return DateFormat(
|
||||
'yyyy. MM. dd. H:mm:ss',
|
||||
l10n.localeName,
|
||||
).format(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,16 +209,12 @@ extension DateExtension on DateTime {
|
||||
return subtract(Duration(days: weekday - 1));
|
||||
}
|
||||
|
||||
DateTime getMidnight() {
|
||||
return subtract(
|
||||
Duration(
|
||||
hours: hour,
|
||||
minutes: minute,
|
||||
seconds: second,
|
||||
milliseconds: millisecond,
|
||||
microseconds: microsecond,
|
||||
),
|
||||
);
|
||||
DateTime getMonthFirstDay() {
|
||||
return DateTime(year, month, 1);
|
||||
}
|
||||
|
||||
DateTime getMonthLastDay() {
|
||||
return DateTime(year, month + 1, 1).subtract(Duration(days: 1));
|
||||
}
|
||||
|
||||
Cycle getDayCycle() {
|
||||
@@ -201,61 +234,20 @@ extension DateExtension on DateTime {
|
||||
|
||||
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> {
|
||||
Map<DateTime, List<T>> groupList(DateTime Function(T elem) getDate) {
|
||||
Map<DateTime, List<T>> newList = {};
|
||||
|
||||
var today = timeNow();
|
||||
today = today.subtract(
|
||||
Duration(
|
||||
hours: today.hour,
|
||||
minutes: today.minute,
|
||||
seconds: today.second,
|
||||
milliseconds: today.millisecond,
|
||||
),
|
||||
);
|
||||
|
||||
var tomorrow = today.add(Duration(days: 1));
|
||||
var yesterday = today.subtract(Duration(days: 1));
|
||||
|
||||
for (var elem in this) {
|
||||
var date = getDate(elem);
|
||||
var day = date.subtract(
|
||||
Duration(
|
||||
hours: date.hour,
|
||||
minutes: date.minute,
|
||||
seconds: date.second,
|
||||
milliseconds: date.millisecond,
|
||||
),
|
||||
);
|
||||
|
||||
if (date.isAfter(tomorrow.add(Duration(days: 1)))) {
|
||||
if (newList[day] == null) {
|
||||
newList[day] = List<T>.empty(growable: true);
|
||||
}
|
||||
|
||||
newList[day]!.add(elem);
|
||||
continue;
|
||||
}
|
||||
if (date.isAfter(today)) {
|
||||
if (newList[tomorrow] == null) {
|
||||
newList[tomorrow] = List<T>.empty(growable: true);
|
||||
}
|
||||
|
||||
newList[tomorrow]!.add(elem);
|
||||
continue;
|
||||
}
|
||||
if (date.isAfter(yesterday.subtract(Duration(days: 1))) &&
|
||||
date.isBefore(today)) {
|
||||
if (newList[yesterday] == null) {
|
||||
newList[yesterday] = List<T>.empty(growable: true);
|
||||
}
|
||||
|
||||
newList[yesterday]!.add(elem);
|
||||
continue;
|
||||
}
|
||||
var day = date.getMidnight();
|
||||
|
||||
if (newList[day] == null) {
|
||||
newList[day] = List<T>.empty(growable: true);
|
||||
@@ -280,7 +272,7 @@ extension LessonExtension on List<Lesson> {
|
||||
}
|
||||
|
||||
Lesson? getPrevLesson(DateTime now) {
|
||||
return firstWhereOrNull(
|
||||
return reversed.firstWhereOrNull(
|
||||
(lesson) => lesson.end.isBefore(now.add(Duration(milliseconds: 1))),
|
||||
);
|
||||
}
|
||||
@@ -303,4 +295,26 @@ extension StringExtension on String {
|
||||
if (length == 1) this[0].toUpperCase();
|
||||
return this[0].toUpperCase() + substring(1, length);
|
||||
}
|
||||
|
||||
String shortenName([int start = 0]) {
|
||||
if (length <= 16 || start >= length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
int index = indexOf(" ", start);
|
||||
if (index == -1) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String string = substring(start, index);
|
||||
if (string.endsWith(".")) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return replaceRange(
|
||||
start,
|
||||
index,
|
||||
"${string[0]}.",
|
||||
).shortenName(index - string.length + 2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class FirkaBundle extends CachingAssetBundle {
|
||||
@override
|
||||
Future<ByteData> load(String key) async {
|
||||
logger.finest(
|
||||
"Loading asset from root bundle: assets/flutter_assets/$key",
|
||||
);
|
||||
return rootBundle.load(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -99,7 +98,6 @@ class ImagePreloader {
|
||||
AssetBundle bundle,
|
||||
String assetPath,
|
||||
) async {
|
||||
logger.finest("Caching: $assetPath");
|
||||
final ByteData data = await bundle.load(assetPath);
|
||||
final Uint8List bytes = data.buffer.asUint8List();
|
||||
return await _decodeImageFromBytes(bytes);
|
||||
|
||||
@@ -21,5 +21,5 @@ Future<void> pickProfilePicture(
|
||||
await File(p.join(dataDir.path, "profile.webp")).writeAsBytes(bytes);
|
||||
|
||||
data.profilePicture = bytes;
|
||||
data.profilePictureCubit?.notifyChanged();
|
||||
data.profilePictureCubit.notifyChanged();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
45
firka/lib/core/settings/setting.dart
Normal file
45
firka/lib/core/settings/setting.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
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});
|
||||
}
|
||||
65
firka/lib/core/settings/settings_effects.dart
Normal file
65
firka/lib/core/settings/settings_effects.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
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 "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.homeRefreshCubit.requestRefresh();
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
146
firka/lib/core/settings/settings_repository.dart
Normal file
146
firka/lib/core/settings/settings_repository.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
99
firka/lib/core/settings/settings_schema.dart
Normal file
99
firka/lib/core/settings/settings_schema.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import "setting.dart";
|
||||
import "settings_repository.dart";
|
||||
|
||||
part "settings_schema.gen.dart";
|
||||
|
||||
enum AppLanguage { auto, hu, en, de }
|
||||
|
||||
enum ThemeBrightness { auto, light, dark }
|
||||
|
||||
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;
|
||||
}
|
||||
161
firka/lib/core/settings/settings_schema.gen.dart
Normal file
161
firka/lib/core/settings/settings_schema.gen.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
// 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 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,
|
||||
];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
151
firka/lib/core/settings/settings_ui.dart
Normal file
151
firka/lib/core/settings/settings_ui.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
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 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);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class IOSWidgetHelper {
|
||||
'description': subject.category.description,
|
||||
},
|
||||
'sortIndex': subject.sortIndex,
|
||||
'teacherName': subject.teacherName,
|
||||
'teacherName': null,
|
||||
}
|
||||
: {
|
||||
'uid': '',
|
||||
@@ -152,8 +152,7 @@ class IOSWidgetHelper {
|
||||
},
|
||||
'theme': lesson.theme,
|
||||
'roomName': lesson.roomName,
|
||||
'isCancelled':
|
||||
lesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||
'isCancelled': lesson.state.name.toLowerCase().contains('elmarad'),
|
||||
'isSubstitution': lesson.substituteTeacher != null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import 'package:isar_community/isar.dart';
|
||||
|
||||
part 'generic_cache_model.g.dart';
|
||||
|
||||
enum CacheId {
|
||||
getStudent,
|
||||
getNoticeBoard,
|
||||
getInfoBoard,
|
||||
getGrades,
|
||||
getOmissions,
|
||||
getTests,
|
||||
getClassGroup,
|
||||
getSubjectAvg,
|
||||
getLessons,
|
||||
getHomework,
|
||||
}
|
||||
|
||||
@collection
|
||||
class GenericCacheModel {
|
||||
Id? cacheKey;
|
||||
String? cacheData;
|
||||
|
||||
GenericCacheModel();
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
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,26 +0,0 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
|
||||
class DatedCacheEntry {
|
||||
Id? cacheKey;
|
||||
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 currentDate = timeNow();
|
||||
var md = key ~/ pow(10, 11);
|
||||
var month = md ~/ pow(10, 2);
|
||||
var day = md - month * pow(10, 2);
|
||||
|
||||
return DateFormat("yyyy-M-d").parse("${currentDate.year}-$month-$day");
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:firka/data/ios_widget_helper.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/data/ios_widget_helper.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:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -14,13 +17,12 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class WidgetCacheHelper {
|
||||
static Map<String, dynamic> toJson(FirkaStyle style, List<Lesson> timetable) {
|
||||
static Map<String, dynamic> toJson(
|
||||
FirkaStyle style,
|
||||
List<LessonCacheModel> timetable,
|
||||
) {
|
||||
List<Map<String, dynamic>> timetableJson = [];
|
||||
|
||||
for (var lesson in timetable) {
|
||||
timetableJson.add(lesson.toJson());
|
||||
}
|
||||
|
||||
return {'colors': _colorsMap(style), 'timetable': timetableJson};
|
||||
}
|
||||
|
||||
@@ -84,20 +86,13 @@ class WidgetCacheHelper {
|
||||
|
||||
final start = now.subtract(Duration(days: 7));
|
||||
final end = now.add(Duration(days: 14));
|
||||
final lessons = await client.getTimeTable(start, end, forceCache: false);
|
||||
final lessons = await client.getLessons(start, end);
|
||||
|
||||
final widgetFile = File(p.join(dataDir.path, "widget_state.json"));
|
||||
|
||||
if (lessons.response != null) {
|
||||
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');
|
||||
}
|
||||
widgetFile.writeAsString(
|
||||
jsonEncode(WidgetCacheHelper.toJson(style, lessons)),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> generateWidgetStateForDate(
|
||||
@@ -106,16 +101,8 @@ class WidgetCacheHelper {
|
||||
KretaClient client,
|
||||
) async {
|
||||
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, dayLessons);
|
||||
final json = toJson(style, []);
|
||||
json['displayDate'] =
|
||||
'${date.year.toString().padLeft(4, '0')}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
|
||||
@@ -123,73 +110,41 @@ class WidgetCacheHelper {
|
||||
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
|
||||
/// Call this on: app open, user switch, data refresh
|
||||
static Future<void> refreshIOSWidgets(
|
||||
KretaClient client,
|
||||
SettingsStore settings,
|
||||
SettingsRepository settings,
|
||||
) async {
|
||||
if (!Platform.isIOS) return;
|
||||
|
||||
try {
|
||||
final langIndex =
|
||||
(settings.group("settings").subGroup("application")["language"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex;
|
||||
final language = settings.get(SettingsRegistry.language);
|
||||
String locale;
|
||||
switch (langIndex) {
|
||||
case 1:
|
||||
switch (language) {
|
||||
case AppLanguage.hu:
|
||||
locale = 'hu';
|
||||
break;
|
||||
case 2:
|
||||
case AppLanguage.en:
|
||||
locale = 'en';
|
||||
break;
|
||||
case 3:
|
||||
case AppLanguage.de:
|
||||
locale = 'de';
|
||||
break;
|
||||
default:
|
||||
case AppLanguage.auto:
|
||||
locale = 'hu';
|
||||
}
|
||||
|
||||
final themeIndex =
|
||||
(settings.group("settings").subGroup("customization")["theme"]
|
||||
as SettingsItemsRadio)
|
||||
.activeIndex;
|
||||
final themeBrightness = settings.get(SettingsRegistry.themeBrightness);
|
||||
String theme;
|
||||
switch (themeIndex) {
|
||||
case 1:
|
||||
switch (themeBrightness) {
|
||||
case ThemeBrightness.light:
|
||||
theme = 'light';
|
||||
break;
|
||||
case 2:
|
||||
case ThemeBrightness.dark:
|
||||
theme = 'dark';
|
||||
break;
|
||||
default:
|
||||
case ThemeBrightness.auto:
|
||||
theme =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.light
|
||||
@@ -201,19 +156,17 @@ class WidgetCacheHelper {
|
||||
final todayMidnight = DateTime(now.year, now.month, now.day);
|
||||
final tomorrowMidnight = todayMidnight.add(Duration(days: 1));
|
||||
|
||||
final todayResponse = await client.getTimeTable(
|
||||
await client.getLessons(
|
||||
todayMidnight,
|
||||
todayMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||
forceCache: false,
|
||||
);
|
||||
final tomorrowResponse = await client.getTimeTable(
|
||||
await client.getLessons(
|
||||
tomorrowMidnight,
|
||||
tomorrowMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||
forceCache: false,
|
||||
);
|
||||
|
||||
final todayLessons = todayResponse.response ?? [];
|
||||
final tomorrowLessons = tomorrowResponse.response ?? [];
|
||||
final todayLessons = [];
|
||||
final tomorrowLessons = [];
|
||||
|
||||
debugPrint(
|
||||
'iOS widget refresh: ${todayLessons.length} today lessons, ${tomorrowLessons.length} tomorrow lessons',
|
||||
@@ -224,12 +177,11 @@ class WidgetCacheHelper {
|
||||
if (tomorrowLessons.isEmpty) {
|
||||
for (int i = 2; i <= 7; i++) {
|
||||
final dayMidnight = todayMidnight.add(Duration(days: i));
|
||||
final dayResponse = await client.getTimeTable(
|
||||
await client.getLessons(
|
||||
dayMidnight,
|
||||
dayMidnight.add(Duration(hours: 23, minutes: 59)),
|
||||
forceCache: false,
|
||||
);
|
||||
final dayLessons = dayResponse.response ?? [];
|
||||
final dayLessons = <Lesson>[];
|
||||
if (dayLessons.isNotEmpty) {
|
||||
nextSchoolDayLessons = dayLessons;
|
||||
nextSchoolDayDate = dayMidnight;
|
||||
@@ -241,51 +193,33 @@ class WidgetCacheHelper {
|
||||
}
|
||||
}
|
||||
|
||||
final gradesResponse = await client.getGrades(forceCache: false);
|
||||
final grades = gradesResponse.response ?? [];
|
||||
final gradesResponse = await client.getGrades();
|
||||
final grades = [];
|
||||
|
||||
debugPrint(
|
||||
'iOS widget refresh: ${grades.length} grades fetched (cached: ${gradesResponse.cached})',
|
||||
'iOS widget refresh: ${grades.length} grades fetched (cached: $gradesResponse)',
|
||||
);
|
||||
|
||||
final Map<String, double> subjectAverages = {};
|
||||
final Set<String> subjectUids = {};
|
||||
final HashSet<Subject> subjects = HashSet(
|
||||
hashCode: (s) => s.uid.hashCode,
|
||||
equals: (s, s2) => s.uid == s2.uid,
|
||||
);
|
||||
|
||||
for (var grade in grades) {
|
||||
subjectUids.add(grade.subject.uid);
|
||||
}
|
||||
|
||||
double overallSum = 0;
|
||||
int validSubjectCount = 0;
|
||||
|
||||
for (var uid in subjectUids) {
|
||||
final subjectGrades = grades
|
||||
.where((g) => g.subject.uid == uid)
|
||||
.toList();
|
||||
final avg = _calculateWeightedAverage(subjectGrades);
|
||||
if (!avg.isNaN && avg > 0) {
|
||||
subjectAverages[uid] = avg;
|
||||
overallSum += avg;
|
||||
validSubjectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
final double? overallAverage = validSubjectCount > 0
|
||||
? overallSum / validSubjectCount
|
||||
: null;
|
||||
subjects.addAll(grades.map((g) => g.subject));
|
||||
|
||||
WidgetBreakInfo? currentBreak;
|
||||
|
||||
await updateIOSWidgets(
|
||||
await IOSWidgetHelper.updateWidgetData(
|
||||
locale: locale,
|
||||
theme: theme,
|
||||
todayLessons: todayLessons,
|
||||
tomorrowLessons: tomorrowLessons,
|
||||
todayLessons: [],
|
||||
tomorrowLessons: [],
|
||||
nextSchoolDayLessons: nextSchoolDayLessons,
|
||||
nextSchoolDayDate: nextSchoolDayDate,
|
||||
grades: grades,
|
||||
grades: [],
|
||||
subjectAverages: subjectAverages,
|
||||
overallAverage: overallAverage,
|
||||
overallAverage: 0.0,
|
||||
currentBreak: currentBreak,
|
||||
);
|
||||
|
||||
@@ -300,7 +234,7 @@ class WidgetCacheHelper {
|
||||
if (!Platform.isIOS) return;
|
||||
|
||||
try {
|
||||
await updateIOSWidgets(
|
||||
await IOSWidgetHelper.updateWidgetData(
|
||||
locale: 'hu',
|
||||
theme: 'light',
|
||||
todayLessons: [],
|
||||
@@ -315,26 +249,4 @@ class WidgetCacheHelper {
|
||||
debugPrint('Error clearing iOS widgets: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate weighted average for a list of grades
|
||||
static double _calculateWeightedAverage(List<Grade> grades) {
|
||||
var weightTotal = 0.0;
|
||||
var sum = 0.0;
|
||||
|
||||
for (var grade in grades) {
|
||||
final name = grade.valueType.name?.toLowerCase() ?? '';
|
||||
final isPercentage =
|
||||
name.contains('szazalek') || name.contains('percent');
|
||||
if (isPercentage) continue;
|
||||
|
||||
if (grade.numericValue != null) {
|
||||
var weight = (grade.weightPercentage ?? 100) / 100.0;
|
||||
weightTotal += weight;
|
||||
sum += grade.numericValue! * weight;
|
||||
}
|
||||
}
|
||||
|
||||
if (weightTotal == 0) return double.nan;
|
||||
return sum / weightTotal;
|
||||
}
|
||||
}
|
||||
|
||||
Submodule firka/lib/l10n updated: 8287ed0936...2715ee8b5d
@@ -13,6 +13,10 @@ void main() async {
|
||||
dio.options.receiveTimeout = Duration(seconds: 3);
|
||||
dio.options.validateStatus = (status) => status != null && status < 500;
|
||||
|
||||
FlutterError.onError = (details) {
|
||||
FlutterError.presentError(details);
|
||||
};
|
||||
|
||||
runZonedGuarded(
|
||||
() async {
|
||||
logger.finest("Initializing app");
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:firka/ui/phone/pages/home/home_omissions.dart';
|
||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/app/app_state.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_subject.dart';
|
||||
import 'package:firka/ui/phone/pages/home/home_main.dart';
|
||||
@@ -24,6 +27,18 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
GoRouter createAppRouter() {
|
||||
final subjectRoute = GoRoute(
|
||||
path: 'subject',
|
||||
builder: (context, state) {
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeGradesSubjectScreen.subject(
|
||||
state.extra as SubjectCacheModel,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return GoRouter(
|
||||
navigatorKey: navigatorKey,
|
||||
initialLocation: _initialLocation,
|
||||
@@ -73,8 +88,8 @@ GoRouter createAppRouter() {
|
||||
path: '/settings',
|
||||
builder: (context, state) {
|
||||
final items = state.extra != null
|
||||
? state.extra! as LinkedHashMap<String, SettingsItem>
|
||||
: initData.settings.items;
|
||||
? state.extra! as List<SettingsUiNode>
|
||||
: buildSettingsTree(initData.l10n).children;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: SettingsScreen(initData, items, key: state.pageKey),
|
||||
@@ -84,7 +99,7 @@ GoRouter createAppRouter() {
|
||||
GoRoute(
|
||||
path: '/message',
|
||||
builder: (context, state) {
|
||||
final info = state.extra as InfoBoardItem?;
|
||||
final info = state.extra as MessageItem?;
|
||||
if (info == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
@@ -124,19 +139,7 @@ GoRouter createAppRouter() {
|
||||
child: HomeMainScreen(initData),
|
||||
),
|
||||
),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'subject/:uid',
|
||||
builder: (context, state) {
|
||||
final uid = state.pathParameters['uid'] ?? '';
|
||||
activeSubjectUid = uid;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeGradesSubjectScreen(initData),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
routes: [subjectRoute],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -151,19 +154,7 @@ GoRouter createAppRouter() {
|
||||
child: HomeGradesScreen(initData),
|
||||
),
|
||||
),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'subject/:uid',
|
||||
builder: (context, state) {
|
||||
final uid = state.pathParameters['uid'] ?? '';
|
||||
activeSubjectUid = uid;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeGradesSubjectScreen(initData),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
routes: [subjectRoute],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -186,21 +177,25 @@ GoRouter createAppRouter() {
|
||||
child: HomeTimetableMonthlyScreen(initData),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: 'subject/:uid',
|
||||
builder: (context, state) {
|
||||
final uid = state.pathParameters['uid'] ?? '';
|
||||
activeSubjectUid = uid;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeGradesSubjectScreen(initData),
|
||||
);
|
||||
},
|
||||
),
|
||||
subjectRoute,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/omissions',
|
||||
pageBuilder: (context, state) => NoTransitionPage(
|
||||
key: state.pageKey,
|
||||
child: DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeOmissionsScreen(initData),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -209,10 +204,8 @@ GoRouter createAppRouter() {
|
||||
|
||||
String get _initialLocation {
|
||||
if (!initDone) return '/';
|
||||
if (initData.tokens.isEmpty) return '/login';
|
||||
final betaWarning = initData.settings
|
||||
.group('settings')
|
||||
.boolean('beta_warning');
|
||||
if (initData.client == null) return '/login';
|
||||
final betaWarning = Settings.betaWarning.value;
|
||||
if (!betaWarning) return '/beta';
|
||||
return '/home';
|
||||
}
|
||||
@@ -220,10 +213,8 @@ String get _initialLocation {
|
||||
String? _redirect(BuildContext context, GoRouterState state) {
|
||||
if (!initDone) return null;
|
||||
final location = state.matchedLocation;
|
||||
final hasTokens = initData.tokens.isNotEmpty;
|
||||
final betaWarning = initData.settings
|
||||
.group('settings')
|
||||
.boolean('beta_warning');
|
||||
final hasTokens = initData.client != null;
|
||||
final betaWarning = Settings.betaWarning.value;
|
||||
|
||||
if (!hasTokens) {
|
||||
if (location != '/login') return '/login';
|
||||
|
||||
@@ -41,57 +41,38 @@ class ShellWithNavBar extends StatelessWidget {
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(55, 0, 55, 12),
|
||||
padding: const EdgeInsets.fromLTRB(55, 16, 55, 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
BottomNavIconWidget(
|
||||
() {
|
||||
if (currentIndex != 0) {
|
||||
navigationShell.goBranch(0);
|
||||
}
|
||||
},
|
||||
currentIndex == 0,
|
||||
currentIndex == 0
|
||||
? Majesticon.homeSolid
|
||||
: Majesticon.homeLine,
|
||||
data.l10n.home,
|
||||
currentIndex == 0
|
||||
? appStyle.colors.accent
|
||||
: appStyle.colors.secondary,
|
||||
appStyle.colors.textPrimary,
|
||||
),
|
||||
BottomNavIconWidget(
|
||||
() {
|
||||
if (currentIndex != 1) {
|
||||
navigationShell.goBranch(1);
|
||||
}
|
||||
},
|
||||
currentIndex == 1,
|
||||
currentIndex == 1
|
||||
? Majesticon.bookmarkSolid
|
||||
: Majesticon.bookmarkLine,
|
||||
data.l10n.grades,
|
||||
currentIndex == 1
|
||||
? appStyle.colors.accent
|
||||
: appStyle.colors.secondary,
|
||||
appStyle.colors.textPrimary,
|
||||
),
|
||||
BottomNavIconWidget(
|
||||
() {
|
||||
if (currentIndex != 2) {
|
||||
navigationShell.goBranch(2);
|
||||
}
|
||||
},
|
||||
currentIndex == 2,
|
||||
currentIndex == 2
|
||||
? Majesticon.calendarSolid
|
||||
: Majesticon.calendarLine,
|
||||
data.l10n.timetable,
|
||||
currentIndex == 2
|
||||
? appStyle.colors.accent
|
||||
: appStyle.colors.secondary,
|
||||
appStyle.colors.textPrimary,
|
||||
...[
|
||||
(data.l10n.home, Majesticon.homeSolid, Majesticon.homeLine),
|
||||
(
|
||||
data.l10n.grades,
|
||||
Majesticon.bookmarkSolid,
|
||||
Majesticon.bookmarkLine,
|
||||
),
|
||||
(
|
||||
data.l10n.timetable,
|
||||
Majesticon.calendarSolid,
|
||||
Majesticon.calendarLine,
|
||||
),
|
||||
(
|
||||
initData.l10n.omissions,
|
||||
Majesticon.timerSolid,
|
||||
Majesticon.timerLine,
|
||||
),
|
||||
].indexed.map(
|
||||
(nav) => BottomNavIconWidget(
|
||||
() {
|
||||
if (currentIndex != nav.$1) {
|
||||
navigationShell.goBranch(nav.$1);
|
||||
}
|
||||
},
|
||||
currentIndex == nav.$1,
|
||||
currentIndex == nav.$1 ? nav.$2.$2 : nav.$2.$3,
|
||||
nav.$2.$1,
|
||||
),
|
||||
),
|
||||
BottomNavIconWidget(
|
||||
() {
|
||||
@@ -102,8 +83,6 @@ class ShellWithNavBar extends StatelessWidget {
|
||||
? data.profilePicture!
|
||||
: Majesticon.menuLine,
|
||||
data.l10n.other,
|
||||
appStyle.colors.secondary,
|
||||
appStyle.colors.textPrimary,
|
||||
isProfilePicture: data.profilePicture != null,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
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,8 +242,7 @@ class LiveActivityManager {
|
||||
'nextRoomName': isBeforeSchool ? null : nextLesson?.roomName,
|
||||
'nextStartTime': nextStartTimeForActivity?.toUtc().toIso8601String(),
|
||||
'isSubstitution': currentLesson.substituteTeacher != null,
|
||||
'isCancelled':
|
||||
currentLesson.state.name?.toLowerCase().contains('elmarad') ?? false,
|
||||
'isCancelled': currentLesson.state.name.toLowerCase().contains('elmarad'),
|
||||
'substituteTeacher': currentLesson.substituteTeacher,
|
||||
'currentTime': now.toUtc().toIso8601String(),
|
||||
'mode': mode,
|
||||
|
||||
@@ -2,12 +2,11 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:firka/api/client/kreta_client.dart';
|
||||
import 'package:firka/api/client/live_activity_backend_client.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:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/services/live_activity_manager.dart';
|
||||
import 'package:firka/services/active_account_helper.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/ui/phone/screens/live_activity/live_activity_consent_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -61,12 +60,12 @@ class LiveActivityService {
|
||||
static String? _getCurrentStudentId({KretaClient? client}) {
|
||||
try {
|
||||
if (client != null) {
|
||||
return client.model.studentId;
|
||||
return client.cache.token.username;
|
||||
}
|
||||
if (!initDone) {
|
||||
return null;
|
||||
}
|
||||
return initData.client.model.studentId;
|
||||
return initData.client!.cache.token.username;
|
||||
} catch (e) {
|
||||
_logger.warning('Error getting current studentId: $e');
|
||||
return null;
|
||||
@@ -216,17 +215,8 @@ class LiveActivityService {
|
||||
final userLiveActivityEnabled = await _getUserLiveActivityEnabled(
|
||||
client: client,
|
||||
);
|
||||
final globalLiveActivitySetting =
|
||||
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);
|
||||
});
|
||||
if (Settings.liveActivityEnabled.value != userLiveActivityEnabled) {
|
||||
await Settings.liveActivityEnabled.setSilently(userLiveActivityEnabled);
|
||||
_logger.info(
|
||||
'Global LiveActivity setting synced: $userLiveActivityEnabled for user $studentId',
|
||||
);
|
||||
@@ -235,19 +225,10 @@ class LiveActivityService {
|
||||
final userMorningEnabled = await _getUserMorningNotificationEnabled(
|
||||
client: client,
|
||||
);
|
||||
final globalMorningEnabledSetting =
|
||||
initData.settings
|
||||
.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,
|
||||
);
|
||||
});
|
||||
if (Settings.morningNotificationEnabled.value != userMorningEnabled) {
|
||||
await Settings.morningNotificationEnabled.setSilently(
|
||||
userMorningEnabled,
|
||||
);
|
||||
_logger.info(
|
||||
'Global morning notification enabled synced: $userMorningEnabled for user $studentId',
|
||||
);
|
||||
@@ -256,40 +237,24 @@ class LiveActivityService {
|
||||
final userMorningTime = await _getUserMorningNotificationTime(
|
||||
client: client,
|
||||
);
|
||||
final globalMorningTimeSetting =
|
||||
initData.settings
|
||||
.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);
|
||||
});
|
||||
if (Settings.morningNotificationTime.value.toInt() != userMorningTime) {
|
||||
await Settings.morningNotificationTime.setSilently(
|
||||
userMorningTime.toDouble(),
|
||||
);
|
||||
_logger.info(
|
||||
'Global morning notification time synced: $userMorningTime for user $studentId',
|
||||
);
|
||||
}
|
||||
|
||||
final userBellDelay = await _getUserBellDelay(client: client);
|
||||
final globalBellDelaySetting =
|
||||
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);
|
||||
});
|
||||
if (Settings.bellDelay.value != userBellDelay) {
|
||||
await Settings.bellDelay.setSilently(userBellDelay);
|
||||
_logger.info(
|
||||
'Global bell delay synced: $userBellDelay for user $studentId',
|
||||
);
|
||||
}
|
||||
|
||||
initData.themeCubit?.refresh();
|
||||
initData.themeCubit.refresh();
|
||||
} catch (e) {
|
||||
_logger.warning('Error syncing global settings: $e');
|
||||
}
|
||||
@@ -302,22 +267,14 @@ class LiveActivityService {
|
||||
return 'hu';
|
||||
}
|
||||
|
||||
final languageSetting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("application")["language"]
|
||||
as SettingsItemsRadio?;
|
||||
|
||||
if (languageSetting == null) return 'hu';
|
||||
|
||||
switch (languageSetting.activeIndex) {
|
||||
case 1:
|
||||
switch (Settings.language.value) {
|
||||
case AppLanguage.hu:
|
||||
return 'hu';
|
||||
case 2:
|
||||
case AppLanguage.en:
|
||||
return 'en';
|
||||
case 3:
|
||||
case AppLanguage.de:
|
||||
return 'de';
|
||||
default: // auto
|
||||
case AppLanguage.auto:
|
||||
final systemLang = Platform.localeName.split('_').first;
|
||||
if (['hu', 'en', 'de'].contains(systemLang)) {
|
||||
return systemLang;
|
||||
@@ -444,7 +401,7 @@ class LiveActivityService {
|
||||
}
|
||||
|
||||
try {
|
||||
final client = initData.client;
|
||||
final client = initData.client!;
|
||||
|
||||
final enabled = await isEnabled(initData.settings, client);
|
||||
if (!enabled) {
|
||||
@@ -465,39 +422,23 @@ class LiveActivityService {
|
||||
_logger.info(
|
||||
'Background fetch: attempting to fetch fresh data from KRÉTA API',
|
||||
);
|
||||
final timetableResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
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');
|
||||
}
|
||||
allLessons = <Lesson>[];
|
||||
_logger.info(
|
||||
'Background fetch: successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
||||
);
|
||||
} catch (e) {
|
||||
_logger.warning(
|
||||
'Background fetch: KRÉTA API failed ($e), falling back to cache',
|
||||
);
|
||||
try {
|
||||
final cachedResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: true,
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
allLessons = <Lesson>[];
|
||||
_logger.info(
|
||||
'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) {
|
||||
_logger.severe(
|
||||
'Background fetch: cache fallback also failed: $cacheError',
|
||||
@@ -525,14 +466,10 @@ class LiveActivityService {
|
||||
|
||||
try {
|
||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||
final response = await client.getTimeTable(
|
||||
candidateDay,
|
||||
candidateDayEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(candidateDay, candidateDayEnd);
|
||||
|
||||
if (response.response != null && response.response!.isNotEmpty) {
|
||||
final schoolLessons = response.response!.where((lesson) {
|
||||
if (true) {
|
||||
final schoolLessons = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
return uid.contains('orarendiora') ||
|
||||
uid.contains('tanitasiora') ||
|
||||
@@ -639,7 +576,7 @@ class LiveActivityService {
|
||||
|
||||
/// Check if LiveActivity is enabled in settings
|
||||
static Future<bool> isEnabled([
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
KretaClient? client,
|
||||
]) async {
|
||||
try {
|
||||
@@ -660,7 +597,7 @@ class LiveActivityService {
|
||||
if (!Platform.isIOS) return;
|
||||
|
||||
try {
|
||||
final effectiveClient = client ?? initData.client;
|
||||
final effectiveClient = initData.client!;
|
||||
final studentId = _getCurrentStudentId(client: effectiveClient);
|
||||
if (studentId == null) {
|
||||
_logger.warning('Cannot change LiveActivity state: no current user');
|
||||
@@ -714,14 +651,9 @@ class LiveActivityService {
|
||||
);
|
||||
}
|
||||
|
||||
final studentResp = await effectiveClient.getStudent();
|
||||
final activeToken = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
preferredStudentIdNorm: effectiveClient.model.studentIdNorm,
|
||||
);
|
||||
final studentName =
|
||||
studentResp.response?.name ?? activeToken?.studentId ?? "Student";
|
||||
await effectiveClient.getStudent();
|
||||
final activeToken = initData.client!.cache.token;
|
||||
final studentName = activeToken.username;
|
||||
|
||||
await onUserLogin(
|
||||
client: effectiveClient,
|
||||
@@ -851,7 +783,7 @@ class LiveActivityService {
|
||||
static Future<void> onUserLogin({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
}) async {
|
||||
_logger.info('onUserLogin: Function called for $studentName');
|
||||
|
||||
@@ -889,39 +821,23 @@ class LiveActivityService {
|
||||
_logger.info(
|
||||
'onUserLogin: Attempting to fetch fresh timetable from KRÉTA API',
|
||||
);
|
||||
final timetableResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
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');
|
||||
}
|
||||
allLessons = <Lesson>[];
|
||||
_logger.info(
|
||||
'onUserLogin: Successfully fetched ${allLessons.length} lessons from KRÉTA API',
|
||||
);
|
||||
} catch (e) {
|
||||
_logger.warning(
|
||||
'onUserLogin: KRÉTA API failed ($e), falling back to cache',
|
||||
);
|
||||
try {
|
||||
final cachedResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: true,
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
allLessons = <Lesson>[];
|
||||
_logger.info(
|
||||
'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) {
|
||||
_logger.severe(
|
||||
'onUserLogin: Cache fallback also failed: $cacheError',
|
||||
@@ -944,14 +860,10 @@ class LiveActivityService {
|
||||
|
||||
List<Lesson> nextWeekBreakEvents = [];
|
||||
try {
|
||||
final nextWeekResponse = await client.getTimeTable(
|
||||
nextWeekStart,
|
||||
nextWeekEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(nextWeekStart, nextWeekEnd);
|
||||
|
||||
if (nextWeekResponse.response != null) {
|
||||
nextWeekBreakEvents = nextWeekResponse.response!.where((lesson) {
|
||||
if (true) {
|
||||
nextWeekBreakEvents = <Lesson>[].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
final name = lesson.name.toLowerCase();
|
||||
return uid.contains('tanevrendjeesemeny') &&
|
||||
@@ -1049,14 +961,10 @@ class LiveActivityService {
|
||||
|
||||
try {
|
||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||
final response = await client.getTimeTable(
|
||||
candidateDay,
|
||||
candidateDayEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(candidateDay, candidateDayEnd);
|
||||
|
||||
if (response.response != null && response.response!.isNotEmpty) {
|
||||
final schoolLessons = response.response!.where((lesson) {
|
||||
if (true) {
|
||||
final schoolLessons = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
return uid.contains('orarendiora') ||
|
||||
uid.contains('tanitasiora') ||
|
||||
@@ -1203,7 +1111,7 @@ class LiveActivityService {
|
||||
static Future<void> checkAndUpdateTimetable({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
bool forceUpdate = false,
|
||||
}) async {
|
||||
if (!Platform.isIOS || !_isInitialized) return;
|
||||
@@ -1228,35 +1136,17 @@ class LiveActivityService {
|
||||
List<Lesson> allLessons = [];
|
||||
|
||||
try {
|
||||
final timetableResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
if (timetableResponse.response != null) {
|
||||
allLessons = List<Lesson>.from(timetableResponse.response!);
|
||||
} else {
|
||||
throw Exception('KRÉTA API returned null response');
|
||||
}
|
||||
allLessons = List<Lesson>.from([]);
|
||||
} catch (e) {
|
||||
_logger.warning(
|
||||
'checkAndUpdateTimetable: KRÉTA API failed ($e), falling back to cache',
|
||||
);
|
||||
try {
|
||||
final cachedResponse = await client.getTimeTable(
|
||||
startOfWeek,
|
||||
endOfWeek,
|
||||
forceCache: true,
|
||||
);
|
||||
if (cachedResponse.response != null) {
|
||||
allLessons = List<Lesson>.from(cachedResponse.response!);
|
||||
} else {
|
||||
_logger.severe(
|
||||
'checkAndUpdateTimetable: Both API and cache failed',
|
||||
);
|
||||
return;
|
||||
}
|
||||
await client.getLessons(startOfWeek, endOfWeek);
|
||||
|
||||
allLessons = <Lesson>[];
|
||||
} catch (cacheError) {
|
||||
_logger.severe(
|
||||
'checkAndUpdateTimetable: Cache fallback also failed: $cacheError',
|
||||
@@ -1274,14 +1164,10 @@ class LiveActivityService {
|
||||
|
||||
List<Lesson> nextWeekBreakEvents = [];
|
||||
try {
|
||||
final nextWeekResponse = await client.getTimeTable(
|
||||
nextWeekStart,
|
||||
nextWeekEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(nextWeekStart, nextWeekEnd);
|
||||
|
||||
if (nextWeekResponse.response != null) {
|
||||
nextWeekBreakEvents = nextWeekResponse.response!.where((lesson) {
|
||||
if (true) {
|
||||
nextWeekBreakEvents = <Lesson>[].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
final name = lesson.name.toLowerCase();
|
||||
return uid.contains('tanevrendjeesemeny') &&
|
||||
@@ -1375,14 +1261,10 @@ class LiveActivityService {
|
||||
|
||||
try {
|
||||
final candidateDayEnd = candidateDay.add(const Duration(days: 1));
|
||||
final response = await client.getTimeTable(
|
||||
candidateDay,
|
||||
candidateDayEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(candidateDay, candidateDayEnd);
|
||||
|
||||
if (response.response != null && response.response!.isNotEmpty) {
|
||||
final schoolLessons = response.response!.where((lesson) {
|
||||
if (true) {
|
||||
final schoolLessons = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
return uid.contains('orarendiora') ||
|
||||
uid.contains('tanitasiora') ||
|
||||
@@ -1490,7 +1372,7 @@ class LiveActivityService {
|
||||
static Future<void> _startTimetableMonitoring({
|
||||
required KretaClient client,
|
||||
required String studentName,
|
||||
SettingsStore? settingsStore,
|
||||
SettingsRepository? settingsStore,
|
||||
}) async {
|
||||
_stopTimetableMonitoring();
|
||||
|
||||
@@ -1581,12 +1463,12 @@ class LiveActivityService {
|
||||
final emptyType = NameUidDesc(
|
||||
uid: 'placeholder',
|
||||
name: 'Placeholder',
|
||||
description: null,
|
||||
description: '',
|
||||
);
|
||||
final emptyState = NameUidDesc(
|
||||
uid: 'active',
|
||||
name: 'Active',
|
||||
description: null,
|
||||
description: '',
|
||||
);
|
||||
|
||||
placeholderLesson = Lesson(
|
||||
@@ -1893,14 +1775,11 @@ class LiveActivityService {
|
||||
'Morning notifications re-enabled, fetching timetable to recreate notifications',
|
||||
);
|
||||
try {
|
||||
final client = initData.client;
|
||||
final client = initData.client!;
|
||||
final settingsStore = initData.settings;
|
||||
|
||||
final studentResp = await client.getStudent();
|
||||
final studentName =
|
||||
studentResp.response?.name ??
|
||||
client.model.studentId ??
|
||||
'Student';
|
||||
final studentName = studentResp.name;
|
||||
|
||||
await checkAndUpdateTimetable(
|
||||
client: client,
|
||||
@@ -1957,12 +1836,7 @@ class LiveActivityService {
|
||||
if (!initDone) {
|
||||
return null;
|
||||
}
|
||||
final setting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_enabled"]
|
||||
as SettingsBoolean?;
|
||||
return setting?.value;
|
||||
return Settings.morningNotificationEnabled.value;
|
||||
} catch (e) {
|
||||
_logger.warning('Error getting current morning notification enabled: $e');
|
||||
return null;
|
||||
@@ -1975,12 +1849,7 @@ class LiveActivityService {
|
||||
if (!initDone) {
|
||||
return null;
|
||||
}
|
||||
final setting =
|
||||
initData.settings
|
||||
.group("settings")
|
||||
.subGroup("notifications")["morning_notification_time"]
|
||||
as SettingsDouble?;
|
||||
return setting?.value;
|
||||
return Settings.morningNotificationTime.value;
|
||||
} catch (e) {
|
||||
_logger.warning('Error getting current morning notification time: $e');
|
||||
return null;
|
||||
@@ -2014,16 +1883,10 @@ class LiveActivityService {
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await client.getTimeTable(
|
||||
weekStart,
|
||||
weekEnd,
|
||||
forceCache: false,
|
||||
);
|
||||
await client.getLessons(weekStart, weekEnd);
|
||||
|
||||
if (response.response != null && response.response!.isNotEmpty) {
|
||||
final weekLessons = response.response!;
|
||||
|
||||
final breakEvents = weekLessons.where((lesson) {
|
||||
if (true) {
|
||||
final breakEvents = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
final name = lesson.name.toLowerCase();
|
||||
return uid.contains('tanevrendjeesemeny') &&
|
||||
@@ -2035,26 +1898,26 @@ class LiveActivityService {
|
||||
name.contains('nem órarendi nap'));
|
||||
}).toList();
|
||||
|
||||
final schoolLessons = weekLessons.where((lesson) {
|
||||
final schoolLessons = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
return uid.contains('orarendiora') ||
|
||||
uid.contains('tanitasiora') ||
|
||||
uid.contains('uresora');
|
||||
}).toList();
|
||||
|
||||
allLessons.addAll(weekLessons);
|
||||
allLessons.addAll([]);
|
||||
|
||||
if (breakEvents.isNotEmpty) {
|
||||
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
||||
lastBreakDay = breakEvents.last;
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in week ${weeksSearched + 1}, last: ${lastBreakDay.name} on ${lastBreakDay.date.split('T')[0]}',
|
||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in week ${weeksSearched + 1}, last: $lastBreakDay on $lastBreakDay',
|
||||
);
|
||||
} else if (schoolLessons.isNotEmpty) {
|
||||
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
||||
firstSchoolDayAfterBreak = schoolLessons.first;
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Found first school day after break: ${firstSchoolDayAfterBreak.name} on ${firstSchoolDayAfterBreak.date.split('T')[0]}',
|
||||
'[GlobalBreakSearcher] Found first school day after break: $firstSchoolDayAfterBreak on $firstSchoolDayAfterBreak',
|
||||
);
|
||||
break;
|
||||
} else {
|
||||
@@ -2062,10 +1925,6 @@ class LiveActivityService {
|
||||
'[GlobalBreakSearcher] Week ${weeksSearched + 1} is empty, continuing search...',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Week ${weeksSearched + 1} returned no data, continuing search...',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
final isTokenError =
|
||||
@@ -2084,15 +1943,10 @@ class LiveActivityService {
|
||||
}
|
||||
|
||||
try {
|
||||
final cachedResponse = await client.getTimeTable(
|
||||
weekStart,
|
||||
weekEnd,
|
||||
forceCache: true,
|
||||
);
|
||||
await client.getLessons(weekStart, weekEnd);
|
||||
|
||||
if (cachedResponse.response != null &&
|
||||
cachedResponse.response!.isNotEmpty) {
|
||||
final weekLessons = cachedResponse.response!;
|
||||
if (true) {
|
||||
final weekLessons = [];
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Loaded ${weekLessons.length} lessons from cache for week ${weeksSearched + 1}',
|
||||
);
|
||||
@@ -2109,33 +1963,29 @@ class LiveActivityService {
|
||||
name.contains('nem órarendi nap'));
|
||||
}).toList();
|
||||
|
||||
final schoolLessons = weekLessons.where((lesson) {
|
||||
final schoolLessons = [].where((lesson) {
|
||||
final uid = lesson.uid.toLowerCase();
|
||||
return uid.contains('orarendiora') ||
|
||||
uid.contains('tanitasiora') ||
|
||||
uid.contains('uresora');
|
||||
}).toList();
|
||||
|
||||
allLessons.addAll(weekLessons);
|
||||
allLessons.addAll([]);
|
||||
|
||||
if (breakEvents.isNotEmpty) {
|
||||
breakEvents.sort((a, b) => a.start.compareTo(b.start));
|
||||
lastBreakDay = breakEvents.last;
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in cached week ${weeksSearched + 1}, last: ${lastBreakDay.name} on ${lastBreakDay.date.split('T')[0]}',
|
||||
'[GlobalBreakSearcher] Found ${breakEvents.length} break event(s) in cached week ${weeksSearched + 1}, last: $lastBreakDay on $lastBreakDay',
|
||||
);
|
||||
} else if (schoolLessons.isNotEmpty) {
|
||||
schoolLessons.sort((a, b) => a.start.compareTo(b.start));
|
||||
firstSchoolDayAfterBreak = schoolLessons.first;
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] Found first school day after break in cache: ${firstSchoolDayAfterBreak.name} on ${firstSchoolDayAfterBreak.date.split('T')[0]}',
|
||||
'[GlobalBreakSearcher] Found first school day after break in cache: $firstSchoolDayAfterBreak on $firstSchoolDayAfterBreak',
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_logger.info(
|
||||
'[GlobalBreakSearcher] No cache available for week ${weeksSearched + 1}',
|
||||
);
|
||||
}
|
||||
} catch (cacheError) {
|
||||
_logger.warning(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka_common/data/database.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
@@ -9,10 +10,9 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.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/api/client/kreta_client.dart';
|
||||
import 'package:firka/data/models/token_model.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
|
||||
/// Helper class for Watch ↔ iPhone token sync (iOS) and Wear OS sync (Android).
|
||||
class WatchSyncHelper {
|
||||
@@ -60,42 +60,6 @@ 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) {
|
||||
if (value is int) return value;
|
||||
if (value is double) return value.toInt();
|
||||
@@ -152,9 +116,6 @@ class WatchSyncHelper {
|
||||
required TokenModel currentToken,
|
||||
}) {
|
||||
final currentExpiry = currentToken.expiryDate;
|
||||
if (currentExpiry == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final incomingVersion =
|
||||
incomingTokenVersion ??
|
||||
@@ -196,7 +157,6 @@ class WatchSyncHelper {
|
||||
|
||||
final currentRefresh = currentToken.refreshToken;
|
||||
if (incomingRefreshToken != null &&
|
||||
currentRefresh != null &&
|
||||
incomingRefreshToken != currentRefresh) {
|
||||
if (incomingIdToken != null && incomingIdToken != currentToken.idToken) {
|
||||
return true;
|
||||
@@ -225,13 +185,13 @@ class WatchSyncHelper {
|
||||
? token.updatedAtMs!
|
||||
: nowMs;
|
||||
final payload = <String, dynamic>{
|
||||
'studentId': token.studentId,
|
||||
'studentIdNorm': token.studentIdNorm,
|
||||
'studentId': token.username,
|
||||
'studentIdNorm': token.key,
|
||||
'iss': token.iss,
|
||||
'idToken': token.idToken,
|
||||
'accessToken': token.accessToken,
|
||||
'refreshToken': token.refreshToken,
|
||||
'expiryDate': token.expiryDate!.millisecondsSinceEpoch,
|
||||
'expiryDate': token.expiryDate.millisecondsSinceEpoch,
|
||||
'tokenVersion': tokenVersion,
|
||||
'updatedAtMs': updatedAtMs,
|
||||
};
|
||||
@@ -448,10 +408,7 @@ class WatchSyncHelper {
|
||||
await isar.tokenModels.clear();
|
||||
});
|
||||
|
||||
if (initDone) {
|
||||
initData.tokens = [];
|
||||
}
|
||||
if (initDone) initData.reauthCubit?.clear();
|
||||
if (initDone) initData.toastCubit.clear();
|
||||
|
||||
await prefs.setBool(_iosFreshInstallHandledKey, true);
|
||||
return true;
|
||||
@@ -523,7 +480,6 @@ class WatchSyncHelper {
|
||||
try {
|
||||
final recovered = await checkAndRecoverFromiCloud(
|
||||
isar: initData.isar,
|
||||
tokens: initData.tokens,
|
||||
client: initData.client,
|
||||
);
|
||||
|
||||
@@ -532,13 +488,10 @@ class WatchSyncHelper {
|
||||
'[WatchSync] Token recovered from iCloud, reauth flag cleared',
|
||||
);
|
||||
} else {
|
||||
final token = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
);
|
||||
final expiryDate = token?.expiryDate;
|
||||
if (expiryDate != null && expiryDate.isAfter(DateTime.now())) {
|
||||
if (initDone) initData.reauthCubit?.clear();
|
||||
final token = initData.client!.cache.token;
|
||||
final expiryDate = token.expiryDate;
|
||||
if (expiryDate.isAfter(DateTime.now())) {
|
||||
if (initDone) initData.toastCubit.clear();
|
||||
debugPrint(
|
||||
'[WatchSync] Cleared reauth flag after iCloud notification (token is valid)',
|
||||
);
|
||||
@@ -550,28 +503,14 @@ class WatchSyncHelper {
|
||||
}
|
||||
|
||||
static Map<String, dynamic>? _getTokenForWatch() {
|
||||
if (!initDone || initData.tokens.isEmpty) {
|
||||
if (!initDone) {
|
||||
debugPrint('[WatchSync] No token available');
|
||||
return {'error': 'no_token'};
|
||||
}
|
||||
|
||||
final token = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
);
|
||||
if (token == null) {
|
||||
debugPrint('[WatchSync] No active token available');
|
||||
return {'error': 'no_token'};
|
||||
}
|
||||
final token = initData.client!.cache.token;
|
||||
|
||||
if (token.accessToken == null ||
|
||||
token.refreshToken == null ||
|
||||
token.expiryDate == null) {
|
||||
debugPrint('[WatchSync] Token incomplete');
|
||||
return {'error': 'token_incomplete'};
|
||||
}
|
||||
|
||||
if (initData.client.needsReauth) {
|
||||
if (initData.client!.needsReauth) {
|
||||
debugPrint('[WatchSync] iPhone needs reauth');
|
||||
return {'error': 'needsReauth'};
|
||||
}
|
||||
@@ -730,14 +669,8 @@ class WatchSyncHelper {
|
||||
return {'success': false, 'error': 'no_student_id_norm'};
|
||||
}
|
||||
|
||||
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||
tokens: initData.tokens,
|
||||
client: initData.client,
|
||||
);
|
||||
final currentToken = _resolveCurrentToken(
|
||||
tokens: initData.tokens,
|
||||
client: initData.client,
|
||||
);
|
||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
||||
final currentToken = initData.client!.cache.token;
|
||||
|
||||
final watchExpiryDate = DateTime.fromMillisecondsSinceEpoch(watchExpiry);
|
||||
if (!_isAccessTokenUsable(watchExpiryDate, skew: const Duration())) {
|
||||
@@ -751,12 +684,8 @@ class WatchSyncHelper {
|
||||
final watchIdToken = tokenData['idToken'] as String?;
|
||||
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
||||
|
||||
final isForActiveAccount =
|
||||
expectedStudentIdNorm == null ||
|
||||
watchStudentIdNorm == expectedStudentIdNorm;
|
||||
if (isForActiveAccount &&
|
||||
currentToken != null &&
|
||||
currentToken.studentIdNorm == watchStudentIdNorm) {
|
||||
final isForActiveAccount = watchStudentIdNorm == expectedStudentIdNorm;
|
||||
if (isForActiveAccount && currentToken.key == watchStudentIdNorm) {
|
||||
if (!_isIncomingTokenNewerThanCurrent(
|
||||
incomingExpiry: watchExpiryDate,
|
||||
incomingIdToken: watchIdToken,
|
||||
@@ -792,10 +721,9 @@ class WatchSyncHelper {
|
||||
await initData.isar.tokenModels.put(newToken);
|
||||
});
|
||||
|
||||
initData.tokens = await initData.isar.tokenModels.where().findAll();
|
||||
if (isForActiveAccount) {
|
||||
initData.client.model = newToken;
|
||||
if (initDone) initData.reauthCubit?.clear();
|
||||
initData.client!.cache.token = newToken;
|
||||
if (initDone) initData.toastCubit.clear();
|
||||
} else {
|
||||
debugPrint(
|
||||
'[WatchSync] Stored token for inactive account ($watchStudentIdNorm), active is $expectedStudentIdNorm',
|
||||
@@ -821,13 +749,6 @@ class WatchSyncHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (token.accessToken == null ||
|
||||
token.refreshToken == null ||
|
||||
token.expiryDate == null) {
|
||||
debugPrint('[WatchSync] Token incomplete, not sending to Watch');
|
||||
return;
|
||||
}
|
||||
|
||||
final accessExpired = !_isAccessTokenUsable(
|
||||
token.expiryDate,
|
||||
skew: const Duration(),
|
||||
@@ -894,7 +815,6 @@ class WatchSyncHelper {
|
||||
}
|
||||
|
||||
final effectiveIsar = isar ?? (initDone ? initData.isar : null);
|
||||
final effectiveTokens = tokens ?? (initDone ? initData.tokens : null);
|
||||
final effectiveClient = client ?? (initDone ? initData.client : null);
|
||||
|
||||
if (effectiveIsar == null) {
|
||||
@@ -921,14 +841,10 @@ class WatchSyncHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||
tokens: effectiveTokens,
|
||||
client: effectiveClient,
|
||||
);
|
||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
||||
|
||||
final iCloudStudentIdNorm = tokenData['studentIdNorm'] as int?;
|
||||
if (expectedStudentIdNorm != null &&
|
||||
iCloudStudentIdNorm != expectedStudentIdNorm) {
|
||||
if (iCloudStudentIdNorm != expectedStudentIdNorm) {
|
||||
debugPrint(
|
||||
'[WatchSync] iCloud token belongs to different account ($iCloudStudentIdNorm), active is $expectedStudentIdNorm - ignoring',
|
||||
);
|
||||
@@ -959,21 +875,16 @@ class WatchSyncHelper {
|
||||
final iCloudIdToken = tokenData['idToken'] as String?;
|
||||
final iCloudRefreshToken = tokenData['refreshToken'] as String?;
|
||||
|
||||
final currentToken = _resolveCurrentToken(
|
||||
tokens: effectiveTokens,
|
||||
client: effectiveClient,
|
||||
final currentToken = initData.client!.cache.token;
|
||||
final localExpiry = currentToken.expiryDate;
|
||||
final shouldAccept = _isIncomingTokenNewerThanCurrent(
|
||||
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) {
|
||||
debugPrint(
|
||||
@@ -997,24 +908,14 @@ class WatchSyncHelper {
|
||||
await effectiveIsar.tokenModels.put(newToken);
|
||||
});
|
||||
|
||||
final updatedTokens = await effectiveIsar.tokenModels.where().findAll();
|
||||
|
||||
if (initDone) {
|
||||
initData.tokens = updatedTokens;
|
||||
}
|
||||
|
||||
if (effectiveClient != null &&
|
||||
(expectedStudentIdNorm == null ||
|
||||
newToken.studentIdNorm == expectedStudentIdNorm)) {
|
||||
effectiveClient.model = newToken;
|
||||
if (effectiveClient != null && newToken.key == expectedStudentIdNorm) {
|
||||
effectiveClient.cache.token = newToken;
|
||||
}
|
||||
|
||||
final shouldClearReauth =
|
||||
!iCloudAccessExpired &&
|
||||
(expectedStudentIdNorm == null ||
|
||||
newToken.studentIdNorm == expectedStudentIdNorm);
|
||||
!iCloudAccessExpired && newToken.key == expectedStudentIdNorm;
|
||||
if (shouldClearReauth) {
|
||||
if (initDone) initData.reauthCubit?.clear();
|
||||
if (initDone) initData.toastCubit.clear();
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
@@ -1040,13 +941,6 @@ class WatchSyncHelper {
|
||||
}) async {
|
||||
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();
|
||||
if (!watchInstalled) {
|
||||
debugPrint(
|
||||
@@ -1071,16 +965,7 @@ class WatchSyncHelper {
|
||||
List<TokenModel>? tokens,
|
||||
KretaClient? client,
|
||||
}) async {
|
||||
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;
|
||||
}
|
||||
if (!Platform.isIOS || !initDone) return;
|
||||
|
||||
try {
|
||||
debugPrint('[WatchSync] Requesting token from Watch...');
|
||||
@@ -1089,22 +974,12 @@ class WatchSyncHelper {
|
||||
null,
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
final expectedStudentIdNorm = _resolveExpectedStudentIdNorm(
|
||||
tokens: effectiveTokens,
|
||||
client: effectiveClient,
|
||||
);
|
||||
final currentToken = _resolveCurrentToken(
|
||||
tokens: effectiveTokens,
|
||||
client: effectiveClient,
|
||||
);
|
||||
final expectedStudentIdNorm = initData.client!.cache.token.key;
|
||||
final currentToken = initData.client!.cache.token;
|
||||
|
||||
if (result == null) {
|
||||
debugPrint('[WatchSync] No response from Watch');
|
||||
if (currentToken != null &&
|
||||
currentToken.accessToken != null &&
|
||||
currentToken.refreshToken != null &&
|
||||
currentToken.expiryDate != null &&
|
||||
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||
if (!initData.client!.needsReauth) {
|
||||
debugPrint('[WatchSync] Sending iPhone token to Watch (no response)');
|
||||
await _sendTokenToWatchInternal(
|
||||
currentToken,
|
||||
@@ -1117,11 +992,7 @@ class WatchSyncHelper {
|
||||
final tokenData = result as Map<dynamic, dynamic>;
|
||||
if (tokenData.containsKey('error')) {
|
||||
debugPrint('[WatchSync] Watch returned error: ${tokenData['error']}');
|
||||
if (currentToken != null &&
|
||||
currentToken.accessToken != null &&
|
||||
currentToken.refreshToken != null &&
|
||||
currentToken.expiryDate != null &&
|
||||
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||
if (!initData.client!.needsReauth) {
|
||||
debugPrint(
|
||||
'[WatchSync] Sending iPhone token to Watch (Watch has no token)',
|
||||
);
|
||||
@@ -1145,16 +1016,11 @@ class WatchSyncHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
if (expectedStudentIdNorm != null &&
|
||||
watchStudentIdNorm != expectedStudentIdNorm) {
|
||||
if (watchStudentIdNorm != expectedStudentIdNorm) {
|
||||
debugPrint(
|
||||
'[WatchSync] Watch token belongs to different account ($watchStudentIdNorm), active is $expectedStudentIdNorm - keeping active account',
|
||||
);
|
||||
if (currentToken != null &&
|
||||
currentToken.accessToken != null &&
|
||||
currentToken.refreshToken != null &&
|
||||
currentToken.expiryDate != null &&
|
||||
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||
if (!(initData.client!.needsReauth)) {
|
||||
await _sendTokenToWatchInternal(
|
||||
currentToken,
|
||||
allowExpiredAccessToken: true,
|
||||
@@ -1168,15 +1034,11 @@ class WatchSyncHelper {
|
||||
debugPrint(
|
||||
'[WatchSync] Watch provided expired token, ignoring and keeping iPhone token',
|
||||
);
|
||||
if (currentToken != null &&
|
||||
currentToken.accessToken != null &&
|
||||
currentToken.refreshToken != null &&
|
||||
currentToken.expiryDate != null &&
|
||||
_isAccessTokenUsable(
|
||||
if (_isAccessTokenUsable(
|
||||
currentToken.expiryDate,
|
||||
skew: const Duration(),
|
||||
) &&
|
||||
!(initData.reauthCubit?.state.needsReauth ?? false)) {
|
||||
!initData.client!.needsReauth) {
|
||||
await _sendTokenToWatchInternal(
|
||||
currentToken,
|
||||
allowExpiredAccessToken: true,
|
||||
@@ -1188,16 +1050,14 @@ class WatchSyncHelper {
|
||||
final watchUpdatedAtMs = _asInt(tokenData['updatedAtMs']);
|
||||
final watchIdToken = tokenData['idToken'] as String?;
|
||||
final watchRefreshToken = tokenData['refreshToken'] as String?;
|
||||
final shouldAccept = currentToken == null
|
||||
? true
|
||||
: _isIncomingTokenNewerThanCurrent(
|
||||
incomingExpiry: watchExpiryDate,
|
||||
incomingIdToken: watchIdToken,
|
||||
incomingRefreshToken: watchRefreshToken,
|
||||
incomingTokenVersion: watchTokenVersion,
|
||||
incomingUpdatedAtMs: watchUpdatedAtMs,
|
||||
currentToken: currentToken,
|
||||
);
|
||||
final shouldAccept = _isIncomingTokenNewerThanCurrent(
|
||||
incomingExpiry: watchExpiryDate,
|
||||
incomingIdToken: watchIdToken,
|
||||
incomingRefreshToken: watchRefreshToken,
|
||||
incomingTokenVersion: watchTokenVersion,
|
||||
incomingUpdatedAtMs: watchUpdatedAtMs,
|
||||
currentToken: currentToken,
|
||||
);
|
||||
if (shouldAccept) {
|
||||
debugPrint('[WatchSync] Watch has newer token, updating iPhone');
|
||||
final newToken = TokenModel.fromValues(
|
||||
@@ -1213,25 +1073,14 @@ class WatchSyncHelper {
|
||||
watchUpdatedAtMs ?? DateTime.now().millisecondsSinceEpoch,
|
||||
);
|
||||
|
||||
await effectiveIsar.writeTxn(() async {
|
||||
await effectiveIsar.tokenModels.put(newToken);
|
||||
await isarInit.writeTxn(() async {
|
||||
await isarInit.tokenModels.put(newToken);
|
||||
});
|
||||
|
||||
final updatedTokens = await effectiveIsar.tokenModels.where().findAll();
|
||||
initData.client!.cache.token = newToken;
|
||||
|
||||
if (initDone) {
|
||||
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();
|
||||
if (newToken.key == expectedStudentIdNorm) {
|
||||
if (initDone) initData.toastCubit.clear();
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka_common/data/database.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
|
||||
import 'package:firka/api/client/kreta_client.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_common/data/models/token_model.dart';
|
||||
import 'package:firka/services/wear_sync_cache.dart';
|
||||
|
||||
/// Background isolate entrypoint for Wear sync (Android).
|
||||
@@ -29,30 +25,12 @@ void wearSyncBackgroundEntrypoint() {
|
||||
final appDirPath = args?['appDirPath'] as String?;
|
||||
if (cachePath == null || appDirPath == null) return null;
|
||||
try {
|
||||
final isar = await Isar.open([
|
||||
TokenModelSchema,
|
||||
GenericCacheModelSchema,
|
||||
TimetableCacheModelSchema,
|
||||
HomeworkCacheModelSchema,
|
||||
AppSettingsModelSchema,
|
||||
HomeworkDoneModelSchema,
|
||||
], directory: appDirPath);
|
||||
final tokens = await isar.tokenModels.where().findAll();
|
||||
await isar.close();
|
||||
await initDB();
|
||||
final tokens = await isarInit.tokenModels.where().findAll();
|
||||
if (tokens.isEmpty) return null;
|
||||
final token = tokens.first;
|
||||
final isar2 = await Isar.open([
|
||||
TokenModelSchema,
|
||||
GenericCacheModelSchema,
|
||||
TimetableCacheModelSchema,
|
||||
HomeworkCacheModelSchema,
|
||||
AppSettingsModelSchema,
|
||||
HomeworkDoneModelSchema,
|
||||
], directory: appDirPath);
|
||||
final reauthCubit = ReauthCubit();
|
||||
final client = KretaClient(token, isar2, reauthCubit);
|
||||
final client = KretaClient(token);
|
||||
final payload = await buildWearSyncPayload(client);
|
||||
await isar2.close();
|
||||
if (payload == null) return null;
|
||||
await writeWearSyncCache(cachePath, payload);
|
||||
final wc = WatchConnectivity();
|
||||
|
||||
@@ -28,25 +28,11 @@ const String wearSyncCacheFileName = 'wear_sync_cache.json';
|
||||
/// Builds the sync payload (same shape as init_data / sync_data): timetable (2 weeks), grades, lastSyncAt.
|
||||
Future<Map<String, dynamic>?> buildWearSyncPayload(KretaClient client) async {
|
||||
final (start, end) = getWearSyncTimetableRange();
|
||||
final timetableResp = await client.getTimeTable(
|
||||
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;
|
||||
}
|
||||
await client.getLessons(start, end);
|
||||
await client.getGrades();
|
||||
final now = timeNow();
|
||||
final timetable = (timetableResp.response ?? <Lesson>[])
|
||||
.map((l) => l.toJson())
|
||||
.toList();
|
||||
final grades = (gradesResp.response ?? <Grade>[])
|
||||
.map((g) => g.toJson())
|
||||
.toList();
|
||||
final timetable = (<Lesson>[]).map((l) => l.toJson()).toList();
|
||||
final grades = (<Grade>[]).map((g) => g.toJson()).toList();
|
||||
return {
|
||||
'lastSyncAt': now.toUtc().toIso8601String(),
|
||||
'timetable': timetable,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
export 'package:firka_common/ui/components/firka_card.dart';
|
||||
@@ -1 +0,0 @@
|
||||
export 'package:firka_common/ui/components/firka_shadow.dart';
|
||||
@@ -1 +0,0 @@
|
||||
export 'package:firka_common/ui/components/grade.dart';
|
||||
@@ -1 +0,0 @@
|
||||
export 'package:firka_common/ui/components/grade_helpers.dart';
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:firka/core/image_preloader.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/core/swear_generator.dart';
|
||||
|
||||
class ErrorPage extends StatelessWidget {
|
||||
final String exception;
|
||||
|
||||
const ErrorPage({super.key, required this.exception});
|
||||
|
||||
@override
|
||||
@@ -51,7 +52,6 @@ class ErrorPage extends StatelessWidget {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
//'a,',
|
||||
generateSwearSentence(),
|
||||
style: appStyle.fonts.H_H2.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
@@ -86,14 +86,21 @@ class ErrorPage extends StatelessWidget {
|
||||
color: appStyle.colors.card,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
exception,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
fontFamily: 'RobotoMono',
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
exception,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
fontFamily: 'RobotoMono',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: _CopyButton(exception: exception),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 16,
|
||||
@@ -160,3 +167,34 @@ class ErrorPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CopyButton extends StatefulWidget {
|
||||
final String exception;
|
||||
const _CopyButton({required this.exception});
|
||||
|
||||
@override
|
||||
State<_CopyButton> createState() => _CopyButtonState();
|
||||
}
|
||||
|
||||
class _CopyButtonState extends State<_CopyButton> {
|
||||
final _tooltipKey = GlobalKey<TooltipState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
key: _tooltipKey,
|
||||
message: initData.l10n.copied,
|
||||
triggerMode: TooltipTriggerMode.manual,
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.copy, size: 18),
|
||||
color: appStyle.colors.textSecondary,
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(ClipboardData(text: widget.exception));
|
||||
_tooltipKey.currentState?.ensureTooltipVisible();
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
_tooltipKey.currentState?.deactivate();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import 'package:majesticons_flutter/majesticons_flutter.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/data/models/app_settings_model.dart';
|
||||
import 'package:firka/ui/components/firka_shadow.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka_common/ui/components/firka_shadow.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -122,9 +123,9 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
||||
context.pop();
|
||||
context.push(
|
||||
'/settings',
|
||||
extra: data.settings.items.group(
|
||||
"profile_settings",
|
||||
),
|
||||
extra: buildProfileSettingsTree(
|
||||
data.l10n,
|
||||
).children,
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
@@ -252,24 +253,9 @@ void showExtrasBottomSheet(BuildContext context, AppInitialization data) {
|
||||
if (debugCounter == 10) {
|
||||
final navigator = Navigator.of(context);
|
||||
final router = GoRouter.of(context);
|
||||
data.settings
|
||||
.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();
|
||||
await Settings.developerOptsEnabled.set(
|
||||
!Settings.developerOptsEnabled.value,
|
||||
);
|
||||
|
||||
navigator.pop();
|
||||
router.go('/home');
|
||||
|
||||
149
firka/lib/ui/phone/pages/extras/firka_toast.dart
Normal file
149
firka/lib/ui/phone/pages/extras/firka_toast.dart
Normal file
@@ -0,0 +1,149 @@
|
||||
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,
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/phone/widgets/login_webview.dart';
|
||||
@@ -9,18 +8,6 @@ void showReauthBottomSheet(
|
||||
AppInitialization data,
|
||||
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(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
@@ -54,8 +41,8 @@ void showReauthBottomSheet(
|
||||
Expanded(
|
||||
child: LoginWebviewWidget(
|
||||
data,
|
||||
username: username,
|
||||
schoolId: schoolId,
|
||||
username: data.client!.cache.token.username,
|
||||
schoolId: data.client!.cache.token.iss,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:firka/services/wear_sync_cache.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
void showWearBottomSheet(
|
||||
@@ -12,7 +12,7 @@ void showWearBottomSheet(
|
||||
AppInitialization data,
|
||||
String model,
|
||||
) async {
|
||||
final payload = await buildWearSyncPayload(data.client);
|
||||
final payload = await buildWearSyncPayload(data.client!);
|
||||
if (payload == null) return;
|
||||
if (!context.mounted) return;
|
||||
|
||||
@@ -66,17 +66,17 @@ class _WearPairSheetContentState extends State<_WearPairSheetContent> {
|
||||
|
||||
void _onPairTap() {
|
||||
setState(() => _syncing = true);
|
||||
final m = widget.data.client.model;
|
||||
final m = widget.data.client!.cache.token;
|
||||
WatchSyncHelper.sendMessageToWatch({
|
||||
'id': 'init_data',
|
||||
'auth': {
|
||||
'studentId': m.studentId,
|
||||
'studentIdNorm': m.studentIdNorm,
|
||||
'studentId': m.username,
|
||||
'studentIdNorm': m.key,
|
||||
'iss': m.iss,
|
||||
'idToken': m.idToken,
|
||||
'accessToken': m.accessToken,
|
||||
'refreshToken': m.refreshToken,
|
||||
'expiryDate': m.expiryDate!.millisecondsSinceEpoch,
|
||||
'expiryDate': m.expiryDate.millisecondsSinceEpoch,
|
||||
},
|
||||
'lastSyncAt': widget.payload['lastSyncAt'],
|
||||
'timetable': widget.payload['timetable'],
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
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,7 +1,8 @@
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/average_helper.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/core/grade_helper.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';
|
||||
@@ -9,14 +10,10 @@ import 'package:flutter/material.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/app/app_state.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/shared/delayed_spinner.dart';
|
||||
|
||||
class HomeGradesScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
@@ -27,330 +24,162 @@ class HomeGradesScreen extends StatefulWidget {
|
||||
State<StatefulWidget> createState() => _HomeGradesScreen();
|
||||
}
|
||||
|
||||
String activeSubjectUid = "";
|
||||
String subjectName = "";
|
||||
String subjectId = "";
|
||||
String subjectCategory = "";
|
||||
List<Subject> subjectInfo = [];
|
||||
|
||||
class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
ApiResponse<List<Grade>>? grades;
|
||||
ApiResponse<List<Lesson>>? week;
|
||||
ApiResponse<List<ClassGroup>>? classGroups;
|
||||
ApiResponse<List<SubjectAverage>>? lessons;
|
||||
|
||||
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,
|
||||
);
|
||||
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);
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
}
|
||||
if (mounted) setState(() {});
|
||||
})();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||
listenWhen: (previous, current) =>
|
||||
current.refreshTrigger != previous.refreshTrigger,
|
||||
listener: (context, state) {
|
||||
_onRefreshRequested(context);
|
||||
setState(() {});
|
||||
},
|
||||
child: _buildContent(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
if (grades == null || week == null) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height / 1.35,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [SizedBox(), DelayedSpinnerWidget(), SizedBox()],
|
||||
final allGrades = widget.data.client!.cache.getGrades().findAllSync();
|
||||
|
||||
final subjectAverage = allGrades.getSubjectAverage();
|
||||
final roundedSubjectAverage = allGrades.getRoundedSubjectAverage();
|
||||
final classAverages = widget.data.client!.cache
|
||||
.getClassAverages()
|
||||
.findAllSync();
|
||||
|
||||
double? classAverage = classAverages.isNotEmpty
|
||||
? 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 {
|
||||
var subjectAvg = 0.00;
|
||||
var subjectCount = 0;
|
||||
var subjectAvgRounded = 0.00;
|
||||
final summaryAvg2 = calculateAverage(grades!.response!);
|
||||
final List<Subject> subjects = List<Subject>.empty(growable: true);
|
||||
final List<Widget> gradeCards = [];
|
||||
}
|
||||
|
||||
for (var grade in grades!.response!) {
|
||||
if (subjects.where((s) => s.uid == grade.subject.uid).isEmpty) {
|
||||
subjects.add(grade.subject);
|
||||
}
|
||||
}
|
||||
|
||||
if (lessons != null && lessons!.response != null) {
|
||||
for (var lesson in lessons!.response!) {
|
||||
if (subjects.where((s) => s.uid == lesson.uid).isEmpty) {
|
||||
subjects.add(
|
||||
Subject(
|
||||
uid: lesson.uid,
|
||||
name: lesson.name,
|
||||
category: NameUidDesc(
|
||||
uid: lesson.subjectCategoryId,
|
||||
name: lesson.subjectCategoryName,
|
||||
description: lesson.subjectCategoryDescription,
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.data.l10n.subjects,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
sortIndex: lesson.sortIndex,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subjects.sort((s1, s2) => s1.name.compareTo(s2.name));
|
||||
|
||||
for (var subject in subjects) {
|
||||
final subjectGrades = grades!.response!
|
||||
.where((g) => g.subject.uid == subject.uid)
|
||||
.toList();
|
||||
|
||||
double avg = double.nan;
|
||||
if (subjectGrades.isNotEmpty) {
|
||||
avg = grades!.response!.getAverageBySubject(subject);
|
||||
}
|
||||
|
||||
if (avg.isNaN) {
|
||||
gradeCards.add(
|
||||
GestureDetector(
|
||||
child: GradeSmallCard(grades!.response!, subject),
|
||||
onTap: () {
|
||||
activeSubjectUid = subject.uid;
|
||||
subjectName = subject.name;
|
||||
subjectId = subject.uid;
|
||||
subjectCategory = subject.category.name!;
|
||||
subjectInfo = subjects
|
||||
.where((s) => s.uid == subject.uid)
|
||||
.toList();
|
||||
context.go('/grades/subject/${subject.uid}');
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
gradeCards.add(
|
||||
GestureDetector(
|
||||
child: GradeSmallCard(grades!.response!, subject),
|
||||
onTap: () {
|
||||
activeSubjectUid = subject.uid;
|
||||
subjectName = subject.name;
|
||||
subjectId = subject.uid;
|
||||
subjectCategory = subject.category.name!;
|
||||
subjectInfo = subjects
|
||||
.where((s) => s.uid == subject.uid)
|
||||
.toList();
|
||||
context.go('/grades/subject/${subject.uid}');
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!avg.isNaN) {
|
||||
subjectCount++;
|
||||
subjectAvg += avg;
|
||||
final rounding = widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("application")
|
||||
.subGroup("rounding");
|
||||
subjectAvgRounded += roundGrade(
|
||||
avg,
|
||||
t1: rounding.dbl("1"),
|
||||
t2: rounding.dbl("2"),
|
||||
t3: rounding.dbl("3"),
|
||||
t4: rounding.dbl("4"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
subjectAvg /= subjectCount;
|
||||
subjectAvgRounded /= subjectCount;
|
||||
|
||||
if (subjectCount == 0) {
|
||||
subjectAvg = 0.00;
|
||||
subjectAvgRounded = 0.00;
|
||||
}
|
||||
|
||||
final rounding = widget.data.settings
|
||||
.group("settings")
|
||||
.subGroup("application")
|
||||
.subGroup("rounding");
|
||||
var subjectAvgColor = getGradeColor(
|
||||
subjectAvg,
|
||||
t1: rounding.dbl("1"),
|
||||
t2: rounding.dbl("2"),
|
||||
t3: rounding.dbl("3"),
|
||||
t4: rounding.dbl("4"),
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
GradeChartWithInteraction(grades: allGrades),
|
||||
SizedBox(height: 10),
|
||||
GradeSummaryBar(grades: allGrades, l10n: widget.data.l10n),
|
||||
SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(
|
||||
widget.data.l10n.subjects,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
widget.data.l10n.your_subjects,
|
||||
style: appStyle.fonts.H_14px.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
GradeChartWithInteraction(grades: grades?.response ?? []),
|
||||
SizedBox(height: 2),
|
||||
GradeSummaryBar(
|
||||
grades: grades?.response ?? [],
|
||||
l10n: widget.data.l10n,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(
|
||||
widget.data.l10n.your_subjects,
|
||||
style: appStyle.fonts.H_14px.apply(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
...gradeCards,
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
widget.data.l10n.data,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
],
|
||||
right: [
|
||||
if (subjectAverage != null)
|
||||
Container(
|
||||
width: 48,
|
||||
height: 26,
|
||||
decoration: ShapeDecoration(
|
||||
color: getGradeColor(subjectAverage).withAlpha(38),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
widget.data.l10n.subject_avg,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: subjectAvgColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
],
|
||||
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(
|
||||
subjectAvg.toStringAsFixed(2),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: subjectAvgColor,
|
||||
roundedSubjectAverage.toStringAsFixed(2),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: getGradeColor(roundedSubjectAverage),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
widget.data.l10n.subject_avg_rounded,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: subjectAvgColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
),
|
||||
child: Text(
|
||||
subjectAvgRounded.toStringAsFixed(2),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: subjectAvgColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
"Összesített átlag",
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: subjectAvgColor.withAlpha(38),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 8,
|
||||
right: 8,
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
),
|
||||
child: Text(
|
||||
summaryAvg2.toStringAsFixed(2),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: subjectAvgColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
if (classAverage != null)
|
||||
FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
@@ -360,37 +189,60 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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,
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),*/
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||
import 'package:kreta_api/kreta_api.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/core/extensions.dart';
|
||||
import 'package:firka/ui/components/common_bottom_sheets.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/shared/class_icon.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
@@ -12,6 +13,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
@@ -20,76 +22,56 @@ import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class HomeGradesSubjectScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
final SubjectCacheModel subject;
|
||||
final String teacherName;
|
||||
final Iterable<GradeCacheModel> grades;
|
||||
|
||||
const HomeGradesSubjectScreen(this.data, {super.key});
|
||||
factory HomeGradesSubjectScreen.subject(SubjectCacheModel subject) {
|
||||
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
|
||||
State<StatefulWidget> createState() => _HomeGradesSubjectScreen();
|
||||
}
|
||||
|
||||
class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||
Iterable<Grade>? grades;
|
||||
final List<(int grade, int weight)> _ghostEntries = [];
|
||||
|
||||
void _onRefreshRequested(BuildContext context) async {
|
||||
final cubit = context.read<HomeRefreshCubit>();
|
||||
grades = (await widget.data.client.getGrades(forceCache: false)).response!
|
||||
.where((grade) => grade.subject.uid == activeSubjectUid)
|
||||
.where((grade) => grade.type.name != "felevi_jegy_ertekeles");
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
cubit.onRefreshComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
(() async {
|
||||
grades = (await widget.data.client.getGrades()).response!
|
||||
.where((grade) => grade.subject.uid == activeSubjectUid)
|
||||
.where((grade) => grade.type.name != "felevi_jegy_ertekeles");
|
||||
|
||||
if (mounted) setState(() {});
|
||||
})();
|
||||
}
|
||||
|
||||
List<Grade> _gradesWithGhosts(Subject subject) {
|
||||
final real = grades?.toList() ?? [];
|
||||
List<GradeCacheModel> _gradesWithGhosts() {
|
||||
final real = widget.grades.toList();
|
||||
if (_ghostEntries.isEmpty) return real;
|
||||
final baseDate = real.isEmpty
|
||||
? DateTime.now()
|
||||
: 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>[];
|
||||
: real.map((g) => g.createdAt).reduce((a, b) => a.isAfter(b) ? a : b);
|
||||
for (var i = 0; i < _ghostEntries.length; i++) {
|
||||
final e = _ghostEntries[i];
|
||||
ghostGrades.add(
|
||||
Grade(
|
||||
uid: 'ghost-$i-${e.$1}-${e.$2}',
|
||||
recordDate: baseDate.add(Duration(seconds: i)),
|
||||
creationDate: baseDate.add(Duration(seconds: i)),
|
||||
subject: subject,
|
||||
type: osztalyzat,
|
||||
valueType: osztalyzat,
|
||||
teacher: '',
|
||||
strValue: '${e.$1}',
|
||||
sortIndex: 0,
|
||||
numericValue: e.$1,
|
||||
weightPercentage: e.$2,
|
||||
),
|
||||
real.add(
|
||||
GradeCacheModel()
|
||||
..type = "Ertekeles"
|
||||
..valueType = "Osztalyzat"
|
||||
..writtenAt = baseDate.add(Duration(seconds: i))
|
||||
..numericValue = e.$1
|
||||
..weightPercentage = e.$2
|
||||
..textValue = e.$1.toString()
|
||||
..teacherName = widget
|
||||
.teacherName // TODO: teacher name
|
||||
..subject.value = widget.subject,
|
||||
);
|
||||
}
|
||||
return [...real, ...ghostGrades];
|
||||
return real;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -98,355 +80,269 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||
listenWhen: (previous, current) =>
|
||||
current.refreshTrigger != previous.refreshTrigger,
|
||||
listener: (context, state) {
|
||||
_onRefreshRequested(context);
|
||||
setState(() => {});
|
||||
},
|
||||
child: _buildContent(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
if (grades != null && grades!.isNotEmpty && activeSubjectUid != "") {
|
||||
var aGrade = grades!.first;
|
||||
var groups = grades!.groupList((grade) => grade.recordDate);
|
||||
|
||||
final ghostGradeWidgets = _ghostEntries.reversed.map((e) {
|
||||
return GestureDetector(
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
Row(
|
||||
children: [
|
||||
GradeWidget.gradeValue(e.$1),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'${widget.data.l10n.ghost_grade} ${e.$2}%',
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
if (widget.grades.isEmpty) {
|
||||
return Container(
|
||||
color: appStyle.colors.background,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 1),
|
||||
child: Text(
|
||||
initData.l10n.subjects,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {},
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var gradeWidgets = List<Widget>.empty(growable: true);
|
||||
if (ghostGradeWidgets.isNotEmpty) {
|
||||
gradeWidgets.add(
|
||||
Text(
|
||||
widget.data.l10n.ghost_grades,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
gradeWidgets.addAll(ghostGradeWidgets);
|
||||
}
|
||||
|
||||
for (var group in groups.entries) {
|
||||
gradeWidgets.add(SizedBox(height: 8));
|
||||
gradeWidgets.add(
|
||||
Text(
|
||||
group.key.format(widget.data.l10n, FormatMode.grades),
|
||||
style: appStyle.fonts.H_14px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
);
|
||||
gradeWidgets.add(SizedBox(height: 8));
|
||||
for (var grade in group.value) {
|
||||
gradeWidgets.add(
|
||||
GestureDetector(
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
Row(
|
||||
children: [
|
||||
GradeWidget(grade),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.45,
|
||||
child: Text(
|
||||
(grade.topic ?? grade.type.description!)
|
||||
.firstUpper(),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
grade.mode?.description != null
|
||||
? SizedBox(
|
||||
width:
|
||||
MediaQuery.of(context).size.width / 1.45,
|
||||
child: Text(
|
||||
grade.mode!.description!.firstUpper(),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showGradeBottomSheet(context, widget.data, grade);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Material(
|
||||
color: appStyle.colors.background,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 12),
|
||||
Column(
|
||||
SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: Text(
|
||||
widget.data.l10n.subjects,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Card(
|
||||
shadowColor: const Color.fromRGBO(0, 0, 0, 0),
|
||||
color: appStyle.colors.a15p,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(6),
|
||||
child: ClassIconWidget(
|
||||
subject: widget.subject,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
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: () {
|
||||
showSubjectBottomSheetSettings(
|
||||
context,
|
||||
widget.data,
|
||||
aGrade.subject,
|
||||
onAddFromCalculator: (g, w) {
|
||||
setState(() => _ghostEntries.add((g, w)));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Card(
|
||||
shadowColor: const Color.fromRGBO(0, 0, 0, 0),
|
||||
color: appStyle.colors.a15p,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(6),
|
||||
child: ClassIconWidget(
|
||||
uid: aGrade.subject.uid,
|
||||
className: aGrade.subject.name,
|
||||
category: aGrade.subject.category.name!,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
aGrade.subject.name,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
aGrade.teacher,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
],
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
widget.subject.name,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
GradeChartWithInteraction(
|
||||
grades: _gradesWithGhosts(aGrade.subject),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
initData.l10n.unknown_teacher,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
GradeSummaryBar(
|
||||
grades: _gradesWithGhosts(aGrade.subject),
|
||||
l10n: widget.data.l10n,
|
||||
showAverage: ghostGradeWidgets.isNotEmpty,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 4),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: gradeWidgets,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/images/logos/dave.svg",
|
||||
width: 48,
|
||||
height: 48,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
initData.l10n.no_grades,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Material(
|
||||
color: appStyle.colors.background,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 1),
|
||||
child: Text(
|
||||
widget.data.l10n.subjects,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height:
|
||||
MediaQuery.of(context).size.height -
|
||||
MediaQuery.of(context).padding.top -
|
||||
230,
|
||||
child: ListView(
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Card(
|
||||
shadowColor: const Color.fromRGBO(0, 0, 0, 0),
|
||||
color: appStyle.colors.a15p,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(6),
|
||||
child: ClassIconWidget(
|
||||
uid: subjectId,
|
||||
className: subjectName,
|
||||
category: subjectCategory,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
subjectName,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
widget.data.l10n.unknown_teacher,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height:
|
||||
MediaQuery.of(context).size.height -
|
||||
MediaQuery.of(context).padding.top -
|
||||
320,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/images/logos/dave.svg",
|
||||
width: 48,
|
||||
height: 48,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
widget.data.l10n.no_grades,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final ghostGradeWidgets = _ghostEntries.indexed
|
||||
.map((e) {
|
||||
return InfoCard.gradeGhost(
|
||||
e.$2.$1,
|
||||
e.$2.$2,
|
||||
onTap: (ctx) {
|
||||
setState(() {
|
||||
_ghostEntries.removeAt(e.$1);
|
||||
});
|
||||
},
|
||||
);
|
||||
})
|
||||
.toList()
|
||||
.reversed;
|
||||
|
||||
return Container(
|
||||
color: appStyle.colors.background,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: Text(
|
||||
initData.l10n.subjects,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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: () {
|
||||
showSubjectBottomSheetSettings(
|
||||
context,
|
||||
initData,
|
||||
widget.subject,
|
||||
onAddFromCalculator: (g, w) {
|
||||
setState(() => _ghostEntries.add((g, w)));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
FilledCircle(
|
||||
diameter: 36,
|
||||
color: appStyle.colors.a15p,
|
||||
child: ClassIconWidget(
|
||||
subject: widget.subject,
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
widget.subject.name,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
widget.teacherName,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
GradeChartWithInteraction(grades: _gradesWithGhosts()),
|
||||
SizedBox(height: 10),
|
||||
GradeSummaryBar(
|
||||
grades: _gradesWithGhosts(),
|
||||
l10n: initData.l10n,
|
||||
showAverage: ghostGradeWidgets.isNotEmpty,
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 20,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 10,
|
||||
children: [
|
||||
if (ghostGradeWidgets.isNotEmpty)
|
||||
Text(
|
||||
initData.l10n.ghost_grades,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
...ghostGradeWidgets,
|
||||
],
|
||||
),
|
||||
...widget.grades
|
||||
.groupList((e) => e.writtenAt)
|
||||
.entries
|
||||
.map(
|
||||
(e) => Column(
|
||||
spacing: 10,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
e.key.format(initData.l10n, FormatMode.main),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
...e.value.map((v) => InfoCard.gradeDesc(v)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:firka/api/client/kreta_stream.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||
import 'package:firka/ui/phone/widgets/lesson_slider.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||
import 'package:firka/ui/phone/widgets/home_main_starting_soon.dart';
|
||||
import 'package:firka/ui/phone/widgets/homework.dart';
|
||||
import 'package:firka/ui/phone/widgets/info_board_item.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_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/ui/components/grade.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import '../../widgets/home_main_welcome.dart';
|
||||
import '../../widgets/lesson_big.dart';
|
||||
|
||||
class HomeMainScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
@@ -37,163 +28,14 @@ class HomeMainScreen extends StatefulWidget {
|
||||
class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
_HomeMainScreen();
|
||||
|
||||
DateTime now = timeNow();
|
||||
List<Lesson>? lessons;
|
||||
List<NoticeBoardItem>? noticeBoard;
|
||||
List<InfoBoardItem>? infoBoard;
|
||||
List<Test>? tests;
|
||||
List<Grade>? grades;
|
||||
List<Homework>? homework;
|
||||
Student? student;
|
||||
Timer? timer;
|
||||
|
||||
void _onRefreshRequested(BuildContext context) async {
|
||||
final cubit = context.read<HomeRefreshCubit>();
|
||||
await fetchData(cacheOnly: false);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
cubit.onRefreshComplete();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchData({bool cacheOnly = false}) async {
|
||||
final midnight = now.getMidnight();
|
||||
|
||||
var lessonsFetched = 0;
|
||||
var noticeBoardFetched = 0;
|
||||
var infoBoardFetched = 0;
|
||||
var studentFetched = 0;
|
||||
var testsFetched = 0;
|
||||
var gradesFetched = 0;
|
||||
var homeworkFetched = 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.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) {
|
||||
if (DateTime.now().difference(startTime) > maxWaitTime) {
|
||||
debugPrint('[HomeMain] Data fetch timed out after 30s');
|
||||
break;
|
||||
}
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
now = timeNow();
|
||||
if (!mounted) return;
|
||||
|
||||
(() async {
|
||||
await fetchData();
|
||||
})();
|
||||
|
||||
timer = Timer.periodic(Duration(seconds: 1), (timer) async {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
now = timeNow();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
timer?.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||
@@ -207,208 +49,104 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
Widget welcomeWidget = SizedBox();
|
||||
Widget nextClass = SizedBox();
|
||||
Widget? nextTest;
|
||||
bool lessonActive = false;
|
||||
final now = timeNow();
|
||||
final infoItems = widget.data.client!.cache.getMessages().findAllSync();
|
||||
final gradeItems = widget.data.client!.cache.getGrades().findAllSync();
|
||||
final testItems = widget.data.client!.cache.getTests().findAllSync();
|
||||
final homeworkItems = widget.data.client!.cache
|
||||
.getHomeworks()
|
||||
.findAllSync();
|
||||
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();
|
||||
|
||||
if (lessons != null && lessons!.isNotEmpty) {
|
||||
if (now.isBefore(lessons!.first.start)) {
|
||||
welcomeWidget = StartingSoonWidget(widget.data.l10n, now, lessons!);
|
||||
} else {
|
||||
var currentLesson = lessons!.firstWhereOrNull(
|
||||
(lesson) => now.isAfter(lesson.start) && now.isBefore(lesson.end),
|
||||
);
|
||||
var prevLesson = lessons!.getPrevLesson(now);
|
||||
var nextLesson = lessons!.getNextLesson(now);
|
||||
int? lessonIndex;
|
||||
|
||||
if (currentLesson != null) {
|
||||
lessonIndex = lessons!.getLessonNo(currentLesson);
|
||||
lessonActive = true;
|
||||
}
|
||||
|
||||
welcomeWidget = LessonBigWidget(
|
||||
widget.data.l10n,
|
||||
now,
|
||||
lessonIndex,
|
||||
currentLesson,
|
||||
prevLesson,
|
||||
nextLesson,
|
||||
lessons!,
|
||||
tests ?? [],
|
||||
);
|
||||
}
|
||||
}
|
||||
if (lessons != null && lessons!.isNotEmpty) {
|
||||
var nextLesson = lessons!.getNextLesson(now);
|
||||
if (nextLesson != null) {
|
||||
nextClass = LessonSmallWidget(
|
||||
widget.data.l10n,
|
||||
nextLesson,
|
||||
lessonActive,
|
||||
);
|
||||
|
||||
if (tests != null) {
|
||||
final testsOnDate = tests!
|
||||
.where(
|
||||
(test) =>
|
||||
test.date.isAfter(
|
||||
nextLesson.start.getMidnight().subtract(
|
||||
Duration(seconds: 1),
|
||||
),
|
||||
) &&
|
||||
test.date.isBefore(
|
||||
nextLesson.end.getMidnight().add(
|
||||
Duration(hours: 23, minutes: 59),
|
||||
),
|
||||
) &&
|
||||
test.subject.uid == nextLesson.subject?.uid,
|
||||
)
|
||||
.toList();
|
||||
|
||||
if (testsOnDate.isNotEmpty) {
|
||||
final test = testsOnDate.first;
|
||||
|
||||
nextTest = FirkaCard(
|
||||
left: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Solid,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
test.theme,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
test.method.description ?? "N/A",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final item in infoItems) {
|
||||
noticeBoardWidgets.add((InfoCard.messageItem(item), item.createdAt));
|
||||
}
|
||||
|
||||
if (student != null && lessons != null) {
|
||||
final infoItems = infoBoard ?? [];
|
||||
final gradeItems = grades ?? [];
|
||||
final homeworkItems = homework ?? [];
|
||||
final noticeBoardWidgets = <(Widget, DateTime)>[];
|
||||
for (final test in testItems) {
|
||||
noticeBoardWidgets.add((InfoCard.test(test), test.createdAt));
|
||||
}
|
||||
|
||||
for (final item in infoItems) {
|
||||
noticeBoardWidgets.add((
|
||||
GestureDetector(
|
||||
child: InfoBoardItemWidget(item),
|
||||
onTap: () {
|
||||
context.push('/message', extra: item);
|
||||
},
|
||||
),
|
||||
item.date,
|
||||
));
|
||||
}
|
||||
for (final grade in gradeItems) {
|
||||
noticeBoardWidgets.add((InfoCard.gradeSubj(grade), grade.createdAt));
|
||||
}
|
||||
|
||||
for (final grade in gradeItems) {
|
||||
noticeBoardWidgets.add((
|
||||
GestureDetector(
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
Row(
|
||||
children: [
|
||||
GradeWidget(grade),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.45,
|
||||
child: Text(
|
||||
(grade.topic ?? grade.type.description!)
|
||||
.firstUpper(),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
grade.mode?.description != null
|
||||
? SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.45,
|
||||
child: Text(
|
||||
grade.mode!.description!.firstUpper(),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showGradeBottomSheet(context, widget.data, grade);
|
||||
},
|
||||
),
|
||||
grade.recordDate,
|
||||
));
|
||||
}
|
||||
for (final entry in homeworkItems) {
|
||||
noticeBoardWidgets.add((InfoCard.homework(entry), entry.createdAt));
|
||||
}
|
||||
|
||||
for (final entry in homeworkItems) {
|
||||
noticeBoardWidgets.add((
|
||||
HomeworkWidget(widget.data, entry),
|
||||
entry.creationDate,
|
||||
));
|
||||
}
|
||||
for (final entry in omissionItems.entries) {
|
||||
noticeBoardWidgets.add((InfoCard.omission(entry.value), entry.key));
|
||||
}
|
||||
|
||||
noticeBoardWidgets.sort(
|
||||
(item1, item2) => item2.$2.difference(item1.$2).inMilliseconds,
|
||||
);
|
||||
noticeBoardWidgets.sort(
|
||||
(item1, item2) => item2.$2.difference(item1.$2).inMilliseconds,
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, top: 24.0, right: 20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
WelcomeWidget(widget.data.l10n, now, student!, lessons!),
|
||||
SizedBox(height: 48),
|
||||
welcomeWidget,
|
||||
lessonActive ? SizedBox(height: 5) : SizedBox(height: 0),
|
||||
nextClass,
|
||||
nextTest != null ? SizedBox(height: 12) : SizedBox(height: 0),
|
||||
nextTest ?? SizedBox(),
|
||||
nextTest != null ? SizedBox(height: 12) : SizedBox(height: 0),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: noticeBoardWidgets.map((e) => e.$1).toList(),
|
||||
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)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
backgroundColor: appStyle.colors.background,
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
)
|
||||
.length;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => Future.value(),
|
||||
notificationPredicate: (ScrollNotification notification) {
|
||||
return notification.depth == 0;
|
||||
},
|
||||
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
||||
displacement: 0,
|
||||
child: ListView(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [DelayedSpinnerWidget()],
|
||||
SizedBox(height: 24),
|
||||
WelcomeWidget(
|
||||
widget.data.l10n,
|
||||
now,
|
||||
widget.data.client!.cache.findStudent(),
|
||||
todayLesson,
|
||||
),
|
||||
SizedBox(height: 48),
|
||||
LessonSlider(todayLesson, testsTomorrow),
|
||||
SizedBox(height: 24),
|
||||
...noticeBoardWidgets
|
||||
.groupList((e) => e.$2)
|
||||
.entries
|
||||
.map(
|
||||
(e) => Column(
|
||||
spacing: 10,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
e.key.format(widget.data.l10n, FormatMode.main),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
...e.value.map((v) => v.$1),
|
||||
SizedBox(height: 10),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
300
firka/lib/ui/phone/pages/home/home_omissions.dart
Normal file
300
firka/lib/ui/phone/pages/home/home_omissions.dart
Normal file
@@ -0,0 +1,300 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||
import 'package:firka/ui/phone/widgets/omission_bar.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/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:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
class HomeOmissionsScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
|
||||
const HomeOmissionsScreen(this.data, {super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomeOmissionsScreen();
|
||||
}
|
||||
|
||||
class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||
listenWhen: (previous, current) =>
|
||||
current.refreshTrigger != previous.refreshTrigger,
|
||||
listener: (context, state) {
|
||||
setState(() {});
|
||||
},
|
||||
child: _buildContent(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
final omissionItems = widget.data.client!.cache
|
||||
.getOmissions()
|
||||
.findAllSync();
|
||||
|
||||
final overallExcused = omissionItems
|
||||
.where((o) => o.state == OmissionState.excused)
|
||||
.length;
|
||||
|
||||
final overallUnexcused = omissionItems
|
||||
.where((o) => o.state == OmissionState.unexcused)
|
||||
.length;
|
||||
|
||||
final overallPending = omissionItems
|
||||
.where((o) => o.state == OmissionState.pending)
|
||||
.length;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.data.l10n.omissions,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"checkSolid",
|
||||
size: 12.0,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Text(
|
||||
overallExcused.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_excused,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.timerSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
Text(
|
||||
overallPending.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_pending,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.restrictedSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
Text(
|
||||
overallUnexcused.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_unexcused,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
OmissionBar(),
|
||||
SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(
|
||||
initData.l10n.subjects,
|
||||
style: appStyle.fonts.B_16SB.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
...omissionItems
|
||||
.fold(
|
||||
LinkedHashMap<
|
||||
SubjectCacheModel,
|
||||
List<OmissionCacheModel>
|
||||
>(
|
||||
equals: (a, b) => a.cacheKey == b.cacheKey,
|
||||
hashCode: (a) => a.cacheKey,
|
||||
),
|
||||
(map, o) => map
|
||||
..putIfAbsent(
|
||||
o.lesson.loadAndGet()!.subject.loadAndGet()!,
|
||||
() => [],
|
||||
).add(o),
|
||||
)
|
||||
.entries
|
||||
.map((entry) {
|
||||
final excused = entry.value
|
||||
.where((o) => o.state == OmissionState.excused)
|
||||
.length;
|
||||
|
||||
final unexcused = entry.value
|
||||
.where((o) => o.state == OmissionState.unexcused)
|
||||
.length;
|
||||
|
||||
final pending = entry.value
|
||||
.where((o) => o.state == OmissionState.pending)
|
||||
.length;
|
||||
|
||||
return FirkaCard.single(
|
||||
height: 64,
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
InfoCard.buildSubject(
|
||||
appStyle.colors.accent,
|
||||
entry.key,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 2,
|
||||
children: [
|
||||
Text(
|
||||
entry.key.name,
|
||||
style: appStyle.fonts.B_16SB.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Row(
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"checkSolid",
|
||||
size: 12.0,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Text(
|
||||
excused.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.timerSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
Text(
|
||||
pending.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.restrictedLine,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
Text(
|
||||
unexcused.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,16 @@
|
||||
import 'dart:io';
|
||||
|
||||
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_common/data/models/class_average_cache_model.dart';
|
||||
import 'package:firka_common/data/models/class_group_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/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/icon_helper.dart';
|
||||
import 'package:firka/core/profile_picture.dart';
|
||||
@@ -14,9 +21,7 @@ import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'package:firka/core/debug_helper.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/theme/style.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -142,11 +147,6 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
);
|
||||
if (!context.mounted || d == null) return;
|
||||
try {
|
||||
await WidgetCacheHelper.generateWidgetStateForDate(
|
||||
d,
|
||||
appStyle,
|
||||
widget.data.client,
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
await HomeWidget.updateWidget(
|
||||
qualifiedAndroidName:
|
||||
@@ -187,7 +187,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getStudent(): ${await widget.data.client.getStudent(forceCache: useCache)}",
|
||||
"getStudent(): ${await widget.data.client!.getStudent()}",
|
||||
);
|
||||
},
|
||||
child: const Text('getStudent()'),
|
||||
@@ -195,7 +195,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getNoticeBoard(): ${await widget.data.client.getNoticeBoard(forceCache: useCache)}",
|
||||
"getNoticeBoard(): ${await widget.data.client!.getNoticeBoard()}",
|
||||
);
|
||||
},
|
||||
child: const Text('getNoticeBoard()'),
|
||||
@@ -203,7 +203,15 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getGrades(): ${await widget.data.client.getGrades(forceCache: useCache)}",
|
||||
"getInfoBoard(): ${await widget.data.client!.getInfoBoard(from: timeNow())}",
|
||||
);
|
||||
},
|
||||
child: const Text('getInfoBoard()'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getGrades(): ${await widget.data.client!.getGrades()}",
|
||||
);
|
||||
},
|
||||
child: const Text('getGrades()'),
|
||||
@@ -216,7 +224,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
var end = now.add(Duration(days: 7));
|
||||
|
||||
logger.finest(
|
||||
"getLessons(): ${await widget.data.client.getTimeTable(start, end, forceCache: useCache)}",
|
||||
"getLessons(): ${await widget.data.client!.getLessons(start, end)}",
|
||||
);
|
||||
},
|
||||
child: const Text('getLessons()'),
|
||||
@@ -224,7 +232,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getHomework(): ${await widget.data.client.getHomework(forceCache: useCache)}",
|
||||
"getHomework(): ${await widget.data.client!.getHomework(from: timeNow())}",
|
||||
);
|
||||
},
|
||||
child: const Text('getHomework()'),
|
||||
@@ -232,7 +240,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getTests(): ${await widget.data.client.getTests(forceCache: useCache)}",
|
||||
"getTests(): ${await widget.data.client!.getTests(from: timeNow())}",
|
||||
);
|
||||
},
|
||||
child: const Text('getTests()'),
|
||||
@@ -240,7 +248,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
logger.finest(
|
||||
"getOmissions(): ${await widget.data.client.getOmissions(forceCache: useCache)}",
|
||||
"getOmissions(): ${await widget.data.client!.getOmissions()}",
|
||||
);
|
||||
},
|
||||
child: const Text('getOmissions()'),
|
||||
@@ -262,13 +270,18 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
onPressed: () async {
|
||||
final isar = widget.data.isar;
|
||||
await isar.writeTxn(() async {
|
||||
await isar.genericCacheModels.clear();
|
||||
await isar.timetableCacheModels.clear();
|
||||
await isar.subjectCacheModels.clear();
|
||||
await isar.testCacheModels.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();
|
||||
});
|
||||
widget.data.client.evictMemCache();
|
||||
if (Platform.isIOS) {
|
||||
await WidgetCacheHelper.clearIOSWidgets();
|
||||
} else {
|
||||
final dataDir = await getApplicationDocumentsDirectory();
|
||||
final widgetFile = File(
|
||||
@@ -300,8 +313,6 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
await isar.tokenModels.clear();
|
||||
});
|
||||
|
||||
widget.data.tokens = List.empty(growable: true);
|
||||
|
||||
if (!context.mounted) return;
|
||||
context.go('/login');
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka/data/models/app_settings_model.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/ui/components/firka_button.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -109,19 +109,7 @@ class _BetaScreenState extends FirkaState<BetaScreen> {
|
||||
),
|
||||
onTap: () async {
|
||||
if (counter != 0) return;
|
||||
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();
|
||||
await Settings.betaWarning.set(true);
|
||||
if (!context.mounted) return;
|
||||
context.go('/home');
|
||||
},
|
||||
|
||||
@@ -1,37 +1,25 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
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/bloc/toast_cubit.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/core/settings.dart';
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/app/app_state.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_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/services.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/reauth_cubit.dart';
|
||||
import 'package:firka/core/bloc/settings_cubit.dart';
|
||||
import 'package:firka/core/state/firka_state.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';
|
||||
|
||||
enum ActiveToastType { fetching, error, reauth, none }
|
||||
|
||||
bool _fetching = true;
|
||||
bool _fetching = false;
|
||||
bool _prefetched = false;
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
@@ -45,16 +33,11 @@ class HomeScreen extends StatefulWidget {
|
||||
|
||||
class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
with WidgetsBindingObserver {
|
||||
Widget? toast;
|
||||
bool _disposed = false;
|
||||
bool _preloadDone = false;
|
||||
bool _didRunSecondaryICloudRecovery = false;
|
||||
bool _prefetchInProgress = false;
|
||||
bool _didRunLiveActivityLogin = false;
|
||||
bool _hasCompletedFirstPrefetch = false;
|
||||
|
||||
ActiveToastType activeToast = ActiveToastType.none;
|
||||
|
||||
void _setupNotificationListener() {
|
||||
final notificationChannel = MethodChannel('firka.app/notifications');
|
||||
|
||||
@@ -109,63 +92,8 @@ 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 {
|
||||
if (_prefetched) return;
|
||||
if (_prefetchInProgress) return;
|
||||
if (_prefetched || _fetching) return;
|
||||
|
||||
final lifecycle = WidgetsBinding.instance.lifecycleState;
|
||||
if (lifecycle != null && lifecycle != AppLifecycleState.resumed) {
|
||||
@@ -175,28 +103,13 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
return;
|
||||
}
|
||||
|
||||
_prefetchInProgress = true;
|
||||
setState(() {
|
||||
_fetching = true;
|
||||
});
|
||||
try {
|
||||
_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();
|
||||
await initData.client!.renewCache(reInit: true);
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
await WidgetCacheHelper.updateWidgetCache(appStyle, initData.client);
|
||||
await HomeWidget.updateWidget(
|
||||
qualifiedAndroidName:
|
||||
"app.firka.naplo.glance.TimetableWidgetReceiver",
|
||||
@@ -204,20 +117,12 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
}
|
||||
|
||||
if (Platform.isIOS) {
|
||||
await WidgetCacheHelper.refreshIOSWidgets(
|
||||
initData.client,
|
||||
initData.settings,
|
||||
);
|
||||
|
||||
if (!_didRunLiveActivityLogin) {
|
||||
_didRunLiveActivityLogin = true;
|
||||
final token = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
);
|
||||
final studentName = token?.studentId ?? "Student";
|
||||
final token = initData.client!.cache.token;
|
||||
final studentName = token.username;
|
||||
LiveActivityService.onUserLogin(
|
||||
client: initData.client,
|
||||
client: initData.client!,
|
||||
studentName: studentName,
|
||||
settingsStore: initData.settings,
|
||||
).catchError((e, st) {
|
||||
@@ -225,173 +130,20 @@ 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) {
|
||||
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;
|
||||
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");
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
(context);
|
||||
} finally {
|
||||
_prefetchInProgress = false;
|
||||
_hasCompletedFirstPrefetch = true;
|
||||
if (!_disposed) {
|
||||
setState(() {
|
||||
_prefetched = true;
|
||||
_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
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -404,8 +156,7 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
prefetch();
|
||||
_preloadImages();
|
||||
|
||||
if (Platform.isIOS &&
|
||||
initData.settings.group("settings").boolean("beta_warning")) {
|
||||
if (Platform.isIOS && Settings.betaWarning.value) {
|
||||
Future.delayed(Duration(seconds: 3), () async {
|
||||
await LiveActivityService.showConsentScreenIfNeeded();
|
||||
});
|
||||
@@ -417,20 +168,20 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _preloadImages() async {
|
||||
final imagePaths = initData.settings.appIcons.keys
|
||||
.map((icon) => "assets/images/icons/$icon.webp")
|
||||
.toList();
|
||||
void _preloadImages() async {
|
||||
final imagePaths = appIconLabels(
|
||||
initData.l10n,
|
||||
).keys.map((icon) => "assets/images/icons/$icon.webp").toList();
|
||||
imagePaths.add("assets/images/background.webp");
|
||||
|
||||
try {
|
||||
await ImagePreloader.preloadMultipleAssets(FirkaBundle(), imagePaths);
|
||||
if (!mounted) return;
|
||||
setState(() => _preloadDone = true);
|
||||
} catch (e) {
|
||||
logger.severe('Home: error preloading images: $e');
|
||||
if (!mounted) return;
|
||||
setState(() => _preloadDone = true);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _preloadDone = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,47 +204,6 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
return BlocListener<SettingsCubit, SettingsState>(
|
||||
listener: (context, state) {
|
||||
@@ -503,14 +213,11 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
listener: (context, state) {
|
||||
if (mounted) setState(() {});
|
||||
},
|
||||
child: BlocListener<ReauthCubit, ReauthState>(
|
||||
child: BlocListener<ToastCubit, ToastState>(
|
||||
listener: (context, state) {
|
||||
if (!mounted || _disposed) return;
|
||||
if (!state.needsReauth && activeToast == ActiveToastType.reauth) {
|
||||
setState(() {
|
||||
activeToast = ActiveToastType.none;
|
||||
toast = null;
|
||||
});
|
||||
if (mounted) setState(() {});
|
||||
if (state.type == .none) {
|
||||
initData.homeRefreshCubit.requestRefresh();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
@@ -519,7 +226,10 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Stack(
|
||||
children: [widget.child, toast ?? SizedBox.shrink()],
|
||||
children: [
|
||||
widget.child,
|
||||
?(context.watch<ToastCubit>().state.buildWidget(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -535,8 +245,8 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
if (state == AppLifecycleState.resumed && !_disposed) {
|
||||
logger.info('[Home] App resumed to foreground, re-running prefetch');
|
||||
_prefetched = false;
|
||||
_didRunSecondaryICloudRecovery = false;
|
||||
prefetch();
|
||||
setState(() {});
|
||||
|
||||
if (Platform.isIOS) {
|
||||
_refreshLiveActivityOnResume();
|
||||
@@ -552,14 +262,9 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
Future.delayed(const Duration(milliseconds: 500), () async {
|
||||
if (_disposed || _didRunLiveActivityLogin) return;
|
||||
_didRunLiveActivityLogin = true;
|
||||
final token = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
preferredStudentIdNorm: initData.client.model.studentIdNorm,
|
||||
);
|
||||
final studentName = token?.studentId ?? 'Student';
|
||||
final studentName = initData.client!.cache.token.username;
|
||||
LiveActivityService.onUserLogin(
|
||||
client: initData.client,
|
||||
client: initData.client!,
|
||||
studentName: studentName,
|
||||
settingsStore: initData.settings,
|
||||
).catchError((e, st) {
|
||||
@@ -572,13 +277,9 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
void _refreshLiveActivityOnResume() async {
|
||||
if (!_hasCompletedFirstPrefetch) return;
|
||||
try {
|
||||
final token = pickActiveToken(
|
||||
tokens: initData.tokens,
|
||||
settings: initData.settings,
|
||||
);
|
||||
final studentName = token?.studentId ?? "Student";
|
||||
final studentName = initData.client!.cache.token.username;
|
||||
await LiveActivityService.checkAndUpdateTimetable(
|
||||
client: initData.client,
|
||||
client: initData.client!,
|
||||
studentName: studentName,
|
||||
settingsStore: initData.settings,
|
||||
);
|
||||
@@ -596,7 +297,6 @@ class _HomeScreenState extends FirkaState<HomeScreen>
|
||||
_disposed = true;
|
||||
_fetching = false;
|
||||
_prefetched = false;
|
||||
activeToast = ActiveToastType.none;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:firka/ui/components/firka_button.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/phone/screens/live_activity/full_privacy_policy_screen.dart';
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:firka/ui/phone/widgets/domain_browser_webview.dart';
|
||||
import 'package:firka/ui/phone/widgets/login_webview.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
@@ -12,7 +13,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:sensors_plus/sensors_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
@@ -21,10 +21,6 @@ import 'package:firka/core/image_preloader.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||
|
||||
const String _privacyUrlHungarian =
|
||||
'https://github.com/QwIT-Development/privacy-policy/blob/master/README.md';
|
||||
const String _privacyUrlOther = 'https://firka.app/privacy';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
const LoginScreen(this.data, {super.key});
|
||||
@@ -45,17 +41,24 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
}
|
||||
|
||||
String _getPrivacyPolicyUrl() {
|
||||
final locale = Localizations.localeOf(context).languageCode;
|
||||
return locale == 'hu' ? _privacyUrlHungarian : _privacyUrlOther;
|
||||
return "https://firka.app/privacy";
|
||||
}
|
||||
|
||||
Future<void> _launchPrivacyPolicy() async {
|
||||
Future<void> _showPrivacyPolicyWebview() async {
|
||||
final url = _getPrivacyPolicyUrl();
|
||||
try {
|
||||
await launchUrl(Uri.parse(url));
|
||||
} catch (e) {
|
||||
logger.shout('LoginScreen: Error launching privacy policy URL: $e');
|
||||
}
|
||||
if (!mounted) return;
|
||||
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: false,
|
||||
builder: (BuildContext context) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: DomainBrowserWebviewWidget(data: widget.data, url: url),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _preloadImages() async {
|
||||
@@ -286,7 +289,8 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8),
|
||||
horizontal: 8,
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (ctx, constraints) =>
|
||||
_FloatingCardsSlide(
|
||||
@@ -513,7 +517,7 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
GestureDetector(
|
||||
onTap: _launchPrivacyPolicy,
|
||||
onTap: _showPrivacyPolicyWebview,
|
||||
child: Text(
|
||||
widget.data.l10n.privacyLabel,
|
||||
textAlign: TextAlign.center,
|
||||
@@ -652,7 +656,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
double _sceneWidth = 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;
|
||||
|
||||
Offset _clampVel(Offset v) => Offset(
|
||||
@@ -664,7 +668,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
// final now = DateTime.now();
|
||||
// if (_lastVibration != null &&
|
||||
// now.difference(_lastVibration!).inMilliseconds < 2) //first used 50 but it wasn't good enough, so now it's 2
|
||||
// return;
|
||||
// return;
|
||||
// _lastVibration = now;
|
||||
Vibration.vibrate(duration: 20);
|
||||
}
|
||||
@@ -887,7 +891,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
child: Stack(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
//background rectangle
|
||||
//background rectangle
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
@@ -895,7 +899,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
bottom: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.buttonSecondaryFill, //button color xdddd
|
||||
color: appStyle.colors.buttonSecondaryFill, //button color xdddd
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(32),
|
||||
topRight: Radius.circular(32),
|
||||
@@ -943,7 +947,7 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.55),
|
||||
color: Colors.black.withValues(alpha: 0.55),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
width: math.min(260, _sceneWidth - 24),
|
||||
@@ -964,10 +968,14 @@ class _FloatingCardsSlideState extends State<_FloatingCardsSlide>
|
||||
'accel: (${accel.x.toStringAsFixed(2)}, ${accel.y.toStringAsFixed(2)}, ${accel.z.toStringAsFixed(2)})',
|
||||
),
|
||||
Text('baseline set: ${_baseline != null}'),
|
||||
Text('scene: ${_sceneWidth.toStringAsFixed(0)} x ${_sceneHeight.toStringAsFixed(0)}'),
|
||||
Text(
|
||||
'scene: ${_sceneWidth.toStringAsFixed(0)} x ${_sceneHeight.toStringAsFixed(0)}',
|
||||
),
|
||||
Text('center: ${formatOffset(center)}'),
|
||||
Text('card[0] pos: ${formatOffset(firstPos)}'),
|
||||
Text('card[0] vel: ${formatOffset(firstVel)} | |v|=${speed.toStringAsFixed(2)}'),
|
||||
Text(
|
||||
'card[0] vel: ${formatOffset(firstVel)} | |v|=${speed.toStringAsFixed(2)}',
|
||||
),
|
||||
Text('cards: ${_cards.length}'),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.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/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class MessageScreen extends StatelessWidget {
|
||||
final AppInitialization data;
|
||||
final InfoBoardItem info;
|
||||
final MessageItem message;
|
||||
|
||||
const MessageScreen(this.data, this.info, {super.key});
|
||||
const MessageScreen(this.data, this.message, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -68,7 +70,7 @@ class MessageScreen extends StatelessWidget {
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.85,
|
||||
child: Text(
|
||||
info.title,
|
||||
message.title,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
@@ -82,7 +84,7 @@ class MessageScreen extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
info.date.format(data.l10n, FormatMode.yyyymmdd),
|
||||
message.date.format(data.l10n, FormatMode.yyyymmdd),
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
@@ -107,7 +109,7 @@ class MessageScreen extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(
|
||||
info.author[0],
|
||||
message.author[0],
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
fontSize: 20,
|
||||
color: appStyle.colors.textPrimary,
|
||||
@@ -125,7 +127,7 @@ class MessageScreen extends StatelessWidget {
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.4,
|
||||
child: Text(
|
||||
info.author,
|
||||
message.author,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
@@ -136,21 +138,34 @@ class MessageScreen extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
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: Text(
|
||||
info.contentText,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
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,
|
||||
onLinkTap: (url, map, element) => {
|
||||
if (url != null) launchUrlString(url),
|
||||
},
|
||||
style: {
|
||||
"*": Style.fromTextStyle(
|
||||
appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
307
firka/lib/ui/phone/screens/settings/settings_account_picker.dart
Normal file
307
firka/lib/ui/phone/screens/settings/settings_account_picker.dart
Normal file
@@ -0,0 +1,307 @@
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
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(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
62
firka/lib/ui/phone/screens/settings/settings_bool_row.dart
Normal file
62
firka/lib/ui/phone/screens/settings/settings_bool_row.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
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,
|
||||
package:
|
||||
item.iconType == FirkaIconType.icons ||
|
||||
item.iconType == FirkaIconType.majesticonsLocal
|
||||
? 'firka'
|
||||
: null,
|
||||
),
|
||||
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(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
108
firka/lib/ui/phone/screens/settings/settings_license_page.dart
Normal file
108
firka/lib/ui/phone/screens/settings/settings_license_page.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
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(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
97
firka/lib/ui/phone/screens/settings/settings_logs.dart
Normal file
97
firka/lib/ui/phone/screens/settings/settings_logs.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,17 +9,13 @@ class BottomNavIconWidget extends StatelessWidget {
|
||||
final bool active;
|
||||
final dynamic icon;
|
||||
final String text;
|
||||
final Color iconColor;
|
||||
final Color textColor;
|
||||
final bool isProfilePicture;
|
||||
|
||||
const BottomNavIconWidget(
|
||||
this.onTap,
|
||||
this.active,
|
||||
this.icon,
|
||||
this.text,
|
||||
this.iconColor,
|
||||
this.textColor, {
|
||||
this.text, {
|
||||
this.isProfilePicture = false,
|
||||
super.key,
|
||||
});
|
||||
@@ -33,43 +29,45 @@ class BottomNavIconWidget extends StatelessWidget {
|
||||
HapticFeedback.lightImpact();
|
||||
onTap();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isProfilePicture && icon != null)
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: MemoryImage(icon as Uint8List),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isProfilePicture && icon != null)
|
||||
Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: MemoryImage(icon as Uint8List),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
)
|
||||
else
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
icon as Uint8List,
|
||||
color: iconColor,
|
||||
size: 24,
|
||||
).build(context),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
text,
|
||||
style: active
|
||||
? appStyle.fonts.B_12SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
)
|
||||
: appStyle.fonts.B_12R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
icon as Uint8List,
|
||||
color: active
|
||||
? appStyle.colors.accent
|
||||
: appStyle.colors.secondary.withAlpha(128),
|
||||
size: 24,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
FittedBox(
|
||||
alignment: Alignment.bottomCenter,
|
||||
fit: BoxFit.scaleDown,
|
||||
clipBehavior: Clip.none,
|
||||
child: Text(
|
||||
text,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: active
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ class BottomTimeTableNavIconWidget extends StatelessWidget {
|
||||
final AppLocalizations l10n;
|
||||
final void Function() onTap;
|
||||
final bool active;
|
||||
final DateTime date;
|
||||
final DateTime? date;
|
||||
|
||||
const BottomTimeTableNavIconWidget(
|
||||
this.l10n,
|
||||
@@ -25,30 +25,48 @@ class BottomTimeTableNavIconWidget extends StatelessWidget {
|
||||
onTap: () {
|
||||
onTap();
|
||||
},
|
||||
child: Card(
|
||||
color: active
|
||||
? appStyle.colors.buttonSecondaryFill
|
||||
: Colors.transparent,
|
||||
shadowColor: active ? appStyle.colors.shadowColor : Colors.transparent,
|
||||
child: SizedBox(
|
||||
width: 40,
|
||||
height: 54,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 54,
|
||||
decoration: ShapeDecoration(
|
||||
shadows: active
|
||||
? [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.shadowColor,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
color: active
|
||||
? appStyle.colors.buttonSecondaryFill
|
||||
: Colors.transparent,
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: 6),
|
||||
Text(
|
||||
date.format(l10n, FormatMode.da),
|
||||
style: appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
date.format(l10n, FormatMode.dd),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: date != null
|
||||
? [
|
||||
Text(
|
||||
date!.format(l10n, FormatMode.da),
|
||||
style: appStyle.fonts.H_16px.apply(
|
||||
color: active
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textTeritary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
date!.format(l10n, FormatMode.dd),
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: active
|
||||
? appStyle.colors.textSecondary
|
||||
: appStyle.colors.textTeritary,
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -19,12 +19,12 @@ class BubbleTest extends StatelessWidget {
|
||||
height: 24,
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(3, 6),
|
||||
offset: Offset(2, 4),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Line,
|
||||
Majesticon.editPen4Solid,
|
||||
color: appStyle.colors.accent,
|
||||
size: 14,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
326
firka/lib/ui/phone/widgets/domain_browser_webview.dart
Normal file
326
firka/lib/ui/phone/widgets/domain_browser_webview.dart
Normal file
@@ -0,0 +1,326 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
/// Lightweight in-app browser used outside the login flow (e.g. privacy policy).
|
||||
///
|
||||
/// This deliberately contains only generic WebView behaviour, keeping all
|
||||
/// login/token handling inside `login_webview.dart`.
|
||||
class DomainBrowserWebviewWidget extends StatefulWidget {
|
||||
final AppInitialization? data;
|
||||
final String? url;
|
||||
|
||||
const DomainBrowserWebviewWidget({super.key, this.data, this.url});
|
||||
|
||||
@override
|
||||
State<DomainBrowserWebviewWidget> createState() =>
|
||||
_DomainBrowserWebviewWidgetState();
|
||||
}
|
||||
|
||||
class _DomainBrowserWebviewWidgetState
|
||||
extends FirkaState<DomainBrowserWebviewWidget>
|
||||
with TickerProviderStateMixin {
|
||||
late WebViewController _webViewController;
|
||||
bool _isLoading = true;
|
||||
AnimationController? _fadeAnimationController;
|
||||
Animation<double>? _fadeAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_fadeAnimationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_fadeAnimation = Tween<double>(
|
||||
begin: 1.0,
|
||||
end: 0.0,
|
||||
).animate(_fadeAnimationController!);
|
||||
|
||||
assert(
|
||||
widget.data != null && widget.url != null,
|
||||
'DomainBrowserWebviewWidget requires non-null data and url',
|
||||
);
|
||||
|
||||
_webViewController = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..loadRequest(Uri.parse(widget.url!))
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onPageFinished: (String url) {
|
||||
Timer(Duration.zero, () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
_fadeAnimationController?.forward().then((_) {
|
||||
_fadeAnimationController?.reset();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
onPageStarted: (String url) {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
_fadeAnimationController?.reset();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_fadeAnimationController?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.data == null || widget.url == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final mediaQuery = MediaQuery.of(context);
|
||||
final safePadding = mediaQuery.padding;
|
||||
final displayUrl = (widget.url ?? '').replaceFirst(
|
||||
RegExp(r'^https?://'),
|
||||
'',
|
||||
);
|
||||
final displayParts = displayUrl.split('/');
|
||||
final host = displayParts.isNotEmpty ? displayParts.first : displayUrl;
|
||||
final path = displayParts.length > 1
|
||||
? '/${displayParts.sublist(1).join('/')}'
|
||||
: '';
|
||||
|
||||
return Material(
|
||||
color: appStyle.colors.background,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 61 + safePadding.top,
|
||||
left: 12,
|
||||
right: 12,
|
||||
bottom: safePadding.bottom,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 2),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/dave.svg",
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.data?.l10n.runningInDomainBrowser ??
|
||||
'Domain Browser',
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
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: Majesticon(
|
||||
Majesticon.multiplySolid,
|
||||
color: appStyle.colors.accent,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Stack(
|
||||
children: [
|
||||
WebViewWidget(
|
||||
controller: _webViewController,
|
||||
gestureRecognizers: {
|
||||
Factory<OneSequenceGestureRecognizer>(
|
||||
() => EagerGestureRecognizer(),
|
||||
),
|
||||
},
|
||||
),
|
||||
if (_fadeAnimationController != null &&
|
||||
_fadeAnimation != null)
|
||||
IgnorePointer(
|
||||
ignoring: !_isLoading,
|
||||
child: AnimatedBuilder(
|
||||
animation: _fadeAnimationController!,
|
||||
builder: (context, child) => AnimatedOpacity(
|
||||
opacity: _isLoading
|
||||
? 1.0
|
||||
: _fadeAnimationController!.isAnimating
|
||||
? _fadeAnimation!.value
|
||||
: 0.0,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: Container(
|
||||
color: appStyle.colors.background,
|
||||
child: Center(
|
||||
child: Image.asset(
|
||||
"assets/images/logos/loading.gif",
|
||||
width: 50,
|
||||
height: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.card,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: host,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
fontSize: 16,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: path,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
fontSize: 16,
|
||||
color:
|
||||
appStyle.colors.textTeritary ??
|
||||
appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
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: Center(
|
||||
child: Image.asset(
|
||||
"assets/icons/button/colorwheel.png",
|
||||
width: 22,
|
||||
height: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
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: Center(
|
||||
child: Majesticon(
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.buttonDisabledIcon,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
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: Center(
|
||||
child: Majesticon(
|
||||
Majesticon.menuLine,
|
||||
color: appStyle.colors.buttonDisabledIcon,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,45 @@
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka_common/core/grade_helper.dart';
|
||||
import 'package:firka_common/data/models/grade_cache_model.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:firka/routing/chart_interaction_scope.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GradeChart extends StatefulWidget {
|
||||
final List<Grade> grades;
|
||||
const GradeChart({super.key, required this.grades});
|
||||
final List<GradeCacheModel> grades;
|
||||
final bool halfYearFallback;
|
||||
GradeChart({
|
||||
super.key,
|
||||
required List<GradeCacheModel> grades,
|
||||
this.halfYearFallback = true,
|
||||
}) : grades = grades.where((g) => g.hasClassicValue()).toList()
|
||||
..sort((a, b) => a.writtenAt.compareTo(b.writtenAt));
|
||||
|
||||
@override
|
||||
State<GradeChart> createState() => _GradeChartState();
|
||||
}
|
||||
|
||||
class DateSpot extends FlSpot {
|
||||
final DateTime date;
|
||||
|
||||
const DateSpot(super.x, super.y, this.date);
|
||||
|
||||
DateSpot copyWithX(double x) {
|
||||
return DateSpot(x, y, date);
|
||||
}
|
||||
}
|
||||
|
||||
class _GradeChartState extends State<GradeChart> {
|
||||
bool _tooltipActive = false;
|
||||
double? _tooltipY;
|
||||
int? _touchedIndex;
|
||||
DateFormat tooltipFormat = DateFormat("MM.dd.");
|
||||
|
||||
List<Color> gradientColors = [
|
||||
appStyle.colors.grade5,
|
||||
appStyle.colors.grade4,
|
||||
appStyle.colors.grade3,
|
||||
appStyle.colors.grade2,
|
||||
appStyle.colors.grade1,
|
||||
];
|
||||
|
||||
late List<FlSpot> spots;
|
||||
|
||||
double? _subjectAverageInList(List<Grade> grades, String subjectUid) {
|
||||
double weightedSum = 0;
|
||||
double totalWeight = 0;
|
||||
for (final g in grades) {
|
||||
if (g.subject.uid != subjectUid) continue;
|
||||
final name = g.valueType.name?.toLowerCase() ?? '';
|
||||
final isPercentage =
|
||||
name.contains('szazalek') || name.contains('percent');
|
||||
if (isPercentage) continue;
|
||||
final v = g.numericValue;
|
||||
final w = g.weightPercentage;
|
||||
if (v != null && w != null) {
|
||||
final effectiveValue = g.valueType.name == "Szazalekos"
|
||||
? percentageToGrade(v).toDouble()
|
||||
: v.toDouble();
|
||||
weightedSum += effectiveValue * w;
|
||||
totalWeight += w;
|
||||
}
|
||||
}
|
||||
return totalWeight > 0 ? weightedSum / totalWeight : null;
|
||||
}
|
||||
|
||||
double _runningSubjectAverage(List<Grade> sortedGrades, int upToInclusive) {
|
||||
final sublist = sortedGrades.sublist(
|
||||
0,
|
||||
(upToInclusive + 1).clamp(0, sortedGrades.length),
|
||||
);
|
||||
final subjectUids = sublist.map((g) => g.subject.uid).toSet();
|
||||
double sum = 0;
|
||||
int count = 0;
|
||||
for (final uid in subjectUids) {
|
||||
final avg = _subjectAverageInList(sublist, uid);
|
||||
if (avg != null) {
|
||||
sum += avg;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0 ? sum / count : 0;
|
||||
}
|
||||
late List<DateSpot> spots;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -75,25 +48,42 @@ class _GradeChartState extends State<GradeChart> {
|
||||
}
|
||||
|
||||
void _computeSpots() {
|
||||
final sortedGrades = List<Grade>.from(widget.grades)
|
||||
..sort((a, b) => a.creationDate.compareTo(b.creationDate));
|
||||
spots = [];
|
||||
for (var i = 0; i < widget.grades.length; i++) {
|
||||
final grade = widget.grades[i];
|
||||
if (!grade.shouldIncludeInAverage()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sortedGrades.isEmpty) {
|
||||
spots = [const FlSpot(0, 0)];
|
||||
return;
|
||||
final partialAvg = widget.grades
|
||||
.take(i + 1)
|
||||
.getSubjectAverage(halfYearFallback: widget.halfYearFallback);
|
||||
|
||||
spots.add(
|
||||
DateSpot(spots.length.toDouble(), partialAvg!, grade.writtenAt),
|
||||
);
|
||||
}
|
||||
|
||||
spots = [];
|
||||
for (var i = 0; i < sortedGrades.length; i++) {
|
||||
final grade = sortedGrades[i];
|
||||
if (grade.numericValue != null && grade.weightPercentage != null) {
|
||||
final partialAvg = _runningSubjectAverage(sortedGrades, i);
|
||||
spots.add(FlSpot(i.toDouble(), partialAvg));
|
||||
if (spots.isEmpty) {
|
||||
for (final grade in widget.grades) {
|
||||
if (grade.hasClassicValue()) {
|
||||
spots.add(
|
||||
DateSpot(
|
||||
spots.length.toDouble(),
|
||||
grade.numericValue!.toDouble(),
|
||||
grade.writtenAt,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spots.isEmpty) {
|
||||
spots = [const FlSpot(0, 0)];
|
||||
spots.add(DateSpot(0, 0, DateTime.now()));
|
||||
}
|
||||
|
||||
if (spots.length == 1) {
|
||||
spots = [spots[0], spots[0].copyWithX(1)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,48 +118,60 @@ class _GradeChartState extends State<GradeChart> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(color: appStyle.colors.card),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1.90,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 28,
|
||||
left: 12,
|
||||
top: 6,
|
||||
bottom: 12,
|
||||
),
|
||||
child: LineChart(avgData()),
|
||||
),
|
||||
),
|
||||
return FirkaCard.single(
|
||||
margin: EdgeInsets.all(0),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: AspectRatio(aspectRatio: 1.82, child: LineChart(avgData())),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget bottomTitleWidgets(double value, TitleMeta meta) {
|
||||
final style = TextStyle(
|
||||
fontFamily: appStyle.fonts.B_16R.fontFamily,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: appStyle.colors.textSecondary,
|
||||
);
|
||||
|
||||
final firstX = spots.first.x.toInt();
|
||||
final lastX = spots.last.x.toInt();
|
||||
String text = '';
|
||||
const epsilon = 0.01;
|
||||
String content = '';
|
||||
|
||||
if ((value - firstX).abs() < epsilon) {
|
||||
text = 'Szeptember';
|
||||
} else if ((value - lastX).abs() < epsilon) {
|
||||
text = 'Most';
|
||||
final shouldHideNow =
|
||||
_touchedIndex != null &&
|
||||
meta.parentAxisSize / lastX * _touchedIndex! > meta.parentAxisSize - 62;
|
||||
|
||||
if (value == _touchedIndex) {
|
||||
final date = spots[_touchedIndex!].date;
|
||||
content = tooltipFormat.format(date);
|
||||
} else if (value == firstX) {
|
||||
content = DateFormat(
|
||||
"MMMM",
|
||||
initData.l10n.localeName,
|
||||
).format(DateTime.now().copyWith(month: DateTime.september)).firstUpper();
|
||||
} else if (value == lastX && !shouldHideNow) {
|
||||
content = initData.l10n.now;
|
||||
}
|
||||
|
||||
final text = Text(
|
||||
content,
|
||||
style: appStyle.fonts.B_12R.apply(color: appStyle.colors.textSecondary),
|
||||
);
|
||||
|
||||
return SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(text, style: style),
|
||||
space: 0,
|
||||
fitInside: SideTitleFitInsideData.fromTitleMeta(
|
||||
meta,
|
||||
distanceFromEdge: value == lastX ? 12 : 0,
|
||||
),
|
||||
child: value == _touchedIndex
|
||||
? Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
||||
decoration: ShapeDecoration(
|
||||
color: appStyle.colors.background,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(27),
|
||||
),
|
||||
),
|
||||
child: text,
|
||||
)
|
||||
: text,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,60 +180,44 @@ class _GradeChartState extends State<GradeChart> {
|
||||
required Color bgColor,
|
||||
required Color textColor,
|
||||
}) {
|
||||
return SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Material(
|
||||
shape: const CircleBorder(),
|
||||
color: bgColor,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: appStyle.fonts.B_14SB.fontFamily,
|
||||
),
|
||||
),
|
||||
),
|
||||
return FilledCircle(
|
||||
diameter: 18,
|
||||
color: bgColor,
|
||||
child: Text(
|
||||
text,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_14px.copyWith(color: textColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color colorForY(double y) {
|
||||
return y == 0 ? appStyle.colors.card : initData.settings.getGradeColor(y);
|
||||
}
|
||||
|
||||
Widget leftTitleWidgets(double value, TitleMeta meta) {
|
||||
String text = switch (value.toInt()) {
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
3 => '3',
|
||||
4 => '4',
|
||||
5 => '5',
|
||||
_ => '',
|
||||
};
|
||||
Color gradeColor;
|
||||
if (text != "") {
|
||||
gradeColor = getGradeColor(int.parse(text).toDouble());
|
||||
} else {
|
||||
gradeColor = getGradeColor(0);
|
||||
if (value == 0 || value > 5) {
|
||||
return SizedBox();
|
||||
}
|
||||
final currentValue = _tooltipActive && _tooltipY != null
|
||||
? _tooltipY!.round()
|
||||
: spots.last.y.round();
|
||||
final isActive = text == currentValue.toString();
|
||||
|
||||
final currentValue = spots.last.y == 0
|
||||
? 0
|
||||
: initData.settings.roundGrade(_tooltipY ?? spots.last.y);
|
||||
final isActive = value == currentValue;
|
||||
|
||||
if (isActive) {
|
||||
final gradeColor = getGradeColor(value);
|
||||
return buildCircle(
|
||||
text: text,
|
||||
text: value.toStringAsFixed(0),
|
||||
bgColor: gradeColor.withAlpha(38),
|
||||
textColor: gradeColor,
|
||||
);
|
||||
}
|
||||
|
||||
return buildCircle(
|
||||
text: text,
|
||||
text: value.toStringAsFixed(0),
|
||||
bgColor: appStyle.colors.card,
|
||||
textColor: appStyle.colors.textPrimary.withValues(alpha: 0.2),
|
||||
textColor: appStyle.colors.textTertiary,
|
||||
);
|
||||
|
||||
// return Text(text, style: style, textAlign: TextAlign.left);
|
||||
@@ -240,29 +226,6 @@ class _GradeChartState extends State<GradeChart> {
|
||||
LineChartData avgData() {
|
||||
final smoothedSpots = _smoothSpots(spots);
|
||||
|
||||
var firstX = smoothedSpots.first.x;
|
||||
var lastX = smoothedSpots.last.x;
|
||||
if (firstX == lastX) {
|
||||
lastX = firstX + 1;
|
||||
}
|
||||
|
||||
Color colorForY(double y) {
|
||||
switch (y.round()) {
|
||||
case 1:
|
||||
return appStyle.colors.grade1;
|
||||
case 2:
|
||||
return appStyle.colors.grade2;
|
||||
case 3:
|
||||
return appStyle.colors.grade3;
|
||||
case 4:
|
||||
return appStyle.colors.grade4;
|
||||
case 5:
|
||||
return appStyle.colors.grade5;
|
||||
default:
|
||||
return appStyle.colors.grade1;
|
||||
}
|
||||
}
|
||||
|
||||
return LineChartData(
|
||||
lineTouchData: LineTouchData(
|
||||
handleBuiltInTouches: true,
|
||||
@@ -270,49 +233,41 @@ class _GradeChartState extends State<GradeChart> {
|
||||
enabled: true,
|
||||
touchCallback: (FlTouchEvent event, LineTouchResponse? response) {
|
||||
setState(() {
|
||||
if (event is FlLongPressEnd ||
|
||||
event is FlPanEndEvent ||
|
||||
event is FlTapUpEvent) {
|
||||
_tooltipActive = false;
|
||||
_tooltipY = null;
|
||||
_touchedIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (response?.lineBarSpots != null &&
|
||||
response!.lineBarSpots!.isNotEmpty) {
|
||||
final spot = response.lineBarSpots!.first;
|
||||
|
||||
_tooltipActive = true;
|
||||
_tooltipY = spot.y;
|
||||
_touchedIndex = spot.spotIndex;
|
||||
if (event.isInterestedForInteractions) {
|
||||
_touchedIndex = response!.lineBarSpots!.first.spotIndex;
|
||||
_tooltipY = spots[_touchedIndex!].y;
|
||||
if (_tooltipY! > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_tooltipY = null;
|
||||
_touchedIndex = null;
|
||||
});
|
||||
},
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
tooltipMargin: 0,
|
||||
tooltipMargin: 4,
|
||||
getTooltipColor: (touchedSpot) => appStyle.colors.buttonSecondaryFill,
|
||||
tooltipBorderRadius: BorderRadius.circular(90),
|
||||
fitInsideVertically: true,
|
||||
tooltipBorderRadius: BorderRadius.circular(27),
|
||||
tooltipPadding: EdgeInsets.symmetric(vertical: 2, horizontal: 6),
|
||||
fitInsideHorizontally: true,
|
||||
|
||||
showOnTopOfTheChartBoxArea: true,
|
||||
showOnTopOfTheChartBoxArea: false,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
color: colorForY(touchedSpot.y),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
);
|
||||
return LineTooltipItem(
|
||||
touchedSpot.y.toStringAsFixed(2),
|
||||
textStyle,
|
||||
if (touchedSpot.y == 0) {
|
||||
return null;
|
||||
}
|
||||
final spot = spots[touchedSpot.spotIndex];
|
||||
final textStyle = appStyle.fonts.B_14SB.apply(
|
||||
color: colorForY(spot.y),
|
||||
);
|
||||
return LineTooltipItem(spot.y.toStringAsFixed(2), textStyle);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
getTouchedSpotIndicator: (barData, spotIndexes) {
|
||||
return spotIndexes.map((index) {
|
||||
final touchedSpot = barData.spots[index];
|
||||
final touchedSpot = spots[index];
|
||||
return TouchedSpotIndicatorData(
|
||||
FlLine(color: colorForY(touchedSpot.y), strokeWidth: 3),
|
||||
FlDotData(show: false),
|
||||
@@ -320,32 +275,16 @@ class _GradeChartState extends State<GradeChart> {
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
backgroundColor: appStyle.colors.card,
|
||||
backgroundColor: Colors.transparent,
|
||||
gridData: FlGridData(
|
||||
show: true,
|
||||
drawHorizontalLine: true,
|
||||
drawVerticalLine: false,
|
||||
horizontalInterval: 1,
|
||||
getDrawingHorizontalLine: (value) {
|
||||
if (!_tooltipActive || _tooltipY == null) {
|
||||
return FlLine(
|
||||
color: const Color(0xFFC8C8C8),
|
||||
strokeWidth: 1.0,
|
||||
dashArray: [8, 12],
|
||||
);
|
||||
}
|
||||
|
||||
const epsilon = 0.01;
|
||||
if ((value - _tooltipY!.round()).abs() < epsilon) {
|
||||
// return FlLine(
|
||||
// color: const Color(0xFFC8C8C8),
|
||||
// strokeWidth: 1.2,
|
||||
// );
|
||||
return FlLine(
|
||||
color: const Color(0xFFC8C8C8),
|
||||
strokeWidth: 1.0,
|
||||
dashArray: [8, 12],
|
||||
);
|
||||
if (_tooltipY != null &&
|
||||
initData.settings.roundGrade(_tooltipY!) == value) {
|
||||
return FlLine(color: const Color(0xFFC8C8C8), strokeWidth: 1.0);
|
||||
}
|
||||
return FlLine(
|
||||
color: const Color(0xFFC8C8C8),
|
||||
@@ -359,30 +298,35 @@ class _GradeChartState extends State<GradeChart> {
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 30,
|
||||
getTitlesWidget: bottomTitleWidgets,
|
||||
interval: 1,
|
||||
),
|
||||
drawBelowEverything: false,
|
||||
sideTitleAlignment: SideTitleAlignment.inside,
|
||||
),
|
||||
leftTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
getTitlesWidget: leftTitleWidgets,
|
||||
reservedSize: 35,
|
||||
reservedSize: 26,
|
||||
interval: 1,
|
||||
),
|
||||
),
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
topTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 20,
|
||||
getTitlesWidget: (v, meta) => SizedBox(),
|
||||
),
|
||||
),
|
||||
rightTitles: const AxisTitles(
|
||||
sideTitles: SideTitles(showTitles: false),
|
||||
),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
|
||||
minX: firstX,
|
||||
maxX: lastX,
|
||||
minY: 0,
|
||||
maxY: 6,
|
||||
maxY: 5.0000000000001,
|
||||
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
@@ -414,9 +358,14 @@ class _GradeChartState extends State<GradeChart> {
|
||||
/// Wraps [GradeChart] with a [Listener] that updates [ChartInteractionScope]
|
||||
/// so the navigator does not intercept touch/drag (e.g. for swipe back).
|
||||
class GradeChartWithInteraction extends StatelessWidget {
|
||||
final List<Grade> grades;
|
||||
final List<GradeCacheModel> grades;
|
||||
final bool halfYearFallback;
|
||||
|
||||
const GradeChartWithInteraction({super.key, required this.grades});
|
||||
const GradeChartWithInteraction({
|
||||
super.key,
|
||||
required this.grades,
|
||||
this.halfYearFallback = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -425,7 +374,7 @@ class GradeChartWithInteraction extends StatelessWidget {
|
||||
onPointerDown: (_) => ChartInteractionScope.of(context).value = true,
|
||||
onPointerUp: (_) => ChartInteractionScope.of(context).value = false,
|
||||
onPointerCancel: (_) => ChartInteractionScope.of(context).value = false,
|
||||
child: GradeChart(grades: grades),
|
||||
child: GradeChart(grades: grades, halfYearFallback: halfYearFallback),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:firka/core/average_helper.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/ui/components/grade.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/core/grade_helper.dart';
|
||||
import 'package:firka_common/data/models/grade_cache_model.dart';
|
||||
import 'package:firka_common/ui/components/grade.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/material.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';
|
||||
|
||||
class GradeSummaryBar extends StatefulWidget {
|
||||
final List<Grade> grades;
|
||||
final List<GradeCacheModel> grades;
|
||||
final AppLocalizations l10n;
|
||||
final bool showAverage;
|
||||
|
||||
@@ -30,98 +30,79 @@ class _GradeSummaryBarState extends State<GradeSummaryBar> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final (total, countsByGrade) = getGradeDistribution(widget.grades);
|
||||
final gradeColors = [
|
||||
appStyle.colors.grade1,
|
||||
appStyle.colors.grade2,
|
||||
appStyle.colors.grade3,
|
||||
appStyle.colors.grade4,
|
||||
appStyle.colors.grade5,
|
||||
];
|
||||
final totalCounted = countsByGrade.reduce((a, b) => a + b);
|
||||
final (total, countsByGrade) = widget.grades.getGradeDistribution();
|
||||
final averageText = widget.showAverage
|
||||
? calculateAverage(widget.grades).toStringAsFixed(2)
|
||||
? (widget.grades.getAverage() ?? 0).toStringAsFixed(2)
|
||||
: '';
|
||||
final bar = ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Row(
|
||||
children: List.generate(5, (i) {
|
||||
final flex = total > 0 ? countsByGrade[i] : 1;
|
||||
return Expanded(
|
||||
flex: flex,
|
||||
child: Container(height: 12, color: getGradeColor(i + 1)),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: appStyle.colors.a15p,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => _expanded = !_expanded),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.showAverage
|
||||
? '${widget.l10n.gradesCount(total)} ($averageText)'
|
||||
: widget.l10n.gradesCount(total),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Row(
|
||||
children: List.generate(5, (i) {
|
||||
final flex = totalCounted > 0 ? countsByGrade[i] : 1;
|
||||
return Expanded(
|
||||
flex: flex,
|
||||
child: Container(height: 10, color: gradeColors[i]),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
_expanded
|
||||
? Majesticon.chevronUpLine
|
||||
: Majesticon.chevronDownLine,
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _expanded = !_expanded),
|
||||
child: FirkaCard.single(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
height: _expanded ? 115 : 52,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 12,
|
||||
children: [
|
||||
Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
Text(
|
||||
widget.showAverage
|
||||
? '${widget.l10n.gradesCount(total)} ($averageText)'
|
||||
: widget.l10n.gradesCount(total),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
size: 24,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_expanded) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(5, (i) {
|
||||
final grade = i + 1;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
height: 32,
|
||||
child: FittedBox(
|
||||
child: GradeWidget.gradeValue(grade),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
countsByGrade[i].toString(),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
Expanded(child: _expanded ? SizedBox() : bar),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
_expanded
|
||||
? Majesticon.chevronUpLine
|
||||
: Majesticon.chevronDownLine,
|
||||
color: appStyle.colors.textPrimary,
|
||||
size: 24,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_expanded) ...[
|
||||
bar,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: List.generate(5, (i) {
|
||||
final grade = i + 1;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 6,
|
||||
children: [
|
||||
GradeWidget.gradeValue(grade, size: 27),
|
||||
Text(
|
||||
countsByGrade[i].toString(),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/counter_digit.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.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:kreta_api/kreta_api.dart';
|
||||
|
||||
class StartingSoonWidget extends StatelessWidget {
|
||||
final AppLocalizations l10n;
|
||||
final List<Lesson> lessons;
|
||||
final List<LessonCacheModel> lessons;
|
||||
final DateTime now;
|
||||
|
||||
const StartingSoonWidget(this.l10n, this.now, this.lessons, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var diff = lessons.first.start.difference(now);
|
||||
var diff = lessons.first.start.difference(now.min(lessons.first.start));
|
||||
var hour = diff.inHours % 60;
|
||||
var min = diff.inMinutes % 60;
|
||||
var sec = diff.inSeconds % 60;
|
||||
@@ -24,89 +26,72 @@ class StartingSoonWidget extends StatelessWidget {
|
||||
var minTxt = hour == 1 ? l10n.starting_min : l10n.starting_min_plural;
|
||||
var secTxt = hour == 1 ? l10n.starting_sec : l10n.starting_sec_plural;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
FirkaCard(
|
||||
attached: Attach.bottom,
|
||||
left: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
l10n.starting_soon,
|
||||
style: appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
return FirkaCard.single(
|
||||
margin: EdgeInsets.only(bottom: 1),
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
FilledCircle(
|
||||
diameter: 32,
|
||||
color: appStyle.colors.a15p,
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"sunSolid",
|
||||
size: 20,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
CounterDigitWidget(
|
||||
hour.toString(),
|
||||
appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 2),
|
||||
Text(
|
||||
hourTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
CounterDigitWidget(
|
||||
(min / 10).floor().toString(),
|
||||
appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
CounterDigitWidget(
|
||||
((min % 10)).toString(),
|
||||
appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 2),
|
||||
Text(
|
||||
minTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
CounterDigitWidget(
|
||||
(sec / 10).floor().toString(),
|
||||
appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
CounterDigitWidget(
|
||||
((sec % 10)).toString(),
|
||||
appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 2),
|
||||
Text(
|
||||
secTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.starting_soon,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
right: [],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
CounterDigitWidget((hour / 10).floor().toString()),
|
||||
SizedBox(width: 4),
|
||||
CounterDigitWidget(((hour % 10)).toString()),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
hourTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
CounterDigitWidget((min / 10).floor().toString()),
|
||||
SizedBox(width: 4),
|
||||
CounterDigitWidget(((min % 10)).toString()),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
minTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
CounterDigitWidget((sec / 10).floor().toString()),
|
||||
SizedBox(width: 4),
|
||||
CounterDigitWidget(((sec % 10)).toString()),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
secTxt,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
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:firka/core/extensions.dart';
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
@@ -6,13 +8,12 @@ import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class WelcomeWidget extends StatefulWidget {
|
||||
final AppLocalizations l10n;
|
||||
final Student student;
|
||||
final List<Lesson> lessons;
|
||||
final StudentCacheModel student;
|
||||
final List<LessonCacheModel> lessons;
|
||||
final DateTime now;
|
||||
|
||||
const WelcomeWidget(
|
||||
@@ -37,7 +38,7 @@ class _WelcomeWidgetState extends State<WelcomeWidget> {
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
|
||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthdate);
|
||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthday);
|
||||
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
||||
_controllerCenter.play();
|
||||
}
|
||||
@@ -100,7 +101,7 @@ class _WelcomeWidgetState extends State<WelcomeWidget> {
|
||||
name = widget.student.name;
|
||||
}
|
||||
|
||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthdate);
|
||||
final birthDate = DateFormat("MM-dd").format(widget.student.birthday);
|
||||
if (birthDate == DateFormat("MM-dd").format(widget.now)) {
|
||||
return widget.l10n.happy_birthday(name);
|
||||
} else if (widget.lessons.length > 1 &&
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/data/models/homework_cache_model.dart';
|
||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
class HomeworkWidget extends StatelessWidget {
|
||||
final AppInitialization data;
|
||||
final Homework item;
|
||||
|
||||
const HomeworkWidget(this.data, this.item, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
Row(
|
||||
children: [
|
||||
FutureBuilder<bool>(
|
||||
future: isHomeworkDone(data.isar, item.uid),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return SizedBox();
|
||||
}
|
||||
final done = snapshot.data!;
|
||||
return done
|
||||
? FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"homeWithMark",
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
)
|
||||
: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.homeSolid,
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FutureBuilder<bool>(
|
||||
future: isHomeworkDone(data.isar, item.uid),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return SizedBox();
|
||||
}
|
||||
final done = snapshot.data!;
|
||||
return done
|
||||
? Text(
|
||||
data.l10n.homework,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
decoration: TextDecoration.lineThrough,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
data.l10n.homework,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Text(
|
||||
item.subjectName,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showHomeworkBottomSheet(context, data, item);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
// TODO: Finish
|
||||
class InfoBoardItemWidget extends StatelessWidget {
|
||||
final InfoBoardItem item;
|
||||
|
||||
const InfoBoardItemWidget(this.item, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FirkaCard(
|
||||
left: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
decoration: ShapeDecoration(
|
||||
color: appStyle.colors.accent,
|
||||
shape: CircleBorder(
|
||||
eccentricity: 1,
|
||||
// borderRadius: BorderRadius.circular(6)),
|
||||
),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 28,
|
||||
height: 28,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text(
|
||||
item.author[0],
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
fontSize: 20,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 1.4,
|
||||
child: Text(
|
||||
item.title,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
item.author,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
295
firka/lib/ui/phone/widgets/info_card.dart
Normal file
295
firka/lib/ui/phone/widgets/info_card.dart
Normal file
@@ -0,0 +1,295 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/extensions.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/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_common/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/ui/components/grade.dart';
|
||||
import 'package:firka/ui/shared/class_icon.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.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:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
class InfoCard extends StatelessWidget {
|
||||
final void Function(BuildContext)? onTap;
|
||||
final Widget icon;
|
||||
final List<String> texts;
|
||||
final List<Widget> right;
|
||||
|
||||
final List<TextStyle> textSyles = [
|
||||
appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary),
|
||||
appStyle.fonts.B_14R.apply(color: appStyle.colors.textSecondary),
|
||||
];
|
||||
|
||||
InfoCard({
|
||||
required this.icon,
|
||||
required this.texts,
|
||||
this.right = const [],
|
||||
this.onTap,
|
||||
super.key,
|
||||
});
|
||||
|
||||
static Widget buildSubject(Color color, SubjectCacheModel subject) {
|
||||
return FilledCircle(
|
||||
diameter: 32,
|
||||
color: color.withAlpha(38),
|
||||
child: ClassIconWidget(subject: subject, color: color, size: 20),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.test(TestCacheModel test) {
|
||||
final color = appStyle.colors.accent;
|
||||
|
||||
final subject = test.lesson.loadAndGet()!.subject.loadAndGet()!;
|
||||
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: color.withAlpha(38),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Solid,
|
||||
color: color,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
texts: [
|
||||
test.topic?.firstUpper() ?? test.method,
|
||||
subject.name.firstUpper(),
|
||||
],
|
||||
right: [buildSubject(color, subject)],
|
||||
onTap: (context) => showTestBottomSheet(context, initData, test),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.testDesc(TestCacheModel test) {
|
||||
if (test.topic == null) {
|
||||
return InfoCard.test(test);
|
||||
}
|
||||
|
||||
final subject = test.lesson.loadAndGet()!.subject.loadAndGet()!;
|
||||
|
||||
final color = appStyle.colors.accent;
|
||||
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: color.withAlpha(38),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Solid,
|
||||
color: color,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
texts: [test.topic!.firstUpper(), test.method.firstUpper()],
|
||||
right: [buildSubject(color, subject)],
|
||||
onTap: (context) => showTestBottomSheet(context, initData, test),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.messageItem(MessageCacheModel item) {
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: appStyle.colors.accent,
|
||||
child: Text(
|
||||
item.author[0],
|
||||
style: appStyle.fonts.H_H2.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
),
|
||||
texts: [item.title, item.author],
|
||||
onTap: (context) => context.push('/message', extra: item),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.omission(List<OmissionCacheModel> omissions) {
|
||||
String title = "-";
|
||||
Color color = appStyle.colors.accent;
|
||||
FirkaIconType iconType = FirkaIconType.majesticons;
|
||||
Object iconData = "check";
|
||||
for (final state in [
|
||||
(
|
||||
OmissionState.pending,
|
||||
appStyle.colors.warningAccent,
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.timerSolid,
|
||||
),
|
||||
(
|
||||
OmissionState.unexcused,
|
||||
appStyle.colors.errorAccent,
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.restrictedLine,
|
||||
),
|
||||
(
|
||||
OmissionState.excused,
|
||||
appStyle.colors.accent,
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"check",
|
||||
),
|
||||
]) {
|
||||
final count = omissions.where((o) => o.state == state.$1).length;
|
||||
|
||||
if (count == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
title = initData.l10n.omissions_count(state.$1.name, count);
|
||||
color = state.$2;
|
||||
iconType = state.$3;
|
||||
iconData = state.$4;
|
||||
break;
|
||||
}
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: color.withAlpha(38),
|
||||
child: FirkaIconWidget(iconType, iconData, color: color, size: 24),
|
||||
),
|
||||
texts: [
|
||||
title,
|
||||
DateFormat.MMMMd(
|
||||
initData.l10n.localeName,
|
||||
).format(omissions.first.createdAt).firstUpper(),
|
||||
],
|
||||
onTap: (context) =>
|
||||
showOmissionBottomSheet(context, initData, title, omissions),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.homework(HomeworkCacheModel homework) {
|
||||
final subject = homework.subject.loadAndGet()!;
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: appStyle.colors.accent.withAlpha(38),
|
||||
child: homework.isDone
|
||||
? FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
"homeWithMark",
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
)
|
||||
: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.homeSolid,
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
texts: [initData.l10n.homework, subject.name],
|
||||
right: [buildSubject(appStyle.colors.accent, subject)],
|
||||
onTap: (context) => showHomeworkBottomSheet(context, initData, homework),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.gradeSubj(
|
||||
GradeCacheModel grade, {
|
||||
void Function(BuildContext)? onTap,
|
||||
}) {
|
||||
String? value = grade.numericValue == null ? grade.textValue : null;
|
||||
return InfoCard(
|
||||
icon: GradeWidget(grade),
|
||||
texts: [
|
||||
(value ?? grade.topic ?? grade.mode ?? grade.type).firstUpper(),
|
||||
grade.subject.loadAndGet()!.name.firstUpper(),
|
||||
],
|
||||
right: [
|
||||
buildSubject(
|
||||
grade.numericValue != null
|
||||
? getGradeColor(grade.numericValue!)
|
||||
: appStyle.colors.accent,
|
||||
grade.subject.loadAndGet()!,
|
||||
),
|
||||
],
|
||||
onTap:
|
||||
onTap ?? (context) => showGradeBottomSheet(context, initData, grade),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.gradeGhost(
|
||||
int gradeValue,
|
||||
int gradeWeigth, {
|
||||
void Function(BuildContext)? onTap,
|
||||
}) {
|
||||
return InfoCard(
|
||||
icon: GradeWidget.gradeValue(gradeValue, gradeWeight: gradeWeigth),
|
||||
texts: ["${initData.l10n.ghost_grade} ($gradeWeigth%)"],
|
||||
right: [],
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.gradeDesc(
|
||||
GradeCacheModel grade, {
|
||||
void Function(BuildContext)? onTap,
|
||||
}) {
|
||||
List<String> texts = [(grade.mode ?? grade.type).firstUpper()];
|
||||
|
||||
if (grade.topic != null) {
|
||||
texts = [grade.topic!.firstUpper(), ...texts];
|
||||
}
|
||||
|
||||
return InfoCard(
|
||||
icon: GradeWidget(grade),
|
||||
texts: texts,
|
||||
right: [
|
||||
buildSubject(appStyle.colors.accent, grade.subject.loadAndGet()!),
|
||||
],
|
||||
onTap:
|
||||
onTap ?? (context) => showGradeBottomSheet(context, initData, grade),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Text> children = [];
|
||||
int i = 0;
|
||||
for (var text in texts) {
|
||||
children.add(
|
||||
Text(text, style: textSyles[i], overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
if (i < textSyles.length) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return GestureDetector(
|
||||
child: FirkaCard.single(
|
||||
height: 68,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
margin: EdgeInsets.all(0),
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
icon,
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 2,
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
...right,
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
if (onTap == null) return;
|
||||
onTap!.call(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||
import 'package:firka/ui/shared/class_icon.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
@@ -16,52 +19,25 @@ import 'bubble_test.dart';
|
||||
|
||||
class LessonWidget extends StatelessWidget {
|
||||
final AppInitialization data;
|
||||
final List<Lesson> week;
|
||||
final List<Lesson> day;
|
||||
final int? lessonNo;
|
||||
final Lesson lesson;
|
||||
final Test? test;
|
||||
final Lesson? nextLesson;
|
||||
final bool? placeholderMode;
|
||||
final LessonCacheModel lesson;
|
||||
final bool active;
|
||||
|
||||
const LessonWidget(
|
||||
this.data,
|
||||
this.week,
|
||||
this.day,
|
||||
this.lessonNo,
|
||||
this.lesson,
|
||||
this.test,
|
||||
this.nextLesson, {
|
||||
super.key,
|
||||
this.placeholderMode,
|
||||
});
|
||||
const LessonWidget(this.data, this.lesson, {this.active = false, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final showTests = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("tests_and_homework");
|
||||
final showSubstitutions = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("substitution");
|
||||
final showLessonNos = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("lesson_no");
|
||||
final isSubstituted = lesson.substituteTeacher != null;
|
||||
final isDismissed = lesson.type.name == "UresOra";
|
||||
// we dont like events
|
||||
assert(lesson.type != TimetableConsts.event);
|
||||
final showTests = Settings.ttToastTestsAndHw.value;
|
||||
|
||||
final test = lesson.test.loadAndGet();
|
||||
|
||||
final isSubstituted = lesson.substituteTeacher != null;
|
||||
final showSubstitutions =
|
||||
isSubstituted && Settings.ttToastSubstitution.value;
|
||||
final showLessonNos = Settings.ttToastLessonNo.value;
|
||||
final isDismissed = lesson.type == "UresOra";
|
||||
|
||||
var showBreak = false;
|
||||
if (week.isNotEmpty) {
|
||||
showBreak =
|
||||
timeNow().isAfter(lesson.start) && timeNow().isBefore(lesson.end) ||
|
||||
timeNow().isAfter(week.last.end) ||
|
||||
lesson.start.getMidnight() != timeNow().getMidnight() ||
|
||||
timeNow().isAfter(day.last.end) ||
|
||||
timeNow().isBefore(day.first.start);
|
||||
}
|
||||
var accent = appStyle.colors.accent;
|
||||
var secondary = appStyle.colors.secondary;
|
||||
var bgColor = appStyle.colors.a15p;
|
||||
@@ -79,408 +55,233 @@ class LessonWidget extends StatelessWidget {
|
||||
|
||||
List<Widget> elements = [];
|
||||
|
||||
var subjectName = lesson.subject?.name ?? 'N/A';
|
||||
if (subjectName.length >= 19) {
|
||||
subjectName = "${subjectName.substring(0, 19 - 3)}...";
|
||||
}
|
||||
subjectName = subjectName.firstUpper();
|
||||
var subjectName = lesson.subject.loadAndGet()!.name.firstUpper();
|
||||
|
||||
var roomName = lesson.roomName ?? 'N/A';
|
||||
if (roomName.length >= 11) {
|
||||
roomName = "${roomName.substring(0, 11 - 3)}...";
|
||||
}
|
||||
var roomName = lesson.roomName;
|
||||
|
||||
elements.add(
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (lessonNo == null) return;
|
||||
showLessonBottomSheet(
|
||||
context,
|
||||
data,
|
||||
lesson,
|
||||
lessonNo,
|
||||
accent,
|
||||
secondary,
|
||||
bgColor,
|
||||
test,
|
||||
);
|
||||
},
|
||||
child: FirkaCard(
|
||||
child: FirkaCard.single(
|
||||
height: 64,
|
||||
borderColor: active ? appStyle.colors.accent : null,
|
||||
margin: EdgeInsets.all(0),
|
||||
padding: EdgeInsets.only(left: 14, right: 16),
|
||||
color: isDismissed
|
||||
? appStyle.colors.cardTranslucent
|
||||
: appStyle.colors.card,
|
||||
attached: showTests && test != null ? Attach.bottom : Attach.none,
|
||||
shadow: !isDismissed,
|
||||
left: [
|
||||
showLessonNos == false || lessonNo == null
|
||||
? SizedBox()
|
||||
: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: bgColor,
|
||||
child: Column(
|
||||
spacing: 12,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
!showLessonNos
|
||||
? SizedBox()
|
||||
: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: bgColor,
|
||||
width: 18,
|
||||
height: 18,
|
||||
),
|
||||
Text(
|
||||
lesson.dailyNth.toString(),
|
||||
style: appStyle.fonts.B_14SB.apply(
|
||||
color: secondary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
lessonNo.toString(),
|
||||
style: appStyle.fonts.B_12R.apply(color: secondary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
FilledCircle(
|
||||
diameter: 36,
|
||||
color: bgColor,
|
||||
child: ClassIconWidget(
|
||||
subject: lesson.subject.loadAndGet()!,
|
||||
color: accent,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(-4, 0),
|
||||
child: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: bgColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsetsGeometry.all(4),
|
||||
child: ClassIconWidget(
|
||||
color: accent,
|
||||
size: 20,
|
||||
uid: lesson.uid,
|
||||
className: lesson.name,
|
||||
category: lesson.subject?.name != null
|
||||
? lesson.subject!.name.firstUpper()
|
||||
: '',
|
||||
),
|
||||
),
|
||||
!showTests && test != null
|
||||
SizedOverflowBox(
|
||||
size: Size(12, 0),
|
||||
child: !showTests && test != null
|
||||
? Transform.translate(
|
||||
offset: Offset(26, -18),
|
||||
offset: Offset(4, -20),
|
||||
child: BubbleTest(),
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: !showTests && test != null ? 16 : 8),
|
||||
Text(
|
||||
subjectName,
|
||||
style: appStyle.fonts.B_15SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
placeholderMode == true
|
||||
? SizedBox()
|
||||
: Text(
|
||||
isDismissed
|
||||
? data.l10n.class_dismissed
|
||||
: lesson.start.toLocal().format(
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
spacing: 12,
|
||||
children: [
|
||||
LimitedBox(
|
||||
maxWidth: 155,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
subjectName,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: !isDismissed
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textSecondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
showSubstitutions
|
||||
? Text(
|
||||
lesson.substituteTeacher!.shortenName(),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
)
|
||||
: SizedBox(),
|
||||
],
|
||||
),
|
||||
),
|
||||
isDismissed
|
||||
? Text(
|
||||
data.l10n.class_dismissed,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
)
|
||||
: Flexible(
|
||||
fit: FlexFit.loose,
|
||||
child: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: appStyle.colors.a15p,
|
||||
margin: EdgeInsets.all(0),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
),
|
||||
child: Text(
|
||||
roomName!,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.secondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isDismissed) SizedBox(width: 8),
|
||||
if (!isDismissed)
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
lesson.start.toLocal().format(
|
||||
data.l10n,
|
||||
FormatMode.hmm,
|
||||
),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
placeholderMode == true
|
||||
? SizedBox()
|
||||
: isDismissed
|
||||
? SizedBox()
|
||||
: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: appStyle.colors.a15p,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Text(
|
||||
roomName,
|
||||
style: appStyle.fonts.B_12R.apply(
|
||||
color: appStyle.colors.secondary,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
lesson.end.toLocal().format(
|
||||
data.l10n,
|
||||
FormatMode.hmm,
|
||||
),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (isSubstituted && showSubstitutions) {
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
data.l10n.class_substitution,
|
||||
style: appStyle.fonts.H_16px.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
lesson.substituteTeacher!,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (test != null && showTests) {
|
||||
var theme = test!.theme;
|
||||
if (theme.length >= 20) {
|
||||
theme = "${theme.substring(0, 20)}...";
|
||||
}
|
||||
var method = test!.method.description ?? 'N/A';
|
||||
if (method.length >= 15) {
|
||||
method = "${method.substring(0, 15)}...";
|
||||
}
|
||||
theme = theme.firstUpper();
|
||||
method = method.firstUpper();
|
||||
var topic = test.topic?.firstUpper() ?? "";
|
||||
var method = test.method.firstUpper();
|
||||
|
||||
elements.add(
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
showTestBottomSheet(
|
||||
context,
|
||||
data,
|
||||
lesson,
|
||||
lessonNo,
|
||||
accent,
|
||||
secondary,
|
||||
bgColor,
|
||||
test,
|
||||
);
|
||||
showTestBottomSheet(context, data, test);
|
||||
},
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Solid,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
theme,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
child: FirkaCard.single(
|
||||
height: 48,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
margin: EdgeInsets.only(top: 4),
|
||||
attached: Attach.top,
|
||||
child: Row(
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Solid,
|
||||
color: appStyle.colors.accent,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
method,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
SizedBox(width: 8),
|
||||
LimitedBox(
|
||||
maxWidth: 160,
|
||||
child: Text(
|
||||
topic,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
SizedBox(width: 12),
|
||||
Flexible(
|
||||
fit: FlexFit.loose,
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
method,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (nextLesson != null) {
|
||||
var breakMins = nextLesson!.start.difference(lesson.end).inMinutes;
|
||||
var seqSchedule = week.getAllSeqs(lesson);
|
||||
|
||||
if (breakMins > 45) {
|
||||
final breakEnd = lesson.end.add(Duration(minutes: breakMins));
|
||||
final emptyClass = seqSchedule.firstWhereOrNull(
|
||||
(lesson2) =>
|
||||
lesson2.start.isAfter(lesson.end) &&
|
||||
lesson2.end.isBefore(breakEnd),
|
||||
);
|
||||
|
||||
if (emptyClass != null) {
|
||||
final preBreak = emptyClass.start.difference(lesson.end).inMinutes;
|
||||
final postBreak = breakEnd.difference(emptyClass.end).inMinutes;
|
||||
|
||||
if (data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("breaks") &&
|
||||
showBreak) {
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
color: appStyle.colors.cardTranslucent,
|
||||
shadow: false,
|
||||
left: [
|
||||
Text(
|
||||
data.l10n.breakTxt,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
"$preBreak ${preBreak == 1 ? data.l10n.starting_min : data.l10n.starting_min_plural}",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
left: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: bgColor,
|
||||
width: 18,
|
||||
height: 18,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 5),
|
||||
child: Text(
|
||||
emptyClass.lessonNumber.toString(),
|
||||
style: appStyle.fonts.B_12R.apply(color: secondary),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(-4, 0),
|
||||
child: Card(
|
||||
shadowColor: Colors.transparent,
|
||||
color: bgColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(4),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticonsLocal,
|
||||
'cupFilled',
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
data.l10n.empty_class,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
isDismissed
|
||||
? data.l10n.class_dismissed
|
||||
: "${emptyClass.start.toLocal().format(data.l10n, FormatMode.hmm)} - ${emptyClass.end.toLocal().format(data.l10n, FormatMode.hmm)}",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("breaks") &&
|
||||
showBreak) {
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
color: appStyle.colors.cardTranslucent,
|
||||
shadow: false,
|
||||
left: [
|
||||
Text(
|
||||
data.l10n.breakTxt,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
"$postBreak ${postBreak == 1 ? data.l10n.starting_min : data.l10n.starting_min_plural}",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("breaks") &&
|
||||
showBreak) {
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
color: appStyle.colors.cardTranslucent,
|
||||
shadow: false,
|
||||
left: [
|
||||
Text(
|
||||
data.l10n.breakTxt,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
"$breakMins ${breakMins == 1 ? data.l10n.starting_min : data.l10n.starting_min_plural}",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("breaks") &&
|
||||
showBreak) {
|
||||
elements.add(
|
||||
FirkaCard(
|
||||
color: appStyle.colors.cardTranslucent,
|
||||
shadow: false,
|
||||
left: [
|
||||
Text(
|
||||
data.l10n.breakTxt,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
Text(
|
||||
"$breakMins ${breakMins == 1 ? data.l10n.starting_min : data.l10n.starting_min_plural}",
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: elements,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user