APIv2: Prepare schemes

This commit is contained in:
Kuba Szczodrzyński 2019-09-20 19:12:05 +02:00
parent 003ffa2251
commit 4b5c14cbd5
17 changed files with 172 additions and 9 deletions

View File

@ -0,0 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Copyright (c) Kuba Szczodrzyński &amp;#36;{today.year}-&amp;#36;{today.month}-&amp;#36;{today.day}. " />
<option name="myName" value="kubasz" />
</copyright>
</component>

View File

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="kubasz" />
</component>

View File

@ -1,5 +1,10 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-9-19.
*/
package pl.szczodrzynski.edziennik.api.v2
internal const val FEATURE_ANY = -1
const val FEATURE_ALL = 0
const val FEATURE_TIMETABLE = 1
const val FEATURE_AGENDA = 2
@ -17,9 +22,25 @@ const val LOGIN_TYPE_IUCZNIOWIE = 3
const val LOGIN_TYPE_VULCAN = 4
const val LOGIN_TYPE_DEMO = 20
// LOGIN MODES
const val LOGIN_MODE_LIBRUS_EMAIL = 0
const val LOGIN_MODE_LIBRUS_SYNERGIA = 1
const val LOGIN_MODE_LIBRUS_JST = 2
const val LOGIN_MODE_MOBIDZIENNIK_WEB = 0
const val LOGIN_MODE_IDZIENNIK_WEB = 0
const val LOGIN_MODE_VULCAN_WEB = 0
// LOGIN METHODS
const val LOGIN_METHOD_NOT_NEEDED = -1
const val LOGIN_METHOD_LIBRUS_PORTAL = 0
const val LOGIN_METHOD_LIBRUS_API = 1
const val LOGIN_METHOD_LIBRUS_SYNERGIA = 2
const val LOGIN_METHOD_LIBRUS_MESSAGES = 3
const val LOGIN_METHOD_MOBIDZIENNIK_API = 0
const val LOGIN_METHOD_IDZIENNIK_WEB = 0
const val LOGIN_METHOD_IDZIENNIK_API = 1
const val LOGIN_METHOD_VULCAN_WEB = 0
const val LOGIN_METHOD_VULCAN_API = 1
const val LIBRUS_USER_AGENT = "Dalvik/2.1.0 Android LibrusMobileApp"
const val LIBRUS_CLIENT_ID = "wmSyUMo8llDAs4y9tJVYY92oyZ6h4lAt7KCuy0Gv"

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-9-20.
*/
package pl.szczodrzynski.edziennik.api.v2
import android.util.Log
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApiGrades
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusSynergiaGrades
import pl.szczodrzynski.edziennik.api.v2.models.Endpoint
const val ENDPOINT_LIBRUS_API_ME = 0
const val ENDPOINT_LIBRUS_API_GRADES = 0
const val ENDPOINT_LIBRUS_SYNERGIA_GRADES = 0
val librusEndpoints = listOf(
Endpoint(LOGIN_TYPE_LIBRUS, 1, listOf(), LibrusSynergiaGrades::class.java) { _, _ -> LOGIN_METHOD_LIBRUS_SYNERGIA },
Endpoint(LOGIN_TYPE_LIBRUS, 1, listOf(), LibrusApiGrades::class.java) { _, _ -> LOGIN_METHOD_LIBRUS_API }
)
/*
SYNC:
look up all endpoints for the given API and given features
load "next sync timers" for every endpoint
exclude every endpoint which does not need to sync now
check all needed login methods
create a login method list, using methods' dependencies as well
use all login methods, saving completed logins to data store
instantiate all endpoint classes and sync them (writing to data store, returns onSuccess or error Callback)
*/

View File

@ -0,0 +1,6 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-9-20.
*/
package pl.szczodrzynski.edziennik.api.v2

View File

@ -0,0 +1,4 @@
package pl.szczodrzynski.edziennik.api.v2.interfaces
interface ILoginMethod {
}

View File

