forked from github/szkolny
[API/Podlasie] Implement basic Podlasie e-register support.
This commit is contained in:
parent
15102fe818
commit
a4f58eb19b
@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginPor
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLoginSynergia
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLoginApi2
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLoginWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login.PodlasieLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.login.TemplateLoginApi
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.login.TemplateLoginWeb
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLoginApi
|
||||
@ -27,7 +28,6 @@ import pl.szczodrzynski.edziennik.data.api.models.LoginMethod
|
||||
const val SYNERGIA_API_ENABLED = false
|
||||
|
||||
|
||||
|
||||
const val LOGIN_TYPE_IDZIENNIK = 3
|
||||
|
||||
const val LOGIN_TYPE_TEMPLATE = 21
|
||||
@ -140,6 +140,14 @@ val edudziennikLoginMethods = listOf(
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
)
|
||||
|
||||
const val LOGIN_TYPE_PODLASIE = 6
|
||||
const val LOGIN_METHOD_PODLASIE_API = 100
|
||||
val podlasieLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_PODLASIE, LOGIN_METHOD_PODLASIE_API, PodlasieLoginApi::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withRequiredLoginMethod { _, _ -> LOGIN_METHOD_NOT_NEEDED }
|
||||
)
|
||||
|
||||
val templateLoginMethods = listOf(
|
||||
LoginMethod(LOGIN_TYPE_TEMPLATE, LOGIN_METHOD_TEMPLATE_WEB, TemplateLoginWeb::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
|
@ -0,0 +1,36 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie
|
||||
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_TEMPLATE_API
|
||||
import pl.szczodrzynski.edziennik.data.api.models.Data
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||
|
||||
class DataPodlasie(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
||||
|
||||
fun isApiLoginValid() = apiToken.isNotNullNorEmpty()
|
||||
|
||||
override fun satisfyLoginMethods() {
|
||||
loginMethods.clear()
|
||||
if (isApiLoginValid())
|
||||
loginMethods += LOGIN_METHOD_TEMPLATE_API
|
||||
}
|
||||
|
||||
override fun generateUserCode(): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
/* _
|
||||
/\ (_)
|
||||
/ \ _ __ _
|
||||
/ /\ \ | '_ \| |
|
||||
/ ____ \| |_) | |
|
||||
/_/ \_\ .__/|_|
|
||||
| |
|
||||
|*/
|
||||
private var mApiToken: String? = null
|
||||
var apiToken: String?
|
||||
get() { mApiToken = mApiToken ?: loginStore.getLoginData("apiToken", null); return mApiToken }
|
||||
set(value) { loginStore.putLoginData("apiToken", value); mApiToken = value }
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.firstlogin.PodlasieFirstLogin
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.template.TemplateFeatures
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
||||
import pl.szczodrzynski.edziennik.data.api.templateLoginMethods
|
||||
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 Podlasie(val app: App, val profile: Profile?, val loginStore: LoginStore, val callback: EdziennikCallback) : EdziennikInterface {
|
||||
companion object {
|
||||
const val TAG = "Podlasie"
|
||||
}
|
||||
|
||||
val internalErrorList = mutableListOf<Int>()
|
||||
val data: DataPodlasie
|
||||
|
||||
init {
|
||||
data = DataPodlasie(app, profile, loginStore).apply {
|
||||
callback = wrapCallback(this@Podlasie.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(templateLoginMethods, TemplateFeatures, featureIds, viewId, onlyEndpoints)
|
||||
Utils.d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
Utils.d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
PodlasieFirstLogin(data) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.firstlogin
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
|
||||
|
||||
class PodlasieFirstLogin(val data: DataPodlasie, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
const val TAG = "PodlasieFirstLogin"
|
||||
}
|
||||
|
||||
init {
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.login
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_LOGIN_DATA_MISSING
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_PROFILE_MISSING
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
|
||||
class PodlasieLoginApi(val data: DataPodlasie, val onSuccess: () -> Unit) {
|
||||
companion object {
|
||||
const val TAG = "PodlasieLoginApi"
|
||||
}
|
||||
|
||||
init { run {
|
||||
if (data.profile == null) {
|
||||
data.error(ApiError(TAG, ERROR_PROFILE_MISSING))
|
||||
return@run
|
||||
}
|
||||
|
||||
if (data.isApiLoginValid()) {
|
||||
onSuccess()
|
||||
} else {
|
||||
data.error(ApiError(TAG, ERROR_LOGIN_DATA_MISSING))
|
||||
}
|
||||
}}
|
||||
}
|
Loading…
Reference in New Issue
Block a user