mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[API/Vulcan] Fix adding unknown subject in timetable. Fix selecting correct TeamClass in timetable.
This commit is contained in:
parent
b5502478e4
commit
c7950c53da
@ -10,7 +10,10 @@ import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
|
|||||||
import pl.szczodrzynski.edziennik.data.api.models.Data
|
import pl.szczodrzynski.edziennik.data.api.models.Data
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Team
|
||||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||||
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
|
import pl.szczodrzynski.edziennik.values
|
||||||
|
|
||||||
class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
||||||
|
|
||||||
@ -26,6 +29,25 @@ 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 }) {
|
||||||
|
profile?.studentClassName?.also { name ->
|
||||||
|
val id = Utils.crc16(name.toByteArray()).toLong()
|
||||||
|
|
||||||
|
val teamObject = Team(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
Team.TYPE_CLASS,
|
||||||
|
"$schoolName:$name",
|
||||||
|
-1
|
||||||
|
)
|
||||||
|
teamList.put(id, teamObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun generateUserCode() = "$schoolName:$studentId"
|
override fun generateUserCode() = "$schoolName:$studentId"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,8 +13,6 @@ import io.github.wulkanowy.signer.android.signContent
|
|||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Team
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -42,22 +40,6 @@ open class VulcanApi(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
|
|
||||||
d(tag, "Request: Vulcan/Api - $url")
|
d(tag, "Request: Vulcan/Api - $url")
|
||||||
|
|
||||||
if (data.teamList.size() == 0) {
|
|
||||||
data.profile?.studentClassName?.also { name ->
|
|
||||||
val id = Utils.crc16(name.toByteArray()).toLong()
|
|
||||||
|
|
||||||
val teamObject = Team(
|
|
||||||
profileId,
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
Team.TYPE_CLASS,
|
|
||||||
"${data.schoolName}:$name",
|
|
||||||
-1
|
|
||||||
)
|
|
||||||
data.teamList.put(id, teamObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val finalPayload = JsonObject()
|
val finalPayload = JsonObject()
|
||||||
parameters.map { (name, value) ->
|
parameters.map { (name, value) ->
|
||||||
when (value) {
|
when (value) {
|
||||||
|
@ -86,31 +86,36 @@ class VulcanApiTimetable(override val data: DataVulcan,
|
|||||||
data.teamList[id] = team
|
data.teamList[id] = team
|
||||||
}
|
}
|
||||||
team.id
|
team.id
|
||||||
} ?: data.studentClassId.toLong()
|
} ?: data.teamClass?.id ?: -1
|
||||||
|
|
||||||
val subjectId = lesson.getLong("IdPrzedmiot")?.let {
|
val subjectId = lesson.getLong("IdPrzedmiot").let { id ->
|
||||||
when (it) {
|
// get the specified subject name
|
||||||
0L -> {
|
val subjectName = lesson.getString("PrzedmiotNazwa") ?: ""
|
||||||
val subjectName = lesson.getString("PrzedmiotNazwa") ?: ""
|
|
||||||
|
|
||||||
data.subjectList.singleOrNull { subject -> subject.longName == subjectName }?.id
|
val condition = when (id) {
|
||||||
?: {
|
// "special" subject - e.g. one time classes, a trip, etc.
|
||||||
/**
|
0L -> { subject: Subject -> subject.longName == subjectName }
|
||||||
* CREATE A NEW SUBJECT IF IT DOESN'T EXIST
|
// normal subject, check if it exists
|
||||||
*/
|
else -> { subject: Subject -> subject.id == id }
|
||||||
|
|
||||||
val subjectObject = Subject(
|
|
||||||
profileId,
|
|
||||||
-1 * crc16(subjectName.toByteArray()).toLong(),
|
|
||||||
subjectName,
|
|
||||||
subjectName
|
|
||||||
)
|
|
||||||
data.subjectList.put(subjectObject.id, subjectObject)
|
|
||||||
subjectObject.id
|
|
||||||
}.invoke()
|
|
||||||
}
|
|
||||||
else -> it
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.subjectList.singleOrNull(condition)?.id ?: {
|
||||||
|
/**
|
||||||
|
* CREATE A NEW SUBJECT IF IT DOESN'T EXIST
|
||||||
|
*/
|
||||||
|
|
||||||
|
val subjectObject = Subject(
|
||||||
|
profileId,
|
||||||
|
if (id == null || id == 0L)
|
||||||
|
-1 * crc16(subjectName.toByteArray()).toLong()
|
||||||
|
else
|
||||||
|
id,
|
||||||
|
subjectName,
|
||||||
|
subjectName
|
||||||
|
)
|
||||||
|
data.subjectList.put(subjectObject.id, subjectObject)
|
||||||
|
subjectObject.id
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
val lessonObject = Lesson(profileId, -1).apply {
|
val lessonObject = Lesson(profileId, -1).apply {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user