mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[APIv2/Mobidziennik] Add Notices, Grades, fix Attendance
This commit is contained in:
parent
6127e574db
commit
bbaa405c59
@ -6,6 +6,7 @@ package pl.szczodrzynski.edziennik.api.v2.mobidziennik
|
|||||||
|
|
||||||
import android.util.LongSparseArray
|
import android.util.LongSparseArray
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
|
import android.util.SparseIntArray
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
||||||
@ -33,6 +34,10 @@ class DataMobidziennik(app: App, profile: Profile?, loginStore: LoginStore) : Da
|
|||||||
val teachersMap = LongSparseArray<String>()
|
val teachersMap = LongSparseArray<String>()
|
||||||
val subjectsMap = LongSparseArray<String>()
|
val subjectsMap = LongSparseArray<String>()
|
||||||
|
|
||||||
|
val gradeAddedDates = SparseArray<Long>()
|
||||||
|
val gradeAverages = SparseArray<Float>()
|
||||||
|
val gradeColors = SparseIntArray()
|
||||||
|
|
||||||
private var mLoginServerName: String? = null
|
private var mLoginServerName: String? = null
|
||||||
var loginServerName: String?
|
var loginServerName: String?
|
||||||
get() { mLoginServerName = mLoginServerName ?: loginStore.getLoginData("serverName", null); return mLoginServerName }
|
get() { mLoginServerName = mLoginServerName ?: loginStore.getLoginData("serverName", null); return mLoginServerName }
|
||||||
|
@ -40,9 +40,9 @@ class MobidziennikApi(override val data: DataMobidziennik,
|
|||||||
14 -> MobidziennikApiGradeCategories(data, rows)
|
14 -> MobidziennikApiGradeCategories(data, rows)
|
||||||
15 -> MobidziennikApiLessons(data, rows)
|
15 -> MobidziennikApiLessons(data, rows)
|
||||||
16 -> MobidziennikApiAttendance(data, rows)
|
16 -> MobidziennikApiAttendance(data, rows)
|
||||||
/*17 -> MobidziennikApiNotices(data, rows)
|
17 -> MobidziennikApiNotices(data, rows)
|
||||||
18 -> MobidziennikApiGrades(data, rows)
|
18 -> MobidziennikApiGrades(data, rows)
|
||||||
21 -> MobidziennikApiEvents(data, rows)
|
/*21 -> MobidziennikApiEvents(data, rows)
|
||||||
23 -> MobidziennikApiHomework(data, rows)
|
23 -> MobidziennikApiHomework(data, rows)
|
||||||
24 -> MobidziennikApiTimetable(data, rows)*/
|
24 -> MobidziennikApiTimetable(data, rows)*/
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||||
|
|
||||||
import androidx.core.util.contains
|
import androidx.core.util.contains
|
||||||
import pl.szczodrzynski.edziennik.App.profileId
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance
|
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance.*
|
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance.*
|
||||||
@ -36,7 +35,7 @@ class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>)
|
|||||||
val semester = data.profile?.dateToSemester(lesson.date) ?: 1
|
val semester = data.profile?.dateToSemester(lesson.date) ?: 1
|
||||||
|
|
||||||
val attendanceObject = Attendance(
|
val attendanceObject = Attendance(
|
||||||
profileId,
|
data.profileId,
|
||||||
id,
|
id,
|
||||||
lesson.teacherId,
|
lesson.teacherId,
|
||||||
lesson.subjectId,
|
lesson.subjectId,
|
||||||
@ -49,7 +48,7 @@ class MobidziennikApiAttendance(val data: DataMobidziennik, rows: List<String>)
|
|||||||
data.attendanceList.add(attendanceObject)
|
data.attendanceList.add(attendanceObject)
|
||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
Metadata(
|
Metadata(
|
||||||
profileId,
|
data.profileId,
|
||||||
Metadata.TYPE_ATTENDANCE,
|
Metadata.TYPE_ATTENDANCE,
|
||||||
id,
|
id,
|
||||||
data.profile?.empty ?: false,
|
data.profile?.empty ?: false,
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2019-10-8.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.*
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
|
||||||
|
class MobidziennikApiGrades(val data: DataMobidziennik, rows: List<String>) {
|
||||||
|
init { run {
|
||||||
|
data.db.gradeDao().getDetails(
|
||||||
|
data.profileId,
|
||||||
|
data.gradeAddedDates,
|
||||||
|
data.gradeAverages,
|
||||||
|
data.gradeColors
|
||||||
|
)
|
||||||
|
var addedDate = System.currentTimeMillis()
|
||||||
|
for (row in rows) {
|
||||||
|
if (row.isEmpty())
|
||||||
|
continue
|
||||||
|
val cols = row.split("|")
|
||||||
|
|
||||||
|
val studentId = cols[2].toInt()
|
||||||
|
if (studentId != data.studentId)
|
||||||
|
return@run
|
||||||
|
|
||||||
|
val id = cols[0].toLong()
|
||||||
|
val categoryId = cols[6].toLongOrNull() ?: -1
|
||||||
|
val categoryColumn = cols[10].toIntOrNull() ?: 1
|
||||||
|
val name = cols[7]
|
||||||
|
val value = cols[11].toFloat()
|
||||||
|
val semester = cols[5].toInt()
|
||||||
|
val teacherId = cols[2].toLong()
|
||||||
|
val subjectId = cols[3].toLong()
|
||||||
|
var type = when (cols[8]) {
|
||||||
|
"3" -> if (semester == 1) TYPE_SEMESTER1_PROPOSED else TYPE_SEMESTER2_PROPOSED
|
||||||
|
"1" -> if (semester == 1) TYPE_SEMESTER1_FINAL else TYPE_SEMESTER2_FINAL
|
||||||
|
"4" -> TYPE_YEAR_PROPOSED
|
||||||
|
"2" -> TYPE_YEAR_FINAL
|
||||||
|
else -> TYPE_NORMAL
|
||||||
|
}
|
||||||
|
|
||||||
|
var weight = 0.0f
|
||||||
|
var category = ""
|
||||||
|
var description = ""
|
||||||
|
var color = -1
|
||||||
|
data.gradeCategories.get(categoryId)?.let { gradeCategory ->
|
||||||
|
weight = gradeCategory.weight
|
||||||
|
category = gradeCategory.text
|
||||||
|
description = gradeCategory.columns[categoryColumn-1]
|
||||||
|
color = gradeCategory.color
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix for "0" value grades, so they're not counted in the average
|
||||||
|
if (value == 0.0f/* && data.app.appConfig.dontCountZeroToAverage*/) {
|
||||||
|
weight = 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
val gradeObject = Grade(
|
||||||
|
data.profileId,
|
||||||
|
id,
|
||||||
|
category,
|
||||||
|
color,
|
||||||
|
description,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
weight,
|
||||||
|
semester,
|
||||||
|
teacherId,
|
||||||
|
subjectId)
|
||||||
|
|
||||||
|
data.gradeList.add(gradeObject)
|
||||||
|
data.metadataList.add(
|
||||||
|
Metadata(
|
||||||
|
data.profileId,
|
||||||
|
Metadata.TYPE_GRADE,
|
||||||
|
id,
|
||||||
|
data.profile?.empty ?: false,
|
||||||
|
data.profile?.empty ?: false,
|
||||||
|
addedDate
|
||||||
|
))
|
||||||
|
addedDate++
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2019-10-8.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.App
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class MobidziennikApiNotices(val data: DataMobidziennik, rows: List<String>) {
|
||||||
|
init { run {
|
||||||
|
for (row in rows) {
|
||||||
|
if (row.isEmpty())
|
||||||
|
continue
|
||||||
|
val cols = row.split("|")
|
||||||
|
|
||||||
|
val studentId = cols[2].toInt()
|
||||||
|
if (studentId != data.studentId)
|
||||||
|
return@run
|
||||||
|
|
||||||
|
val id = cols[0].toLong()
|
||||||
|
val text = cols[4]
|
||||||
|
val semester = cols[6].toInt()
|
||||||
|
val type = when (cols[3]) {
|
||||||
|
"0" -> Notice.TYPE_NEGATIVE
|
||||||
|
"1" -> Notice.TYPE_POSITIVE
|
||||||
|
else -> Notice.TYPE_NEUTRAL
|
||||||
|
}
|
||||||
|
val teacherId = cols[5].toLong()
|
||||||
|
val addedDate = Date.fromYmd(cols[7]).inMillis
|
||||||
|
|
||||||
|
val noticeObject = Notice(
|
||||||
|
data.profileId,
|
||||||
|
id,
|
||||||
|
text,
|
||||||
|
semester,
|
||||||
|
type,
|
||||||
|
teacherId)
|
||||||
|
|
||||||
|
data.noticeList.add(noticeObject)
|
||||||
|
data.metadataList.add(
|
||||||
|
Metadata(
|
||||||
|
data.profileId,
|
||||||
|
Metadata.TYPE_NOTICE,
|
||||||
|
id,
|
||||||
|
data.profile?.empty ?: false,
|
||||||
|
data.profile?.empty ?: false,
|
||||||
|
addedDate
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
@ -141,7 +141,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
val metadataList = mutableListOf<Metadata>()
|
val metadataList = mutableListOf<Metadata>()
|
||||||
val messageMetadataList = mutableListOf<Metadata>()
|
val messageMetadataList = mutableListOf<Metadata>()
|
||||||
|
|
||||||
private val db by lazy { app.db }
|
val db by lazy { app.db }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user