forked from github/szkolny
[Vulcan/Hebe] Add getting exams.
This commit is contained in:
parent
4fc965d970
commit
28725c6400
@ -127,6 +127,7 @@ const val VULCAN_WEB_ENDPOINT_LUCKY_NUMBER = "Start.mvc/GetKidsLuckyNumbers"
|
||||
const val VULCAN_WEB_ENDPOINT_REGISTER_DEVICE = "RejestracjaUrzadzeniaToken.mvc/Get"
|
||||
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 EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
@ -21,6 +21,7 @@ const val ENDPOINT_VULCAN_API_MESSAGES_INBOX = 1090
|
||||
const val ENDPOINT_VULCAN_API_MESSAGES_SENT = 1100
|
||||
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
|
||||
|
||||
val VulcanFeatures = listOf(
|
||||
@ -32,6 +33,9 @@ val VulcanFeatures = listOf(
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
||||
ENDPOINT_VULCAN_API_EVENTS to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_EXAMS to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// grades
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_GRADES, listOf(
|
||||
ENDPOINT_VULCAN_API_GRADES to LOGIN_METHOD_VULCAN_API,
|
||||
|
@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
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.web.VulcanWebLuckyNumber
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
@ -92,6 +93,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
VulcanWebLuckyNumber(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_EXAMS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_exams)
|
||||
VulcanHebeExams(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
VulcanHebeGrades(data, lastSync, onSuccess)
|
||||
|
@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.HebeFilter
|
||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Subject
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Team
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import java.net.HttpURLConnection
|
||||
@ -39,11 +40,16 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
val profile
|
||||
get() = data.profile
|
||||
|
||||
fun getDate(json: JsonObject?, key: String): Long {
|
||||
fun getDateTime(json: JsonObject?, key: String): Long {
|
||||
val date = json.getJsonObject(key)
|
||||
return date.getLong("Timestamp") ?: return System.currentTimeMillis()
|
||||
}
|
||||
|
||||
fun getDate(json: JsonObject?, key: String): Date? {
|
||||
val date = json.getJsonObject(key)
|
||||
return date.getString("Date")?.let { Date.fromY_m_d(it) }
|
||||
}
|
||||
|
||||
fun getTeacherId(json: JsonObject?, key: String): Long {
|
||||
val teacher = json.getJsonObject(key)
|
||||
val teacherId = teacher.getLong("Id") ?: return -1
|
||||
@ -72,6 +78,41 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
||||
return subjectId
|
||||
}
|
||||
|
||||
fun getTeamId(json: JsonObject?, key: String): Long? {
|
||||
val team = json.getJsonObject(key)
|
||||
val teamId = team.getLong("Id") ?: return null
|
||||
if (data.teamList[teamId] == null) {
|
||||
data.teamList[teamId] = Team(
|
||||
data.profileId,
|
||||
teamId,
|
||||
team.getString("Name") ?: "",
|
||||
Team.TYPE_VIRTUAL,
|
||||
team.getString("Shortcut") ?: "",
|
||||
-1
|
||||
)
|
||||
}
|
||||
return teamId
|
||||
}
|
||||
|
||||
fun getClassId(json: JsonObject?, key: String): Long? {
|
||||
val team = json.getJsonObject(key)
|
||||
val teamId = team.getLong("Id") ?: return null
|
||||
if (data.teamList[teamId] == null) {
|
||||
val name = data.profile?.studentClassName
|
||||
?: team.getString("Name")
|
||||
?: ""
|
||||
data.teamList[teamId] = Team(
|
||||
data.profileId,
|
||||
teamId,
|
||||
name,
|
||||
Team.TYPE_CLASS,
|
||||
name,
|
||||
-1
|
||||
)
|
||||
}
|
||||
return teamId
|
||||
}
|
||||
|
||||
fun getSemester(json: JsonObject?): Int {
|
||||
val periodId = json.getInt("PeriodId") ?: return 1
|
||||
return if (periodId == data.semester1Id)
|
||||
|
@ -0,0 +1,80 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_EXAMS
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_EXAMS
|
||||
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
|
||||
|
||||
class VulcanHebeExams(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeExams"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_EXAMS,
|
||||
HebeFilterType.BY_PUPIL,
|
||||
lastSync = lastSync
|
||||
) { list, _ ->
|
||||
list.forEach { exam ->
|
||||
val id = exam.getLong("Id") ?: return@forEach
|
||||
val eventDate = getDate(exam, "Deadline") ?: return@forEach
|
||||
val subjectId = getSubjectId(exam, "Subject")
|
||||
val teacherId = getTeacherId(exam, "Creator")
|
||||
val teamId = getTeamId(exam, "Distribution")
|
||||
?: getClassId(exam, "Class")
|
||||
?: 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 type = when (exam.getString("Type")) {
|
||||
"Praca klasowa",
|
||||
"Sprawdzian" -> Event.TYPE_EXAM
|
||||
"Kartkówka" -> Event.TYPE_SHORT_QUIZ
|
||||
else -> Event.TYPE_DEFAULT
|
||||
}
|
||||
|
||||
val eventObject = Event(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
date = eventDate,
|
||||
time = startTime,
|
||||
topic = topic,
|
||||
color = null,
|
||||
type = type,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
teamId = teamId
|
||||
)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
profile?.empty ?: true,
|
||||
profile?.empty ?: true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Events.futureExceptType(Event.TYPE_HOMEWORK))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_EXAMS, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_EXAMS)
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class VulcanHebeGrades(
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiGrades"
|
||||
const val TAG = "VulcanHebeGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
@ -44,7 +44,7 @@ class VulcanHebeGrades(
|
||||
var weight = column.getFloat("Weight") ?: 0.0f
|
||||
val numerator = grade.getFloat("Numerator ")
|
||||
val denominator = grade.getFloat("Denominator")
|
||||
val addedDate = getDate(grade, "DateModify")
|
||||
val addedDate = getDateTime(grade, "DateModify")
|
||||
|
||||
var finalDescription = ""
|
||||
|
||||
@ -115,12 +115,12 @@ class VulcanHebeGrades(
|
||||
)
|
||||
}
|
||||
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_GRADES)
|
||||
data.toRemove.add(
|
||||
DataRemoveModel.Grades.semesterWithType(data.studentSemesterNumber,
|
||||
Grade.TYPE_NORMAL
|
||||
))
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_GRADES, SYNC_ALWAYS)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_GRADES)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user