mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[APIv2] Add API first login method. Better cancellation handling.
This commit is contained in:
parent
b59887d4e0
commit
b35df5ef11
@ -87,6 +87,7 @@ class ApiService : Service() {
|
|||||||
apiError.throwable?.printStackTrace()
|
apiError.throwable?.printStackTrace()
|
||||||
if (apiError.isCritical) {
|
if (apiError.isCritical) {
|
||||||
notification.setCriticalError().post()
|
notification.setCriticalError().post()
|
||||||
|
taskRunningObject = null
|
||||||
taskRunning = false
|
taskRunning = false
|
||||||
taskRunningId = -1
|
taskRunningId = -1
|
||||||
sync()
|
sync()
|
||||||
@ -148,18 +149,30 @@ class ApiService : Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the requested profile and login store
|
val profile: Profile?
|
||||||
val profile: Profile? = app.db.profileDao().getByIdNow(task.profileId)
|
val loginStore: LoginStore
|
||||||
if (profile == null || !profile.syncEnabled) {
|
if (task is FirstLoginRequest) {
|
||||||
return
|
// get the requested profile and login store
|
||||||
|
profile = null
|
||||||
|
loginStore = task.loginStore
|
||||||
|
// save the profile ID and name as the current task's
|
||||||
|
taskProfileId = -1
|
||||||
|
taskProfileName = getString(R.string.edziennik_notification_api_first_login_title)
|
||||||
}
|
}
|
||||||
val loginStore: LoginStore? = app.db.loginStoreDao().getByIdNow(profile.loginStoreId)
|
else {
|
||||||
if (loginStore == null) {
|
// get the requested profile and login store
|
||||||
return
|
profile = app.db.profileDao().getByIdNow(task.profileId)
|
||||||
|
if (profile == null || !profile.syncEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loginStore = app.db.loginStoreDao().getByIdNow(profile.loginStoreId)
|
||||||
|
if (loginStore == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// save the profile ID and name as the current task's
|
||||||
|
taskProfileId = profile.id
|
||||||
|
taskProfileName = profile.name
|
||||||
}
|
}
|
||||||
// save the profile ID and name as the current task's
|
|
||||||
taskProfileId = profile.id
|
|
||||||
taskProfileName = profile.name
|
|
||||||
taskProgress = 0
|
taskProgress = 0
|
||||||
taskProgressRes = null
|
taskProgressRes = null
|
||||||
|
|
||||||
@ -182,6 +195,7 @@ class ApiService : Service() {
|
|||||||
featureIds = task.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) } ?: Features.getAllIds(),
|
featureIds = task.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) } ?: Features.getAllIds(),
|
||||||
viewId = task.viewIds?.get(0)?.first)
|
viewId = task.viewIds?.get(0)?.first)
|
||||||
is MessageGetRequest -> edziennikInterface?.getMessage(task.messageId)
|
is MessageGetRequest -> edziennikInterface?.getMessage(task.messageId)
|
||||||
|
is FirstLoginRequest -> edziennikInterface?.firstLogin()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package pl.szczodrzynski.edziennik.api.v2.events.requests
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiTask
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
|
|
||||||
|
data class FirstLoginRequest(val loginStore: LoginStore) : ApiTask(-1) {
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FirstLoginRequest(loginStore=$loginStore)"
|
||||||
|
}
|
||||||
|
}
|
@ -7,5 +7,6 @@ package pl.szczodrzynski.edziennik.api.v2.interfaces
|
|||||||
interface EdziennikInterface {
|
interface EdziennikInterface {
|
||||||
fun sync(featureIds: List<Int>, viewId: Int? = null)
|
fun sync(featureIds: List<Int>, viewId: Int? = null)
|
||||||
fun getMessage(messageId: Int)
|
fun getMessage(messageId: Int)
|
||||||
|
fun firstLogin()
|
||||||
fun cancel()
|
fun cancel()
|
||||||
}
|
}
|
@ -132,6 +132,10 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun firstLogin() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
data.cancel()
|
data.cancel()
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (data.cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
||||||
if (data.cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useEndpoint
|
|
||||||
}
|
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,13 @@ class LibrusLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
||||||
if (usedMethodId != -1)
|
if (usedMethodId != -1)
|
||||||
data.loginMethods.add(usedMethodId)
|
data.loginMethods.add(usedMethodId)
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useLoginMethod
|
|
||||||
}
|
|
||||||
nextLoginMethod(onSuccess)
|
nextLoginMethod(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,10 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun firstLogin() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
Utils.d(TAG, "Cancelled")
|
Utils.d(TAG, "Cancelled")
|
||||||
cancelled = true
|
cancelled = true
|
||||||
|
@ -27,11 +27,11 @@ class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (data.cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
||||||
if (data.cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useEndpoint
|
|
||||||
}
|
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ class MobidziennikLogin(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
||||||
if (usedMethodId != -1)
|
if (usedMethodId != -1)
|
||||||
data.loginMethods.add(usedMethodId)
|
data.loginMethods.add(usedMethodId)
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useLoginMethod
|
|
||||||
}
|
|
||||||
nextLoginMethod(onSuccess)
|
nextLoginMethod(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,10 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun firstLogin() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
Utils.d(TAG, "Cancelled")
|
Utils.d(TAG, "Cancelled")
|
||||||
cancelled = true
|
cancelled = true
|
||||||
|
@ -30,11 +30,11 @@ class TemplateData(val data: DataTemplate, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useEndpoint
|
|
||||||
}
|
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@ class TemplateLogin(val data: DataTemplate, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
||||||
if (usedMethodId != -1)
|
if (usedMethodId != -1)
|
||||||
data.loginMethods.add(usedMethodId)
|
data.loginMethods.add(usedMethodId)
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useLoginMethod
|
|
||||||
}
|
|
||||||
nextLoginMethod(onSuccess)
|
nextLoginMethod(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,10 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun firstLogin() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
Utils.d(TAG, "Cancelled")
|
Utils.d(TAG, "Cancelled")
|
||||||
cancelled = true
|
cancelled = true
|
||||||
|
@ -23,11 +23,11 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
useEndpoint(data.targetEndpointIds.removeAt(0)) {
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useEndpoint
|
|
||||||
}
|
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@ class VulcanLogin(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
onSuccess()
|
onSuccess()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (cancelled) {
|
||||||
|
onSuccess()
|
||||||
|
return
|
||||||
|
}
|
||||||
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
useLoginMethod(data.targetLoginMethodIds.removeAt(0)) { usedMethodId ->
|
||||||
if (usedMethodId != -1)
|
if (usedMethodId != -1)
|
||||||
data.loginMethods.add(usedMethodId)
|
data.loginMethods.add(usedMethodId)
|
||||||
if (cancelled) {
|
|
||||||
onSuccess()
|
|
||||||
return@useLoginMethod
|
|
||||||
}
|
|
||||||
nextLoginMethod(onSuccess)
|
nextLoginMethod(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -943,4 +943,5 @@
|
|||||||
<string name="edziennik_progress_endpoint_homework">Pobieranie zadań domowych...</string>
|
<string name="edziennik_progress_endpoint_homework">Pobieranie zadań domowych...</string>
|
||||||
<string name="edziennik_progress_endpoint_attendance_types">Pobieranie kategorii obecności...</string>
|
<string name="edziennik_progress_endpoint_attendance_types">Pobieranie kategorii obecności...</string>
|
||||||
<string name="edziennik_progress_endpoint_announcements">Pobieranie ogłoszeń szkolnych...</string>
|
<string name="edziennik_progress_endpoint_announcements">Pobieranie ogłoszeń szkolnych...</string>
|
||||||
|
<string name="edziennik_notification_api_first_login_title">Pierwsze logowanie</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user