mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 21:52:44 +01:00
[API/Edudziennik] Fix fix for semesters and getting grades on first login.
This commit is contained in:
parent
2050083bce
commit
c5ce582678
@ -74,6 +74,11 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
| | | | __| '_ \ / _ \ '__|
|
| | | | __| '_ \ / _ \ '__|
|
||||||
| |__| | |_| | | | __/ |
|
| |__| | |_| | | | __/ |
|
||||||
\____/ \__|_| |_|\___|*/
|
\____/ \__|_| |_|\___|*/
|
||||||
|
private var mCurrentSemester: Int? = null
|
||||||
|
var currentSemester: Int
|
||||||
|
get() { mCurrentSemester = mCurrentSemester ?: profile?.getStudentData("currentSemester", 1); return mCurrentSemester ?: 1 }
|
||||||
|
set(value) { profile?.putStudentData("currentSemester", value) ?: return; mCurrentSemester = value }
|
||||||
|
|
||||||
private var mSchoolName: String? = null
|
private var mSchoolName: String? = null
|
||||||
var schoolName: String?
|
var schoolName: String?
|
||||||
get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName }
|
get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName }
|
||||||
|
@ -25,11 +25,11 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
val profile
|
val profile
|
||||||
get() = data.profile
|
get() = data.profile
|
||||||
|
|
||||||
fun webGet(tag: String, endpoint: String, xhr: Boolean = false, onSuccess: (text: String) -> Unit) {
|
fun webGet(tag: String, endpoint: String, xhr: Boolean = false, semester: Int? = null, onSuccess: (text: String) -> Unit) {
|
||||||
val url = "https://dziennikel.appspot.com/" + when (endpoint.endsWith('/') || endpoint.contains('?') || endpoint.isEmpty()) {
|
val url = "https://dziennikel.appspot.com/" + when (endpoint.endsWith('/') || endpoint.contains('?') || endpoint.isEmpty()) {
|
||||||
true -> endpoint
|
true -> endpoint
|
||||||
else -> "$endpoint/"
|
else -> "$endpoint/"
|
||||||
}
|
} + (semester?.let { "?semester=$it" } ?: "")
|
||||||
|
|
||||||
d(tag, "Request: Edudziennik/Web - $url")
|
d(tag, "Request: Edudziennik/Web - $url")
|
||||||
|
|
||||||
@ -41,11 +41,17 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (semester == null && url.contains("start")) {
|
||||||
|
profile?.also { profile ->
|
||||||
val cookies = data.app.cookieJar.getForDomain("dziennikel.appspot.com")
|
val cookies = data.app.cookieJar.getForDomain("dziennikel.appspot.com")
|
||||||
val semester = cookies.firstOrNull { it.name() == "semester" }?.value()?.toIntOrNull()
|
val semesterCookie = cookies.firstOrNull { it.name() == "semester" }?.value()?.toIntOrNull()
|
||||||
|
|
||||||
if (profile != null && semester == 2 && profile!!.dateSemester2Start > Date.getToday())
|
semesterCookie?.let { data.currentSemester = it }
|
||||||
profile!!.dateSemester2Start = Date.getToday().stepForward(0, 0, -1)
|
|
||||||
|
if (semesterCookie == 2 && profile.dateSemester2Start > Date.getToday())
|
||||||
|
profile.dateSemester2Start = Date.getToday().stepForward(0, 0, -1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onSuccess(text)
|
onSuccess(text)
|
||||||
|
@ -27,17 +27,18 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
|||||||
private const val TAG = "EdudziennikWebGrades"
|
private const val TAG = "EdudziennikWebGrades"
|
||||||
}
|
}
|
||||||
|
|
||||||
private var semester: Int = 1
|
private var requestSemester: Int? = null
|
||||||
|
|
||||||
init { data.profile?.also { profile ->
|
init {
|
||||||
semester = profile.currentSemester
|
if (profile?.empty == true && data.currentSemester == 2) requestSemester = 1
|
||||||
getGrades()
|
getGrades()
|
||||||
} ?: onSuccess() }
|
}
|
||||||
|
|
||||||
private fun getGrades() { data.profile?.also { profile ->
|
private fun getGrades() { data.profile?.also { profile ->
|
||||||
webGet(TAG, data.studentEndpoint + "start/?semester=$semester") { text ->
|
webGet(TAG, data.studentEndpoint + "start", semester = requestSemester) { text ->
|
||||||
val doc = Jsoup.parse(text)
|
val semester = requestSemester ?: data.currentSemester
|
||||||
|
|
||||||
|
val doc = Jsoup.parse(text)
|
||||||
val subjects = doc.select("#student_grades tbody").firstOrNull()?.children()
|
val subjects = doc.select("#student_grades tbody").firstOrNull()?.children()
|
||||||
|
|
||||||
subjects?.forEach { subjectElement ->
|
subjects?.forEach { subjectElement ->
|
||||||
@ -212,8 +213,8 @@ class EdudziennikWebGrades(override val data: DataEdudziennik,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.empty && semester == 2) {
|
if (profile.empty && requestSemester == 1 && data.currentSemester == 2) {
|
||||||
semester = 1
|
requestSemester = null
|
||||||
getGrades()
|
getGrades()
|
||||||
} else {
|
} else {
|
||||||
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_GRADES, SYNC_ALWAYS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user