mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[API/Vulcan] Force presence of a TeamClass.
This commit is contained in:
parent
cb953ea8a8
commit
519d75d9d9
@ -22,7 +22,6 @@ import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
|||||||
import pl.szczodrzynski.edziennik.data.db.entity.LessonRange
|
import pl.szczodrzynski.edziennik.data.db.entity.LessonRange
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Subject
|
import pl.szczodrzynski.edziennik.data.db.entity.Subject
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Team
|
|
||||||
import pl.szczodrzynski.edziennik.ext.*
|
import pl.szczodrzynski.edziennik.ext.*
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
@ -91,41 +90,31 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
|
|
||||||
fun getTeamId(json: JsonObject?, key: String): Long? {
|
fun getTeamId(json: JsonObject?, key: String): Long? {
|
||||||
val team = json.getJsonObject(key)
|
val team = json.getJsonObject(key)
|
||||||
val teamId = team.getLong("Id") ?: return null
|
val teamId = team.getLong("Id")
|
||||||
if (data.teamList[teamId] == null) {
|
var teamName = team.getString("Shortcut")
|
||||||
var name = team.getString("Shortcut")
|
?: team.getString("Name")
|
||||||
?: team.getString("Name")
|
?: ""
|
||||||
?: ""
|
teamName = "${profile?.studentClassName ?: ""} $teamName"
|
||||||
name = "${profile?.studentClassName ?: ""} $name"
|
return data.getTeam(
|
||||||
data.teamList[teamId] = Team(
|
id = teamId,
|
||||||
data.profileId,
|
name = teamName,
|
||||||
teamId,
|
schoolCode = data.schoolCode ?: "",
|
||||||
name,
|
isTeamClass = false,
|
||||||
Team.TYPE_VIRTUAL,
|
).id
|
||||||
"${data.schoolCode}:$name",
|
|
||||||
-1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return teamId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getClassId(json: JsonObject?, key: String): Long? {
|
fun getClassId(json: JsonObject?, key: String): Long? {
|
||||||
val team = json.getJsonObject(key)
|
val team = json.getJsonObject(key)
|
||||||
val teamId = team.getLong("Id") ?: return null
|
val teamId = team.getLong("Id")
|
||||||
if (data.teamList[teamId] == null) {
|
val teamName = data.profile?.studentClassName
|
||||||
val name = data.profile?.studentClassName
|
?: team.getString("Name")
|
||||||
?: team.getString("Name")
|
?: ""
|
||||||
?: ""
|
return data.getTeam(
|
||||||
data.teamList[teamId] = Team(
|
id = teamId,
|
||||||
data.profileId,
|
name = teamName,
|
||||||
teamId,
|
schoolCode = data.schoolCode ?: "",
|
||||||
name,
|
isTeamClass = true,
|
||||||
Team.TYPE_CLASS,
|
).id
|
||||||
"${data.schoolCode}:$name",
|
|
||||||
-1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return teamId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLessonRange(json: JsonObject?, key: String): LessonRange? {
|
fun getLessonRange(json: JsonObject?, key: String): LessonRange? {
|
||||||
|
@ -151,6 +151,15 @@ class VulcanHebeMain(
|
|||||||
studentData["senderAddressName"] = senderAddressName
|
studentData["senderAddressName"] = senderAddressName
|
||||||
studentData["senderAddressHash"] = senderAddressHash
|
studentData["senderAddressHash"] = senderAddressHash
|
||||||
studentData["hebeContext"] = hebeContext
|
studentData["hebeContext"] = hebeContext
|
||||||
|
|
||||||
|
// create the default TeamClass
|
||||||
|
data.getTeam(
|
||||||
|
id = null,
|
||||||
|
name = studentClassName,
|
||||||
|
schoolCode = schoolCode,
|
||||||
|
isTeamClass = true,
|
||||||
|
profileId = this.id,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
dateSemester1Start?.let {
|
dateSemester1Start?.let {
|
||||||
newProfile.dateSemester1Start = it
|
newProfile.dateSemester1Start = it
|
||||||
|
@ -406,7 +406,13 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
|||||||
return subject
|
return subject
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTeam(id: Long?, name: String, schoolCode: String, isTeamClass: Boolean = false): Team {
|
fun getTeam(
|
||||||
|
id: Long?,
|
||||||
|
name: String,
|
||||||
|
schoolCode: String,
|
||||||
|
isTeamClass: Boolean = false,
|
||||||
|
profileId: Int? = null,
|
||||||
|
): Team {
|
||||||
if (isTeamClass && teamClass != null)
|
if (isTeamClass && teamClass != null)
|
||||||
return teamClass as Team
|
return teamClass as Team
|
||||||
var team = teamList.singleOrNull { it.id == id }
|
var team = teamList.singleOrNull { it.id == id }
|
||||||
@ -417,7 +423,7 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
|||||||
|
|
||||||
if (team == null) {
|
if (team == null) {
|
||||||
team = Team(
|
team = Team(
|
||||||
profileId,
|
profileId ?: this.profileId,
|
||||||
id ?: name.crc32(),
|
id ?: name.crc32(),
|
||||||
name,
|
name,
|
||||||
if (isTeamClass) Team.TYPE_CLASS else Team.TYPE_VIRTUAL,
|
if (isTeamClass) Team.TYPE_CLASS else Team.TYPE_VIRTUAL,
|
||||||
@ -425,6 +431,8 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
|||||||
-1
|
-1
|
||||||
)
|
)
|
||||||
teamList[team.id] = team
|
teamList[team.id] = team
|
||||||
|
} else if (id != null) {
|
||||||
|
team.id = id
|
||||||
}
|
}
|
||||||
return team
|
return team
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user