[API/Gdynia] Add basic implementation of Gdynia e-register.

This commit is contained in:
Kacper Ziubryniewicz 2020-05-17 15:03:13 +02:00
parent 83e1b21ec3
commit cea5071a34
3 changed files with 144 additions and 0 deletions

View File

@ -151,6 +151,10 @@ val podlasieLoginMethods = listOf(
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
)
const val LOGIN_TYPE_GDYNIA = 7
const val LOGIN_MODE_GDYNIA_WEB = 0
const val LOGIN_METHOD_GDYNIA_WEB = 100
val templateLoginMethods = listOf(
LoginMethod(LOGIN_TYPE_TEMPLATE, LOGIN_METHOD_TEMPLATE_WEB, TemplateLoginWeb::class.java)
.withIsPossible { _, _ -> true }

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2020-5-17
*/
package pl.szczodrzynski.edziennik.data.api.edziennik.gdynia
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_GDYNIA_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
class DataGdynia(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
fun isWebLoginValid() = false
override fun satisfyLoginMethods() {
loginMethods.clear()
if (isWebLoginValid())
loginMethods += LOGIN_METHOD_GDYNIA_WEB
}
override fun generateUserCode(): String {
TODO("Not yet implemented")
}
private var mLoginUsername: String? = null
var loginUsername: String?
get() { mLoginUsername = mLoginUsername ?: loginStore.getLoginData("username", null); return mLoginUsername }
set(value) { loginStore.putLoginData("username", value); mLoginUsername = value }
private var mLoginPassword: String? = null
var loginPassword: String?
get() { mLoginPassword = mLoginPassword ?: loginStore.getLoginData("password", null); return mLoginPassword }
set(value) { loginStore.putLoginData("password", value); mLoginPassword = value }
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2020-5-17
*/
package pl.szczodrzynski.edziennik.data.api.edziennik.gdynia
import com.google.gson.JsonObject
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
import pl.szczodrzynski.edziennik.data.api.models.ApiError
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
import pl.szczodrzynski.edziennik.data.db.entity.Profile
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
import pl.szczodrzynski.edziennik.data.db.full.EventFull
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
import pl.szczodrzynski.edziennik.utils.Utils
class Gdynia(val app: App, val profile: Profile?, val loginStore: LoginStore, val callback: EdziennikCallback) : EdziennikInterface {
companion object {
const val TAG = "Gdynia"
}
val internalErrorList = mutableListOf<Int>()
val data: DataGdynia
init {
data = DataGdynia(app, profile, loginStore).apply {
callback = wrapCallback(this@Gdynia.callback)
satisfyLoginMethods()
}
}
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
}
override fun getMessage(message: MessageFull) {
}
override fun sendMessage(recipients: List<Teacher>, subject: String, text: String) {
}
override fun markAllAnnouncementsAsRead() {
}
override fun getAnnouncement(announcement: AnnouncementFull) {
}
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
}
override fun getRecipientList() {
}
override fun getEvent(eventFull: EventFull) {
}
override fun firstLogin() {
TODO("Not yet implemented")
}
override fun cancel() {
Utils.d(TAG, "Cancelled")
data.cancel()
callback.onCompleted()
}
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) {
// TODO Error handling
when (apiError.errorCode) {
in internalErrorList -> {
// finish immediately if the same error occurs twice during the same sync
callback.onError(apiError)
}
else -> callback.onError(apiError)
}
}
}
}
}