@ -99,7 +99,7 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore) :
| |__| |____) | | |
\____/|_____/ |*/
private fun loginJst() {
LoginJst(app, loginStore, syncCallback) {
LoginJst(app, null, loginStore, syncCallback) {
if (profile == null) {
firstLoginSynergia()
return@LoginJst

View File

@ -0,0 +1,18 @@
package pl.szczodrzynski.edziennik.api.v2.librus.data
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.api.interfaces.ProgressCallback
import pl.szczodrzynski.edziennik.api.v2.models.DataStore
import pl.szczodrzynski.edziennik.datamodels.LoginStore
import pl.szczodrzynski.edziennik.datamodels.Profile
class LibrusGrades(val app: App,
val profile: Profile,
val loginStore: LoginStore,
val dataStore: DataStore,
val callback: ProgressCallback,
val onSuccess: () -> Unit) {
init {
}
}

View File

@ -0,0 +1,4 @@
package pl.szczodrzynski.edziennik.api.v2.librus.data
class LibrusSynergiaGrades {
}

View File

@ -2,10 +2,17 @@ package pl.szczodrzynski.edziennik.api.v2.librus.login
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.api.interfaces.ProgressCallback
import pl.szczodrzynski.edziennik.api.v2.ApiLoginResult
import pl.szczodrzynski.edziennik.api.v2.interfaces.ILoginMethod
import pl.szczodrzynski.edziennik.datamodels.LoginStore
import pl.szczodrzynski.edziennik.datamodels.Profile
class LoginJst(val app: App, val loginStore: LoginStore, val callback: ProgressCallback, val onSuccess: () -> Unit) {
class LoginJst(
app: App,
profile: Profile?,
loginStore: LoginStore,
callback: ProgressCallback,
onSuccess: () -> Unit
): ILoginMethod(app, profile, loginStore, callback, onSuccess) {
companion object {
private const val TAG = "librus.LoginJst"
}

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.api.v2
package pl.szczodrzynski.edziennik.api.v2.models
import pl.szczodrzynski.edziennik.api.AppError
import pl.szczodrzynski.edziennik.datamodels.LoginStore

View File

@ -1,4 +0,0 @@
package pl.szczodrzynski.edziennik.api.v2.models
class DataEndpoint() {
}

View File

@ -7,6 +7,9 @@ import pl.szczodrzynski.edziennik.datamodels.*
import pl.szczodrzynski.edziennik.models.Date
data class DataStore(private val appDb: AppDb, val profileId: Int) {
val loginMethods = mutableListOf<Int>()
val teacherList: LongSparseArray<Teacher> = LongSparseArray()
val subjectList: LongSparseArray<Subject> = LongSparseArray()
val teamList = mutableListOf<Team>()
@ -43,6 +46,8 @@ data class DataStore(private val appDb: AppDb, val profileId: Int) {
}
fun clear() {
loginMethods.clear()
teacherList.clear()
subjectList.clear()
teamList.clear()

View File

@ -0,0 +1,26 @@
package pl.szczodrzynski.edziennik.api.v2.models
import pl.szczodrzynski.edziennik.datamodels.LoginStore
import pl.szczodrzynski.edziennik.datamodels.Profile
/**
* A Endpoint descriptor class.
*
* The API runs appropriate endpoints in order to fulfill its
* [Feature] list.
* An endpoint may have its [LoginMethod] dependencies which will be
* satisfied by the API before the [endpointClass]'s constructor is invoked.
*
* @param loginType type of the e-register this endpoint handles
* @param endpointId a unique ID of this endpoint
* @param featureIds a [List] of [Feature]s (their IDs) this endpoint can download
* @param endpointClass a [Class] which constructor will be invoked when a data download is needed
* @param requiredLoginMethod a lambda returning a required login method (which will be called before this). May differ depending on the [Profile] and/or [LoginStore].
*/
class Endpoint(
val loginType: Int,
val endpointId: Int,
val featureIds: List<Int>,
val endpointClass: Class<*>,
val requiredLoginMethod: (profile: Profile?, loginStore: LoginStore) -> Int
)

View File

@ -1,5 +1,7 @@
package pl.szczodrzynski.edziennik.api.v2.models
import pl.szczodrzynski.edziennik.api.v2.endpoint
data class Feature(val featureId: Int, val loginOptions: Map<Int, List<Int>>) {

View File

@ -1,4 +1,4 @@
package pl.szczodrzynski.edziennik.api.v2
package pl.szczodrzynski.edziennik.api.v2.models
import pl.szczodrzynski.edziennik.api.AppError
import pl.szczodrzynski.edziennik.datamodels.Profile

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-9-20.
*/
package pl.szczodrzynski.edziennik.api.v2.models
import pl.szczodrzynski.edziennik.datamodels.LoginStore
import pl.szczodrzynski.edziennik.datamodels.Profile
/**
* A Login Method descriptor class.
*
* This is used by the API to satisfy all [Endpoint]s' dependencies.
* A login method may have its own dependencies which need to be
* satisfied before the [loginMethodClass]'s constructor is invoked.
*
* @param loginType type of the e-register this login method handles
* @param loginMethodId a unique ID of this login method
* @param featureIds a [List] of [Feature]s (their IDs) this login method can provide access to
* @param loginMethodClass a [Class] which constructor will be invoked when a log in is needed
* @param requiredLoginMethod a lambda returning a required login method (which will be called before this). May differ depending on the [Profile] and/or [LoginStore].
*/
class LoginMethod(
val loginType: Int,
val loginMethodId: Int,
val featureIds: List<Int>,
val loginMethodClass: Class<*>,
val requiredLoginMethod: (profile: Profile?, loginStore: LoginStore) -> Int
)