mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[Idziennik] Remove iDziennik implementation [*]
This commit is contained in:
parent
22abad35cc
commit
256f6c8732
@ -173,28 +173,6 @@ const val ERROR_VULCAN_HEBE_SERVER_ERROR = 364
|
|||||||
const val ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND = 365
|
const val ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND = 365
|
||||||
const val ERROR_VULCAN_API_DEPRECATED = 390
|
const val ERROR_VULCAN_API_DEPRECATED = 390
|
||||||
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN = 401
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME = 402
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED = 403
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_MAINTENANCE = 404
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_SERVER_ERROR = 405
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_OTHER = 410
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_API_NO_ACCESS = 411 /* {"d":{"__type":"mds.Web.mod_komunikator.WS_mod_wiadomosci+detailWiadomosci","Wiadomosc":{"_recordId":0,"DataNadania":null,"DataOdczytania":null,"Nadawca":null,"ListaOdbiorcow":[],"Tytul":null,"Text":null,"ListaZal":[]},"Bledy":{"__type":"mds.Module.Globalne+sBledy","CzyJestBlad":true,"ListaBledow":["Nie masz dostępu do tych zasobów!"],"ListaKodowBledow":[]},"czyJestWiecej":false}} */
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_NO_SESSION = 420
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_NO_AUTH = 421
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_WEB_NO_BEARER = 422
|
|
||||||
const val ERROR_IDZIENNIK_WEB_ACCESS_DENIED = 430
|
|
||||||
const val ERROR_IDZIENNIK_WEB_OTHER = 431
|
|
||||||
const val ERROR_IDZIENNIK_WEB_MAINTENANCE = 432
|
|
||||||
const val ERROR_IDZIENNIK_WEB_SERVER_ERROR = 433
|
|
||||||
const val ERROR_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED = 434
|
|
||||||
const val ERROR_LOGIN_IDZIENNIK_FIRST_NO_SCHOOL_YEAR = 440
|
|
||||||
const val ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA = 441
|
|
||||||
const val ERROR_IDZIENNIK_API_ACCESS_DENIED = 450
|
|
||||||
const val ERROR_IDZIENNIK_API_OTHER = 451
|
|
||||||
const val ERROR_IDZIENNIK_API_NO_REGISTER = 452
|
|
||||||
const val ERROR_IDZIENNIK_WEB_RECIPIENT_LIST_NO_PERMISSION = 453
|
|
||||||
|
|
||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN = 501
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN = 501
|
||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER = 510
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER = 510
|
||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
||||||
@ -221,9 +199,6 @@ const val EXCEPTION_MOBIDZIENNIK_WEB_FILE_REQUEST = 908
|
|||||||
const val EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST = 909
|
const val EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST = 909
|
||||||
const val EXCEPTION_NOTIFY = 910
|
const val EXCEPTION_NOTIFY = 910
|
||||||
const val EXCEPTION_LIBRUS_MESSAGES_REQUEST = 911
|
const val EXCEPTION_LIBRUS_MESSAGES_REQUEST = 911
|
||||||
const val EXCEPTION_IDZIENNIK_WEB_REQUEST = 912
|
|
||||||
const val EXCEPTION_IDZIENNIK_WEB_API_REQUEST = 913
|
|
||||||
const val EXCEPTION_IDZIENNIK_API_REQUEST = 914
|
|
||||||
const val EXCEPTION_EDUDZIENNIK_WEB_REQUEST = 920
|
const val EXCEPTION_EDUDZIENNIK_WEB_REQUEST = 920
|
||||||
const val EXCEPTION_EDUDZIENNIK_FILE_REQUEST = 921
|
const val EXCEPTION_EDUDZIENNIK_FILE_REQUEST = 921
|
||||||
const val ERROR_ONEDRIVE_DOWNLOAD = 930
|
const val ERROR_ONEDRIVE_DOWNLOAD = 930
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api
|
package pl.szczodrzynski.edziennik.data.api
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLoginApi
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLoginWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginApi
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginApi
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginMessages
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginMessages
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginPortal
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginPortal
|
||||||
@ -22,7 +20,7 @@ import pl.szczodrzynski.edziennik.data.api.models.LoginMethod
|
|||||||
|
|
||||||
// librus
|
// librus
|
||||||
// mobidziennik
|
// mobidziennik
|
||||||
// idziennik
|
// idziennik [*]
|
||||||
// vulcan
|
// vulcan
|
||||||
// mobireg
|
// mobireg
|
||||||
|
|
||||||
@ -34,14 +32,10 @@ const val LOGIN_TYPE_IDZIENNIK = 3
|
|||||||
const val LOGIN_TYPE_TEMPLATE = 21
|
const val LOGIN_TYPE_TEMPLATE = 21
|
||||||
|
|
||||||
// LOGIN MODES
|
// LOGIN MODES
|
||||||
const val LOGIN_MODE_IDZIENNIK_WEB = 0
|
|
||||||
|
|
||||||
const val LOGIN_MODE_TEMPLATE_WEB = 0
|
const val LOGIN_MODE_TEMPLATE_WEB = 0
|
||||||
|
|
||||||
// LOGIN METHODS
|
// LOGIN METHODS
|
||||||
const val LOGIN_METHOD_NOT_NEEDED = -1
|
const val LOGIN_METHOD_NOT_NEEDED = -1
|
||||||
const val LOGIN_METHOD_IDZIENNIK_WEB = 100
|
|
||||||
const val LOGIN_METHOD_IDZIENNIK_API = 200
|
|
||||||
const val LOGIN_METHOD_TEMPLATE_WEB = 100
|
const val LOGIN_METHOD_TEMPLATE_WEB = 100
|
||||||
const val LOGIN_METHOD_TEMPLATE_API = 200
|
const val LOGIN_METHOD_TEMPLATE_API = 200
|
||||||
|
|
||||||
@ -124,16 +118,6 @@ val vulcanLoginMethods = listOf(
|
|||||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||||
)
|
)
|
||||||
|
|
||||||
val idziennikLoginMethods = listOf(
|
|
||||||
LoginMethod(LOGIN_TYPE_IDZIENNIK, LOGIN_METHOD_IDZIENNIK_WEB, IdziennikLoginWeb::class.java)
|
|
||||||
.withIsPossible { _, _ -> true }
|
|
||||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED },
|
|
||||||
|
|
||||||
LoginMethod(LOGIN_TYPE_IDZIENNIK, LOGIN_METHOD_IDZIENNIK_API, IdziennikLoginApi::class.java)
|
|
||||||
.withIsPossible { _, _ -> true }
|
|
||||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_IDZIENNIK_WEB }
|
|
||||||
)
|
|
||||||
|
|
||||||
const val LOGIN_TYPE_EDUDZIENNIK = 5
|
const val LOGIN_TYPE_EDUDZIENNIK = 5
|
||||||
const val LOGIN_MODE_EDUDZIENNIK_WEB = 0
|
const val LOGIN_MODE_EDUDZIENNIK_WEB = 0
|
||||||
const val LOGIN_METHOD_EDUDZIENNIK_WEB = 100
|
const val LOGIN_METHOD_EDUDZIENNIK_WEB = 100
|
||||||
|
@ -9,7 +9,6 @@ import org.greenrobot.eventbus.EventBus
|
|||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.Edudziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.Edudziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.Idziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.Librus
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.Librus
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.Mobidziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.Mobidziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.Podlasie
|
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.Podlasie
|
||||||
@ -123,7 +122,6 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
LOGIN_TYPE_LIBRUS -> Librus(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_LIBRUS -> Librus(app, profile, loginStore, taskCallback)
|
||||||
LOGIN_TYPE_MOBIDZIENNIK -> Mobidziennik(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_MOBIDZIENNIK -> Mobidziennik(app, profile, loginStore, taskCallback)
|
||||||
LOGIN_TYPE_VULCAN -> Vulcan(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_VULCAN -> Vulcan(app, profile, loginStore, taskCallback)
|
||||||
LOGIN_TYPE_IDZIENNIK -> Idziennik(app, profile, loginStore, taskCallback)
|
|
||||||
LOGIN_TYPE_EDUDZIENNIK -> Edudziennik(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_EDUDZIENNIK -> Edudziennik(app, profile, loginStore, taskCallback)
|
||||||
LOGIN_TYPE_PODLASIE -> Podlasie(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_PODLASIE -> Podlasie(app, profile, loginStore, taskCallback)
|
||||||
LOGIN_TYPE_TEMPLATE -> Template(app, profile, loginStore, taskCallback)
|
LOGIN_TYPE_TEMPLATE -> Template(app, profile, loginStore, taskCallback)
|
||||||
|
@ -1,175 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik
|
|
||||||
|
|
||||||
import androidx.core.util.set
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
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.Subject
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
|
||||||
|
|
||||||
class DataIdziennik(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
|
||||||
|
|
||||||
fun isWebLoginValid() = loginExpiryTime-30 > currentTimeUnix() && webSessionId.isNotNullNorEmpty() && webAuth.isNotNullNorEmpty()
|
|
||||||
fun isApiLoginValid() = apiExpiryTime-30 > currentTimeUnix() && apiBearer.isNotNullNorEmpty()
|
|
||||||
|
|
||||||
override fun satisfyLoginMethods() {
|
|
||||||
loginMethods.clear()
|
|
||||||
if (isWebLoginValid()) {
|
|
||||||
loginMethods += LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
app.cookieJar.set("iuczniowie.progman.pl", "ASP.NET_SessionId_iDziennik", webSessionId)
|
|
||||||
app.cookieJar.set("iuczniowie.progman.pl", ".ASPXAUTH", webAuth)
|
|
||||||
}
|
|
||||||
if (isApiLoginValid())
|
|
||||||
loginMethods += LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun generateUserCode() = "$webSchoolName:$webUsername:$registerId"
|
|
||||||
|
|
||||||
private var mLoginExpiryTime: Long? = null
|
|
||||||
var loginExpiryTime: Long
|
|
||||||
get() { mLoginExpiryTime = mLoginExpiryTime ?: loginStore.getLoginData("loginExpiryTime", 0L); return mLoginExpiryTime ?: 0L }
|
|
||||||
set(value) { loginStore.putLoginData("loginExpiryTime", value); mLoginExpiryTime = value }
|
|
||||||
|
|
||||||
private var mApiExpiryTime: Long? = null
|
|
||||||
var apiExpiryTime: Long
|
|
||||||
get() { mApiExpiryTime = mApiExpiryTime ?: loginStore.getLoginData("apiExpiryTime", 0L); return mApiExpiryTime ?: 0L }
|
|
||||||
set(value) { loginStore.putLoginData("apiExpiryTime", value); mApiExpiryTime = value }
|
|
||||||
|
|
||||||
/* __ __ _
|
|
||||||
\ \ / / | |
|
|
||||||
\ \ /\ / /__| |__
|
|
||||||
\ \/ \/ / _ \ '_ \
|
|
||||||
\ /\ / __/ |_) |
|
|
||||||
\/ \/ \___|_._*/
|
|
||||||
private var mWebSchoolName: String? = null
|
|
||||||
var webSchoolName: String?
|
|
||||||
get() { mWebSchoolName = mWebSchoolName ?: loginStore.getLoginData("schoolName", null); return mWebSchoolName }
|
|
||||||
set(value) { loginStore.putLoginData("schoolName", value); mWebSchoolName = value }
|
|
||||||
private var mWebUsername: String? = null
|
|
||||||
var webUsername: String?
|
|
||||||
get() { mWebUsername = mWebUsername ?: loginStore.getLoginData("username", null); return mWebUsername }
|
|
||||||
set(value) { loginStore.putLoginData("username", value); mWebUsername = value }
|
|
||||||
private var mWebPassword: String? = null
|
|
||||||
var webPassword: String?
|
|
||||||
get() { mWebPassword = mWebPassword ?: loginStore.getLoginData("password", null); return mWebPassword }
|
|
||||||
set(value) { loginStore.putLoginData("password", value); mWebPassword = value }
|
|
||||||
|
|
||||||
private var mWebSessionId: String? = null
|
|
||||||
var webSessionId: String?
|
|
||||||
get() { mWebSessionId = mWebSessionId ?: loginStore.getLoginData("webSessionId", null); return mWebSessionId }
|
|
||||||
set(value) { loginStore.putLoginData("webSessionId", value); mWebSessionId = value }
|
|
||||||
private var mWebAuth: String? = null
|
|
||||||
var webAuth: String?
|
|
||||||
get() { mWebAuth = mWebAuth ?: loginStore.getLoginData("webAuth", null); return mWebAuth }
|
|
||||||
set(value) { loginStore.putLoginData("webAuth", value); mWebAuth = value }
|
|
||||||
|
|
||||||
private var mWebSelectedRegister: Int? = null
|
|
||||||
var webSelectedRegister: Int
|
|
||||||
get() { mWebSelectedRegister = mWebSelectedRegister ?: loginStore.getLoginData("webSelectedRegister", 0); return mWebSelectedRegister ?: 0 }
|
|
||||||
set(value) { loginStore.putLoginData("webSelectedRegister", value); mWebSelectedRegister = value }
|
|
||||||
|
|
||||||
/* _
|
|
||||||
/\ (_)
|
|
||||||
/ \ _ __ _
|
|
||||||
/ /\ \ | '_ \| |
|
|
||||||
/ ____ \| |_) | |
|
|
||||||
/_/ \_\ .__/|_|
|
|
||||||
| |
|
|
||||||
|*/
|
|
||||||
private var mApiBearer: String? = null
|
|
||||||
var apiBearer: String?
|
|
||||||
get() { mApiBearer = mApiBearer ?: loginStore.getLoginData("apiBearer", null); return mApiBearer }
|
|
||||||
set(value) { loginStore.putLoginData("apiBearer", value); mApiBearer = value }
|
|
||||||
|
|
||||||
/* ____ _ _
|
|
||||||
/ __ \| | | |
|
|
||||||
| | | | |_| |__ ___ _ __
|
|
||||||
| | | | __| '_ \ / _ \ '__|
|
|
||||||
| |__| | |_| | | | __/ |
|
|
||||||
\____/ \__|_| |_|\___|*/
|
|
||||||
private var mStudentId: String? = null
|
|
||||||
var studentId: String?
|
|
||||||
get() { mStudentId = mStudentId ?: profile?.getStudentData("studentId", null); return mStudentId }
|
|
||||||
set(value) { profile?.putStudentData("studentId", value) ?: return; mStudentId = value }
|
|
||||||
|
|
||||||
private var mRegisterId: Int? = null
|
|
||||||
var registerId: Int
|
|
||||||
get() { mRegisterId = mRegisterId ?: profile?.getStudentData("registerId", 0); return mRegisterId ?: 0 }
|
|
||||||
set(value) { profile?.putStudentData("registerId", value) ?: return; mRegisterId = value }
|
|
||||||
|
|
||||||
private var mSchoolYearId: Int? = null
|
|
||||||
var schoolYearId: Int
|
|
||||||
get() { mSchoolYearId = mSchoolYearId ?: profile?.getStudentData("schoolYearId", 0); return mSchoolYearId ?: 0 }
|
|
||||||
set(value) { profile?.putStudentData("schoolYearId", value) ?: return; mSchoolYearId = value }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* _ _ _ _ _
|
|
||||||
| | | | | (_) |
|
|
||||||
| | | | |_ _| |___
|
|
||||||
| | | | __| | / __|
|
|
||||||
| |__| | |_| | \__ \
|
|
||||||
\____/ \__|_|_|__*/
|
|
||||||
fun getSubject(name: String, id: Long?, shortName: String): Subject {
|
|
||||||
var subject = if (id == null)
|
|
||||||
subjectList.singleOrNull { it.longName == name }
|
|
||||||
else
|
|
||||||
subjectList.singleOrNull { it.id == id }
|
|
||||||
|
|
||||||
if (subject == null) {
|
|
||||||
subject = Subject(profileId, id
|
|
||||||
?: name.crc16().toLong(), name, shortName)
|
|
||||||
subjectList[subject.id] = subject
|
|
||||||
}
|
|
||||||
return subject
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacher(firstName: String, lastName: String): Teacher {
|
|
||||||
val teacher = teacherList.singleOrNull { it.fullName == "$firstName $lastName" }
|
|
||||||
return validateTeacher(teacher, firstName, lastName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacher(firstNameChar: Char, lastName: String): Teacher {
|
|
||||||
val teacher = teacherList.singleOrNull { it.shortName == "$firstNameChar.$lastName" }
|
|
||||||
return validateTeacher(teacher, firstNameChar.toString(), lastName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacherByLastFirst(nameLastFirst: String): Teacher {
|
|
||||||
val nameParts = nameLastFirst.split(" ")
|
|
||||||
return if (nameParts.size == 1) getTeacher(nameParts[0], "") else getTeacher(nameParts[1], nameParts[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacherByFirstLast(nameFirstLast: String): Teacher {
|
|
||||||
val nameParts = nameFirstLast.split(" ")
|
|
||||||
return if (nameParts.size == 1) getTeacher(nameParts[0], "") else getTeacher(nameParts[0], nameParts[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacherByFDotLast(nameFDotLast: String): Teacher {
|
|
||||||
val nameParts = nameFDotLast.split(".")
|
|
||||||
return if (nameParts.size == 1) getTeacher(nameParts[0], "") else getTeacher(nameParts[0][0], nameParts[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTeacherByFDotSpaceLast(nameFDotSpaceLast: String): Teacher {
|
|
||||||
val nameParts = nameFDotSpaceLast.split(".")
|
|
||||||
return if (nameParts.size == 1) getTeacher(nameParts[0], "") else getTeacher(nameParts[0][0], nameParts[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun validateTeacher(teacher: Teacher?, firstName: String, lastName: String): Teacher {
|
|
||||||
(teacher ?: Teacher(profileId, -1, firstName, lastName).apply {
|
|
||||||
id = shortName.crc16().toLong()
|
|
||||||
teacherList[id] = this
|
|
||||||
}).apply {
|
|
||||||
if (firstName.length > 1)
|
|
||||||
name = firstName
|
|
||||||
surname = lastName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.App
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikData
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.firstlogin.IdziennikFirstLogin
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLogin
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
|
||||||
|
|
||||||
class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore, val callback: EdziennikCallback) : EdziennikInterface {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "Idziennik"
|
|
||||||
}
|
|
||||||
|
|
||||||
val internalErrorList = mutableListOf<Int>()
|
|
||||||
val data: DataIdziennik
|
|
||||||
private var afterLogin: (() -> Unit)? = null
|
|
||||||
|
|
||||||
init {
|
|
||||||
data = DataIdziennik(app, profile, loginStore).apply {
|
|
||||||
callback = wrapCallback(this@Idziennik.callback)
|
|
||||||
satisfyLoginMethods()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun completed() {
|
|
||||||
data.saveData()
|
|
||||||
callback.onCompleted()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* _______ _ _ _ _ _
|
|
||||||
|__ __| | /\ | | (_) | | |
|
|
||||||
| | | |__ ___ / \ | | __ _ ___ _ __ _| |_| |__ _ __ ___
|
|
||||||
| | | '_ \ / _ \ / /\ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \
|
|
||||||
| | | | | | __/ / ____ \| | (_| | (_) | | | | |_| | | | | | | | |
|
|
||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|
||||||
__/ |
|
|
||||||
|__*/
|
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
|
||||||
data.arguments = arguments
|
|
||||||
data.prepare(idziennikLoginMethods, IdziennikFeatures, featureIds, viewId, onlyEndpoints)
|
|
||||||
login()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun login(loginMethodId: Int? = null, afterLogin: (() -> Unit)? = null) {
|
|
||||||
d(TAG, "Trying to login with ${data.targetLoginMethodIds}")
|
|
||||||
if (internalErrorList.isNotEmpty()) {
|
|
||||||
d(TAG, " - Internal errors:")
|
|
||||||
internalErrorList.forEach { d(TAG, " - code $it") }
|
|
||||||
}
|
|
||||||
loginMethodId?.let { data.prepareFor(idziennikLoginMethods, it) }
|
|
||||||
afterLogin?.let { this.afterLogin = it }
|
|
||||||
IdziennikLogin(data) {
|
|
||||||
data()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun data() {
|
|
||||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
|
||||||
if (internalErrorList.isNotEmpty()) {
|
|
||||||
d(TAG, " - Internal errors:")
|
|
||||||
internalErrorList.forEach { d(TAG, " - code $it") }
|
|
||||||
}
|
|
||||||
afterLogin?.invoke() ?: IdziennikData(data) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getMessage(message: MessageFull) {
|
|
||||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
|
||||||
IdziennikWebGetMessage(data, message) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sendMessage(recipients: List<Teacher>, subject: String, text: String) {
|
|
||||||
login(LOGIN_METHOD_IDZIENNIK_API) {
|
|
||||||
IdziennikWebSendMessage(data, recipients, subject, text) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun markAllAnnouncementsAsRead() {}
|
|
||||||
override fun getAnnouncement(announcement: AnnouncementFull) {}
|
|
||||||
|
|
||||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
|
||||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
|
||||||
if (owner is Message) {
|
|
||||||
IdziennikWebGetAttachment(data, owner, attachmentId, attachmentName) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (owner is Event) {
|
|
||||||
IdziennikWebGetHomeworkAttachment(data, owner, attachmentId, attachmentName) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getRecipientList() {
|
|
||||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
|
||||||
IdziennikWebGetRecipientList(data) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getEvent(eventFull: EventFull) {
|
|
||||||
login(LOGIN_METHOD_IDZIENNIK_WEB) {
|
|
||||||
IdziennikWebGetHomework(data, eventFull) {
|
|
||||||
completed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun firstLogin() { IdziennikFirstLogin(data) { completed() } }
|
|
||||||
override fun cancel() {
|
|
||||||
d(TAG, "Cancelled")
|
|
||||||
data.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
|
||||||
return object : EdziennikCallback {
|
|
||||||
override fun onCompleted() { callback.onCompleted() }
|
|
||||||
override fun onProgress(step: Float) { callback.onProgress(step) }
|
|
||||||
override fun onStartProgress(stringRes: Int) { callback.onStartProgress(stringRes) }
|
|
||||||
override fun onError(apiError: ApiError) {
|
|
||||||
if (apiError.errorCode in internalErrorList) {
|
|
||||||
// finish immediately if the same error occurs twice during the same sync
|
|
||||||
callback.onError(apiError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
internalErrorList.add(apiError.errorCode)
|
|
||||||
when (apiError.errorCode) {
|
|
||||||
ERROR_LOGIN_IDZIENNIK_WEB_NO_SESSION,
|
|
||||||
ERROR_LOGIN_IDZIENNIK_WEB_NO_AUTH,
|
|
||||||
ERROR_LOGIN_IDZIENNIK_WEB_NO_BEARER,
|
|
||||||
ERROR_IDZIENNIK_WEB_ACCESS_DENIED,
|
|
||||||
ERROR_IDZIENNIK_API_ACCESS_DENIED -> {
|
|
||||||
data.loginMethods.remove(LOGIN_METHOD_IDZIENNIK_WEB)
|
|
||||||
data.prepareFor(idziennikLoginMethods, LOGIN_METHOD_IDZIENNIK_WEB)
|
|
||||||
data.loginExpiryTime = 0
|
|
||||||
login()
|
|
||||||
}
|
|
||||||
ERROR_IDZIENNIK_API_NO_REGISTER -> {
|
|
||||||
data()
|
|
||||||
}
|
|
||||||
else -> callback.onError(apiError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.Feature
|
|
||||||
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_TIMETABLE = 1030
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_GRADES = 1040
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES = 1050
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_EXAMS = 1060
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_HOMEWORK = 1061
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_NOTICES = 1070
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS = 1080
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_ATTENDANCE = 1090
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_MESSAGES_INBOX = 1110
|
|
||||||
const val ENDPOINT_IDZIENNIK_WEB_MESSAGES_SENT = 1120
|
|
||||||
const val ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER = 2010
|
|
||||||
const val ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX = 2110
|
|
||||||
const val ENDPOINT_IDZIENNIK_API_MESSAGES_SENT = 2120
|
|
||||||
|
|
||||||
val IdziennikFeatures = listOf(
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_TIMETABLE, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_TIMETABLE to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_GRADES, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_GRADES to LOGIN_METHOD_IDZIENNIK_WEB,
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_AGENDA, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_EXAMS to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_HOMEWORK, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_HOMEWORK to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_BEHAVIOUR, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_NOTICES to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_ATTENDANCE, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_ATTENDANCE to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_ANNOUNCEMENTS, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)),
|
|
||||||
|
|
||||||
/*Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_MESSAGES_INBOX, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_MESSAGES_INBOX to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)).withPriority(2),
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_MESSAGES_SENT, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_MESSAGES_SENT to LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_WEB)).withPriority(2),*/
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_MESSAGES_INBOX, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX to LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_API)),
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_MESSAGES_SENT, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_API_MESSAGES_SENT to LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_API)),
|
|
||||||
|
|
||||||
Feature(LOGIN_TYPE_IDZIENNIK, FEATURE_LUCKY_NUMBER, listOf(
|
|
||||||
ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER to LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
), listOf(LOGIN_METHOD_IDZIENNIK_API))
|
|
||||||
)
|
|
@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-29.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import com.google.gson.JsonElement
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import com.google.gson.JsonParser
|
|
||||||
import im.wangchao.mhttp.Request
|
|
||||||
import im.wangchao.mhttp.Response
|
|
||||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
import java.net.HttpURLConnection
|
|
||||||
|
|
||||||
open class IdziennikApi(open val data: DataIdziennik, open val lastSync: Long?) {
|
|
||||||
companion object {
|
|
||||||
const val TAG = "IdziennikApi"
|
|
||||||
}
|
|
||||||
|
|
||||||
val profileId
|
|
||||||
get() = data.profile?.id ?: -1
|
|
||||||
|
|
||||||
val profile
|
|
||||||
get() = data.profile
|
|
||||||
|
|
||||||
fun apiGet(tag: String, endpointTemplate: String, method: Int = GET, parameters: Map<String, Any> = emptyMap(), onSuccess: (json: JsonElement) -> Unit) {
|
|
||||||
val endpoint = endpointTemplate.replace("\$STUDENT_ID", data.studentId ?: "")
|
|
||||||
Utils.d(tag, "Request: Idziennik/API - $IDZIENNIK_API_URL/$endpoint")
|
|
||||||
|
|
||||||
val callback = object : TextCallbackHandler() {
|
|
||||||
override fun onSuccess(text: String?, response: Response?) {
|
|
||||||
if (text == null) {
|
|
||||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val json = try {
|
|
||||||
JsonParser().parse(text)
|
|
||||||
} catch (_: Exception) { null }
|
|
||||||
|
|
||||||
var error: String? = null
|
|
||||||
if (json == null) {
|
|
||||||
error = text
|
|
||||||
}
|
|
||||||
else if (json is JsonObject) {
|
|
||||||
error = if (response?.code() == 200) null else
|
|
||||||
json.getString("message") ?: json.toString()
|
|
||||||
}
|
|
||||||
error?.let { code ->
|
|
||||||
when (code) {
|
|
||||||
"Uczeń nie posiada aktywnej pozycji w dzienniku" -> ERROR_IDZIENNIK_API_NO_REGISTER
|
|
||||||
"Authorization has been denied for this request." -> ERROR_IDZIENNIK_API_ACCESS_DENIED
|
|
||||||
else -> ERROR_IDZIENNIK_API_OTHER
|
|
||||||
}.let { errorCode ->
|
|
||||||
data.error(ApiError(tag, errorCode)
|
|
||||||
.withApiResponse(text)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
onSuccess(json!!)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
data.error(ApiError(tag, EXCEPTION_IDZIENNIK_API_REQUEST)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(e)
|
|
||||||
.withApiResponse(text))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
|
||||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(throwable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Request.builder()
|
|
||||||
.url("$IDZIENNIK_API_URL/$endpoint")
|
|
||||||
.userAgent(IDZIENNIK_API_USER_AGENT)
|
|
||||||
.addHeader("Authorization", "Bearer ${data.apiBearer}")
|
|
||||||
.apply {
|
|
||||||
when (method) {
|
|
||||||
GET -> get()
|
|
||||||
POST -> {
|
|
||||||
postJson()
|
|
||||||
val json = JsonObject()
|
|
||||||
parameters.map { (name, value) ->
|
|
||||||
when (value) {
|
|
||||||
is JsonObject -> json.add(name, value)
|
|
||||||
is JsonArray -> json.add(name, value)
|
|
||||||
is String -> json.addProperty(name, value)
|
|
||||||
is Int -> json.addProperty(name, value)
|
|
||||||
is Long -> json.addProperty(name, value)
|
|
||||||
is Float -> json.addProperty(name, value)
|
|
||||||
is Char -> json.addProperty(name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setJsonBody(json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.allowErrorCode(HttpURLConnection.HTTP_BAD_REQUEST)
|
|
||||||
.allowErrorCode(HttpURLConnection.HTTP_UNAUTHORIZED)
|
|
||||||
.allowErrorCode(HttpURLConnection.HTTP_INTERNAL_ERROR)
|
|
||||||
.callback(callback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api.IdziennikApiCurrentRegister
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api.IdziennikApiMessagesInbox
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api.IdziennikApiMessagesSent
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.*
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
|
|
||||||
class IdziennikData(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikData"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
nextEndpoint(onSuccess)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun nextEndpoint(onSuccess: () -> Unit) {
|
|
||||||
if (data.targetEndpointIds.isEmpty()) {
|
|
||||||
onSuccess()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (data.cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val id = data.targetEndpointIds.firstKey()
|
|
||||||
val lastSync = data.targetEndpointIds.remove(id)
|
|
||||||
useEndpoint(id, lastSync) { endpointId ->
|
|
||||||
data.progress(data.progressStep)
|
|
||||||
nextEndpoint(onSuccess)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
|
||||||
when (endpointId) {
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_TIMETABLE -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
|
||||||
IdziennikWebTimetable(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_GRADES -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
|
||||||
IdziennikWebGrades(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_proposed_grades)
|
|
||||||
IdziennikWebProposedGrades(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_EXAMS -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_exams)
|
|
||||||
IdziennikWebExams(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_HOMEWORK -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
|
||||||
IdziennikWebHomework(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_NOTICES -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
|
||||||
IdziennikWebNotices(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
|
||||||
IdziennikWebAnnouncements(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_WEB_ATTENDANCE -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
|
||||||
IdziennikWebAttendance(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
|
||||||
IdziennikApiCurrentRegister(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
|
||||||
IdziennikApiMessagesInbox(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_IDZIENNIK_API_MESSAGES_SENT -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
|
||||||
IdziennikApiMessagesSent(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
else -> onSuccess(endpointId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,238 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.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.FileCallbackHandler
|
|
||||||
import im.wangchao.mhttp.callback.JsonCallbackHandler
|
|
||||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web.IdziennikWebSwitchRegister
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
|
||||||
import java.io.File
|
|
||||||
import java.net.HttpURLConnection.HTTP_INTERNAL_ERROR
|
|
||||||
import java.net.HttpURLConnection.HTTP_UNAUTHORIZED
|
|
||||||
|
|
||||||
open class IdziennikWeb(open val data: DataIdziennik, open val lastSync: Long?) {
|
|
||||||
companion object {
|
|
||||||
const val TAG = "IdziennikWeb"
|
|
||||||
}
|
|
||||||
|
|
||||||
val profileId
|
|
||||||
get() = data.profile?.id ?: -1
|
|
||||||
|
|
||||||
val profile
|
|
||||||
get() = data.profile
|
|
||||||
|
|
||||||
fun webApiGet(tag: String, endpoint: String, parameters: Map<String, Any> = emptyMap(), onSuccess: (json: JsonObject) -> Unit) {
|
|
||||||
d(tag, "Request: Idziennik/Web/API - $IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
|
|
||||||
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() == HTTP_INTERNAL_ERROR && endpoint == IDZIENNIK_WEB_GET_RECIPIENT_LIST) {
|
|
||||||
data.error(ApiError(tag, ERROR_IDZIENNIK_WEB_RECIPIENT_LIST_NO_PERMISSION)
|
|
||||||
.withResponse(response)
|
|
||||||
.withApiResponse(json))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response?.code() == HTTP_INTERNAL_ERROR && endpoint == IDZIENNIK_WEB_GRADES) {
|
|
||||||
// special override for accounts where displaying grades
|
|
||||||
// for another student requires switching it manually
|
|
||||||
if (data.registerId != data.webSelectedRegister) {
|
|
||||||
IdziennikWebSwitchRegister(data, data.registerId) {
|
|
||||||
webApiGet(tag, endpoint, parameters, onSuccess)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
|
||||||
response?.code() == HTTP_UNAUTHORIZED -> ERROR_IDZIENNIK_WEB_ACCESS_DENIED
|
|
||||||
response?.code() == HTTP_INTERNAL_ERROR -> ERROR_IDZIENNIK_WEB_SERVER_ERROR
|
|
||||||
response?.parserErrorBody != null -> when {
|
|
||||||
response.parserErrorBody.contains("Identyfikator zgłoszenia") -> ERROR_IDZIENNIK_WEB_SERVER_ERROR
|
|
||||||
response.parserErrorBody.contains("Hasło dostępu do systemu wygasło") -> ERROR_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED
|
|
||||||
response.parserErrorBody.contains("Trwają prace konserwacyjne") -> ERROR_IDZIENNIK_WEB_MAINTENANCE
|
|
||||||
else -> ERROR_IDZIENNIK_WEB_OTHER
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}?.let { errorCode ->
|
|
||||||
data.error(ApiError(TAG, errorCode)
|
|
||||||
.withApiResponse(json?.toString() ?: response?.parserErrorBody)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json == null) {
|
|
||||||
data.error(ApiError(tag, ERROR_RESPONSE_EMPTY)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
onSuccess(json)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
data.error(ApiError(tag, EXCEPTION_IDZIENNIK_WEB_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("$IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
.userAgent(IDZIENNIK_USER_AGENT)
|
|
||||||
.postJson()
|
|
||||||
.apply {
|
|
||||||
val json = JsonObject()
|
|
||||||
parameters.map { (name, value) ->
|
|
||||||
when (value) {
|
|
||||||
is JsonObject -> json.add(name, value)
|
|
||||||
is JsonArray -> json.add(name, value)
|
|
||||||
is String -> json.addProperty(name, value)
|
|
||||||
is Int -> json.addProperty(name, value)
|
|
||||||
is Long -> json.addProperty(name, value)
|
|
||||||
is Float -> json.addProperty(name, value)
|
|
||||||
is Char -> json.addProperty(name, value)
|
|
||||||
is Boolean -> json.addProperty(name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setJsonBody(json)
|
|
||||||
}
|
|
||||||
.allowErrorCode(HTTP_UNAUTHORIZED)
|
|
||||||
.allowErrorCode(HTTP_INTERNAL_ERROR)
|
|
||||||
.callback(callback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun webGet(tag: String, endpoint: String, parameters: Map<String, Any> = emptyMap(), onSuccess: (text: String) -> Unit) {
|
|
||||||
d(tag, "Request: Idziennik/Web - $IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
|
|
||||||
val callback = object : TextCallbackHandler() {
|
|
||||||
override fun onSuccess(text: String?, response: Response?) {
|
|
||||||
if (text == null) {
|
|
||||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!text.contains("czyWyswietlicDostepMobilny")) {
|
|
||||||
when {
|
|
||||||
text.contains("Identyfikator zgłoszenia") -> ERROR_IDZIENNIK_WEB_SERVER_ERROR
|
|
||||||
text.contains("Hasło dostępu do systemu wygasło") -> ERROR_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED
|
|
||||||
text.contains("Trwają prace konserwacyjne") -> ERROR_IDZIENNIK_WEB_MAINTENANCE
|
|
||||||
else -> ERROR_IDZIENNIK_WEB_OTHER
|
|
||||||
}.let { errorCode ->
|
|
||||||
data.error(ApiError(TAG, errorCode)
|
|
||||||
.withApiResponse(text)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
onSuccess(text)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
data.error(ApiError(tag, EXCEPTION_IDZIENNIK_WEB_REQUEST)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(e)
|
|
||||||
.withApiResponse(text))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
|
||||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(throwable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Request.builder()
|
|
||||||
.url("$IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
.userAgent(IDZIENNIK_USER_AGENT)
|
|
||||||
.apply {
|
|
||||||
if (parameters.isEmpty()) get()
|
|
||||||
else post()
|
|
||||||
|
|
||||||
parameters.map { (name, value) ->
|
|
||||||
addParameter(name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.callback(callback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun webGetFile(tag: String, endpoint: String, targetFile: File, parameters: Map<String, Any>,
|
|
||||||
onSuccess: (file: File) -> Unit, onProgress: (written: Long, total: Long) -> Unit) {
|
|
||||||
|
|
||||||
d(tag, "Request: Idziennik/Web - $IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
|
|
||||||
val callback = object : FileCallbackHandler(targetFile) {
|
|
||||||
override fun onSuccess(file: File?, response: Response?) {
|
|
||||||
if (file == null) {
|
|
||||||
data.error(ApiError(TAG, ERROR_FILE_DOWNLOAD)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
onSuccess(file)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
data.error(ApiError(tag, EXCEPTION_EDUDZIENNIK_FILE_REQUEST)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onProgress(bytesWritten: Long, bytesTotal: Long) {
|
|
||||||
try {
|
|
||||||
onProgress(bytesWritten, bytesTotal)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
data.error(ApiError(tag, EXCEPTION_EDUDZIENNIK_FILE_REQUEST)
|
|
||||||
.withThrowable(e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
|
||||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(throwable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Request.builder()
|
|
||||||
.url("$IDZIENNIK_WEB_URL/$endpoint")
|
|
||||||
.userAgent(IDZIENNIK_USER_AGENT)
|
|
||||||
.apply {
|
|
||||||
parameters.forEach { (k, v) -> addParameter(k, v) }
|
|
||||||
}
|
|
||||||
.contentType("application/x-www-form-urlencoded")
|
|
||||||
.post()
|
|
||||||
.callback(callback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-29.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.DAY
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_API_CURRENT_REGISTER
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.getInt
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
|
||||||
|
|
||||||
class IdziennikApiCurrentRegister(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikApi(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikApiCurrentRegister"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
apiGet(TAG, IDZIENNIK_API_CURRENT_REGISTER) { json ->
|
|
||||||
if (json !is JsonObject) {
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER)
|
|
||||||
return@apiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
var nextSync = System.currentTimeMillis() + 14*DAY*1000
|
|
||||||
|
|
||||||
val settings = json.getJsonObject("ustawienia")?.apply {
|
|
||||||
getString("poczatekSemestru1")?.let { profile?.dateSemester1Start = Date.fromY_m_d(it) }
|
|
||||||
getString("koniecSemestru1")?.let { profile?.dateSemester2Start = Date.fromY_m_d(it).stepForward(0, 0, 1) }
|
|
||||||
getString("koniecSemestru2")?.let { profile?.dateYearEnd = Date.fromY_m_d(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getInt("szczesliwyNumerek")?.let { luckyNumber ->
|
|
||||||
val luckyNumberDate = Date.getToday()
|
|
||||||
settings.getString("godzinaPublikacjiSzczesliwegoLosu")
|
|
||||||
?.let { Time.fromH_m(it) }
|
|
||||||
?.let { publishTime ->
|
|
||||||
val now = Time.getNow()
|
|
||||||
if (publishTime.value < 150000 && now.value < publishTime.value) {
|
|
||||||
nextSync = luckyNumberDate.combineWith(publishTime)
|
|
||||||
luckyNumberDate.stepForward(0, 0, -1) // the lucky number is still for yesterday
|
|
||||||
}
|
|
||||||
else if (publishTime.value >= 150000 && now.value > publishTime.value) {
|
|
||||||
luckyNumberDate.stepForward(0, 0, 1) // the lucky number is already for tomorrow
|
|
||||||
nextSync = luckyNumberDate.combineWith(publishTime)
|
|
||||||
}
|
|
||||||
else if (publishTime.value < 150000) {
|
|
||||||
nextSync = luckyNumberDate
|
|
||||||
.clone()
|
|
||||||
.stepForward(0, 0, 1)
|
|
||||||
.combineWith(publishTime)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nextSync = luckyNumberDate.combineWith(publishTime)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val luckyNumberObject = LuckyNumber(
|
|
||||||
profileId = data.profileId,
|
|
||||||
date = luckyNumberDate,
|
|
||||||
number = luckyNumber
|
|
||||||
)
|
|
||||||
|
|
||||||
data.luckyNumberList.add(luckyNumberObject)
|
|
||||||
data.metadataList.add(
|
|
||||||
Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_LUCKY_NUMBER,
|
|
||||||
luckyNumberObject.date.value.toLong(),
|
|
||||||
true,
|
|
||||||
data.profile?.empty ?: false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER, syncAt = nextSync)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-30.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_API_MESSAGES_INBOX
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_DELETED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
|
||||||
import pl.szczodrzynski.edziennik.getBoolean
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.crc32
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikApi(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikApiMessagesInbox"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
apiGet(TAG, IDZIENNIK_API_MESSAGES_INBOX) { json ->
|
|
||||||
if (json !is JsonArray) {
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX)
|
|
||||||
return@apiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.asJsonObjectList().forEach { jMessage ->
|
|
||||||
val subject = jMessage.getString("tytul") ?: ""
|
|
||||||
if (subject.contains("(") && subject.startsWith("iDziennik - "))
|
|
||||||
return@forEach
|
|
||||||
if (subject.startsWith("Uwaga dla ucznia (klasa:"))
|
|
||||||
return@forEach
|
|
||||||
|
|
||||||
val messageIdStr = jMessage.getString("id")
|
|
||||||
val messageId = crc32((messageIdStr + "0").toByteArray())
|
|
||||||
|
|
||||||
var body = "[META:$messageIdStr;-1]"
|
|
||||||
body += jMessage.getString("tresc")?.replace("\n".toRegex(), "<br>")
|
|
||||||
|
|
||||||
val readDate = if (jMessage.getBoolean("odczytana") == true) Date.fromIso(jMessage.getString("wersjaRekordu")) else 0
|
|
||||||
val sentDate = Date.fromIso(jMessage.getString("dataWyslania"))
|
|
||||||
|
|
||||||
val sender = jMessage.getAsJsonObject("nadawca")
|
|
||||||
var firstName = sender.getString("imie")
|
|
||||||
var lastName = sender.getString("nazwisko")
|
|
||||||
if (firstName.isNullOrEmpty() || lastName.isNullOrEmpty()) {
|
|
||||||
firstName = "usunięty"
|
|
||||||
lastName = "użytkownik"
|
|
||||||
}
|
|
||||||
val rTeacher = data.getTeacher(
|
|
||||||
firstName,
|
|
||||||
lastName
|
|
||||||
)
|
|
||||||
rTeacher.loginId = /*sender.getString("id") + ":" + */sender.getString("usr")
|
|
||||||
rTeacher.setTeacherType(Teacher.TYPE_OTHER)
|
|
||||||
|
|
||||||
val message = Message(
|
|
||||||
profileId = profileId,
|
|
||||||
id = messageId,
|
|
||||||
type = if (jMessage.getBoolean("rekordUsuniety") == true) TYPE_DELETED else TYPE_RECEIVED,
|
|
||||||
subject = subject,
|
|
||||||
body = body,
|
|
||||||
senderId = rTeacher.id,
|
|
||||||
addedDate = sentDate
|
|
||||||
)
|
|
||||||
|
|
||||||
val messageRecipient = MessageRecipient(
|
|
||||||
profileId,
|
|
||||||
-1 /* me */,
|
|
||||||
-1,
|
|
||||||
readDate,
|
|
||||||
/*messageId*/ messageId
|
|
||||||
)
|
|
||||||
|
|
||||||
data.messageList.add(message)
|
|
||||||
data.messageRecipientList.add(messageRecipient)
|
|
||||||
data.setSeenMetadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_MESSAGE,
|
|
||||||
message.id,
|
|
||||||
readDate > 0,
|
|
||||||
readDate > 0 || profile?.empty ?: false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-30.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import pl.szczodrzynski.edziennik.DAY
|
|
||||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
|
||||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_API_MESSAGES_SENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_MESSAGES_SENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.MessageRecipient
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.crc32
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikApiMessagesSent(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikApi(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikApiMessagesSent"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
apiGet(TAG, IDZIENNIK_API_MESSAGES_SENT) { json ->
|
|
||||||
if (json !is JsonArray) {
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_MESSAGES_SENT)
|
|
||||||
return@apiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.asJsonObjectList()?.forEach { jMessage ->
|
|
||||||
val messageIdStr = jMessage.get("id").asString
|
|
||||||
val messageId = crc32((messageIdStr + "1").toByteArray())
|
|
||||||
|
|
||||||
val subject = jMessage.get("tytul").asString
|
|
||||||
|
|
||||||
var body = "[META:$messageIdStr;-1]"
|
|
||||||
body += jMessage.get("tresc").asString.replace("\n".toRegex(), "<br>")
|
|
||||||
|
|
||||||
val sentDate = Date.fromIso(jMessage.get("dataWyslania").asString)
|
|
||||||
|
|
||||||
val message = Message(
|
|
||||||
profileId = profileId,
|
|
||||||
id = messageId,
|
|
||||||
type = TYPE_SENT,
|
|
||||||
subject = subject,
|
|
||||||
body = body,
|
|
||||||
senderId = null,
|
|
||||||
addedDate = sentDate
|
|
||||||
)
|
|
||||||
|
|
||||||
for (recipientEl in jMessage.getAsJsonArray("odbiorcy")) {
|
|
||||||
val recipient = recipientEl.asJsonObject
|
|
||||||
var firstName = recipient.get("imie").asString
|
|
||||||
var lastName = recipient.get("nazwisko").asString
|
|
||||||
if (firstName.isEmpty() || lastName.isEmpty()) {
|
|
||||||
firstName = "usunięty"
|
|
||||||
lastName = "użytkownik"
|
|
||||||
}
|
|
||||||
val rTeacher = data.getTeacher(firstName, lastName)
|
|
||||||
rTeacher.loginId = /*recipient.get("id").asString + ":" + */recipient.get("usr").asString
|
|
||||||
|
|
||||||
val messageRecipient = MessageRecipient(
|
|
||||||
profileId,
|
|
||||||
rTeacher.id,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
/*messageId*/ messageId
|
|
||||||
)
|
|
||||||
data.messageRecipientIgnoreList.add(messageRecipient)
|
|
||||||
}
|
|
||||||
|
|
||||||
data.messageList.add(message)
|
|
||||||
data.metadataList.add(Metadata(profileId, Metadata.TYPE_MESSAGE, message.id, true, true))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_API_MESSAGES_SENT, DAY, DRAWER_ITEM_MESSAGES)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_API_MESSAGES_SENT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_ANNOUNCEMENTS
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Announcement
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getLong
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikWebAnnouncements(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebAnnouncements"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val param = JsonObject()
|
|
||||||
param.add("parametryFiltrow", JsonArray())
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_ANNOUNCEMENTS, mapOf(
|
|
||||||
"uczenId" to (data.studentId ?: ""),
|
|
||||||
"param" to param
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
for (jAnnouncementEl in json.getAsJsonArray("ListK")) {
|
|
||||||
val jAnnouncement = jAnnouncementEl.asJsonObject
|
|
||||||
// jAnnouncement
|
|
||||||
val announcementId = jAnnouncement.getLong("Id") ?: -1
|
|
||||||
|
|
||||||
val rTeacher = data.getTeacherByFirstLast(jAnnouncement.getString("Autor") ?: "")
|
|
||||||
val addedDate = jAnnouncement.getString("DataDodania")?.replace("[^\\d]".toRegex(), "")?.toLongOrNull() ?: System.currentTimeMillis()
|
|
||||||
val startDate = jAnnouncement.getString("DataWydarzenia")?.replace("[^\\d]".toRegex(), "")?.toLongOrNull()?.let { Date.fromMillis(it) }
|
|
||||||
|
|
||||||
val announcementObject = Announcement(
|
|
||||||
profileId = profileId,
|
|
||||||
id = announcementId,
|
|
||||||
subject = jAnnouncement.get("Temat").asString,
|
|
||||||
text = jAnnouncement.get("Tresc").asString,
|
|
||||||
startDate = startDate,
|
|
||||||
endDate = null,
|
|
||||||
teacherId = rTeacher.id,
|
|
||||||
addedDate = addedDate
|
|
||||||
)
|
|
||||||
data.announcementList.add(announcementObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_ANNOUNCEMENT,
|
|
||||||
announcementObject.id,
|
|
||||||
profile?.empty ?: false,
|
|
||||||
profile?.empty ?: false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,180 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.crc16
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_ATTENDANCE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_ATTENDANCE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_ABSENT_EXCUSED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_BELATED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_PRESENT_CUSTOM
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_RELEASED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance.Companion.TYPE_UNKNOWN
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.getInt
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
|
||||||
|
|
||||||
class IdziennikWebAttendance(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebAttendance"
|
|
||||||
}
|
|
||||||
|
|
||||||
private var attendanceYear = Date.getToday().year
|
|
||||||
private var attendanceMonth = Date.getToday().month
|
|
||||||
private var attendancePrevMonthChecked = false
|
|
||||||
|
|
||||||
init {
|
|
||||||
getAttendance()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getAttendance() {
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_ATTENDANCE, mapOf(
|
|
||||||
"idPozDziennika" to data.registerId,
|
|
||||||
"mc" to attendanceMonth,
|
|
||||||
"rok" to attendanceYear,
|
|
||||||
"dataTygodnia" to ""
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
for (jAttendanceEl in json.getAsJsonArray("Obecnosci")) {
|
|
||||||
val jAttendance = jAttendanceEl.asJsonObject
|
|
||||||
// jAttendance
|
|
||||||
val type = jAttendance.get("TypObecnosci").asInt
|
|
||||||
|
|
||||||
// skip "zajęcia nie odbyły się" and "Ferie"
|
|
||||||
if (type == 5 || type == 7)
|
|
||||||
continue
|
|
||||||
|
|
||||||
val date = Date.fromY_m_d(jAttendance.get("Data").asString)
|
|
||||||
val time = Time.fromH_m(jAttendance.get("OdDoGodziny").asString)
|
|
||||||
if (date.combineWith(time) > System.currentTimeMillis())
|
|
||||||
continue
|
|
||||||
|
|
||||||
val id = jAttendance.get("IdLesson").asString.crc16().toLong()
|
|
||||||
val rSubject = data.getSubject(jAttendance.get("Przedmiot").asString, jAttendance.get("IdPrzedmiot").asLong, "")
|
|
||||||
val rTeacher = data.getTeacherByFDotSpaceLast(jAttendance.get("PrzedmiotNauczyciel").asString)
|
|
||||||
|
|
||||||
var baseType = TYPE_UNKNOWN
|
|
||||||
var typeName = "nieznany rodzaj"
|
|
||||||
var typeSymbol: String? = null
|
|
||||||
var typeColor: Long? = null
|
|
||||||
|
|
||||||
/* https://iuczniowie.progman.pl/idziennik/mod_panelRodzica/obecnosci/obecnosciUcznia_lmt637231494660000000.js */
|
|
||||||
/* https://iuczniowie.progman.pl/idziennik/mod_panelRodzica/obecnosci/obecnosci_lmt637231494660000000.css */
|
|
||||||
when (type) {
|
|
||||||
1 -> {
|
|
||||||
baseType = TYPE_ABSENT_EXCUSED
|
|
||||||
typeName = "nieobecność usprawiedliwiona"
|
|
||||||
typeColor = 0xffffe099
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
baseType = TYPE_BELATED
|
|
||||||
typeName = "spóźnienie"
|
|
||||||
typeColor = 0xffffffaa
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
baseType = TYPE_ABSENT
|
|
||||||
typeName = "nieobecność nieusprawiedliwiona"
|
|
||||||
typeColor = 0xffffad99
|
|
||||||
}
|
|
||||||
4, 9 -> {
|
|
||||||
baseType = TYPE_RELEASED
|
|
||||||
if (type == 4) {
|
|
||||||
typeName = "zwolnienie"
|
|
||||||
typeColor = 0xffa8beff
|
|
||||||
}
|
|
||||||
if (type == 9) {
|
|
||||||
typeName = "zwolniony / obecny"
|
|
||||||
typeSymbol = "zb"
|
|
||||||
typeColor = 0xffff69b4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8 -> {
|
|
||||||
baseType = TYPE_PRESENT_CUSTOM
|
|
||||||
typeName = "wycieczka"
|
|
||||||
typeSymbol = "w"
|
|
||||||
typeColor = null
|
|
||||||
}
|
|
||||||
0 -> {
|
|
||||||
baseType = TYPE_PRESENT
|
|
||||||
typeName = "obecny"
|
|
||||||
typeColor = 0xffccffcc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val semester = profile?.dateToSemester(date) ?: 1
|
|
||||||
|
|
||||||
val attendanceObject = Attendance(
|
|
||||||
profileId = profileId,
|
|
||||||
id = id,
|
|
||||||
baseType = baseType,
|
|
||||||
typeName = typeName,
|
|
||||||
typeShort = typeSymbol ?: data.app.attendanceManager.getTypeShort(baseType),
|
|
||||||
typeSymbol = typeSymbol ?: data.app.attendanceManager.getTypeShort(baseType),
|
|
||||||
typeColor = typeColor?.toInt(),
|
|
||||||
date = date,
|
|
||||||
startTime = time,
|
|
||||||
semester = semester,
|
|
||||||
teacherId = rTeacher.id,
|
|
||||||
subjectId = rSubject.id
|
|
||||||
).also {
|
|
||||||
it.lessonTopic = jAttendance.getString("PrzedmiotTemat")
|
|
||||||
it.lessonNumber = jAttendance.getInt("Godzina")
|
|
||||||
}
|
|
||||||
|
|
||||||
data.attendanceList.add(attendanceObject)
|
|
||||||
if (attendanceObject.baseType != TYPE_PRESENT) {
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_ATTENDANCE,
|
|
||||||
attendanceObject.id,
|
|
||||||
profile?.empty ?: false || baseType == TYPE_PRESENT_CUSTOM || baseType == TYPE_UNKNOWN,
|
|
||||||
profile?.empty ?: false || baseType == TYPE_PRESENT_CUSTOM || baseType == TYPE_UNKNOWN
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val attendanceDateValue = attendanceYear * 10000 + attendanceMonth * 100
|
|
||||||
if (profile?.empty == true && attendanceDateValue > profile?.getSemesterStart(1)?.value ?: 99999999) {
|
|
||||||
attendancePrevMonthChecked = true // do not need to check prev month later
|
|
||||||
attendanceMonth--
|
|
||||||
if (attendanceMonth < 1) {
|
|
||||||
attendanceMonth = 12
|
|
||||||
attendanceYear--
|
|
||||||
}
|
|
||||||
getAttendance()
|
|
||||||
} else if (!attendancePrevMonthChecked /* get also the previous month */) {
|
|
||||||
attendanceMonth--
|
|
||||||
if (attendanceMonth < 1) {
|
|
||||||
attendanceMonth = 12
|
|
||||||
attendanceYear--
|
|
||||||
}
|
|
||||||
attendancePrevMonthChecked = true
|
|
||||||
getAttendance()
|
|
||||||
} else {
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_ATTENDANCE, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_ATTENDANCE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_EXAMS
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_EXAMS
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class IdziennikWebExams(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebExams"
|
|
||||||
}
|
|
||||||
|
|
||||||
private var examsYear = Date.getToday().year
|
|
||||||
private var examsMonth = Date.getToday().month
|
|
||||||
private var examsMonthsChecked = 0
|
|
||||||
private var examsNextMonthChecked = false // TO DO temporary // no more // idk
|
|
||||||
|
|
||||||
init {
|
|
||||||
getExams()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getExams() {
|
|
||||||
val param = JsonObject().apply {
|
|
||||||
addProperty("strona", 1)
|
|
||||||
addProperty("iloscNaStrone", "99")
|
|
||||||
addProperty("iloscRekordow", -1)
|
|
||||||
addProperty("kolumnaSort", "ss.Nazwa,sp.Data_sprawdzianu")
|
|
||||||
addProperty("kierunekSort", 0)
|
|
||||||
addProperty("maxIloscZaznaczonych", 0)
|
|
||||||
addProperty("panelFiltrow", 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_EXAMS, mapOf(
|
|
||||||
"idP" to data.registerId,
|
|
||||||
"rok" to examsYear,
|
|
||||||
"miesiac" to examsMonth,
|
|
||||||
"param" to param
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("ListK")?.asJsonObjectList()?.forEach { exam ->
|
|
||||||
val id = exam.getLong("_recordId") ?: return@forEach
|
|
||||||
val examDate = Date.fromY_m_d(exam.getString("data") ?: return@forEach)
|
|
||||||
val subjectName = exam.getString("przedmiot") ?: return@forEach
|
|
||||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
|
||||||
val teacherName = exam.getString("wpisal") ?: return@forEach
|
|
||||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
|
||||||
val topic = exam.getString("zakres")?.trim() ?: ""
|
|
||||||
|
|
||||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, examDate)
|
|
||||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
|
||||||
|
|
||||||
val eventType = when (exam.getString("rodzaj")?.toLowerCase(Locale.getDefault())) {
|
|
||||||
"sprawdzian/praca klasowa",
|
|
||||||
"sprawdzian",
|
|
||||||
"praca klasowa" -> Event.TYPE_EXAM
|
|
||||||
"kartkówka" -> Event.TYPE_SHORT_QUIZ
|
|
||||||
else -> Event.TYPE_EXAM
|
|
||||||
}
|
|
||||||
|
|
||||||
val eventObject = Event(
|
|
||||||
profileId = profileId,
|
|
||||||
id = id,
|
|
||||||
date = examDate,
|
|
||||||
time = startTime,
|
|
||||||
topic = topic,
|
|
||||||
color = null,
|
|
||||||
type = eventType,
|
|
||||||
teacherId = teacherId,
|
|
||||||
subjectId = subjectId,
|
|
||||||
teamId = data.teamClass?.id ?: -1
|
|
||||||
)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_EVENT,
|
|
||||||
eventObject.id,
|
|
||||||
profile?.empty ?: false,
|
|
||||||
profile?.empty ?: false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profile?.empty == true && examsMonthsChecked < 3 /* how many months backwards to check? */) {
|
|
||||||
examsMonthsChecked++
|
|
||||||
examsMonth--
|
|
||||||
if (examsMonth < 1) {
|
|
||||||
examsMonth = 12
|
|
||||||
examsYear--
|
|
||||||
}
|
|
||||||
getExams()
|
|
||||||
} else if (!examsNextMonthChecked /* get also one month forward */) {
|
|
||||||
val showDate = Date.getToday().stepForward(0, 1, 0)
|
|
||||||
examsYear = showDate.year
|
|
||||||
examsMonth = showDate.month
|
|
||||||
examsNextMonthChecked = true
|
|
||||||
getExams()
|
|
||||||
} else {
|
|
||||||
data.toRemove.add(DataRemoveModel.Events.futureExceptType(Event.TYPE_HOMEWORK))
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_EXAMS, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_EXAMS)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2019-12-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_ATTACHMENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
|
||||||
import pl.szczodrzynski.edziennik.get
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class IdziennikWebGetAttachment(override val data: DataIdziennik,
|
|
||||||
val owner: Any,
|
|
||||||
val attachmentId: Long,
|
|
||||||
val attachmentName: String,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
const val TAG = "IdziennikWebGetAttachment"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val message = owner as Message
|
|
||||||
|
|
||||||
val messageId = "\\[META:([A-z0-9]+);([0-9-]+)]".toRegex().find(message.body ?: "")?.get(2) ?: -1
|
|
||||||
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
|
||||||
|
|
||||||
webGetFile(TAG, IDZIENNIK_WEB_GET_ATTACHMENT, targetFile, mapOf(
|
|
||||||
"id" to messageId,
|
|
||||||
"fileName" to attachmentName
|
|
||||||
), { file ->
|
|
||||||
val event = AttachmentGetEvent(
|
|
||||||
profileId,
|
|
||||||
owner,
|
|
||||||
attachmentId,
|
|
||||||
AttachmentGetEvent.TYPE_FINISHED,
|
|
||||||
file.absolutePath
|
|
||||||
)
|
|
||||||
|
|
||||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.ownerId}_${event.attachmentId}")
|
|
||||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
|
|
||||||
onSuccess()
|
|
||||||
|
|
||||||
}) { written, _ ->
|
|
||||||
val event = AttachmentGetEvent(
|
|
||||||
profileId,
|
|
||||||
owner,
|
|
||||||
attachmentId,
|
|
||||||
AttachmentGetEvent.TYPE_PROGRESS,
|
|
||||||
bytesWritten = written
|
|
||||||
)
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2020-4-1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_HOMEWORK
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
|
||||||
import pl.szczodrzynski.edziennik.getBoolean
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
|
|
||||||
class IdziennikWebGetHomework(override val data: DataIdziennik,
|
|
||||||
val event: EventFull,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebGetHomework"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_GET_HOMEWORK, mapOf(
|
|
||||||
"idP" to data.registerId,
|
|
||||||
"idPD" to event.id
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
val homework = json.getJsonObject("praca") ?: return@webApiGet
|
|
||||||
|
|
||||||
if (homework.getBoolean("zalacznik", false)) {
|
|
||||||
event.attachmentIds = mutableListOf(event.id)
|
|
||||||
event.attachmentNames = mutableListOf("Załącznik do zadania")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
event.attachmentIds = mutableListOf()
|
|
||||||
event.attachmentNames = mutableListOf()
|
|
||||||
}
|
|
||||||
event.homeworkBody = homework.getString("tresc")
|
|
||||||
|
|
||||||
data.eventList.add(event)
|
|
||||||
data.eventListReplace = true
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(EventGetEvent(event))
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2020-4-1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
|
||||||
import pl.szczodrzynski.edziennik.get
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.set
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class IdziennikWebGetHomeworkAttachment(override val data: DataIdziennik,
|
|
||||||
val owner: Any,
|
|
||||||
val attachmentId: Long,
|
|
||||||
val attachmentName: String,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
const val TAG = "IdziennikWebGetHomeworkAttachment"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val homework = owner as Event
|
|
||||||
|
|
||||||
/*val request = Request.Builder()
|
|
||||||
.url("")
|
|
||||||
.build()
|
|
||||||
data.app.http.newCall(request).enqueue(object : Callback {
|
|
||||||
override fun onFailure(call: Call, e: IOException) {
|
|
||||||
data.error(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
|
||||||
.withThrowable(e))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResponse(call: Call, response: Response) {
|
|
||||||
val filename = response.header("content-disposition")?.substringAfter("\"")?.substringBeforeLast("\"")
|
|
||||||
|
|
||||||
val file: File = File(Utils.getStorageDir(), filename)
|
|
||||||
val sink = file.sink().buffer()
|
|
||||||
response.body()?.source()?.let {
|
|
||||||
sink.writeAll(it)
|
|
||||||
}
|
|
||||||
sink.close()
|
|
||||||
}
|
|
||||||
})*/
|
|
||||||
|
|
||||||
webGet(TAG, IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT) { text ->
|
|
||||||
val hiddenFields = JsonObject()
|
|
||||||
Regexes.IDZIENNIK_LOGIN_HIDDEN_FIELDS.findAll(text).forEach {
|
|
||||||
hiddenFields[it[1]] = it[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
webGetFile(TAG, IDZIENNIK_WEB_GET_HOMEWORK_ATTACHMENT, Utils.getStorageDir(), mapOf(
|
|
||||||
"__VIEWSTATE" to hiddenFields.getString("__VIEWSTATE", ""),
|
|
||||||
"__VIEWSTATEGENERATOR" to hiddenFields.getString("__VIEWSTATEGENERATOR", ""),
|
|
||||||
"__EVENTVALIDATION" to hiddenFields.getString("__EVENTVALIDATION", ""),
|
|
||||||
"__EVENTTARGET" to "ctl00\$cphContent\$bt_pobraniePliku",
|
|
||||||
"ctl00\$dxComboUczniowie" to data.registerId,
|
|
||||||
"ctl00\$cphContent\$idPracyDomowej" to attachmentId
|
|
||||||
), { file ->
|
|
||||||
val event = AttachmentGetEvent(
|
|
||||||
profileId,
|
|
||||||
owner,
|
|
||||||
attachmentId,
|
|
||||||
AttachmentGetEvent.TYPE_FINISHED,
|
|
||||||
file.absolutePath
|
|
||||||
)
|
|
||||||
|
|
||||||
val attachmentDataFile = File(Utils.getStorageDir(), ".${profileId}_${event.ownerId}_${event.attachmentId}")
|
|
||||||
Utils.writeStringToFile(attachmentDataFile, event.fileName)
|
|
||||||
|
|
||||||
homework.attachmentNames = mutableListOf(file.name)
|
|
||||||
data.eventList.add(homework)
|
|
||||||
data.eventListReplace = true
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
onSuccess()
|
|
||||||
|
|
||||||
}) { written, _ ->
|
|
||||||
val event = AttachmentGetEvent(
|
|
||||||
profileId,
|
|
||||||
owner,
|
|
||||||
attachmentId,
|
|
||||||
AttachmentGetEvent.TYPE_PROGRESS,
|
|
||||||
bytesWritten = written
|
|
||||||
)
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2019-12-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_MESSAGE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.MessageRecipientFull
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikWebGetMessage(override val data: DataIdziennik,
|
|
||||||
private val message: MessageFull,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
const val TAG = "IdziennikWebGetMessage"
|
|
||||||
}
|
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
|
||||||
val metaPattern = "\\[META:([A-z0-9]+);([0-9-]+)]".toRegex()
|
|
||||||
val meta = metaPattern.find(message.body!!)
|
|
||||||
val messageIdString = meta?.get(1) ?: ""
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_GET_MESSAGE, parameters = mapOf(
|
|
||||||
"idWiadomosci" to messageIdString,
|
|
||||||
"typWiadomosci" to if (message.type == TYPE_SENT) 1 else 0
|
|
||||||
)) { json ->
|
|
||||||
json.getJsonObject("d")?.getJsonObject("Wiadomosc")?.also {
|
|
||||||
val id = it.getLong("_recordId")
|
|
||||||
message.body = message.body?.replace(metaPattern, "[META:$messageIdString;$id]")
|
|
||||||
|
|
||||||
message.clearAttachments()
|
|
||||||
it.getJsonArray("ListaZal")?.asJsonObjectList()?.forEach { attachment ->
|
|
||||||
message.addAttachment(
|
|
||||||
attachment.getLong("Id") ?: return@forEach,
|
|
||||||
attachment.getString("Nazwa") ?: return@forEach,
|
|
||||||
-1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
message.recipients?.clear()
|
|
||||||
when (message.type) {
|
|
||||||
TYPE_RECEIVED -> {
|
|
||||||
val recipientObject = MessageRecipientFull(
|
|
||||||
profileId = profileId,
|
|
||||||
id = -1,
|
|
||||||
messageId = message.id
|
|
||||||
)
|
|
||||||
|
|
||||||
val readDateString = it.getString("DataOdczytania")
|
|
||||||
recipientObject.readDate = if (readDateString.isNullOrBlank()) System.currentTimeMillis()
|
|
||||||
else Date.fromIso(readDateString)
|
|
||||||
|
|
||||||
recipientObject.fullName = profile.accountName ?: profile.studentNameLong
|
|
||||||
|
|
||||||
data.messageRecipientList.add(recipientObject)
|
|
||||||
message.addRecipient(recipientObject)
|
|
||||||
}
|
|
||||||
|
|
||||||
TYPE_SENT -> {
|
|
||||||
it.getJsonArray("ListaOdbiorcow")?.asJsonObjectList()?.forEach { recipient ->
|
|
||||||
val recipientName = recipient.getString("NazwaOdbiorcy") ?: return@forEach
|
|
||||||
val teacher = data.getTeacherByLastFirst(recipientName)
|
|
||||||
|
|
||||||
val recipientObject = MessageRecipientFull(
|
|
||||||
profileId = profileId,
|
|
||||||
id = teacher.id,
|
|
||||||
messageId = message.id
|
|
||||||
)
|
|
||||||
|
|
||||||
recipientObject.readDate = recipient.getLong("Status") ?: return@forEach
|
|
||||||
recipientObject.fullName = teacher.fullName
|
|
||||||
|
|
||||||
data.messageRecipientList.add(recipientObject)
|
|
||||||
message.addRecipient(recipientObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!message.seen) {
|
|
||||||
message.seen = true
|
|
||||||
|
|
||||||
data.setSeenMetadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_MESSAGE,
|
|
||||||
message.id,
|
|
||||||
message.seen,
|
|
||||||
message.notified
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.messageList.add(message)
|
|
||||||
data.messageListReplace = true
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(MessageGetEvent(message))
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} ?: onSuccess() }
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-12-30.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GET_RECIPIENT_LIST
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.RecipientListGetEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
|
||||||
|
|
||||||
class IdziennikWebGetRecipientList(override val data: DataIdziennik,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebGetRecipientList"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_GET_RECIPIENT_LIST, mapOf(
|
|
||||||
"idP" to data.registerId
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("ListK_Pracownicy")?.asJsonObjectList()?.forEach { recipient ->
|
|
||||||
val name = recipient.getString("ImieNazwisko") ?: ": "
|
|
||||||
val (fullName, subject) = name.split(": ").let {
|
|
||||||
Pair(it.getOrNull(0), it.getOrNull(1))
|
|
||||||
}
|
|
||||||
val guid = recipient.getString("Id") ?: ""
|
|
||||||
// get teacher by ID or create it
|
|
||||||
val teacher = data.getTeacherByFirstLast(fullName ?: " ")
|
|
||||||
teacher.loginId = guid
|
|
||||||
teacher.setTeacherType(Teacher.TYPE_TEACHER)
|
|
||||||
// unset OTHER that is automatically set in IdziennikApiMessages*
|
|
||||||
teacher.unsetTeacherType(Teacher.TYPE_OTHER)
|
|
||||||
teacher.typeDescription = subject
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("ListK_Opiekunowie")?.asJsonObjectList()?.forEach { recipient ->
|
|
||||||
val name = recipient.getString("ImieNazwisko") ?: ": "
|
|
||||||
val (fullName, parentOf) = Regexes.IDZIENNIK_MESSAGES_RECIPIENT_PARENT.find(name)?.let {
|
|
||||||
Pair(it.groupValues.getOrNull(1), it.groupValues.getOrNull(2))
|
|
||||||
} ?: Pair(null, null)
|
|
||||||
val guid = recipient.getString("Id") ?: ""
|
|
||||||
// get teacher by ID or create it
|
|
||||||
val teacher = data.getTeacherByFirstLast(fullName ?: " ")
|
|
||||||
teacher.loginId = guid
|
|
||||||
teacher.setTeacherType(Teacher.TYPE_PARENT)
|
|
||||||
// unset OTHER that is automatically set in IdziennikApiMessages*
|
|
||||||
teacher.unsetTeacherType(Teacher.TYPE_OTHER)
|
|
||||||
teacher.typeDescription = parentOf
|
|
||||||
}
|
|
||||||
|
|
||||||
val event = RecipientListGetEvent(
|
|
||||||
data.profileId,
|
|
||||||
data.teacherList.filter { it.loginId != null }
|
|
||||||
)
|
|
||||||
|
|
||||||
profile?.lastReceiversSync = System.currentTimeMillis()
|
|
||||||
|
|
||||||
data.teacherOnConflictStrategy = OnConflictStrategy.REPLACE
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import android.graphics.Color
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_NORMAL
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikWebGrades(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebGrades"
|
|
||||||
}
|
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_GRADES, mapOf(
|
|
||||||
"idPozDziennika" to data.registerId
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("Przedmioty")?.asJsonObjectList()?.onEach { subjectJson ->
|
|
||||||
val subject = data.getSubject(
|
|
||||||
subjectJson.getString("Przedmiot") ?: return@onEach,
|
|
||||||
subjectJson.getLong("IdPrzedmiotu") ?: return@onEach,
|
|
||||||
subjectJson.getString("Przedmiot") ?: return@onEach
|
|
||||||
)
|
|
||||||
subjectJson.getJsonArray("Oceny")?.asJsonObjectList()?.forEach { grade ->
|
|
||||||
val id = grade.getLong("idK") ?: return@forEach
|
|
||||||
val category = grade.getString("Kategoria") ?: ""
|
|
||||||
val name = grade.getString("Ocena") ?: "?"
|
|
||||||
val semester = grade.getInt("Semestr") ?: 1
|
|
||||||
val teacher = data.getTeacherByLastFirst(grade.getString("Wystawil") ?: return@forEach)
|
|
||||||
|
|
||||||
val countToAverage = grade.getBoolean("DoSredniej") ?: true
|
|
||||||
var value = grade.getFloat("WartoscDoSred") ?: 0.0f
|
|
||||||
val weight = if (countToAverage)
|
|
||||||
grade.getFloat("Waga") ?: 0.0f
|
|
||||||
else
|
|
||||||
0.0f
|
|
||||||
|
|
||||||
val gradeColor = grade.getString("Kolor") ?: ""
|
|
||||||
var colorInt = 0xff2196f3.toInt()
|
|
||||||
if (gradeColor.isNotEmpty()) {
|
|
||||||
colorInt = Color.parseColor("#$gradeColor")
|
|
||||||
}
|
|
||||||
|
|
||||||
val addedDate = grade.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
|
||||||
|
|
||||||
val gradeObject = Grade(
|
|
||||||
profileId = profileId,
|
|
||||||
id = id,
|
|
||||||
name = name,
|
|
||||||
type = TYPE_NORMAL,
|
|
||||||
value = value,
|
|
||||||
weight = weight,
|
|
||||||
color = colorInt,
|
|
||||||
category = category,
|
|
||||||
description = null,
|
|
||||||
comment = null,
|
|
||||||
semester = semester,
|
|
||||||
teacherId = teacher.id,
|
|
||||||
subjectId = subject.id,
|
|
||||||
addedDate = addedDate
|
|
||||||
)
|
|
||||||
|
|
||||||
when (grade.getInt("Typ")) {
|
|
||||||
0 -> {
|
|
||||||
val history = grade.getJsonArray("Historia")?.asJsonObjectList()
|
|
||||||
if (history?.isNotEmpty() == true) {
|
|
||||||
var sum = gradeObject.value * gradeObject.weight
|
|
||||||
var count = gradeObject.weight
|
|
||||||
for (historyItem in history) {
|
|
||||||
val countToTheAverage = historyItem.getBoolean("DoSredniej") ?: false
|
|
||||||
value = historyItem.get("WartoscDoSred").asFloat
|
|
||||||
val weight = historyItem.get("Waga").asFloat
|
|
||||||
|
|
||||||
if (value > 0 && countToTheAverage) {
|
|
||||||
sum += value * weight
|
|
||||||
count += weight
|
|
||||||
}
|
|
||||||
|
|
||||||
val historyColor = historyItem.getString("Kolor") ?: ""
|
|
||||||
colorInt = 0xff2196f3.toInt()
|
|
||||||
if (historyColor.isNotEmpty()) {
|
|
||||||
colorInt = Color.parseColor("#$historyColor")
|
|
||||||
}
|
|
||||||
|
|
||||||
val addedDate = historyItem.getString("Data_wystaw")?.let { Date.fromY_m_d(it).inMillis } ?: System.currentTimeMillis()
|
|
||||||
|
|
||||||
val historyObject = Grade(
|
|
||||||
profileId = profileId,
|
|
||||||
id = gradeObject.id * -1,
|
|
||||||
name = historyItem.getString("Ocena") ?: "",
|
|
||||||
type = TYPE_NORMAL,
|
|
||||||
value = value,
|
|
||||||
weight = if (value > 0f && countToTheAverage) weight * -1f else 0f,
|
|
||||||
color = colorInt,
|
|
||||||
category = historyItem.getString("Kategoria"),
|
|
||||||
description = historyItem.getString("Uzasadnienie"),
|
|
||||||
comment = null,
|
|
||||||
semester = historyItem.getInt("Semestr") ?: 1,
|
|
||||||
teacherId = teacher.id,
|
|
||||||
subjectId = subject.id,
|
|
||||||
addedDate = addedDate
|
|
||||||
)
|
|
||||||
historyObject.parentId = gradeObject.id
|
|
||||||
|
|
||||||
data.gradeList.add(historyObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_GRADE,
|
|
||||||
historyObject.id,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
))
|
|
||||||
}
|
|
||||||
// update the current grade's value with an average of all historical grades and itself
|
|
||||||
if (sum > 0 && count > 0) {
|
|
||||||
gradeObject.value = sum / count
|
|
||||||
}
|
|
||||||
gradeObject.isImprovement = true // gradeObject is the improved grade. Originals are historyObjects
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
gradeObject.type = Grade.TYPE_SEMESTER1_FINAL
|
|
||||||
gradeObject.name = value.toInt().toString()
|
|
||||||
gradeObject.weight = 0f
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
gradeObject.type = Grade.TYPE_YEAR_FINAL
|
|
||||||
gradeObject.name = value.toInt().toString()
|
|
||||||
gradeObject.weight = 0f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.gradeList.add(gradeObject)
|
|
||||||
data.metadataList.add(
|
|
||||||
Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_GRADE,
|
|
||||||
id,
|
|
||||||
data.profile.empty,
|
|
||||||
data.profile.empty
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.toRemove.addAll(listOf(
|
|
||||||
Grade.TYPE_NORMAL,
|
|
||||||
Grade.TYPE_SEMESTER1_FINAL,
|
|
||||||
Grade.TYPE_YEAR_FINAL
|
|
||||||
).map {
|
|
||||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
|
||||||
})
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_GRADES)
|
|
||||||
}
|
|
||||||
} ?: onSuccess(ENDPOINT_IDZIENNIK_WEB_GRADES) }
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-25
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_HOMEWORK
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_HOMEWORK
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikWebHomework(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebHomework"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val param = JsonObject().apply {
|
|
||||||
addProperty("strona", 1)
|
|
||||||
addProperty("iloscNaStrone", 997)
|
|
||||||
addProperty("iloscRekordow", -1)
|
|
||||||
addProperty("kolumnaSort", "DataZadania")
|
|
||||||
addProperty("kierunekSort", 0)
|
|
||||||
addProperty("maxIloscZaznaczonych", 0)
|
|
||||||
addProperty("panelFiltrow", 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_HOMEWORK, mapOf(
|
|
||||||
"idP" to data.registerId,
|
|
||||||
"data" to Date.getToday().stringY_m_d,
|
|
||||||
"wszystkie" to true,
|
|
||||||
"param" to param
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("ListK")?.asJsonObjectList()?.forEach { homework ->
|
|
||||||
val id = homework.getLong("_recordId") ?: return@forEach
|
|
||||||
val eventDate = Date.fromY_m_d(homework.getString("dataO") ?: return@forEach)
|
|
||||||
val addedDate = Date.fromY_m_d(homework.getString("dataZ") ?: return@forEach)
|
|
||||||
val subjectName = homework.getString("przed") ?: return@forEach
|
|
||||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
|
||||||
val teacherName = homework.getString("usr") ?: return@forEach
|
|
||||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
|
||||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
|
||||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.displayStartTime
|
|
||||||
val topic = homework.getString("tytul")?.trim() ?: ""
|
|
||||||
|
|
||||||
val seen = when (profile?.empty) {
|
|
||||||
true -> true
|
|
||||||
else -> eventDate < Date.getToday()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val eventObject = Event(
|
|
||||||
profileId = profileId,
|
|
||||||
id = id,
|
|
||||||
date = eventDate,
|
|
||||||
time = startTime,
|
|
||||||
topic = topic,
|
|
||||||
color = null,
|
|
||||||
type = Event.TYPE_HOMEWORK,
|
|
||||||
teacherId = teacherId,
|
|
||||||
subjectId = subjectId,
|
|
||||||
teamId = data.teamClass?.id ?: -1,
|
|
||||||
addedDate = addedDate.inMillis
|
|
||||||
)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_HOMEWORK,
|
|
||||||
eventObject.id,
|
|
||||||
seen,
|
|
||||||
seen
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK))
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_HOMEWORK, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_HOMEWORK)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.crc16
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_NOTICES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_NOTICES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_NEGATIVE
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_NEUTRAL
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Notice.Companion.TYPE_POSITIVE
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikWebNotices(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebNotices"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_NOTICES, mapOf(
|
|
||||||
"idPozDziennika" to data.registerId
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
for (jNoticeEl in json.getAsJsonArray("SUwaga")) {
|
|
||||||
val jNotice = jNoticeEl.asJsonObject
|
|
||||||
// jNotice
|
|
||||||
val noticeId = jNotice.get("id").asString.crc16().toLong()
|
|
||||||
|
|
||||||
val rTeacher = data.getTeacherByLastFirst(jNotice.get("Nauczyciel").asString)
|
|
||||||
val addedDate = Date.fromY_m_d(jNotice.get("Data").asString)
|
|
||||||
|
|
||||||
var nType = TYPE_NEUTRAL
|
|
||||||
val jType = jNotice.get("Typ").asString
|
|
||||||
if (jType == "n") {
|
|
||||||
nType = TYPE_NEGATIVE
|
|
||||||
} else if (jType == "p") {
|
|
||||||
nType = TYPE_POSITIVE
|
|
||||||
}
|
|
||||||
|
|
||||||
val noticeObject = Notice(
|
|
||||||
profileId = profileId,
|
|
||||||
id = noticeId,
|
|
||||||
type = nType,
|
|
||||||
semester = jNotice.get("Semestr").asInt,
|
|
||||||
text = jNotice.getString("Tresc") ?: "",
|
|
||||||
category = null,
|
|
||||||
points = null,
|
|
||||||
teacherId = rTeacher.id,
|
|
||||||
addedDate = addedDate.inMillis
|
|
||||||
)
|
|
||||||
|
|
||||||
data.noticeList.add(noticeObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_NOTICE,
|
|
||||||
noticeObject.id,
|
|
||||||
profile?.empty ?: false,
|
|
||||||
profile?.empty ?: false
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_NOTICES, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_NOTICES)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,152 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-28.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_MISSING_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_DESCRIPTIVE
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_SEMESTER1_PROPOSED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Grade.Companion.TYPE_YEAR_PROPOSED
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonArray
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
|
|
||||||
class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebProposedGrades"
|
|
||||||
}
|
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_MISSING_GRADES, mapOf(
|
|
||||||
"idPozDziennika" to data.registerId
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
val manager = data.app.gradesManager
|
|
||||||
|
|
||||||
json.getJsonArray("Przedmioty")?.asJsonObjectList()?.forEach { subject ->
|
|
||||||
val subjectName = subject.getString("Przedmiot") ?: return@forEach
|
|
||||||
val subjectObject = data.getSubject(subjectName, null, subjectName)
|
|
||||||
|
|
||||||
val semester1Proposed = subject.getString("OcenaSem1") ?: ""
|
|
||||||
val semester1Value = manager.getGradeValue(semester1Proposed)
|
|
||||||
val semester1Id = subjectObject.id * (-100) - 1
|
|
||||||
val semester1Type =
|
|
||||||
if (semester1Value == 0f) TYPE_DESCRIPTIVE
|
|
||||||
else TYPE_SEMESTER1_PROPOSED
|
|
||||||
val semester1Name = when {
|
|
||||||
semester1Value == 0f -> " "
|
|
||||||
semester1Value % 1.0f == 0f -> semester1Value.toInt().toString()
|
|
||||||
else -> semester1Value.toString()
|
|
||||||
}
|
|
||||||
val semester1Color =
|
|
||||||
if (semester1Value == 0f) 0xff536dfe.toInt()
|
|
||||||
else -1
|
|
||||||
|
|
||||||
val semester2Proposed = subject.getString("OcenaSem2") ?: ""
|
|
||||||
val semester2Value = manager.getGradeValue(semester2Proposed)
|
|
||||||
val semester2Id = subjectObject.id * (-100) - 2
|
|
||||||
val semester2Type =
|
|
||||||
if (semester2Value == 0f) TYPE_DESCRIPTIVE
|
|
||||||
else TYPE_YEAR_PROPOSED
|
|
||||||
val semester2Name = when {
|
|
||||||
semester2Value == 0f -> " "
|
|
||||||
semester2Value % 1.0f == 0f -> semester2Value.toInt().toString()
|
|
||||||
else -> semester2Value.toString()
|
|
||||||
}
|
|
||||||
val semester2Color =
|
|
||||||
if (semester2Value == 0f) 0xffff4081.toInt()
|
|
||||||
else -1
|
|
||||||
|
|
||||||
if (semester1Proposed != "") {
|
|
||||||
val addedDate = if (data.profile.empty)
|
|
||||||
data.profile.dateSemester1Start.inMillis
|
|
||||||
else
|
|
||||||
System.currentTimeMillis()
|
|
||||||
|
|
||||||
val gradeObject = Grade(
|
|
||||||
profileId = profileId,
|
|
||||||
id = semester1Id,
|
|
||||||
name = semester1Name,
|
|
||||||
type = semester1Type,
|
|
||||||
value = semester1Value,
|
|
||||||
weight = 0f,
|
|
||||||
color = semester1Color,
|
|
||||||
category = if (semester1Value == 0f) "Ocena opisowa semestralna" else null,
|
|
||||||
description = if (semester1Value == 0f) semester1Proposed else null,
|
|
||||||
comment = null,
|
|
||||||
semester = 1,
|
|
||||||
teacherId = -1,
|
|
||||||
subjectId = subjectObject.id,
|
|
||||||
addedDate = addedDate
|
|
||||||
)
|
|
||||||
|
|
||||||
data.gradeList.add(gradeObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_GRADE,
|
|
||||||
gradeObject.id,
|
|
||||||
profile.empty,
|
|
||||||
profile.empty
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (semester2Proposed != "") {
|
|
||||||
val addedDate = if (data.profile.empty)
|
|
||||||
data.profile.dateSemester2Start.inMillis
|
|
||||||
else
|
|
||||||
System.currentTimeMillis()
|
|
||||||
|
|
||||||
val gradeObject = Grade(
|
|
||||||
profileId = profileId,
|
|
||||||
id = semester2Id,
|
|
||||||
name = semester2Name,
|
|
||||||
type = semester2Type,
|
|
||||||
value = semester2Value,
|
|
||||||
weight = 0f,
|
|
||||||
color = semester2Color,
|
|
||||||
category = if (semester2Value == 0f) "Ocena opisowa końcoworoczna" else null,
|
|
||||||
description = if (semester2Value == 0f) semester2Proposed else null,
|
|
||||||
comment = null,
|
|
||||||
semester = 2,
|
|
||||||
teacherId = -1,
|
|
||||||
subjectId = subjectObject.id,
|
|
||||||
addedDate = addedDate
|
|
||||||
)
|
|
||||||
|
|
||||||
data.gradeList.add(gradeObject)
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_GRADE,
|
|
||||||
gradeObject.id,
|
|
||||||
profile.empty,
|
|
||||||
profile.empty
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.toRemove.addAll(listOf(TYPE_SEMESTER1_PROPOSED, TYPE_YEAR_PROPOSED).map {
|
|
||||||
DataRemoveModel.Grades.semesterWithType(profile.currentSemester, it)
|
|
||||||
})
|
|
||||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES)
|
|
||||||
}
|
|
||||||
} ?: onSuccess(ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES) }
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-12-30.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_SEND_MESSAGE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api.IdziennikApiMessagesSent
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.MessageSentEvent
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class IdziennikWebSendMessage(override val data: DataIdziennik,
|
|
||||||
val recipients: List<Teacher>,
|
|
||||||
val subject: String,
|
|
||||||
val text: String,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebSendMessage"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val recipientsArray = JsonArray()
|
|
||||||
for (teacher in recipients) {
|
|
||||||
teacher.loginId?.let {
|
|
||||||
recipientsArray += it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_SEND_MESSAGE, mapOf(
|
|
||||||
"Wiadomosc" to JsonObject(
|
|
||||||
"Tytul" to subject,
|
|
||||||
"Tresc" to text,
|
|
||||||
"Confirmation" to false,
|
|
||||||
"GuidMessage" to UUID.randomUUID().toString().toUpperCase(Locale.ROOT),
|
|
||||||
"Odbiorcy" to recipientsArray
|
|
||||||
)
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.getBoolean("CzyJestBlad") != false) {
|
|
||||||
// TODO error
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
IdziennikApiMessagesSent(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 == message?.id }
|
|
||||||
val event = MessageSentEvent(data.profileId, message, message?.addedDate)
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(event)
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_HOME
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.get
|
|
||||||
import pl.szczodrzynski.edziennik.getString
|
|
||||||
|
|
||||||
class IdziennikWebSwitchRegister(override val data: DataIdziennik,
|
|
||||||
val registerId: Int,
|
|
||||||
val onSuccess: () -> Unit
|
|
||||||
) : IdziennikWeb(data, null) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebSwitchRegister"
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
val hiddenFields = data.loginStore.getLoginData("hiddenFields", JsonObject())
|
|
||||||
// TODO error checking
|
|
||||||
|
|
||||||
webGet(TAG, IDZIENNIK_WEB_HOME, mapOf(
|
|
||||||
"__VIEWSTATE" to hiddenFields.getString("__VIEWSTATE", ""),
|
|
||||||
"__VIEWSTATEGENERATOR" to hiddenFields.getString("__VIEWSTATEGENERATOR", ""),
|
|
||||||
"__EVENTVALIDATION" to hiddenFields.getString("__EVENTVALIDATION", ""),
|
|
||||||
"ctl00\$dxComboUczniowie" to registerId
|
|
||||||
)) { text ->
|
|
||||||
Regexes.IDZIENNIK_WEB_SELECTED_REGISTER.find(text)?.let {
|
|
||||||
val registerId = it[1].toIntOrNull() ?: return@let
|
|
||||||
data.webSelectedRegister = registerId
|
|
||||||
}
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,194 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-22
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.web
|
|
||||||
|
|
||||||
import androidx.core.util.set
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_TIMETABLE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_WEB_TIMETABLE
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.LessonRange
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
|
||||||
|
|
||||||
class IdziennikWebTimetable(override val data: DataIdziennik,
|
|
||||||
override val lastSync: Long?,
|
|
||||||
val onSuccess: (endpointId: Int) -> Unit
|
|
||||||
) : IdziennikWeb(data, lastSync) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikWebTimetable"
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
webApiGet(TAG, IDZIENNIK_WEB_TIMETABLE, mapOf(
|
|
||||||
"idPozDziennika" to data.registerId,
|
|
||||||
"pidRokSzkolny" to data.schoolYearId,
|
|
||||||
"data" to "${weekStart.stringY_m_d}T10:00:00.000Z"
|
|
||||||
)) { result ->
|
|
||||||
val json = result.getJsonObject("d") ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA)
|
|
||||||
.withApiResponse(result))
|
|
||||||
return@webApiGet
|
|
||||||
}
|
|
||||||
|
|
||||||
json.getJsonArray("GodzinyLekcyjne")?.asJsonObjectList()?.forEachIndexed { index, range ->
|
|
||||||
val lessonRange = LessonRange(
|
|
||||||
profileId,
|
|
||||||
index + 1,
|
|
||||||
range.getString("Poczatek")?.let { Time.fromH_m(it) }
|
|
||||||
?: return@forEachIndexed,
|
|
||||||
range.getString("Koniec")?.let { Time.fromH_m(it) } ?: return@forEachIndexed
|
|
||||||
)
|
|
||||||
data.lessonRanges[lessonRange.lessonNumber] = lessonRange
|
|
||||||
}
|
|
||||||
|
|
||||||
val dates = mutableSetOf<Int>()
|
|
||||||
val lessons = mutableListOf<Lesson>()
|
|
||||||
|
|
||||||
json.getJsonArray("Przedmioty")?.asJsonObjectList()?.forEach { lesson ->
|
|
||||||
val subject = data.getSubject(
|
|
||||||
lesson.getString("Nazwa") ?: return@forEach,
|
|
||||||
lesson.getLong("Id"),
|
|
||||||
lesson.getString("Skrot") ?: ""
|
|
||||||
)
|
|
||||||
val teacher = data.getTeacherByFDotLast(lesson.getString("Nauczyciel")
|
|
||||||
?: return@forEach)
|
|
||||||
|
|
||||||
val newSubjectName = lesson.getString("PrzedmiotZastepujacy")
|
|
||||||
val newSubject = when (newSubjectName.isNullOrBlank()) {
|
|
||||||
true -> null
|
|
||||||
else -> data.getSubject(newSubjectName, null, newSubjectName)
|
|
||||||
}
|
|
||||||
|
|
||||||
val newTeacherName = lesson.getString("NauZastepujacy")
|
|
||||||
val newTeacher = when (newTeacherName.isNullOrBlank()) {
|
|
||||||
true -> null
|
|
||||||
else -> data.getTeacherByFDotLast(newTeacherName)
|
|
||||||
}
|
|
||||||
|
|
||||||
val weekDay = lesson.getInt("DzienTygodnia")?.minus(1) ?: return@forEach
|
|
||||||
val lessonRange = data.lessonRanges[lesson.getInt("Godzina")?.plus(1)
|
|
||||||
?: return@forEach]
|
|
||||||
val lessonDate = weekStart.clone().stepForward(0, 0, weekDay)
|
|
||||||
val classroom = lesson.getString("NazwaSali")
|
|
||||||
|
|
||||||
val type = lesson.getInt("TypZastepstwa") ?: -1
|
|
||||||
|
|
||||||
val lessonObject = Lesson(profileId, -1)
|
|
||||||
|
|
||||||
when (type) {
|
|
||||||
1, 2, 3, 4, 5 -> {
|
|
||||||
lessonObject.apply {
|
|
||||||
this.type = Lesson.TYPE_CHANGE
|
|
||||||
|
|
||||||
this.date = lessonDate
|
|
||||||
this.lessonNumber = lessonRange.lessonNumber
|
|
||||||
this.startTime = lessonRange.startTime
|
|
||||||
this.endTime = lessonRange.endTime
|
|
||||||
this.subjectId = newSubject?.id
|
|
||||||
this.teacherId = newTeacher?.id
|
|
||||||
this.teamId = data.teamClass?.id
|
|
||||||
this.classroom = classroom
|
|
||||||
|
|
||||||
this.oldDate = lessonDate
|
|
||||||
this.oldLessonNumber = lessonRange.lessonNumber
|
|
||||||
this.oldStartTime = lessonRange.startTime
|
|
||||||
this.oldEndTime = lessonRange.endTime
|
|
||||||
this.oldSubjectId = subject.id
|
|
||||||
this.oldTeacherId = teacher.id
|
|
||||||
this.oldTeamId = data.teamClass?.id
|
|
||||||
this.oldClassroom = classroom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
0 -> {
|
|
||||||
lessonObject.apply {
|
|
||||||
this.type = Lesson.TYPE_CANCELLED
|
|
||||||
|
|
||||||
this.oldDate = lessonDate
|
|
||||||
this.oldLessonNumber = lessonRange.lessonNumber
|
|
||||||
this.oldStartTime = lessonRange.startTime
|
|
||||||
this.oldEndTime = lessonRange.endTime
|
|
||||||
this.oldSubjectId = subject.id
|
|
||||||
this.oldTeacherId = teacher.id
|
|
||||||
this.oldTeamId = data.teamClass?.id
|
|
||||||
this.oldClassroom = classroom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
lessonObject.apply {
|
|
||||||
this.type = Lesson.TYPE_NORMAL
|
|
||||||
|
|
||||||
this.date = lessonDate
|
|
||||||
this.lessonNumber = lessonRange.lessonNumber
|
|
||||||
this.startTime = lessonRange.startTime
|
|
||||||
this.endTime = lessonRange.endTime
|
|
||||||
this.subjectId = subject.id
|
|
||||||
this.teacherId = teacher.id
|
|
||||||
this.teamId = data.teamClass?.id
|
|
||||||
this.classroom = classroom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lessonObject.id = lessonObject.buildId()
|
|
||||||
|
|
||||||
dates.add(lessonDate.value)
|
|
||||||
lessons.add(lessonObject)
|
|
||||||
|
|
||||||
val seen = profile.empty || lessonDate < Date.getToday()
|
|
||||||
|
|
||||||
if (lessonObject.type != Lesson.TYPE_NORMAL && lessonDate >= Date.getToday()) {
|
|
||||||
data.metadataList.add(Metadata(
|
|
||||||
profileId,
|
|
||||||
Metadata.TYPE_LESSON_CHANGE,
|
|
||||||
lessonObject.id,
|
|
||||||
seen,
|
|
||||||
seen
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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_IDZIENNIK_WEB_TIMETABLE, SYNC_ALWAYS)
|
|
||||||
onSuccess(ENDPOINT_IDZIENNIK_WEB_TIMETABLE)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-27.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.firstlogin
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_LOGIN_IDZIENNIK_FIRST_NO_SCHOOL_YEAR
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_WEB_SETTINGS
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_IDZIENNIK
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikWeb
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login.IdziennikLoginWeb
|
|
||||||
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.fixName
|
|
||||||
import pl.szczodrzynski.edziennik.get
|
|
||||||
import pl.szczodrzynski.edziennik.set
|
|
||||||
import pl.szczodrzynski.edziennik.swapFirstLastName
|
|
||||||
|
|
||||||
class IdziennikFirstLogin(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikFirstLogin"
|
|
||||||
}
|
|
||||||
|
|
||||||
private val web = IdziennikWeb(data, null)
|
|
||||||
private val profileList = mutableListOf<Profile>()
|
|
||||||
|
|
||||||
init {
|
|
||||||
val loginStoreId = data.loginStore.id
|
|
||||||
val loginStoreType = LOGIN_TYPE_IDZIENNIK
|
|
||||||
var firstProfileId = loginStoreId
|
|
||||||
|
|
||||||
IdziennikLoginWeb(data) {
|
|
||||||
web.webGet(TAG, IDZIENNIK_WEB_SETTINGS) { text ->
|
|
||||||
//val accounts = json.getJsonArray("accounts")
|
|
||||||
|
|
||||||
val isParent = Regexes.IDZIENNIK_LOGIN_FIRST_IS_PARENT.find(text)?.get(1) != "0"
|
|
||||||
val accountNameLong = if (isParent)
|
|
||||||
Regexes.IDZIENNIK_LOGIN_FIRST_ACCOUNT_NAME.find(text)?.get(1)?.swapFirstLastName()?.fixName()
|
|
||||||
else null
|
|
||||||
|
|
||||||
var schoolYearStart: Int? = null
|
|
||||||
var schoolYearEnd: Int? = null
|
|
||||||
var schoolYearName: String? = null
|
|
||||||
val schoolYearId = Regexes.IDZIENNIK_LOGIN_FIRST_SCHOOL_YEAR.find(text)?.let {
|
|
||||||
schoolYearName = it[2]+"/"+it[3]
|
|
||||||
schoolYearStart = it[2].toIntOrNull()
|
|
||||||
schoolYearEnd = it[3].toIntOrNull()
|
|
||||||
it[1].toIntOrNull()
|
|
||||||
} ?: run {
|
|
||||||
data.error(ApiError(TAG, ERROR_LOGIN_IDZIENNIK_FIRST_NO_SCHOOL_YEAR)
|
|
||||||
.withApiResponse(text))
|
|
||||||
return@webGet
|
|
||||||
}
|
|
||||||
|
|
||||||
Regexes.IDZIENNIK_LOGIN_FIRST_STUDENT.findAll(text)
|
|
||||||
.toMutableList()
|
|
||||||
.reversed()
|
|
||||||
.forEach { match ->
|
|
||||||
val registerId = match[1].toIntOrNull() ?: return@forEach
|
|
||||||
val studentId = match[2]
|
|
||||||
val firstName = match[3]
|
|
||||||
val lastName = match[4]
|
|
||||||
val className = match[5] + " " + match[6]
|
|
||||||
|
|
||||||
val studentNameLong = "$firstName $lastName".fixName()
|
|
||||||
val studentNameShort = "$firstName ${lastName[0]}.".fixName()
|
|
||||||
val accountName = if (accountNameLong == studentNameLong) null else accountNameLong
|
|
||||||
|
|
||||||
val profile = Profile(
|
|
||||||
firstProfileId++,
|
|
||||||
loginStoreId,
|
|
||||||
loginStoreType,
|
|
||||||
studentNameLong,
|
|
||||||
data.webUsername,
|
|
||||||
studentNameLong,
|
|
||||||
studentNameShort,
|
|
||||||
accountName
|
|
||||||
).apply {
|
|
||||||
schoolYearStart?.let { studentSchoolYearStart = it }
|
|
||||||
studentClassName = className
|
|
||||||
studentData["studentId"] = studentId
|
|
||||||
studentData["registerId"] = registerId
|
|
||||||
studentData["schoolYearId"] = schoolYearId
|
|
||||||
}
|
|
||||||
profileList.add(profile)
|
|
||||||
}
|
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(FirstLoginFinishedEvent(profileList, data.loginStore))
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-25.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_IDZIENNIK_API
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_IDZIENNIK_WEB
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
|
|
||||||
class IdziennikLogin(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikLogin"
|
|
||||||
}
|
|
||||||
|
|
||||||
private var cancelled = false
|
|
||||||
|
|
||||||
init {
|
|
||||||
nextLoginMethod(onSuccess)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun nextLoginMethod(onSuccess: () -> Unit) {
|
|
||||||
if (data.targetLoginMethodIds.isEmpty()) {
|
|
||||||
onSuccess()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
|
||||||
data.progress(data.progressStep)
|
|
||||||
if (usedMethodId != -1)
|
|
||||||
data.loginMethods.add(usedMethodId)
|
|
||||||
nextLoginMethod(onSuccess)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun useLoginMethod(loginMethodId: Int, onSuccess: (usedMethodId: Int) -> Unit) {
|
|
||||||
// this should never be true
|
|
||||||
if (data.loginMethods.contains(loginMethodId)) {
|
|
||||||
onSuccess(-1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Utils.d(TAG, "Using login method $loginMethodId")
|
|
||||||
when (loginMethodId) {
|
|
||||||
LOGIN_METHOD_IDZIENNIK_WEB -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_login_idziennik_web)
|
|
||||||
IdziennikLoginWeb(data) { onSuccess(loginMethodId) }
|
|
||||||
}
|
|
||||||
LOGIN_METHOD_IDZIENNIK_API -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_login_idziennik_api)
|
|
||||||
IdziennikLoginApi(data) { onSuccess(loginMethodId) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-27.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
|
|
||||||
class IdziennikLoginApi(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikLoginApi"
|
|
||||||
}
|
|
||||||
|
|
||||||
init { run {
|
|
||||||
if (data.isApiLoginValid()) {
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
}
|
|
@ -1,178 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) Kuba Szczodrzyński 2019-10-26.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.login
|
|
||||||
|
|
||||||
import im.wangchao.mhttp.Request
|
|
||||||
import im.wangchao.mhttp.Response
|
|
||||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
|
||||||
|
|
||||||
class IdziennikLoginWeb(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "IdziennikLoginWeb"
|
|
||||||
}
|
|
||||||
|
|
||||||
init { run {
|
|
||||||
if (data.isWebLoginValid()) {
|
|
||||||
data.app.cookieJar.set("iuczniowie.progman.pl", "ASP.NET_SessionId_iDziennik", data.webSessionId)
|
|
||||||
data.app.cookieJar.set("iuczniowie.progman.pl", ".ASPXAUTH", data.webAuth)
|
|
||||||
onSuccess()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
data.app.cookieJar.clear("iuczniowie.progman.pl")
|
|
||||||
if (data.webSchoolName != null && data.webUsername != null && data.webPassword != null) {
|
|
||||||
loginWithCredentials()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
data.error(ApiError(TAG, ERROR_LOGIN_DATA_MISSING))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
|
|
||||||
private fun loginWithCredentials() {
|
|
||||||
Utils.d(TAG, "Request: Idziennik/Login/Web - $IDZIENNIK_WEB_URL/$IDZIENNIK_WEB_LOGIN")
|
|
||||||
|
|
||||||
val loginCallback = object : TextCallbackHandler() {
|
|
||||||
override fun onSuccess(text: String?, response: Response?) {
|
|
||||||
if (text.isNullOrEmpty()) {
|
|
||||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// login succeeded: there is a start page
|
|
||||||
if (text.contains("czyWyswietlicDostepMobilny")) {
|
|
||||||
val cookies = data.app.cookieJar.getAll("iuczniowie.progman.pl")
|
|
||||||
run {
|
|
||||||
data.webSessionId = cookies["ASP.NET_SessionId_iDziennik"] ?: return@run ERROR_LOGIN_IDZIENNIK_WEB_NO_SESSION
|
|
||||||
data.webAuth = cookies[".ASPXAUTH"] ?: return@run ERROR_LOGIN_IDZIENNIK_WEB_NO_AUTH
|
|
||||||
data.apiBearer = cookies["Bearer"]?: return@run ERROR_LOGIN_IDZIENNIK_WEB_NO_BEARER
|
|
||||||
data.loginExpiryTime = response.getUnixDate() + 30 * MINUTE /* after about 40 minutes the login didn't work already */
|
|
||||||
data.apiExpiryTime = response.getUnixDate() + 12 * HOUR /* actually it expires after 24 hours but I'm not sure when does the token refresh. */
|
|
||||||
|
|
||||||
val hiddenFields = JsonObject()
|
|
||||||
Regexes.IDZIENNIK_LOGIN_HIDDEN_FIELDS.findAll(text).forEach {
|
|
||||||
hiddenFields[it[1]] = it[2]
|
|
||||||
}
|
|
||||||
data.loginStore.putLoginData("hiddenFields", hiddenFields)
|
|
||||||
|
|
||||||
Regexes.IDZIENNIK_WEB_SELECTED_REGISTER.find(text)?.let {
|
|
||||||
val registerId = it[1].toIntOrNull() ?: return@let
|
|
||||||
data.webSelectedRegister = registerId
|
|
||||||
}
|
|
||||||
|
|
||||||
// for profiles created after archiving
|
|
||||||
data.schoolYearId = Regexes.IDZIENNIK_LOGIN_FIRST_SCHOOL_YEAR.find(text)?.let {
|
|
||||||
it[1].toIntOrNull()
|
|
||||||
} ?: data.schoolYearId
|
|
||||||
data.profile?.studentClassName = Regexes.IDZIENNIK_LOGIN_FIRST_STUDENT.findAll(text)
|
|
||||||
.firstOrNull { it[1].toIntOrNull() == data.registerId }
|
|
||||||
?.let { "${it[5]} ${it[6]}" } ?: data.profile?.studentClassName
|
|
||||||
|
|
||||||
data.profile?.let { profile ->
|
|
||||||
Regexes.IDZIENNIK_WEB_LUCKY_NUMBER.find(text)?.also {
|
|
||||||
val number = it[1].toIntOrNull() ?: return@also
|
|
||||||
val luckyNumberObject = LuckyNumber(
|
|
||||||
profileId = data.profileId,
|
|
||||||
date = Date.getToday(),
|
|
||||||
number = number
|
|
||||||
)
|
|
||||||
|
|
||||||
data.luckyNumberList.add(luckyNumberObject)
|
|
||||||
data.metadataList.add(
|
|
||||||
Metadata(
|
|
||||||
profile.id,
|
|
||||||
Metadata.TYPE_LUCKY_NUMBER,
|
|
||||||
luckyNumberObject.date.value.toLong(),
|
|
||||||
true,
|
|
||||||
profile.empty
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return@run null
|
|
||||||
}?.let { errorCode ->
|
|
||||||
data.error(ApiError(TAG, errorCode)
|
|
||||||
.withApiResponse(text)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
onSuccess()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val errorText = Regexes.IDZIENNIK_LOGIN_ERROR.find(text)?.get(1)
|
|
||||||
when {
|
|
||||||
errorText?.contains("nieprawidłową nazwę szkoły") == true -> ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME
|
|
||||||
errorText?.contains("nieprawidłowy login lub hasło") == true -> ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN
|
|
||||||
text.contains("Identyfikator zgłoszenia") -> ERROR_LOGIN_IDZIENNIK_WEB_SERVER_ERROR
|
|
||||||
text.contains("Hasło dostępu do systemu wygasło") -> ERROR_LOGIN_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED
|
|
||||||
text.contains("Trwają prace konserwacyjne") -> ERROR_LOGIN_IDZIENNIK_WEB_MAINTENANCE
|
|
||||||
else -> ERROR_LOGIN_IDZIENNIK_WEB_OTHER
|
|
||||||
}.let { errorCode ->
|
|
||||||
data.error(ApiError(TAG, errorCode)
|
|
||||||
.withApiResponse(text)
|
|
||||||
.withResponse(response))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
|
||||||
data.error(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(throwable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val getCallback = object : TextCallbackHandler() {
|
|
||||||
override fun onSuccess(text: String?, response: Response?) {
|
|
||||||
Request.builder()
|
|
||||||
.url("$IDZIENNIK_WEB_URL/$IDZIENNIK_WEB_LOGIN")
|
|
||||||
.userAgent(IDZIENNIK_USER_AGENT)
|
|
||||||
.addHeader("Origin", "https://iuczniowie.progman.pl")
|
|
||||||
.addHeader("Referer", "$IDZIENNIK_WEB_URL/$IDZIENNIK_WEB_LOGIN")
|
|
||||||
.apply {
|
|
||||||
Regexes.IDZIENNIK_LOGIN_HIDDEN_FIELDS.findAll(text ?: return@apply).forEach {
|
|
||||||
addParameter(it[1], it[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$nazwaPrzegladarki", IDZIENNIK_USER_AGENT)
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$NazwaSzkoly", data.webSchoolName)
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$UserName", data.webUsername)
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$Password", data.webPassword)
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$captcha", "")
|
|
||||||
.addParameter("ctl00\$ContentPlaceHolder\$Logowanie", "Zaloguj")
|
|
||||||
.post()
|
|
||||||
.allowErrorCode(502)
|
|
||||||
.callback(loginCallback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
|
||||||
data.error(ApiError(TAG, ERROR_REQUEST_FAILURE)
|
|
||||||
.withResponse(response)
|
|
||||||
.withThrowable(throwable))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Request.builder()
|
|
||||||
.url("$IDZIENNIK_WEB_URL/$IDZIENNIK_WEB_LOGIN")
|
|
||||||
.userAgent(IDZIENNIK_USER_AGENT)
|
|
||||||
.get()
|
|
||||||
.allowErrorCode(502)
|
|
||||||
.callback(getCallback)
|
|
||||||
.build()
|
|
||||||
.enqueue()
|
|
||||||
}
|
|
||||||
}
|
|
@ -270,51 +270,6 @@ object LoginInfo {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Register(
|
Register(
|
||||||
loginType = LOGIN_TYPE_EDUDZIENNIK,
|
loginType = LOGIN_TYPE_EDUDZIENNIK,
|
||||||
internalName = "edudziennik",
|
internalName = "edudziennik",
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB |
Binary file not shown.
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB |
@ -143,28 +143,6 @@
|
|||||||
<string name="error_365" translatable="false">ERROR_VULCAN_HEBE_ENTITY_NOT_FOUND</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_390" translatable="false">ERROR_VULCAN_API_DEPRECATED</string>
|
||||||
|
|
||||||
<string name="error_401" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_INVALID_LOGIN</string>
|
|
||||||
<string name="error_402" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_INVALID_SCHOOL_NAME</string>
|
|
||||||
<string name="error_403" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED</string>
|
|
||||||
<string name="error_404" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_MAINTENANCE</string>
|
|
||||||
<string name="error_405" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_SERVER_ERROR</string>
|
|
||||||
<string name="error_410" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_OTHER</string>
|
|
||||||
<string name="error_411" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_API_NO_ACCESS</string>
|
|
||||||
<string name="error_420" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_NO_SESSION</string>
|
|
||||||
<string name="error_421" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_NO_AUTH</string>
|
|
||||||
<string name="error_422" translatable="false">ERROR_LOGIN_IDZIENNIK_WEB_NO_BEARER</string>
|
|
||||||
<string name="error_430" translatable="false">ERROR_IDZIENNIK_WEB_ACCESS_DENIED</string>
|
|
||||||
<string name="error_431" translatable="false">ERROR_IDZIENNIK_WEB_OTHER</string>
|
|
||||||
<string name="error_432" translatable="false">ERROR_IDZIENNIK_WEB_MAINTENANCE</string>
|
|
||||||
<string name="error_433" translatable="false">ERROR_IDZIENNIK_WEB_SERVER_ERROR</string>
|
|
||||||
<string name="error_434" translatable="false">ERROR_IDZIENNIK_WEB_PASSWORD_CHANGE_NEEDED</string>
|
|
||||||
<string name="error_440" translatable="false">ERROR_LOGIN_IDZIENNIK_FIRST_NO_SCHOOL_YEAR</string>
|
|
||||||
<string name="error_441" translatable="false">ERROR_IDZIENNIK_WEB_REQUEST_NO_DATA</string>
|
|
||||||
<string name="error_450" translatable="false">ERROR_IDZIENNIK_API_ACCESS_DENIED</string>
|
|
||||||
<string name="error_451" translatable="false">ERROR_IDZIENNIK_API_OTHER</string>
|
|
||||||
<string name="error_452" translatable="false">ERROR_IDZIENNIK_API_NO_REGISTER</string>
|
|
||||||
<string name="error_453" translatable="false">ERROR_IDZIENNIK_WEB_RECIPIENT_LIST_NO_PERMISSION</string>
|
|
||||||
|
|
||||||
<string name="error_501" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN</string>
|
<string name="error_501" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN</string>
|
||||||
<string name="error_510" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER</string>
|
<string name="error_510" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER</string>
|
||||||
<string name="error_511" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID</string>
|
<string name="error_511" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID</string>
|
||||||
@ -191,9 +169,6 @@
|
|||||||
<string name="error_909" translatable="false">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
<string name="error_909" translatable="false">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
||||||
<string name="error_910" translatable="false">EXCEPTION_NOTIFY</string>
|
<string name="error_910" translatable="false">EXCEPTION_NOTIFY</string>
|
||||||
<string name="error_911" translatable="false">EXCEPTION_LIBRUS_MESSAGES_REQUEST</string>
|
<string name="error_911" translatable="false">EXCEPTION_LIBRUS_MESSAGES_REQUEST</string>
|
||||||
<string name="error_912" translatable="false">EXCEPTION_IDZIENNIK_WEB_REQUEST</string>
|
|
||||||
<string name="error_913" translatable="false">EXCEPTION_IDZIENNIK_WEB_API_REQUEST</string>
|
|
||||||
<string name="error_914" translatable="false">EXCEPTION_IDZIENNIK_API_REQUEST</string>
|
|
||||||
<string name="error_920" translatable="false">EXCEPTION_EDUDZIENNIK_WEB_REQUEST</string>
|
<string name="error_920" translatable="false">EXCEPTION_EDUDZIENNIK_WEB_REQUEST</string>
|
||||||
<string name="error_921" translatable="false">EXCEPTION_EDUDZIENNIK_FILE_REQUEST</string>
|
<string name="error_921" translatable="false">EXCEPTION_EDUDZIENNIK_FILE_REQUEST</string>
|
||||||
<string name="error_930" translatable="false">ERROR_ONEDRIVE_DOWNLOAD</string>
|
<string name="error_930" translatable="false">ERROR_ONEDRIVE_DOWNLOAD</string>
|
||||||
@ -342,28 +317,6 @@
|
|||||||
<string name="error_365_reason">VULCAN®: nie znaleziono bytu</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_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>
|
|
||||||
<string name="error_402_reason">Nieprawidłowa nazwa szkoły</string>
|
|
||||||
<string name="error_403_reason">iDziennik: wymagana zmiana hasła. Zaloguj się na stronie iDziennika, by dokonać zmiany hasła.</string>
|
|
||||||
<string name="error_404_reason">Chwilowa przerwa techniczna iDziennika, lub inny problem z serwerem</string>
|
|
||||||
<string name="error_405_reason">Chwilowa przerwa techniczna iDziennika, lub inny problem z serwerem (serwer zwrócił błąd)</string>
|
|
||||||
<string name="error_410_reason">iDziennik: inny błąd logowania</string>
|
|
||||||
<string name="error_411_reason">iDziennik: brak dostępu do API</string>
|
|
||||||
<string name="error_420_reason">iDziennik: nie znaleziono sesji</string>
|
|
||||||
<string name="error_421_reason">iDziennik: nie znaleziono tokenu autoryzacji</string>
|
|
||||||
<string name="error_422_reason">iDziennik: nie znaleziono tokenu API</string>
|
|
||||||
<string name="error_430_reason">iDziennik: brak dostępu. Zaloguj się ponownie.</string>
|
|
||||||
<string name="error_431_reason">iDziennik: inny błąd synchronizacji</string>
|
|
||||||
<string name="error_432_reason">Chwilowa przerwa techniczna iDziennika, lub inny problem z serwerem</string>
|
|
||||||
<string name="error_433_reason">Chwilowa przerwa techniczna iDziennika, lub inny problem z serwerem (serwer zwrócił błąd)</string>
|
|
||||||
<string name="error_434_reason">iDziennik: wymagana zmiana hasła. Zaloguj się na stronie iDziennika, by dokonać zmiany hasła.</string>
|
|
||||||
<string name="error_440_reason">iDziennik: nie znaleziono numeru roku szkolnego. Uczeń może nie być aktywny w aktualnym roku szkolnym.</string>
|
|
||||||
<string name="error_441_reason">iDziennik: serwer nie zwrócił żadnych danych</string>
|
|
||||||
<string name="error_450_reason">Brak dostępu do API iDziennika</string>
|
|
||||||
<string name="error_451_reason">Inny błąd API iDziennika</string>
|
|
||||||
<string name="error_452_reason">iDziennik: nie znaleziono ID dziennika. Zgłoś błąd programiście.</string>
|
|
||||||
<string name="error_453_reason">Twoje konto nie ma uprawnień do wysyłania wiadomości (bądź wystąpił inny błąd serwera iDziennika)</string>
|
|
||||||
|
|
||||||
<string name="error_501_reason">Błędny email lub hasło</string>
|
<string name="error_501_reason">Błędny email lub hasło</string>
|
||||||
<string name="error_510_reason">Inny błąd logowania</string>
|
<string name="error_510_reason">Inny błąd logowania</string>
|
||||||
<string name="error_511_reason">Brak ID sesji</string>
|
<string name="error_511_reason">Brak ID sesji</string>
|
||||||
@ -390,9 +343,6 @@
|
|||||||
<string name="error_909_reason">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
<string name="error_909_reason">EXCEPTION_LIBRUS_MESSAGES_FILE_REQUEST</string>
|
||||||
<string name="error_910_reason">EXCEPTION_NOTIFY</string>
|
<string name="error_910_reason">EXCEPTION_NOTIFY</string>
|
||||||
<string name="error_911_reason">Zgłoś błąd: pobieranie wiadomości LIBRUS®</string>
|
<string name="error_911_reason">Zgłoś błąd: pobieranie wiadomości LIBRUS®</string>
|
||||||
<string name="error_912_reason">EXCEPTION_IDZIENNIK_WEB_REQUEST</string>
|
|
||||||
<string name="error_913_reason">EXCEPTION_IDZIENNIK_WEB_API_REQUEST</string>
|
|
||||||
<string name="error_914_reason">EXCEPTION_IDZIENNIK_API_REQUEST</string>
|
|
||||||
<string name="error_920_reason">Wystąpił błąd</string>
|
<string name="error_920_reason">Wystąpił błąd</string>
|
||||||
<string name="error_921_reason">Wystąpił błąd podczas pobierania pliku</string>
|
<string name="error_921_reason">Wystąpił błąd podczas pobierania pliku</string>
|
||||||
<string name="error_930_reason">Nie udało się pobrać pliku z OneDrive</string>
|
<string name="error_930_reason">Nie udało się pobrać pliku z OneDrive</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user