From cea5071a3419cc9c02f5543cb9101ca8841e1cc5 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 17 May 2020 15:03:13 +0200 Subject: [PATCH] [API/Gdynia] Add basic implementation of Gdynia e-register. --- .../edziennik/data/api/LoginMethods.kt | 4 + .../data/api/edziennik/gdynia/DataGdynia.kt | 36 ++++++ .../data/api/edziennik/gdynia/Gdynia.kt | 104 ++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/DataGdynia.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/Gdynia.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt index 24444a58..b2f3cd88 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/LoginMethods.kt @@ -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 } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/DataGdynia.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/DataGdynia.kt new file mode 100644 index 00000000..a94913e4 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/DataGdynia.kt @@ -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 } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/Gdynia.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/Gdynia.kt new file mode 100644 index 00000000..b6b44c4e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/gdynia/Gdynia.kt @@ -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() + val data: DataGdynia + + init { + data = DataGdynia(app, profile, loginStore).apply { + callback = wrapCallback(this@Gdynia.callback) + satisfyLoginMethods() + } + } + + override fun sync(featureIds: List, viewId: Int?, onlyEndpoints: List?, arguments: JsonObject?) { + + } + + override fun getMessage(message: MessageFull) { + + } + + override fun sendMessage(recipients: List, 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) + } + } + + } + } +}