mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Vulcan/Hebe] Add getting notices.
This commit is contained in:
parent
c698dfdb73
commit
1eecd24d91
@ -135,6 +135,7 @@ const val VULCAN_HEBE_ENDPOINT_EXAMS = "api/mobile/exam"
|
|||||||
const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
|
const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
|
||||||
const val VULCAN_HEBE_ENDPOINT_GRADE_SUMMARY = "api/mobile/grade/summary"
|
const val VULCAN_HEBE_ENDPOINT_GRADE_SUMMARY = "api/mobile/grade/summary"
|
||||||
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
||||||
|
const val VULCAN_HEBE_ENDPOINT_NOTICES = "api/mobile/note"
|
||||||
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
|
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
|
||||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
|
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
|
||||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS = "api/mobile/message/status"
|
const val VULCAN_HEBE_ENDPOINT_MESSAGES_STATUS = "api/mobile/message/status"
|
||||||
|
@ -30,6 +30,7 @@ const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030
|
|||||||
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
||||||
const val ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY = 3050
|
const val ENDPOINT_VULCAN_HEBE_GRADE_SUMMARY = 3050
|
||||||
const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
||||||
|
const val ENDPOINT_VULCAN_HEBE_NOTICES = 3070
|
||||||
const val ENDPOINT_VULCAN_HEBE_ATTENDANCE = 3080
|
const val ENDPOINT_VULCAN_HEBE_ATTENDANCE = 3080
|
||||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX = 3090
|
const val ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX = 3090
|
||||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_SENT = 3100
|
const val ENDPOINT_VULCAN_HEBE_MESSAGES_SENT = 3100
|
||||||
@ -70,6 +71,9 @@ val VulcanFeatures = listOf(
|
|||||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf(
|
Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf(
|
||||||
ENDPOINT_VULCAN_API_NOTICES to LOGIN_METHOD_VULCAN_API
|
ENDPOINT_VULCAN_API_NOTICES to LOGIN_METHOD_VULCAN_API
|
||||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||||
|
Feature(LOGIN_TYPE_VULCAN, FEATURE_BEHAVIOUR, listOf(
|
||||||
|
ENDPOINT_VULCAN_HEBE_NOTICES to LOGIN_METHOD_VULCAN_HEBE
|
||||||
|
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||||
// attendance
|
// attendance
|
||||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
||||||
ENDPOINT_VULCAN_API_ATTENDANCE to LOGIN_METHOD_VULCAN_API
|
ENDPOINT_VULCAN_API_ATTENDANCE to LOGIN_METHOD_VULCAN_API
|
||||||
|
@ -24,6 +24,9 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
ENDPOINT_VULCAN_HEBE_MAIN,
|
ENDPOINT_VULCAN_HEBE_MAIN,
|
||||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK,
|
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK,
|
||||||
ENDPOINT_VULCAN_HEBE_TIMETABLE,
|
ENDPOINT_VULCAN_HEBE_TIMETABLE,
|
||||||
|
ENDPOINT_VULCAN_HEBE_EXAMS,
|
||||||
|
ENDPOINT_VULCAN_HEBE_HOMEWORK,
|
||||||
|
ENDPOINT_VULCAN_HEBE_NOTICES,
|
||||||
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX,
|
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX,
|
||||||
ENDPOINT_VULCAN_HEBE_MESSAGES_SENT
|
ENDPOINT_VULCAN_HEBE_MESSAGES_SENT
|
||||||
)
|
)
|
||||||
@ -176,6 +179,14 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||||
VulcanHebeHomework(data, lastSync, onSuccess)
|
VulcanHebeHomework(data, lastSync, onSuccess)
|
||||||
}
|
}
|
||||||
|
ENDPOINT_VULCAN_HEBE_NOTICES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||||
|
VulcanHebeNotices(data, lastSync, onSuccess)
|
||||||
|
}
|
||||||
|
ENDPOINT_VULCAN_HEBE_ATTENDANCE -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||||
|
VulcanHebeAttendance(data, lastSync, onSuccess)
|
||||||
|
}
|
||||||
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX -> {
|
ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||||
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_RECEIVED)
|
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_RECEIVED)
|
||||||
@ -184,10 +195,6 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||||
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_SENT)
|
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_SENT)
|
||||||
}
|
}
|
||||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE -> {
|
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
|
||||||
VulcanHebeAttendance(data, lastSync, onSuccess)
|
|
||||||
}
|
|
||||||
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER -> {
|
ENDPOINT_VULCAN_HEBE_LUCKY_NUMBER -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||||
VulcanHebeLuckyNumber(data, lastSync, onSuccess)
|
VulcanHebeLuckyNumber(data, lastSync, onSuccess)
|
||||||
|
@ -46,7 +46,11 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
val profile
|
val profile
|
||||||
get() = data.profile
|
get() = data.profile
|
||||||
|
|
||||||
fun getDateTime(json: JsonObject?, key: String, default: Long = System.currentTimeMillis()): Long {
|
fun getDateTime(
|
||||||
|
json: JsonObject?,
|
||||||
|
key: String,
|
||||||
|
default: Long = System.currentTimeMillis()
|
||||||
|
): Long {
|
||||||
val date = json.getJsonObject(key)
|
val date = json.getJsonObject(key)
|
||||||
return date.getLong("Timestamp") ?: return default
|
return date.getLong("Timestamp") ?: return default
|
||||||
}
|
}
|
||||||
@ -146,6 +150,12 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
2
|
2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isCurrentYear(date: Date): Boolean {
|
||||||
|
return profile?.let { profile ->
|
||||||
|
return@let profile.dateSemester1Start >= date
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <reified T> apiRequest(
|
inline fun <reified T> apiRequest(
|
||||||
tag: String,
|
tag: String,
|
||||||
endpoint: String,
|
endpoint: String,
|
||||||
@ -197,7 +207,8 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
val callback = object : JsonCallbackHandler() {
|
val callback = object : JsonCallbackHandler() {
|
||||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
data.error(ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
data.error(
|
||||||
|
ApiError(TAG, ERROR_RESPONSE_EMPTY)
|
||||||
.withResponse(response)
|
.withResponse(response)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -205,9 +216,11 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
|
|
||||||
val status = json.getJsonObject("Status")
|
val status = json.getJsonObject("Status")
|
||||||
if (status?.getInt("Code") != 0) {
|
if (status?.getInt("Code") != 0) {
|
||||||
data.error(ApiError(tag, ERROR_VULCAN_HEBE_OTHER)
|
data.error(
|
||||||
.withResponse(response)
|
ApiError(tag, ERROR_VULCAN_HEBE_OTHER)
|
||||||
.withApiResponse(json.toString()))
|
.withResponse(response)
|
||||||
|
.withApiResponse(json.toString())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val envelope = if (json.get("Envelope").isJsonNull && null is T)
|
val envelope = if (json.get("Envelope").isJsonNull && null is T)
|
||||||
@ -217,9 +230,10 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
JsonArray::class.java -> json.getJsonArray("Envelope") as T
|
JsonArray::class.java -> json.getJsonArray("Envelope") as T
|
||||||
java.lang.Boolean::class.java -> json.getBoolean("Envelope") as T
|
java.lang.Boolean::class.java -> json.getBoolean("Envelope") as T
|
||||||
else -> {
|
else -> {
|
||||||
data.error(ApiError(tag, ERROR_RESPONSE_EMPTY)
|
data.error(
|
||||||
.withResponse(response)
|
ApiError(tag, ERROR_RESPONSE_EMPTY)
|
||||||
.withApiResponse(json)
|
.withResponse(response)
|
||||||
|
.withApiResponse(json)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -228,7 +242,8 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
try {
|
try {
|
||||||
onSuccess(envelope, response)
|
onSuccess(envelope, response)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
data.error(ApiError(tag, EXCEPTION_VULCAN_HEBE_REQUEST)
|
data.error(
|
||||||
|
ApiError(tag, EXCEPTION_VULCAN_HEBE_REQUEST)
|
||||||
.withResponse(response)
|
.withResponse(response)
|
||||||
.withThrowable(e)
|
.withThrowable(e)
|
||||||
.withApiResponse(json)
|
.withApiResponse(json)
|
||||||
@ -237,7 +252,8 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||||
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
data.error(
|
||||||
|
ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||||
.withResponse(response)
|
.withResponse(response)
|
||||||
.withThrowable(throwable)
|
.withThrowable(throwable)
|
||||||
)
|
)
|
||||||
@ -353,10 +369,15 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
if (folder != null)
|
if (folder != null)
|
||||||
query["folder"] = folder.toString()
|
query["folder"] = folder.toString()
|
||||||
|
|
||||||
|
val semester1Start = profile?.dateSemester1Start?.inMillis
|
||||||
|
|
||||||
query["lastId"] = "-2147483648" // don't ask, it's just Vulcan
|
query["lastId"] = "-2147483648" // don't ask, it's just Vulcan
|
||||||
query["pageSize"] = "500"
|
query["pageSize"] = "500"
|
||||||
query["lastSyncDate"] = LocalDateTime
|
query["lastSyncDate"] = LocalDateTime
|
||||||
.ofInstant(Instant.ofEpochMilli(lastSync ?: 0), ZoneId.systemDefault())
|
.ofInstant(
|
||||||
|
Instant.ofEpochMilli(lastSync ?: semester1Start ?: 0),
|
||||||
|
ZoneId.systemDefault()
|
||||||
|
)
|
||||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||||
|
|
||||||
apiGet(tag, url, query) { json: JsonArray, response ->
|
apiGet(tag, url, query) { json: JsonArray, response ->
|
||||||
|
@ -25,16 +25,10 @@ class VulcanHebeAttendance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val semesterNumber = data.studentSemesterNumber
|
|
||||||
val startDate = profile?.getSemesterStart(semesterNumber)
|
|
||||||
val endDate = profile?.getSemesterEnd(semesterNumber)
|
|
||||||
|
|
||||||
apiGetList(
|
apiGetList(
|
||||||
TAG,
|
TAG,
|
||||||
VULCAN_HEBE_ENDPOINT_ATTENDANCE,
|
VULCAN_HEBE_ENDPOINT_ATTENDANCE,
|
||||||
HebeFilterType.BY_PUPIL,
|
HebeFilterType.BY_PUPIL,
|
||||||
dateFrom = startDate,
|
|
||||||
dateTo = endDate,
|
|
||||||
lastSync = lastSync
|
lastSync = lastSync
|
||||||
) { list, _ ->
|
) { list, _ ->
|
||||||
list.forEach { attendance ->
|
list.forEach { attendance ->
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2021-2-22
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_NOTICES
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_NOTICES
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Notice
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||||
|
|
||||||
|
class VulcanHebeNotices(
|
||||||
|
override val data: DataVulcan,
|
||||||
|
override val lastSync: Long?,
|
||||||
|
val onSuccess: (endpointId: Int) -> Unit
|
||||||
|
) : VulcanHebe(data, lastSync) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VulcanHebeNotices"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
apiGetList(
|
||||||
|
VulcanHebeAttendance.TAG,
|
||||||
|
VULCAN_HEBE_ENDPOINT_NOTICES,
|
||||||
|
HebeFilterType.BY_PUPIL,
|
||||||
|
lastSync = lastSync
|
||||||
|
) { list, _ ->
|
||||||
|
list.forEach { notice ->
|
||||||
|
val id = notice.getLong("Id") ?: return@forEach
|
||||||
|
val type = when (notice.getBoolean("Positive")) {
|
||||||
|
true -> Notice.TYPE_POSITIVE
|
||||||
|
else -> Notice.TYPE_NEUTRAL
|
||||||
|
}
|
||||||
|
val date = getDate(notice, "DateValid") ?: return@forEach
|
||||||
|
val semester = profile?.dateToSemester(date) ?: return@forEach
|
||||||
|
val text = notice.getString("Content") ?: ""
|
||||||
|
val category = notice.getJsonObject("Category")?.getString("Name")
|
||||||
|
val points = notice.getFloat("Points")
|
||||||
|
val teacherId = getTeacherId(notice, "Creator") ?: -1
|
||||||
|
val addedDate = getDateTime(notice, "DateModify")
|
||||||
|
|
||||||
|
if (!isCurrentYear(date)) return@forEach
|
||||||
|
|
||||||
|
val noticeObject = Notice(
|
||||||
|
profileId = profileId,
|
||||||
|
id = id,
|
||||||
|
type = type,
|
||||||
|
semester = semester,
|
||||||
|
text = text,
|
||||||
|
category = category,
|
||||||
|
points = points,
|
||||||
|
teacherId = teacherId,
|
||||||
|
addedDate = addedDate
|
||||||
|
)
|
||||||
|
|
||||||
|
data.noticeList.add(noticeObject)
|
||||||
|
data.metadataList.add(
|
||||||
|
Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_NOTICE,
|
||||||
|
id,
|
||||||
|
profile?.empty ?: true,
|
||||||
|
profile?.empty ?: true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_VULCAN_HEBE_NOTICES, SYNC_ALWAYS)
|
||||||
|
onSuccess(ENDPOINT_VULCAN_HEBE_NOTICES)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user