forked from github/szkolny
[Events] Add Mobidziennik event attachment listing.
This commit is contained in:
parent
14d267a95a
commit
ddb2760c16
@ -1208,3 +1208,7 @@ val SwipeRefreshLayout.onScrollListener: RecyclerView.OnScrollListener
|
|||||||
this@onScrollListener.isEnabled = true
|
this@onScrollListener.isEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator fun <K, V> Iterable<Pair<K, V>>.get(key: K): V? {
|
||||||
|
return firstOrNull { it.first == key }?.second
|
||||||
|
}
|
||||||
|
@ -84,6 +84,22 @@ object Regexes {
|
|||||||
"""<strong>(.+?) - (.*?)</strong>.+?<small>.+?\((.+?), .+?(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
"""<strong>(.+?) - (.*?)</strong>.+?<small>.+?\((.+?), .+?(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MOBIDZIENNIK_HOMEWORK_ROW by lazy {
|
||||||
|
"""class="rowRolling">(.+?</div>\s*</td>)""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
val MOBIDZIENNIK_HOMEWORK_ITEM by lazy {
|
||||||
|
"""<p><b>(.+?):</b>\s*(.+?)\s*</p>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
val MOBIDZIENNIK_HOMEWORK_BODY by lazy {
|
||||||
|
"""Treść:</b>(.+?)<p><b>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
val MOBIDZIENNIK_HOMEWORK_ID by lazy {
|
||||||
|
"""zadanieFormularz\(([0-9]+),""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
val MOBIDZIENNIK_HOMEWORK_ATTACHMENT by lazy {
|
||||||
|
"""zalacznik=([0-9]+)'.+?word-break">(.+?)</td>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val IDZIENNIK_LOGIN_HIDDEN_FIELDS by lazy {
|
val IDZIENNIK_LOGIN_HIDDEN_FIELDS by lazy {
|
||||||
|
@ -8,10 +8,7 @@ import com.google.gson.JsonObject
|
|||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.MobidziennikData
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.MobidziennikData
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetAttachment
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetMessage
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebGetRecipientList
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web.MobidziennikWebSendMessage
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.firstlogin.MobidziennikFirstLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.firstlogin.MobidziennikFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.login.MobidziennikLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
@ -25,6 +22,7 @@ import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
|||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginStore, val callback: EdziennikCallback) : EdziennikInterface {
|
class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginStore, val callback: EdziennikCallback) : EdziennikInterface {
|
||||||
companion object {
|
companion object {
|
||||||
@ -122,7 +120,18 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEvent(eventFull: EventFull) {}
|
override fun getEvent(eventFull: EventFull) {
|
||||||
|
val type = if (eventFull.date >= Date.getToday())
|
||||||
|
MobidziennikWebHomework.TYPE_CURRENT
|
||||||
|
else
|
||||||
|
MobidziennikWebHomework.TYPE_PAST
|
||||||
|
|
||||||
|
login(LOGIN_METHOD_MOBIDZIENNIK_WEB) {
|
||||||
|
MobidziennikWebHomework(data, 0L, type, eventFull) {
|
||||||
|
completed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun firstLogin() { MobidziennikFirstLogin(data) { completed() } }
|
override fun firstLogin() { MobidziennikFirstLogin(data) { completed() } }
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
|
@ -17,6 +17,7 @@ const val ENDPOINT_MOBIDZIENNIK_WEB_NOTICES = 2040
|
|||||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ATTENDANCE = 2050
|
const val ENDPOINT_MOBIDZIENNIK_WEB_ATTENDANCE = 2050
|
||||||
const val ENDPOINT_MOBIDZIENNIK_WEB_MANUALS = 2100
|
const val ENDPOINT_MOBIDZIENNIK_WEB_MANUALS = 2100
|
||||||
const val ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL = 2200
|
const val ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL = 2200
|
||||||
|
const val ENDPOINT_MOBIDZIENNIK_WEB_HOMEWORK = 2300 // not used as an endpoint
|
||||||
const val ENDPOINT_MOBIDZIENNIK_API2_MAIN = 3000
|
const val ENDPOINT_MOBIDZIENNIK_API2_MAIN = 3000
|
||||||
|
|
||||||
val MobidziennikFeatures = listOf(
|
val MobidziennikFeatures = listOf(
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2020-3-31.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.web
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_HOMEWORK
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.data.MobidziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
|
||||||
|
class MobidziennikWebHomework(override val data: DataMobidziennik,
|
||||||
|
override val lastSync: Long?,
|
||||||
|
val type: Int = TYPE_CURRENT,
|
||||||
|
val event: EventFull,
|
||||||
|
val onSuccess: (endpointId: Int) -> Unit
|
||||||
|
) : MobidziennikWeb(data, lastSync) {
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "MobidziennikWebHomework"
|
||||||
|
const val TYPE_CURRENT = 0
|
||||||
|
const val TYPE_PAST = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val endpoint = when (type) {
|
||||||
|
TYPE_PAST -> "zadaniadomowearchiwalne"
|
||||||
|
else -> "zadaniadomowe"
|
||||||
|
}
|
||||||
|
webGet(TAG, "/mobile/$endpoint") { text ->
|
||||||
|
MobidziennikLuckyNumberExtractor(data, text)
|
||||||
|
|
||||||
|
Regexes.MOBIDZIENNIK_HOMEWORK_ROW.findAll(text).forEach { homeworkMatch ->
|
||||||
|
val tableRow = homeworkMatch[1].ifBlank { return@forEach }
|
||||||
|
|
||||||
|
/*val items = Regexes.MOBIDZIENNIK_HOMEWORK_ITEM.findAll(tableRow).map { match ->
|
||||||
|
match[1] to match[2].fixWhiteSpaces()
|
||||||
|
}.toList()*/
|
||||||
|
|
||||||
|
val id = Regexes.MOBIDZIENNIK_HOMEWORK_ID.find(tableRow)?.get(1)?.toLongOrNull() ?: return@forEach
|
||||||
|
if (event.id != id)
|
||||||
|
return@forEach
|
||||||
|
|
||||||
|
//val homeworkBody = Regexes.MOBIDZIENNIK_HOMEWORK_BODY.find(tableRow)?.get(1) ?: ""
|
||||||
|
|
||||||
|
event.attachmentIds = mutableListOf()
|
||||||
|
event.attachmentNames = mutableListOf()
|
||||||
|
Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach {
|
||||||
|
event.attachmentIds?.add(it[1].toLongOrNull() ?: return@forEach)
|
||||||
|
event.attachmentNames?.add(it[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
event.homeworkBody = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
//data.eventList.add(eventObject)
|
||||||
|
//data.metadataList.add(
|
||||||
|
// Metadata(
|
||||||
|
// profileId,
|
||||||
|
// Metadata.TYPE_EVENT,
|
||||||
|
// eventObject.id,
|
||||||
|
// profile?.empty ?: false,
|
||||||
|
// profile?.empty ?: false,
|
||||||
|
// System.currentTimeMillis() /* no addedDate here though */
|
||||||
|
// ))
|
||||||
|
|
||||||
|
// not used as an endpoint
|
||||||
|
//data.setSyncNext(ENDPOINT_MOBIDZIENNIK_WEB_HOMEWORK, SYNC_ALWAYS)
|
||||||
|
data.eventList.add(event)
|
||||||
|
data.eventListReplace = true
|
||||||
|
|
||||||
|
EventBus.getDefault().postSticky(EventGetEvent(event))
|
||||||
|
onSuccess(ENDPOINT_MOBIDZIENNIK_WEB_HOMEWORK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -82,9 +82,15 @@ open class Event(
|
|||||||
@ColumnInfo(name = "eventIsDone")
|
@ColumnInfo(name = "eventIsDone")
|
||||||
var isDone: Boolean = false
|
var isDone: Boolean = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Body/text of the event, if this is a [TYPE_HOMEWORK].
|
||||||
|
* May be null if the body is not downloaded yet, or the type is not [TYPE_HOMEWORK].
|
||||||
|
* May be empty or blank if the homework has no specific body attached,
|
||||||
|
* or the topic contains the body already.
|
||||||
|
*/
|
||||||
var homeworkBody: String? = null
|
var homeworkBody: String? = null
|
||||||
var attachmentIds: List<Long>? = null
|
var attachmentIds: MutableList<Long>? = null
|
||||||
var attachmentNames: List<String>? = null
|
var attachmentNames: MutableList<String>? = null
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
var showAsUnseen = false
|
var showAsUnseen = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user