forked from github/szkolny
Compare commits
134 Commits
Author | SHA1 | Date | |
---|---|---|---|
f1570b8eb9 | |||
de0f29a09e | |||
c0d11c91e3 | |||
22c540a3d4 | |||
b7e35d0322 | |||
7bcd6bf038 | |||
ea4591144b | |||
7627d184a2 | |||
076b485fda | |||
09cb97e367 | |||
4e1f2ed41a | |||
281b6a95ef | |||
e40871c0d0 | |||
b74eeed994 | |||
ccde482364 | |||
a02033d0f3 | |||
6c6bc89f57 | |||
1e3da45340 | |||
0d366adddb | |||
2c24eba46d | |||
7c6dbca986 | |||
33a8fa2a1e | |||
300e2c4bc2 | |||
f883318bd2 | |||
5460c1e2a0 | |||
137c975e81 | |||
001de4a88c | |||
5dcb3fd580 | |||
f13995aa5c | |||
e23deb5ca6 | |||
d688b379a2 | |||
d6a796e25e | |||
e02d3e571d | |||
907b75b22d | |||
c3660b5f80 | |||
7ff10df70c | |||
83e1b21ec3 | |||
deb54e4b24 | |||
48873caecc | |||
cadd1a3dbd | |||
f09f069b2c | |||
1fb5aaed5d | |||
65ba330d5f | |||
795317f13f | |||
031cc05209 | |||
0ac8e1d9c1 | |||
4389dc9d79 | |||
b13257cb78 | |||
fcffa2afeb | |||
3c2f85f263 | |||
0a2323acf3 | |||
45c2948ed1 | |||
f72a6103b5 | |||
9261848369 | |||
7f4e45c57c | |||
180154b684 | |||
a4f58eb19b | |||
fada483d55 | |||
3ae9ba3d61 | |||
15102fe818 | |||
8864bb2a5e | |||
ef1cdd5b20 | |||
35f4f34342 | |||
1a8134459a | |||
a6ce3a5068 | |||
328b20f78b | |||
771712da99 | |||
65e0e10db6 | |||
62e0e53354 | |||
a5461a488a | |||
192dd0c4c7 | |||
c49755c0eb | |||
c8c758958d | |||
e068f1944f | |||
97412a3736 | |||
9167d53a1a | |||
6436a17036 | |||
5ab5dbe940 | |||
d68ab0d010 | |||
f70a1f5730 | |||
85106a01d7 | |||
90e99e241a | |||
3f61ab8299 | |||
f685a4dceb | |||
e8dad29e5d | |||
13a3f66db3 | |||
dc9e6081c5 | |||
26f8c03570 | |||
97e0f36f09 | |||
27e49b10fd | |||
97dc8d12f1 | |||
9b13552b73 | |||
d8559637a5 | |||
00a90a14dc | |||
d56afb034b | |||
0327ba37f1 | |||
12a54e58b5 | |||
238250e8c9 | |||
041bfc6cc0 | |||
8a4866cb62 | |||
0e4d609bbf | |||
f07b12bd87 | |||
0413dbffa2 | |||
c214b48409 | |||
91a6366548 | |||
03c9932b8c | |||
ea4919a25d | |||
f98b174857 | |||
c0aeb0d2f3 | |||
fcb627aac6 | |||
7f0aea29cd | |||
f6dcbb6594 | |||
b790421693 | |||
f5a7799924 | |||
b052b5bd66 | |||
12d8de1def | |||
9303483470 | |||
f8adc86a0e | |||
db57c258c5 | |||
ddb2760c16 | |||
14d267a95a | |||
a6c4053896 | |||
949a68ec1d | |||
93333a8c48 | |||
3c8afb0609 | |||
27f9b8a04e | |||
86669a491a | |||
6a2c863fcc | |||
cf69273de1 | |||
fa99b7fd11 | |||
9c5653b52e | |||
88ad8523a0 | |||
a15f59fbd1 | |||
188470a043 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -86,4 +86,5 @@ app/schemas/
|
||||
|
||||
signatures/
|
||||
|
||||
app/.cxx
|
||||
app/.cxx
|
||||
/i18n/
|
||||
|
16
.idea/compiler.xml
generated
Normal file
16
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.7">
|
||||
<module name="annotation" target="1.7" />
|
||||
<module name="codegen" target="1.7" />
|
||||
<module name="Szkolny.eu.agendacalendarview" target="1.8" />
|
||||
<module name="Szkolny.eu.app" target="1.8" />
|
||||
<module name="Szkolny.eu.cafebar" target="1.8" />
|
||||
<module name="Szkolny.eu.material-about-library" target="1.8" />
|
||||
<module name="Szkolny.eu.mhttp" target="1.8" />
|
||||
<module name="Szkolny.eu.nachos" target="1.8" />
|
||||
<module name="Szkolny.eu.szkolny-font" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
10
.idea/jarRepositories.xml
generated
10
.idea/jarRepositories.xml
generated
@ -41,5 +41,15 @@
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven4" />
|
||||
<option name="name" value="maven4" />
|
||||
<option name="url" value="https://dl.bintray.com/undervoid/Powerpermission" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven4" />
|
||||
<option name="name" value="maven4" />
|
||||
<option name="url" value="https://dl.bintray.com/undervoid/PowerPermission" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -11,7 +11,6 @@
|
||||
<item index="1" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
|
||||
<option name="myDefaultNotNull" value="androidx.annotation.RecentlyNonNull" />
|
||||
@ -51,7 +50,7 @@
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -145,7 +145,11 @@ dependencies {
|
||||
implementation("com.github.ozodrukh:CircularReveal:2.0.1@aar") {transitive = true}
|
||||
implementation "com.heinrichreimersoftware:material-intro:1.5.8" // do not update
|
||||
implementation "com.jaredrummler:colorpicker:1.0.2"
|
||||
implementation "com.squareup.okhttp3:okhttp:3.12.2"
|
||||
implementation("com.squareup.okhttp3:okhttp") {
|
||||
version {
|
||||
strictly "3.12.2"
|
||||
}
|
||||
}
|
||||
implementation "com.theartofdev.edmodo:android-image-cropper:2.8.0" // do not update
|
||||
implementation "com.wdullaer:materialdatetimepicker:4.1.2"
|
||||
implementation "com.yuyh.json:jsonviewer:1.0.6"
|
||||
@ -196,6 +200,16 @@ dependencies {
|
||||
|
||||
implementation project(":annotation")
|
||||
kapt project(":codegen")
|
||||
|
||||
implementation 'com.google.android:flexbox:2.0.1'
|
||||
|
||||
implementation 'com.qifan.powerpermission:powerpermission:1.3.0'
|
||||
implementation 'com.qifan.powerpermission:powerpermission-coroutines:1.3.0'
|
||||
|
||||
implementation 'com.github.kuba2k2.FSLogin:lib:master-SNAPSHOT'
|
||||
implementation 'pl.droidsonroids:jspoon:1.3.2'
|
||||
implementation "com.squareup.retrofit2:converter-scalars:2.8.1"
|
||||
implementation "pl.droidsonroids.retrofit2:converter-jspoon:1.3.2"
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -66,3 +66,4 @@
|
||||
|
||||
-keepclassmembernames class pl.szczodrzynski.edziennik.data.api.szkolny.request.** { *; }
|
||||
-keepclassmembernames class pl.szczodrzynski.edziennik.data.api.szkolny.response.** { *; }
|
||||
-keepclassmembernames class pl.szczodrzynski.edziennik.ui.modules.login.LoginInfo.Platform { *; }
|
||||
|
BIN
app/sampledata/vulcan/edu.lublin.eu.png
Normal file
BIN
app/sampledata/vulcan/edu.lublin.eu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
@ -14,6 +14,9 @@
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<!-- PowerPermission uses minSdk 21, it's safe to override as it is used only in >= 23 -->
|
||||
<uses-sdk tools:overrideLibrary="com.qifan.powerpermission.coroutines, com.qifan.powerpermission.core" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
@ -21,7 +24,6 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.Dark"
|
||||
android:usesCleartextTraffic="true"
|
||||
@ -132,9 +134,6 @@
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AppTheme.Light" />
|
||||
<activity android:name=".ui.modules.login.LoginLibrusCaptchaActivity"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
android:excludeFromRecents="true"/>
|
||||
<activity android:name=".ui.modules.home.CounterActivity"
|
||||
android:theme="@style/AppTheme.Black" />
|
||||
<activity android:name=".ui.modules.feedback.FeedbackActivity"
|
||||
|
@ -1,34 +1,9 @@
|
||||
<h3>Wersja 4.0-rc.4, 2020-03-30</h3>
|
||||
<h3>Wersja 4.4.1, 2020-09-03</h3>
|
||||
<ul>
|
||||
<li>Poprawione pobieranie załączników w Librusie.</li>
|
||||
<li>Nowy widok zadań domowych</li>
|
||||
<li>Możliwość oznaczania zadań domowych i wydarzeń jako wykonane.</li>
|
||||
<li>Poprawione komunikaty o aktualizacjach aplikacji.</li>
|
||||
<li>Mobidziennik: poprawione wyświetlanie przedmiotu w planie lekcji.</li>
|
||||
<li>Mobidziennik: naprawiony moduł frekwencji.</li>
|
||||
</ul>
|
||||
<!--<h3>Wersja 4.0-rc.3, 2020-03-29</h3>
|
||||
<ul>
|
||||
<li><b><u>Wysyłanie wiadomości</u></b> - funkcja, na którą czekał każdy. Od teraz w Szkolnym można wysyłać oraz odpowiadać na wiadomości do nauczycieli 👏</li>
|
||||
<li><b>Przebudowaliśmy cały moduł synchronizacji</b>, co oznacza większą stabilność aplikacji, szybkość oraz poprawność pobieranych danych</li>
|
||||
<li>Udoskonalony wygląd Szkolnego - sprawi, że korzystanie z aplikacji będzie jeszcze przyjemniejsze</li>
|
||||
<li>Nowa <b>Strona główna</b> - ładniejszy wygląd oraz możliwość przestawiania kart na każdym profilu</li>
|
||||
<li>Nowy <b>Plan lekcji</b> - z doskonałą obsługą lekcji przesuniętych oraz dwóch lekcji o tej samej godzinie</li>
|
||||
<li>Nowe <b>Oceny</b> - z możliwością zmiany wartości plusów oraz minusów oraz wyłączenia niektórych ocen ze średniej</li>
|
||||
<li>Opcja wyłączenia wybranych powiadomień z aplikacji</li>
|
||||
<li>Znaczki nieprzeczytanych informacji na obrazkach profili.</li>
|
||||
<br>
|
||||
<br>
|
||||
<li>Nowe okienka informacji o wydarzeniach oraz lekcjach</li>
|
||||
<li>Nowe, przyjemniejsze powiadomienia</li>
|
||||
<li>Dużo poprawek w widoku <b>Wiadomości</b> oraz <b>Ogłoszeń</b></li>
|
||||
<li>Częściowa <b>Obsługa dziennika EduDziennik</b></li>
|
||||
<li>Librus: opcja logowania w dziennikach <b>Jednostek Samorządu Terytorialnego</b> oraz <b>Oświata w Radomiu</b></li>
|
||||
<li>Librus: <b>poprawione obliczanie frekwencji</b></li>
|
||||
<li>Librus: obsługa Zadań domowych bez posiadania Mobilnych dodatków (przez system Synergia)</li>
|
||||
<li>Lepsze <b>przekazywanie powiadomień na komputer</b> oraz łatwiejsze parowanie</li>
|
||||
<li>Łatwiejsze dodawanie własnych wydarzeń</li>
|
||||
<li>Poprawiliśmy synchronizację w tle na niektórych telefonach</li>
|
||||
<li>Usunąłem denerwujący brak zaznaczenia w lewym menu</li>
|
||||
<li>Znaczna ilość błędów z poprzednich wersji już nie występuje</li>
|
||||
</ul>-->
|
||||
<br>
|
||||
<br>
|
||||
Dzięki za korzystanie ze Szkolnego!<br>
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
/*secret password - removed for source code publication*/
|
||||
static toys AES_IV[16] = {
|
||||
0x1c, 0x15, 0x0f, 0x1c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
0x72, 0x4b, 0x61, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
|
||||
unsigned char *agony(unsigned int laugh, unsigned char *box, unsigned char *heat);
|
||||
|
||||
|
@ -43,10 +43,8 @@ import pl.szczodrzynski.edziennik.sync.SyncWorker
|
||||
import pl.szczodrzynski.edziennik.sync.UpdateWorker
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.CrashActivity
|
||||
import pl.szczodrzynski.edziennik.utils.*
|
||||
import pl.szczodrzynski.edziennik.utils.managers.GradesManager
|
||||
import pl.szczodrzynski.edziennik.utils.managers.NotificationChannelsManager
|
||||
import pl.szczodrzynski.edziennik.utils.managers.TimetableManager
|
||||
import pl.szczodrzynski.edziennik.utils.managers.UserActionManager
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.managers.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@ -67,6 +65,9 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
val userActionManager by lazy { UserActionManager(this) }
|
||||
val gradesManager by lazy { GradesManager(this) }
|
||||
val timetableManager by lazy { TimetableManager(this) }
|
||||
val eventManager by lazy { EventManager(this) }
|
||||
val permissionManager by lazy { PermissionManager(this) }
|
||||
val attendanceManager by lazy { AttendanceManager(this) }
|
||||
|
||||
val db
|
||||
get() = App.db
|
||||
@ -101,9 +102,9 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
.followSslRedirects(true)
|
||||
.retryOnConnectionFailure(true)
|
||||
.cookieJar(cookieJar)
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.writeTimeout(5, TimeUnit.SECONDS)
|
||||
.readTimeout(10, TimeUnit.SECONDS)
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.writeTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
builder.installHttpsSupport(this)
|
||||
|
||||
if (debugMode || BuildConfig.DEBUG) {
|
||||
@ -168,7 +169,13 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
db.profileDao().firstId?.let { profileLoadById(it) }
|
||||
}
|
||||
|
||||
devMode = "f054761fbdb6a238" == deviceId || BuildConfig.DEBUG
|
||||
config.ui.language?.let {
|
||||
setLanguage(it)
|
||||
}
|
||||
|
||||
devMode = BuildConfig.DEBUG
|
||||
if (BuildConfig.DEBUG)
|
||||
debugMode = true
|
||||
|
||||
Signing.getCert(this)
|
||||
|
||||
@ -251,6 +258,10 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
val pushMobidziennikApp = FirebaseApp.initializeApp(
|
||||
this@App,
|
||||
FirebaseOptions.Builder()
|
||||
.setProjectId("mobidziennik")
|
||||
.setStorageBucket("mobidziennik.appspot.com")
|
||||
.setDatabaseUrl("https://mobidziennik.firebaseio.com")
|
||||
.setGcmSenderId("747285019373")
|
||||
.setApiKey("AIzaSyCi5LmsZ5BBCQnGtrdvWnp1bWLCNP8OWQE")
|
||||
.setApplicationId("1:747285019373:android:f6341bf7b158621d")
|
||||
.build(),
|
||||
@ -260,6 +271,10 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
val pushLibrusApp = FirebaseApp.initializeApp(
|
||||
this@App,
|
||||
FirebaseOptions.Builder()
|
||||
.setProjectId("synergiadru")
|
||||
.setStorageBucket("synergiadru.appspot.com")
|
||||
.setDatabaseUrl("https://synergiadru.firebaseio.com")
|
||||
.setGcmSenderId("513056078587")
|
||||
.setApiKey("AIzaSyDfTuEoYPKdv4aceEws1CO3n0-HvTndz-o")
|
||||
.setApplicationId("1:513056078587:android:1e29083b760af544")
|
||||
.build(),
|
||||
@ -269,6 +284,10 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
val pushVulcanApp = FirebaseApp.initializeApp(
|
||||
this@App,
|
||||
FirebaseOptions.Builder()
|
||||
.setProjectId("dzienniczekplus")
|
||||
.setStorageBucket("dzienniczekplus.appspot.com")
|
||||
.setDatabaseUrl("https://dzienniczekplus.firebaseio.com")
|
||||
.setGcmSenderId("987828170337")
|
||||
.setApiKey("AIzaSyDW8MUtanHy64_I0oCpY6cOxB3jrvJd_iA")
|
||||
.setApplicationId("1:987828170337:android:ac97431a0a4578c3")
|
||||
.build(),
|
||||
@ -278,10 +297,12 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
try {
|
||||
FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener { instanceIdResult ->
|
||||
val token = instanceIdResult.token
|
||||
d("Firebase", "Got App token: $token")
|
||||
config.sync.tokenApp = token
|
||||
}
|
||||
FirebaseInstanceId.getInstance(pushMobidziennikApp).instanceId.addOnSuccessListener { instanceIdResult ->
|
||||
val token = instanceIdResult.token
|
||||
d("Firebase", "Got Mobidziennik2 token: $token")
|
||||
if (token != config.sync.tokenMobidziennik) {
|
||||
config.sync.tokenMobidziennik = token
|
||||
config.sync.tokenMobidziennikList = listOf()
|
||||
@ -289,6 +310,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
}
|
||||
FirebaseInstanceId.getInstance(pushLibrusApp).instanceId.addOnSuccessListener { instanceIdResult ->
|
||||
val token = instanceIdResult.token
|
||||
d("Firebase", "Got Librus token: $token")
|
||||
if (token != config.sync.tokenLibrus) {
|
||||
config.sync.tokenLibrus = token
|
||||
config.sync.tokenLibrusList = listOf()
|
||||
@ -296,6 +318,7 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
}
|
||||
FirebaseInstanceId.getInstance(pushVulcanApp).instanceId.addOnSuccessListener { instanceIdResult ->
|
||||
val token = instanceIdResult.token
|
||||
d("Firebase", "Got Vulcan token: $token")
|
||||
if (token != config.sync.tokenVulcan) {
|
||||
config.sync.tokenVulcan = token
|
||||
config.sync.tokenVulcanList = listOf()
|
||||
@ -341,6 +364,9 @@ class App : MultiDexApplication(), Configuration.Provider, CoroutineScope {
|
||||
if (!success) {
|
||||
EventBus.getDefault().post(ProfileListEmptyEvent())
|
||||
}
|
||||
else {
|
||||
onSuccess(profile)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun profileSave() = profileSave(profile)
|
||||
|
@ -27,10 +27,7 @@ import android.util.Base64.NO_WRAP
|
||||
import android.util.Base64.encodeToString
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.CheckBox
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TextView
|
||||
import android.widget.*
|
||||
import androidx.annotation.*
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.database.getIntOrNull
|
||||
@ -44,6 +41,8 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.google.android.gms.security.ProviderInstaller
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
@ -167,6 +166,13 @@ fun Bundle?.getString(key: String, defaultValue: String): String {
|
||||
return this?.getString(key, defaultValue) ?: defaultValue
|
||||
}
|
||||
|
||||
fun Bundle?.getIntOrNull(key: String): Int? {
|
||||
return this?.get(key) as? Int
|
||||
}
|
||||
fun <T : Any> Bundle?.get(key: String): T? {
|
||||
return this?.get(key) as? T?
|
||||
}
|
||||
|
||||
/**
|
||||
* ` The quick BROWN_fox Jumps OveR THE LAZy-DOG. `
|
||||
*
|
||||
@ -449,7 +455,7 @@ operator fun MatchResult.get(group: Int): String {
|
||||
return groupValues[group]
|
||||
}
|
||||
|
||||
fun Activity.setLanguage(language: String) {
|
||||
fun Context.setLanguage(language: String) {
|
||||
val locale = Locale(language.toLowerCase(Locale.ROOT))
|
||||
val configuration = resources.configuration
|
||||
Locale.setDefault(locale)
|
||||
@ -458,7 +464,6 @@ fun Activity.setLanguage(language: String) {
|
||||
}
|
||||
configuration.locale = locale
|
||||
resources.updateConfiguration(configuration, resources.displayMetrics)
|
||||
baseContext.resources.updateConfiguration(configuration, baseContext.resources.displayMetrics)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -567,7 +572,7 @@ fun CharSequence?.asBoldSpannable(): Spannable {
|
||||
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, spannable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
return spannable
|
||||
}
|
||||
fun CharSequence.asSpannable(vararg spans: Any, substring: String? = null, ignoreCase: Boolean = false): Spannable {
|
||||
fun CharSequence.asSpannable(vararg spans: Any, substring: String? = null, ignoreCase: Boolean = false, ignoreDiacritics: Boolean = false): Spannable {
|
||||
val spannable = SpannableString(this)
|
||||
if (substring == null) {
|
||||
spans.forEach {
|
||||
@ -575,17 +580,44 @@ fun CharSequence.asSpannable(vararg spans: Any, substring: String? = null, ignor
|
||||
}
|
||||
}
|
||||
else if (substring.isNotEmpty()) {
|
||||
var index = indexOf(substring, ignoreCase = ignoreCase)
|
||||
val string =
|
||||
if (ignoreDiacritics)
|
||||
this.cleanDiacritics()
|
||||
else this
|
||||
|
||||
var index = string.indexOf(substring, ignoreCase = ignoreCase)
|
||||
.takeIf { it != -1 } ?: indexOf(substring, ignoreCase = ignoreCase)
|
||||
while (index >= 0) {
|
||||
spans.forEach {
|
||||
spannable.setSpan(it, index, index + substring.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
index = indexOf(substring, startIndex = index + 1, ignoreCase = ignoreCase)
|
||||
index = string.indexOf(substring, startIndex = index + 1, ignoreCase = ignoreCase)
|
||||
.takeIf { it != -1 } ?: indexOf(substring, startIndex = index + 1, ignoreCase = ignoreCase)
|
||||
}
|
||||
}
|
||||
return spannable
|
||||
}
|
||||
|
||||
fun CharSequence.cleanDiacritics(): String {
|
||||
val nameClean = StringBuilder()
|
||||
forEach {
|
||||
val ch = when (it) {
|
||||
'ż' -> 'z'
|
||||
'ó' -> 'o'
|
||||
'ł' -> 'l'
|
||||
'ć' -> 'c'
|
||||
'ę' -> 'e'
|
||||
'ś' -> 's'
|
||||
'ą' -> 'a'
|
||||
'ź' -> 'z'
|
||||
'ń' -> 'n'
|
||||
else -> it
|
||||
}
|
||||
nameClean.append(ch)
|
||||
}
|
||||
return nameClean.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new read-only list only of those given elements, that are not empty.
|
||||
* Applies for CharSequence and descendants.
|
||||
@ -641,6 +673,16 @@ fun TextView.setText(@StringRes resid: Int, vararg formatArgs: Any) {
|
||||
text = context.getString(resid, *formatArgs)
|
||||
}
|
||||
|
||||
fun MaterialAlertDialogBuilder.setTitle(@StringRes resid: Int, vararg formatArgs: Any): MaterialAlertDialogBuilder {
|
||||
setTitle(context.getString(resid, *formatArgs))
|
||||
return this
|
||||
}
|
||||
|
||||
fun MaterialAlertDialogBuilder.setMessage(@StringRes resid: Int, vararg formatArgs: Any): MaterialAlertDialogBuilder {
|
||||
setMessage(context.getString(resid, *formatArgs))
|
||||
return this
|
||||
}
|
||||
|
||||
fun JsonObject(vararg properties: Pair<String, Any?>): JsonObject {
|
||||
return JsonObject().apply {
|
||||
for (property in properties) {
|
||||
@ -743,6 +785,19 @@ inline fun <T : CompoundButton> T.onChange(crossinline onChangeListener: (v: T,
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T : MaterialButton> T.onChange(crossinline onChangeListener: (v: T, isChecked: Boolean) -> Unit) {
|
||||
clearOnCheckedChangeListeners()
|
||||
addOnCheckedChangeListener { buttonView, isChecked ->
|
||||
onChangeListener(buttonView as T, isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
fun View.attachToastHint(stringRes: Int) = onLongClick {
|
||||
Toast.makeText(it.context, stringRes, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) {
|
||||
observe(lifecycleOwner, object : Observer<T> {
|
||||
override fun onChanged(t: T?) {
|
||||
@ -798,7 +853,7 @@ fun View.findParentById(targetId: Int): View? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun CoroutineScope.startCoroutineTimer(delayMillis: Long = 0, repeatMillis: Long = 0, action: () -> Unit) = launch {
|
||||
fun CoroutineScope.startCoroutineTimer(delayMillis: Long = 0, repeatMillis: Long = 0, action: suspend CoroutineScope.() -> Unit) = launch {
|
||||
delay(delayMillis)
|
||||
if (repeatMillis > 0) {
|
||||
while (true) {
|
||||
@ -1197,3 +1252,9 @@ val SwipeRefreshLayout.onScrollListener: RecyclerView.OnScrollListener
|
||||
this@onScrollListener.isEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
operator fun <K, V> Iterable<Pair<K, V>>.get(key: K): V? {
|
||||
return firstOrNull { it.first == key }?.second
|
||||
}
|
||||
|
||||
fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }
|
||||
|
@ -18,9 +18,9 @@ import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.danimahardhika.cafebar.CafeBar
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.mikepenz.iconics.IconicsColor
|
||||
@ -41,13 +41,18 @@ import pl.droidsonroids.gif.GifDrawable
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.api.events.*
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.databinding.ActivitySzkolnyBinding
|
||||
import pl.szczodrzynski.edziennik.sync.AppManagerDetectedEvent
|
||||
import pl.szczodrzynski.edziennik.sync.SyncWorker
|
||||
import pl.szczodrzynski.edziennik.sync.UpdateWorker
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.RegisterUnavailableDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.ServerMessageDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.UpdateAvailableDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog
|
||||
@ -55,9 +60,10 @@ import pl.szczodrzynski.edziennik.ui.dialogs.sync.SyncViewListDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.agenda.AgendaFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.announcements.AnnouncementsFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.DebugFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.MainSnackbar
|
||||
import pl.szczodrzynski.edziennik.ui.modules.behaviour.BehaviourFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.DebugFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.LabFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.error.ErrorSnackbar
|
||||
import pl.szczodrzynski.edziennik.ui.modules.feedback.FeedbackFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.feedback.HelpFragment
|
||||
@ -67,13 +73,11 @@ import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.HomeworkFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginActivity
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessageFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesListFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.compose.MessagesComposeFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.notifications.NotificationsListFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.ProfileManagerFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.SettingsNewFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.template.TemplateFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.webpush.WebPushFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
@ -130,7 +134,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
const val TARGET_MESSAGES_DETAILS = 503
|
||||
const val TARGET_MESSAGES_COMPOSE = 504
|
||||
const val TARGET_WEB_PUSH = 140
|
||||
const val TARGET_TEMPLATE = 1000
|
||||
const val TARGET_LAB = 1000
|
||||
|
||||
const val HOME_ID = DRAWER_ITEM_HOME
|
||||
|
||||
@ -228,10 +232,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
list += NavTarget(TARGET_MESSAGES_DETAILS, R.string.menu_message, MessageFragment::class).withPopTo(DRAWER_ITEM_MESSAGES)
|
||||
list += NavTarget(TARGET_MESSAGES_COMPOSE, R.string.menu_message_compose, MessagesComposeFragment::class)
|
||||
list += NavTarget(TARGET_WEB_PUSH, R.string.menu_web_push, WebPushFragment::class)
|
||||
list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
|
||||
if (App.devMode) {
|
||||
list += NavTarget(TARGET_TEMPLATE, R.string.menu_template, TemplateFragment::class)
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_test_tube_empty)
|
||||
if (App.debugMode) {
|
||||
list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
|
||||
list += NavTarget(TARGET_LAB, R.string.menu_lab, LabFragment::class)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_flask_outline)
|
||||
.isInDrawer(true)
|
||||
.isBelowSeparator(true)
|
||||
.isStatic(true)
|
||||
@ -296,6 +300,22 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
mainSnackbar.setCoordinator(b.navView.coordinator, b.navView.bottomBar)
|
||||
errorSnackbar.setCoordinator(b.navView.coordinator, b.navView.bottomBar)
|
||||
|
||||
when {
|
||||
BuildConfig.VERSION_NAME.contains("nightly") -> {
|
||||
b.nightlyText.isVisible = true
|
||||
b.nightlyText.text = "Nightly\n"+BuildConfig.VERSION_NAME.substringAfterLast(".")
|
||||
}
|
||||
BuildConfig.VERSION_NAME.contains("daily") -> {
|
||||
b.nightlyText.isVisible = true
|
||||
b.nightlyText.text = "Daily\n"+BuildConfig.VERSION_NAME.substringAfterLast(".")
|
||||
}
|
||||
BuildConfig.DEBUG -> {
|
||||
b.nightlyText.isVisible = true
|
||||
b.nightlyText.text = "Debug\n"+BuildConfig.VERSION_NAME
|
||||
}
|
||||
else -> b.nightlyText.isVisible = false
|
||||
}
|
||||
|
||||
navLoading = true
|
||||
|
||||
b.navView.apply {
|
||||
@ -393,7 +413,20 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
}
|
||||
|
||||
app.db.profileDao().all.observe(this, Observer { profiles ->
|
||||
drawer.setProfileList(profiles.filter { it.id >= 0 }.toMutableList())
|
||||
val allArchived = profiles.all { it.archived }
|
||||
drawer.setProfileList(profiles.filter { it.id >= 0 && (!it.archived || allArchived) }.toMutableList())
|
||||
//prepend the archived profile if loaded
|
||||
if (app.profile.archived && !allArchived) {
|
||||
drawer.prependProfile(Profile(
|
||||
id = app.profile.id,
|
||||
loginStoreId = app.profile.loginStoreId,
|
||||
loginStoreType = app.profile.loginStoreType,
|
||||
name = app.profile.name,
|
||||
subname = "Archiwum - ${app.profile.subname}"
|
||||
).also {
|
||||
it.archived = true
|
||||
})
|
||||
}
|
||||
drawer.currentProfile = App.profileId
|
||||
})
|
||||
|
||||
@ -409,18 +442,33 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
})
|
||||
|
||||
b.swipeRefreshLayout.isEnabled = true
|
||||
b.swipeRefreshLayout.setOnRefreshListener { this.syncCurrentFeature() }
|
||||
b.swipeRefreshLayout.setOnRefreshListener { launch { syncCurrentFeature() } }
|
||||
b.swipeRefreshLayout.setColorSchemeResources(
|
||||
R.color.md_blue_500,
|
||||
R.color.md_amber_500,
|
||||
R.color.md_green_500
|
||||
)
|
||||
|
||||
isStoragePermissionGranted()
|
||||
|
||||
SyncWorker.scheduleNext(app)
|
||||
UpdateWorker.scheduleNext(app)
|
||||
|
||||
// if loaded profile is archived, switch to the up-to-date version of it
|
||||
if (app.profile.archived) {
|
||||
launch {
|
||||
if (app.profile.archiveId != null) {
|
||||
val profile = withContext(Dispatchers.IO) {
|
||||
app.db.profileDao().getNotArchivedOf(app.profile.archiveId!!)
|
||||
}
|
||||
if (profile != null)
|
||||
loadProfile(profile)
|
||||
else
|
||||
loadProfile(0)
|
||||
} else {
|
||||
loadProfile(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// APP BACKGROUND
|
||||
if (app.config.ui.appBackground != null) {
|
||||
try {
|
||||
@ -518,7 +566,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_help_circle_outline)
|
||||
.withOnClickListener(View.OnClickListener { loadTarget(TARGET_FEEDBACK) })
|
||||
)
|
||||
if (App.devMode) {
|
||||
if (App.debugMode) {
|
||||
bottomSheet += BottomSheetPrimaryItem(false)
|
||||
.withTitle(R.string.menu_debug)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_android_studio)
|
||||
@ -560,7 +608,66 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
|_____/ \__, |_| |_|\___|
|
||||
__/ |
|
||||
|__*/
|
||||
fun syncCurrentFeature() {
|
||||
suspend fun syncCurrentFeature() {
|
||||
if (app.profile.archived) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.profile_archived_title)
|
||||
.setMessage(
|
||||
R.string.profile_archived_text,
|
||||
app.profile.studentSchoolYearStart,
|
||||
app.profile.studentSchoolYearStart + 1
|
||||
)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
return
|
||||
}
|
||||
if (app.profile.shouldArchive()) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.profile_archiving_title)
|
||||
.setMessage(
|
||||
R.string.profile_archiving_format,
|
||||
app.profile.dateYearEnd.formattedString
|
||||
)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
if (app.profile.isBeforeYear()) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.profile_year_not_started_title)
|
||||
.setMessage(
|
||||
R.string.profile_year_not_started_format,
|
||||
app.profile.dateSemester1Start.formattedString
|
||||
)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
return
|
||||
}
|
||||
|
||||
app.profile.registerName?.let { registerName ->
|
||||
var status = app.config.sync.registerAvailability[registerName]
|
||||
if (status == null || status.nextCheck < currentTimeUnix()) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val api = SzkolnyApi(app)
|
||||
api.runCatching(this@MainActivity) {
|
||||
val availability = getRegisterAvailability()
|
||||
app.config.sync.registerAvailability = availability
|
||||
status = availability[registerName]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status?.available != true
|
||||
|| status?.minVersionCode ?: BuildConfig.VERSION_CODE > BuildConfig.VERSION_CODE) {
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
loadTarget(DRAWER_ITEM_HOME)
|
||||
if (status != null)
|
||||
RegisterUnavailableDialog(this, status!!)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
swipeRefreshLayout.isRefreshing = true
|
||||
Toast.makeText(this, fragmentToSyncName(navTargetId), Toast.LENGTH_SHORT).show()
|
||||
val fragmentParam = when (navTargetId) {
|
||||
@ -577,6 +684,20 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
arguments = arguments
|
||||
).enqueue(this)
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onUpdateEvent(event: Update) {
|
||||
EventBus.getDefault().removeStickyEvent(event)
|
||||
UpdateAvailableDialog(this, event)
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onRegisterAvailabilityEvent(event: RegisterAvailabilityEvent) {
|
||||
EventBus.getDefault().removeStickyEvent(event)
|
||||
app.profile.registerName?.let { registerName ->
|
||||
event.data[registerName]?.let {
|
||||
RegisterUnavailableDialog(this, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onApiTaskStartedEvent(event: ApiTaskStartedEvent) {
|
||||
swipeRefreshLayout.isRefreshing = true
|
||||
@ -881,26 +1002,51 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
|
||||
fun loadProfile(id: Int) = loadProfile(id, navTargetId)
|
||||
fun loadProfile(id: Int, arguments: Bundle?) = loadProfile(id, navTargetId, arguments)
|
||||
fun loadProfile(id: Int, drawerSelection: Int, arguments: Bundle? = null) {
|
||||
fun loadProfile(profile: Profile) = loadProfile(
|
||||
profile,
|
||||
navTargetId,
|
||||
null,
|
||||
if (app.profile.archived) app.profile.id else null
|
||||
)
|
||||
private fun loadProfile(id: Int, drawerSelection: Int, arguments: Bundle? = null) {
|
||||
if (App.profileId == id) {
|
||||
drawer.currentProfile = app.profile.id
|
||||
loadTarget(drawerSelection, arguments)
|
||||
return
|
||||
}
|
||||
val previousArchivedId = if (app.profile.archived) app.profile.id else null
|
||||
app.profileLoad(id) {
|
||||
MessagesFragment.pageSelection = -1
|
||||
MessagesListFragment.tapPositions = intArrayOf(RecyclerView.NO_POSITION, RecyclerView.NO_POSITION)
|
||||
MessagesListFragment.topPositions = intArrayOf(RecyclerView.NO_POSITION, RecyclerView.NO_POSITION)
|
||||
MessagesListFragment.bottomPositions = intArrayOf(RecyclerView.NO_POSITION, RecyclerView.NO_POSITION)
|
||||
|
||||
setDrawerItems()
|
||||
// the drawer profile is updated automatically when the drawer item is clicked
|
||||
// update it manually when switching profiles from other source
|
||||
//if (drawer.currentProfile != app.profile.id)
|
||||
drawer.currentProfile = app.profileId
|
||||
loadTarget(drawerSelection, arguments)
|
||||
loadProfile(it, drawerSelection, arguments, previousArchivedId)
|
||||
}
|
||||
}
|
||||
private fun loadProfile(profile: Profile, drawerSelection: Int, arguments: Bundle?, previousArchivedId: Int?) {
|
||||
App.profile = profile
|
||||
MessagesFragment.pageSelection = -1
|
||||
|
||||
setDrawerItems()
|
||||
|
||||
if (previousArchivedId != null) {
|
||||
// prevents accidentally removing the first item if the archived profile is not shown
|
||||
drawer.removeProfileById(previousArchivedId)
|
||||
}
|
||||
if (profile.archived) {
|
||||
drawer.prependProfile(Profile(
|
||||
id = profile.id,
|
||||
loginStoreId = profile.loginStoreId,
|
||||
loginStoreType = profile.loginStoreType,
|
||||
name = profile.name,
|
||||
subname = "Archiwum - ${profile.subname}"
|
||||
).also {
|
||||
it.archived = true
|
||||
})
|
||||
}
|
||||
|
||||
// the drawer profile is updated automatically when the drawer item is clicked
|
||||
// update it manually when switching profiles from other source
|
||||
//if (drawer.currentProfile != app.profile.id)
|
||||
drawer.currentProfile = app.profileId
|
||||
loadTarget(drawerSelection, arguments)
|
||||
}
|
||||
fun loadTarget(id: Int, arguments: Bundle? = null) {
|
||||
var loadId = id
|
||||
if (loadId == -1) {
|
||||
@ -916,9 +1062,10 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
loadTarget(target, arguments)
|
||||
}
|
||||
}
|
||||
private fun loadTarget(target: NavTarget, arguments: Bundle? = null) {
|
||||
d("NavDebug", "loadTarget(target = $target, arguments = $arguments)")
|
||||
private fun loadTarget(target: NavTarget, args: Bundle? = null) {
|
||||
d("NavDebug", "loadTarget(target = $target, args = $args)")
|
||||
|
||||
val arguments = args ?: navBackStack.firstOrNull { it.first.id == target.id }?.second ?: Bundle()
|
||||
bottomSheet.close()
|
||||
bottomSheet.removeAllContextual()
|
||||
bottomSheet.toggleGroupEnabled = false
|
||||
@ -966,6 +1113,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
navBackStack.removeAt(navBackStack.lastIndex)
|
||||
}
|
||||
navTarget = target
|
||||
navArguments = arguments
|
||||
|
||||
return@let null
|
||||
}?.let {
|
||||
@ -975,7 +1123,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
R.anim.task_open_enter,
|
||||
R.anim.task_open_exit
|
||||
)
|
||||
navBackStack.add(navTarget to arguments)
|
||||
navBackStack.add(navTarget to navArguments)
|
||||
navTarget = target
|
||||
navArguments = arguments
|
||||
}
|
||||
|
@ -4,12 +4,18 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.config
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import pl.szczodrzynski.edziennik.config.utils.get
|
||||
import pl.szczodrzynski.edziennik.config.utils.getIntList
|
||||
import pl.szczodrzynski.edziennik.config.utils.set
|
||||
import pl.szczodrzynski.edziennik.config.utils.setMap
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.RegisterAvailabilityStatus
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class ConfigSync(private val config: Config) {
|
||||
private val gson = Gson()
|
||||
|
||||
private var mDontShowAppManagerDialog: Boolean? = null
|
||||
var dontShowAppManagerDialog: Boolean
|
||||
get() { mDontShowAppManagerDialog = mDontShowAppManagerDialog ?: config.values.get("dontShowAppManagerDialog", false); return mDontShowAppManagerDialog ?: false }
|
||||
@ -106,4 +112,9 @@ class ConfigSync(private val config: Config) {
|
||||
var tokenVulcanList: List<Int>
|
||||
get() { mTokenVulcanList = mTokenVulcanList ?: config.values.getIntList("tokenVulcanList", listOf()); return mTokenVulcanList ?: listOf() }
|
||||
set(value) { config.set("tokenVulcanList", value); mTokenVulcanList = value }
|
||||
|
||||
private var mRegisterAvailability: Map<String, RegisterAvailabilityStatus>? = null
|
||||
var registerAvailability: Map<String, RegisterAvailabilityStatus>
|
||||
get() { mRegisterAvailability = mRegisterAvailability ?: config.values.get("registerAvailability", null as String?)?.let { it -> gson.fromJson<Map<String, RegisterAvailabilityStatus>>(it, object: TypeToken<Map<String, RegisterAvailabilityStatus>>(){}.type) }; return mRegisterAvailability ?: mapOf() }
|
||||
set(value) { config.setMap("registerAvailability", value); mRegisterAvailability = value }
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class ProfileConfig(val db: AppDb, val profileId: Int, rawEntries: List<ConfigEn
|
||||
val grades by lazy { ProfileConfigGrades(this) }
|
||||
val ui by lazy { ProfileConfigUI(this) }
|
||||
val sync by lazy { ProfileConfigSync(this) }
|
||||
val attendance by lazy { ProfileConfigAttendance(this) }
|
||||
/*
|
||||
val timetable by lazy { ConfigTimetable(this) }
|
||||
val grades by lazy { ConfigGrades(this) }*/
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-4-29.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.config
|
||||
|
||||
import pl.szczodrzynski.edziennik.config.utils.get
|
||||
import pl.szczodrzynski.edziennik.config.utils.set
|
||||
|
||||
class ProfileConfigAttendance(private val config: ProfileConfig) {
|
||||
private var mAttendancePageSelection: Int? = null
|
||||
var attendancePageSelection: Int
|
||||
get() { mAttendancePageSelection = mAttendancePageSelection ?: config.values.get("attendancePageSelection", 1); return mAttendancePageSelection ?: 1 }
|
||||
set(value) { config.set("attendancePageSelection", value); mAttendancePageSelection = value }
|
||||
|
||||
private var mUseSymbols: Boolean? = null
|
||||
var useSymbols: Boolean
|
||||
get() { mUseSymbols = mUseSymbols ?: config.values.get("useSymbols", false); return mUseSymbols ?: false }
|
||||
set(value) { config.set("useSymbols", value); mUseSymbols = value }
|
||||
|
||||
private var mGroupConsecutiveDays: Boolean? = null
|
||||
var groupConsecutiveDays: Boolean
|
||||
get() { mGroupConsecutiveDays = mGroupConsecutiveDays ?: config.values.get("groupConsecutiveDays", true); return mGroupConsecutiveDays ?: true }
|
||||
set(value) { config.set("groupConsecutiveDays", value); mGroupConsecutiveDays = value }
|
||||
|
||||
private var mShowPresenceInMonth: Boolean? = null
|
||||
var showPresenceInMonth: Boolean
|
||||
get() { mShowPresenceInMonth = mShowPresenceInMonth ?: config.values.get("showPresenceInMonth", false); return mShowPresenceInMonth ?: false }
|
||||
set(value) { config.set("showPresenceInMonth", value); mShowPresenceInMonth = value }
|
||||
}
|
@ -49,6 +49,9 @@ fun AbstractConfig.setIntList(key: String, value: List<Int>?) {
|
||||
fun AbstractConfig.setLongList(key: String, value: List<Long>?) {
|
||||
set(key, value?.let { gson.toJson(it) })
|
||||
}
|
||||
fun <K, V> AbstractConfig.setMap(key: String, value: Map<K, V>?) {
|
||||
set(key, value?.let { gson.toJson(it) })
|
||||
}
|
||||
|
||||
fun HashMap<String, String?>.get(key: String, default: String?): String? {
|
||||
return this[key] ?: default
|
||||
|
@ -38,6 +38,9 @@ class ApiService : Service() {
|
||||
context.startService(Intent(context, ApiService::class.java))
|
||||
EventBus.getDefault().postSticky(request)
|
||||
}
|
||||
|
||||
var lastEventTime = System.currentTimeMillis()
|
||||
var taskCancelTries = 0
|
||||
}
|
||||
|
||||
private val app by lazy { applicationContext as App }
|
||||
@ -64,9 +67,6 @@ class ApiService : Service() {
|
||||
|
||||
private val notification by lazy { EdziennikNotification(app) }
|
||||
|
||||
private var lastEventTime = System.currentTimeMillis()
|
||||
private var taskCancelTries = 0
|
||||
|
||||
/* ______ _ _ _ _ _____ _ _ _ _
|
||||
| ____| | | (_) (_) | / ____| | | | | | |
|
||||
| |__ __| |_____ ___ _ __ _ __ _| | __ | | __ _| | | |__ __ _ ___| | __
|
||||
|
@ -24,14 +24,14 @@ const val FAKE_LIBRUS_ACCOUNTS = "/synergia_accounts.php"
|
||||
|
||||
val LIBRUS_USER_AGENT = "${SYSTEM_USER_AGENT}LibrusMobileApp"
|
||||
const val SYNERGIA_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101 Firefox/62.0"
|
||||
const val LIBRUS_CLIENT_ID = "6XPsKf10LPz1nxgHQLcvZ1KM48DYzlBAhxipaXY8"
|
||||
const val LIBRUS_REDIRECT_URL = "http://localhost/bar"
|
||||
const val LIBRUS_CLIENT_ID = "0RbsDOkV9tyKEQYzlLv5hs3DM1ukrynFI4p6C1Yc"
|
||||
const val LIBRUS_REDIRECT_URL = "app://librus"
|
||||
const val LIBRUS_AUTHORIZE_URL = "https://portal.librus.pl/oauth2/authorize?client_id=$LIBRUS_CLIENT_ID&redirect_uri=$LIBRUS_REDIRECT_URL&response_type=code"
|
||||
const val LIBRUS_LOGIN_URL = "https://portal.librus.pl/rodzina/login/action"
|
||||
const val LIBRUS_TOKEN_URL = "https://portal.librus.pl/oauth2/access_token"
|
||||
|
||||
const val LIBRUS_ACCOUNT_URL = "/v2/SynergiaAccounts/fresh/" // + login
|
||||
const val LIBRUS_ACCOUNTS_URL = "/v2/SynergiaAccounts"
|
||||
const val LIBRUS_ACCOUNT_URL = "/v3/SynergiaAccounts/fresh/" // + login
|
||||
const val LIBRUS_ACCOUNTS_URL = "/v3/SynergiaAccounts"
|
||||
|
||||
/** https://api.librus.pl/2.0 */
|
||||
const val LIBRUS_API_URL = "https://api.librus.pl/2.0"
|
||||
@ -56,6 +56,9 @@ const val LIBRUS_SYNERGIA_TOKEN_LOGIN_URL = "https://synergia.librus.pl/loguj/to
|
||||
const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module"
|
||||
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
||||
|
||||
const val LIBRUS_SYNERGIA_HOMEWORK_ATTACHMENT_URL = "https://synergia.librus.pl/homework/downloadFile"
|
||||
const val LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL = "https://synergia.librus.pl/wiadomosci/pobierz_zalacznik"
|
||||
|
||||
const val IDZIENNIK_USER_AGENT = SYNERGIA_USER_AGENT
|
||||
const val IDZIENNIK_WEB_URL = "https://iuczniowie.progman.pl/idziennik"
|
||||
const val IDZIENNIK_WEB_LOGIN = "login.aspx"
|
||||
@ -74,6 +77,8 @@ const val IDZIENNIK_WEB_GET_MESSAGE = "mod_komunikator/WS_wiadomosci.asmx/Pobier
|
||||
const val IDZIENNIK_WEB_GET_RECIPIENT_LIST = "mod_komunikator/WS_wiadomosci.asmx/pobierzListeOdbiorcowPanelRodzic"
|
||||
const val IDZIENNIK_WEB_SEND_MESSAGE = "mod_komunikator/WS_wiadomosci.asmx/WyslijWiadomosc"
|
||||
const val IDZIENNIK_WEB_GET_ATTACHMENT = "mod_komunikator/Download.ashx"
|
||||
const val IDZIENNIK_WEB_GET_HOMEWORK = "mod_panelRodzica/pracaDomowa/WS_pracaDomowa.asmx/pobierzJednaPraceDomowa"
|
||||
const val IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT = "mod_panelRodzica/pracaDomowa.aspx"
|
||||
|
||||
val IDZIENNIK_API_USER_AGENT = SYSTEM_USER_AGENT
|
||||
const val IDZIENNIK_API_URL = "https://iuczniowie.progman.pl/idziennik/api"
|
||||
@ -87,7 +92,7 @@ val MOBIDZIENNIK_USER_AGENT = SYSTEM_USER_AGENT
|
||||
|
||||
const val VULCAN_API_USER_AGENT = "MobileUserAgent"
|
||||
const val VULCAN_API_APP_NAME = "VULCAN-Android-ModulUcznia"
|
||||
const val VULCAN_API_APP_VERSION = "19.4.1.436"
|
||||
const val VULCAN_API_APP_VERSION = "20.5.1.470"
|
||||
const val VULCAN_API_PASSWORD = "CE75EA598C7743AD9B0B7328DED85B06"
|
||||
const val VULCAN_API_PASSWORD_FAKELOG = "012345678901234567890123456789AB"
|
||||
val VULCAN_API_DEVICE_NAME = "Szkolny.eu ${Build.MODEL}"
|
||||
@ -107,5 +112,13 @@ const val VULCAN_API_ENDPOINT_MESSAGES_SENT = "mobile-api/Uczen.v3.Uczen/Wiadomo
|
||||
const val VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS = "mobile-api/Uczen.v3.Uczen/ZmienStatusWiadomosci"
|
||||
const val VULCAN_API_ENDPOINT_MESSAGES_ADD = "mobile-api/Uczen.v3.Uczen/DodajWiadomosc"
|
||||
const val VULCAN_API_ENDPOINT_PUSH = "mobile-api/Uczen.v3.Uczen/UstawPushToken"
|
||||
const val VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS = "mobile-api/Uczen.v3.Uczen/WiadomosciZalacznik"
|
||||
const val VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS = "mobile-api/Uczen.v3.Uczen/ZadaniaDomoweZalacznik"
|
||||
const val VULCAN_WEB_ENDPOINT_LUCKY_NUMBER = "Start.mvc/GetKidsLuckyNumbers"
|
||||
const val VULCAN_WEB_ENDPOINT_REGISTER_DEVICE = "RejestracjaUrzadzeniaToken.mvc/Get"
|
||||
|
||||
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
||||
const val PODLASIE_API_VERSION = "1.0.31"
|
||||
const val PODLASIE_API_URL = "https://cpdklaser.zeto.bialystok.pl/api"
|
||||
const val PODLASIE_API_USER_ENDPOINT = "/pobierzDaneUcznia"
|
||||
|
@ -8,11 +8,12 @@ import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationCompat.PRIORITY_MIN
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.Bundle
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
@ -35,16 +36,18 @@ class EdziennikNotification(val app: App) {
|
||||
var serviceClosed = false
|
||||
|
||||
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
||||
intent.putExtra("task", "TaskCancelRequest")
|
||||
intent.putExtra("taskId", taskId)
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
||||
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||
"task" to "TaskCancelRequest",
|
||||
"taskId" to taskId
|
||||
))
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) as PendingIntent
|
||||
}
|
||||
private val closePendingIntent: PendingIntent
|
||||
get() {
|
||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
||||
intent.putExtra("task", "ServiceCloseRequest")
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
||||
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||
"task" to "ServiceCloseRequest"
|
||||
))
|
||||
return PendingIntent.getBroadcast(app, 0, intent, 0) as PendingIntent
|
||||
}
|
||||
|
||||
private fun errorCountText(): String? {
|
||||
|
@ -126,6 +126,8 @@ const val ERROR_LOGIN_LIBRUS_PORTAL_CSRF_EXPIRED = 184
|
||||
const val ERROR_LIBRUS_API_DEVICE_REGISTERED = 185
|
||||
const val ERROR_LIBRUS_MESSAGES_NOT_FOUND = 186
|
||||
const val ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST = 187
|
||||
const val ERROR_LIBRUS_MESSAGES_ATTACHMENT_NOT_FOUND = 188
|
||||
const val ERROR_LOGIN_LIBRUS_MESSAGES_TIMEOUT = 189
|
||||
|
||||
const val ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN = 201
|
||||
const val ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD = 202
|
||||
@ -157,6 +159,17 @@ const val ERROR_LOGIN_VULCAN_NO_PUPILS = 331
|
||||
const val ERROR_VULCAN_API_MAINTENANCE = 340
|
||||
const val ERROR_VULCAN_API_BAD_REQUEST = 341
|
||||
const val ERROR_VULCAN_API_OTHER = 342
|
||||
const val ERROR_VULCAN_ATTACHMENT_DOWNLOAD = 343
|
||||
const val ERROR_VULCAN_WEB_DATA_MISSING = 344
|
||||
const val ERROR_VULCAN_WEB_429 = 345
|
||||
const val ERROR_VULCAN_WEB_OTHER = 346
|
||||
const val ERROR_VULCAN_WEB_NO_CERTIFICATE = 347
|
||||
const val ERROR_VULCAN_WEB_NO_REGISTER = 348
|
||||
const val ERROR_VULCAN_WEB_CERTIFICATE_EXPIRED = 349
|
||||
const val ERROR_VULCAN_WEB_LOGGED_OUT = 350
|
||||
const val ERROR_VULCAN_WEB_CERTIFICATE_POST_FAILED = 351
|
||||
const val ERROR_VULCAN_WEB_GRADUATE_ACCOUNT = 352
|
||||
const val ERROR_VULCAN_WEB_NO_SCHOOLS = 353
|
||||
|
||||
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN = 401
|
||||
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME = 402
|
||||
@ -187,6 +200,12 @@ const val ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS = 521
|
||||
const val ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED = 522
|
||||
const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530
|
||||
|
||||
const val ERROR_LOGIN_PODLASIE_API_INVALID_TOKEN = 601
|
||||
const val ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT = 602
|
||||
const val ERROR_PODLASIE_API_NO_TOKEN = 630
|
||||
const val ERROR_PODLASIE_API_OTHER = 631
|
||||
const val ERROR_PODLASIE_API_DATA_MISSING = 632
|
||||
|
||||
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
||||
|
||||
const val EXCEPTION_API_TASK = 900
|
||||
@ -206,5 +225,9 @@ const val EXCEPTION_IDZIENNIK_WEB_API_REQUEST = 913
|
||||
const val EXCEPTION_IDZIENNIK_API_REQUEST = 914
|
||||
const val EXCEPTION_EDUDZIENNIK_WEB_REQUEST = 920
|
||||
const val EXCEPTION_EDUDZIENNIK_FILE_REQUEST = 921
|
||||
const val ERROR_ONEDRIVE_DOWNLOAD = 930
|
||||
const val EXCEPTION_VULCAN_WEB_LOGIN = 931
|
||||
const val EXCEPTION_VULCAN_WEB_REQUEST = 932
|
||||
const val EXCEPTION_PODLASIE_API_REQUEST = 940
|
||||
|
||||
const val LOGIN_NO_ARGUMENTS = 1201
|
||||
|
@ -13,8 +13,8 @@ import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOME
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
||||
|
||||
internal const val FEATURE_TIMETABLE = 1
|
||||
internal const val FEATURE_AGENDA = 2
|
||||
|
@ -13,9 +13,11 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginPor
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLoginApi2
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLoginWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login.PodlasieLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.login.TemplateLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.login.TemplateLoginWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginWebMain
|
||||
import pl.szczodrzynski.edziennik.data.api.models.LoginMethod
|
||||
|
||||
// librus
|
||||
@ -27,7 +29,6 @@ import pl.szczodrzynski.edziennik.data.api.models.LoginMethod
|
||||
const val SYNERGIA_API_ENABLED = false
|
||||
|
||||
|
||||
|
||||
const val LOGIN_TYPE_IDZIENNIK = 3
|
||||
|
||||
const val LOGIN_TYPE_TEMPLATE = 21
|
||||
@ -103,11 +104,11 @@ const val LOGIN_METHOD_VULCAN_WEB_OLD = 300
|
||||
const val LOGIN_METHOD_VULCAN_WEB_MESSAGES = 400
|
||||
const val LOGIN_METHOD_VULCAN_API = 500
|
||||
val vulcanLoginMethods = listOf(
|
||||
/*LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_WEB_MAIN, VulcanLoginWebMain::class.java)
|
||||
.withIsPossible { _, _ -> false }
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_WEB_MAIN, VulcanLoginWebMain::class.java)
|
||||
.withIsPossible { _, loginStore -> loginStore.hasLoginData("webHost") }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED },
|
||||
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_WEB_NEW, VulcanLoginWebNew::class.java)
|
||||
/*LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_WEB_NEW, VulcanLoginWebNew::class.java)
|
||||
.withIsPossible { _, _ -> false }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_VULCAN_WEB_MAIN },
|
||||
|
||||
@ -118,7 +119,7 @@ val vulcanLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_API, VulcanLoginApi::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withRequiredLoginMethod { _, loginStore ->
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_WEB) LOGIN_METHOD_VULCAN_WEB_NEW else LOGIN_METHOD_NOT_NEEDED
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_WEB) LOGIN_METHOD_VULCAN_WEB_MAIN else LOGIN_METHOD_NOT_NEEDED
|
||||
}
|
||||
)
|
||||
|
||||
@ -133,6 +134,7 @@ val idziennikLoginMethods = listOf(
|
||||
)
|
||||
|
||||
const val LOGIN_TYPE_EDUDZIENNIK = 5
|
||||
const val LOGIN_MODE_EDUDZIENNIK_WEB = 0
|
||||
const val LOGIN_METHOD_EDUDZIENNIK_WEB = 100
|
||||
val edudziennikLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_EDUDZIENNIK, LOGIN_METHOD_EDUDZIENNIK_WEB, EdudziennikLoginWeb::class.java)
|
||||
@ -140,6 +142,15 @@ val edudziennikLoginMethods = listOf(
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
)
|
||||
|
||||
const val LOGIN_TYPE_PODLASIE = 6
|
||||
const val LOGIN_MODE_PODLASIE_API = 0
|
||||
const val LOGIN_METHOD_PODLASIE_API = 100
|
||||
val podlasieLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_PODLASIE, LOGIN_METHOD_PODLASIE_API, PodlasieLoginApi::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
)
|
||||
|
||||
val templateLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_TEMPLATE, LOGIN_METHOD_TEMPLATE_WEB, TemplateLoginWeb::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
|
@ -40,7 +40,7 @@ object Regexes {
|
||||
"""\(([0-9A-ząęóżźńśłć]*?)\)$""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_LUCKY_NUMBER by lazy {
|
||||
"""class="szczesliwy_numerek".*>0*([0-9]+)(?:/0*[0-9]+)*</a>""".toRegex(DOT_MATCHES_ALL)
|
||||
"""class="szczesliwy_numerek".*?>0?([0-9]+)/?0?([0-9]+)?</a>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_CLASS_CALENDAR by lazy {
|
||||
"""events: (.+),$""".toRegex(RegexOption.MULTILINE)
|
||||
@ -68,6 +68,9 @@ object Regexes {
|
||||
}
|
||||
|
||||
|
||||
val MOBIDZIENNIK_ATTENDANCE_TYPES by lazy {
|
||||
"""Legenda:.+?normal;">(.+?)</span>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_TABLE by lazy {
|
||||
"""<table .+?id="obecnosci_tabela">(.+?)</table>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
@ -77,11 +80,36 @@ object Regexes {
|
||||
val MOBIDZIENNIK_ATTENDANCE_ENTRIES by lazy {
|
||||
"""font-size:.+?class=".*?">(.*?)</td>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_COLUMNS by lazy {
|
||||
"""<tr><td class="border-right1".+?/td>(.+?)</tr>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_COLUMN by lazy {
|
||||
"""(<td.+?>)(.*?)</td>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_COLUMN_SPAN by lazy {
|
||||
"""colspan="(\d+)"""".toRegex()
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_RANGE by lazy {
|
||||
"""<span>([0-9:]+) - .+? (.+?)</span></a>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_ATTENDANCE_LESSON by lazy {
|
||||
"""<strong>(.+?) - (.*?)</strong>.+?<small>.+?\((.+?), .+?(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
||||
"""<strong>(.+?)</strong>\s*<small>\s*\((.+?),\s*(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
|
||||
val MOBIDZIENNIK_HOMEWORK_ROW by lazy {
|
||||
"""class="rowRolling">(.+?</div>\s*</td>)""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_HOMEWORK_ITEM by lazy {
|
||||
"""<p><b>(.+?):</b>\s*(.+?)\s*</p>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_HOMEWORK_BODY by lazy {
|
||||
"""Treść:</b>(.+?)<p><b>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_HOMEWORK_ID by lazy {
|
||||
"""zadanieFormularz\(([0-9]+),""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_HOMEWORK_ATTACHMENT by lazy {
|
||||
"""zalacznik(_zadania)?=([0-9]+)'.+?word-break">(.+?)</td>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
|
||||
|
||||
@ -123,12 +151,21 @@ object Regexes {
|
||||
val VULCAN_SHIFT_ANNOTATION by lazy {
|
||||
"""\(przeniesiona (z|na) lekcj[ię] ([0-9]+), (.+)\)""".toRegex()
|
||||
}
|
||||
val VULCAN_WEB_PERMISSIONS by lazy {
|
||||
"""permissions: '([A-z0-9/=+\-_]+?)'""".toRegex()
|
||||
}
|
||||
val VULCAN_WEB_SYMBOL_VALIDATE by lazy {
|
||||
"""[A-z0-9]+""".toRegex(IGNORE_CASE)
|
||||
}
|
||||
|
||||
|
||||
|
||||
val LIBRUS_ATTACHMENT_KEY by lazy {
|
||||
"""singleUseKey=([0-9A-z_]+)""".toRegex()
|
||||
}
|
||||
val LIBRUS_MESSAGE_ID by lazy {
|
||||
"""/wiadomosci/[0-9]+/[0-9]+/([0-9]+?)/""".toRegex()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -155,6 +192,9 @@ object Regexes {
|
||||
val EDUDZIENNIK_ANNOUNCEMENT_DESCRIPTION by lazy {
|
||||
"""<div class="desc">.*?<p>(.*?)</p>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
val EDUDZIENNIK_HOMEWORK_DESCRIPTION by lazy {
|
||||
"""<div class="desc">(.*?)</div>""".toRegex(DOT_MATCHES_ALL)
|
||||
}
|
||||
|
||||
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
||||
"""/Courses/([\w-_]+?)/""".toRegex()
|
||||
|
@ -5,29 +5,37 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.Edudziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.Idziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.Librus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.Mobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.Podlasie
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.Template
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.Vulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.events.RegisterAvailabilityEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.data.api.task.IApiTask
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTask(profileId) {
|
||||
companion object {
|
||||
private const val TAG = "EdziennikTask"
|
||||
|
||||
var profile: Profile? = null
|
||||
var loginStore: LoginStore? = null
|
||||
|
||||
fun firstLogin(loginStore: LoginStore) = EdziennikTask(-1, FirstLoginRequest(loginStore))
|
||||
fun sync() = EdziennikTask(-1, SyncRequest())
|
||||
fun syncProfile(profileId: Int, viewIds: List<Pair<Int, Int>>? = null, onlyEndpoints: List<Int>? = null, arguments: JsonObject? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds, onlyEndpoints, arguments))
|
||||
@ -36,8 +44,9 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
fun messageSend(profileId: Int, recipients: List<Teacher>, subject: String, text: String) = EdziennikTask(profileId, MessageSendRequest(recipients, subject, text))
|
||||
fun announcementsRead(profileId: Int) = EdziennikTask(profileId, AnnouncementsReadRequest())
|
||||
fun announcementGet(profileId: Int, announcement: AnnouncementFull) = EdziennikTask(profileId, AnnouncementGetRequest(announcement))
|
||||
fun attachmentGet(profileId: Int, message: Message, attachmentId: Long, attachmentName: String) = EdziennikTask(profileId, AttachmentGetRequest(message, attachmentId, attachmentName))
|
||||
fun attachmentGet(profileId: Int, owner: Any, attachmentId: Long, attachmentName: String) = EdziennikTask(profileId, AttachmentGetRequest(owner, attachmentId, attachmentName))
|
||||
fun recipientListGet(profileId: Int) = EdziennikTask(profileId, RecipientListGetRequest())
|
||||
fun eventGet(profileId: Int, event: EventFull) = EdziennikTask(profileId, EventGetRequest(event))
|
||||
}
|
||||
|
||||
private lateinit var loginStore: LoginStore
|
||||
@ -58,21 +67,65 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
// save the profile ID and name as the current task's
|
||||
taskName = app.getString(R.string.edziennik_notification_api_sync_title_format, profile.name)
|
||||
}
|
||||
EdziennikTask.profile = this.profile
|
||||
EdziennikTask.loginStore = this.loginStore
|
||||
}
|
||||
|
||||
private var edziennikInterface: EdziennikInterface? = null
|
||||
|
||||
internal fun run(app: App, taskCallback: EdziennikCallback) {
|
||||
if (profile?.archived == true) {
|
||||
taskCallback.onError(ApiError(TAG, ERROR_PROFILE_ARCHIVED))
|
||||
return
|
||||
profile?.let { profile ->
|
||||
if (profile.archived) {
|
||||
d(TAG, "The profile $profileId is archived")
|
||||
taskCallback.onError(ApiError(TAG, ERROR_PROFILE_ARCHIVED))
|
||||
return
|
||||
}
|
||||
else if (profile.shouldArchive()) {
|
||||
d(TAG, "The profile $profileId's year ended on ${profile.dateYearEnd}, archiving")
|
||||
ProfileArchiver(app, profile)
|
||||
}
|
||||
if (profile.isBeforeYear()) {
|
||||
d(TAG, "The profile $profileId's school year has not started yet; aborting sync")
|
||||
cancel()
|
||||
taskCallback.onCompleted()
|
||||
return
|
||||
}
|
||||
|
||||
profile.registerName?.let { registerName ->
|
||||
var status = app.config.sync.registerAvailability[registerName]
|
||||
if (status == null || status.nextCheck < currentTimeUnix()) {
|
||||
val api = SzkolnyApi(app)
|
||||
api.runCatching({
|
||||
val availability = getRegisterAvailability()
|
||||
app.config.sync.registerAvailability = availability
|
||||
status = availability[registerName]
|
||||
}, onError = {
|
||||
taskCallback.onError(it.toApiError(TAG))
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
if (status?.available != true
|
||||
|| status?.minVersionCode ?: BuildConfig.VERSION_CODE > BuildConfig.VERSION_CODE) {
|
||||
if (EventBus.getDefault().hasSubscriberForEvent(RegisterAvailabilityEvent::class.java)) {
|
||||
EventBus.getDefault().postSticky(
|
||||
RegisterAvailabilityEvent(app.config.sync.registerAvailability)
|
||||
)
|
||||
}
|
||||
cancel()
|
||||
taskCallback.onCompleted()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
edziennikInterface = when (loginStore.type) {
|
||||
LOGIN_TYPE_LIBRUS -> Librus(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_MOBIDZIENNIK -> Mobidziennik(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_VULCAN -> Vulcan(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_IDZIENNIK -> Idziennik(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_EDUDZIENNIK -> Edudziennik(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_PODLASIE -> Podlasie(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_TEMPLATE -> Template(app, profile, loginStore, taskCallback)
|
||||
else -> null
|
||||
}
|
||||
@ -92,12 +145,14 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
is FirstLoginRequest -> edziennikInterface?.firstLogin()
|
||||
is AnnouncementsReadRequest -> edziennikInterface?.markAllAnnouncementsAsRead()
|
||||
is AnnouncementGetRequest -> edziennikInterface?.getAnnouncement(request.announcement)
|
||||
is AttachmentGetRequest -> edziennikInterface?.getAttachment(request.message, request.attachmentId, request.attachmentName)
|
||||
is AttachmentGetRequest -> edziennikInterface?.getAttachment(request.owner, request.attachmentId, request.attachmentName)
|
||||
is RecipientListGetRequest -> edziennikInterface?.getRecipientList()
|
||||
is EventGetRequest -> edziennikInterface?.getEvent(request.event)
|
||||
}
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
d(TAG, "Task ${toString()} cancelling...")
|
||||
edziennikInterface?.cancel()
|
||||
}
|
||||
|
||||
@ -113,6 +168,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
data class MessageSendRequest(val recipients: List<Teacher>, val subject: String, val text: String)
|
||||
class AnnouncementsReadRequest
|
||||
data class AnnouncementGetRequest(val announcement: AnnouncementFull)
|
||||
data class AttachmentGetRequest(val message: Message, val attachmentId: Long, val attachmentName: String)
|
||||
data class AttachmentGetRequest(val owner: Any, val attachmentId: Long, val attachmentName: String)
|
||||
class RecipientListGetRequest
|
||||
data class EventGetRequest(val event: EventFull)
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-8-25.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik
|
||||
|
||||
import android.content.Intent
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.Intent
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class ProfileArchiver(val app: App, val profile: Profile) {
|
||||
companion object {
|
||||
private const val TAG = "ProfileArchiver"
|
||||
}
|
||||
|
||||
init {
|
||||
if (profile.archiveId == null)
|
||||
profile.archiveId = profile.id
|
||||
d(TAG, "Processing ${profile.name}#${profile.id}, archiveId = ${profile.archiveId}")
|
||||
|
||||
profile.archived = true
|
||||
app.db.profileDao().add(profile)
|
||||
//app.db.metadataDao().setAllSeen(profile.id, true)
|
||||
app.db.notificationDao().clear(profile.id)
|
||||
app.db.endpointTimerDao().clear(profile.id)
|
||||
d(TAG, "Archived profile ${profile.id} saved")
|
||||
profile.archived = false
|
||||
|
||||
// guess the nearest school year
|
||||
val today = Date.getToday()
|
||||
profile.studentSchoolYearStart = when {
|
||||
today.month <= profile.dateYearEnd.month -> today.year - 1
|
||||
else -> today.year
|
||||
}
|
||||
|
||||
// set default semester dates
|
||||
profile.dateSemester1Start = Date(profile.studentSchoolYearStart, 9, 1)
|
||||
profile.dateSemester2Start = Date(profile.studentSchoolYearStart + 1, 2, 1)
|
||||
profile.dateYearEnd = Date(profile.studentSchoolYearStart + 1, 6, 30)
|
||||
|
||||
val oldId = profile.id
|
||||
val newId = (app.db.profileDao().lastId ?: profile.id) + 1
|
||||
profile.id = newId
|
||||
profile.subname = "Nowy rok szkolny - ${profile.studentSchoolYearStart}"
|
||||
profile.studentClassName = null
|
||||
|
||||
d(TAG, "New profile ID for ${profile.name}: ${profile.id}")
|
||||
|
||||
when (profile.loginStoreType) {
|
||||
LOGIN_TYPE_LIBRUS -> {
|
||||
profile.removeStudentData("isPremium")
|
||||
profile.removeStudentData("pushDeviceId")
|
||||
profile.removeStudentData("startPointsSemester1")
|
||||
profile.removeStudentData("startPointsSemester2")
|
||||
profile.removeStudentData("enablePointGrades")
|
||||
profile.removeStudentData("enableDescriptiveGrades")
|
||||
}
|
||||
LOGIN_TYPE_MOBIDZIENNIK -> {
|
||||
|
||||
}
|
||||
LOGIN_TYPE_VULCAN -> {
|
||||
// DataVulcan.isApiLoginValid() returns false so it will update the semester
|
||||
profile.removeStudentData("currentSemesterEndDate")
|
||||
profile.removeStudentData("studentSemesterId")
|
||||
profile.removeStudentData("studentSemesterNumber")
|
||||
profile.removeStudentData("semester1Id")
|
||||
profile.removeStudentData("semester2Id")
|
||||
profile.removeStudentData("studentClassId")
|
||||
}
|
||||
LOGIN_TYPE_IDZIENNIK -> {
|
||||
profile.removeStudentData("schoolYearId")
|
||||
}
|
||||
LOGIN_TYPE_EDUDZIENNIK -> {
|
||||
|
||||
}
|
||||
LOGIN_TYPE_PODLASIE -> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
d(TAG, "Processed student data: ${profile.studentData}")
|
||||
|
||||
app.db.profileDao().add(profile)
|
||||
|
||||
if (app.profileId == oldId) {
|
||||
val intent = Intent(
|
||||
Intent.ACTION_MAIN,
|
||||
"profileId" to newId
|
||||
)
|
||||
app.sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikData
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebGetAnnouncement
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebGetHomework
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin.EdudziennikFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
||||
@ -16,10 +17,10 @@ import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -94,9 +95,17 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {}
|
||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {}
|
||||
override fun getRecipientList() {}
|
||||
|
||||
override fun getEvent(eventFull: EventFull) {
|
||||
EdudziennikLoginWeb(data) {
|
||||
EdudziennikWebGetHomework(data, eventFull) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun firstLogin() { EdudziennikFirstLogin(data) { completed() } }
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
|
@ -45,24 +45,25 @@ class EdudziennikWebAnnouncements(override val data: DataEdudziennik,
|
||||
val addedDate = Date.fromIsoHm(dateString)
|
||||
|
||||
val announcementObject = Announcement(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
null,
|
||||
startDate,
|
||||
null,
|
||||
teacher.id,
|
||||
longId
|
||||
)
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
subject = subject,
|
||||
text = null,
|
||||
startDate = startDate,
|
||||
endDate = null,
|
||||
teacherId = teacher.id,
|
||||
addedDate = addedDate
|
||||
).also {
|
||||
it.idString = longId
|
||||
}
|
||||
|
||||
data.announcementIgnoreList.add(announcementObject)
|
||||
data.announcementList.add(announcementObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
|
||||
|
||||
val attendanceTypes = EDUDZIENNIK_ATTENDANCE_TYPES.find(text)?.get(1)?.split(',')?.map {
|
||||
val type = EDUDZIENNIK_ATTENDANCE_TYPE.find(it.trim())
|
||||
val symbol = type?.get(1)?.trim()
|
||||
val name = type?.get(2)?.trim()
|
||||
val symbol = type?.get(1)?.trim() ?: "?"
|
||||
val name = type?.get(2)?.trim() ?: "nieznany rodzaj"
|
||||
return@map Triple(
|
||||
symbol,
|
||||
name,
|
||||
when (name?.toLowerCase(Locale.ROOT)) {
|
||||
when (name.toLowerCase(Locale.ROOT)) {
|
||||
"obecność" -> Attendance.TYPE_PRESENT
|
||||
"nieobecność" -> Attendance.TYPE_ABSENT
|
||||
"spóźnienie" -> Attendance.TYPE_BELATED
|
||||
@ -52,7 +52,7 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
|
||||
"dzień wolny" -> Attendance.TYPE_DAY_FREE
|
||||
"brak zajęć" -> Attendance.TYPE_DAY_FREE
|
||||
"oddelegowany" -> Attendance.TYPE_RELEASED
|
||||
else -> Attendance.TYPE_CUSTOM
|
||||
else -> Attendance.TYPE_UNKNOWN
|
||||
}
|
||||
)
|
||||
} ?: emptyList()
|
||||
@ -62,38 +62,42 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
|
||||
val lessonNumber = attendanceElement[2].toInt()
|
||||
val attendanceSymbol = attendanceElement[3]
|
||||
|
||||
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
||||
val lessons = data.app.db.timetableDao().getAllForDateNow(profileId, date)
|
||||
val lesson = lessons.firstOrNull { it.lessonNumber == lessonNumber }
|
||||
|
||||
val id = "${date.stringY_m_d}:$lessonNumber:$attendanceSymbol".crc32()
|
||||
|
||||
val (_, name, type) = attendanceTypes.firstOrNull { (symbol, _, _) -> symbol == attendanceSymbol }
|
||||
val (typeSymbol, typeName, baseType) = attendanceTypes.firstOrNull { (symbol, _, _) -> symbol == attendanceSymbol }
|
||||
?: return@forEach
|
||||
|
||||
val startTime = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNumber }?.startTime
|
||||
?: return@forEach
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId,
|
||||
id,
|
||||
lesson?.displayTeacherId ?: -1,
|
||||
lesson?.displaySubjectId ?: -1,
|
||||
profile.currentSemester,
|
||||
name,
|
||||
date,
|
||||
lesson?.displayStartTime ?: startTime,
|
||||
type
|
||||
)
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
baseType = baseType,
|
||||
typeName = typeName,
|
||||
typeShort = data.app.attendanceManager.getTypeShort(baseType),
|
||||
typeSymbol = typeSymbol,
|
||||
typeColor = null,
|
||||
date = date,
|
||||
startTime = lesson?.displayStartTime ?: startTime,
|
||||
semester = profile.currentSemester,
|
||||
teacherId = lesson?.displayTeacherId ?: -1,
|
||||
subjectId = lesson?.displaySubjectId ?: -1
|
||||
).also {
|
||||
it.lessonNumber = lessonNumber
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
if(type != Attendance.TYPE_PRESENT) {
|
||||
if (baseType != Attendance.TYPE_PRESENT) {
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN,
|
||||
profile.empty || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ class EdudziennikWebEvents(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class EdudziennikWebExams(override val data: DataEdudziennik,
|
||||
if (dateString.isBlank()) return@forEach
|
||||
val date = Date.fromY_m_d(dateString)
|
||||
|
||||
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
||||
val lessons = data.app.db.timetableDao().getAllForDateNow(profileId, date)
|
||||
val startTime = lessons.firstOrNull { it.displaySubjectId == subject.id }?.displayStartTime
|
||||
|
||||
val eventTypeElement = examElement.child(3).child(0)
|
||||
@ -74,8 +74,7 @@ class EdudziennikWebExams(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||
|
||||
import android.text.Html
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
|
||||
class EdudziennikWebGetHomework(
|
||||
override val data: DataEdudziennik,
|
||||
val event: EventFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : EdudziennikWeb(data, null) {
|
||||
companion object {
|
||||
const val TAG = "EdudziennikWebGetHomework"
|
||||
}
|
||||
|
||||
init {
|
||||
if (event.attachmentNames.isNotNullNorEmpty()) {
|
||||
val id = event.attachmentNames!![0]
|
||||
|
||||
webGet(TAG, "Homework/$id") { text ->
|
||||
val description = Regexes.EDUDZIENNIK_HOMEWORK_DESCRIPTION.find(text)?.get(1)?.trim()
|
||||
|
||||
if (description != null) event.topic = Html.fromHtml(description).toString()
|
||||
|
||||
event.homeworkBody = ""
|
||||
event.attachmentNames = null
|
||||
|
||||
data.eventList += event
|
||||
data.eventListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||
onSuccess()
|
||||
}
|
||||
} else {
|
||||
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -126,7 +126,8 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = teacher.id,
|
||||
subjectId = subject.id
|
||||
subjectId = subject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
@ -135,8 +136,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
@ -168,8 +168,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_GRADE,
|
||||
proposedGradeObject.id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
@ -201,8 +200,7 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_GRADE,
|
||||
finalGradeObject.id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
||||
if (doc.getElementsByClass("message").text().trim() != "Brak prac domowych") {
|
||||
doc.getElementsByTag("tr").forEach { homeworkElement ->
|
||||
val dateElement = homeworkElement.getElementsByClass("date").first().child(0)
|
||||
val id = EDUDZIENNIK_HOMEWORK_ID.find(dateElement.attr("href"))?.get(1)?.crc32()
|
||||
?: return@forEach
|
||||
val idStr = EDUDZIENNIK_HOMEWORK_ID.find(dateElement.attr("href"))?.get(1) ?: return@forEach
|
||||
val id = idStr.crc32()
|
||||
val date = Date.fromY_m_d(dateElement.text())
|
||||
|
||||
val subjectElement = homeworkElement.child(1).child(0)
|
||||
@ -43,20 +43,20 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
||||
val subjectName = subjectElement.text()
|
||||
val subject = data.getSubject(subjectId, subjectName)
|
||||
|
||||
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
||||
val lessons = data.app.db.timetableDao().getAllForDateNow(profileId, date)
|
||||
val startTime = lessons.firstOrNull { it.subjectId == subject.id }?.displayStartTime
|
||||
|
||||
val teacherName = homeworkElement.child(2).text()
|
||||
val teacher = data.getTeacherByFirstLast(teacherName)
|
||||
|
||||
val topic = homeworkElement.child(4).text()
|
||||
val topic = homeworkElement.child(4).text()?.trim()
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
date = date,
|
||||
time = startTime,
|
||||
topic = topic,
|
||||
topic = topic ?: "",
|
||||
color = null,
|
||||
type = Event.TYPE_HOMEWORK,
|
||||
teacherId = teacher.id,
|
||||
@ -64,14 +64,15 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
||||
teamId = data.teamClass?.id ?: -1
|
||||
)
|
||||
|
||||
eventObject.attachmentNames = mutableListOf(idStr)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ class EdudziennikWebLuckyNumber(override val data: DataEdudziennik,
|
||||
webGet(TAG, data.schoolEndpoint + "Lucky", xhr = true) { text ->
|
||||
text.toIntOrNull()?.also { luckyNumber ->
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
profileId,
|
||||
Date.getToday(),
|
||||
luckyNumber
|
||||
profileId = profileId,
|
||||
date = Date.getToday(),
|
||||
number = luckyNumber
|
||||
)
|
||||
|
||||
data.luckyNumberList.add(luckyNumberObject)
|
||||
@ -35,8 +35,7 @@ class EdudziennikWebLuckyNumber(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -41,12 +41,15 @@ class EdudziennikWebNotes(override val data: DataEdudziennik,
|
||||
val description = noteElement.child(3).text()
|
||||
|
||||
val noticeObject = Notice(
|
||||
profileId,
|
||||
id,
|
||||
description,
|
||||
profile.currentSemester,
|
||||
Notice.TYPE_NEUTRAL,
|
||||
teacher.id
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = Notice.TYPE_NEUTRAL,
|
||||
semester = profile.currentSemester,
|
||||
text = description,
|
||||
category = null,
|
||||
points = null,
|
||||
teacherId = teacher.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.noticeList.add(noticeObject)
|
||||
@ -55,8 +58,7 @@ class EdudziennikWebNotes(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_NOTICE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -124,8 +124,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonObject.id,
|
||||
seen,
|
||||
seen,
|
||||
System.currentTimeMillis()
|
||||
seen
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class EdudziennikFirstLogin(val data: DataEdudziennik, val onSuccess: () -> Unit
|
||||
profileList.add(profile)
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-5-14
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.helper
|
||||
|
||||
import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.FileCallbackHandler
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_FILE_DOWNLOAD
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_REQUEST_FAILURE
|
||||
import pl.szczodrzynski.edziennik.data.api.SYSTEM_USER_AGENT
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
|
||||
class DownloadAttachment(
|
||||
fileUrl: String,
|
||||
val onSuccess: (file: File) -> Unit,
|
||||
val onProgress: (written: Long, total: Long) -> Unit,
|
||||
val onError: (apiError: ApiError) -> Unit
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "DownloadAttachment"
|
||||
}
|
||||
|
||||
init {
|
||||
val targetFile = Utils.getStorageDir()
|
||||
|
||||
val callback = object : FileCallbackHandler(targetFile) {
|
||||
override fun onSuccess(file: File?, response: Response?) {
|
||||
if (file == null) {
|
||||
onError(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
onSuccess(file)
|
||||
} catch (e: Exception) {
|
||||
onError(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
||||
.withResponse(response)
|
||||
.withThrowable(e))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress(bytesWritten: Long, bytesTotal: Long) {
|
||||
try {
|
||||
this@DownloadAttachment.onProgress(bytesWritten, bytesTotal)
|
||||
} catch (e: Exception) {
|
||||
onError(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
||||
.withThrowable(e))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
onError(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(fileUrl)
|
||||
.userAgent(SYSTEM_USER_AGENT)
|
||||
.callback(callback)
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-4-7.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.helper
|
||||
|
||||
import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.FileCallbackHandler
|
||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_ONEDRIVE_DOWNLOAD
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_REQUEST_FAILURE
|
||||
import pl.szczodrzynski.edziennik.data.api.SYSTEM_USER_AGENT
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
|
||||
class OneDriveDownloadAttachment(
|
||||
app: App,
|
||||
fileUrl: String,
|
||||
val onSuccess: (file: File) -> Unit,
|
||||
val onProgress: (written: Long, total: Long) -> Unit,
|
||||
val onError: (apiError: ApiError) -> Unit
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "OneDriveDownloadAttachment"
|
||||
}
|
||||
|
||||
init {
|
||||
Request.builder()
|
||||
.url(fileUrl)
|
||||
.userAgent(SYSTEM_USER_AGENT)
|
||||
.withClient(app.httpLazy)
|
||||
.callback(object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String, response: Response) {
|
||||
val location = response.headers().get("Location")
|
||||
// https://onedrive.live.com/redir?resid=D75496A2EB87531C!706&authkey=!ABjZeh3pHMqj11Q
|
||||
if (location?.contains("onedrive.live.com/redir?resid=") != true) {
|
||||
onError(ApiError(TAG, ERROR_ONEDRIVE_DOWNLOAD)
|
||||
.withApiResponse(text)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
val url = location
|
||||
.replace("onedrive.live.com/redir?resid=", "storage.live.com/items/")
|
||||
.replace("?", "&")
|
||||
.replaceFirst("&", "?")
|
||||
downloadFile(url)
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response, throwable: Throwable) {
|
||||
onError(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
|
||||
private fun downloadFile(url: String) {
|
||||
val targetFile = Utils.getStorageDir()
|
||||
|
||||
val callback = object : FileCallbackHandler(targetFile) {
|
||||
override fun onSuccess(file: File?, response: Response?) {
|
||||
if (file == null) {
|
||||
onError(ApiError(TAG, ERROR_ONEDRIVE_DOWNLOAD)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
onSuccess(file)
|
||||
} catch (e: Exception) {
|
||||
onError(ApiError(TAG, ERROR_ONEDRIVE_DOWNLOAD)
|
||||
.withResponse(response)
|
||||
.withThrowable(e))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress(bytesWritten: Long, bytesTotal: Long) {
|
||||
try {
|
||||
this@OneDriveDownloadAttachment.onProgress(bytesWritten, bytesTotal)
|
||||
} catch (e: Exception) {
|
||||
onError(ApiError(TAG, ERROR_ONEDRIVE_DOWNLOAD)
|
||||
.withThrowable(e))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
onError(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(url)
|
||||
.userAgent(SYSTEM_USER_AGENT)
|
||||
.callback(callback)
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
}
|
@ -8,20 +8,15 @@ import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikData
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebGetAttachment
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebGetMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebGetRecipientList
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebSendMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.firstlogin.IdziennikFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -103,10 +98,17 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
override fun markAllAnnouncementsAsRead() {}
|
||||
override fun getAnnouncement(announcement: AnnouncementFull) {}
|
||||
|
||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
||||
IdziennikWebGetAttachment(data, message, attachmentId, attachmentName) {
|
||||
completed()
|
||||
if (owner is Message) {
|
||||
IdziennikWebGetAttachment(data, owner, attachmentId, attachmentName) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
else if (owner is Event) {
|
||||
IdziennikWebGetHomeworkAttachment(data, owner, attachmentId, attachmentName) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,6 +121,14 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEvent(eventFull: EventFull) {
|
||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
||||
IdziennikWebGetHomework(data, eventFull) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun firstLogin() { IdziennikFirstLogin(data) { completed() } }
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
|
@ -229,6 +229,7 @@ open class IdziennikWeb(open val data: DataIdziennik, open val lastSync: Long?)
|
||||
.apply {
|
||||
parameters.forEach { (k, v) -> addParameter(k, v) }
|
||||
}
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.post()
|
||||
.callback(callback)
|
||||
.build()
|
||||
|
@ -68,9 +68,9 @@ class IdziennikApiCurrentRegister(override val data: DataIdziennik,
|
||||
|
||||
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
data.profileId,
|
||||
luckyNumberDate,
|
||||
luckyNumber
|
||||
profileId = data.profileId,
|
||||
date = luckyNumberDate,
|
||||
number = luckyNumber
|
||||
)
|
||||
|
||||
data.luckyNumberList.add(luckyNumberObject)
|
||||
@ -80,8 +80,7 @@ class IdziennikApiCurrentRegister(override val data: DataIdziennik,
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
data.profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_DELETED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_DELETED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.getBoolean
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.crc32
|
||||
@ -33,11 +33,11 @@ class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
||||
return@apiGet
|
||||
}
|
||||
|
||||
json.asJsonObjectList()?.forEach { jMessage ->
|
||||
val subject = jMessage.getString("tytul")
|
||||
if (subject?.contains("(") == true && subject.startsWith("iDziennik - "))
|
||||
json.asJsonObjectList().forEach { jMessage ->
|
||||
val subject = jMessage.getString("tytul") ?: ""
|
||||
if (subject.contains("(") && subject.startsWith("iDziennik - "))
|
||||
return@forEach
|
||||
if (subject?.startsWith("Uwaga dla ucznia (klasa:") == true)
|
||||
if (subject.startsWith("Uwaga dla ucznia (klasa:"))
|
||||
return@forEach
|
||||
|
||||
val messageIdStr = jMessage.getString("id")
|
||||
@ -64,13 +64,13 @@ class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
||||
rTeacher.setTeacherType(Teacher.TYPE_OTHER)
|
||||
|
||||
val message = Message(
|
||||
profileId,
|
||||
messageId,
|
||||
subject,
|
||||
body,
|
||||
if (jMessage.getBoolean("rekordUsuniety") == true) TYPE_DELETED else TYPE_RECEIVED,
|
||||
rTeacher.id,
|
||||
-1
|
||||
profileId = profileId,
|
||||
id = messageId,
|
||||
type = if (jMessage.getBoolean("rekordUsuniety") == true) TYPE_DELETED else TYPE_RECEIVED,
|
||||
subject = subject,
|
||||
body = body,
|
||||
senderId = rTeacher.id,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
val messageRecipient = MessageRecipient(
|
||||
@ -81,15 +81,14 @@ class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
||||
/*messageId*/ messageId
|
||||
)
|
||||
|
||||
data.messageIgnoreList.add(message)
|
||||
data.messageList.add(message)
|
||||
data.messageRecipientList.add(messageRecipient)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
message.id,
|
||||
readDate > 0,
|
||||
readDate > 0 || profile?.empty ?: false,
|
||||
sentDate
|
||||
readDate > 0 || profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.MessageRecipient
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.crc32
|
||||
@ -46,13 +46,13 @@ class IdziennikApiMessagesSent(override val data: DataIdziennik,
|
||||
val sentDate = Date.fromIso(jMessage.get("dataWyslania").asString)
|
||||
|
||||
val message = Message(
|
||||
profileId,
|
||||
messageId,
|
||||
subject,
|
||||
body,
|
||||
TYPE_SENT,
|
||||
-1,
|
||||
-1
|
||||
profileId = profileId,
|
||||
id = messageId,
|
||||
type = TYPE_SENT,
|
||||
subject = subject,
|
||||
body = body,
|
||||
senderId = null,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
for (recipientEl in jMessage.getAsJsonArray("odbiorcy")) {
|
||||
@ -76,8 +76,8 @@ class IdziennikApiMessagesSent(override val data: DataIdziennik,
|
||||
data.messageRecipientIgnoreList.add(messageRecipient)
|
||||
}
|
||||
|
||||
data.messageIgnoreList.add(message)
|
||||
data.metadataList.add(Metadata(profileId, Metadata.TYPE_MESSAGE, message.id, true, true, sentDate))
|
||||
data.messageList.add(message)
|
||||
data.metadataList.add(Metadata(profileId, Metadata.TYPE_MESSAGE, message.id, true, true))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_IDZIENNIK_API_MESSAGES_SENT, DAY, DRAWER_ITEM_MESSAGES)
|
||||
|
@ -52,14 +52,14 @@ class IdziennikWebAnnouncements(override val data: DataIdziennik,
|
||||
val startDate = jAnnouncement.getString("DataWydarzenia")?.replace("[^\\d]".toRegex(), "")?.toLongOrNull()?.let { Date.fromMillis(it) }
|
||||
|
||||
val announcementObject = Announcement(
|
||||
profileId,
|
||||
announcementId,
|
||||
jAnnouncement.get("Temat").asString,
|
||||
jAnnouncement.get("Tresc").asString,
|
||||
startDate,
|
||||
null,
|
||||
rTeacher.id,
|
||||
null
|
||||
profileId = profileId,
|
||||
id = announcementId,
|
||||
subject = jAnnouncement.get("Temat").asString,
|
||||
text = jAnnouncement.get("Tresc").asString,
|
||||
startDate = startDate,
|
||||
endDate = null,
|
||||
teacherId = rTeacher.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
data.announcementList.add(announcementObject)
|
||||
data.metadataList.add(Metadata(
|
||||
@ -67,8 +67,7 @@ class IdziennikWebAnnouncements(override val data: DataIdziennik,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
announcementObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,18 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNI
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT_EXCUSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_BELATED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT_CUSTOM
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_RELEASED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_UNKNOWN
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
@ -51,71 +59,97 @@ class IdziennikWebAttendance(override val data: DataIdziennik,
|
||||
for (jAttendanceEl in json.getAsJsonArray("Obecnosci")) {
|
||||
val jAttendance = jAttendanceEl.asJsonObject
|
||||
// jAttendance
|
||||
val attendanceTypeIdziennik = jAttendance.get("TypObecnosci").asInt
|
||||
if (attendanceTypeIdziennik == 5 || attendanceTypeIdziennik == 7)
|
||||
continue
|
||||
val attendanceDate = Date.fromY_m_d(jAttendance.get("Data").asString)
|
||||
val attendanceTime = Time.fromH_m(jAttendance.get("OdDoGodziny").asString)
|
||||
if (attendanceDate.combineWith(attendanceTime) > System.currentTimeMillis())
|
||||
val type = jAttendance.get("TypObecnosci").asInt
|
||||
|
||||
// skip "zajęcia nie odbyły się" and "Ferie"
|
||||
if (type == 5 || type == 7)
|
||||
continue
|
||||
|
||||
val attendanceId = jAttendance.get("IdLesson").asString.crc16().toLong()
|
||||
val date = Date.fromY_m_d(jAttendance.get("Data").asString)
|
||||
val time = Time.fromH_m(jAttendance.get("OdDoGodziny").asString)
|
||||
if (date.combineWith(time) > System.currentTimeMillis())
|
||||
continue
|
||||
|
||||
val id = jAttendance.get("IdLesson").asString.crc16().toLong()
|
||||
val rSubject = data.getSubject(jAttendance.get("Przedmiot").asString, jAttendance.get("IdPrzedmiot").asLong, "")
|
||||
val rTeacher = data.getTeacherByFDotSpaceLast(jAttendance.get("PrzedmiotNauczyciel").asString)
|
||||
|
||||
var attendanceName = "obecność"
|
||||
var attendanceType = Attendance.TYPE_CUSTOM
|
||||
var baseType = TYPE_UNKNOWN
|
||||
var typeName = "nieznany rodzaj"
|
||||
var typeSymbol: String? = null
|
||||
var typeColor: Long? = null
|
||||
|
||||
when (attendanceTypeIdziennik) {
|
||||
1 /* nieobecność usprawiedliwiona */ -> {
|
||||
attendanceName = "nieobecność usprawiedliwiona"
|
||||
attendanceType = TYPE_ABSENT_EXCUSED
|
||||
/* https://iuczniowie.progman.pl/idziennik/mod_panelRodzica/obecnosci/obecnosciUcznia_lmt637231494660000000.js */
|
||||
/* https://iuczniowie.progman.pl/idziennik/mod_panelRodzica/obecnosci/obecnosci_lmt637231494660000000.css */
|
||||
when (type) {
|
||||
1 -> {
|
||||
baseType = TYPE_ABSENT_EXCUSED
|
||||
typeName = "nieobecność usprawiedliwiona"
|
||||
typeColor = 0xffffe099
|
||||
}
|
||||
2 /* spóźnienie */ -> {
|
||||
attendanceName = "spóźnienie"
|
||||
attendanceType = TYPE_BELATED
|
||||
2 -> {
|
||||
baseType = TYPE_BELATED
|
||||
typeName = "spóźnienie"
|
||||
typeColor = 0xffffffaa
|
||||
}
|
||||
3 /* nieobecność nieusprawiedliwiona */ -> {
|
||||
attendanceName = "nieobecność nieusprawiedliwiona"
|
||||
attendanceType = TYPE_ABSENT
|
||||
3 -> {
|
||||
baseType = TYPE_ABSENT
|
||||
typeName = "nieobecność nieusprawiedliwiona"
|
||||
typeColor = 0xffffad99
|
||||
}
|
||||
4 /* zwolnienie */, 9 /* zwolniony / obecny */ -> {
|
||||
attendanceType = TYPE_RELEASED
|
||||
if (attendanceTypeIdziennik == 4)
|
||||
attendanceName = "zwolnienie"
|
||||
if (attendanceTypeIdziennik == 9)
|
||||
attendanceName = "zwolnienie / obecność"
|
||||
4, 9 -> {
|
||||
baseType = TYPE_RELEASED
|
||||
if (type == 4) {
|
||||
typeName = "zwolnienie"
|
||||
typeColor = 0xffa8beff
|
||||
}
|
||||
if (type == 9) {
|
||||
typeName = "zwolniony / obecny"
|
||||
typeSymbol = "zb"
|
||||
typeColor = 0xffff69b4
|
||||
}
|
||||
}
|
||||
0 /* obecny */, 8 /* Wycieczka */ -> {
|
||||
attendanceType = TYPE_PRESENT
|
||||
if (attendanceTypeIdziennik == 8)
|
||||
attendanceName = "wycieczka"
|
||||
8 -> {
|
||||
baseType = TYPE_PRESENT_CUSTOM
|
||||
typeName = "wycieczka"
|
||||
typeSymbol = "w"
|
||||
typeColor = null
|
||||
}
|
||||
0 -> {
|
||||
baseType = TYPE_PRESENT
|
||||
typeName = "obecny"
|
||||
typeColor = 0xffccffcc
|
||||
}
|
||||
}
|
||||
|
||||
val semester = profile?.dateToSemester(attendanceDate) ?: 1
|
||||
val semester = profile?.dateToSemester(date) ?: 1
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId,
|
||||
attendanceId,
|
||||
rTeacher.id,
|
||||
rSubject.id,
|
||||
semester,
|
||||
attendanceName,
|
||||
attendanceDate,
|
||||
attendanceTime,
|
||||
attendanceType
|
||||
)
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
baseType = baseType,
|
||||
typeName = typeName,
|
||||
typeShort = typeSymbol ?: data.app.attendanceManager.getTypeShort(baseType),
|
||||
typeSymbol = typeSymbol ?: data.app.attendanceManager.getTypeShort(baseType),
|
||||
typeColor = typeColor?.toInt(),
|
||||
date = date,
|
||||
startTime = time,
|
||||
semester = semester,
|
||||
teacherId = rTeacher.id,
|
||||
subjectId = rSubject.id
|
||||
).also {
|
||||
it.lessonTopic = jAttendance.getString("PrzedmiotTemat")
|
||||
it.lessonNumber = jAttendance.getInt("Godzina")
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
if (attendanceObject.type != TYPE_PRESENT) {
|
||||
if (attendanceObject.baseType != TYPE_PRESENT) {
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
attendanceObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
profile?.empty ?: false || baseType == TYPE_PRESENT_CUSTOM || baseType == TYPE_UNKNOWN,
|
||||
profile?.empty ?: false || baseType == TYPE_PRESENT_CUSTOM || baseType == TYPE_UNKNOWN
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ class IdziennikWebExams(override val data: DataIdziennik,
|
||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
||||
val teacherName = exam.getString("wpisal") ?: return@forEach
|
||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
||||
val topic = exam.getString("zakres") ?: ""
|
||||
val topic = exam.getString("zakres")?.trim() ?: ""
|
||||
|
||||
val lessonList = data.db.timetableDao().getForDateNow(profileId, examDate)
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, examDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
val eventType = when (exam.getString("rodzaj")?.toLowerCase(Locale.getDefault())) {
|
||||
@ -98,8 +98,7 @@ class IdziennikWebExams(override val data: DataIdziennik,
|
||||
Metadata.TYPE_EVENT,
|
||||
eventObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
|
||||
class IdziennikWebGetAttachment(override val data: DataIdziennik,
|
||||
val message: Message,
|
||||
val owner: Any,
|
||||
val attachmentId: Long,
|
||||
val attachmentName: String,
|
||||
val onSuccess: () -> Unit
|
||||
@ -25,6 +25,8 @@ class IdziennikWebGetAttachment(override val data: DataIdziennik,
|
||||
}
|
||||
|
||||
init {
|
||||
val message = owner as Message
|
||||
|
||||
val messageId = "\\[META:([A-z0-9]+);([0-9-]+)]".toRegex().find(message.body ?: "")?.get(2) ?: -1
|
||||
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
||||
|
||||
@ -34,29 +36,29 @@ class IdziennikWebGetAttachment(override val data: DataIdziennik,
|
||||
), { file ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
message.id,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_FINISHED,
|
||||
file.absolutePath
|
||||
)
|
||||
|
||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.messageId}_${event.attachmentId}")
|
||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.ownerId}_${event.attachmentId}")
|
||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
||||
|
||||
EventBus.getDefault().post(event)
|
||||
EventBus.getDefault().postSticky(event)
|
||||
|
||||
onSuccess()
|
||||
|
||||
}) { written, _ ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
message.id,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_PROGRESS,
|
||||
bytesWritten = written
|
||||
)
|
||||
|
||||
EventBus.getDefault().post(event)
|
||||
EventBus.getDefault().postSticky(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-4-1.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.getBoolean
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class IdziennikWebGetHomework(override val data: DataIdziennik,
|
||||
val event: EventFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : IdziennikWeb(data, null) {
|
||||
companion object {
|
||||
private const val TAG = "IdziennikWebGetHomework"
|
||||
}
|
||||
|
||||
init {
|
||||
webApiGet(TAG, IDZIENNIK_WEB_GET_HOMEWORK, mapOf(
|
||||
"idP" to data.registerId,
|
||||
"idPD" to event.id
|
||||
)) { result ->
|
||||
val json = result.getJsonObject("d") ?: run {
|
||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
||||
.withApiResponse(result))
|
||||
return@webApiGet
|
||||
}
|
||||
|
||||
val homework = json.getJsonObject("praca") ?: return@webApiGet
|
||||
|
||||
if (homework.getBoolean("zalacznik", false)) {
|
||||
event.attachmentIds = mutableListOf(event.id)
|
||||
event.attachmentNames = mutableListOf("Załącznik do zadania")
|
||||
}
|
||||
else {
|
||||
event.attachmentIds = mutableListOf()
|
||||
event.attachmentNames = mutableListOf()
|
||||
}
|
||||
event.homeworkBody = homework.getString("tresc")
|
||||
|
||||
data.eventList.add(event)
|
||||
data.eventListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-4-1.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT
|
||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.set
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
|
||||
class IdziennikWebGetHomeworkAttachment(override val data: DataIdziennik,
|
||||
val owner: Any,
|
||||
val attachmentId: Long,
|
||||
val attachmentName: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : IdziennikWeb(data, null) {
|
||||
companion object {
|
||||
const val TAG = "IdziennikWebGetHomeworkAttachment"
|
||||
}
|
||||
|
||||
init {
|
||||
val homework = owner as Event
|
||||
|
||||
/*val request = Request.Builder()
|
||||
.url("")
|
||||
.build()
|
||||
data.app.http.newCall(request).enqueue(object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
data.error(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
||||
.withThrowable(e))
|
||||
}
|
||||
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
val filename = response.header("content-disposition")?.substringAfter("\"")?.substringBeforeLast("\"")
|
||||
|
||||
val file: File = File(Utils.getStorageDir(), filename)
|
||||
val sink = file.sink().buffer()
|
||||
response.body()?.source()?.let {
|
||||
sink.writeAll(it)
|
||||
}
|
||||
sink.close()
|
||||
}
|
||||
})*/
|
||||
|
||||
webGet(TAG, IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT) { text ->
|
||||
val hiddenFields = JsonObject()
|
||||
Regexes.IDZIENNIK_LOGIN_HIDDEN_FIELDS.findAll(text).forEach {
|
||||
hiddenFields[it[1]] = it[2]
|
||||
}
|
||||
|
||||
webGetFile(TAG, IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT, Utils.getStorageDir(), mapOf(
|
||||
"__VIEWSTATE" to hiddenFields.getString("__VIEWSTATE", ""),
|
||||
"__VIEWSTATEGENERATOR" to hiddenFields.getString("__VIEWSTATEGENERATOR", ""),
|
||||
"__EVENTVALIDATION" to hiddenFields.getString("__EVENTVALIDATION", ""),
|
||||
"__EVENTTARGET" to "ctl00\$cphContent\$bt_pobraniePliku",
|
||||
"ctl00\$dxComboUczniowie" to data.registerId,
|
||||
"ctl00\$cphContent\$idPracyDomowej" to attachmentId
|
||||
), { file ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_FINISHED,
|
||||
file.absolutePath
|
||||
)
|
||||
|
||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.ownerId}_${event.attachmentId}")
|
||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
||||
|
||||
homework.attachmentNames = mutableListOf(file.name)
|
||||
data.eventList.add(homework)
|
||||
data.eventListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
onSuccess()
|
||||
|
||||
}) { written, _ ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_PROGRESS,
|
||||
bytesWritten = written
|
||||
)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,8 +10,8 @@ import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_MESSAGE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageRecipientFull
|
||||
@ -50,7 +50,11 @@ class IdziennikWebGetMessage(override val data: DataIdziennik,
|
||||
message.recipients?.clear()
|
||||
when (message.type) {
|
||||
TYPE_RECEIVED -> {
|
||||
val recipientObject = MessageRecipientFull(profileId, -1, message.id)
|
||||
val recipientObject = MessageRecipientFull(
|
||||
profileId = profileId,
|
||||
id = -1,
|
||||
messageId = message.id
|
||||
)
|
||||
|
||||
val readDateString = it.getString("DataOdczytania")
|
||||
recipientObject.readDate = if (readDateString.isNullOrBlank()) System.currentTimeMillis()
|
||||
@ -67,7 +71,11 @@ class IdziennikWebGetMessage(override val data: DataIdziennik,
|
||||
val recipientName = recipient.getString("NazwaOdbiorcy") ?: return@forEach
|
||||
val teacher = data.getTeacherByLastFirst(recipientName)
|
||||
|
||||
val recipientObject = MessageRecipientFull(profileId, teacher.id, message.id)
|
||||
val recipientObject = MessageRecipientFull(
|
||||
profileId = profileId,
|
||||
id = teacher.id,
|
||||
messageId = message.id
|
||||
)
|
||||
|
||||
recipientObject.readDate = recipient.getLong("Status") ?: return@forEach
|
||||
recipientObject.fullName = teacher.fullName
|
||||
@ -86,14 +94,14 @@ class IdziennikWebGetMessage(override val data: DataIdziennik,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
message.id,
|
||||
message.seen,
|
||||
message.notified,
|
||||
message.addedDate
|
||||
message.notified
|
||||
))
|
||||
}
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||
|
||||
data.messageList.add(message)
|
||||
data.messageListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
colorInt = Color.parseColor("#$gradeColor")
|
||||
}
|
||||
|
||||
val addedDate = grade.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
@ -76,7 +78,9 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = teacher.id,
|
||||
subjectId = subject.id)
|
||||
subjectId = subject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
when (grade.getInt("Typ")) {
|
||||
0 -> {
|
||||
@ -100,6 +104,8 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
colorInt = Color.parseColor("#$historyColor")
|
||||
}
|
||||
|
||||
val addedDate = historyItem.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
||||
|
||||
val historyObject = Grade(
|
||||
profileId = profileId,
|
||||
id = gradeObject.id * -1,
|
||||
@ -113,19 +119,18 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
comment = null,
|
||||
semester = historyItem.getInt("Semestr") ?: 1,
|
||||
teacherId = teacher.id,
|
||||
subjectId = subject.id)
|
||||
subjectId = subject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
historyObject.parentId = gradeObject.id
|
||||
|
||||
val addedDate = historyItem.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
||||
|
||||
data.gradeList.add(historyObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
historyObject.id,
|
||||
true,
|
||||
true,
|
||||
addedDate
|
||||
true
|
||||
))
|
||||
}
|
||||
// update the current grade's value with an average of all historical grades and itself
|
||||
@ -147,8 +152,6 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
}
|
||||
}
|
||||
|
||||
val addedDate = grade.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
@ -156,8 +159,7 @@ class IdziennikWebGrades(override val data: DataIdziennik,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
data.profile.empty,
|
||||
data.profile.empty,
|
||||
addedDate
|
||||
data.profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -52,13 +52,14 @@ class IdziennikWebHomework(override val data: DataIdziennik,
|
||||
json.getJsonArray("ListK")?.asJsonObjectList()?.forEach { homework ->
|
||||
val id = homework.getLong("_recordId") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(homework.getString("dataO") ?: return@forEach)
|
||||
val addedDate = Date.fromY_m_d(homework.getString("dataZ") ?: return@forEach)
|
||||
val subjectName = homework.getString("przed") ?: return@forEach
|
||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
||||
val teacherName = homework.getString("usr") ?: return@forEach
|
||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
||||
val lessonList = data.db.timetableDao().getForDateNow(profileId, eventDate)
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.displayStartTime
|
||||
val topic = homework.getString("tytul") ?: ""
|
||||
val topic = homework.getString("tytul")?.trim() ?: ""
|
||||
|
||||
val seen = when (profile?.empty) {
|
||||
true -> true
|
||||
@ -76,7 +77,8 @@ class IdziennikWebHomework(override val data: DataIdziennik,
|
||||
type = Event.TYPE_HOMEWORK,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = data.teamClass?.id ?: -1
|
||||
teamId = data.teamClass?.id ?: -1,
|
||||
addedDate = addedDate.inMillis
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
@ -85,8 +87,7 @@ class IdziennikWebHomework(override val data: DataIdziennik,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
eventObject.id,
|
||||
seen,
|
||||
seen,
|
||||
System.currentTimeMillis()
|
||||
seen
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,12 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_NEGATIVE
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_NEUTRAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_POSITIVE
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class IdziennikWebNotices(override val data: DataIdziennik,
|
||||
@ -53,20 +56,24 @@ class IdziennikWebNotices(override val data: DataIdziennik,
|
||||
}
|
||||
|
||||
val noticeObject = Notice(
|
||||
profileId,
|
||||
noticeId,
|
||||
jNotice.get("Tresc").asString,
|
||||
jNotice.get("Semestr").asInt,
|
||||
nType,
|
||||
rTeacher.id)
|
||||
profileId = profileId,
|
||||
id = noticeId,
|
||||
type = nType,
|
||||
semester = jNotice.get("Semestr").asInt,
|
||||
text = jNotice.getString("Tresc") ?: "",
|
||||
category = null,
|
||||
points = null,
|
||||
teacherId = rTeacher.id,
|
||||
addedDate = addedDate.inMillis
|
||||
)
|
||||
|
||||
data.noticeList.add(noticeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_NOTICE,
|
||||
noticeObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate.inMillis
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_DESCRIPTIVE
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_YEAR_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
@ -20,7 +21,6 @@ import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.getWordGradeValue
|
||||
|
||||
class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
override val lastSync: Long?,
|
||||
@ -39,77 +39,105 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
.withApiResponse(result))
|
||||
return@webApiGet
|
||||
}
|
||||
val manager = data.app.gradesManager
|
||||
|
||||
json.getJsonArray("Przedmioty")?.asJsonObjectList()?.forEach { subject ->
|
||||
val subjectName = subject.getString("Przedmiot") ?: return@forEach
|
||||
val subjectObject = data.getSubject(subjectName, null, subjectName)
|
||||
|
||||
val semester1Proposed = subject.getString("OcenaSem1") ?: ""
|
||||
val semester1Value = getWordGradeValue(semester1Proposed)
|
||||
val semester1Value = manager.getGradeValue(semester1Proposed)
|
||||
val semester1Id = subjectObject.id * (-100) - 1
|
||||
val semester1Type =
|
||||
if (semester1Value == 0f) TYPE_DESCRIPTIVE
|
||||
else TYPE_SEMESTER1_PROPOSED
|
||||
val semester1Name = when {
|
||||
semester1Value == 0f -> " "
|
||||
semester1Value % 1.0f == 0f -> semester1Value.toInt().toString()
|
||||
else -> semester1Value.toString()
|
||||
}
|
||||
val semester1Color =
|
||||
if (semester1Value == 0f) 0xff536dfe.toInt()
|
||||
else -1
|
||||
|
||||
val semester2Proposed = subject.getString("OcenaSem2") ?: ""
|
||||
val semester2Value = getWordGradeValue(semester2Proposed)
|
||||
val semester2Value = manager.getGradeValue(semester2Proposed)
|
||||
val semester2Id = subjectObject.id * (-100) - 2
|
||||
val semester2Type =
|
||||
if (semester2Value == 0f) TYPE_DESCRIPTIVE
|
||||
else TYPE_YEAR_PROPOSED
|
||||
val semester2Name = when {
|
||||
semester2Value == 0f -> " "
|
||||
semester2Value % 1.0f == 0f -> semester2Value.toInt().toString()
|
||||
else -> semester2Value.toString()
|
||||
}
|
||||
val semester2Color =
|
||||
if (semester2Value == 0f) 0xffff4081.toInt()
|
||||
else -1
|
||||
|
||||
if (semester1Proposed != "") {
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = semester1Id,
|
||||
name = semester1Value.toString(),
|
||||
type = TYPE_SEMESTER1_PROPOSED,
|
||||
value = semester1Value.toFloat(),
|
||||
weight = 0f,
|
||||
color = -1,
|
||||
category = null,
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = 1,
|
||||
teacherId = -1,
|
||||
subjectId = subjectObject.id
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
|
||||
if (semester2Proposed != "") {
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = semester2Id,
|
||||
name = semester2Value.toString(),
|
||||
type = TYPE_YEAR_PROPOSED,
|
||||
value = semester2Value.toFloat(),
|
||||
weight = 0f,
|
||||
color = -1,
|
||||
category = null,
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = 2,
|
||||
teacherId = -1,
|
||||
subjectId = subjectObject.id
|
||||
)
|
||||
|
||||
val addedDate = if (data.profile.empty)
|
||||
data.profile.dateSemester1Start.inMillis
|
||||
else
|
||||
System.currentTimeMillis()
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = semester1Id,
|
||||
name = semester1Name,
|
||||
type = semester1Type,
|
||||
value = semester1Value,
|
||||
weight = 0f,
|
||||
color = semester1Color,
|
||||
category = if (semester1Value == 0f) "Ocena opisowa semestralna" else null,
|
||||
description = if (semester1Value == 0f) semester1Proposed else null,
|
||||
comment = null,
|
||||
semester = 1,
|
||||
teacherId = -1,
|
||||
subjectId = subjectObject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
if (semester2Proposed != "") {
|
||||
val addedDate = if (data.profile.empty)
|
||||
data.profile.dateSemester2Start.inMillis
|
||||
else
|
||||
System.currentTimeMillis()
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = semester2Id,
|
||||
name = semester2Name,
|
||||
type = semester2Type,
|
||||
value = semester2Value,
|
||||
weight = 0f,
|
||||
color = semester2Color,
|
||||
category = if (semester2Value == 0f) "Ocena opisowa końcoworoczna" else null,
|
||||
description = if (semester2Value == 0f) semester2Proposed else null,
|
||||
comment = null,
|
||||
semester = 2,
|
||||
teacherId = -1,
|
||||
subjectId = subjectObject.id,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ class IdziennikWebSendMessage(override val data: DataIdziennik,
|
||||
}
|
||||
|
||||
IdziennikApiMessagesSent(data, null) {
|
||||
val message = data.messageIgnoreList.firstOrNull { it.type == Message.TYPE_SENT && it.subject == subject }
|
||||
val message = data.messageList.firstOrNull { it.type == Message.TYPE_SENT && it.subject == subject }
|
||||
val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == message?.id }
|
||||
val event = MessageSentEvent(data.profileId, message, metadata?.addedDate)
|
||||
val event = MessageSentEvent(data.profileId, message, message?.addedDate)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
onSuccess()
|
||||
|
@ -165,8 +165,7 @@ class IdziennikWebTimetable(override val data: DataIdziennik,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonObject.id,
|
||||
seen,
|
||||
seen,
|
||||
System.currentTimeMillis()
|
||||
seen
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class IdziennikFirstLogin(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
||||
profileList.add(profile)
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,21 @@ class IdziennikLoginWeb(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
||||
data.webSelectedRegister = registerId
|
||||
}
|
||||
|
||||
// for profiles created after archiving
|
||||
data.schoolYearId = Regexes.IDZIENNIK_LOGIN_FIRST_SCHOOL_YEAR.find(text)?.let {
|
||||
it[1].toIntOrNull()
|
||||
} ?: data.schoolYearId
|
||||
data.profile?.studentClassName = Regexes.IDZIENNIK_LOGIN_FIRST_STUDENT.findAll(text)
|
||||
.firstOrNull { it[1].toIntOrNull() == data.registerId }
|
||||
?.let { "${it[5]} ${it[6]}" } ?: data.profile?.studentClassName
|
||||
|
||||
data.profile?.let { profile ->
|
||||
Regexes.IDZIENNIK_WEB_LUCKY_NUMBER.find(text)?.also {
|
||||
val number = it[1].toIntOrNull() ?: return@also
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
data.profileId,
|
||||
Date.getToday(),
|
||||
number
|
||||
profileId = data.profileId,
|
||||
date = Date.getToday(),
|
||||
number = number
|
||||
)
|
||||
|
||||
data.luckyNumberList.add(luckyNumberObject)
|
||||
@ -86,8 +94,7 @@ class IdziennikLoginWeb(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
private var mApiLogin: String? = null
|
||||
var apiLogin: String?
|
||||
get() { mApiLogin = mApiLogin ?: profile?.getStudentData("accountLogin", null); return mApiLogin }
|
||||
set(value) { profile?.putStudentData("accountLogin", value) ?: return; mApiLogin = value }
|
||||
set(value) { profile?.putStudentData("accountLogin", value); mApiLogin = value }
|
||||
/**
|
||||
* A Synergia password.
|
||||
* Used: for login (API Login Method) in Synergia mode.
|
||||
@ -129,7 +129,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
private var mApiPassword: String? = null
|
||||
var apiPassword: String?
|
||||
get() { mApiPassword = mApiPassword ?: profile?.getStudentData("accountPassword", null); return mApiPassword }
|
||||
set(value) { profile?.putStudentData("accountPassword", value) ?: return; mApiPassword = value }
|
||||
set(value) { profile?.putStudentData("accountPassword", value); mApiPassword = value }
|
||||
|
||||
/**
|
||||
* A JST login Code.
|
||||
@ -138,8 +138,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
private var mApiCode: String? = null
|
||||
var apiCode: String?
|
||||
get() { mApiCode = mApiCode ?: loginStore.getLoginData("accountCode", null); return mApiCode }
|
||||
set(value) {
|
||||
loginStore.putLoginData("accountCode", value); mApiCode = value }
|
||||
set(value) { profile?.putStudentData("accountCode", value); mApiCode = value }
|
||||
/**
|
||||
* A JST login PIN.
|
||||
* Used only during first login in JST mode.
|
||||
@ -147,8 +146,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
private var mApiPin: String? = null
|
||||
var apiPin: String?
|
||||
get() { mApiPin = mApiPin ?: loginStore.getLoginData("accountPin", null); return mApiPin }
|
||||
set(value) {
|
||||
loginStore.putLoginData("accountPin", value); mApiPin = value }
|
||||
set(value) { profile?.putStudentData("accountPin", value); mApiPin = value }
|
||||
|
||||
/**
|
||||
* A Synergia API access token.
|
||||
@ -277,4 +275,10 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
var timetableNotPublic: Boolean
|
||||
get() { mTimetableNotPublic = mTimetableNotPublic ?: profile?.getStudentData("timetableNotPublic", false); return mTimetableNotPublic ?: false }
|
||||
set(value) { profile?.putStudentData("timetableNotPublic", value) ?: return; mTimetableNotPublic = value }
|
||||
|
||||
/**
|
||||
* Set to false when Recaptcha helper doesn't provide a working token.
|
||||
* When it's set to false uses Synergia for messages.
|
||||
*/
|
||||
var messagesLoginSuccessful: Boolean = true
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.Librus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetRecipientList
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesSendMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaMarkAllAnnouncementsAsRead
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.firstlogin.LibrusFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
@ -24,6 +24,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -88,9 +89,8 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
|
||||
override fun getMessage(message: MessageFull) {
|
||||
login(LOGIN_METHOD_LIBRUS_MESSAGES) {
|
||||
LibrusMessagesGetMessage(data, message) {
|
||||
completed()
|
||||
}
|
||||
if (data.messagesLoginSuccessful) LibrusMessagesGetMessage(data, message) { completed() }
|
||||
else LibrusSynergiaGetMessage(data, message) { completed() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,11 +118,22 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||
login(LOGIN_METHOD_LIBRUS_MESSAGES) {
|
||||
LibrusMessagesGetAttachment(data, message, attachmentId, attachmentName) {
|
||||
completed()
|
||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
||||
when (owner) {
|
||||
is Message -> {
|
||||
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
|
||||
if (data.messagesLoginSuccessful) LibrusMessagesGetAttachment(data, owner, attachmentId, attachmentName) { completed() }
|
||||
LibrusSynergiaGetAttachment(data, owner, attachmentId, attachmentName) { completed() }
|
||||
}
|
||||
}
|
||||
is EventFull -> {
|
||||
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
|
||||
LibrusSynergiaHomeworkGetAttachment(data, owner, attachmentId, attachmentName) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> completed()
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,6 +145,14 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEvent(eventFull: EventFull) {
|
||||
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
|
||||
LibrusSynergiaGetHomework(data, eventFull) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun firstLogin() { LibrusFirstLogin(data) { completed() } }
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
|
@ -50,6 +50,8 @@ const val ENDPOINT_LIBRUS_API_CLASS_FREE_DAYS = 1130
|
||||
const val ENDPOINT_LIBRUS_SYNERGIA_INFO = 2010
|
||||
const val ENDPOINT_LIBRUS_SYNERGIA_GRADES = 2020
|
||||
const val ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK = 2030
|
||||
const val ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_RECEIVED = 2040
|
||||
const val ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_SENT = 2050
|
||||
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVED = 3010
|
||||
const val ENDPOINT_LIBRUS_MESSAGES_SENT = 3020
|
||||
const val ENDPOINT_LIBRUS_MESSAGES_TRASH = 3030
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-5-8.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus
|
||||
|
||||
import android.content.Context
|
||||
import android.webkit.WebView
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import pl.szczodrzynski.edziennik.startCoroutineTimer
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LibrusRecaptchaHelper(
|
||||
val context: Context,
|
||||
url: String,
|
||||
html: String,
|
||||
val onSuccess: (url: String) -> Unit,
|
||||
val onTimeout: () -> Unit
|
||||
) : CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "LibrusRecaptchaHelper"
|
||||
}
|
||||
|
||||
private val job: Job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Default
|
||||
|
||||
private val webView by lazy {
|
||||
WebView(context).also {
|
||||
it.settings.javaScriptEnabled = true
|
||||
it.webViewClient = WebViewClient()
|
||||
}
|
||||
}
|
||||
|
||||
private var timeout: Job? = null
|
||||
private var timedOut = false
|
||||
|
||||
inner class WebViewClient : android.webkit.WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
||||
timeout?.cancel()
|
||||
if (!timedOut) {
|
||||
onSuccess(url)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
launch(Dispatchers.Main) {
|
||||
webView.loadDataWithBaseURL(url, html, "text/html", "UTF-8", null)
|
||||
}
|
||||
timeout = startCoroutineTimer(delayMillis = 10000L) {
|
||||
timedOut = true
|
||||
onTimeout()
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetList
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaGetMessages
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaHomework
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaInfo
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
@ -201,17 +202,27 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
LibrusSynergiaInfo(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_RECEIVED -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
LibrusSynergiaGetMessages(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
LibrusSynergiaGetMessages(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
|
||||
/**
|
||||
* MESSAGES
|
||||
*/
|
||||
ENDPOINT_LIBRUS_MESSAGES_RECEIVED -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
|
||||
if (data.messagesLoginSuccessful) LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
|
||||
else LibrusSynergiaGetMessages(data, type = Message.TYPE_RECEIVED, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
|
||||
if (data.messagesLoginSuccessful) LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
|
||||
else LibrusSynergiaGetMessages(data, type = Message.TYPE_SENT, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
|
||||
else -> onSuccess(endpointId)
|
||||
|
@ -35,7 +35,7 @@ open class LibrusSynergia(open val data: DataLibrus, open val lastSync: Long?) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!text.contains("jesteś zalogowany")) {
|
||||
if (!text.contains("jesteś zalogowany") && !text.contains("Podgląd zadania")) {
|
||||
when {
|
||||
text.contains("stop.png") -> ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED
|
||||
text.contains("Przerwa techniczna") -> ERROR_LIBRUS_SYNERGIA_MAINTENANCE
|
||||
@ -48,7 +48,6 @@ open class LibrusSynergia(open val data: DataLibrus, open val lastSync: Long?) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
onSuccess(text)
|
||||
} catch (e: Exception) {
|
||||
@ -90,4 +89,44 @@ open class LibrusSynergia(open val data: DataLibrus, open val lastSync: Long?) {
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
|
||||
fun redirectUrlGet(tag: String, url: String, onSuccess: (url: String) -> Unit) {
|
||||
d(tag, "Request: Librus/Synergia - $url")
|
||||
|
||||
val callback = object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String?, response: Response) {
|
||||
val redirectUrl = response.headers().get("Location")
|
||||
|
||||
if (redirectUrl != null) {
|
||||
try {
|
||||
onSuccess(redirectUrl)
|
||||
} catch (e: Exception) {
|
||||
data.error(ApiError(tag, EXCEPTION_LIBRUS_SYNERGIA_REQUEST)
|
||||
.withResponse(response)
|
||||
.withThrowable(e)
|
||||
.withApiResponse(text))
|
||||
}
|
||||
} else {
|
||||
data.error(ApiError(tag, ERROR_LIBRUS_SYNERGIA_OTHER)
|
||||
.withResponse(response)
|
||||
.withApiResponse(text))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(url)
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.withClient(data.app.httpLazy)
|
||||
.get()
|
||||
.callback(callback)
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ class LibrusApiAnnouncementMarkAsRead(override val data: DataLibrus,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
announcement.id,
|
||||
announcement.seen,
|
||||
announcement.notified,
|
||||
announcement.addedDate
|
||||
announcement.notified
|
||||
))
|
||||
onSuccess()
|
||||
}
|
||||
|
@ -38,15 +38,17 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
||||
val read = announcement.getBoolean("WasRead") ?: false
|
||||
|
||||
val announcementObject = Announcement(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
text,
|
||||
startDate,
|
||||
endDate,
|
||||
teacherId,
|
||||
longId
|
||||
)
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
subject = subject,
|
||||
text = text,
|
||||
startDate = startDate,
|
||||
endDate = endDate,
|
||||
teacherId = teacherId,
|
||||
addedDate = addedDate
|
||||
).also {
|
||||
it.idString = longId
|
||||
}
|
||||
|
||||
data.announcementList.add(announcementObject)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
@ -54,8 +56,7 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
id,
|
||||
read,
|
||||
profile.empty || read,
|
||||
addedDate
|
||||
profile.empty || read
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -26,25 +26,39 @@ class LibrusApiAttendanceTypes(override val data: DataLibrus,
|
||||
|
||||
attendanceTypes?.forEach { attendanceType ->
|
||||
val id = attendanceType.getLong("Id") ?: return@forEach
|
||||
val name = attendanceType.getString("Name") ?: ""
|
||||
val color = attendanceType.getString("ColorRGB")?.let { Color.parseColor("#$it") } ?: -1
|
||||
|
||||
val standardId = when (attendanceType.getBoolean("Standard") ?: false) {
|
||||
true -> id
|
||||
false -> attendanceType.getJsonObject("StandardType")?.getLong("Id") ?: id
|
||||
}
|
||||
val type = when (standardId) {
|
||||
val typeName = attendanceType.getString("Name") ?: ""
|
||||
val typeSymbol = attendanceType.getString("Short") ?: ""
|
||||
val typeColor = attendanceType.getString("ColorRGB")?.let { Color.parseColor("#$it") }
|
||||
|
||||
val isStandard = attendanceType.getBoolean("Standard") ?: false
|
||||
val baseType = when (attendanceType.getJsonObject("StandardType")?.getLong("Id") ?: id) {
|
||||
1L -> Attendance.TYPE_ABSENT
|
||||
2L -> Attendance.TYPE_BELATED
|
||||
3L -> Attendance.TYPE_ABSENT_EXCUSED
|
||||
4L -> Attendance.TYPE_RELEASED
|
||||
/*100*/else -> Attendance.TYPE_PRESENT
|
||||
/*100*/else -> when (isStandard) {
|
||||
true -> Attendance.TYPE_PRESENT
|
||||
false -> Attendance.TYPE_PRESENT_CUSTOM
|
||||
}
|
||||
}
|
||||
val typeShort = when (isStandard) {
|
||||
true -> data.app.attendanceManager.getTypeShort(baseType)
|
||||
false -> typeSymbol
|
||||
}
|
||||
|
||||
data.attendanceTypes.put(id, AttendanceType(profileId, id, name, type, color))
|
||||
data.attendanceTypes.put(id, AttendanceType(
|
||||
profileId,
|
||||
id,
|
||||
baseType,
|
||||
typeName,
|
||||
typeShort,
|
||||
typeSymbol,
|
||||
typeColor
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES, 4*DAY)
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES, 2*DAY)
|
||||
onSuccess(ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class LibrusApiAttendances(override val data: DataLibrus,
|
||||
override val lastSync: Long?,
|
||||
@ -42,9 +41,9 @@ class LibrusApiAttendances(override val data: DataLibrus,
|
||||
val lessonDate = Date.fromY_m_d(attendance.getString("Date"))
|
||||
val teacherId = attendance.getJsonObject("AddedBy")?.getLong("Id")
|
||||
val semester = attendance.getInt("Semester") ?: return@forEach
|
||||
val type = attendance.getJsonObject("Type")?.getLong("Id") ?: return@forEach
|
||||
val typeObject = data.attendanceTypes[type] ?: null
|
||||
val topic = typeObject?.name ?: ""
|
||||
|
||||
val typeId = attendance.getJsonObject("Type")?.getLong("Id") ?: return@forEach
|
||||
val type = data.attendanceTypes[typeId] ?: null
|
||||
|
||||
val startTime = data.lessonRanges.get(lessonNo)?.startTime
|
||||
|
||||
@ -52,29 +51,34 @@ class LibrusApiAttendances(override val data: DataLibrus,
|
||||
data.librusLessons.singleOrNull { it.lessonId == lessonId }
|
||||
else null
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId,
|
||||
id,
|
||||
teacherId ?: lesson?.teacherId ?: -1,
|
||||
lesson?.subjectId ?: -1,
|
||||
semester,
|
||||
topic,
|
||||
lessonDate,
|
||||
startTime ?: Time(0, 0, 0),
|
||||
typeObject?.type ?: Attendance.TYPE_CUSTOM
|
||||
)
|
||||
|
||||
val addedDate = Date.fromIso(attendance.getString("AddDate") ?: return@forEach)
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
baseType = type?.baseType ?: Attendance.TYPE_UNKNOWN,
|
||||
typeName = type?.typeName ?: "nieznany rodzaj",
|
||||
typeShort = type?.typeShort ?: "?",
|
||||
typeSymbol = type?.typeSymbol ?: "?",
|
||||
typeColor = type?.typeColor,
|
||||
date = lessonDate,
|
||||
startTime = startTime,
|
||||
semester = semester,
|
||||
teacherId = teacherId ?: lesson?.teacherId ?: -1,
|
||||
subjectId = lesson?.subjectId ?: -1,
|
||||
addedDate = addedDate
|
||||
).also {
|
||||
it.lessonNumber = lessonNo
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
if(typeObject?.type != Attendance.TYPE_PRESENT) {
|
||||
if(type?.baseType != Attendance.TYPE_PRESENT) {
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate
|
||||
profile?.empty ?: false || type?.baseType == Attendance.TYPE_PRESENT_CUSTOM || type?.baseType == Attendance.TYPE_UNKNOWN,
|
||||
profile?.empty ?: false || type?.baseType == Attendance.TYPE_PRESENT_CUSTOM || type?.baseType == Attendance.TYPE_UNKNOWN
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
comment = null,
|
||||
semester = 1,
|
||||
teacherId = -1,
|
||||
subjectId = 1
|
||||
subjectId = 1,
|
||||
addedDate = profile.getSemesterStart(1).inMillis
|
||||
)
|
||||
|
||||
data.gradeList.add(semester1StartGradeObject)
|
||||
@ -64,8 +65,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
semester1StartGradeObject.id,
|
||||
true,
|
||||
true,
|
||||
profile.getSemesterStart(1).inMillis
|
||||
true
|
||||
))
|
||||
}
|
||||
|
||||
@ -83,7 +83,8 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
comment = null,
|
||||
semester = 2,
|
||||
teacherId = -1,
|
||||
subjectId = 1
|
||||
subjectId = 1,
|
||||
addedDate = profile.getSemesterStart(2).inMillis
|
||||
)
|
||||
|
||||
data.gradeList.add(semester2StartGradeObject)
|
||||
@ -92,8 +93,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
semester2StartGradeObject.id,
|
||||
true,
|
||||
true,
|
||||
profile.getSemesterStart(2).inMillis
|
||||
true
|
||||
))
|
||||
}
|
||||
|
||||
@ -155,7 +155,8 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
comment = if (text != null) description.join(" - ") else null,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = 1
|
||||
subjectId = 1,
|
||||
addedDate = addedDate
|
||||
).apply {
|
||||
valueMax = valueTo
|
||||
}
|
||||
@ -166,8 +167,7 @@ class LibrusApiBehaviourGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,8 @@ class LibrusApiDescriptiveGrades(override val data: DataLibrus,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
@ -74,8 +75,7 @@ class LibrusApiDescriptiveGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
events?.forEach { event ->
|
||||
val id = event.getLong("Id") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(event.getString("Date"))
|
||||
val topic = event.getString("Content") ?: ""
|
||||
var topic = event.getString("Content")?.trim() ?: ""
|
||||
val type = event.getJsonObject("Category")?.getLong("Id") ?: -1
|
||||
val teacherId = event.getJsonObject("CreatedBy")?.getLong("Id") ?: -1
|
||||
val subjectId = event.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||
@ -46,6 +46,12 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
val startTime = lessonRange?.startTime ?: Time.fromH_m(event.getString("TimeFrom"))
|
||||
val addedDate = Date.fromIso(event.getString("AddDate"))
|
||||
|
||||
event.getJsonObject("onlineLessonUrl")?.let { onlineLesson ->
|
||||
val text = onlineLesson.getString("text")?.let { "$it - " } ?: ""
|
||||
val url = onlineLesson.getString("url")
|
||||
topic += "\n\n$text$url"
|
||||
}
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
@ -56,7 +62,8 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
type = type,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = teamId
|
||||
teamId = teamId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
@ -66,8 +73,7 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
grade.getJsonObject("Improvement")?.also {
|
||||
@ -98,8 +99,7 @@ class LibrusApiGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,8 @@ class LibrusApiHomework(override val data: DataLibrus,
|
||||
type = -1,
|
||||
teacherId = teacherId,
|
||||
subjectId = -1,
|
||||
teamId = -1
|
||||
teamId = -1,
|
||||
addedDate = addedDate.inMillis
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
@ -52,8 +53,7 @@ class LibrusApiHomework(override val data: DataLibrus,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate.inMillis
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ class LibrusApiLuckyNumber(override val data: DataLibrus,
|
||||
val luckyNumberDate = Date.fromY_m_d(luckyNumberEl.getString("LuckyNumberDay")) ?: Date.getToday()
|
||||
val luckyNumber = luckyNumberEl.getInt("LuckyNumber") ?: -1
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
profileId,
|
||||
luckyNumberDate,
|
||||
luckyNumber
|
||||
profileId = profileId,
|
||||
date = luckyNumberDate,
|
||||
number = luckyNumber
|
||||
)
|
||||
|
||||
if (luckyNumberDate >= Date.getToday())
|
||||
@ -50,8 +50,7 @@ class LibrusApiLuckyNumber(override val data: DataLibrus,
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +46,15 @@ class LibrusApiNotices(override val data: DataLibrus,
|
||||
val semester = profile?.dateToSemester(addedDate) ?: 1
|
||||
|
||||
val noticeObject = Notice(
|
||||
profileId,
|
||||
id,
|
||||
categoryText + "\n" + text,
|
||||
semester,
|
||||
type,
|
||||
teacherId
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = type,
|
||||
semester = semester,
|
||||
text = text,
|
||||
category = categoryText,
|
||||
points = null,
|
||||
teacherId = teacherId,
|
||||
addedDate = addedDate.inMillis
|
||||
)
|
||||
|
||||
data.noticeList.add(noticeObject)
|
||||
@ -61,8 +64,7 @@ class LibrusApiNotices(override val data: DataLibrus,
|
||||
Metadata.TYPE_NOTICE,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate.inMillis
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,8 @@ class LibrusApiPointGrades(override val data: DataLibrus,
|
||||
comment = null,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
).apply {
|
||||
valueMax = category?.valueTo ?: 0f
|
||||
}
|
||||
@ -67,8 +68,7 @@ class LibrusApiPointGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,7 @@ class LibrusApiPtMeetings(override val data: DataLibrus,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -43,15 +43,15 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
|
||||
val timeTo = teacherAbsence.getString("TimeTo")?.let { Time.fromH_m_s(it) }
|
||||
|
||||
val teacherAbsenceObject = TeacherAbsence(
|
||||
profileId,
|
||||
id,
|
||||
teacherId,
|
||||
type,
|
||||
name,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
timeFrom,
|
||||
timeTo
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = type,
|
||||
name = name,
|
||||
dateFrom = dateFrom,
|
||||
dateTo = dateTo,
|
||||
timeFrom = timeFrom,
|
||||
timeTo = timeTo,
|
||||
teacherId = teacherId
|
||||
)
|
||||
|
||||
data.teacherAbsenceList.add(teacherAbsenceObject)
|
||||
@ -60,8 +60,7 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
|
||||
Metadata.TYPE_TEACHER_ABSENCE,
|
||||
id,
|
||||
true,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,8 @@ class LibrusApiTextGrades(override val data: DataLibrus,
|
||||
comment = grade.getString("Phrase") /* whatever it is */,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
@ -69,8 +70,7 @@ class LibrusApiTextGrades(override val data: DataLibrus,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
addedDate
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -198,8 +198,7 @@ class LibrusApiTimetables(override val data: DataLibrus,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonObject.id,
|
||||
seen,
|
||||
seen,
|
||||
System.currentTimeMillis()
|
||||
seen
|
||||
))
|
||||
}
|
||||
data.lessonList.add(lessonObject)
|
||||
|
@ -4,20 +4,12 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_FINISHED
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.TYPE_PROGRESS
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LibrusMessagesGetAttachment(override val data: DataLibrus,
|
||||
@ -35,8 +27,6 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus,
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Default
|
||||
|
||||
private var getAttachmentCheckKeyTries = 0
|
||||
|
||||
init {
|
||||
messagesGet(TAG, "GetFileDownloadLink", parameters = mapOf(
|
||||
"fileId" to attachmentId,
|
||||
@ -44,80 +34,8 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus,
|
||||
"archive" to 0
|
||||
)) { doc ->
|
||||
val downloadLink = doc.select("response GetFileDownloadLink downloadLink").text()
|
||||
val keyMatcher = Regexes.LIBRUS_ATTACHMENT_KEY.find(downloadLink)
|
||||
|
||||
if (keyMatcher != null) {
|
||||
getAttachmentCheckKeyTries = 0
|
||||
|
||||
val attachmentKey = keyMatcher[1]
|
||||
getAttachmentCheckKey(attachmentKey) {
|
||||
downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey", method = POST)
|
||||
}
|
||||
} else {
|
||||
downloadAttachment("$downloadLink/get", method = GET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAttachmentCheckKey(attachmentKey: String, callback: () -> Unit) {
|
||||
sandboxGet(TAG, "CSCheckKey",
|
||||
parameters = mapOf("singleUseKey" to attachmentKey)) { json ->
|
||||
|
||||
when (json.getString("status")) {
|
||||
"not_downloaded_yet" -> {
|
||||
if (getAttachmentCheckKeyTries++ > 5) {
|
||||
data.error(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
||||
.withApiResponse(json))
|
||||
return@sandboxGet
|
||||
}
|
||||
launch {
|
||||
delay(2000)
|
||||
getAttachmentCheckKey(attachmentKey, callback)
|
||||
}
|
||||
}
|
||||
|
||||
"ready" -> {
|
||||
launch { callback() }
|
||||
}
|
||||
|
||||
else -> {
|
||||
data.error(ApiError(TAG, EXCEPTION_LIBRUS_MESSAGES_REQUEST)
|
||||
.withApiResponse(json))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadAttachment(url: String, method: Int = GET) {
|
||||
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
||||
|
||||
sandboxGetFile(TAG, url, targetFile, { file ->
|
||||
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
message.id,
|
||||
attachmentId,
|
||||
TYPE_FINISHED,
|
||||
file.absolutePath
|
||||
)
|
||||
|
||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.messageId}_${event.attachmentId}")
|
||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
||||
|
||||
EventBus.getDefault().post(event)
|
||||
|
||||
onSuccess()
|
||||
|
||||
}) { written, _ ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
message.id,
|
||||
attachmentId,
|
||||
TYPE_PROGRESS,
|
||||
bytesWritten = written
|
||||
)
|
||||
|
||||
EventBus.getDefault().post(event)
|
||||
LibrusSandboxDownloadAttachment(data, downloadLink, message, attachmentId, attachmentName, onSuccess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_MESS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.fixName
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
@ -78,7 +78,7 @@ class LibrusMessagesGetList(override val data: DataLibrus,
|
||||
|
||||
val senderId = when (type) {
|
||||
TYPE_RECEIVED -> recipientId
|
||||
else -> -1
|
||||
else -> null
|
||||
}
|
||||
|
||||
val receiverId = when (type) {
|
||||
@ -92,13 +92,13 @@ class LibrusMessagesGetList(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
val messageObject = Message(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
null,
|
||||
type,
|
||||
senderId,
|
||||
-1
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = type,
|
||||
subject = subject,
|
||||
body = null,
|
||||
senderId = senderId,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
@ -111,18 +111,17 @@ class LibrusMessagesGetList(override val data: DataLibrus,
|
||||
|
||||
element.select("isAnyFileAttached")?.text()?.let {
|
||||
if (it == "1")
|
||||
messageObject.overrideHasAttachments = true
|
||||
messageObject.hasAttachments = true
|
||||
}
|
||||
|
||||
data.messageIgnoreList.add(messageObject)
|
||||
data.messageList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
notified,
|
||||
notified,
|
||||
sentDate
|
||||
notified
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
@ -102,11 +102,10 @@ class LibrusMessagesGetMessage(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
readDate,
|
||||
messageObject.id
|
||||
profileId = profileId,
|
||||
id = -1,
|
||||
messageId = messageObject.id,
|
||||
readDate = readDate
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = profile.accountName ?: profile.studentNameLong ?: ""
|
||||
@ -132,11 +131,10 @@ class LibrusMessagesGetMessage(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId,
|
||||
receiverId,
|
||||
-1,
|
||||
readDate,
|
||||
messageObject.id
|
||||
profileId = profileId,
|
||||
id = receiverId,
|
||||
messageId = messageObject.id,
|
||||
readDate = readDate
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = "$receiverFirstName $receiverLastName"
|
||||
@ -152,14 +150,15 @@ class LibrusMessagesGetMessage(override val data: DataLibrus,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
true,
|
||||
true,
|
||||
messageObject.addedDate
|
||||
true
|
||||
))
|
||||
}
|
||||
|
||||
messageObject.recipients = messageRecipientList
|
||||
data.messageRecipientList.addAll(messageRecipientList)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
|
||||
onSuccess()
|
||||
|
@ -48,9 +48,9 @@ class LibrusMessagesSendMessage(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_SENT, lastSync = null) {
|
||||
val message = data.messageIgnoreList.firstOrNull { it.type == Message.TYPE_SENT && it.id == id }
|
||||
val message = data.messageList.firstOrNull { it.type == Message.TYPE_SENT && it.id == id }
|
||||
val metadata = data.metadataList.firstOrNull { it.thingType == Metadata.TYPE_MESSAGE && it.thingId == message?.id }
|
||||
val event = MessageSentEvent(data.profileId, message, metadata?.addedDate)
|
||||
val event = MessageSentEvent(data.profileId, message, message?.addedDate)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
onSuccess()
|
||||
|
@ -0,0 +1,117 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.io.File
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LibrusSandboxDownloadAttachment(override val data: DataLibrus,
|
||||
downloadLink: String,
|
||||
val owner: Any,
|
||||
val attachmentId: Long,
|
||||
val attachmentName: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusMessages(data, null), CoroutineScope {
|
||||
companion object {
|
||||
const val TAG = "LibrusSandboxDownloadAttachment"
|
||||
}
|
||||
|
||||
private var job = Job()
|
||||
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Default
|
||||
|
||||
private var getAttachmentCheckKeyTries = 0
|
||||
|
||||
init {
|
||||
val keyMatcher = Regexes.LIBRUS_ATTACHMENT_KEY.find(downloadLink)
|
||||
|
||||
when {
|
||||
downloadLink.contains("CSDownloadFailed") -> {
|
||||
data.error(ApiError(TAG, ERROR_LIBRUS_MESSAGES_ATTACHMENT_NOT_FOUND))
|
||||
onSuccess()
|
||||
}
|
||||
keyMatcher != null -> {
|
||||
getAttachmentCheckKeyTries = 0
|
||||
|
||||
val attachmentKey = keyMatcher[1]
|
||||
getAttachmentCheckKey(attachmentKey) {
|
||||
downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey", method = POST)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
downloadAttachment("$downloadLink/get", method = GET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAttachmentCheckKey(attachmentKey: String, callback: () -> Unit) {
|
||||
sandboxGet(TAG, "CSCheckKey",
|
||||
parameters = mapOf("singleUseKey" to attachmentKey)) { json ->
|
||||
|
||||
when (json.getString("status")) {
|
||||
"not_downloaded_yet" -> {
|
||||
if (getAttachmentCheckKeyTries++ > 5) {
|
||||
data.error(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
||||
.withApiResponse(json))
|
||||
return@sandboxGet
|
||||
}
|
||||
launch {
|
||||
delay(2000)
|
||||
getAttachmentCheckKey(attachmentKey, callback)
|
||||
}
|
||||
}
|
||||
|
||||
"ready" -> {
|
||||
launch { callback() }
|
||||
}
|
||||
|
||||
else -> {
|
||||
data.error(ApiError(TAG, EXCEPTION_LIBRUS_MESSAGES_REQUEST)
|
||||
.withApiResponse(json))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadAttachment(url: String, method: Int = GET) {
|
||||
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
||||
|
||||
sandboxGetFile(TAG, url, targetFile, { file ->
|
||||
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_FINISHED,
|
||||
file.absolutePath
|
||||
)
|
||||
|
||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.ownerId}_${event.attachmentId}")
|
||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
|
||||
onSuccess()
|
||||
|
||||
}) { written, _ ->
|
||||
val event = AttachmentGetEvent(
|
||||
profileId,
|
||||
owner,
|
||||
attachmentId,
|
||||
AttachmentGetEvent.TYPE_PROGRESS,
|
||||
bytesWritten = written
|
||||
)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusSandboxDownloadAttachment
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
|
||||
class LibrusSynergiaGetAttachment(override val data: DataLibrus,
|
||||
val message: Message,
|
||||
val attachmentId: Long,
|
||||
val attachmentName: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusSynergia(data, null) {
|
||||
companion object {
|
||||
const val TAG = "LibrusSynergiaGetAttachment"
|
||||
}
|
||||
|
||||
init {
|
||||
redirectUrlGet(TAG, "$LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL/${message.id}/$attachmentId") { url ->
|
||||
LibrusSandboxDownloadAttachment(data, url, message, attachmentId, attachmentName, onSuccess)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import android.text.Html
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
|
||||
class LibrusSynergiaGetHomework(override val data: DataLibrus,
|
||||
val event: EventFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusSynergia(data, null) {
|
||||
companion object {
|
||||
const val TAG = "LibrusSynergiaGetHomework"
|
||||
}
|
||||
|
||||
init {
|
||||
synergiaGet(TAG, "moje_zadania/podglad/${event.id}") { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
|
||||
val table = doc.select("table.decorated tbody > tr")
|
||||
|
||||
event.topic = table[1].select("td")[1].text()
|
||||
event.homeworkBody = Html.fromHtml(table[5].select("td")[1].html()).toString()
|
||||
|
||||
event.attachmentIds = mutableListOf()
|
||||
event.attachmentNames = mutableListOf()
|
||||
|
||||
if (table.size > 6) {
|
||||
table[6].select("a").forEach { a ->
|
||||
val attachmentId = a.attr("href").split('/')
|
||||
.last().toLongOrNull() ?: return@forEach
|
||||
val filename = a.text()
|
||||
event.attachmentIds?.add(attachmentId)
|
||||
event.attachmentNames?.add(filename)
|
||||
}
|
||||
}
|
||||
|
||||
data.eventList.add(event)
|
||||
data.eventListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageRecipientFull
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.swapFirstLastName
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class LibrusSynergiaGetMessage(override val data: DataLibrus,
|
||||
private val messageObject: MessageFull,
|
||||
val onSuccess: () -> Unit) : LibrusSynergia(data, null) {
|
||||
companion object {
|
||||
const val TAG = "LibrusSynergiaGetMessage"
|
||||
}
|
||||
|
||||
init {
|
||||
val endpoint = when (messageObject.type) {
|
||||
Message.TYPE_SENT -> "wiadomosci/1/6/${messageObject.id}/f0"
|
||||
else -> "wiadomosci/1/5/${messageObject.id}/f0"
|
||||
}
|
||||
|
||||
data.profile?.also { profile ->
|
||||
synergiaGet(TAG, endpoint) { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
|
||||
val messageElement = doc.select(".container-message tr")[0].child(1)
|
||||
val detailsElement = messageElement.child(1)
|
||||
val readElement = messageElement.children().last()
|
||||
|
||||
val body = messageElement.select(".container-message-content").html()
|
||||
|
||||
messageObject.apply {
|
||||
this.body = body
|
||||
|
||||
clearAttachments()
|
||||
if (messageElement.children().size >= 5) {
|
||||
messageElement.child(3).select("tr").forEachIndexed { i, attachment ->
|
||||
if (i == 0) return@forEachIndexed // Skip the header
|
||||
val filename = attachment.child(0).text().trim()
|
||||
val attachmentId = "wiadomosci\\\\/pobierz_zalacznik\\\\/[0-9]+?\\\\/([0-9]+)\"".toRegex()
|
||||
.find(attachment.select("img").attr("onclick"))?.get(1)
|
||||
?: return@forEachIndexed
|
||||
addAttachment(attachmentId.toLong(), filename, -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val messageRecipientList = mutableListOf<MessageRecipientFull>()
|
||||
|
||||
when (messageObject.type) {
|
||||
Message.TYPE_RECEIVED -> {
|
||||
val senderFullName = detailsElement.child(0).select(".left").text()
|
||||
val senderGroupName = "\\[(.+?)]".toRegex().find(senderFullName)?.get(1)?.trim()
|
||||
|
||||
data.teacherList.singleOrNull { it.id == messageObject.senderId }?.apply {
|
||||
setTeacherType(when (senderGroupName) {
|
||||
/* https://api.librus.pl/2.0/Messages/Role */
|
||||
"Pomoc techniczna Librus", "SuperAdministrator" -> Teacher.TYPE_SUPER_ADMIN
|
||||
"Administrator szkoły" -> Teacher.TYPE_SCHOOL_ADMIN
|
||||
"Dyrektor Szkoły" -> Teacher.TYPE_PRINCIPAL
|
||||
"Nauczyciel" -> Teacher.TYPE_TEACHER
|
||||
"Rodzic", "Opiekun" -> Teacher.TYPE_PARENT
|
||||
"Sekretariat" -> Teacher.TYPE_SECRETARIAT
|
||||
"Uczeń" -> Teacher.TYPE_STUDENT
|
||||
"Pedagog/Psycholog szkolny" -> Teacher.TYPE_PEDAGOGUE
|
||||
"Pracownik biblioteki" -> Teacher.TYPE_LIBRARIAN
|
||||
"Inny specjalista" -> Teacher.TYPE_SPECIALIST
|
||||
"Jednostka Nadrzędna" -> {
|
||||
typeDescription = "Jednostka Nadrzędna"
|
||||
Teacher.TYPE_OTHER
|
||||
}
|
||||
"Jednostka Samorządu Terytorialnego" -> {
|
||||
typeDescription = "Jednostka Samorządu Terytorialnego"
|
||||
Teacher.TYPE_OTHER
|
||||
}
|
||||
else -> Teacher.TYPE_OTHER
|
||||
})
|
||||
}
|
||||
|
||||
val readDateText = readElement.select(".left").text()
|
||||
val readDate = when (readDateText.isNotNullNorEmpty()) {
|
||||
true -> Date.fromIso(readDateText)
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId = profileId,
|
||||
id = -1,
|
||||
messageId = messageObject.id,
|
||||
readDate = readDate
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = profile.accountName
|
||||
?: profile.studentNameLong
|
||||
|
||||
messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
Message.TYPE_SENT -> {
|
||||
|
||||
readElement.select("tr").forEachIndexed { i, receiver ->
|
||||
if (i == 0) return@forEachIndexed // Skip the header
|
||||
|
||||
val receiverFullName = receiver.child(0).text()
|
||||
val receiverName = receiverFullName.split('(')[0].swapFirstLastName()
|
||||
|
||||
val teacher = data.teacherList.singleOrNull { it.fullName == receiverName }
|
||||
val receiverId = teacher?.id ?: -1
|
||||
|
||||
val readDate = when (val readDateText = receiver.child(1).text().trim()) {
|
||||
"NIE" -> 0
|
||||
else -> Date.fromIso(readDateText)
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId = profileId,
|
||||
id = receiverId,
|
||||
messageId = messageObject.id,
|
||||
readDate = readDate
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = receiverName
|
||||
|
||||
messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageObject.seen) {
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
messageObject.profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
true,
|
||||
true
|
||||
))
|
||||
}
|
||||
|
||||
messageObject.recipients = messageRecipientList
|
||||
data.messageRecipientList.addAll(messageRecipientList)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageListReplace = true
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
|
||||
onSuccess()
|
||||
}
|
||||
} ?: onSuccess()
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_NOT_IMPLEMENTED
|
||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class LibrusSynergiaGetMessages(override val data: DataLibrus,
|
||||
override val lastSync: Long?,
|
||||
private val type: Int = Message.TYPE_RECEIVED,
|
||||
archived: Boolean = false,
|
||||
val onSuccess: (Int) -> Unit) : LibrusSynergia(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "LibrusSynergiaGetMessages"
|
||||
}
|
||||
|
||||
init {
|
||||
val endpoint = when (type) {
|
||||
Message.TYPE_RECEIVED -> "wiadomosci/5"
|
||||
Message.TYPE_SENT -> "wiadomosci/6"
|
||||
else -> null
|
||||
}
|
||||
val endpointId = when (type) {
|
||||
Message.TYPE_RECEIVED -> ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_RECEIVED
|
||||
else -> ENDPOINT_LIBRUS_SYNERGIA_MESSAGES_SENT
|
||||
}
|
||||
|
||||
if (endpoint != null) {
|
||||
synergiaGet(TAG, endpoint) { text ->
|
||||
val doc = Jsoup.parse(text)
|
||||
|
||||
fun getRecipientId(name: String): Long = data.teacherList.singleOrNull {
|
||||
it.fullNameLastFirst == name
|
||||
}?.id ?: {
|
||||
val teacherObject = Teacher(
|
||||
profileId,
|
||||
-1 * Utils.crc16(name.swapFirstLastName().toByteArray()).toLong(),
|
||||
name.splitName()?.second!!,
|
||||
name.splitName()?.first!!
|
||||
)
|
||||
data.teacherList.put(teacherObject.id, teacherObject)
|
||||
teacherObject.id
|
||||
}.invoke()
|
||||
|
||||
doc.select(".decorated.stretch tbody > tr").forEach { messageElement ->
|
||||
val url = messageElement.select("a").first().attr("href")
|
||||
val id = Regexes.LIBRUS_MESSAGE_ID.find(url)?.get(1)?.toLong() ?: return@forEach
|
||||
val subject = messageElement.child(3).text()
|
||||
val sentDate = Date.fromIso(messageElement.child(4).text())
|
||||
val recipientName = messageElement.child(2).text().split('(')[0].fixName()
|
||||
val recipientId = getRecipientId(recipientName)
|
||||
val read = messageElement.child(2).attr("style").isNullOrBlank()
|
||||
|
||||
val senderId = when (type) {
|
||||
Message.TYPE_RECEIVED -> recipientId
|
||||
else -> null
|
||||
}
|
||||
|
||||
val receiverId = when (type) {
|
||||
Message.TYPE_RECEIVED -> -1
|
||||
else -> recipientId
|
||||
}
|
||||
|
||||
val notified = when (type) {
|
||||
Message.TYPE_SENT -> true
|
||||
else -> read || profile?.empty ?: false
|
||||
}
|
||||
|
||||
val messageObject = Message(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = type,
|
||||
subject = subject,
|
||||
body = null,
|
||||
senderId = senderId,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
receiverId,
|
||||
-1,
|
||||
if (read) 1 else 0,
|
||||
id
|
||||
)
|
||||
|
||||
messageObject.hasAttachments = !messageElement.child(1).select("img").isEmpty()
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
notified,
|
||||
notified
|
||||
))
|
||||
}
|
||||
|
||||
when (type) {
|
||||
Message.TYPE_RECEIVED -> data.setSyncNext(ENDPOINT_LIBRUS_MESSAGES_RECEIVED, SYNC_ALWAYS)
|
||||
Message.TYPE_SENT -> data.setSyncNext(ENDPOINT_LIBRUS_MESSAGES_SENT, DAY, MainActivity.DRAWER_ITEM_MESSAGES)
|
||||
}
|
||||
onSuccess(endpointId)
|
||||
}
|
||||
} else {
|
||||
data.error(TAG, ERROR_NOT_IMPLEMENTED)
|
||||
onSuccess(endpointId)
|
||||
}
|
||||
}
|
||||
}
|
@ -42,8 +42,6 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
||||
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
|
||||
val homeworkElements = homeworkTable.children()
|
||||
|
||||
val graphElements = doc.select("table[border].center td[align=left] tbody").first().children()
|
||||
|
||||
homeworkElements.forEachIndexed { i, el ->
|
||||
val elements = el.children()
|
||||
|
||||
@ -60,29 +58,9 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
||||
elements[9].select("input").attr("onclick")
|
||||
)?.get(1)?.toLong() ?: return@forEachIndexed
|
||||
|
||||
val lessons = data.db.timetableDao().getForDateNow(profileId, eventDate)
|
||||
val lessons = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessons.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
/*val moreInfo = graphElements[2 * i + 1].select("td[title]")
|
||||
.attr("title").trim()*/
|
||||
|
||||
var description = ""
|
||||
|
||||
graphElements.forEach { graphEl ->
|
||||
graphEl.select("td[title]")?.also {
|
||||
val title = it.attr("title")
|
||||
val r = "Temat: (.*?)<br.?/>Data udostępnienia: (.*?)<br.?/>Termin wykonania: (.*?)<br.?/>Treść: (.*)"
|
||||
.toRegex(RegexOption.DOT_MATCHES_ALL).find(title) ?: return@forEach
|
||||
val gTopic = r[1].trim()
|
||||
val gAddedDate = Date.fromY_m_d(r[2].trim())
|
||||
val gEventDate = Date.fromY_m_d(r[3].trim())
|
||||
if (gTopic == topic && gAddedDate == addedDate && gEventDate == eventDate) {
|
||||
description = r[4].replace("<br.?/>".toRegex(), "\n").trim()
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val seen = when (profile.empty) {
|
||||
true -> true
|
||||
else -> eventDate < Date.getToday()
|
||||
@ -93,12 +71,13 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
||||
id = id,
|
||||
date = eventDate,
|
||||
time = startTime,
|
||||
topic = "$topic\n$description",
|
||||
topic = topic,
|
||||
color = null,
|
||||
type = Event.TYPE_HOMEWORK,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = data.teamClass?.id ?: -1
|
||||
teamId = data.teamClass?.id ?: -1,
|
||||
addedDate = addedDate.inMillis
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
@ -107,8 +86,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
seen,
|
||||
seen,
|
||||
addedDate.inMillis
|
||||
seen
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.LIBRUS_SYNERGIA_HOMEWORK_ATTACHMENT_URL
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusSandboxDownloadAttachment
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
|
||||
class LibrusSynergiaHomeworkGetAttachment(
|
||||
override val data: DataLibrus,
|
||||
val event: EventFull,
|
||||
val attachmentId: Long,
|
||||
val attachmentName: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusSynergia(data, null) {
|
||||
companion object {
|
||||
const val TAG = "LibrusSynergiaHomeworkGetAttachment"
|
||||
}
|
||||
|
||||
init {
|
||||
redirectUrlGet(TAG, "$LIBRUS_SYNERGIA_HOMEWORK_ATTACHMENT_URL/$attachmentId") { url ->
|
||||
LibrusSandboxDownloadAttachment(data, url, event, attachmentId, attachmentName, onSuccess)
|
||||
}
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ class LibrusFirstLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
val accounts = json.getJsonArray("accounts")
|
||||
|
||||
if (accounts == null || accounts.size() < 1) {
|
||||
EventBus.getDefault().post(FirstLoginFinishedEvent(listOf(), data.loginStore))
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(listOf(), data.loginStore))
|
||||
onSuccess()
|
||||
return@portalGet
|
||||
}
|
||||
@ -81,7 +81,7 @@ class LibrusFirstLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
profileList.add(profile)
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
@ -116,14 +116,15 @@ class LibrusFirstLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
).apply {
|
||||
studentData["isPremium"] = account?.getBoolean("IsPremium") == true || account?.getBoolean("IsPremiumDemo") == true
|
||||
studentData["accountId"] = account.getInt("Id") ?: 0
|
||||
studentData["accountLogin"] = login
|
||||
studentData["accountLogin"] = data.apiLogin ?: login
|
||||
studentData["accountPassword"] = data.apiPassword
|
||||
studentData["accountToken"] = data.apiAccessToken
|
||||
studentData["accountTokenTime"] = data.apiTokenExpiryTime
|
||||
studentData["accountRefreshToken"] = data.apiRefreshToken
|
||||
}
|
||||
profileList.add(profile)
|
||||
|
||||
EventBus.getDefault().post(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import pl.szczodrzynski.edziennik.getUnixDate
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import java.net.HttpURLConnection.*
|
||||
|
||||
@Suppress("ConvertSecondaryConstructorToPrimary")
|
||||
class LibrusLoginApi {
|
||||
companion object {
|
||||
private const val TAG = "LoginLibrusApi"
|
||||
|
@ -10,6 +10,7 @@ import im.wangchao.mhttp.body.MediaTypeUtils
|
||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.LibrusRecaptchaHelper
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.getUnixDate
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
@ -35,17 +36,39 @@ class LibrusLoginMessages(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
onSuccess()
|
||||
}
|
||||
|
||||
text?.contains("grecaptcha.ready") == true -> {
|
||||
val url = response?.request()?.url()?.toString() ?: run {
|
||||
//data.error(TAG, ERROR_LIBRUS_MESSAGES_OTHER, response, text)
|
||||
data.messagesLoginSuccessful = false
|
||||
onSuccess()
|
||||
return
|
||||
}
|
||||
|
||||
LibrusRecaptchaHelper(data.app, url, text, onSuccess = { newUrl ->
|
||||
loginWithSynergia(newUrl)
|
||||
}, onTimeout = {
|
||||
//data.error(TAG, ERROR_LOGIN_LIBRUS_MESSAGES_TIMEOUT, response, text)
|
||||
data.messagesLoginSuccessful = false
|
||||
onSuccess()
|
||||
})
|
||||
}
|
||||
|
||||
text?.contains("<status>ok</status>") == true -> {
|
||||
saveSessionId(response, text)
|
||||
onSuccess()
|
||||
}
|
||||
text?.contains("<message>Niepoprawny login i/lub hasło.</message>") == true -> data.error(TAG, ERROR_LOGIN_LIBRUS_MESSAGES_INVALID_LOGIN, response, text)
|
||||
text?.contains("stop.png") == true -> data.error(TAG, ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED, response, text)
|
||||
text?.contains("eAccessDeny") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)
|
||||
text?.contains("eAccessDeny") == true -> {
|
||||
// data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)
|
||||
data.messagesLoginSuccessful = false
|
||||
onSuccess()
|
||||
}
|
||||
text?.contains("OffLine") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_MAINTENANCE, response, text)
|
||||
text?.contains("<status>error</status>") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ERROR, response, text)
|
||||
text?.contains("<type>eVarWhitThisNameNotExists</type>") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_ACCESS_DENIED, response, text)
|
||||
text?.contains("<error>") == true -> data.error(TAG, ERROR_LIBRUS_MESSAGES_OTHER, response, text)
|
||||
else -> data.error(TAG, ERROR_LIBRUS_MESSAGES_OTHER, response, text)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
override fun onSuccess(text: String, response: Response) {
|
||||
val location = response.headers().get("Location")
|
||||
if (location != null) {
|
||||
val authMatcher = Pattern.compile("http://localhost/bar\\?code=([A-z0-9]+?)$", Pattern.DOTALL or Pattern.MULTILINE).matcher(location)
|
||||
val authMatcher = Pattern.compile("$LIBRUS_REDIRECT_URL\\?code=([A-z0-9]+?)$", Pattern.DOTALL or Pattern.MULTILINE).matcher(location)
|
||||
when {
|
||||
authMatcher.find() -> {
|
||||
accessToken(authMatcher.group(1), null)
|
||||
@ -127,7 +127,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
.callback(object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response) {
|
||||
val location = response.headers()?.get("Location")
|
||||
if (location == "http://localhost/bar?command=close") {
|
||||
if (location == "$LIBRUS_REDIRECT_URL?command=close") {
|
||||
data.error(ApiError(TAG, ERROR_LIBRUS_PORTAL_MAINTENANCE)
|
||||
.withApiResponse(json)
|
||||
.withResponse(response))
|
||||
@ -146,12 +146,14 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
}
|
||||
val error = if (response.code() == 200) null else
|
||||
json.getJsonArray("errors")?.getString(0)
|
||||
?: json.getJsonObject("errors")?.entrySet()?.firstOrNull()?.value?.asString
|
||||
error?.let { code ->
|
||||
when {
|
||||
code.contains("Sesja logowania wygasła") -> ERROR_LOGIN_LIBRUS_PORTAL_CSRF_EXPIRED
|
||||
code.contains("Upewnij się, że nie") -> ERROR_LOGIN_LIBRUS_PORTAL_INVALID_LOGIN
|
||||
// this doesn't work anyway: `errors` is an object with `g-recaptcha-response` set
|
||||
code.contains("robotem") -> ERROR_CAPTCHA_LIBRUS_PORTAL
|
||||
code.contains("Podany adres e-mail jest nieprawidłowy.") -> ERROR_LOGIN_LIBRUS_PORTAL_INVALID_LOGIN
|
||||
else -> ERROR_LOGIN_LIBRUS_PORTAL_ACTION_ERROR
|
||||
}.let { errorCode ->
|
||||
data.error(ApiError(TAG, errorCode)
|
||||
|
@ -8,20 +8,17 @@ import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.MobidziennikData
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetAttachment
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetRecipientList
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebSendMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.firstlogin.MobidziennikFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -105,9 +102,9 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
||||
override fun markAllAnnouncementsAsRead() {}
|
||||
override fun getAnnouncement(announcement: AnnouncementFull) {}
|
||||
|
||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
||||
login(LOGIN_METHOD_MOBIDZIENNIK_WEB) {
|
||||
MobidziennikWebGetAttachment(data, message, attachmentId, attachmentName) {
|
||||
MobidziennikWebGetAttachment(data, owner, attachmentId, attachmentName) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
@ -121,6 +118,14 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEvent(eventFull: EventFull) {
|
||||
login(LOGIN_METHOD_MOBIDZIENNIK_WEB) {
|
||||
MobidziennikWebGetHomework(data, eventFull) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun firstLogin() { MobidziennikFirstLogin(data) { completed() } }
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
|
@ -17,6 +17,7 @@ const val ENDPOINT_MOBIDZIENNIK_WEB_NOTICES = 2040
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ATTENDANCE = 2050
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MANUALS = 2100
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL = 2200
|
||||
const val ENDPOINT_MOBIDZIENNIK_WEB_HOMEWORK = 2300 // not used as an endpoint
|
||||
const val ENDPOINT_MOBIDZIENNIK_API2_MAIN = 3000
|
||||
|
||||
val MobidziennikFeatures = listOf(
|
||||
|
@ -6,7 +6,10 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT_EXCUSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_RELEASED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
|
||||
class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>) {
|
||||
@ -23,7 +26,7 @@ class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>)
|
||||
val id = cols[0].toLong()
|
||||
val lessonId = cols[1].toLong()
|
||||
data.mobiLessons.singleOrNull { it.id == lessonId }?.let { lesson ->
|
||||
val type = when (cols[4]) {
|
||||
val baseType = when (cols[4]) {
|
||||
"2" -> TYPE_ABSENT
|
||||
"5" -> TYPE_ABSENT_EXCUSED
|
||||
"4" -> TYPE_RELEASED
|
||||
@ -31,16 +34,37 @@ class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>)
|
||||
}
|
||||
val semester = data.profile?.dateToSemester(lesson.date) ?: 1
|
||||
|
||||
val typeName = when (baseType) {
|
||||
TYPE_ABSENT -> "nieobecność"
|
||||
TYPE_ABSENT_EXCUSED -> "nieobecność usprawiedliwiona"
|
||||
TYPE_RELEASED -> "zwolnienie"
|
||||
TYPE_PRESENT -> "obecność"
|
||||
else -> "nieznany rodzaj"
|
||||
}
|
||||
val typeSymbol = when (baseType) {
|
||||
TYPE_ABSENT -> "|"
|
||||
TYPE_ABSENT_EXCUSED -> "+"
|
||||
TYPE_RELEASED -> "z"
|
||||
TYPE_PRESENT -> "."
|
||||
else -> "?"
|
||||
}
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
data.profileId,
|
||||
id,
|
||||
lesson.teacherId,
|
||||
lesson.subjectId,
|
||||
semester,
|
||||
lesson.topic,
|
||||
lesson.date,
|
||||
lesson.startTime,
|
||||
type)
|
||||
profileId = data.profileId,
|
||||
id = id,
|
||||
baseType = baseType,
|
||||
typeName = typeName,
|
||||
typeShort = data.app.attendanceManager.getTypeShort(baseType),
|
||||
typeSymbol = typeSymbol,
|
||||
typeColor = null,
|
||||
date = lesson.date,
|
||||
startTime = lesson.startTime,
|
||||
semester = semester,
|
||||
teacherId = lesson.teacherId,
|
||||
subjectId = lesson.subjectId
|
||||
).also {
|
||||
it.lessonTopic = lesson.topic
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
data.metadataList.add(
|
||||
@ -48,9 +72,8 @@ class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>)
|
||||
data.profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
data.profile?.empty ?: false || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN,
|
||||
data.profile?.empty ?: false || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN
|
||||
))
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user