mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-22 22:44:45 +01:00
Merge pull request #1 from szkolny-eu/feature/vulcan-hebe
Vulcan Hebe implementation
This commit is contained in:
commit
22abad35cc
@ -183,7 +183,6 @@ dependencies {
|
||||
|
||||
//implementation "org.redundent:kotlin-xml-builder:1.5.3"
|
||||
|
||||
implementation "io.github.wulkanowy:signer-android:0.1.1"
|
||||
implementation 'com.github.wulkanowy.uonet-request-signer:hebe-jvm:a99ca50a31'
|
||||
|
||||
implementation "androidx.work:work-runtime-ktx:${versions.work}"
|
||||
@ -211,7 +210,7 @@ dependencies {
|
||||
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 'com.github.kuba2k2.FSLogin:lib:2.0.0'
|
||||
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"
|
||||
|
@ -67,3 +67,6 @@
|
||||
-keepclassmembers class pl.szczodrzynski.edziennik.data.api.szkolny.request.** { *; }
|
||||
-keepclassmembers class pl.szczodrzynski.edziennik.data.api.szkolny.response.** { *; }
|
||||
-keepclassmembernames class pl.szczodrzynski.edziennik.ui.modules.login.LoginInfo$Platform { *; }
|
||||
|
||||
-keepclassmembernames class pl.szczodrzynski.fslogin.realm.RealmData { *; }
|
||||
-keepclassmembernames class pl.szczodrzynski.fslogin.realm.RealmData$Type { *; }
|
||||
|
@ -1,7 +1,8 @@
|
||||
<h3>Wersja 4.5, 2021-02-21</h3>
|
||||
<h3>Wersja 4.6-beta.1, 2021-02-25</h3>
|
||||
<ul>
|
||||
<li>Vulcan: aplikacja Szkolny.eu zaktualizowana w związku z wygaszeniem aplikacji Dzienniczek+.</li>
|
||||
<li><b>Mogą pojawić się brakujące funkcje, np. wysyłanie wiadomości - zostaną one wprowadzone w najbliższych dniach.</b></li>
|
||||
<li>Vulcan: dodano możliwość logowania adresem e-mail lub nazwą użytkownika.</li>
|
||||
<li>Vulcan: dodano obsługę załączników w wiadomościach i zadaniach domowych.</li>
|
||||
<li>Zalecane jest zalogowanie się ponownie.</li>
|
||||
</ul>
|
||||
<br>
|
||||
<br>
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
/*secret password - removed for source code publication*/
|
||||
static toys AES_IV[16] = {
|
||||
0x4f, 0x43, 0x04, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
0xe5, 0x07, 0x0f, 0xec, 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,9 @@ 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.*
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import im.wangchao.mhttp.Response
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
@ -538,6 +537,12 @@ fun String.md5(): String {
|
||||
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
|
||||
}
|
||||
|
||||
fun String.sha1Hex(): String {
|
||||
val md = MessageDigest.getInstance("SHA-1")
|
||||
md.update(toByteArray())
|
||||
return md.digest().joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
|
||||
fun String.sha256(): ByteArray {
|
||||
val md = MessageDigest.getInstance("SHA-256")
|
||||
md.update(toByteArray())
|
||||
@ -697,6 +702,21 @@ fun JsonObject(vararg properties: Pair<String, Any?>): JsonObject {
|
||||
}
|
||||
}
|
||||
|
||||
fun JsonObject.toBundle(): Bundle {
|
||||
return Bundle().also {
|
||||
for ((key, value) in this.entrySet()) {
|
||||
when (value) {
|
||||
is JsonObject -> it.putBundle(key, value.toBundle())
|
||||
is JsonPrimitive -> when {
|
||||
value.isString -> it.putString(key, value.asString)
|
||||
value.isBoolean -> it.putBoolean(key, value.asBoolean)
|
||||
value.isNumber -> it.putInt(key, value.asInt)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun JsonArray(vararg properties: Any?): JsonArray {
|
||||
return JsonArray().apply {
|
||||
for (property in properties) {
|
||||
|
@ -751,6 +751,11 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onApiTaskErrorEvent(event: ApiTaskErrorEvent) {
|
||||
EventBus.getDefault().removeStickyEvent(event)
|
||||
if (event.error.errorCode == ERROR_VULCAN_API_DEPRECATED) {
|
||||
if (event.error.profileId != App.profileId)
|
||||
return
|
||||
ErrorDetailsDialog(this, listOf(event.error))
|
||||
}
|
||||
navView.toolbar.apply {
|
||||
subtitleFormat = R.string.toolbar_subtitle
|
||||
subtitleFormatWithUnread = R.plurals.toolbar_subtitle_with_unread
|
||||
@ -758,9 +763,6 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
||||
}
|
||||
mainSnackbar.dismiss()
|
||||
errorSnackbar.addError(event.error).show()
|
||||
if (event.error.errorCode == ERROR_VULCAN_API_DEPRECATED) {
|
||||
ErrorDetailsDialog(this, listOf(event.error))
|
||||
}
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onAppManagerDetectedEvent(event: AppManagerDetectedEvent) {
|
||||
|
@ -90,11 +90,6 @@ const val IDZIENNIK_API_MESSAGES_SENT = "Wiadomosci/Wyslane"
|
||||
|
||||
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 = "20.5.1.470"
|
||||
const val VULCAN_API_PASSWORD = "CE75EA598C7743AD9B0B7328DED85B06"
|
||||
const val VULCAN_API_PASSWORD_FAKELOG = "012345678901234567890123456789AB"
|
||||
const val VULCAN_HEBE_USER_AGENT = "Dart/2.10 (dart:io)"
|
||||
const val VULCAN_HEBE_APP_NAME = "DzienniczekPlus 2.0"
|
||||
const val VULCAN_HEBE_APP_VERSION = "21.02.09 (G)"
|
||||
@ -106,36 +101,24 @@ val VULCAN_API_DEVICE_NAME by lazy {
|
||||
base.take(baseMaxLength) + VULCAN_API_DEVICE_NAME_SUFFIX
|
||||
}
|
||||
|
||||
const val VULCAN_API_ENDPOINT_CERTIFICATE = "mobile-api/Uczen.v3.UczenStart/Certyfikat"
|
||||
const val VULCAN_API_ENDPOINT_STUDENT_LIST = "mobile-api/Uczen.v3.UczenStart/ListaUczniow"
|
||||
const val VULCAN_API_ENDPOINT_DICTIONARIES = "mobile-api/Uczen.v3.Uczen/Slowniki"
|
||||
const val VULCAN_API_ENDPOINT_TIMETABLE = "mobile-api/Uczen.v3.Uczen/PlanLekcjiZeZmianami"
|
||||
const val VULCAN_API_ENDPOINT_GRADES = "mobile-api/Uczen.v3.Uczen/Oceny"
|
||||
const val VULCAN_API_ENDPOINT_GRADES_PROPOSITIONS = "mobile-api/Uczen.v3.Uczen/OcenyPodsumowanie"
|
||||
const val VULCAN_API_ENDPOINT_EVENTS = "mobile-api/Uczen.v3.Uczen/Sprawdziany"
|
||||
const val VULCAN_API_ENDPOINT_HOMEWORK = "mobile-api/Uczen.v3.Uczen/ZadaniaDomowe"
|
||||
const val VULCAN_API_ENDPOINT_NOTICES = "mobile-api/Uczen.v3.Uczen/UwagiUcznia"
|
||||
const val VULCAN_API_ENDPOINT_ATTENDANCE = "mobile-api/Uczen.v3.Uczen/Frekwencje"
|
||||
const val VULCAN_API_ENDPOINT_MESSAGES_RECEIVED = "mobile-api/Uczen.v3.Uczen/WiadomosciOdebrane"
|
||||
const val VULCAN_API_ENDPOINT_MESSAGES_SENT = "mobile-api/Uczen.v3.Uczen/WiadomosciWyslane"
|
||||
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 VULCAN_HEBE_ENDPOINT_REGISTER_NEW = "api/mobile/register/new"
|
||||
const val VULCAN_HEBE_ENDPOINT_MAIN = "api/mobile/register/hebe"
|
||||
const val VULCAN_HEBE_ENDPOINT_PUSH_ALL = "api/mobile/push/all"
|
||||
const val VULCAN_HEBE_ENDPOINT_TIMETABLE = "api/mobile/schedule"
|
||||
const val VULCAN_HEBE_ENDPOINT_TIMETABLE_CHANGES = "api/mobile/schedule/changes"
|
||||
const val VULCAN_HEBE_ENDPOINT_ADDRESSBOOK = "api/mobile/addressbook"
|
||||
const val VULCAN_HEBE_ENDPOINT_EXAMS = "api/mobile/exam"
|
||||
const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
|
||||
const val VULCAN_HEBE_ENDPOINT_GRADE_SUMMARY = "api/mobile/grade/summary"
|
||||
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
||||
const val VULCAN_HEBE_ENDPOINT_NOTICES = "api/mobile/note"
|
||||
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS = "api/mobile/message/status"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES_SEND = "api/mobile/message"
|
||||
const val VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER = "api/mobile/school/lucky"
|
||||
|
||||
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
||||
|
@ -148,17 +148,11 @@ const val ERROR_MOBIDZIENNIK_WEB_SERVER_PROBLEM = 218
|
||||
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_SYMBOL = 301
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_TOKEN = 302
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_PIN = 309
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING = 310
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_PIN_1_REMAINING = 311
|
||||
const val ERROR_LOGIN_VULCAN_INVALID_PIN_2_REMAINING = 312
|
||||
const val ERROR_LOGIN_VULCAN_EXPIRED_TOKEN = 321
|
||||
const val ERROR_LOGIN_VULCAN_OTHER = 322
|
||||
const val ERROR_LOGIN_VULCAN_ONLY_KINDERGARTEN = 330
|
||||
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
|
||||
@ -171,6 +165,12 @@ 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_VULCAN_HEBE_OTHER = 354
|
||||
const val ERROR_VULCAN_HEBE_SIGNATURE_ERROR = 360
|
||||
const val ERROR_VULCAN_HEBE_INVALID_PAYLOAD = 361
|
||||
const val ERROR_VULCAN_HEBE_FIREBASE_ERROR = 362
|
||||
const val ERROR_VULCAN_HEBE_CERTIFICATE_GONE = 363
|
||||
const val ERROR_VULCAN_HEBE_SERVER_ERROR = 364
|
||||
const val ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND = 365
|
||||
const val ERROR_VULCAN_API_DEPRECATED = 390
|
||||
|
||||
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN = 401
|
||||
@ -217,7 +217,6 @@ const val EXCEPTION_LIBRUS_PORTAL_SYNERGIA_TOKEN = 903
|
||||
const val EXCEPTION_LIBRUS_API_REQUEST = 904
|
||||
const val EXCEPTION_LIBRUS_SYNERGIA_REQUEST = 905
|
||||
const val EXCEPTION_MOBIDZIENNIK_WEB_REQUEST = 906
|
||||
const val EXCEPTION_VULCAN_API_REQUEST = 907
|
||||
const val EXCEPTION_MOBIDZIENNIK_WEB_FILE_REQUEST = 908
|
||||
const val EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST = 909
|
||||
const val EXCEPTION_NOTIFY = 910
|
||||
|
@ -16,7 +16,6 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.Mobidzie
|
||||
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.VulcanLoginHebe
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginWebMain
|
||||
import pl.szczodrzynski.edziennik.data.api.models.LoginMethod
|
||||
@ -104,7 +103,6 @@ const val LOGIN_METHOD_VULCAN_WEB_MAIN = 100
|
||||
const val LOGIN_METHOD_VULCAN_WEB_NEW = 200
|
||||
const val LOGIN_METHOD_VULCAN_WEB_OLD = 300
|
||||
const val LOGIN_METHOD_VULCAN_WEB_MESSAGES = 400
|
||||
const val LOGIN_METHOD_VULCAN_API = 500
|
||||
const val LOGIN_METHOD_VULCAN_HEBE = 600
|
||||
val vulcanLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_WEB_MAIN, VulcanLoginWebMain::class.java)
|
||||
@ -119,21 +117,11 @@ val vulcanLoginMethods = listOf(
|
||||
.withIsPossible { _, _ -> false }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_VULCAN_WEB_MAIN },*/
|
||||
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_API, VulcanLoginApi::class.java)
|
||||
.withIsPossible { _, loginStore ->
|
||||
loginStore.mode != LOGIN_MODE_VULCAN_HEBE
|
||||
}
|
||||
.withRequiredLoginMethod { _, loginStore ->
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_WEB) LOGIN_METHOD_VULCAN_WEB_MAIN else LOGIN_METHOD_NOT_NEEDED
|
||||
},
|
||||
|
||||
LoginMethod(LOGIN_TYPE_VULCAN, LOGIN_METHOD_VULCAN_HEBE, VulcanLoginHebe::class.java)
|
||||
.withIsPossible { _, loginStore ->
|
||||
loginStore.mode != LOGIN_MODE_VULCAN_API
|
||||
}
|
||||
.withRequiredLoginMethod { _, loginStore ->
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_WEB) LOGIN_METHOD_VULCAN_WEB_MAIN else LOGIN_METHOD_NOT_NEEDED
|
||||
}
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
)
|
||||
|
||||
val idziennikLoginMethods = listOf(
|
||||
|
@ -156,7 +156,7 @@ object Regexes {
|
||||
"""\(przeniesiona (z|na) lekcj[ię] ([0-9]+), (.+)\)""".toRegex()
|
||||
}
|
||||
val VULCAN_WEB_PERMISSIONS by lazy {
|
||||
"""permissions: '([A-z0-9/=+\-_]+?)'""".toRegex()
|
||||
"""permissions: '([A-z0-9/=+\-_|]+?)'""".toRegex()
|
||||
}
|
||||
val VULCAN_WEB_SYMBOL_VALIDATE by lazy {
|
||||
"""[A-z0-9]+""".toRegex(IGNORE_CASE)
|
||||
|
@ -4,28 +4,23 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.crc16
|
||||
import pl.szczodrzynski.edziennik.currentTimeUnix
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_HEBE
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_MODE_VULCAN_API
|
||||
import pl.szczodrzynski.edziennik.data.api.models.Data
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Team
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
import pl.szczodrzynski.fslogin.realm.RealmData
|
||||
|
||||
class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
||||
|
||||
fun isWebMainLoginValid() = webExpiryTime-30 > currentTimeUnix()
|
||||
&& webAuthCookie.isNotNullNorEmpty()
|
||||
&& webHost.isNotNullNorEmpty()
|
||||
&& webType.isNotNullNorEmpty()
|
||||
&& symbol.isNotNullNorEmpty()
|
||||
fun isApiLoginValid() = currentSemesterEndDate-30 > currentTimeUnix()
|
||||
&& apiFingerprint[symbol].isNotNullNorEmpty()
|
||||
&& apiPrivateKey[symbol].isNotNullNorEmpty()
|
||||
&& symbol.isNotNullNorEmpty()
|
||||
fun isWebMainLoginValid() = symbol.isNotNullNorEmpty()
|
||||
&& (webExpiryTime[symbol]?.toLongOrNull() ?: 0) - 30 > currentTimeUnix()
|
||||
&& webAuthCookie[symbol].isNotNullNorEmpty()
|
||||
&& webRealmData != null
|
||||
fun isHebeLoginValid() = hebePublicKey.isNotNullNorEmpty()
|
||||
&& hebePrivateKey.isNotNullNorEmpty()
|
||||
&& symbol.isNotNullNorEmpty()
|
||||
@ -35,34 +30,11 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
if (isWebMainLoginValid()) {
|
||||
loginMethods += LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
}
|
||||
if (isApiLoginValid()) {
|
||||
loginMethods += LOGIN_METHOD_VULCAN_API
|
||||
}
|
||||
if (isHebeLoginValid()) {
|
||||
loginMethods += LOGIN_METHOD_VULCAN_HEBE
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
// during the first sync `profile.studentClassName` is already set
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_API
|
||||
&& teamList.values().none { it.type == Team.TYPE_CLASS }) {
|
||||
profile?.studentClassName?.also { name ->
|
||||
val id = Utils.crc16(name.toByteArray()).toLong()
|
||||
|
||||
val teamObject = Team(
|
||||
profileId,
|
||||
id,
|
||||
name,
|
||||
Team.TYPE_CLASS,
|
||||
"$schoolCode:$name",
|
||||
-1
|
||||
)
|
||||
teamList.put(id, teamObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun generateUserCode() = "$schoolCode:$studentId"
|
||||
|
||||
fun buildDeviceId(): String {
|
||||
@ -224,16 +196,6 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
get() { mApiPin = mApiPin ?: loginStore.getLoginData("apiPin", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mApiPin ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("apiPin", app.gson.toJson(value)); mApiPin = value }
|
||||
|
||||
private var mApiFingerprint: Map<String?, String?>? = null
|
||||
var apiFingerprint: Map<String?, String?> = mapOf()
|
||||
get() { mApiFingerprint = mApiFingerprint ?: loginStore.getLoginData("apiFingerprint", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mApiFingerprint ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("apiFingerprint", app.gson.toJson(value)); mApiFingerprint = value }
|
||||
|
||||
private var mApiPrivateKey: Map<String?, String?>? = null
|
||||
var apiPrivateKey: Map<String?, String?> = mapOf()
|
||||
get() { mApiPrivateKey = mApiPrivateKey ?: loginStore.getLoginData("apiPrivateKey", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mApiPrivateKey ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("apiPrivateKey", app.gson.toJson(value)); mApiPrivateKey = value }
|
||||
|
||||
/* _ _ _ _____ _____
|
||||
| | | | | | /\ | __ \_ _|
|
||||
| |__| | ___| |__ ___ / \ | |__) || |
|
||||
@ -297,49 +259,15 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
\/ \/ \___|_.__/ |_| |_____/ |______\___/ \__, |_|_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
/**
|
||||
* Federation Services login type.
|
||||
* This might be one of: cufs, adfs, adfslight.
|
||||
*/
|
||||
var webType: String?
|
||||
get() { mWebType = mWebType ?: loginStore.getLoginData("webType", null); return mWebType }
|
||||
set(value) { loginStore.putLoginData("webType", value); mWebType = value }
|
||||
private var mWebType: String? = null
|
||||
var webRealmData: RealmData?
|
||||
get() { mWebRealmData = mWebRealmData ?: loginStore.getLoginData("webRealmData", JsonObject()).let {
|
||||
app.gson.fromJson(it, RealmData::class.java)
|
||||
}; return mWebRealmData }
|
||||
set(value) { loginStore.putLoginData("webRealmData", app.gson.toJsonTree(value) as JsonObject); mWebRealmData = value }
|
||||
private var mWebRealmData: RealmData? = null
|
||||
|
||||
/**
|
||||
* Web server providing the federation services login.
|
||||
* If this is present, WEB_MAIN login is considered as available.
|
||||
*/
|
||||
var webHost: String?
|
||||
get() { mWebHost = mWebHost ?: loginStore.getLoginData("webHost", null); return mWebHost }
|
||||
set(value) { loginStore.putLoginData("webHost", value); mWebHost = value }
|
||||
private var mWebHost: String? = null
|
||||
|
||||
/**
|
||||
* An ID used in ADFS & ADFSLight login types.
|
||||
*/
|
||||
var webAdfsId: String?
|
||||
get() { mWebAdfsId = mWebAdfsId ?: loginStore.getLoginData("webAdfsId", null); return mWebAdfsId }
|
||||
set(value) { loginStore.putLoginData("webAdfsId", value); mWebAdfsId = value }
|
||||
private var mWebAdfsId: String? = null
|
||||
|
||||
/**
|
||||
* A domain override for ADFS Light.
|
||||
*/
|
||||
var webAdfsDomain: String?
|
||||
get() { mWebAdfsDomain = mWebAdfsDomain ?: loginStore.getLoginData("webAdfsDomain", null); return mWebAdfsDomain }
|
||||
set(value) { loginStore.putLoginData("webAdfsDomain", value); mWebAdfsDomain = value }
|
||||
private var mWebAdfsDomain: String? = null
|
||||
|
||||
var webIsHttpCufs: Boolean
|
||||
get() { mWebIsHttpCufs = mWebIsHttpCufs ?: loginStore.getLoginData("webIsHttpCufs", false); return mWebIsHttpCufs ?: false }
|
||||
set(value) { loginStore.putLoginData("webIsHttpCufs", value); mWebIsHttpCufs = value }
|
||||
private var mWebIsHttpCufs: Boolean? = null
|
||||
|
||||
var webIsScopedAdfs: Boolean
|
||||
get() { mWebIsScopedAdfs = mWebIsScopedAdfs ?: loginStore.getLoginData("webIsScopedAdfs", false); return mWebIsScopedAdfs ?: false }
|
||||
set(value) { loginStore.putLoginData("webIsScopedAdfs", value); mWebIsScopedAdfs = value }
|
||||
private var mWebIsScopedAdfs: Boolean? = null
|
||||
val webHost
|
||||
get() = webRealmData?.host
|
||||
|
||||
var webEmail: String?
|
||||
get() { mWebEmail = mWebEmail ?: loginStore.getLoginData("webEmail", null); return mWebEmail }
|
||||
@ -359,24 +287,24 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
* If the time passes, the certificate needs to be POSTed again (if valid)
|
||||
* or re-generated.
|
||||
*/
|
||||
var webExpiryTime: Long
|
||||
get() { mWebExpiryTime = mWebExpiryTime ?: profile?.getStudentData("webExpiryTime", 0L); return mWebExpiryTime ?: 0L }
|
||||
set(value) { profile?.putStudentData("webExpiryTime", value); mWebExpiryTime = value }
|
||||
private var mWebExpiryTime: Long? = null
|
||||
var webExpiryTime: Map<String, String?> = mapOf()
|
||||
get() { mWebExpiryTime = mWebExpiryTime ?: loginStore.getLoginData("webExpiryTime", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mWebExpiryTime ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("webExpiryTime", app.gson.toJson(value)); mWebExpiryTime = value }
|
||||
private var mWebExpiryTime: Map<String, String?>? = null
|
||||
|
||||
/**
|
||||
* EfebSsoAuthCookie retrieved after posting a certificate
|
||||
*/
|
||||
var webAuthCookie: String?
|
||||
get() { mWebAuthCookie = mWebAuthCookie ?: profile?.getStudentData("webAuthCookie", null); return mWebAuthCookie }
|
||||
set(value) { profile?.putStudentData("webAuthCookie", value); mWebAuthCookie = value }
|
||||
private var mWebAuthCookie: String? = null
|
||||
var webAuthCookie: Map<String, String?> = mapOf()
|
||||
get() { mWebAuthCookie = mWebAuthCookie ?: loginStore.getLoginData("webAuthCookie", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mWebAuthCookie ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("webAuthCookie", app.gson.toJson(value)); mWebAuthCookie = value }
|
||||
private var mWebAuthCookie: Map<String, String?>? = null
|
||||
|
||||
/**
|
||||
* Permissions needed to get JSONs from home page
|
||||
*/
|
||||
var webPermissions: String?
|
||||
get() { mWebPermissions = mWebPermissions ?: profile?.getStudentData("webPermissions", null); return mWebPermissions }
|
||||
set(value) { profile?.putStudentData("webPermissions", value); mWebPermissions = value }
|
||||
private var mWebPermissions: String? = null
|
||||
var webPermissions: Map<String, String?> = mapOf()
|
||||
get() { mWebPermissions = mWebPermissions ?: loginStore.getLoginData("webPermissions", null)?.let { app.gson.fromJson(it, field.toMutableMap()::class.java) }; return mWebPermissions ?: mapOf() }
|
||||
set(value) { loginStore.putLoginData("webPermissions", app.gson.toJson(value)); mWebPermissions = value }
|
||||
private var mWebPermissions: Map<String, String?>? = null
|
||||
}
|
||||
|
@ -10,10 +10,8 @@ import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.helper.OneDriveDownloadAttachment
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanData
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiAttachments
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiMessagesChangeStatus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiSendMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeMessagesChangeStatus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeSendMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.firstlogin.VulcanFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||
@ -68,6 +66,11 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
|
||||
private fun login(loginMethodId: Int? = null, afterLogin: (() -> Unit)? = null) {
|
||||
if (data.loginStore.mode == LOGIN_MODE_VULCAN_API) {
|
||||
data.error(TAG, ERROR_VULCAN_API_DEPRECATED)
|
||||
return
|
||||
}
|
||||
|
||||
d(TAG, "Trying to login with ${data.targetLoginMethodIds}")
|
||||
if (internalErrorList.isNotEmpty()) {
|
||||
d(TAG, " - Internal errors:")
|
||||
@ -92,51 +95,21 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
|
||||
override fun getMessage(message: MessageFull) {
|
||||
if (loginStore.mode != LOGIN_MODE_VULCAN_API) {
|
||||
login(LOGIN_METHOD_VULCAN_HEBE) {
|
||||
if (message.seen) {
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||
completed()
|
||||
return@login
|
||||
}
|
||||
VulcanHebeMessagesChangeStatus(data, message) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
login(LOGIN_METHOD_VULCAN_API) {
|
||||
if (message.attachmentIds != null) {
|
||||
VulcanApiMessagesChangeStatus(data, message) {
|
||||
completed()
|
||||
}
|
||||
login(LOGIN_METHOD_VULCAN_HEBE) {
|
||||
if (message.seen) {
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||
completed()
|
||||
return@login
|
||||
}
|
||||
val list = data.app.db.messageDao().getAllNow(data.profileId)
|
||||
VulcanApiAttachments(data, list, message, MessageFull::class) { _ ->
|
||||
list.forEach {
|
||||
if (it.attachmentIds == null)
|
||||
it.attachmentIds = mutableListOf()
|
||||
data.messageList.add(it)
|
||||
}
|
||||
data.messageListReplace = true
|
||||
|
||||
if (message.seen) {
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
||||
completed()
|
||||
return@VulcanApiAttachments
|
||||
}
|
||||
VulcanApiMessagesChangeStatus(data, message) {
|
||||
completed()
|
||||
}
|
||||
VulcanHebeMessagesChangeStatus(data, message) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendMessage(recipients: List<Teacher>, subject: String, text: String) {
|
||||
login(LOGIN_METHOD_VULCAN_API) {
|
||||
VulcanApiSendMessage(data, recipients, subject, text) {
|
||||
login(LOGIN_METHOD_VULCAN_HEBE) {
|
||||
VulcanHebeSendMessage(data, recipients, subject, text) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
@ -190,19 +163,10 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
|
||||
override fun getEvent(eventFull: EventFull) {
|
||||
login(LOGIN_METHOD_VULCAN_API) {
|
||||
val list = data.app.db.eventDao().getAllNow(data.profileId).filter { !it.addedManually }
|
||||
VulcanApiAttachments(data, list, eventFull, EventFull::class) { _ ->
|
||||
list.forEach {
|
||||
it.homeworkBody = ""
|
||||
data.eventList.add(it)
|
||||
}
|
||||
data.eventListReplace = true
|
||||
eventFull.homeworkBody = ""
|
||||
|
||||
EventBus.getDefault().postSticky(EventGetEvent(eventFull))
|
||||
completed()
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().postSticky(EventGetEvent(eventFull))
|
||||
completed()
|
||||
}
|
||||
|
||||
override fun firstLogin() { VulcanFirstLogin(data) { completed() } }
|
||||
|
@ -7,77 +7,49 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.models.Feature
|
||||
|
||||
const val ENDPOINT_VULCAN_API_UPDATE_SEMESTER = 1000
|
||||
const val ENDPOINT_VULCAN_API_PUSH_CONFIG = 1005
|
||||
const val ENDPOINT_VULCAN_API_DICTIONARIES = 1010
|
||||
const val ENDPOINT_VULCAN_API_TIMETABLE = 1020
|
||||
const val ENDPOINT_VULCAN_API_EVENTS = 1030
|
||||
const val ENDPOINT_VULCAN_API_GRADES = 1040
|
||||
const val ENDPOINT_VULCAN_API_GRADES_SUMMARY = 1050
|
||||
const val ENDPOINT_VULCAN_API_HOMEWORK = 1060
|
||||
const val ENDPOINT_VULCAN_API_NOTICES = 1070
|
||||
const val ENDPOINT_VULCAN_API_ATTENDANCE = 1080
|
||||
const val ENDPOINT_VULCAN_API_MESSAGES_INBOX = 1090
|
||||
const val ENDPOINT_VULCAN_API_MESSAGES_SENT = 1100
|
||||
const val ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS = 2010
|
||||
|
||||
const val ENDPOINT_VULCAN_HEBE_MAIN = 3000
|
||||
const val ENDPOINT_VULCAN_HEBE_PUSH_CONFIG = 3005
|
||||
const val ENDPOINT_VULCAN_HEBE_ADDRESSBOOK = 3010
|
||||
const val ENDPOINT_VULCAN_HEBE_TIMETABLE = 3020
|
||||
const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030
|
||||
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
||||
const val ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY = 3050
|
||||
const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
||||
const val ENDPOINT_VULCAN_HEBE_NOTICES = 3070
|
||||
const val ENDPOINT_VULCAN_HEBE_ATTENDANCE = 3080
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX = 3090
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_SENT = 3100
|
||||
const val ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER = 3200
|
||||
|
||||
val VulcanFeatures = listOf(
|
||||
// timetable
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_TIMETABLE, listOf(
|
||||
ENDPOINT_VULCAN_API_TIMETABLE to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_TIMETABLE, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_TIMETABLE to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// agenda
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
||||
ENDPOINT_VULCAN_API_EVENTS to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_EXAMS to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// grades
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_GRADES, listOf(
|
||||
ENDPOINT_VULCAN_API_GRADES to LOGIN_METHOD_VULCAN_API,
|
||||
ENDPOINT_VULCAN_API_GRADES_SUMMARY to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_GRADES, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_GRADES to LOGIN_METHOD_VULCAN_HEBE
|
||||
ENDPOINT_VULCAN_HEBE_GRADES to LOGIN_METHOD_VULCAN_HEBE,
|
||||
ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// homework
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf(
|
||||
ENDPOINT_VULCAN_API_HOMEWORK to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_HOMEWORK to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// behaviour
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf(
|
||||
ENDPOINT_VULCAN_API_NOTICES to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
ENDPOINT_VULCAN_HEBE_NOTICES to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// attendance
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
||||
ENDPOINT_VULCAN_API_ATTENDANCE to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// messages
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_MESSAGES_INBOX, listOf(
|
||||
ENDPOINT_VULCAN_API_MESSAGES_INBOX to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_MESSAGES_SENT, listOf(
|
||||
ENDPOINT_VULCAN_API_MESSAGES_SENT to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_MESSAGES_INBOX, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
@ -87,8 +59,8 @@ val VulcanFeatures = listOf(
|
||||
|
||||
// push config
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_PUSH_CONFIG, listOf(
|
||||
ENDPOINT_VULCAN_API_PUSH_CONFIG to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)).withShouldSync { data ->
|
||||
ENDPOINT_VULCAN_HEBE_PUSH_CONFIG to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)).withShouldSync { data ->
|
||||
!data.app.config.sync.tokenVulcanList.contains(data.profileId)
|
||||
},
|
||||
|
||||
@ -97,39 +69,20 @@ val VulcanFeatures = listOf(
|
||||
*/
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_LUCKY_NUMBER, listOf(
|
||||
ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS to LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB_MAIN)).withShouldSync { data -> data.shouldSyncLuckyNumber() },
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB_MAIN))
|
||||
.withShouldSync { data -> data.shouldSyncLuckyNumber() }
|
||||
.withPriority(2),
|
||||
/**
|
||||
* Lucky number - using Hebe API
|
||||
*/
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_LUCKY_NUMBER, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE))
|
||||
.withShouldSync { data -> data.shouldSyncLuckyNumber() }
|
||||
.withPriority(1),
|
||||
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_VULCAN_API_UPDATE_SEMESTER to LOGIN_METHOD_VULCAN_API,
|
||||
ENDPOINT_VULCAN_API_DICTIONARIES to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_MAIN to LOGIN_METHOD_VULCAN_HEBE,
|
||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE))
|
||||
/*Feature(LOGIN_TYPE_VULCAN, FEATURE_STUDENT_INFO, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_STUDENT_NUMBER, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_SCHOOL_INFO, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_CLASS_INFO, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_TEAM_INFO, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_TEACHERS, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_SUBJECTS, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_CLASSROOMS, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),*/
|
||||
|
||||
)
|
||||
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-19
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.JsonCallbackHandler
|
||||
import io.github.wulkanowy.signer.android.signContent
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import java.net.HttpURLConnection
|
||||
import java.util.*
|
||||
|
||||
open class VulcanApi(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApi"
|
||||
}
|
||||
|
||||
val profileId
|
||||
get() = data.profile?.id ?: -1
|
||||
|
||||
val profile
|
||||
get() = data.profile
|
||||
|
||||
fun apiGet(
|
||||
tag: String,
|
||||
endpoint: String,
|
||||
method: Int = POST,
|
||||
parameters: Map<String, Any> = emptyMap(),
|
||||
baseUrl: Boolean = false,
|
||||
onSuccess: (json: JsonObject, response: Response?) -> Unit
|
||||
) {
|
||||
val url = "${if (baseUrl) data.apiUrl else data.fullApiUrl}$endpoint"
|
||||
|
||||
d(tag, "Request: Vulcan/Api - $url")
|
||||
|
||||
val finalPayload = JsonObject()
|
||||
parameters.map { (name, value) ->
|
||||
when (value) {
|
||||
is JsonObject -> finalPayload.add(name, value)
|
||||
is JsonArray -> finalPayload.add(name, value)
|
||||
is String -> finalPayload.addProperty(name, value)
|
||||
is Int -> finalPayload.addProperty(name, value)
|
||||
is Long -> finalPayload.addProperty(name, value)
|
||||
is Float -> finalPayload.addProperty(name, value)
|
||||
is Char -> finalPayload.addProperty(name, value)
|
||||
is Boolean -> finalPayload.addProperty(name, value)
|
||||
}
|
||||
}
|
||||
finalPayload.addProperty("RemoteMobileTimeKey", System.currentTimeMillis() / 1000)
|
||||
finalPayload.addProperty("TimeKey", System.currentTimeMillis() / 1000 - 1)
|
||||
finalPayload.addProperty("RequestId", UUID.randomUUID().toString())
|
||||
finalPayload.addProperty("RemoteMobileAppVersion", VULCAN_API_APP_VERSION)
|
||||
finalPayload.addProperty("RemoteMobileAppName", VULCAN_API_APP_NAME)
|
||||
|
||||
val callback = object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||
if (json == null && response?.parserErrorBody == null) {
|
||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
if (response?.code() ?: 200 != 200) {
|
||||
when (response?.code()) {
|
||||
503 -> ERROR_VULCAN_API_MAINTENANCE
|
||||
400 -> ERROR_VULCAN_API_BAD_REQUEST
|
||||
else -> ERROR_VULCAN_API_OTHER
|
||||
}.let { errorCode ->
|
||||
data.error(ApiError(tag, errorCode)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json?.toString() ?: response?.parserErrorBody))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (json == null) {
|
||||
data.error(ApiError(tag, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
onSuccess(json, response)
|
||||
} catch (e: Exception) {
|
||||
data.error(ApiError(tag, EXCEPTION_VULCAN_API_REQUEST)
|
||||
.withResponse(response)
|
||||
.withThrowable(e)
|
||||
.withApiResponse(json))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(url)
|
||||
.userAgent(VULCAN_API_USER_AGENT)
|
||||
.addHeader("RequestCertificateKey", data.apiFingerprint[data.symbol])
|
||||
.addHeader("RequestSignatureValue",
|
||||
try {
|
||||
signContent(
|
||||
data.apiPrivateKey[data.symbol] ?: "",
|
||||
finalPayload.toString()
|
||||
)
|
||||
} catch (e: Exception) {e.printStackTrace();""})
|
||||
.apply {
|
||||
when (method) {
|
||||
GET -> get()
|
||||
POST -> post()
|
||||
}
|
||||
}
|
||||
.setJsonBody(finalPayload)
|
||||
.allowErrorCode(HttpURLConnection.HTTP_BAD_REQUEST)
|
||||
.allowErrorCode(HttpURLConnection.HTTP_FORBIDDEN)
|
||||
.allowErrorCode(HttpURLConnection.HTTP_UNAUTHORIZED)
|
||||
.allowErrorCode(HttpURLConnection.HTTP_UNAVAILABLE)
|
||||
.callback(callback)
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
}
|
@ -5,10 +5,7 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data
|
||||
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_VULCAN_API_DEPRECATED
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_MODE_VULCAN_API
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.web.VulcanWebLuckyNumber
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
@ -22,17 +19,18 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
private var firstSemesterSync = false
|
||||
private val firstSemesterSyncExclude = listOf(
|
||||
ENDPOINT_VULCAN_HEBE_MAIN,
|
||||
ENDPOINT_VULCAN_HEBE_PUSH_CONFIG,
|
||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK,
|
||||
ENDPOINT_VULCAN_HEBE_TIMETABLE,
|
||||
ENDPOINT_VULCAN_HEBE_EXAMS,
|
||||
ENDPOINT_VULCAN_HEBE_HOMEWORK,
|
||||
ENDPOINT_VULCAN_HEBE_NOTICES,
|
||||
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX,
|
||||
ENDPOINT_VULCAN_HEBE_MESSAGES_SENT
|
||||
ENDPOINT_VULCAN_HEBE_MESSAGES_SENT,
|
||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER
|
||||
)
|
||||
|
||||
init { run {
|
||||
if (data.loginStore.mode == LOGIN_MODE_VULCAN_API) {
|
||||
data.error(TAG, ERROR_VULCAN_API_DEPRECATED)
|
||||
return@run
|
||||
}
|
||||
init {
|
||||
if (data.studentSemesterNumber == 2 && data.profile?.empty != false) {
|
||||
firstSemesterSync = true
|
||||
// set to sync 1st semester first
|
||||
@ -47,7 +45,7 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
}
|
||||
onSuccess()
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
private fun nextEndpoint(onSuccess: () -> Unit) {
|
||||
if (data.targetEndpointIds.isEmpty()) {
|
||||
@ -83,54 +81,6 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||
when (endpointId) {
|
||||
ENDPOINT_VULCAN_API_UPDATE_SEMESTER -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
VulcanApiUpdateSemester(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_PUSH_CONFIG -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_push_config)
|
||||
VulcanApiPushConfig(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_DICTIONARIES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_dictionaries)
|
||||
VulcanApiDictionaries(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
VulcanApiGrades(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_GRADES_SUMMARY -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_proposed_grades)
|
||||
VulcanApiProposedGrades(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_EVENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_events)
|
||||
VulcanApiEvents(data, isHomework = false, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
VulcanApiEvents(data, isHomework = true, lastSync = lastSync, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||
VulcanApiNotices(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanApiAttendance(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_TIMETABLE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
||||
VulcanApiTimetable(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_MESSAGES_INBOX -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
VulcanApiMessagesInbox(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
VulcanApiMessagesSent(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
VulcanWebLuckyNumber(data, lastSync, onSuccess)
|
||||
@ -148,6 +98,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_MAIN)
|
||||
}
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_PUSH_CONFIG -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_push_config)
|
||||
VulcanHebePushConfig(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teachers)
|
||||
VulcanHebeAddressbook(data, lastSync, onSuccess)
|
||||
@ -164,10 +118,22 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
VulcanHebeGrades(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_proposed_grades)
|
||||
VulcanHebeGradeSummary(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
VulcanHebeHomework(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||
VulcanHebeNotices(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanHebeAttendance(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_RECEIVED)
|
||||
@ -176,9 +142,9 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_SENT)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanHebeAttendance(data, lastSync, onSuccess)
|
||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
VulcanHebeLuckyNumber(data, lastSync, onSuccess)
|
||||
}
|
||||
else -> onSuccess(endpointId)
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data
|
||||
|
||||
import android.os.Build
|
||||
@ -42,7 +46,11 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
val profile
|
||||
get() = data.profile
|
||||
|
||||
fun getDateTime(json: JsonObject?, key: String, default: Long = System.currentTimeMillis()): Long {
|
||||
fun getDateTime(
|
||||
json: JsonObject?,
|
||||
key: String,
|
||||
default: Long = System.currentTimeMillis()
|
||||
): Long {
|
||||
val date = json.getJsonObject(key)
|
||||
return date.getLong("Timestamp") ?: return default
|
||||
}
|
||||
@ -142,6 +150,18 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
2
|
||||
}
|
||||
|
||||
fun isCurrentYear(date: Date): Boolean {
|
||||
return profile?.let { profile ->
|
||||
return@let date >= profile.dateSemester1Start
|
||||
} ?: false
|
||||
}
|
||||
|
||||
fun isCurrentYear(dateTime: Long): Boolean {
|
||||
return profile?.let { profile ->
|
||||
return@let dateTime >= profile.dateSemester1Start.inMillis
|
||||
} ?: false
|
||||
}
|
||||
|
||||
inline fun <reified T> apiRequest(
|
||||
tag: String,
|
||||
endpoint: String,
|
||||
@ -193,27 +213,56 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
val callback = object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||
if (json == null) {
|
||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||
data.error(
|
||||
ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val status = json.getJsonObject("Status")
|
||||
if (status?.getInt("Code") != 0) {
|
||||
data.error(ApiError(tag, ERROR_VULCAN_HEBE_OTHER)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json.toString()))
|
||||
val statusCode = status?.getInt("Code") ?: 0
|
||||
if (statusCode != 0) {
|
||||
val statusMessage = status?.getString("Message")
|
||||
val errorCode = when (statusCode) {
|
||||
-1 -> ERROR_VULCAN_HEBE_SERVER_ERROR
|
||||
100 -> ERROR_VULCAN_HEBE_SIGNATURE_ERROR
|
||||
101 -> ERROR_VULCAN_HEBE_INVALID_PAYLOAD
|
||||
106 -> ERROR_VULCAN_HEBE_FIREBASE_ERROR
|
||||
108 -> ERROR_VULCAN_HEBE_CERTIFICATE_GONE
|
||||
200 -> when (true) {
|
||||
statusMessage?.contains("Class") -> ERROR_LOGIN_VULCAN_NO_PUPILS
|
||||
statusMessage?.contains("Token") -> ERROR_LOGIN_VULCAN_INVALID_TOKEN
|
||||
else -> ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND
|
||||
}
|
||||
201 -> ERROR_LOGIN_VULCAN_EXPIRED_TOKEN
|
||||
203 -> when (json.getJsonObject("Envelope").getInt("AvailableRetries")) {
|
||||
2 -> ERROR_LOGIN_VULCAN_INVALID_PIN_2_REMAINING
|
||||
1 -> ERROR_LOGIN_VULCAN_INVALID_PIN_1_REMAINING
|
||||
else -> ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING
|
||||
}
|
||||
204 -> ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING
|
||||
else -> ERROR_VULCAN_HEBE_OTHER
|
||||
}
|
||||
data.error(
|
||||
ApiError(tag, errorCode)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json.toString())
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val envelope = when (T::class.java) {
|
||||
val envelope = if (json.get("Envelope").isJsonNull && null is T)
|
||||
null as T
|
||||
else when (T::class.java) {
|
||||
JsonObject::class.java -> json.getJsonObject("Envelope") as T
|
||||
JsonArray::class.java -> json.getJsonArray("Envelope") as T
|
||||
java.lang.Boolean::class.java -> json.getBoolean("Envelope") as T
|
||||
else -> {
|
||||
data.error(ApiError(tag, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json)
|
||||
data.error(
|
||||
ApiError(tag, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json)
|
||||
)
|
||||
return
|
||||
}
|
||||
@ -222,7 +271,8 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
try {
|
||||
onSuccess(envelope, response)
|
||||
} catch (e: Exception) {
|
||||
data.error(ApiError(tag, EXCEPTION_VULCAN_HEBE_REQUEST)
|
||||
data.error(
|
||||
ApiError(tag, EXCEPTION_VULCAN_HEBE_REQUEST)
|
||||
.withResponse(response)
|
||||
.withThrowable(e)
|
||||
.withApiResponse(json)
|
||||
@ -231,7 +281,8 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||
data.error(
|
||||
ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable)
|
||||
)
|
||||
@ -347,10 +398,15 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
if (folder != null)
|
||||
query["folder"] = folder.toString()
|
||||
|
||||
val semester1Start = profile?.dateSemester1Start?.inMillis
|
||||
|
||||
query["lastId"] = "-2147483648" // don't ask, it's just Vulcan
|
||||
query["pageSize"] = "500"
|
||||
query["lastSyncDate"] = LocalDateTime
|
||||
.ofInstant(Instant.ofEpochMilli(lastSync ?: 0), ZoneId.systemDefault())
|
||||
.ofInstant(
|
||||
Instant.ofEpochMilli(lastSync ?: semester1Start ?: 0),
|
||||
ZoneId.systemDefault()
|
||||
)
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
|
||||
apiGet(tag, url, query) { json: JsonArray, response ->
|
||||
|
@ -11,12 +11,11 @@ import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||
import pl.droidsonroids.jspoon.Jspoon
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.CufsCertificate
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorBlank
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import java.io.File
|
||||
@ -83,10 +82,12 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
onResult(symbol, STATE_NO_REGISTER)
|
||||
return
|
||||
}
|
||||
if (!validateCallback(text, response, jsonResponse = false)) {
|
||||
if (!validateCallback(symbol, text, response, jsonResponse = false)) {
|
||||
return
|
||||
}
|
||||
data.webExpiryTime = Date.fromIso(certificate.expiryDate) / 1000L
|
||||
data.webExpiryTime = data.webExpiryTime.toMutableMap().also { map ->
|
||||
map[symbol] = (Date.fromIso(certificate.expiryDate) / 1000L).toString()
|
||||
}
|
||||
onResult(symbol, STATE_SUCCESS)
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
fun getStartPage(symbol: String = data.symbol ?: "default", postErrors: Boolean = true, onSuccess: (html: String, schoolSymbols: List<String>) -> Unit) {
|
||||
val callback = object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String?, response: Response?) {
|
||||
if (!validateCallback(text, response, jsonResponse = false) || text == null) {
|
||||
if (!validateCallback(symbol, text, response, jsonResponse = false) || text == null) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -136,7 +137,30 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
}
|
||||
}
|
||||
|
||||
data.webPermissions = Regexes.VULCAN_WEB_PERMISSIONS.find(text)?.let { it[1] }
|
||||
data.webPermissions = data.webPermissions.toMutableMap().also { map ->
|
||||
val permissions = Regexes.VULCAN_WEB_PERMISSIONS.find(text)?.let { it[1] }
|
||||
if (permissions?.isNotBlank() == true) {
|
||||
val studentId = permissions.split("|")
|
||||
.getOrNull(0)
|
||||
?.base64DecodeToString()
|
||||
?.toJsonObject()
|
||||
?.getJsonArray("AuthInfos")
|
||||
?.asJsonObjectList()
|
||||
?.flatMap { authInfo ->
|
||||
authInfo.getJsonArray("UczenIds")
|
||||
?.map { it.asInt }
|
||||
?: listOf()
|
||||
}
|
||||
?.firstOrNull()
|
||||
?.toString()
|
||||
data.app.cookieJar.set(
|
||||
data.webHost ?: "vulcan.net.pl",
|
||||
"idBiezacyUczen",
|
||||
studentId
|
||||
)
|
||||
}
|
||||
map[symbol] = permissions
|
||||
}
|
||||
|
||||
val schoolSymbols = mutableListOf<String>()
|
||||
val clientUrl = "://uonetplus-uczen.${data.webHost}/$symbol/"
|
||||
@ -144,7 +168,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
var count = 0
|
||||
while (clientIndex != -1 && count < 100) {
|
||||
val startIndex = clientIndex + clientUrl.length
|
||||
val endIndex = text.indexOf('/', startIndex = startIndex)
|
||||
val endIndex = text.indexOfAny(charArrayOf('"', '/'), startIndex = startIndex)
|
||||
val schoolSymbol = text.substring(startIndex, endIndex)
|
||||
schoolSymbols += schoolSymbol
|
||||
clientIndex = text.indexOf(clientUrl, startIndex = endIndex)
|
||||
@ -186,7 +210,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
.enqueue()
|
||||
}
|
||||
|
||||
private fun validateCallback(text: String?, response: Response?, jsonResponse: Boolean = true): Boolean {
|
||||
private fun validateCallback(symbol: String, text: String?, response: Response?, jsonResponse: Boolean = true): Boolean {
|
||||
if (text == null) {
|
||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response))
|
||||
@ -207,11 +231,13 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
|
||||
val cookies = data.app.cookieJar.getAll(data.webHost ?: "vulcan.net.pl")
|
||||
val authCookie = cookies["EfebSsoAuthCookie"]
|
||||
if ((authCookie == null || authCookie == "null") && data.webAuthCookie != null) {
|
||||
data.app.cookieJar.set(data.webHost ?: "vulcan.net.pl", "EfebSsoAuthCookie", data.webAuthCookie)
|
||||
if ((authCookie == null || authCookie == "null") && data.webAuthCookie[symbol] != null) {
|
||||
data.app.cookieJar.set(data.webHost ?: "vulcan.net.pl", "EfebSsoAuthCookie", data.webAuthCookie[symbol])
|
||||
}
|
||||
else if (authCookie.isNotNullNorBlank() && authCookie != "null" && authCookie != data.webAuthCookie) {
|
||||
data.webAuthCookie = authCookie
|
||||
else if (authCookie.isNotNullNorBlank() && authCookie != "null" && authCookie != data.webAuthCookie[symbol]) {
|
||||
data.webAuthCookie = data.webAuthCookie.toMutableMap().also { map ->
|
||||
map[symbol] = authCookie
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -250,7 +276,7 @@ open class VulcanWebMain(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
|
||||
val callback = object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String?, response: Response?) {
|
||||
if (!validateCallback(text, response))
|
||||
if (!validateCallback(data.symbol ?: "default", text, response))
|
||||
return
|
||||
|
||||
try {
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-4-6.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class VulcanApiAttachments(override val data: DataVulcan,
|
||||
val list: List<*>,
|
||||
val owner: Any?,
|
||||
val ownerClass: KClass<*>,
|
||||
val onSuccess: (list: List<*>) -> Unit
|
||||
) : VulcanApi(data, null) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiAttachments"
|
||||
}
|
||||
|
||||
init { run {
|
||||
val endpoint = when (ownerClass) {
|
||||
MessageFull::class -> VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS
|
||||
EventFull::class -> VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS
|
||||
else -> null
|
||||
} ?: return@run
|
||||
|
||||
val idName = when (ownerClass) {
|
||||
MessageFull::class -> "IdWiadomosc"
|
||||
EventFull::class -> "IdZadanieDomowe"
|
||||
else -> null
|
||||
} ?: return@run
|
||||
|
||||
val startDate = profile?.getSemesterStart(profile?.currentSemester ?: 1)?.inUnix ?: 0
|
||||
val endDate = Date.getToday().stepForward(0, 1, 0).inUnix
|
||||
|
||||
apiGet(TAG, endpoint, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
|
||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { attachment ->
|
||||
val id = attachment.getLong("Id") ?: return@forEach
|
||||
val itemId = attachment.getLong(idName) ?: return@forEach
|
||||
val url = attachment.getString("Url") ?: return@forEach
|
||||
val fileName = "${attachment.getString("NazwaPliku")}:$url"
|
||||
|
||||
list.forEach {
|
||||
if (it is MessageFull
|
||||
&& it.profileId == profileId
|
||||
&& it.id == itemId
|
||||
&& it.attachmentIds?.contains(id) != true) {
|
||||
if (it.attachmentIds == null)
|
||||
it.attachmentIds = mutableListOf()
|
||||
if (it.attachmentNames == null)
|
||||
it.attachmentNames = mutableListOf()
|
||||
it.attachmentIds?.add(id)
|
||||
it.attachmentNames?.add(fileName)
|
||||
}
|
||||
|
||||
if (it is EventFull
|
||||
&& it.profileId == profileId
|
||||
&& it.id == itemId
|
||||
&& it.attachmentIds?.contains(id) != true) {
|
||||
if (it.attachmentIds == null)
|
||||
it.attachmentIds = mutableListOf()
|
||||
if (it.attachmentNames == null)
|
||||
it.attachmentNames = mutableListOf()
|
||||
it.attachmentIds?.add(id)
|
||||
it.attachmentNames?.add(fileName)
|
||||
}
|
||||
|
||||
if (owner is MessageFull
|
||||
&& it is MessageFull
|
||||
&& owner.profileId == it.profileId
|
||||
&& owner.id == it.id) {
|
||||
owner.attachmentIds = it.attachmentIds
|
||||
owner.attachmentNames = it.attachmentNames
|
||||
}
|
||||
|
||||
if (owner is EventFull
|
||||
&& it is EventFull
|
||||
&& owner.profileId == it.profileId
|
||||
&& owner.id == it.id) {
|
||||
owner.attachmentIds = it.attachmentIds
|
||||
owner.attachmentNames = it.attachmentNames
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (owner is MessageFull) {
|
||||
list.forEach {
|
||||
(it as? MessageFull)?.let { message ->
|
||||
data.messageList.add(message)
|
||||
}
|
||||
}
|
||||
data.messageListReplace = true
|
||||
}
|
||||
|
||||
if (owner is EventFull) {
|
||||
list.forEach {
|
||||
(it as? EventFull)?.let { it1 ->
|
||||
it1.homeworkBody = ""
|
||||
data.eventList.add(it1)
|
||||
}
|
||||
}
|
||||
data.eventListReplace = true
|
||||
}*/
|
||||
|
||||
onSuccess(list)
|
||||
}
|
||||
}}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import androidx.core.util.isEmpty
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_ATTENDANCE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_ATTENDANCE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class VulcanApiAttendance(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiAttendance"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
if (data.attendanceTypes.isEmpty()) {
|
||||
data.db.attendanceTypeDao().getAllNow(profileId).toSparseArray(data.attendanceTypes) { it.id }
|
||||
}
|
||||
|
||||
val semesterId = data.studentSemesterId
|
||||
val semesterNumber = data.studentSemesterNumber
|
||||
if (semesterNumber == 2 && lastSync ?: 0 < profile.dateSemester1Start.inMillis) {
|
||||
getAttendance(profile, semesterId - 1, semesterNumber - 1) {
|
||||
getAttendance(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getAttendance(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_ATTENDANCE) }
|
||||
|
||||
private fun finish() {
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_ATTENDANCE, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_API_ATTENDANCE)
|
||||
}
|
||||
|
||||
private fun getAttendance(profile: Profile, semesterId: Int, semesterNumber: Int, onSuccess: () -> Unit) {
|
||||
val startDate = profile.getSemesterStart(semesterNumber).stringY_m_d
|
||||
val endDate = profile.getSemesterEnd(semesterNumber).stringY_m_d
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_ATTENDANCE, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"IdOddzial" to data.studentClassId,
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOkresKlasyfikacyjny" to semesterId
|
||||
)) { json, _ ->
|
||||
json.getJsonObject("Data")?.getJsonArray("Frekwencje")?.forEach { attendanceEl ->
|
||||
val attendance = attendanceEl.asJsonObject
|
||||
|
||||
val type = data.attendanceTypes.get(attendance.getLong("IdKategoria") ?: return@forEach)
|
||||
?: return@forEach
|
||||
|
||||
val id = (attendance.getInt("Dzien") ?: 0) + (attendance.getInt("Numer") ?: 0)
|
||||
|
||||
val lessonDateMillis = Date.fromY_m_d(attendance.getString("DzienTekst")).inMillis
|
||||
val lessonDate = Date.fromMillis(lessonDateMillis)
|
||||
val startTime = data.lessonRanges.get(attendance.getInt("Numer") ?: 0)?.startTime
|
||||
|
||||
val lessonSemester = semesterNumber
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId = profileId,
|
||||
id = id.toLong(),
|
||||
baseType = type.baseType,
|
||||
typeName = type.typeName,
|
||||
typeShort = type.typeShort,
|
||||
typeSymbol = type.typeSymbol,
|
||||
typeColor = type.typeColor,
|
||||
date = lessonDate,
|
||||
startTime = startTime,
|
||||
semester = lessonSemester,
|
||||
teacherId = -1,
|
||||
subjectId = attendance.getLong("IdPrzedmiot") ?: -1,
|
||||
addedDate = lessonDate.combineWith(startTime)
|
||||
).also {
|
||||
it.lessonNumber = attendance.getInt("Numer")
|
||||
it.isCounted = it.baseType != Attendance.TYPE_RELEASED
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
if (type.baseType != TYPE_PRESENT) {
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
attendanceObject.id,
|
||||
profile.empty || type.baseType == Attendance.TYPE_PRESENT_CUSTOM || type.baseType == Attendance.TYPE_UNKNOWN,
|
||||
profile.empty || type.baseType == Attendance.TYPE_PRESENT_CUSTOM || type.baseType == Attendance.TYPE_UNKNOWN
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-20
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_DICTIONARIES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_DICTIONARIES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class VulcanApiDictionaries(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiDictionaries"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_DICTIONARIES) { json, _ ->
|
||||
val elements = json.getJsonObject("Data")
|
||||
|
||||
elements?.getJsonArray("Pracownicy")?.forEach { saveTeacher(it.asJsonObject) }
|
||||
elements?.getJsonArray("Przedmioty")?.forEach { saveSubject(it.asJsonObject) }
|
||||
elements?.getJsonArray("PoryLekcji")?.forEach { saveLessonRange(it.asJsonObject) }
|
||||
elements?.getJsonArray("KategorieOcen")?.forEach { saveGradeCategory(it.asJsonObject) }
|
||||
elements?.getJsonArray("KategorieUwag")?.forEach { saveNoticeType(it.asJsonObject) }
|
||||
elements?.getJsonArray("KategorieFrekwencji")?.forEach { saveAttendanceType(it.asJsonObject) }
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_DICTIONARIES, 4 * DAY)
|
||||
onSuccess(ENDPOINT_VULCAN_API_DICTIONARIES)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveTeacher(teacher: JsonObject) {
|
||||
val id = teacher.getLong("Id") ?: return
|
||||
val name = teacher.getString("Imie") ?: ""
|
||||
val surname = teacher.getString("Nazwisko") ?: ""
|
||||
val loginId = teacher.getString("LoginId") ?: "-1"
|
||||
|
||||
val teacherObject = Teacher(
|
||||
profileId,
|
||||
id,
|
||||
name,
|
||||
surname,
|
||||
loginId
|
||||
)
|
||||
|
||||
data.teacherList.put(id, teacherObject)
|
||||
}
|
||||
|
||||
private fun saveSubject(subject: JsonObject) {
|
||||
val id = subject.getLong("Id") ?: return
|
||||
val longName = subject.getString("Nazwa") ?: ""
|
||||
val shortName = subject.getString("Kod") ?: ""
|
||||
|
||||
val subjectObject = Subject(
|
||||
profileId,
|
||||
id,
|
||||
longName,
|
||||
shortName
|
||||
)
|
||||
|
||||
data.subjectList.put(id, subjectObject)
|
||||
}
|
||||
|
||||
private fun saveLessonRange(lessonRange: JsonObject) {
|
||||
val lessonNumber = lessonRange.getInt("Numer") ?: return
|
||||
val startTime = lessonRange.getString("PoczatekTekst")?.let { Time.fromH_m(it) } ?: return
|
||||
val endTime = lessonRange.getString("KoniecTekst")?.let { Time.fromH_m(it) } ?: return
|
||||
|
||||
val lessonRangeObject = LessonRange(
|
||||
profileId,
|
||||
lessonNumber,
|
||||
startTime,
|
||||
endTime
|
||||
)
|
||||
|
||||
data.lessonRanges.put(lessonNumber, lessonRangeObject)
|
||||
}
|
||||
|
||||
private fun saveGradeCategory(gradeCategory: JsonObject) {
|
||||
val id = gradeCategory.getLong("Id") ?: return
|
||||
val name = gradeCategory.getString("Nazwa") ?: ""
|
||||
|
||||
val gradeCategoryObject = GradeCategory(
|
||||
profileId,
|
||||
id,
|
||||
0.0f,
|
||||
-1,
|
||||
name
|
||||
)
|
||||
|
||||
data.gradeCategories.put(id, gradeCategoryObject)
|
||||
}
|
||||
|
||||
private fun saveNoticeType(noticeType: JsonObject) {
|
||||
val id = noticeType.getLong("Id") ?: return
|
||||
val name = noticeType.getString("Nazwa") ?: ""
|
||||
|
||||
val noticeTypeObject = NoticeType(
|
||||
profileId,
|
||||
id,
|
||||
name
|
||||
)
|
||||
|
||||
data.noticeTypes.put(id, noticeTypeObject)
|
||||
}
|
||||
|
||||
private fun saveAttendanceType(attendanceType: JsonObject) {
|
||||
val id = attendanceType.getLong("Id") ?: return
|
||||
val typeName = attendanceType.getString("Nazwa") ?: ""
|
||||
|
||||
val absent = attendanceType.getBoolean("Nieobecnosc") ?: false
|
||||
val excused = attendanceType.getBoolean("Usprawiedliwione") ?: false
|
||||
val baseType = if (absent) {
|
||||
if (excused)
|
||||
Attendance.TYPE_ABSENT_EXCUSED
|
||||
else
|
||||
Attendance.TYPE_ABSENT
|
||||
} else {
|
||||
val belated = attendanceType.getBoolean("Spoznienie") ?: false
|
||||
val released = attendanceType.getBoolean("Zwolnienie") ?: false
|
||||
val present = attendanceType.getBoolean("Obecnosc") ?: true
|
||||
if (belated)
|
||||
if (excused)
|
||||
Attendance.TYPE_BELATED_EXCUSED
|
||||
else
|
||||
Attendance.TYPE_BELATED
|
||||
else if (released)
|
||||
Attendance.TYPE_RELEASED
|
||||
else if (present)
|
||||
Attendance.TYPE_PRESENT
|
||||
else
|
||||
Attendance.TYPE_UNKNOWN
|
||||
}
|
||||
|
||||
val (typeColor, typeSymbol) = when (id.toInt()) {
|
||||
1 -> 0xffffffff to "●" // obecność
|
||||
2 -> 0xffffa687 to "—" // nieobecność
|
||||
3 -> 0xfffcc150 to "u" // nieobecność usprawiedliwiona
|
||||
4 -> 0xffede049 to "s" // spóźnienie
|
||||
5 -> 0xffbbdd5f to "su" // spóźnienie usprawiedliwione
|
||||
6 -> 0xffa9c9fd to "ns" // nieobecny z przyczyn szkolnych
|
||||
7 -> 0xffddbbe5 to "z" // zwolniony
|
||||
8 -> 0xffffffff to "" // usunięty wpis
|
||||
else -> null to "?"
|
||||
}
|
||||
|
||||
val typeShort = when (id.toInt()) {
|
||||
6 -> "ns" // nieobecny z przyczyn szkolnych
|
||||
8 -> "" // usunięty wpis
|
||||
else -> data.app.attendanceManager.getTypeShort(baseType)
|
||||
}
|
||||
|
||||
val attendanceTypeObject = AttendanceType(
|
||||
profileId,
|
||||
id,
|
||||
baseType,
|
||||
typeName,
|
||||
typeShort,
|
||||
typeSymbol,
|
||||
typeColor?.toInt()
|
||||
)
|
||||
|
||||
data.attendanceTypes.put(id, attendanceTypeObject)
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-20
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_EVENTS
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_EVENTS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getBoolean
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class VulcanApiEvents(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
private val isHomework: Boolean,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiEvents"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
|
||||
val semesterId = data.studentSemesterId
|
||||
val semesterNumber = data.studentSemesterNumber
|
||||
if (semesterNumber == 2 && lastSync ?: 0 < profile.dateSemester1Start.inMillis) {
|
||||
getEvents(profile, semesterId - 1, semesterNumber - 1) {
|
||||
getEvents(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getEvents(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
} ?: onSuccess(if (isHomework) ENDPOINT_VULCAN_API_HOMEWORK else ENDPOINT_VULCAN_API_EVENTS) }
|
||||
|
||||
private fun finish() {
|
||||
when (isHomework) {
|
||||
true -> {
|
||||
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_HOMEWORK, SYNC_ALWAYS)
|
||||
}
|
||||
false -> {
|
||||
data.toRemove.add(DataRemoveModel.Events.futureExceptType(Event.TYPE_HOMEWORK))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_EVENTS, SYNC_ALWAYS)
|
||||
}
|
||||
}
|
||||
onSuccess(if (isHomework) ENDPOINT_VULCAN_API_HOMEWORK else ENDPOINT_VULCAN_API_EVENTS)
|
||||
}
|
||||
|
||||
private fun getEvents(profile: Profile, semesterId: Int, semesterNumber: Int, onSuccess: () -> Unit) {
|
||||
val startDate = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(semesterNumber).stringY_m_d
|
||||
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||
}
|
||||
val endDate = profile.getSemesterEnd(semesterNumber).stringY_m_d
|
||||
|
||||
val endpoint = when (isHomework) {
|
||||
true -> VULCAN_API_ENDPOINT_HOMEWORK
|
||||
else -> VULCAN_API_ENDPOINT_EVENTS
|
||||
}
|
||||
apiGet(TAG, endpoint, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"IdOddzial" to data.studentClassId,
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOkresKlasyfikacyjny" to semesterId
|
||||
)) { json, _ ->
|
||||
val events = json.getJsonArray("Data")
|
||||
|
||||
events?.forEach { eventEl ->
|
||||
val event = eventEl.asJsonObject
|
||||
|
||||
val id = event?.getLong("Id") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(event.getString("DataTekst") ?: return@forEach)
|
||||
val subjectId = event.getLong("IdPrzedmiot") ?: -1
|
||||
val teacherId = event.getLong("IdPracownik") ?: -1
|
||||
val topic = event.getString("Opis")?.trim() ?: ""
|
||||
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
val type = when (isHomework) {
|
||||
true -> Event.TYPE_HOMEWORK
|
||||
else -> when (event.getBoolean("Rodzaj")) {
|
||||
false -> Event.TYPE_SHORT_QUIZ
|
||||
else -> Event.TYPE_EXAM
|
||||
}
|
||||
}
|
||||
val teamId = event.getLong("IdOddzial") ?: data.teamClass?.id ?: -1
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
date = eventDate,
|
||||
time = startTime,
|
||||
topic = topic,
|
||||
color = null,
|
||||
type = type,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = teamId
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
if (isHomework) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-19
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_GRADES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
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_NORMAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import java.text.DecimalFormat
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class VulcanApiGrades(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiGrades"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
|
||||
val semesterId = data.studentSemesterId
|
||||
val semesterNumber = data.studentSemesterNumber
|
||||
if (semesterNumber == 2 && lastSync ?: 0 < profile.dateSemester1Start.inMillis) {
|
||||
getGrades(profile, semesterId - 1, semesterNumber - 1) {
|
||||
getGrades(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getGrades(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_GRADES) }
|
||||
|
||||
private fun finish() {
|
||||
data.toRemove.add(DataRemoveModel.Grades.semesterWithType(data.studentSemesterNumber, TYPE_NORMAL))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_GRADES, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_API_GRADES)
|
||||
}
|
||||
|
||||
private fun getGrades(profile: Profile, semesterId: Int, semesterNumber: Int, onSuccess: () -> Unit) {
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_GRADES, parameters = mapOf(
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOkresKlasyfikacyjny" to semesterId
|
||||
)) { json, _ ->
|
||||
val grades = json.getJsonArray("Data")
|
||||
|
||||
grades?.forEach { gradeEl ->
|
||||
val grade = gradeEl.asJsonObject
|
||||
|
||||
val id = grade.getLong("Id") ?: return@forEach
|
||||
val categoryId = grade.getLong("IdKategoria") ?: -1
|
||||
val category = data.gradeCategories.singleOrNull{ it.categoryId == categoryId }?.text
|
||||
?: ""
|
||||
val teacherId = grade.getLong("IdPracownikD") ?: -1
|
||||
val subjectId = grade.getLong("IdPrzedmiot") ?: -1
|
||||
val description = grade.getString("Opis")
|
||||
val comment = grade.getString("Komentarz")
|
||||
var value = grade.getFloat("Wartosc")
|
||||
var weight = grade.getFloat("WagaOceny") ?: 0.0f
|
||||
val modificatorValue = grade.getFloat("WagaModyfikatora")
|
||||
val numerator = grade.getFloat("Licznik")
|
||||
val denominator = grade.getFloat("Mianownik")
|
||||
val addedDate = (grade.getLong("DataModyfikacji") ?: return@forEach) * 1000
|
||||
|
||||
var finalDescription = ""
|
||||
|
||||
var name = when (numerator != null && denominator != null) {
|
||||
true -> {
|
||||
value = numerator / denominator
|
||||
finalDescription += DecimalFormat("#.##").format(numerator) +
|
||||
"/" + DecimalFormat("#.##").format(denominator)
|
||||
weight = 0.0f
|
||||
(value * 100).roundToInt().toString() + "%"
|
||||
}
|
||||
else -> {
|
||||
if (value != null) modificatorValue?.also { value += it }
|
||||
else weight = 0.0f
|
||||
|
||||
grade.getString("Wpis") ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
comment?.also {
|
||||
if (name == "") name = it
|
||||
else finalDescription = (if (finalDescription == "") "" else " ") + it
|
||||
}
|
||||
|
||||
description?.also {
|
||||
finalDescription = (if (finalDescription == "") "" else " - ") + it
|
||||
}
|
||||
|
||||
val color = when (name) {
|
||||
"1-", "1", "1+" -> 0xffd65757
|
||||
"2-", "2", "2+" -> 0xff9071b3
|
||||
"3-", "3", "3+" -> 0xffd2ab24
|
||||
"4-", "4", "4+" -> 0xff50b6d6
|
||||
"5-", "5", "5+" -> 0xff2cbd92
|
||||
"6-", "6", "6+" -> 0xff91b43c
|
||||
else -> 0xff3D5F9C
|
||||
}.toInt()
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
name = name,
|
||||
type = TYPE_NORMAL,
|
||||
value = value ?: 0.0f,
|
||||
weight = weight,
|
||||
color = color,
|
||||
category = category,
|
||||
description = finalDescription,
|
||||
comment = null,
|
||||
semester = semesterNumber,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-12
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
||||
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.data.db.full.MessageFull
|
||||
|
||||
class VulcanApiMessagesChangeStatus(override val data: DataVulcan,
|
||||
private val messageObject: MessageFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : VulcanApi(data, null) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiMessagesChangeStatus"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS, parameters = mapOf(
|
||||
"WiadomoscId" to messageObject.id,
|
||||
"FolderWiadomosci" to "Odebrane",
|
||||
"Status" to "Widoczna",
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { _, _ ->
|
||||
|
||||
if (!messageObject.seen) {
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
true,
|
||||
true
|
||||
))
|
||||
|
||||
messageObject.seen = true
|
||||
}
|
||||
|
||||
if (messageObject.type != TYPE_SENT) {
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
System.currentTimeMillis(),
|
||||
messageObject.id
|
||||
)
|
||||
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-01
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_MESSAGES_INBOX
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import kotlin.text.replace
|
||||
|
||||
class VulcanApiMessagesInbox(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiMessagesInbox"
|
||||
}
|
||||
|
||||
init {
|
||||
data.profile?.also { profile ->
|
||||
|
||||
val startDate = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(profile.currentSemester).inUnix
|
||||
else -> Date.getToday().stepForward(0, -2, 0).inUnix
|
||||
}
|
||||
val endDate = Date.getToday().stepForward(0, 1, 0).inUnix
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_RECEIVED, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { message ->
|
||||
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||
val subject = message.getString("Tytul") ?: ""
|
||||
val body = message.getString("Tresc") ?: ""
|
||||
|
||||
val senderLoginId = message.getString("NadawcaId") ?: return@forEach
|
||||
val senderId = data.teacherList.singleOrNull { it.loginId == senderLoginId }?.id ?: {
|
||||
|
||||
val senderName = message.getString("Nadawca") ?: ""
|
||||
|
||||
senderName.splitName()?.let { (senderLastName, senderFirstName) ->
|
||||
val teacherObject = Teacher(
|
||||
profileId,
|
||||
-1 * Utils.crc16(senderName.toByteArray()).toLong(),
|
||||
senderFirstName,
|
||||
senderLastName,
|
||||
senderLoginId
|
||||
)
|
||||
data.teacherList.put(teacherObject.id, teacherObject)
|
||||
teacherObject.id
|
||||
}
|
||||
}.invoke()
|
||||
|
||||
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 }
|
||||
?: -1
|
||||
val readDate = message.getLong("DataPrzeczytaniaUnixEpoch")?.let { it * 1000 }
|
||||
?: -1
|
||||
|
||||
val messageObject = Message(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = TYPE_RECEIVED,
|
||||
subject = subject,
|
||||
body = body.replace("\n", "<br>"),
|
||||
senderId = senderId,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
readDate,
|
||||
id
|
||||
)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
readDate > 0,
|
||||
readDate > 0
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_API_MESSAGES_INBOX)
|
||||
}
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_MESSAGES_INBOX)
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-5
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
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.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import kotlin.text.replace
|
||||
|
||||
class VulcanApiMessagesSent(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiMessagesSent"
|
||||
}
|
||||
|
||||
init {
|
||||
data.profile?.also { profile ->
|
||||
|
||||
val startDate = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(profile.currentSemester).inUnix
|
||||
else -> Date.getToday().stepForward(0, -2, 0).inUnix
|
||||
}
|
||||
val endDate = Date.getToday().stepForward(0, 1, 0).inUnix
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_SENT, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { message ->
|
||||
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||
val subject = message.getString("Tytul") ?: ""
|
||||
val body = message.getString("Tresc") ?: ""
|
||||
val readBy = message.getInt("Przeczytane") ?: 0
|
||||
val unreadBy = message.getInt("Nieprzeczytane") ?: 0
|
||||
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
||||
|
||||
message.getJsonArray("Adresaci")?.asJsonObjectList()
|
||||
?.onEach { receiver ->
|
||||
|
||||
val receiverLoginId = receiver.getString("LoginId")
|
||||
?: return@onEach
|
||||
val receiverId = data.teacherList.singleOrNull { it.loginId == receiverLoginId }?.id
|
||||
?: {
|
||||
val receiverName = receiver.getString("Nazwa") ?: ""
|
||||
|
||||
receiverName.splitName()?.let { (receiverLastName, receiverFirstName) ->
|
||||
val teacherObject = Teacher(
|
||||
profileId,
|
||||
-1 * Utils.crc16(receiverName.toByteArray()).toLong(),
|
||||
receiverFirstName,
|
||||
receiverLastName,
|
||||
receiverLoginId
|
||||
)
|
||||
data.teacherList.put(teacherObject.id, teacherObject)
|
||||
teacherObject.id
|
||||
}
|
||||
}.invoke() ?: -1
|
||||
|
||||
val readDate: Long = when (readBy) {
|
||||
0 -> 0
|
||||
else -> when (unreadBy) {
|
||||
0 -> 1
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
receiverId,
|
||||
-1,
|
||||
readDate,
|
||||
id
|
||||
)
|
||||
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
val messageObject = Message(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = TYPE_SENT,
|
||||
subject = subject,
|
||||
body = body.replace("\n", "<br>"),
|
||||
senderId = null,
|
||||
addedDate = sentDate
|
||||
)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
true,
|
||||
true
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_SENT, 1 * DAY, DRAWER_ITEM_MESSAGES)
|
||||
onSuccess(ENDPOINT_VULCAN_API_MESSAGES_SENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-23
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import androidx.core.util.isEmpty
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_NOTICES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_NOTICES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.toSparseArray
|
||||
|
||||
class VulcanApiNotices(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiNotices"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
if (data.noticeTypes.isEmpty()) {
|
||||
data.db.noticeTypeDao().getAllNow(profileId).toSparseArray(data.noticeTypes) { it.id }
|
||||
}
|
||||
|
||||
val semesterId = data.studentSemesterId
|
||||
val semesterNumber = data.studentSemesterNumber
|
||||
if (semesterNumber == 2 && lastSync ?: 0 < profile.dateSemester1Start.inMillis) {
|
||||
getNotices(profile, semesterId - 1, semesterNumber - 1) {
|
||||
getNotices(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getNotices(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_NOTICES) }
|
||||
|
||||
private fun finish() {
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_NOTICES, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_API_NOTICES)
|
||||
}
|
||||
|
||||
private fun getNotices(profile: Profile, semesterId: Int, semesterNumber: Int, onSuccess: () -> Unit) {
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_NOTICES, parameters = mapOf(
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOkresKlasyfikacyjny" to data.studentSemesterId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data")?.forEach { noticeEl ->
|
||||
val notice = noticeEl.asJsonObject
|
||||
|
||||
val id = notice.getLong("Id") ?: return@forEach
|
||||
val text = notice.getString("TrescUwagi") ?: return@forEach
|
||||
val teacherId = notice.getLong("IdPracownik") ?: -1
|
||||
val addedDate = notice.getLong("DataModyfikacji")?.times(1000) ?: System.currentTimeMillis()
|
||||
|
||||
val categoryId = notice.getLong("IdKategoriaUwag") ?: -1
|
||||
val categoryText = data.noticeTypes[categoryId]?.name ?: ""
|
||||
|
||||
val noticeObject = Notice(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = Notice.TYPE_NEUTRAL,
|
||||
semester = profile.currentSemester,
|
||||
text = text,
|
||||
category = categoryText,
|
||||
points = null,
|
||||
teacherId = teacherId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.noticeList.add(noticeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_NOTICE,
|
||||
id,
|
||||
profile.empty,
|
||||
profile.empty
|
||||
))
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import pl.szczodrzynski.edziennik.HOUR
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_GRADES_PROPOSITIONS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_GRADES_SUMMARY
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_FINAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER2_FINAL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER2_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
class VulcanApiProposedGrades(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiProposedGrades"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
|
||||
val semesterId = data.studentSemesterId
|
||||
val semesterNumber = data.studentSemesterNumber
|
||||
if (semesterNumber == 2 && lastSync ?: 0 < profile.dateSemester1Start.inMillis) {
|
||||
getProposedGrades(profile, semesterId - 1, semesterNumber - 1) {
|
||||
getProposedGrades(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
getProposedGrades(profile, semesterId, semesterNumber) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_GRADES_SUMMARY) }
|
||||
|
||||
private fun finish() {
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_GRADES_SUMMARY, 6*HOUR)
|
||||
onSuccess(ENDPOINT_VULCAN_API_GRADES_SUMMARY)
|
||||
}
|
||||
|
||||
private fun getProposedGrades(profile: Profile, semesterId: Int, semesterNumber: Int, onSuccess: () -> Unit) {
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_GRADES_PROPOSITIONS, parameters = mapOf(
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOkresKlasyfikacyjny" to semesterId
|
||||
)) { json, _ ->
|
||||
val grades = json.getJsonObject("Data")
|
||||
|
||||
grades.getJsonArray("OcenyPrzewidywane")?.let {
|
||||
processGradeList(it, semesterNumber, isFinal = false)
|
||||
}
|
||||
|
||||
grades.getJsonArray("OcenyKlasyfikacyjne")?.let {
|
||||
processGradeList(it, semesterNumber, isFinal = true)
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
private fun processGradeList(grades: JsonArray, semesterNumber: Int, isFinal: Boolean) {
|
||||
grades.asJsonObjectList().forEach { grade ->
|
||||
val name = grade.get("Wpis").asString
|
||||
val value = Utils.getGradeValue(name)
|
||||
val subjectId = grade.get("IdPrzedmiot").asLong
|
||||
|
||||
val id = subjectId * -100 - semesterNumber
|
||||
|
||||
val color = Utils.getVulcanGradeColor(name)
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
name = name,
|
||||
type = if (semesterNumber == 1) {
|
||||
if (isFinal) TYPE_SEMESTER1_FINAL else TYPE_SEMESTER1_PROPOSED
|
||||
} else {
|
||||
if (isFinal) TYPE_SEMESTER2_FINAL else TYPE_SEMESTER2_PROPOSED
|
||||
},
|
||||
value = value,
|
||||
weight = 0f,
|
||||
color = color,
|
||||
category = "",
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = semesterNumber,
|
||||
teacherId = -1,
|
||||
subjectId = subjectId
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_PUSH
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_PUSH_CONFIG
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
|
||||
class VulcanApiPushConfig(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiPushConfig"
|
||||
}
|
||||
|
||||
init { data.app.config.sync.tokenVulcan?.also { tokenVulcan ->
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_PUSH, parameters = mapOf(
|
||||
"Token" to tokenVulcan,
|
||||
"IdUczen" to data.studentId,
|
||||
"PushOcena" to true,
|
||||
"PushFrekwencja" to true,
|
||||
"PushUwaga" to true,
|
||||
"PushWiadomosc" to true
|
||||
)) { _, _ ->
|
||||
// sync always: this endpoint has .shouldSync set
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_PUSH_CONFIG, SYNC_ALWAYS)
|
||||
data.app.config.sync.tokenVulcanList =
|
||||
data.app.config.sync.tokenVulcanList + profileId
|
||||
onSuccess(ENDPOINT_VULCAN_API_PUSH_CONFIG)
|
||||
}
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_PUSH_CONFIG) }
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-12-29.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_ADD
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
|
||||
class VulcanApiSendMessage(override val data: DataVulcan,
|
||||
val recipients: List<Teacher>,
|
||||
val subject: String,
|
||||
val text: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : VulcanApi(data, null) {
|
||||
companion object {
|
||||
private const val TAG = "VulcanApiSendMessage"
|
||||
}
|
||||
|
||||
init {
|
||||
val recipientsArray = JsonArray()
|
||||
for (teacher in recipients) {
|
||||
teacher.loginId?.let {
|
||||
recipientsArray += JsonObject(
|
||||
"LoginId" to it,
|
||||
"Nazwa" to "${teacher.fullNameLastFirst} - pracownik"
|
||||
)
|
||||
}
|
||||
}
|
||||
val params = mapOf(
|
||||
"NadawcaWiadomosci" to (profile?.accountName ?: profile?.studentNameLong ?: ""),
|
||||
"Tytul" to subject,
|
||||
"Tresc" to text,
|
||||
"Adresaci" to recipientsArray,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_ADD, parameters = params) { json, _ ->
|
||||
val messageId = json.getJsonObject("Data").getLong("WiadomoscId")
|
||||
|
||||
if (messageId == null) {
|
||||
// TODO error
|
||||
return@apiGet
|
||||
}
|
||||
|
||||
VulcanApiMessagesSent(data, null) {
|
||||
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 == messageId }
|
||||
val event = MessageSentEvent(data.profileId, message, message?.addedDate)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-10-20
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
|
||||
class VulcanApiTemplate(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApi"
|
||||
}
|
||||
|
||||
init {
|
||||
/* data.profile?.also { profile ->
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_) { json, _ ->
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-13
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import androidx.core.util.set
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.Regexes.VULCAN_SHIFT_ANNOTATION
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_TIMETABLE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_TIMETABLE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.crc16
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class VulcanApiTimetable(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiTimetable"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
val currentWeekStart = Week.getWeekStart()
|
||||
|
||||
if (Date.getToday().weekDay > 4) {
|
||||
currentWeekStart.stepForward(0, 0, 7)
|
||||
}
|
||||
|
||||
val getDate = data.arguments?.getString("weekStart") ?: currentWeekStart.stringY_m_d
|
||||
|
||||
val weekStart = Date.fromY_m_d(getDate)
|
||||
val weekEnd = weekStart.clone().stepForward(0, 0, 6)
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_TIMETABLE, parameters = mapOf(
|
||||
"DataPoczatkowa" to weekStart.stringY_m_d,
|
||||
"DataKoncowa" to weekEnd.stringY_m_d,
|
||||
"IdUczen" to data.studentId,
|
||||
"IdOddzial" to data.studentClassId,
|
||||
"IdOkresKlasyfikacyjny" to data.studentSemesterId
|
||||
)) { json, _ ->
|
||||
val dates = mutableSetOf<Int>()
|
||||
val lessons = mutableListOf<Lesson>()
|
||||
|
||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { lesson ->
|
||||
if (lesson.getBoolean("PlanUcznia") != true)
|
||||
return@forEach
|
||||
val lessonDate = Date.fromY_m_d(lesson.getString("DzienTekst"))
|
||||
val lessonNumber = lesson.getInt("NumerLekcji")
|
||||
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNumber }
|
||||
val startTime = lessonRange?.startTime
|
||||
val endTime = lessonRange?.endTime
|
||||
val teacherId = lesson.getLong("IdPracownik")
|
||||
val classroom = lesson.getString("Sala")
|
||||
|
||||
val oldTeacherId = lesson.getLong("IdPracownikOld")
|
||||
|
||||
val changeAnnotation = lesson.getString("AdnotacjaOZmianie") ?: ""
|
||||
val type = when {
|
||||
changeAnnotation.startsWith("(przeniesiona z") -> Lesson.TYPE_SHIFTED_TARGET
|
||||
changeAnnotation.startsWith("(przeniesiona na") -> Lesson.TYPE_SHIFTED_SOURCE
|
||||
changeAnnotation.startsWith("(zastępstwo") -> Lesson.TYPE_CHANGE
|
||||
lesson.getBoolean("PrzekreslonaNazwa") == true -> Lesson.TYPE_CANCELLED
|
||||
else -> Lesson.TYPE_NORMAL
|
||||
}
|
||||
|
||||
val teamId = lesson.getString("PodzialSkrot")?.let { teamName ->
|
||||
val name = "${data.teamClass?.name} $teamName"
|
||||
val id = name.crc16().toLong()
|
||||
var team = data.teamList.singleOrNull { it.name == name }
|
||||
if (team == null) {
|
||||
team = Team(
|
||||
profileId,
|
||||
id,
|
||||
name,
|
||||
Team.TYPE_VIRTUAL,
|
||||
"${data.schoolCode}:$name",
|
||||
teacherId ?: oldTeacherId ?: -1
|
||||
)
|
||||
data.teamList[id] = team
|
||||
}
|
||||
team.id
|
||||
} ?: data.teamClass?.id ?: -1
|
||||
|
||||
val subjectId = lesson.getLong("IdPrzedmiot").let { id ->
|
||||
// get the specified subject name
|
||||
val subjectName = lesson.getString("PrzedmiotNazwa") ?: ""
|
||||
|
||||
val condition = when (id) {
|
||||
// "special" subject - e.g. one time classes, a trip, etc.
|
||||
0L -> { subject: Subject -> subject.longName == subjectName }
|
||||
// normal subject, check if it exists
|
||||
else -> { subject: Subject -> subject.id == id }
|
||||
}
|
||||
|
||||
data.subjectList.singleOrNull(condition)?.id ?: {
|
||||
/**
|
||||
* CREATE A NEW SUBJECT IF IT DOESN'T EXIST
|
||||
*/
|
||||
|
||||
val subjectObject = Subject(
|
||||
profileId,
|
||||
if (id == null || id == 0L)
|
||||
-1 * crc16(subjectName.toByteArray()).toLong()
|
||||
else
|
||||
id,
|
||||
subjectName,
|
||||
subjectName
|
||||
)
|
||||
data.subjectList.put(subjectObject.id, subjectObject)
|
||||
subjectObject.id
|
||||
}()
|
||||
}
|
||||
|
||||
val lessonObject = Lesson(profileId, -1).apply {
|
||||
this.type = type
|
||||
|
||||
when (type) {
|
||||
Lesson.TYPE_NORMAL, Lesson.TYPE_CHANGE, Lesson.TYPE_SHIFTED_TARGET -> {
|
||||
this.date = lessonDate
|
||||
this.lessonNumber = lessonNumber
|
||||
this.startTime = startTime
|
||||
this.endTime = endTime
|
||||
this.subjectId = subjectId
|
||||
this.teacherId = teacherId
|
||||
this.teamId = teamId
|
||||
this.classroom = classroom
|
||||
|
||||
this.oldTeacherId = oldTeacherId
|
||||
}
|
||||
|
||||
Lesson.TYPE_CANCELLED, Lesson.TYPE_SHIFTED_SOURCE -> {
|
||||
this.oldDate = lessonDate
|
||||
this.oldLessonNumber = lessonNumber
|
||||
this.oldStartTime = startTime
|
||||
this.oldEndTime = endTime
|
||||
this.oldSubjectId = subjectId
|
||||
this.oldTeacherId = teacherId
|
||||
this.oldTeamId = teamId
|
||||
this.oldClassroom = classroom
|
||||
}
|
||||
}
|
||||
|
||||
if (type == Lesson.TYPE_SHIFTED_SOURCE || type == Lesson.TYPE_SHIFTED_TARGET) {
|
||||
val shift = VULCAN_SHIFT_ANNOTATION.find(changeAnnotation)
|
||||
val oldLessonNumber = shift?.get(2)?.toInt()
|
||||
val oldLessonDate = shift?.get(3)?.let { Date.fromd_m_Y(it) }
|
||||
|
||||
val oldLessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == oldLessonNumber }
|
||||
val oldStartTime = oldLessonRange?.startTime
|
||||
val oldEndTime = oldLessonRange?.endTime
|
||||
|
||||
when (type) {
|
||||
Lesson.TYPE_SHIFTED_SOURCE -> {
|
||||
this.lessonNumber = oldLessonNumber
|
||||
this.date = oldLessonDate
|
||||
this.startTime = oldStartTime
|
||||
this.endTime = oldEndTime
|
||||
}
|
||||
|
||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||
this.oldLessonNumber = oldLessonNumber
|
||||
this.oldDate = oldLessonDate
|
||||
this.oldStartTime = oldStartTime
|
||||
this.oldEndTime = oldEndTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.id = buildId()
|
||||
}
|
||||
|
||||
val seen = profile.empty || lessonDate < Date.getToday()
|
||||
|
||||
if (type != Lesson.TYPE_NORMAL) {
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonObject.id,
|
||||
seen,
|
||||
seen
|
||||
))
|
||||
}
|
||||
|
||||
dates.add(lessonDate.value)
|
||||
lessons.add(lessonObject)
|
||||
}
|
||||
|
||||
val date: Date = weekStart.clone()
|
||||
while (date <= weekEnd) {
|
||||
if (!dates.contains(date.value)) {
|
||||
lessons.add(Lesson(profileId, date.value.toLong()).apply {
|
||||
this.type = Lesson.TYPE_NO_LESSONS
|
||||
this.date = date.clone()
|
||||
})
|
||||
}
|
||||
|
||||
date.stepForward(0, 0, 1)
|
||||
}
|
||||
|
||||
d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate")
|
||||
|
||||
data.lessonList.addAll(lessons)
|
||||
data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd))
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_TIMETABLE, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_API_TIMETABLE)
|
||||
}
|
||||
}}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-2-1.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_NO_STUDENTS_IN_ACCOUNT
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_STUDENT_LIST
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_UPDATE_SEMESTER
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class VulcanApiUpdateSemester(override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanApi(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiUpdateSemester"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_STUDENT_LIST, baseUrl = true) { json, response ->
|
||||
val students = json.getJsonArray("Data")
|
||||
|
||||
if (students == null || students.isEmpty()) {
|
||||
data.error(ApiError(TAG, ERROR_NO_STUDENTS_IN_ACCOUNT)
|
||||
.withResponse(response)
|
||||
.withApiResponse(json))
|
||||
return@apiGet
|
||||
}
|
||||
|
||||
students.asJsonObjectList().firstOrNull {
|
||||
it.getInt("Id") == data.studentId
|
||||
}?.let { student ->
|
||||
val studentClassId = student.getInt("IdOddzial") ?: return@let
|
||||
val studentClassName = student.getString("OkresPoziom").toString() + (student.getString("OddzialSymbol") ?: return@let)
|
||||
val studentSemesterId = student.getInt("IdOkresKlasyfikacyjny") ?: return@let
|
||||
|
||||
val currentSemesterStartDate = student.getLong("OkresDataOd") ?: return@let
|
||||
val currentSemesterEndDate = (student.getLong("OkresDataDo") ?: return@let) + 86400
|
||||
val studentSemesterNumber = student.getInt("OkresNumer") ?: return@let
|
||||
|
||||
var dateSemester1Start: Date? = null
|
||||
var dateSemester2Start: Date? = null
|
||||
var dateYearEnd: Date? = null
|
||||
when (studentSemesterNumber) {
|
||||
1 -> {
|
||||
dateSemester1Start = Date.fromMillis(currentSemesterStartDate * 1000)
|
||||
dateSemester2Start = Date.fromMillis(currentSemesterEndDate * 1000)
|
||||
}
|
||||
2 -> {
|
||||
dateSemester2Start = Date.fromMillis(currentSemesterStartDate * 1000)
|
||||
dateYearEnd = Date.fromMillis(currentSemesterEndDate * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
data.studentClassId = studentClassId
|
||||
data.studentSemesterId = studentSemesterId
|
||||
data.studentSemesterNumber = studentSemesterNumber
|
||||
data.profile.studentData["semester${studentSemesterNumber}Id"] = studentSemesterId
|
||||
data.currentSemesterEndDate = currentSemesterEndDate
|
||||
profile.studentClassName = studentClassName
|
||||
dateSemester1Start?.let {
|
||||
profile.dateSemester1Start = it
|
||||
profile.studentSchoolYearStart = it.year
|
||||
}
|
||||
dateSemester2Start?.let { profile.dateSemester2Start = it }
|
||||
dateYearEnd?.let { profile.dateYearEnd = it }
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_UPDATE_SEMESTER, if (data.studentSemesterNumber == 2) 7*DAY else 2*DAY)
|
||||
onSuccess(ENDPOINT_VULCAN_API_UPDATE_SEMESTER)
|
||||
}
|
||||
} ?: onSuccess(ENDPOINT_VULCAN_API_UPDATE_SEMESTER) }
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
enum class HebeFilterType(val endpoint: String) {
|
||||
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import androidx.core.util.set
|
||||
|
@ -85,6 +85,7 @@ class VulcanHebeAttendance(
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
).also {
|
||||
it.lessonTopic = attendance.getString("Topic")
|
||||
it.lessonNumber = lessonNumber
|
||||
it.isCounted = isCounted
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
@ -36,6 +40,8 @@ class VulcanHebeExams(
|
||||
?: -1
|
||||
val topic = exam.getString("Content")?.trim() ?: ""
|
||||
|
||||
if (!isCurrentYear(eventDate)) return@forEach
|
||||
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-22.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.DAY
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_GRADE_SUMMARY
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
class VulcanHebeGradeSummary(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeGradeSummary"
|
||||
}
|
||||
|
||||
init {
|
||||
val entries = mapOf(
|
||||
"Entry_1" to
|
||||
if (data.studentSemesterNumber == 1)
|
||||
Grade.TYPE_SEMESTER1_PROPOSED
|
||||
else Grade.TYPE_SEMESTER2_PROPOSED,
|
||||
"Entry_2" to
|
||||
if (data.studentSemesterNumber == 1)
|
||||
Grade.TYPE_SEMESTER1_FINAL
|
||||
else Grade.TYPE_SEMESTER2_FINAL
|
||||
)
|
||||
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_GRADE_SUMMARY,
|
||||
HebeFilterType.BY_PUPIL,
|
||||
lastSync = lastSync
|
||||
) { list, _ ->
|
||||
list.forEach { grade ->
|
||||
val subjectId = getSubjectId(grade, "Subject") ?: return@forEach
|
||||
val addedDate = getDateTime(grade, "DateModify")
|
||||
|
||||
entries.onEach { (key, type) ->
|
||||
val id = subjectId * -100 - type
|
||||
val entry = grade.getString(key) ?: return@onEach
|
||||
val value = Utils.getGradeValue(entry)
|
||||
val color = Utils.getVulcanGradeColor(entry)
|
||||
|
||||
val gradeObject = Grade(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
name = entry,
|
||||
type = type,
|
||||
value = value,
|
||||
weight = 0f,
|
||||
color = color,
|
||||
category = "",
|
||||
description = null,
|
||||
comment = null,
|
||||
semester = data.studentSemesterNumber,
|
||||
teacherId = -1,
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
id,
|
||||
profile?.empty ?: true,
|
||||
profile?.empty ?: true
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY, 1 * DAY)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
|
@ -1,5 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_HOMEWORK
|
||||
@ -7,8 +12,10 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
class VulcanHebeHomework(
|
||||
override val data: DataVulcan,
|
||||
@ -34,6 +41,8 @@ class VulcanHebeHomework(
|
||||
val teamId = data.teamClass?.id ?: -1
|
||||
val topic = exam.getString("Content")?.trim() ?: ""
|
||||
|
||||
if (!isCurrentYear(eventDate)) return@forEach
|
||||
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
@ -50,6 +59,22 @@ class VulcanHebeHomework(
|
||||
teamId = teamId
|
||||
)
|
||||
|
||||
val attachments = exam.getJsonArray("Attachments")
|
||||
?.asJsonObjectList()
|
||||
?: return@forEach
|
||||
|
||||
for (attachment in attachments) {
|
||||
val fileName = attachment.getString("Name") ?: continue
|
||||
val url = attachment.getString("Link") ?: continue
|
||||
val attachmentName = "$fileName:$url"
|
||||
val attachmentId = Utils.crc32(attachmentName.toByteArray())
|
||||
|
||||
eventObject.addAttachment(
|
||||
id = attachmentId,
|
||||
name = attachmentName
|
||||
)
|
||||
}
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-22.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber
|
||||
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.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class VulcanHebeLuckyNumber(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeLuckyNumber"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER,
|
||||
query = mapOf(
|
||||
"constituentId" to data.studentConstituentId.toString(),
|
||||
"day" to Date.getToday().stringY_m_d
|
||||
)
|
||||
) { lucky: JsonObject?, _ ->
|
||||
// sync tomorrow if lucky number set or is weekend or afternoon
|
||||
var nextSync = Date.getToday().stepForward(0, 0, 1).inMillis
|
||||
if (lucky == null) {
|
||||
if (Date.getToday().weekDay <= Week.FRIDAY && Time.getNow().hour < 12) {
|
||||
// working days morning, sync always
|
||||
nextSync = SYNC_ALWAYS
|
||||
}
|
||||
}
|
||||
else {
|
||||
val luckyNumberDate = Date.fromY_m_d(lucky.getString("Day")) ?: Date.getToday()
|
||||
val luckyNumber = lucky.getInt("Number") ?: -1
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
profileId = profileId,
|
||||
date = luckyNumberDate,
|
||||
number = luckyNumber
|
||||
)
|
||||
|
||||
data.luckyNumberList.add(luckyNumberObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
profile?.empty ?: false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER, syncAt = nextSync)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import androidx.core.util.set
|
||||
@ -13,6 +17,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.*
|
||||
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.data.db.entity.Message.Companion.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.navlib.crc16
|
||||
import kotlin.text.replace
|
||||
|
||||
@ -76,6 +81,8 @@ class VulcanHebeMessages(
|
||||
val sentDate = getDateTime(message, "DateSent")
|
||||
val readDate = getDateTime(message, "DateRead", default = 0)
|
||||
|
||||
if (!isCurrentYear(sentDate)) return@forEach
|
||||
|
||||
val messageObject = Message(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
@ -104,6 +111,23 @@ class VulcanHebeMessages(
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
val attachments = message.getJsonArray("Attachments")
|
||||
?.asJsonObjectList()
|
||||
?: return@forEach
|
||||
|
||||
for (attachment in attachments) {
|
||||
val fileName = attachment.getString("Name") ?: continue
|
||||
val url = attachment.getString("Link") ?: continue
|
||||
val attachmentName = "$fileName:$url"
|
||||
val attachmentId = Utils.crc32(attachmentName.toByteArray())
|
||||
|
||||
messageObject.addAttachment(
|
||||
id = attachmentId,
|
||||
name = attachmentName,
|
||||
size = -1
|
||||
)
|
||||
}
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.setSeenMetadataList.add(
|
||||
Metadata(
|
||||
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2021-2-22
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_NOTICES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_NOTICES
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
|
||||
class VulcanHebeNotices(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeNotices"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_NOTICES,
|
||||
HebeFilterType.BY_PUPIL,
|
||||
lastSync = lastSync
|
||||
) { list, _ ->
|
||||
list.forEach { notice ->
|
||||
val id = notice.getLong("Id") ?: return@forEach
|
||||
val type = when (notice.getBoolean("Positive")) {
|
||||
true -> Notice.TYPE_POSITIVE
|
||||
else -> Notice.TYPE_NEUTRAL
|
||||
}
|
||||
val date = getDate(notice, "DateValid") ?: return@forEach
|
||||
val semester = profile?.dateToSemester(date) ?: return@forEach
|
||||
val text = notice.getString("Content") ?: ""
|
||||
val category = notice.getJsonObject("Category")?.getString("Name")
|
||||
val points = notice.getFloat("Points")
|
||||
val teacherId = getTeacherId(notice, "Creator") ?: -1
|
||||
val addedDate = getDateTime(notice, "DateModify")
|
||||
|
||||
if (!isCurrentYear(date)) return@forEach
|
||||
|
||||
val noticeObject = Notice(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
type = type,
|
||||
semester = semester,
|
||||
text = text,
|
||||
category = category,
|
||||
points = points,
|
||||
teacherId = teacherId,
|
||||
addedDate = addedDate
|
||||
)
|
||||
|
||||
data.noticeList.add(noticeObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_NOTICE,
|
||||
id,
|
||||
profile?.empty ?: true,
|
||||
profile?.empty ?: true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_NOTICES, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_NOTICES)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-22.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonPrimitive
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_PUSH_ALL
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_PUSH_CONFIG
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
|
||||
class VulcanHebePushConfig(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebePushConfig"
|
||||
}
|
||||
|
||||
init {
|
||||
apiPost(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_PUSH_ALL,
|
||||
payload = JsonPrimitive("on")
|
||||
) { _: Boolean, _ ->
|
||||
// sync always: this endpoint has .shouldSync set
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_PUSH_CONFIG, SYNC_ALWAYS)
|
||||
data.app.config.sync.tokenVulcanList =
|
||||
data.app.config.sync.tokenVulcanList + profileId
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_PUSH_CONFIG)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-22.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_MESSAGES_SEND
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
|
||||
class VulcanHebeSendMessage(
|
||||
override val data: DataVulcan,
|
||||
val recipients: List<Teacher>,
|
||||
val subject: String,
|
||||
val text: String,
|
||||
val onSuccess: () -> Unit
|
||||
) : VulcanHebe(data, null) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeSendMessage"
|
||||
}
|
||||
|
||||
init {
|
||||
val recipientsArray = JsonArray()
|
||||
recipients.forEach { teacher ->
|
||||
recipientsArray += JsonObject(
|
||||
"Address" to teacher.fullNameLastFirst,
|
||||
"LoginId" to (teacher.loginId?.toIntOrNull() ?: return@forEach),
|
||||
"Initials" to teacher.initialsLastFirst,
|
||||
"AddressHash" to teacher.fullNameLastFirst.sha1Hex()
|
||||
)
|
||||
}
|
||||
|
||||
val senderName = (profile?.accountName ?: profile?.studentNameLong)
|
||||
?.swapFirstLastName() ?: ""
|
||||
val sender = JsonObject(
|
||||
"Address" to senderName,
|
||||
"LoginId" to data.studentLoginId.toString(),
|
||||
"Initials" to senderName.getNameInitials(),
|
||||
"AddressHash" to senderName.sha1Hex()
|
||||
)
|
||||
|
||||
apiPost(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_MESSAGES_SEND,
|
||||
payload = JsonObject(
|
||||
"Status" to 1,
|
||||
"Sender" to sender,
|
||||
"DateSent" to null,
|
||||
"DateRead" to null,
|
||||
"Content" to text,
|
||||
"Receiver" to recipientsArray,
|
||||
"Id" to 0,
|
||||
"Subject" to subject,
|
||||
"Attachments" to null,
|
||||
"Self" to null
|
||||
)
|
||||
) { json: JsonObject, _ ->
|
||||
val messageId = json.getLong("Id")
|
||||
|
||||
if (messageId == null) {
|
||||
// TODO error
|
||||
return@apiPost
|
||||
}
|
||||
|
||||
VulcanHebeMessages(data, null) {
|
||||
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 == messageId }
|
||||
val event = MessageSentEvent(data.profileId, message, message?.addedDate)
|
||||
|
||||
EventBus.getDefault().postSticky(event)
|
||||
onSuccess()
|
||||
}.getMessages(Message.TYPE_SENT)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-21.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
|
@ -8,25 +8,21 @@ import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanWebMain
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeMain
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.CufsCertificate
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginHebe
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginWebMain
|
||||
import pl.szczodrzynski.edziennik.data.api.events.FirstLoginFinishedEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class VulcanFirstLogin(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
const val TAG = "VulcanFirstLogin"
|
||||
}
|
||||
|
||||
private val api = VulcanApi(data, null)
|
||||
private val web = VulcanWebMain(data, null)
|
||||
private val hebe = VulcanHebe(data, null)
|
||||
private val profileList = mutableListOf<Profile>()
|
||||
@ -54,12 +50,6 @@ class VulcanFirstLogin(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
checkSymbol(certificate)
|
||||
}
|
||||
}
|
||||
else if (data.loginStore.mode == LOGIN_MODE_VULCAN_API) {
|
||||
registerDevice {
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
else {
|
||||
registerDeviceHebe {
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
||||
@ -118,96 +108,6 @@ class VulcanFirstLogin(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerDevice(onSuccess: () -> Unit) {
|
||||
VulcanLoginApi(data) {
|
||||
api.apiGet(TAG, VULCAN_API_ENDPOINT_STUDENT_LIST, baseUrl = true) { json, _ ->
|
||||
val students = json.getJsonArray("Data")
|
||||
|
||||
if (students == null || students.isEmpty()) {
|
||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(listOf(), data.loginStore))
|
||||
onSuccess()
|
||||
return@apiGet
|
||||
}
|
||||
|
||||
students.forEach { studentEl ->
|
||||
val student = studentEl.asJsonObject
|
||||
|
||||
val schoolSymbol = student.getString("JednostkaSprawozdawczaSymbol") ?: return@forEach
|
||||
val schoolShort = student.getString("JednostkaSprawozdawczaSkrot") ?: return@forEach
|
||||
val schoolCode = "${data.symbol}_$schoolSymbol"
|
||||
val studentId = student.getInt("Id") ?: return@forEach
|
||||
val studentLoginId = student.getInt("UzytkownikLoginId") ?: return@forEach
|
||||
val studentClassId = student.getInt("IdOddzial") ?: return@forEach
|
||||
val studentClassName = student.getString("OkresPoziom").toString() + (student.getString("OddzialSymbol") ?: return@forEach)
|
||||
val studentSemesterId = student.getInt("IdOkresKlasyfikacyjny") ?: return@forEach
|
||||
val studentFirstName = student.getString("Imie") ?: ""
|
||||
val studentLastName = student.getString("Nazwisko") ?: ""
|
||||
val studentNameLong = "$studentFirstName $studentLastName".fixName()
|
||||
val studentNameShort = "$studentFirstName ${studentLastName[0]}.".fixName()
|
||||
|
||||
val userLogin = student.getString("UzytkownikLogin") ?: ""
|
||||
val currentSemesterStartDate = student.getLong("OkresDataOd") ?: return@forEach
|
||||
val currentSemesterEndDate = (student.getLong("OkresDataDo") ?: return@forEach) + 86400
|
||||
val studentSemesterNumber = student.getInt("OkresNumer") ?: return@forEach
|
||||
|
||||
val isParent = student.getString("UzytkownikRola") == "opiekun"
|
||||
val accountName = if (isParent)
|
||||
student.getString("UzytkownikNazwa")?.swapFirstLastName()?.fixName()
|
||||
else null
|
||||
|
||||
var dateSemester1Start: Date? = null
|
||||
var dateSemester2Start: Date? = null
|
||||
var dateYearEnd: Date? = null
|
||||
when (studentSemesterNumber) {
|
||||
1 -> {
|
||||
dateSemester1Start = Date.fromMillis(currentSemesterStartDate * 1000)
|
||||
dateSemester2Start = Date.fromMillis(currentSemesterEndDate * 1000)
|
||||
}
|
||||
2 -> {
|
||||
dateSemester2Start = Date.fromMillis(currentSemesterStartDate * 1000)
|
||||
dateYearEnd = Date.fromMillis(currentSemesterEndDate * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
val profile = Profile(
|
||||
firstProfileId++,
|
||||
loginStoreId,
|
||||
LOGIN_TYPE_VULCAN,
|
||||
studentNameLong,
|
||||
userLogin,
|
||||
studentNameLong,
|
||||
studentNameShort,
|
||||
accountName
|
||||
).apply {
|
||||
this.studentClassName = studentClassName
|
||||
studentData["symbol"] = data.symbol
|
||||
|
||||
studentData["studentId"] = studentId
|
||||
studentData["studentLoginId"] = studentLoginId
|
||||
studentData["studentClassId"] = studentClassId
|
||||
studentData["studentSemesterId"] = studentSemesterId
|
||||
studentData["studentSemesterNumber"] = studentSemesterNumber
|
||||
studentData["semester${studentSemesterNumber}Id"] = studentSemesterId
|
||||
studentData["schoolSymbol"] = schoolSymbol
|
||||
studentData["schoolShort"] = schoolShort
|
||||
studentData["schoolName"] = schoolCode
|
||||
studentData["currentSemesterEndDate"] = currentSemesterEndDate
|
||||
}
|
||||
dateSemester1Start?.let {
|
||||
profile.dateSemester1Start = it
|
||||
profile.studentSchoolYearStart = it.year
|
||||
}
|
||||
dateSemester2Start?.let { profile.dateSemester2Start = it }
|
||||
dateYearEnd?.let { profile.dateYearEnd = it }
|
||||
|
||||
profileList.add(profile)
|
||||
}
|
||||
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerDeviceHebe(onSuccess: () -> Unit) {
|
||||
VulcanLoginHebe(data) {
|
||||
VulcanHebeMain(data).getStudents(
|
||||
|
@ -5,7 +5,6 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login
|
||||
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_HEBE
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
@ -51,10 +50,6 @@ class VulcanLogin(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_login_vulcan_web_main)
|
||||
VulcanLoginWebMain(data) { onSuccess(loginMethodId) }
|
||||
}
|
||||
LOGIN_METHOD_VULCAN_API -> {
|
||||
data.startProgress(R.string.edziennik_progress_login_vulcan_api)
|
||||
VulcanLoginApi(data) { onSuccess(loginMethodId) }
|
||||
}
|
||||
LOGIN_METHOD_VULCAN_HEBE -> {
|
||||
data.startProgress(R.string.edziennik_progress_login_vulcan_api)
|
||||
VulcanLoginHebe(data) { onSuccess(loginMethodId) }
|
||||
|
@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-6.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login
|
||||
|
||||
import android.os.Build
|
||||
import com.google.gson.JsonObject
|
||||
import im.wangchao.mhttp.Request
|
||||
import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.callback.JsonCallbackHandler
|
||||
import io.github.wulkanowy.signer.android.getPrivateKeyFromCert
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiUpdateSemester
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class VulcanLoginApi(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
private const val TAG = "VulcanLoginApi"
|
||||
}
|
||||
|
||||
init { run {
|
||||
if (data.studentSemesterNumber == 1 && data.semester1Id == 0)
|
||||
data.semester1Id = data.studentSemesterNumber
|
||||
if (data.studentSemesterNumber == 2 && data.semester2Id == 0)
|
||||
data.semester2Id = data.studentSemesterNumber
|
||||
|
||||
copyFromLoginStore()
|
||||
|
||||
if (data.profile != null && data.isApiLoginValid()) {
|
||||
onSuccess()
|
||||
}
|
||||
else {
|
||||
if (data.apiFingerprint[data.symbol].isNotNullNorEmpty()
|
||||
&& data.apiPrivateKey[data.symbol].isNotNullNorEmpty()
|
||||
&& data.symbol.isNotNullNorEmpty()) {
|
||||
// (see data.isApiLoginValid())
|
||||
// the semester end date is over
|
||||
VulcanApiUpdateSemester(data, null) { onSuccess() }
|
||||
return@run
|
||||
}
|
||||
|
||||
if (data.symbol.isNotNullNorEmpty() && data.apiToken[data.symbol].isNotNullNorEmpty() && data.apiPin[data.symbol].isNotNullNorEmpty()) {
|
||||
loginWithToken()
|
||||
}
|
||||
else {
|
||||
data.error(ApiError(TAG, ERROR_LOGIN_DATA_MISSING))
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
private fun copyFromLoginStore() {
|
||||
data.loginStore.data.apply {
|
||||
// < v4.0 - PFX to Private Key migration
|
||||
if (has("certificatePfx")) {
|
||||
try {
|
||||
val privateKey = getPrivateKeyFromCert(
|
||||
if (data.apiToken[data.symbol]?.get(0) == 'F') VULCAN_API_PASSWORD_FAKELOG else VULCAN_API_PASSWORD,
|
||||
getString("certificatePfx") ?: ""
|
||||
)
|
||||
data.apiPrivateKey = mapOf(
|
||||
data.symbol to privateKey
|
||||
)
|
||||
remove("certificatePfx")
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
// 4.0 - new login form - copy user input to profile
|
||||
if (has("symbol")) {
|
||||
data.symbol = getString("symbol")
|
||||
remove("symbol")
|
||||
}
|
||||
|
||||
// 4.0 - before Vulcan Web impl - migrate from strings to Map of Symbol to String
|
||||
if (has("deviceSymbol")) {
|
||||
data.symbol = getString("deviceSymbol")
|
||||
remove("deviceSymbol")
|
||||
}
|
||||
if (has("certificateKey")) {
|
||||
data.apiFingerprint = data.apiFingerprint.toMutableMap().also {
|
||||
it[data.symbol] = getString("certificateKey")
|
||||
}
|
||||
remove("certificateKey")
|
||||
}
|
||||
if (has("certificatePrivate")) {
|
||||
data.apiPrivateKey = data.apiPrivateKey.toMutableMap().also {
|
||||
it[data.symbol] = getString("certificatePrivate")
|
||||
}
|
||||
remove("certificatePrivate")
|
||||
}
|
||||
|
||||
// map form inputs to the symbol
|
||||
if (has("deviceToken")) {
|
||||
data.apiToken = data.apiToken.toMutableMap().also {
|
||||
it[data.symbol] = getString("deviceToken")
|
||||
}
|
||||
remove("deviceToken")
|
||||
}
|
||||
if (has("devicePin")) {
|
||||
data.apiPin = data.apiPin.toMutableMap().also {
|
||||
it[data.symbol] = getString("devicePin")
|
||||
}
|
||||
remove("devicePin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loginWithToken() {
|
||||
d(TAG, "Request: Vulcan/Login/Api - ${data.apiUrl}/$VULCAN_API_ENDPOINT_CERTIFICATE")
|
||||
|
||||
val callback = object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||
if (json == null) {
|
||||
if (response?.code() == HTTP_BAD_REQUEST) {
|
||||
data.error(TAG, ERROR_LOGIN_VULCAN_INVALID_SYMBOL, response)
|
||||
return
|
||||
}
|
||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
var tokenStatus = json.getString("TokenStatus")
|
||||
if (tokenStatus == "Null" || tokenStatus == "CertGenerated")
|
||||
tokenStatus = null
|
||||
val error = tokenStatus ?: json.getString("Message")
|
||||
error?.let { code ->
|
||||
when (code) {
|
||||
"TokenNotFound" -> ERROR_LOGIN_VULCAN_INVALID_TOKEN
|
||||
"TokenDead" -> ERROR_LOGIN_VULCAN_EXPIRED_TOKEN
|
||||
"WrongPIN" -> {
|
||||
Pattern.compile("Liczba pozostałych prób: ([0-9])", Pattern.DOTALL).matcher(tokenStatus).let { matcher ->
|
||||
if (matcher.matches())
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN + 1 + matcher.group(1).toInt()
|
||||
else
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN
|
||||
}
|
||||
}
|
||||
"Broken" -> ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING
|
||||
"OnlyKindergarten" -> ERROR_LOGIN_VULCAN_ONLY_KINDERGARTEN
|
||||
"NoPupils" -> ERROR_LOGIN_VULCAN_NO_PUPILS
|
||||
else -> ERROR_LOGIN_VULCAN_OTHER
|
||||
}.let { errorCode ->
|
||||
data.error(ApiError(TAG, errorCode)
|
||||
.withApiResponse(json)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val cert = json.getJsonObject("TokenCert")
|
||||
if (cert == null) {
|
||||
data.error(ApiError(TAG, ERROR_LOGIN_VULCAN_OTHER)
|
||||
.withApiResponse(json)
|
||||
.withResponse(response))
|
||||
return
|
||||
}
|
||||
|
||||
val privateKey = getPrivateKeyFromCert(
|
||||
if (data.apiToken[data.symbol]?.get(0) == 'F') VULCAN_API_PASSWORD_FAKELOG else VULCAN_API_PASSWORD,
|
||||
cert.getString("CertyfikatPfx") ?: ""
|
||||
)
|
||||
|
||||
data.apiFingerprint = data.apiFingerprint.toMutableMap().also {
|
||||
it[data.symbol] = cert.getString("CertyfikatKlucz")
|
||||
}
|
||||
data.apiToken = data.apiToken.toMutableMap().also {
|
||||
it[data.symbol] = it[data.symbol]?.substring(0, 3)
|
||||
}
|
||||
data.apiPrivateKey = data.apiPrivateKey.toMutableMap().also {
|
||||
it[data.symbol] = privateKey
|
||||
}
|
||||
data.loginStore.removeLoginData("certificatePfx")
|
||||
data.loginStore.removeLoginData("apiPin")
|
||||
onSuccess()
|
||||
}
|
||||
|
||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||
data.error(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
||||
.withResponse(response)
|
||||
.withThrowable(throwable))
|
||||
}
|
||||
}
|
||||
|
||||
val szkolnyApi = SzkolnyApi(data.app)
|
||||
val firebaseToken = szkolnyApi.runCatching({
|
||||
getFirebaseToken("vulcan")
|
||||
}, onError = {
|
||||
// screw errors
|
||||
}) ?: data.app.config.sync.tokenVulcan
|
||||
|
||||
Request.builder()
|
||||
.url("${data.apiUrl}$VULCAN_API_ENDPOINT_CERTIFICATE")
|
||||
.userAgent(VULCAN_API_USER_AGENT)
|
||||
.addHeader("RequestMobileType", "RegisterDevice")
|
||||
.addParameter("PIN", data.apiPin[data.symbol])
|
||||
.addParameter("TokenKey", data.apiToken[data.symbol])
|
||||
.addParameter("DeviceId", data.buildDeviceId())
|
||||
.addParameter("DeviceName", VULCAN_API_DEVICE_NAME)
|
||||
.addParameter("DeviceNameUser", "")
|
||||
.addParameter("DeviceDescription", "")
|
||||
.addParameter("DeviceSystemType", "Android")
|
||||
.addParameter("DeviceSystemVersion", Build.VERSION.RELEASE)
|
||||
.addParameter("RemoteMobileTimeKey", currentTimeUnix())
|
||||
.addParameter("TimeKey", currentTimeUnix() - 1)
|
||||
.addParameter("RequestId", UUID.randomUUID().toString())
|
||||
.addParameter("AppVersion", VULCAN_API_APP_VERSION)
|
||||
.addParameter("RemoteMobileAppVersion", VULCAN_API_APP_VERSION)
|
||||
.addParameter("RemoteMobileAppName", VULCAN_API_APP_NAME)
|
||||
.addParameter("FirebaseTokenKey", firebaseToken ?: "")
|
||||
.postJson()
|
||||
.allowErrorCode(HTTP_BAD_REQUEST)
|
||||
.callback(callback)
|
||||
.build()
|
||||
.enqueue()
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-20.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
@ -28,7 +32,7 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
|
||||
copyFromLoginStore()
|
||||
|
||||
if (data.profile != null && data.isApiLoginValid()) {
|
||||
if (data.profile != null && data.isHebeLoginValid()) {
|
||||
onSuccess()
|
||||
}
|
||||
else {
|
||||
|
@ -13,7 +13,7 @@ import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.fslogin.FSLogin
|
||||
import pl.szczodrzynski.fslogin.realm.CufsRealm
|
||||
import pl.szczodrzynski.fslogin.realm.toRealm
|
||||
|
||||
class VulcanLoginWebMain(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
@ -30,8 +30,7 @@ class VulcanLoginWebMain(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
}
|
||||
else {
|
||||
if (data.symbol.isNotNullNorEmpty()
|
||||
&& data.webType.isNotNullNorEmpty()
|
||||
&& data.webHost.isNotNullNorEmpty()
|
||||
&& data.webRealmData != null
|
||||
&& (data.webEmail.isNotNullNorEmpty() || data.webUsername.isNotNullNorEmpty())
|
||||
&& data.webPassword.isNotNullNorEmpty()) {
|
||||
try {
|
||||
@ -56,32 +55,28 @@ class VulcanLoginWebMain(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.symbol = getString("symbol")
|
||||
remove("symbol")
|
||||
}
|
||||
// 4.6 - form inputs renamed
|
||||
if (has("email")) {
|
||||
data.webEmail = getString("email")
|
||||
remove("email")
|
||||
}
|
||||
if (has("username")) {
|
||||
data.webUsername = getString("username")
|
||||
remove("username")
|
||||
}
|
||||
if (has("password")) {
|
||||
data.webPassword = getString("password")
|
||||
remove("password")
|
||||
}
|
||||
}
|
||||
|
||||
if (data.symbol == null && data.webRealmData != null) {
|
||||
data.symbol = data.webRealmData?.symbol
|
||||
}
|
||||
}
|
||||
|
||||
private fun loginWithCredentials(): Boolean {
|
||||
val realm = when (data.webType) {
|
||||
"cufs" -> CufsRealm(
|
||||
host = data.webHost ?: return false,
|
||||
symbol = data.symbol ?: "default",
|
||||
httpCufs = data.webIsHttpCufs
|
||||
)
|
||||
"adfs" -> CufsRealm(
|
||||
host = data.webHost ?: return false,
|
||||
symbol = data.symbol ?: "default",
|
||||
httpCufs = data.webIsHttpCufs
|
||||
).toAdfsRealm(id = data.webAdfsId ?: return false)
|
||||
"adfslight" -> CufsRealm(
|
||||
host = data.webHost ?: return false,
|
||||
symbol = data.symbol ?: "default",
|
||||
httpCufs = data.webIsHttpCufs
|
||||
).toAdfsLightRealm(
|
||||
id = data.webAdfsId ?: return false,
|
||||
domain = data.webAdfsDomain ?: "adfslight",
|
||||
isScoped = data.webIsScopedAdfs
|
||||
)
|
||||
else -> return false
|
||||
}
|
||||
val realm = data.webRealmData?.toRealm() ?: return false
|
||||
|
||||
val certificate = web.readCertificate()?.let { web.parseCertificate(it) }
|
||||
if (certificate != null && Date.fromIso(certificate.expiryDate) > System.currentTimeMillis()) {
|
||||
|
@ -88,11 +88,13 @@ class SzkolnyApi(val app: App) : CoroutineScope {
|
||||
withContext(Dispatchers.Default) { block.invoke(this@SzkolnyApi) }
|
||||
}
|
||||
catch (e: Exception) {
|
||||
ErrorDetailsDialog(
|
||||
withContext(coroutineContext) {
|
||||
ErrorDetailsDialog(
|
||||
activity,
|
||||
listOf(e.toApiError(TAG)),
|
||||
R.string.error_occured
|
||||
)
|
||||
)
|
||||
}
|
||||
null
|
||||
}
|
||||
}
|
||||
@ -348,8 +350,8 @@ class SzkolnyApi(val app: App) : CoroutineScope {
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun getPlatforms(registerName: String): List<LoginInfo.Platform> {
|
||||
val response = api.appLoginPlatforms(registerName).execute()
|
||||
fun getRealms(registerName: String): List<LoginInfo.Platform> {
|
||||
val response = api.fsLoginRealms(registerName).execute()
|
||||
|
||||
return parseResponse(response)
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ interface SzkolnyService {
|
||||
@POST("feedbackMessage")
|
||||
fun feedbackMessage(@Body request: FeedbackMessageRequest): Call<ApiResponse<FeedbackMessageResponse>>
|
||||
|
||||
@GET("appLogin/platforms/{registerName}")
|
||||
fun appLoginPlatforms(@Path("registerName") registerName: String): Call<ApiResponse<List<LoginInfo.Platform>>>
|
||||
|
||||
@GET("firebase/token/{registerName}")
|
||||
fun firebaseToken(@Path("registerName") registerName: String): Call<ApiResponse<String>>
|
||||
|
||||
@GET("registerAvailability")
|
||||
fun registerAvailability(): Call<ApiResponse<Map<String, RegisterAvailabilityStatus>>>
|
||||
|
||||
@GET("fsLogin/{registerName}")
|
||||
fun fsLoginRealms(@Path("registerName") registerName: String): Call<ApiResponse<List<LoginInfo.Platform>>>
|
||||
}
|
||||
|
@ -46,6 +46,6 @@ object Signing {
|
||||
|
||||
/*fun provideKey(param1: String, param2: Long): ByteArray {*/
|
||||
fun pleaseStopRightNow(param1: String, param2: Long): ByteArray {
|
||||
return "$param1.MTIzNDU2Nzg5MD5LwH9bSc===.$param2".sha256()
|
||||
return "$param1.MTIzNDU2Nzg5MDAwogntL3===.$param2".sha256()
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
||||
LibrusLesson::class,
|
||||
TimetableManual::class,
|
||||
Metadata::class
|
||||
], version = 89)
|
||||
], version = 90)
|
||||
@TypeConverters(
|
||||
ConverterTime::class,
|
||||
ConverterDate::class,
|
||||
@ -174,7 +174,8 @@ abstract class AppDb : RoomDatabase() {
|
||||
Migration86(),
|
||||
Migration87(),
|
||||
Migration88(),
|
||||
Migration89()
|
||||
Migration89(),
|
||||
Migration90()
|
||||
).allowMainThreadQueries().build()
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,25 @@ open class Event(
|
||||
var attachmentIds: MutableList<Long>? = null
|
||||
var attachmentNames: MutableList<String>? = null
|
||||
|
||||
/**
|
||||
* Add an attachment
|
||||
* @param id attachment ID
|
||||
* @param name file name incl. extension
|
||||
* @return a Event to which the attachment has been added
|
||||
*/
|
||||
fun addAttachment(id: Long, name: String): Event {
|
||||
if (attachmentIds == null) attachmentIds = mutableListOf()
|
||||
if (attachmentNames == null) attachmentNames = mutableListOf()
|
||||
attachmentIds?.add(id)
|
||||
attachmentNames?.add(name)
|
||||
return this
|
||||
}
|
||||
|
||||
fun clearAttachments() {
|
||||
attachmentIds = null
|
||||
attachmentNames = null
|
||||
}
|
||||
|
||||
@Ignore
|
||||
var showAsUnseen: Boolean? = null
|
||||
|
||||
|
@ -59,6 +59,7 @@ class LoginStore(
|
||||
is Long -> putLoginData(key, o)
|
||||
is Float -> putLoginData(key, o)
|
||||
is Boolean -> putLoginData(key, o)
|
||||
is Bundle -> putLoginData(key, o.toJsonObject())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.fixName
|
||||
import pl.szczodrzynski.edziennik.getNameInitials
|
||||
import pl.szczodrzynski.edziennik.join
|
||||
import java.util.*
|
||||
|
||||
@ -180,6 +181,9 @@ open class Teacher {
|
||||
@delegate:Ignore
|
||||
val fullNameLastFirst by lazy { "$surname $name".fixName() }
|
||||
|
||||
@delegate:Ignore
|
||||
val initialsLastFirst by lazy { fullNameLastFirst.getNameInitials() }
|
||||
|
||||
val shortName: String
|
||||
get() = (if (name == null || name?.length == 0) "" else name!![0].toString()) + "." + surname
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-26.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.migration
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration90 : Migration(89, 90) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
// get all profiles using Vulcan/Hebe
|
||||
database.execSQL("CREATE TABLE _90_ids (id INTEGER NOT NULL);")
|
||||
database.execSQL("INSERT INTO _90_ids SELECT profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 4 AND loginStores.loginStoreMode != 0;")
|
||||
|
||||
// force full sync when updating from <4.6
|
||||
database.execSQL("DELETE FROM endpointTimers WHERE profileId IN (SELECT id FROM _90_ids);")
|
||||
database.execSQL("UPDATE profiles SET empty = 1 WHERE profileId IN (SELECT id FROM _90_ids);")
|
||||
// remove messages and events to re-download attachments and remove older than current school year
|
||||
database.execSQL("DELETE FROM messages WHERE profileId IN (SELECT id FROM _90_ids);")
|
||||
database.execSQL("DELETE FROM events WHERE profileId IN (SELECT id FROM _90_ids) AND eventAddedManually = 0;")
|
||||
// remove older data
|
||||
database.execSQL("DELETE FROM notices WHERE profileId IN (SELECT id FROM _90_ids);")
|
||||
|
||||
// fix for v4.5 users who logged in using Vulcan/Web
|
||||
database.execSQL("UPDATE loginStores SET loginStoreMode = 2 WHERE loginStoreType = 4 AND loginStoreMode = 1;")
|
||||
|
||||
database.execSQL("DROP TABLE _90_ids;")
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List<Profile>, val messa
|
||||
val data = message.data.getString("data")?.toJsonObject() ?: return@run
|
||||
val type = data.getString("table") ?: return@run
|
||||
val studentId = data.getInt("pupilid")
|
||||
val loginId = data.getInt("loginid")
|
||||
|
||||
/* pl.vulcan.uonetmobile.auxilary.enums.CDCPushEnum */
|
||||
val viewIdPair = when (type.toLowerCase(Locale.ROOT)) {
|
||||
@ -42,8 +43,9 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List<Profile>, val messa
|
||||
}
|
||||
|
||||
val tasks = profiles.filter {
|
||||
it.loginStoreType == LOGIN_TYPE_VULCAN &&
|
||||
it.getStudentData("studentId", 0) == studentId
|
||||
it.loginStoreType == LOGIN_TYPE_VULCAN
|
||||
&& (it.getStudentData("studentId", 0) == studentId
|
||||
|| it.getStudentData("studentLoginId", 0) == loginId)
|
||||
}.map {
|
||||
EdziennikTask.syncProfile(it.id, listOf(viewIdPair))
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ import kotlin.coroutines.CoroutineContext
|
||||
class ProfileRemoveDialog(
|
||||
val activity: MainActivity,
|
||||
val profileId: Int,
|
||||
val profileName: String
|
||||
val profileName: String,
|
||||
val noProfileRemoval: Boolean = false
|
||||
) : CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "ProfileRemoveDialog"
|
||||
@ -52,7 +53,6 @@ class ProfileRemoveDialog(
|
||||
app.db.attendanceDao().clear(profileId)
|
||||
app.db.attendanceTypeDao().clear(profileId)
|
||||
app.db.classroomDao().clear(profileId)
|
||||
app.db.configDao().clear(profileId)
|
||||
app.db.endpointTimerDao().clear(profileId)
|
||||
app.db.eventDao().clear(profileId)
|
||||
app.db.eventTypeDao().clear(profileId)
|
||||
@ -65,23 +65,27 @@ class ProfileRemoveDialog(
|
||||
app.db.messageRecipientDao().clear(profileId)
|
||||
app.db.noticeDao().clear(profileId)
|
||||
app.db.noticeTypeDao().clear(profileId)
|
||||
app.db.noticeTypeDao().clear(profileId)
|
||||
app.db.notificationDao().clear(profileId)
|
||||
app.db.subjectDao().clear(profileId)
|
||||
app.db.teacherAbsenceDao().clear(profileId)
|
||||
app.db.teacherAbsenceDao().clear(profileId)
|
||||
app.db.teacherAbsenceTypeDao().clear(profileId)
|
||||
app.db.teacherDao().clear(profileId)
|
||||
app.db.teamDao().clear(profileId)
|
||||
app.db.timetableDao().clear(profileId)
|
||||
|
||||
app.db.metadataDao().deleteAll(profileId)
|
||||
|
||||
if (noProfileRemoval)
|
||||
return@async
|
||||
|
||||
app.db.configDao().clear(profileId)
|
||||
|
||||
val loginStoreId = profileObject.loginStoreId
|
||||
val profilesUsingLoginStore = app.db.profileDao().getIdsByLoginStoreIdNow(loginStoreId)
|
||||
if (profilesUsingLoginStore.size == 1) {
|
||||
app.db.loginStoreDao().remove(loginStoreId)
|
||||
}
|
||||
app.db.profileDao().remove(profileId)
|
||||
app.db.metadataDao().deleteAll(profileId)
|
||||
|
||||
if (App.profileId == profileId) {
|
||||
app.profileLoadLast { }
|
||||
|
@ -26,6 +26,7 @@ import pl.szczodrzynski.edziennik.ui.modules.debug.models.LabJsonObject
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.viewholder.JsonArrayViewHolder
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.viewholder.JsonElementViewHolder
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.viewholder.JsonObjectViewHolder
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.viewholder.JsonSubObjectViewHolder
|
||||
import pl.szczodrzynski.edziennik.ui.modules.grades.models.ExpandableItemModel
|
||||
import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -35,14 +36,20 @@ class LabJsonAdapter(
|
||||
var onJsonElementClick: ((item: LabJsonElement) -> Unit)? = null
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>(), CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "AttendanceAdapter"
|
||||
private const val TAG = "LabJsonAdapter"
|
||||
private const val ITEM_TYPE_OBJECT = 0
|
||||
private const val ITEM_TYPE_ARRAY = 1
|
||||
private const val ITEM_TYPE_ELEMENT = 2
|
||||
private const val ITEM_TYPE_SUB_OBJECT = 1
|
||||
private const val ITEM_TYPE_ARRAY = 2
|
||||
private const val ITEM_TYPE_ELEMENT = 3
|
||||
const val STATE_CLOSED = 0
|
||||
const val STATE_OPENED = 1
|
||||
|
||||
fun expand(item: Any, level: Int): MutableList<Any> {
|
||||
val path = when (item) {
|
||||
is LabJsonObject -> item.key + ":"
|
||||
is LabJsonArray -> item.key + ":"
|
||||
else -> ""
|
||||
}
|
||||
val json = when (item) {
|
||||
is LabJsonObject -> item.jsonObject
|
||||
is LabJsonArray -> item.jsonArray
|
||||
@ -53,17 +60,16 @@ class LabJsonAdapter(
|
||||
}
|
||||
|
||||
return when (json) {
|
||||
is JsonObject -> json.entrySet().mapNotNull { wrap(it.key, it.value, level) }
|
||||
is JsonArray -> json.mapIndexedNotNull { index, jsonElement -> wrap(index.toString(), jsonElement, level) }
|
||||
else -> listOf(LabJsonElement("?", json, level))
|
||||
is JsonObject -> json.entrySet().mapNotNull { wrap(path + it.key, it.value, level) }
|
||||
is JsonArray -> json.mapIndexedNotNull { index, jsonElement -> wrap(path + index.toString(), jsonElement, level) }
|
||||
else -> listOf(LabJsonElement("$path?", json, level))
|
||||
}.toMutableList()
|
||||
}
|
||||
fun wrap(key: String, item: JsonElement, level: Int = 0): Any? {
|
||||
fun wrap(key: String, item: JsonElement, level: Int = 0): Any {
|
||||
return when (item) {
|
||||
is JsonObject -> LabJsonObject(key, item, level + 1)
|
||||
is JsonArray -> LabJsonArray(key, item, level + 1)
|
||||
is JsonElement -> LabJsonElement(key, item, level + 1)
|
||||
else -> null
|
||||
else -> LabJsonElement(key, item, level + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,6 +86,7 @@ class LabJsonAdapter(
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
return when (viewType) {
|
||||
ITEM_TYPE_OBJECT -> JsonObjectViewHolder(inflater, parent)
|
||||
ITEM_TYPE_SUB_OBJECT -> JsonSubObjectViewHolder(inflater, parent)
|
||||
ITEM_TYPE_ARRAY -> JsonArrayViewHolder(inflater, parent)
|
||||
ITEM_TYPE_ELEMENT -> JsonElementViewHolder(inflater, parent)
|
||||
else -> throw IllegalArgumentException("Incorrect viewType")
|
||||
@ -87,8 +94,10 @@ class LabJsonAdapter(
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (items[position]) {
|
||||
is LabJsonObject -> ITEM_TYPE_OBJECT
|
||||
return when (val item = items[position]) {
|
||||
is LabJsonObject ->
|
||||
if (item.level == 1) ITEM_TYPE_OBJECT
|
||||
else ITEM_TYPE_SUB_OBJECT
|
||||
is LabJsonArray -> ITEM_TYPE_ARRAY
|
||||
is LabJsonElement -> ITEM_TYPE_ELEMENT
|
||||
else -> throw IllegalArgumentException("Incorrect viewType")
|
||||
@ -118,7 +127,7 @@ class LabJsonAdapter(
|
||||
View.ROTATION,
|
||||
if (model.state == STATE_CLOSED) 0f else 180f,
|
||||
if (model.state == STATE_CLOSED) 180f else 0f
|
||||
).setDuration(200).start();
|
||||
).setDuration(200).start()
|
||||
}
|
||||
|
||||
// hide the preview, show summary
|
||||
@ -143,7 +152,9 @@ class LabJsonAdapter(
|
||||
var end: Int = items.size
|
||||
for (i in start until items.size) {
|
||||
val model1 = items[i]
|
||||
val level = (model1 as? ExpandableItemModel<*>)?.level ?: 3
|
||||
val level = (model1 as? ExpandableItemModel<*>)?.level
|
||||
?: (model1 as? LabJsonElement)?.level
|
||||
?: model.level
|
||||
if (level <= model.level) {
|
||||
end = i
|
||||
break
|
||||
@ -170,6 +181,7 @@ class LabJsonAdapter(
|
||||
|
||||
val viewType = when (holder) {
|
||||
is JsonObjectViewHolder -> ITEM_TYPE_OBJECT
|
||||
is JsonSubObjectViewHolder -> ITEM_TYPE_SUB_OBJECT
|
||||
is JsonArrayViewHolder -> ITEM_TYPE_ARRAY
|
||||
is JsonElementViewHolder -> ITEM_TYPE_ELEMENT
|
||||
else -> throw IllegalArgumentException("Incorrect viewType")
|
||||
@ -180,6 +192,7 @@ class LabJsonAdapter(
|
||||
|
||||
when {
|
||||
holder is JsonObjectViewHolder && item is LabJsonObject -> holder.onBind(activity, app, item, position, this)
|
||||
holder is JsonSubObjectViewHolder && item is LabJsonObject -> holder.onBind(activity, app, item, position, this)
|
||||
holder is JsonArrayViewHolder && item is LabJsonArray -> holder.onBind(activity, app, item, position, this)
|
||||
holder is JsonElementViewHolder && item is LabJsonElement -> holder.onBind(activity, app, item, position, this)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.launch
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.databinding.LabFragmentBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment
|
||||
import pl.szczodrzynski.edziennik.utils.TextInputDropDown
|
||||
import pl.szczodrzynski.fslogin.decode
|
||||
@ -60,6 +61,15 @@ class LabPageFragment : LazyFragment(), CoroutineScope {
|
||||
b.rodo.onClick {
|
||||
app.db.teacherDao().query(SimpleSQLiteQuery("UPDATE teachers SET teacherSurname = \"\" WHERE profileId = ${App.profileId}"))
|
||||
}
|
||||
|
||||
b.fullSync.onClick {
|
||||
app.db.query(SimpleSQLiteQuery("UPDATE profiles SET empty = 1 WHERE profileId = ${App.profileId}"))
|
||||
app.db.query(SimpleSQLiteQuery("DELETE FROM endpointTimers WHERE profileId = ${App.profileId}"))
|
||||
}
|
||||
|
||||
b.clearProfile.onClick {
|
||||
ProfileRemoveDialog(activity, App.profileId, "FAKE", noProfileRemoval = true)
|
||||
}
|
||||
|
||||
b.removeHomework.onClick {
|
||||
app.db.eventDao().getRawNow("UPDATE events SET homeworkBody = NULL WHERE profileId = ${App.profileId}")
|
||||
|
@ -10,16 +10,14 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.google.gson.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.databinding.TemplateListPageFragmentBinding
|
||||
import pl.szczodrzynski.edziennik.startCoroutineTimer
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.lazypager.LazyFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -38,6 +36,10 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
get() = job + Dispatchers.Main
|
||||
|
||||
// local/private variables go here
|
||||
private lateinit var adapter: LabJsonAdapter
|
||||
private val loginStore by lazy {
|
||||
app.db.loginStoreDao().getByIdNow(app.profile.loginStoreId)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
@ -48,22 +50,96 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
override fun onPageCreated(): Boolean { startCoroutineTimer(100L) {
|
||||
val adapter = LabJsonAdapter(activity)
|
||||
val json = JsonObject().also { json ->
|
||||
json.add("app.profile", app.profile.studentData)
|
||||
json.add("app.config", JsonParser().parse(app.gson.toJson(app.config.values)))
|
||||
EdziennikTask.profile?.let {
|
||||
json.add("API.profile", it.studentData)
|
||||
} ?: {
|
||||
json.addProperty("API.profile", "null")
|
||||
}()
|
||||
EdziennikTask.loginStore?.let {
|
||||
json.add("API.loginStore", it.data)
|
||||
} ?: {
|
||||
json.addProperty("API.loginStore", "null")
|
||||
}()
|
||||
}
|
||||
adapter.items = LabJsonAdapter.expand(json, 0)
|
||||
adapter = LabJsonAdapter(activity, onJsonElementClick = { item ->
|
||||
try {
|
||||
var parent: Any = Unit
|
||||
var obj: Any = Unit
|
||||
var objName: String = ""
|
||||
item.key.split(":").forEach { el ->
|
||||
parent = obj
|
||||
obj = when (el) {
|
||||
"App.profile" -> app.profile
|
||||
"App.profile.studentData" -> app.profile.studentData
|
||||
"App.profile.loginStore" -> loginStore?.data ?: JsonObject()
|
||||
"App.config" -> app.config.values
|
||||
else -> when (obj) {
|
||||
is JsonObject -> (obj as JsonObject).get(el)
|
||||
is JsonArray -> (obj as JsonArray).get(el.toInt())
|
||||
is HashMap<*, *> -> (obj as HashMap<String, String?>)[el].toString()
|
||||
else -> {
|
||||
val field = obj::class.java.getDeclaredField(el)
|
||||
field.isAccessible = true
|
||||
field.get(obj) ?: return@forEach
|
||||
}
|
||||
}
|
||||
}
|
||||
objName = el
|
||||
}
|
||||
|
||||
val objVal = obj
|
||||
val value = when (objVal) {
|
||||
is JsonPrimitive -> when {
|
||||
objVal.isString -> objVal.asString
|
||||
objVal.isNumber -> objVal.asNumber.toString()
|
||||
objVal.isBoolean -> objVal.asBoolean.toString()
|
||||
else -> objVal.asString
|
||||
}
|
||||
else -> objVal.toString()
|
||||
}
|
||||
|
||||
MaterialDialog.Builder(activity)
|
||||
.input("value", value, false) { _, input ->
|
||||
val input = input.toString()
|
||||
when (parent) {
|
||||
is JsonObject -> {
|
||||
val v = objVal as JsonPrimitive
|
||||
when {
|
||||
v.isString -> (parent as JsonObject)[objName] = input
|
||||
v.isNumber -> (parent as JsonObject)[objName] = input.toLong()
|
||||
v.isBoolean -> (parent as JsonObject)[objName] = input.toBoolean()
|
||||
}
|
||||
}
|
||||
is JsonArray -> {
|
||||
|
||||
}
|
||||
is HashMap<*, *> -> app.config.set(objName, input)
|
||||
else -> {
|
||||
val field = parent::class.java.getDeclaredField(objName)
|
||||
field.isAccessible = true
|
||||
val newVal = when (objVal) {
|
||||
is Int -> input.toInt()
|
||||
is Boolean -> input.toBoolean()
|
||||
is Float -> input.toFloat()
|
||||
is Char -> input.toCharArray()[0]
|
||||
is String -> input
|
||||
is Long -> input.toLong()
|
||||
is Double -> input.toDouble()
|
||||
else -> input
|
||||
}
|
||||
field.set(parent, newVal)
|
||||
}
|
||||
}
|
||||
|
||||
when (item.key.substringBefore(":")) {
|
||||
"App.profile" -> app.profileSave()
|
||||
"App.profile.studentData" -> app.profileSave()
|
||||
"App.profile.loginStore" -> app.db.loginStoreDao().add(loginStore)
|
||||
}
|
||||
|
||||
showJson()
|
||||
|
||||
}
|
||||
.title(item.key)
|
||||
.positiveText(R.string.ok)
|
||||
.negativeText(R.string.cancel)
|
||||
.show()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
activity.error(ApiError.fromThrowable(TAG, e))
|
||||
}
|
||||
})
|
||||
|
||||
showJson()
|
||||
|
||||
b.list.adapter = adapter
|
||||
b.list.apply {
|
||||
@ -79,4 +155,15 @@ class LabProfileFragment : LazyFragment(), CoroutineScope {
|
||||
b.noData.isVisible = false
|
||||
|
||||
}; return true }
|
||||
|
||||
private fun showJson() {
|
||||
val json = JsonObject().also { json ->
|
||||
json.add("App.profile", app.gson.toJsonTree(app.profile))
|
||||
json.add("App.profile.studentData", app.profile.studentData)
|
||||
json.add("App.profile.loginStore", loginStore?.data ?: JsonObject())
|
||||
json.add("App.config", JsonParser().parse(app.gson.toJson(app.config.values)))
|
||||
}
|
||||
adapter.items = LabJsonAdapter.expand(json, 0)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import androidx.core.view.isInvisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.databinding.LabItemObjectBinding
|
||||
import pl.szczodrzynski.edziennik.dp
|
||||
import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.LabJsonAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.models.LabJsonArray
|
||||
@ -32,6 +33,10 @@ class JsonArrayViewHolder(
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonArray, position: Int, adapter: LabJsonAdapter) {
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
|
||||
|
||||
b.type.text = "Array"
|
||||
|
||||
b.dropdownIcon.rotation = when (item.state) {
|
||||
AttendanceAdapter.STATE_CLOSED -> 0f
|
||||
else -> 180f
|
||||
@ -39,7 +44,7 @@ class JsonArrayViewHolder(
|
||||
b.previewContainer.isInvisible = item.state != AttendanceAdapter.STATE_CLOSED
|
||||
b.summaryContainer.isInvisible = item.state == AttendanceAdapter.STATE_CLOSED
|
||||
|
||||
b.key.text = item.key
|
||||
b.key.text = item.key.substringAfterLast(":")
|
||||
b.previewContainer.text = item.jsonArray.toString().take(200)
|
||||
b.summaryContainer.text = item.jsonArray.size().toString() + " elements"
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ class JsonElementViewHolder(
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonElement, position: Int, adapter: LabJsonAdapter) {
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
|
||||
|
||||
b.type.text = when (item.jsonElement) {
|
||||
is JsonPrimitive -> when {
|
||||
item.jsonElement.isNumber -> "Number"
|
||||
@ -45,7 +47,9 @@ class JsonElementViewHolder(
|
||||
|
||||
val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(activity)
|
||||
b.key.text = listOf(
|
||||
item.key.asColoredSpannable(colorSecondary),
|
||||
item.key
|
||||
.substringAfterLast(":")
|
||||
.asColoredSpannable(colorSecondary),
|
||||
": ",
|
||||
item.jsonElement.toString().asItalicSpannable()
|
||||
).concat("")
|
||||
|
@ -13,6 +13,7 @@ import androidx.core.view.isInvisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.databinding.LabItemObjectBinding
|
||||
import pl.szczodrzynski.edziennik.dp
|
||||
import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.LabJsonAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.models.LabJsonObject
|
||||
@ -32,6 +33,10 @@ class JsonObjectViewHolder(
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) {
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
|
||||
|
||||
b.type.text = "Object"
|
||||
|
||||
b.dropdownIcon.rotation = when (item.state) {
|
||||
AttendanceAdapter.STATE_CLOSED -> 0f
|
||||
else -> 180f
|
||||
@ -39,7 +44,7 @@ class JsonObjectViewHolder(
|
||||
b.previewContainer.isInvisible = item.state != AttendanceAdapter.STATE_CLOSED
|
||||
b.summaryContainer.isInvisible = item.state == AttendanceAdapter.STATE_CLOSED
|
||||
|
||||
b.key.text = item.key
|
||||
b.key.text = item.key.substringAfterLast(":")
|
||||
b.previewContainer.text = item.jsonObject.toString().take(200)
|
||||
b.summaryContainer.text = item.jsonObject.size().toString() + " elements"
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-26.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.debug.viewholder
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.databinding.LabItemSubObjectBinding
|
||||
import pl.szczodrzynski.edziennik.dp
|
||||
import pl.szczodrzynski.edziennik.ui.modules.attendance.AttendanceAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.LabJsonAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.debug.models.LabJsonObject
|
||||
import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class JsonSubObjectViewHolder(
|
||||
inflater: LayoutInflater,
|
||||
parent: ViewGroup,
|
||||
val b: LabItemSubObjectBinding = LabItemSubObjectBinding.inflate(inflater, parent, false)
|
||||
) : RecyclerView.ViewHolder(b.root), BindableViewHolder<LabJsonObject, LabJsonAdapter> {
|
||||
companion object {
|
||||
private const val TAG = "JsonSubObjectViewHolder"
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBind(activity: AppCompatActivity, app: App, item: LabJsonObject, position: Int, adapter: LabJsonAdapter) {
|
||||
val contextWrapper = ContextThemeWrapper(activity, Themes.appTheme)
|
||||
|
||||
b.root.setPadding(item.level * 8.dp + 8.dp, 8.dp, 8.dp, 8.dp)
|
||||
|
||||
b.type.text = "Object"
|
||||
|
||||
b.dropdownIcon.rotation = when (item.state) {
|
||||
AttendanceAdapter.STATE_CLOSED -> 0f
|
||||
else -> 180f
|
||||
}
|
||||
|
||||
b.key.text = item.key.substringAfterLast(":")
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ import androidx.core.view.isVisible
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.google.gson.JsonParser
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.iconics.utils.paddingDp
|
||||
import com.mikepenz.iconics.utils.sizeDp
|
||||
@ -72,7 +71,7 @@ class LoginFormFragment : Fragment(), CoroutineScope {
|
||||
val platformGuideText = arguments?.getString("platformGuideText")
|
||||
val platformDescription = arguments?.getString("platformDescription")
|
||||
val platformFormFields = arguments?.getString("platformFormFields")?.split(";")
|
||||
val platformApiData = arguments?.getString("platformApiData")?.let { JsonParser().parse(it)?.asJsonObject }
|
||||
val platformRealmData = arguments?.getString("platformRealmData")?.toJsonObject()
|
||||
|
||||
b.title.setText(R.string.login_form_title_format, app.getString(register.registerName))
|
||||
b.subTitle.text = platformName ?: app.getString(mode.name)
|
||||
@ -159,9 +158,7 @@ class LoginFormFragment : Fragment(), CoroutineScope {
|
||||
payload.putBoolean("fakeLogin", true)
|
||||
}
|
||||
|
||||
platformApiData?.entrySet()?.forEach {
|
||||
payload.putString(it.key, it.value.asString)
|
||||
}
|
||||
payload.putBundle("webRealmData", platformRealmData?.toBundle())
|
||||
|
||||
var hasErrors = false
|
||||
credentials.forEach { (credential, b) ->
|
||||
|
@ -6,456 +6,457 @@ package pl.szczodrzynski.edziennik.ui.modules.login
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import com.google.gson.JsonObject
|
||||
import com.mikepenz.iconics.typeface.IIcon
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.ui.modules.grades.models.ExpandableItemModel
|
||||
import pl.szczodrzynski.fslogin.realm.RealmData
|
||||
|
||||
object LoginInfo {
|
||||
|
||||
private fun getEmailCredential(keyName: String) = FormField(
|
||||
keyName = keyName,
|
||||
name = R.string.login_hint_email,
|
||||
icon = CommunityMaterial.Icon.cmd_at,
|
||||
emptyText = R.string.login_error_no_email,
|
||||
invalidText = R.string.login_error_incorrect_email,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "([\\w.\\-_+]+)?\\w+@[\\w-_]+(\\.\\w+)+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
private fun getPasswordCredential(keyName: String) = FormField(
|
||||
keyName = keyName,
|
||||
name = R.string.login_hint_password,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_password,
|
||||
invalidText = R.string.login_error_incorrect_login_or_password,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = ".*",
|
||||
hideText = true
|
||||
keyName = keyName,
|
||||
name = R.string.login_hint_email,
|
||||
icon = CommunityMaterial.Icon.cmd_at,
|
||||
emptyText = R.string.login_error_no_email,
|
||||
invalidText = R.string.login_error_incorrect_email,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "([\\w.\\-_+]+)?\\w+@[\\w-_]+(\\.\\w+)+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
|
||||
val list by lazy { listOf(
|
||||
private fun getPasswordCredential(keyName: String) = FormField(
|
||||
keyName = keyName,
|
||||
name = R.string.login_hint_password,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_password,
|
||||
invalidText = R.string.login_error_incorrect_login_or_password,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = ".*",
|
||||
hideText = true
|
||||
)
|
||||
|
||||
val list by lazy {
|
||||
listOf(
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_LIBRUS,
|
||||
internalName = "librus",
|
||||
registerName = R.string.login_register_librus,
|
||||
registerLogo = R.drawable.login_logo_librus,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_EMAIL,
|
||||
name = R.string.login_mode_librus_email,
|
||||
icon = R.drawable.login_mode_librus_email,
|
||||
hintText = R.string.login_mode_librus_email_hint,
|
||||
guideText = R.string.login_mode_librus_email_guide,
|
||||
isRecommended = true,
|
||||
credentials = listOf(
|
||||
getEmailCredential("email"),
|
||||
getPasswordCredential("password")
|
||||
loginType = LOGIN_TYPE_LIBRUS,
|
||||
internalName = "librus",
|
||||
registerName = R.string.login_register_librus,
|
||||
registerLogo = R.drawable.login_logo_librus,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_EMAIL,
|
||||
name = R.string.login_mode_librus_email,
|
||||
icon = R.drawable.login_mode_librus_email,
|
||||
hintText = R.string.login_mode_librus_email_hint,
|
||||
guideText = R.string.login_mode_librus_email_guide,
|
||||
isRecommended = true,
|
||||
credentials = listOf(
|
||||
getEmailCredential("email"),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_NOT_ACTIVATED to R.string.login_error_account_not_activated,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_CAPTCHA_LIBRUS_PORTAL to R.string.error_3001_reason
|
||||
)
|
||||
),
|
||||
/*Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_SYNERGIA,
|
||||
name = R.string.login_mode_librus_synergia,
|
||||
icon = R.drawable.login_mode_librus_synergia,
|
||||
hintText = R.string.login_mode_librus_synergia_hint,
|
||||
guideText = R.string.login_mode_librus_synergia_guide,
|
||||
credentials = listOf(
|
||||
Credential(
|
||||
keyName = "accountLogin",
|
||||
name = R.string.login_hint_login,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_login,
|
||||
invalidText = R.string.login_error_incorrect_login,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-z0-9._\\-+]+",
|
||||
caseMode = Credential.CaseMode.LOWER_CASE
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_NOT_ACTIVATED to R.string.login_error_account_not_activated,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_CAPTCHA_LIBRUS_PORTAL to R.string.error_3001_reason
|
||||
)
|
||||
getPasswordCredential("accountPassword")
|
||||
),
|
||||
/*Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_SYNERGIA,
|
||||
name = R.string.login_mode_librus_synergia,
|
||||
icon = R.drawable.login_mode_librus_synergia,
|
||||
hintText = R.string.login_mode_librus_synergia_hint,
|
||||
guideText = R.string.login_mode_librus_synergia_guide,
|
||||
credentials = listOf(
|
||||
Credential(
|
||||
keyName = "accountLogin",
|
||||
name = R.string.login_hint_login,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_login,
|
||||
invalidText = R.string.login_error_incorrect_login,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-z0-9._\\-+]+",
|
||||
caseMode = Credential.CaseMode.LOWER_CASE
|
||||
),
|
||||
getPasswordCredential("accountPassword")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
),*/
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_JST,
|
||||
name = R.string.login_mode_librus_jst,
|
||||
icon = R.drawable.login_mode_librus_jst,
|
||||
hintText = R.string.login_mode_librus_jst_hint,
|
||||
guideText = R.string.login_mode_librus_jst_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "accountCode",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon.cmd_code_braces,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z0-9_]+",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "accountPin",
|
||||
name = R.string.login_hint_pin,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock,
|
||||
emptyText = R.string.login_error_no_pin,
|
||||
invalidText = R.string.login_error_incorrect_pin,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-z0-9_]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN to R.string.login_error_incorrect_code_or_pin,
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST to R.string.login_error_incorrect_code_or_pin
|
||||
)
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_VULCAN,
|
||||
internalName = "vulcan",
|
||||
registerName = R.string.login_type_vulcan,
|
||||
registerLogo = R.drawable.login_logo_vulcan,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_VULCAN_HEBE,
|
||||
name = R.string.login_mode_vulcan_api,
|
||||
icon = R.drawable.login_mode_vulcan_hebe,
|
||||
hintText = R.string.login_mode_vulcan_api_hint,
|
||||
guideText = R.string.login_mode_vulcan_api_guide,
|
||||
isRecommended = true,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "deviceToken",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon.cmd_code_braces,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_TOKEN to R.string.login_error_incorrect_token
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z0-9]{5,12}",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "symbol",
|
||||
name = R.string.login_hint_symbol,
|
||||
icon = CommunityMaterial.Icon2.cmd_school,
|
||||
emptyText = R.string.login_error_no_symbol,
|
||||
invalidText = R.string.login_error_incorrect_symbol,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_SYMBOL to R.string.login_error_incorrect_symbol
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-z0-9_-]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "devicePin",
|
||||
name = R.string.login_hint_pin,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock,
|
||||
emptyText = R.string.login_error_no_pin,
|
||||
invalidText = R.string.login_error_incorrect_pin,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN to R.string.login_error_incorrect_pin
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[0-9]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_EXPIRED_TOKEN to R.string.login_error_expired_token
|
||||
)
|
||||
),*/
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_LIBRUS_JST,
|
||||
name = R.string.login_mode_librus_jst,
|
||||
icon = R.drawable.login_mode_librus_jst,
|
||||
hintText = R.string.login_mode_librus_jst_hint,
|
||||
guideText = R.string.login_mode_librus_jst_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "accountCode",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon.cmd_code_braces,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z0-9_]+",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_VULCAN_WEB,
|
||||
name = R.string.login_mode_vulcan_web,
|
||||
icon = R.drawable.login_mode_vulcan_web,
|
||||
hintText = R.string.login_mode_vulcan_web_hint,
|
||||
guideText = R.string.login_mode_vulcan_web_guide,
|
||||
isDevOnly = true,
|
||||
isPlatformSelection = true,
|
||||
credentials = listOf(
|
||||
getEmailCredential("webEmail"),
|
||||
FormField(
|
||||
keyName = "webUsername",
|
||||
name = R.string.login_hint_username,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_username,
|
||||
invalidText = R.string.login_error_incorrect_username,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z]{7}[0-9]+",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
getPasswordCredential("webPassword")
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
FormField(
|
||||
keyName = "accountPin",
|
||||
name = R.string.login_hint_pin,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock,
|
||||
emptyText = R.string.login_error_no_pin,
|
||||
invalidText = R.string.login_error_incorrect_pin,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-z0-9_]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN to R.string.login_error_incorrect_code_or_pin,
|
||||
ERROR_LOGIN_LIBRUS_API_INVALID_REQUEST to R.string.login_error_incorrect_code_or_pin
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_MOBIDZIENNIK,
|
||||
internalName = "mobidziennik",
|
||||
registerName = R.string.login_type_mobidziennik,
|
||||
registerLogo = R.drawable.login_logo_mobidziennik,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_MOBIDZIENNIK_WEB,
|
||||
name = R.string.login_mode_mobidziennik_web,
|
||||
icon = R.drawable.login_mode_mobidziennik_web,
|
||||
hintText = R.string.login_mode_mobidziennik_web_hint,
|
||||
guideText = R.string.login_mode_mobidziennik_web_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "username",
|
||||
name = R.string.login_hint_login_email,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_login,
|
||||
invalidText = R.string.login_error_incorrect_login,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-@+.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "password",
|
||||
name = R.string.login_hint_password,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_password,
|
||||
invalidText = R.string.login_error_incorrect_login_or_password,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD to R.string.login_error_old_password
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = ".*",
|
||||
hideText = true
|
||||
),
|
||||
FormField(
|
||||
keyName = "serverName",
|
||||
name = R.string.login_hint_address,
|
||||
icon = CommunityMaterial.Icon2.cmd_web,
|
||||
emptyText = R.string.login_error_no_address,
|
||||
invalidText = R.string.login_error_incorrect_address,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_ADDRESS to R.string.login_error_incorrect_address
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-]+\$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_ARCHIVED to R.string.sync_error_archived
|
||||
)
|
||||
loginType = LOGIN_TYPE_VULCAN,
|
||||
internalName = "vulcan",
|
||||
registerName = R.string.login_type_vulcan,
|
||||
registerLogo = R.drawable.login_logo_vulcan,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_VULCAN_HEBE,
|
||||
name = R.string.login_mode_vulcan_api,
|
||||
icon = R.drawable.login_mode_vulcan_hebe,
|
||||
hintText = R.string.login_mode_vulcan_api_hint,
|
||||
guideText = R.string.login_mode_vulcan_api_guide,
|
||||
isRecommended = true,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "deviceToken",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon.cmd_code_braces,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_TOKEN to R.string.login_error_incorrect_token,
|
||||
ERROR_LOGIN_VULCAN_EXPIRED_TOKEN to R.string.login_error_expired_token
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z0-9]{5,12}",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "symbol",
|
||||
name = R.string.login_hint_symbol,
|
||||
icon = CommunityMaterial.Icon2.cmd_school,
|
||||
emptyText = R.string.login_error_no_symbol,
|
||||
invalidText = R.string.login_error_incorrect_symbol,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_SYMBOL to R.string.login_error_incorrect_symbol
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-z0-9_-]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "devicePin",
|
||||
name = R.string.login_hint_pin,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock,
|
||||
emptyText = R.string.login_error_no_pin,
|
||||
invalidText = R.string.login_error_incorrect_pin,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING to R.string.error_310_reason,
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN_1_REMAINING to R.string.error_311_reason,
|
||||
ERROR_LOGIN_VULCAN_INVALID_PIN_2_REMAINING to R.string.error_312_reason
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "[0-9]+",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
),
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_VULCAN_WEB,
|
||||
name = R.string.login_mode_vulcan_web,
|
||||
icon = R.drawable.login_mode_vulcan_web,
|
||||
hintText = R.string.login_mode_vulcan_web_hint,
|
||||
guideText = R.string.login_mode_vulcan_web_guide,
|
||||
isTesting = true,
|
||||
isPlatformSelection = true,
|
||||
credentials = listOf(
|
||||
getEmailCredential("email"),
|
||||
FormField(
|
||||
keyName = "username",
|
||||
name = R.string.login_hint_username,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_username,
|
||||
invalidText = R.string.login_error_incorrect_username,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[A-Z]{7}[0-9]+",
|
||||
caseMode = FormField.CaseMode.UPPER_CASE
|
||||
),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_IDZIENNIK,
|
||||
internalName = "idziennik",
|
||||
registerName = R.string.login_type_idziennik,
|
||||
registerLogo = R.drawable.login_logo_iuczniowie,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_IDZIENNIK_WEB,
|
||||
name = R.string.login_mode_idziennik_web,
|
||||
icon = R.drawable.login_mode_idziennik_web,
|
||||
hintText = R.string.login_mode_idziennik_web_hint,
|
||||
guideText = R.string.login_mode_idziennik_web_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "schoolName",
|
||||
name = R.string.login_hint_school_name,
|
||||
icon = CommunityMaterial.Icon2.cmd_school,
|
||||
emptyText = R.string.login_error_no_school_name,
|
||||
invalidText = R.string.login_error_incorrect_school_name,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME to R.string.login_error_incorrect_school_name
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "username",
|
||||
name = R.string.login_hint_username,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_username,
|
||||
invalidText = R.string.login_error_incorrect_username,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
loginType = LOGIN_TYPE_MOBIDZIENNIK,
|
||||
internalName = "mobidziennik",
|
||||
registerName = R.string.login_type_mobidziennik,
|
||||
registerLogo = R.drawable.login_logo_mobidziennik,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_MOBIDZIENNIK_WEB,
|
||||
name = R.string.login_mode_mobidziennik_web,
|
||||
icon = R.drawable.login_mode_mobidziennik_web,
|
||||
hintText = R.string.login_mode_mobidziennik_web_hint,
|
||||
guideText = R.string.login_mode_mobidziennik_web_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "username",
|
||||
name = R.string.login_hint_login_email,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_login,
|
||||
invalidText = R.string.login_error_incorrect_login,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-@+.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "password",
|
||||
name = R.string.login_hint_password,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_password,
|
||||
invalidText = R.string.login_error_incorrect_login_or_password,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_OLD_PASSWORD to R.string.login_error_old_password
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = ".*",
|
||||
hideText = true
|
||||
),
|
||||
FormField(
|
||||
keyName = "serverName",
|
||||
name = R.string.login_hint_address,
|
||||
icon = CommunityMaterial.Icon2.cmd_web,
|
||||
emptyText = R.string.login_error_no_address,
|
||||
invalidText = R.string.login_error_incorrect_address,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_ADDRESS to R.string.login_error_incorrect_address
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-]+\$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password,
|
||||
ERROR_LOGIN_MOBIDZIENNIK_WEB_ARCHIVED to R.string.sync_error_archived
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_EDUDZIENNIK,
|
||||
internalName = "edudziennik",
|
||||
registerName = R.string.login_type_edudziennik,
|
||||
registerLogo = R.drawable.login_logo_edudziennik,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_EDUDZIENNIK_WEB,
|
||||
name = R.string.login_mode_edudziennik_web,
|
||||
icon = R.drawable.login_mode_edudziennik_web,
|
||||
hintText = R.string.login_mode_edudziennik_web_hint,
|
||||
guideText = R.string.login_mode_edudziennik_web_guide,
|
||||
credentials = listOf(
|
||||
getEmailCredential("email"),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
)
|
||||
loginType = LOGIN_TYPE_IDZIENNIK,
|
||||
internalName = "idziennik",
|
||||
registerName = R.string.login_type_idziennik,
|
||||
registerLogo = R.drawable.login_logo_iuczniowie,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_IDZIENNIK_WEB,
|
||||
name = R.string.login_mode_idziennik_web,
|
||||
icon = R.drawable.login_mode_idziennik_web,
|
||||
hintText = R.string.login_mode_idziennik_web_hint,
|
||||
guideText = R.string.login_mode_idziennik_web_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "schoolName",
|
||||
name = R.string.login_hint_school_name,
|
||||
icon = CommunityMaterial.Icon2.cmd_school,
|
||||
emptyText = R.string.login_error_no_school_name,
|
||||
invalidText = R.string.login_error_incorrect_school_name,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME to R.string.login_error_incorrect_school_name
|
||||
),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
FormField(
|
||||
keyName = "username",
|
||||
name = R.string.login_hint_username,
|
||||
icon = CommunityMaterial.Icon.cmd_account_outline,
|
||||
emptyText = R.string.login_error_no_username,
|
||||
invalidText = R.string.login_error_incorrect_username,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "^[a-z0-9_\\-.]+$",
|
||||
caseMode = FormField.CaseMode.LOWER_CASE
|
||||
),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_PODLASIE,
|
||||
internalName = "podlasie",
|
||||
registerName = R.string.login_type_podlasie,
|
||||
registerLogo = R.drawable.login_logo_podlasie,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_PODLASIE_API,
|
||||
name = R.string.login_mode_podlasie_api,
|
||||
icon = R.drawable.login_mode_podlasie_api,
|
||||
guideText = R.string.login_mode_podlasie_api_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "apiToken",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-zA-Z0-9]{10}",
|
||||
caseMode = FormField.CaseMode.UNCHANGED
|
||||
),
|
||||
FormCheckbox(
|
||||
keyName = "logoutDevices",
|
||||
name = R.string.login_podlasie_logout_devices,
|
||||
checked = false,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT to R.string.error_602_reason
|
||||
)
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
)
|
||||
loginType = LOGIN_TYPE_EDUDZIENNIK,
|
||||
internalName = "edudziennik",
|
||||
registerName = R.string.login_type_edudziennik,
|
||||
registerLogo = R.drawable.login_logo_edudziennik,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_EDUDZIENNIK_WEB,
|
||||
name = R.string.login_mode_edudziennik_web,
|
||||
icon = R.drawable.login_mode_edudziennik_web,
|
||||
hintText = R.string.login_mode_edudziennik_web_hint,
|
||||
guideText = R.string.login_mode_edudziennik_web_guide,
|
||||
credentials = listOf(
|
||||
getEmailCredential("email"),
|
||||
getPasswordCredential("password")
|
||||
),
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN to R.string.login_error_incorrect_login_or_password
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
Register(
|
||||
loginType = LOGIN_TYPE_PODLASIE,
|
||||
internalName = "podlasie",
|
||||
registerName = R.string.login_type_podlasie,
|
||||
registerLogo = R.drawable.login_logo_podlasie,
|
||||
loginModes = listOf(
|
||||
Mode(
|
||||
loginMode = LOGIN_MODE_PODLASIE_API,
|
||||
name = R.string.login_mode_podlasie_api,
|
||||
icon = R.drawable.login_mode_podlasie_api,
|
||||
guideText = R.string.login_mode_podlasie_api_guide,
|
||||
credentials = listOf(
|
||||
FormField(
|
||||
keyName = "apiToken",
|
||||
name = R.string.login_hint_token,
|
||||
icon = CommunityMaterial.Icon2.cmd_lock_outline,
|
||||
emptyText = R.string.login_error_no_token,
|
||||
invalidText = R.string.login_error_incorrect_token,
|
||||
errorCodes = mapOf(),
|
||||
isRequired = true,
|
||||
validationRegex = "[a-zA-Z0-9]{10}",
|
||||
caseMode = FormField.CaseMode.UNCHANGED
|
||||
),
|
||||
FormCheckbox(
|
||||
keyName = "logoutDevices",
|
||||
name = R.string.login_podlasie_logout_devices,
|
||||
checked = false,
|
||||
errorCodes = mapOf(
|
||||
ERROR_LOGIN_PODLASIE_API_DEVICE_LIMIT to R.string.error_602_reason
|
||||
)
|
||||
)
|
||||
),
|
||||
errorCodes = mapOf()
|
||||
)
|
||||
)
|
||||
)
|
||||
) }
|
||||
)
|
||||
}
|
||||
|
||||
data class Register(
|
||||
val loginType: Int,
|
||||
val internalName: String,
|
||||
val registerName: Int,
|
||||
@DrawableRes
|
||||
val registerLogo: Int,
|
||||
val loginType: Int,
|
||||
val internalName: String,
|
||||
val registerName: Int,
|
||||
@DrawableRes
|
||||
val registerLogo: Int,
|
||||
|
||||
val loginModes: List<Mode>
|
||||
val loginModes: List<Mode>
|
||||
) : ExpandableItemModel<Mode>(loginModes.toMutableList()) {
|
||||
override var level = 1
|
||||
}
|
||||
|
||||
data class Mode(
|
||||
val loginMode: Int,
|
||||
val loginMode: Int,
|
||||
|
||||
@StringRes
|
||||
val name: Int,
|
||||
@DrawableRes
|
||||
val icon: Int,
|
||||
@StringRes
|
||||
val hintText: Int? = null,
|
||||
@StringRes
|
||||
val guideText: Int,
|
||||
@StringRes
|
||||
val name: Int,
|
||||
@DrawableRes
|
||||
val icon: Int,
|
||||
@StringRes
|
||||
val hintText: Int? = null,
|
||||
@StringRes
|
||||
val guideText: Int,
|
||||
|
||||
val isRecommended: Boolean = false,
|
||||
val isTesting: Boolean = false,
|
||||
val isDevOnly: Boolean = false,
|
||||
val isPlatformSelection: Boolean = false,
|
||||
val isRecommended: Boolean = false,
|
||||
val isTesting: Boolean = false,
|
||||
val isDevOnly: Boolean = false,
|
||||
val isPlatformSelection: Boolean = false,
|
||||
|
||||
val credentials: List<BaseCredential>,
|
||||
val errorCodes: Map<Int, Int>
|
||||
val credentials: List<BaseCredential>,
|
||||
val errorCodes: Map<Int, Int>
|
||||
)
|
||||
|
||||
data class Platform(
|
||||
val id: Int,
|
||||
val loginType: Int,
|
||||
val loginMode: Int,
|
||||
val name: String,
|
||||
val description: String?,
|
||||
val guideText: String?,
|
||||
val icon: String,
|
||||
val screenshot: String?,
|
||||
val formFields: List<String>,
|
||||
val apiData: JsonObject
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val description: String?,
|
||||
val icon: String,
|
||||
val screenshot: String?,
|
||||
val formFields: List<String>,
|
||||
val realmData: RealmData
|
||||
)
|
||||
|
||||
open class BaseCredential(
|
||||
open val keyName: String,
|
||||
@StringRes
|
||||
open val name: Int,
|
||||
open val errorCodes: Map<Int, Int>
|
||||
open val keyName: String,
|
||||
@StringRes
|
||||
open val name: Int,
|
||||
open val errorCodes: Map<Int, Int>
|
||||
)
|
||||
|
||||
data class FormField(
|
||||
override val keyName: String,
|
||||
override val keyName: String,
|
||||
|
||||
@StringRes
|
||||
override val name: Int,
|
||||
val icon: IIcon,
|
||||
@StringRes
|
||||
val placeholder: Int? = null,
|
||||
@StringRes
|
||||
val emptyText: Int,
|
||||
@StringRes
|
||||
val invalidText: Int,
|
||||
override val errorCodes: Map<Int, Int>,
|
||||
@StringRes
|
||||
val hintText: Int? = null,
|
||||
@StringRes
|
||||
override val name: Int,
|
||||
val icon: IIcon,
|
||||
@StringRes
|
||||
val placeholder: Int? = null,
|
||||
@StringRes
|
||||
val emptyText: Int,
|
||||
@StringRes
|
||||
val invalidText: Int,
|
||||
override val errorCodes: Map<Int, Int>,
|
||||
@StringRes
|
||||
val hintText: Int? = null,
|
||||
|
||||
val isRequired: Boolean = true,
|
||||
val validationRegex: String,
|
||||
val caseMode: CaseMode = CaseMode.UNCHANGED,
|
||||
val hideText: Boolean = false,
|
||||
val stripTextRegex: String? = null
|
||||
val isRequired: Boolean = true,
|
||||
val validationRegex: String,
|
||||
val caseMode: CaseMode = CaseMode.UNCHANGED,
|
||||
val hideText: Boolean = false,
|
||||
val stripTextRegex: String? = null
|
||||
) : BaseCredential(keyName, name, errorCodes) {
|
||||
enum class CaseMode { UNCHANGED, UPPER_CASE, LOWER_CASE }
|
||||
}
|
||||
|
||||
data class FormCheckbox(
|
||||
override val keyName: String,
|
||||
@StringRes
|
||||
override val name: Int,
|
||||
val checked: Boolean = false,
|
||||
override val errorCodes: Map<Int, Int> = mapOf()
|
||||
override val keyName: String,
|
||||
@StringRes
|
||||
override val name: Int,
|
||||
val checked: Boolean = false,
|
||||
override val errorCodes: Map<Int, Int> = mapOf()
|
||||
) : BaseCredential(keyName, name, errorCodes)
|
||||
|
||||
var chooserList: MutableList<Any>? = null
|
||||
|
@ -60,12 +60,12 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
||||
|
||||
adapter = LoginPlatformAdapter(activity) { platform ->
|
||||
nav.navigate(R.id.loginFormFragment, Bundle(
|
||||
"loginType" to platform.loginType,
|
||||
"loginMode" to platform.loginMode,
|
||||
"loginType" to loginType,
|
||||
"loginMode" to loginMode,
|
||||
"platformName" to platform.name,
|
||||
"platformDescription" to platform.description,
|
||||
"platformFormFields" to platform.formFields.joinToString(";"),
|
||||
"platformApiData" to platform.apiData.toString()
|
||||
"platformRealmData" to app.gson.toJson(platform.realmData)
|
||||
), activity.navOptions)
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
|
||||
val platforms = LoginInfo.platformList[mode.name]
|
||||
?: run {
|
||||
api.runCatching(activity) {
|
||||
getPlatforms(register.internalName)
|
||||
getRealms(register.internalName)
|
||||
} ?: run {
|
||||
nav.navigateUp()
|
||||
return@launch
|
||||
|
@ -258,7 +258,7 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
||||
.color(IconicsColor.colorInt(iconColor))
|
||||
)
|
||||
.setOnClickAction(() -> {
|
||||
new ProfileRemoveDialog(activity, app.getProfile().getId(), app.getProfile().getName());
|
||||
new ProfileRemoveDialog(activity, app.getProfile().getId(), app.getProfile().getName(), false);
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -121,19 +121,21 @@ class AttachmentsView @JvmOverloads constructor(
|
||||
// open file by name, or first part before ':' (Vulcan OneDrive)
|
||||
Utils.openFile(context, File(Utils.getStorageDir(), attachment.name.substringBefore(":")))
|
||||
return
|
||||
}
|
||||
} else if (attachment.name.contains(":")) {
|
||||
Utils.openUrl(context, attachment.name.substringAfter(":"))
|
||||
} else {
|
||||
attachment.isDownloading = true
|
||||
(adapter as? AttachmentAdapter)?.let {
|
||||
it.notifyItemChanged(it.items.indexOf(attachment))
|
||||
}
|
||||
|
||||
attachment.isDownloading = true
|
||||
(adapter as? AttachmentAdapter)?.let {
|
||||
it.notifyItemChanged(it.items.indexOf(attachment))
|
||||
}
|
||||
|
||||
EdziennikTask.attachmentGet(
|
||||
EdziennikTask.attachmentGet(
|
||||
attachment.profileId,
|
||||
attachment.owner,
|
||||
attachment.id,
|
||||
attachment.name
|
||||
).enqueue(context)
|
||||
).enqueue(context)
|
||||
}
|
||||
}
|
||||
|
||||
private val lastUpdate: Long = 0
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.3 KiB |
@ -45,6 +45,22 @@
|
||||
android:text="Set last 10 as unseen"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/fullSync"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="Full sync and empty profile"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/clearProfile"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:text="Clear all profile data"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/rodo"
|
||||
android:layout_width="match_parent"
|
||||
@ -70,6 +86,7 @@
|
||||
android:id="@+id/unarchive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="Unarchive this profile"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
|
@ -30,11 +30,12 @@
|
||||
tools:text="lessonRanges" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:fontFamily="monospace"
|
||||
android:text="JsonObject"
|
||||
android:text="Object"
|
||||
android:textAppearance="@style/NavView.TextView.Helper" />
|
||||
|
||||
<com.mikepenz.iconics.view.IconicsImageView
|
||||
|
48
app/src/main/res/layout/lab_item_sub_object.xml
Normal file
48
app/src/main/res/layout/lab_item_sub_object.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) Kuba Szczodrzyński 2021-2-26.
|
||||
-->
|
||||
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/key"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="monospace"
|
||||
android:maxLines="2"
|
||||
tools:text="lessonRanges" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:fontFamily="monospace"
|
||||
android:text="Object"
|
||||
android:textAppearance="@style/NavView.TextView.Helper" />
|
||||
|
||||
<com.mikepenz.iconics.view.IconicsImageView
|
||||
android:id="@+id/dropdownIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:scaleType="centerInside"
|
||||
app:iiv_color="?android:textColorSecondary"
|
||||
app:iiv_icon="cmd-chevron-down"
|
||||
app:iiv_size="18dp"
|
||||
tools:src="@android:drawable/ic_menu_more" />
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -118,18 +118,29 @@
|
||||
|
||||
<string name="error_301" translatable="false">ERROR_LOGIN_VULCAN_INVALID_SYMBOL</string>
|
||||
<string name="error_302" translatable="false">ERROR_LOGIN_VULCAN_INVALID_TOKEN</string>
|
||||
<string name="error_309" translatable="false">ERROR_LOGIN_VULCAN_INVALID_PIN</string>
|
||||
<string name="error_310" translatable="false">ERROR_LOGIN_VULCAN_INVALID_PIN_0_REMAINING</string>
|
||||
<string name="error_311" translatable="false">ERROR_LOGIN_VULCAN_INVALID_PIN_1_REMAINING</string>
|
||||
<string name="error_312" translatable="false">ERROR_LOGIN_VULCAN_INVALID_PIN_2_REMAINING</string>
|
||||
<string name="error_321" translatable="false">ERROR_LOGIN_VULCAN_EXPIRED_TOKEN</string>
|
||||
<string name="error_322" translatable="false">ERROR_LOGIN_VULCAN_OTHER</string>
|
||||
<string name="error_330" translatable="false">ERROR_LOGIN_VULCAN_ONLY_KINDERGARTEN</string>
|
||||
<string name="error_331" translatable="false">ERROR_LOGIN_VULCAN_NO_PUPILS</string>
|
||||
<string name="error_340" translatable="false">ERROR_VULCAN_API_MAINTENANCE</string>
|
||||
<string name="error_341" translatable="false">ERROR_VULCAN_API_BAD_REQUEST</string>
|
||||
<string name="error_342" translatable="false">ERROR_VULCAN_API_OTHER</string>
|
||||
<string name="error_343" translatable="false">ERROR_VULCAN_ATTACHMENT_DOWNLOAD</string>
|
||||
<string name="error_344" translatable="false">ERROR_VULCAN_WEB_DATA_MISSING</string>
|
||||
<string name="error_345" translatable="false">ERROR_VULCAN_WEB_429</string>
|
||||
<string name="error_346" translatable="false">ERROR_VULCAN_WEB_OTHER</string>
|
||||
<string name="error_347" translatable="false">ERROR_VULCAN_WEB_NO_CERTIFICATE</string>
|
||||
<string name="error_348" translatable="false">ERROR_VULCAN_WEB_NO_REGISTER</string>
|
||||
<string name="error_349" translatable="false">ERROR_VULCAN_WEB_CERTIFICATE_EXPIRED</string>
|
||||
<string name="error_350" translatable="false">ERROR_VULCAN_WEB_LOGGED_OUT</string>
|
||||
<string name="error_351" translatable="false">ERROR_VULCAN_WEB_CERTIFICATE_POST_FAILED</string>
|
||||
<string name="error_352" translatable="false">ERROR_VULCAN_WEB_GRADUATE_ACCOUNT</string>
|
||||
<string name="error_353" translatable="false">ERROR_VULCAN_WEB_NO_SCHOOLS</string>
|
||||
<string name="error_354" translatable="false">ERROR_VULCAN_HEBE_OTHER</string>
|
||||
<string name="error_360" translatable="false">ERROR_VULCAN_HEBE_SIGNATURE_ERROR</string>
|
||||
<string name="error_361" translatable="false">ERROR_VULCAN_HEBE_INVALID_PAYLOAD</string>
|
||||
<string name="error_362" translatable="false">ERROR_VULCAN_HEBE_FIREBASE_ERROR</string>
|
||||
<string name="error_363" translatable="false">ERROR_VULCAN_HEBE_CERTIFICATE_GONE</string>
|
||||
<string name="error_364" translatable="false">ERROR_VULCAN_HEBE_SERVER_ERROR</string>
|
||||
<string name="error_365" translatable="false">ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND</string>
|
||||
<string name="error_390" translatable="false">ERROR_VULCAN_API_DEPRECATED</string>
|
||||
|
||||
<string name="error_401" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN</string>
|
||||
@ -176,7 +187,6 @@
|
||||
<string name="error_904" translatable="false">EXCEPTION_LIBRUS_API_REQUEST</string>
|
||||
<string name="error_905" translatable="false">EXCEPTION_LIBRUS_SYNERGIA_REQUEST</string>
|
||||
<string name="error_906" translatable="false">EXCEPTION_MOBIDZIENNIK_WEB_REQUEST</string>
|
||||
<string name="error_907" translatable="false">EXCEPTION_VULCAN_API_REQUEST</string>
|
||||
<string name="error_908" translatable="false">EXCEPTION_MOBIDZIENNIK_WEB_FILE_REQUEST</string>
|
||||
<string name="error_909" translatable="false">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
||||
<string name="error_910" translatable="false">EXCEPTION_NOTIFY</string>
|
||||
@ -307,18 +317,29 @@
|
||||
|
||||
<string name="error_301_reason">Nieprawidłowy symbol</string>
|
||||
<string name="error_302_reason">Nieprawidłowy token</string>
|
||||
<string name="error_309_reason">Nieprawidłowy PIN</string>
|
||||
<string name="error_310_reason">Nieprawidłowy PIN: pozostało 0 prób</string>
|
||||
<string name="error_310_reason">Nieprawidłowy PIN. Wygeneruj nowy token.</string>
|
||||
<string name="error_311_reason">Nieprawidłowy PIN: pozostała 1 próba</string>
|
||||
<string name="error_312_reason">Nieprawidłowy PIN: pozostały 2 próby</string>
|
||||
<string name="error_321_reason">Token wygasły, wygeneruj ponownie</string>
|
||||
<string name="error_322_reason">Inny błąd logowania do dziennika VULCAN®</string>
|
||||
<string name="error_330_reason">Dziennik przedszkolny - logowanie niemożliwe</string>
|
||||
<string name="error_331_reason">Brak uczniów przypisanych do konta, bądź ukończyli oni już szkołę</string>
|
||||
<string name="error_340_reason">VULCAN®: przerwa techniczna</string>
|
||||
<string name="error_341_reason">VULCAN®: błąd żądania, zgłoś błąd</string>
|
||||
<string name="error_342_reason">VULCAN®: inny błąd, wyślij zgłoszenie</string>
|
||||
<string name="error_343_reason">VULCAN®: nie znaleziono adresu załącznika</string>
|
||||
<string name="error_344_reason">VULCAN®: brakujące dane logowania FS. Usuń profil i zaloguj się ponownie.</string>
|
||||
<string name="error_345_reason">VULCAN®: błąd logowania (429). Dziennik może być przeciążony.</string>
|
||||
<string name="error_346_reason">VULCAN®: inny błąd logowania</string>
|
||||
<string name="error_347_reason">VULCAN®: nie znaleziono zapisanego certyfikatu</string>
|
||||
<string name="error_348_reason">VULCAN®: konto nie jest przypisane do żadnej szkoły</string>
|
||||
<string name="error_349_reason">VULCAN®: certyfikat logowania wygasł</string>
|
||||
<string name="error_350_reason">VULCAN®: wylogowano z konta</string>
|
||||
<string name="error_351_reason">VULCAN®: nie udało się wysłać certyfikatu</string>
|
||||
<string name="error_352_reason">VULCAN®: konto nie posiada już uczniów uczęszczających do szkoły</string>
|
||||
<string name="error_353_reason">VULCAN®: nie znaleziono żadnej szkoły. Zgłoś błąd.</string>
|
||||
<string name="error_354_reason">VULCAN®: nieznany błąd pobierania danych</string>
|
||||
<string name="error_360_reason">Nieprawidłowy podpis zapytania. Sprawdź ustawienia daty i godziny w systemie.</string>
|
||||
<string name="error_361_reason">VULCAN®: zapytanie zawiera niepoprawne dane</string>
|
||||
<string name="error_362_reason">Błąd powiadomień push. Sprawdź połączenie z internetem.</string>
|
||||
<string name="error_363_reason">VULCAN®: urządzenie usunięte. Zaloguj się ponownie do dziennika.</string>
|
||||
<string name="error_364_reason">VULCAN®: błąd serwera. Dziennik może być przeciążony.</string>
|
||||
<string name="error_365_reason">VULCAN®: nie znaleziono bytu</string>
|
||||
<string name="error_390_reason">W związku z wygaszeniem aplikacji Dzienniczek+ przez firmę Vulcan, należy zalogować się ponownie.\n\nAby móc dalej korzystać z aplikacji Szkolny.eu, otwórz Ustawienia i wybierz opcję Dodaj nowego ucznia.\nNastępnie zaloguj się do dziennika Vulcan zgodnie z instrukcją.\n\nPrzepraszamy za niedogodności.</string>
|
||||
|
||||
<string name="error_401_reason">Nieprawidłowe dane logowania</string>
|
||||
@ -365,7 +386,6 @@
|
||||
<string name="error_904_reason">Zgłoś błąd: wyjątek w API LIBRUS®</string>
|
||||
<string name="error_905_reason">EXCEPTION_LIBRUS_SYNERGIA_REQUEST</string>
|
||||
<string name="error_906_reason">EXCEPTION_MOBIDZIENNIK_WEB_REQUEST</string>
|
||||
<string name="error_907_reason">EXCEPTION_VULCAN_API_REQUEST</string>
|
||||
<string name="error_908_reason">EXCEPTION_MOBIDZIENNIK_WEB_FILE_REQUEST</string>
|
||||
<string name="error_909_reason">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
||||
<string name="error_910_reason">EXCEPTION_NOTIFY</string>
|
||||
|
@ -5,8 +5,8 @@ buildscript {
|
||||
kotlin_version = '1.4.30'
|
||||
|
||||
release = [
|
||||
versionName: "4.5",
|
||||
versionCode: 4050099
|
||||
versionName: "4.6-beta.1",
|
||||
versionCode: 4060001
|
||||
]
|
||||
|
||||
setup = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user