forked from github/szkolny
[Vulcan/Hebe] Add getting homework list.
This commit is contained in:
parent
28725c6400
commit
d6a67a0da6
@ -129,6 +129,7 @@ const val VULCAN_HEBE_ENDPOINT_REGISTER_NEW = "api/mobile/register/new"
|
||||
const val VULCAN_HEBE_ENDPOINT_MAIN = "api/mobile/register/hebe"
|
||||
const val VULCAN_HEBE_ENDPOINT_EXAMS = "api/mobile/exam"
|
||||
const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
|
||||
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
||||
|
||||
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
||||
|
@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_HEBE
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_WEB_MAIN
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_MODE_VULCAN_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
|
||||
@ -44,7 +45,8 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
||||
|
||||
init {
|
||||
// during the first sync `profile.studentClassName` is already set
|
||||
if (teamList.values().none { it.type == Team.TYPE_CLASS }) {
|
||||
if (loginStore.mode == LOGIN_MODE_VULCAN_API
|
||||
&& teamList.values().none { it.type == Team.TYPE_CLASS }) {
|
||||
profile?.studentClassName?.also { name ->
|
||||
val id = Utils.crc16(name.toByteArray()).toLong()
|
||||
|
||||
|
@ -23,6 +23,7 @@ const val ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS = 2010
|
||||
const val ENDPOINT_VULCAN_HEBE_MAIN = 3000
|
||||
const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030
|
||||
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
||||
const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
||||
|
||||
val VulcanFeatures = listOf(
|
||||
// timetable
|
||||
@ -48,6 +49,9 @@ val VulcanFeatures = listOf(
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf(
|
||||
ENDPOINT_VULCAN_API_HOMEWORK to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_HOMEWORK, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_HOMEWORK to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// behaviour
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf(
|
||||
ENDPOINT_VULCAN_API_NOTICES to LOGIN_METHOD_VULCAN_API
|
||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeExams
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeGrades
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeHomework
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.web.VulcanWebLuckyNumber
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
@ -101,6 +102,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
VulcanHebeGrades(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
VulcanHebeHomework(data, lastSync, onSuccess)
|
||||
}
|
||||
else -> onSuccess(endpointId)
|
||||
}
|
||||
}
|
||||
|
@ -82,12 +82,16 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
val team = json.getJsonObject(key)
|
||||
val teamId = team.getLong("Id") ?: return null
|
||||
if (data.teamList[teamId] == null) {
|
||||
var name = team.getString("Shortcut")
|
||||
?: team.getString("Name")
|
||||
?: ""
|
||||
name = "${profile?.studentClassName ?: ""} $name"
|
||||
data.teamList[teamId] = Team(
|
||||
data.profileId,
|
||||
teamId,
|
||||
team.getString("Name") ?: "",
|
||||
name,
|
||||
Team.TYPE_VIRTUAL,
|
||||
team.getString("Shortcut") ?: "",
|
||||
"${data.schoolCode}:$name",
|
||||
-1
|
||||
)
|
||||
}
|
||||
@ -106,7 +110,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
teamId,
|
||||
name,
|
||||
Team.TYPE_CLASS,
|
||||
name,
|
||||
"${data.schoolCode}:$name",
|
||||
-1
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_HOMEWORK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
|
||||
class VulcanHebeHomework(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeHomework"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_HOMEWORK,
|
||||
HebeFilterType.BY_PUPIL,
|
||||
lastSync = lastSync
|
||||
) { list, _ ->
|
||||
list.forEach { exam ->
|
||||
val id = exam.getLong("IdHomework") ?: return@forEach
|
||||
val eventDate = getDate(exam, "Deadline") ?: return@forEach
|
||||
val subjectId = getSubjectId(exam, "Subject")
|
||||
val teacherId = getTeacherId(exam, "Creator")
|
||||
val teamId = data.teamClass?.id ?: -1
|
||||
val topic = exam.getString("Content")?.trim() ?: ""
|
||||
|
||||
val lessonList = data.db.timetableDao().getAllForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
date = eventDate,
|
||||
time = startTime,
|
||||
topic = topic,
|
||||
color = null,
|
||||
type = Event.TYPE_HOMEWORK,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = teamId
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
profile?.empty ?: true,
|
||||
profile?.empty ?: true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_HOMEWORK, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_HOMEWORK)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user