forked from github/szkolny
[APIv2/Vulcan] Fix timetable teams issue. Fix missing login data error.
This commit is contained in:
parent
67f98b08c6
commit
9866017f7e
@ -7,15 +7,14 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan
|
|||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_VULCAN_API
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_VULCAN_API
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
||||||
import pl.szczodrzynski.edziennik.currentTimeUnix
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||||
|
|
||||||
class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app, profile, loginStore) {
|
||||||
|
|
||||||
fun isApiLoginValid() = apiCertificateExpiryTime-30 > currentTimeUnix()
|
fun isApiLoginValid() = /*apiCertificateExpiryTime-30 > currentTimeUnix()
|
||||||
&& apiCertificateKey.isNotNullNorEmpty()
|
&&*/ apiCertificateKey.isNotNullNorEmpty()
|
||||||
&& apiCertificatePrivate.isNotNullNorEmpty()
|
&& apiCertificatePrivate.isNotNullNorEmpty()
|
||||||
&& symbol.isNotNullNorEmpty()
|
&& symbol.isNotNullNorEmpty()
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
|
import androidx.core.util.set
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.Regexes
|
import pl.szczodrzynski.edziennik.api.v2.Regexes
|
||||||
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_TIMETABLE
|
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_TIMETABLE
|
||||||
@ -14,6 +15,7 @@ import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
|||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.crc16
|
import pl.szczodrzynski.edziennik.utils.Utils.crc16
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
@ -24,8 +26,7 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni
|
|||||||
const val TAG = "VulcanApiTimetable"
|
const val TAG = "VulcanApiTimetable"
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init { data.profile?.also { profile ->
|
||||||
data.profile?.also { profile ->
|
|
||||||
val currentWeekStart = Date.getToday().let { it.stepForward(0, 0, -it.weekDay) }
|
val currentWeekStart = Date.getToday().let { it.stepForward(0, 0, -it.weekDay) }
|
||||||
val getDate = data.arguments?.getString("weekStart") ?: currentWeekStart.stringY_m_d
|
val getDate = data.arguments?.getString("weekStart") ?: currentWeekStart.stringY_m_d
|
||||||
|
|
||||||
@ -43,14 +44,15 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni
|
|||||||
val lessons: MutableList<Lesson> = mutableListOf()
|
val lessons: MutableList<Lesson> = mutableListOf()
|
||||||
|
|
||||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { lesson ->
|
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { lesson ->
|
||||||
|
if (lesson.getBoolean("PlanUcznia") != true)
|
||||||
|
return@forEach
|
||||||
val lessonDate = Date.fromY_m_d(lesson.getString("DzienTekst"))
|
val lessonDate = Date.fromY_m_d(lesson.getString("DzienTekst"))
|
||||||
val lessonNumber = lesson.getInt("NumerLekcji")
|
val lessonNumber = lesson.getInt("NumerLekcji")
|
||||||
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNumber }
|
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNumber }
|
||||||
val startTime = lessonRange?.startTime
|
val startTime = lessonRange?.startTime
|
||||||
val endTime = lessonRange?.endTime
|
val endTime = lessonRange?.endTime
|
||||||
val teacherId = lesson.getLong("IdPracownik")
|
val teacherId = lesson.getLong("IdPracownik")
|
||||||
val teamId = data.studentClassId.toLong()
|
val classroom = lesson.getString("Sala")
|
||||||
val classroom = lesson.getString("Classroom")
|
|
||||||
|
|
||||||
val oldTeacherId = lesson.getLong("IdPracownikOld")
|
val oldTeacherId = lesson.getLong("IdPracownikOld")
|
||||||
|
|
||||||
@ -63,6 +65,24 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni
|
|||||||
else -> Lesson.TYPE_NORMAL
|
else -> Lesson.TYPE_NORMAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val teamId = lesson.getString("PodzialSkrot")?.let { teamName ->
|
||||||
|
val name = "${data.teamClass?.name} $teamName"
|
||||||
|
val id = name.crc16().toLong()
|
||||||
|
var team = data.teamList.singleOrNull { it.name == name }
|
||||||
|
if (team == null) {
|
||||||
|
team = Team(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
Team.TYPE_VIRTUAL,
|
||||||
|
"${data.schoolName}:$name",
|
||||||
|
teacherId ?: oldTeacherId ?: -1
|
||||||
|
)
|
||||||
|
data.teamList[id] = team
|
||||||
|
}
|
||||||
|
team.id
|
||||||
|
} ?: data.studentClassId.toLong()
|
||||||
|
|
||||||
val subjectId = lesson.getLong("IdPrzedmiot")?.let {
|
val subjectId = lesson.getLong("IdPrzedmiot")?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
0L -> {
|
0L -> {
|
||||||
@ -181,6 +201,5 @@ class VulcanApiTimetable(override val data: DataVulcan, val onSuccess: () -> Uni
|
|||||||
data.setSyncNext(ENDPOINT_VULCAN_API_TIMETABLE, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_VULCAN_API_TIMETABLE, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user