forked from github/szkolny
[API/Edudziennik] Add getting whole homework body.
This commit is contained in:
parent
ea4919a25d
commit
03c9932b8c
@ -171,6 +171,9 @@ object Regexes {
|
|||||||
val EDUDZIENNIK_ANNOUNCEMENT_DESCRIPTION by lazy {
|
val EDUDZIENNIK_ANNOUNCEMENT_DESCRIPTION by lazy {
|
||||||
"""<div class="desc">.*?<p>(.*?)</p>""".toRegex(DOT_MATCHES_ALL)
|
"""<div class="desc">.*?<p>(.*?)</p>""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
|
val EDUDZIENNIK_HOMEWORK_DESCRIPTION by lazy {
|
||||||
|
"""<div class="desc">(.*?)</div>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
|
||||||
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
||||||
"""/Courses/([\w-_]+?)/""".toRegex()
|
"""/Courses/([\w-_]+?)/""".toRegex()
|
||||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.App
|
|||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikData
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikData
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebGetAnnouncement
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebGetAnnouncement
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebGetHomework
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin.EdudziennikFirstLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin.EdudziennikFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
||||||
@ -96,7 +97,14 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
|||||||
|
|
||||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {}
|
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {}
|
||||||
override fun getRecipientList() {}
|
override fun getRecipientList() {}
|
||||||
override fun getEvent(eventFull: EventFull) {}
|
|
||||||
|
override fun getEvent(eventFull: EventFull) {
|
||||||
|
EdudziennikLoginWeb(data) {
|
||||||
|
EdudziennikWebGetHomework(data, eventFull) {
|
||||||
|
completed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun firstLogin() { EdudziennikFirstLogin(data) { completed() } }
|
override fun firstLogin() { EdudziennikFirstLogin(data) { completed() } }
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
import android.text.Html
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||||
|
|
||||||
|
class EdudziennikWebGetHomework(
|
||||||
|
override val data: DataEdudziennik,
|
||||||
|
val event: EventFull,
|
||||||
|
val onSuccess: () -> Unit
|
||||||
|
) : EdudziennikWeb(data, null) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "EdudziennikWebGetHomework"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (event.attachmentNames.isNotNullNorEmpty()) {
|
||||||
|
val id = event.attachmentNames!![0]
|
||||||
|
|
||||||
|
webGet(TAG, "Homework/$id") { text ->
|
||||||
|
val description = Regexes.EDUDZIENNIK_HOMEWORK_DESCRIPTION.find(text)?.get(1)?.trim()
|
||||||
|
|
||||||
|
if (description != null) event.topic = Html.fromHtml(description).toString()
|
||||||
|
|
||||||
|
event.homeworkBody = ""
|
||||||
|
event.attachmentNames = null
|
||||||
|
|
||||||
|
data.eventList += event
|
||||||
|
data.eventListReplace = true
|
||||||
|
|
||||||
|
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,8 +33,8 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
|||||||
if (doc.getElementsByClass("message").text().trim() != "Brak prac domowych") {
|
if (doc.getElementsByClass("message").text().trim() != "Brak prac domowych") {
|
||||||
doc.getElementsByTag("tr").forEach { homeworkElement ->
|
doc.getElementsByTag("tr").forEach { homeworkElement ->
|
||||||
val dateElement = homeworkElement.getElementsByClass("date").first().child(0)
|
val dateElement = homeworkElement.getElementsByClass("date").first().child(0)
|
||||||
val id = EDUDZIENNIK_HOMEWORK_ID.find(dateElement.attr("href"))?.get(1)?.crc32()
|
val idStr = EDUDZIENNIK_HOMEWORK_ID.find(dateElement.attr("href"))?.get(1) ?: return@forEach
|
||||||
?: return@forEach
|
val id = idStr.crc32()
|
||||||
val date = Date.fromY_m_d(dateElement.text())
|
val date = Date.fromY_m_d(dateElement.text())
|
||||||
|
|
||||||
val subjectElement = homeworkElement.child(1).child(0)
|
val subjectElement = homeworkElement.child(1).child(0)
|
||||||
@ -64,6 +64,8 @@ class EdudziennikWebHomework(override val data: DataEdudziennik,
|
|||||||
teamId = data.teamClass?.id ?: -1
|
teamId = data.teamClass?.id ?: -1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
eventObject.attachmentNames = mutableListOf(idStr)
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
|
@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
|||||||
LibrusLesson::class,
|
LibrusLesson::class,
|
||||||
TimetableManual::class,
|
TimetableManual::class,
|
||||||
Metadata::class
|
Metadata::class
|
||||||
], version = 84)
|
], version = 85)
|
||||||
@TypeConverters(
|
@TypeConverters(
|
||||||
ConverterTime::class,
|
ConverterTime::class,
|
||||||
ConverterDate::class,
|
ConverterDate::class,
|
||||||
@ -169,7 +169,8 @@ abstract class AppDb : RoomDatabase() {
|
|||||||
Migration81(),
|
Migration81(),
|
||||||
Migration82(),
|
Migration82(),
|
||||||
Migration83(),
|
Migration83(),
|
||||||
Migration84()
|
Migration84(),
|
||||||
|
Migration85()
|
||||||
).allowMainThreadQueries().build()
|
).allowMainThreadQueries().build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package pl.szczodrzynski.edziennik.data.db.migration
|
||||||
|
|
||||||
|
import androidx.room.migration.Migration
|
||||||
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_EDUDZIENNIK
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
|
|
||||||
|
class Migration85 : Migration(84, 85) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("DELETE FROM events WHERE eventAddedManually = 0 AND eventType = ${Event.TYPE_HOMEWORK} AND profileId IN (SELECT profileId FROM (SELECT profileId FROM profiles WHERE loginStoreType = $LOGIN_TYPE_EDUDZIENNIK) x)")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user