mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Vulcan/Hebe] Add getting lucky number.
This commit is contained in:
parent
552acd4043
commit
c8ee6ff1e7
@ -136,6 +136,7 @@ const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
||||
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS = "api/mobile/message/status"
|
||||
const val VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER = "api/mobile/school/lucky"
|
||||
|
||||
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
||||
|
@ -29,6 +29,7 @@ const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
||||
const val ENDPOINT_VULCAN_HEBE_ATTENDANCE = 3080
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX = 3090
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_SENT = 3100
|
||||
const val ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER = 3200
|
||||
|
||||
val VulcanFeatures = listOf(
|
||||
// timetable
|
||||
@ -97,7 +98,17 @@ val VulcanFeatures = listOf(
|
||||
*/
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_LUCKY_NUMBER, listOf(
|
||||
ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS to LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB_MAIN)).withShouldSync { data -> data.shouldSyncLuckyNumber() },
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB_MAIN))
|
||||
.withShouldSync { data -> data.shouldSyncLuckyNumber() }
|
||||
.withPriority(2),
|
||||
/**
|
||||
* Lucky number - using Hebe API
|
||||
*/
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_LUCKY_NUMBER, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE))
|
||||
.withShouldSync { data -> data.shouldSyncLuckyNumber() }
|
||||
.withPriority(1),
|
||||
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_VULCAN_API_UPDATE_SEMESTER to LOGIN_METHOD_VULCAN_API,
|
||||
|
@ -180,6 +180,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanHebeAttendance(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
VulcanHebeLuckyNumber(data, lastSync, onSuccess)
|
||||
}
|
||||
else -> onSuccess(endpointId)
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,9 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
.withApiResponse(json.toString()))
|
||||
}
|
||||
|
||||
val envelope = when (T::class.java) {
|
||||
val envelope = if (json.get("Envelope").isJsonNull && null is T)
|
||||
null as T
|
||||
else when (T::class.java) {
|
||||
JsonObject::class.java -> json.getJsonObject("Envelope") as T
|
||||
JsonArray::class.java -> json.getJsonArray("Envelope") as T
|
||||
java.lang.Boolean::class.java -> json.getBoolean("Envelope") as T
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2021-2-22.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.LuckyNumber
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class VulcanHebeLuckyNumber(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeLuckyNumber"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_LUCKY_NUMBER,
|
||||
query = mapOf(
|
||||
"constituentId" to data.studentConstituentId.toString(),
|
||||
"day" to Date.getToday().stringY_m_d
|
||||
)
|
||||
) { lucky: JsonObject?, _ ->
|
||||
// sync tomorrow if lucky number set or is weekend or afternoon
|
||||
var nextSync = Date.getToday().stepForward(0, 0, 1).inMillis
|
||||
if (lucky == null) {
|
||||
if (Date.getToday().weekDay <= Week.FRIDAY && Time.getNow().hour < 12) {
|
||||
// working days morning, sync always
|
||||
nextSync = SYNC_ALWAYS
|
||||
}
|
||||
}
|
||||
else {
|
||||
val luckyNumberDate = Date.fromY_m_d(lucky.getString("Day")) ?: Date.getToday()
|
||||
val luckyNumber = lucky.getInt("Number") ?: -1
|
||||
val luckyNumberObject = LuckyNumber(
|
||||
profileId = profileId,
|
||||
date = luckyNumberDate,
|
||||
number = luckyNumber
|
||||
)
|
||||
|
||||
data.luckyNumberList.add(luckyNumberObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_LUCKY_NUMBER,
|
||||
luckyNumberObject.date.value.toLong(),
|
||||
true,
|
||||
profile?.empty ?: false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER, syncAt = nextSync)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user