mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[APIv2/Vulcan] Add getting events
This commit is contained in:
parent
0e5a32b253
commit
9e6741d542
@ -10,7 +10,7 @@ import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
|||||||
const val ENDPOINT_VULCAN_API_STUDENT_LIST = 1000
|
const val ENDPOINT_VULCAN_API_STUDENT_LIST = 1000
|
||||||
const val ENDPOINT_VULCAN_API_DICTIONARIES = 1010
|
const val ENDPOINT_VULCAN_API_DICTIONARIES = 1010
|
||||||
const val ENDPOINT_VULCAN_API_TIMETABLE = 1020
|
const val ENDPOINT_VULCAN_API_TIMETABLE = 1020
|
||||||
const val ENDPOINT_VULCAN_API_EXAMS = 1030
|
const val ENDPOINT_VULCAN_API_EVENTS = 1030
|
||||||
const val ENDPOINT_VULCAN_API_GRADES = 1040
|
const val ENDPOINT_VULCAN_API_GRADES = 1040
|
||||||
const val ENDPOINT_VULCAN_API_GRADES_SUMMARY = 1050
|
const val ENDPOINT_VULCAN_API_GRADES_SUMMARY = 1050
|
||||||
const val ENDPOINT_VULCAN_API_HOMEWORK = 1060
|
const val ENDPOINT_VULCAN_API_HOMEWORK = 1060
|
||||||
@ -26,7 +26,7 @@ val VulcanFeatures = listOf(
|
|||||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||||
// agenda
|
// agenda
|
||||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
Feature(LOGIN_TYPE_VULCAN, FEATURE_AGENDA, listOf(
|
||||||
ENDPOINT_VULCAN_API_EXAMS to LOGIN_METHOD_VULCAN_API
|
ENDPOINT_VULCAN_API_EVENTS to LOGIN_METHOD_VULCAN_API
|
||||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||||
// grades
|
// grades
|
||||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_GRADES, listOf(
|
Feature(LOGIN_TYPE_VULCAN, FEATURE_GRADES, listOf(
|
||||||
@ -82,4 +82,4 @@ val VulcanFeatures = listOf(
|
|||||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),*/
|
), listOf(LOGIN_METHOD_VULCAN_WEB)),*/
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.api.v2.*
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -31,18 +32,30 @@ open class VulcanApi(open val data: DataVulcan) {
|
|||||||
baseUrl: Boolean = false, onSuccess: (json: JsonObject, response: Response?) -> Unit) {
|
baseUrl: Boolean = false, onSuccess: (json: JsonObject, response: Response?) -> Unit) {
|
||||||
val url = "${if (baseUrl) data.apiUrl else data.fullApiUrl}$endpoint"
|
val url = "${if (baseUrl) data.apiUrl else data.fullApiUrl}$endpoint"
|
||||||
|
|
||||||
d(tag, "Request: Librus/Api - $url")
|
d(tag, "Request: Vulcan/Api - $url")
|
||||||
|
|
||||||
|
val startDate = when(profile?.empty) {
|
||||||
|
true -> profile?.getSemesterStart(profile?.currentSemester ?: 1)?.stringY_m_d
|
||||||
|
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||||
|
}
|
||||||
|
val endDate = profile?.getSemesterEnd(profile?.currentSemester ?: 1)?.stringY_m_d
|
||||||
|
|
||||||
val finalPayload = JsonObject()
|
val finalPayload = JsonObject()
|
||||||
finalPayload.addProperty("IdUczen", data.studentId)
|
finalPayload.addProperty("IdUczen", data.studentId)
|
||||||
finalPayload.addProperty("IdOkresKlasyfikacyjny", data.studentSemesterId)
|
finalPayload.addProperty("IdOkresKlasyfikacyjny", data.studentSemesterId)
|
||||||
finalPayload.addProperty("IdOddzial", data.studentClassId)
|
finalPayload.addProperty("IdOddzial", data.studentClassId)
|
||||||
|
finalPayload.addProperty("DataPoczatkowa", startDate)
|
||||||
|
finalPayload.addProperty("DataKoncowa", endDate)
|
||||||
finalPayload.addProperty("RemoteMobileTimeKey", System.currentTimeMillis() / 1000)
|
finalPayload.addProperty("RemoteMobileTimeKey", System.currentTimeMillis() / 1000)
|
||||||
finalPayload.addProperty("TimeKey", System.currentTimeMillis() / 1000 - 1)
|
finalPayload.addProperty("TimeKey", System.currentTimeMillis() / 1000 - 1)
|
||||||
finalPayload.addProperty("RequestId", UUID.randomUUID().toString())
|
finalPayload.addProperty("RequestId", UUID.randomUUID().toString())
|
||||||
finalPayload.addProperty("RemoteMobileAppVersion", VULCAN_API_APP_VERSION)
|
finalPayload.addProperty("RemoteMobileAppVersion", VULCAN_API_APP_VERSION)
|
||||||
finalPayload.addProperty("RemoteMobileAppName", VULCAN_API_APP_NAME)
|
finalPayload.addProperty("RemoteMobileAppName", VULCAN_API_APP_NAME)
|
||||||
|
|
||||||
|
payload?.keySet()?.forEach {
|
||||||
|
finalPayload.add(it, payload.get(it))
|
||||||
|
}
|
||||||
|
|
||||||
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 && response?.parserErrorBody == null) {
|
if (json == null && response?.parserErrorBody == null) {
|
||||||
|
@ -7,8 +7,10 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan.data
|
|||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_DICTIONARIES
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_DICTIONARIES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_EVENTS
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_GRADES
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_GRADES
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiDictionaries
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiDictionaries
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiEvents
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
|
|
||||||
@ -48,6 +50,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||||
VulcanApiGrades(data) { onSuccess() }
|
VulcanApiGrades(data) { onSuccess() }
|
||||||
}
|
}
|
||||||
|
ENDPOINT_VULCAN_API_EVENTS -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_events)
|
||||||
|
VulcanApiEvents(data) { onSuccess() }
|
||||||
|
}
|
||||||
else -> onSuccess()
|
else -> onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-10-20
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_EVENTS
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_EVENTS
|
||||||
|
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.events.Event
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.getBoolean
|
||||||
|
import pl.szczodrzynski.edziennik.getJsonArray
|
||||||
|
import pl.szczodrzynski.edziennik.getLong
|
||||||
|
import pl.szczodrzynski.edziennik.getString
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class VulcanApiEvents(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VulcanApi"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
apiGet(TAG, VULCAN_API_ENDPOINT_EVENTS) { json, _ ->
|
||||||
|
val events = json.getJsonArray("Data")
|
||||||
|
|
||||||
|
events?.forEach { eventEl ->
|
||||||
|
val event = eventEl.asJsonObject
|
||||||
|
|
||||||
|
val id = event?.getLong("Id") ?: return@forEach
|
||||||
|
val eventDate = Date.fromY_m_d(event.getString("DataTekst") ?: return@forEach)
|
||||||
|
val subjectId = event.getLong("IdPrzedmiot") ?: -1
|
||||||
|
val teacherId = event.getLong("IdPracownik") ?: -1
|
||||||
|
val startTime = data.lessonList.singleOrNull {
|
||||||
|
it.weekDay == eventDate.weekDay && it.subjectId == subjectId
|
||||||
|
}?.startTime
|
||||||
|
val topic = event.getString("Opis") ?: ""
|
||||||
|
val type = when (event.getBoolean("Rodzaj")) {
|
||||||
|
true -> Event.TYPE_EXAM
|
||||||
|
else -> Event.TYPE_SHORT_QUIZ
|
||||||
|
}
|
||||||
|
val teamId = event.getLong("IdOddzial") ?: data.teamClass?.id ?: return@forEach
|
||||||
|
|
||||||
|
val eventObject = Event(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
eventDate,
|
||||||
|
startTime,
|
||||||
|
topic,
|
||||||
|
-1,
|
||||||
|
type,
|
||||||
|
false,
|
||||||
|
teacherId,
|
||||||
|
subjectId,
|
||||||
|
teamId
|
||||||
|
)
|
||||||
|
|
||||||
|
data.eventList.add(eventObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_EVENT,
|
||||||
|
id,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_VULCAN_API_EVENTS, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.db.modules.events;
|
package pl.szczodrzynski.edziennik.data.db.modules.events;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.Ignore;
|
import androidx.room.Ignore;
|
||||||
@ -19,6 +20,7 @@ public class Event {
|
|||||||
@ColumnInfo(name = "eventDate")
|
@ColumnInfo(name = "eventDate")
|
||||||
public Date eventDate;
|
public Date eventDate;
|
||||||
@ColumnInfo(name = "eventStartTime")
|
@ColumnInfo(name = "eventStartTime")
|
||||||
|
@Nullable
|
||||||
public Time startTime; // null for allDay
|
public Time startTime; // null for allDay
|
||||||
@ColumnInfo(name = "eventTopic")
|
@ColumnInfo(name = "eventTopic")
|
||||||
public String topic;
|
public String topic;
|
||||||
@ -68,7 +70,7 @@ public class Event {
|
|||||||
@Ignore
|
@Ignore
|
||||||
public Event() {}
|
public Event() {}
|
||||||
|
|
||||||
public Event(int profileId, long id, Date eventDate, Time startTime, String topic, int color, int type, boolean addedManually, long teacherId, long subjectId, long teamId)
|
public Event(int profileId, long id, Date eventDate, @Nullable Time startTime, String topic, int color, int type, boolean addedManually, long teacherId, long subjectId, long teamId)
|
||||||
{
|
{
|
||||||
this.profileId = profileId;
|
this.profileId = profileId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user