mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[Mobidziennik] Fix syncing message lists.
This commit is contained in:
parent
e314fafaff
commit
aeed735521
@ -7,10 +7,12 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik
|
|||||||
import android.util.LongSparseArray
|
import android.util.LongSparseArray
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.Data
|
import pl.szczodrzynski.edziennik.data.api.models.Data
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||||
import pl.szczodrzynski.edziennik.ext.currentTimeUnix
|
import pl.szczodrzynski.edziennik.ext.currentTimeUnix
|
||||||
|
import pl.szczodrzynski.edziennik.ext.get
|
||||||
import pl.szczodrzynski.edziennik.ext.isNotNullNorEmpty
|
import pl.szczodrzynski.edziennik.ext.isNotNullNorEmpty
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
@ -35,6 +37,31 @@ class DataMobidziennik(app: App, profile: Profile?, loginStore: LoginStore) : Da
|
|||||||
|
|
||||||
override fun generateUserCode() = "$loginServerName:$loginUsername:$studentId"
|
override fun generateUserCode() = "$loginServerName:$loginUsername:$studentId"
|
||||||
|
|
||||||
|
fun parseDateTime(dateStr: String): Pair<Date, Time> {
|
||||||
|
// pt, 4 lut, 09:11
|
||||||
|
val dateParts = dateStr.split(',', ' ').filter { it.isNotEmpty() }
|
||||||
|
// [pt], [4], [lut], [09:11]
|
||||||
|
val date = Date.getToday()
|
||||||
|
date.day = dateParts[1].toIntOrNull() ?: 1
|
||||||
|
date.month = when (dateParts[2]) {
|
||||||
|
"sty" -> 1
|
||||||
|
"lut" -> 2
|
||||||
|
"mar" -> 3
|
||||||
|
"kwi" -> 4
|
||||||
|
"maj" -> 5
|
||||||
|
"cze" -> 6
|
||||||
|
"lip" -> 7
|
||||||
|
"sie" -> 8
|
||||||
|
"wrz" -> 9
|
||||||
|
"paź" -> 10
|
||||||
|
"lis" -> 11
|
||||||
|
"gru" -> 12
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
val time = Time.fromH_m(dateParts[3])
|
||||||
|
return date to time
|
||||||
|
}
|
||||||
|
|
||||||
val teachersMap = LongSparseArray<String>()
|
val teachersMap = LongSparseArray<String>()
|
||||||
val subjectsMap = LongSparseArray<String>()
|
val subjectsMap = LongSparseArray<String>()
|
||||||
|
|
||||||
|
@ -36,6 +36,10 @@ class MobidziennikWebMessagesInbox(override val data: DataMobidziennik,
|
|||||||
|
|
||||||
val doc = Jsoup.parse(text)
|
val doc = Jsoup.parse(text)
|
||||||
|
|
||||||
|
val today = Date.getToday()
|
||||||
|
var currentYear = today.year
|
||||||
|
var currentMonth = today.month
|
||||||
|
|
||||||
val list = doc.getElementsByClass("spis").first()?.getElementsByClass("podswietl")
|
val list = doc.getElementsByClass("spis").first()?.getElementsByClass("podswietl")
|
||||||
list?.forEach { item ->
|
list?.forEach { item ->
|
||||||
val id = item.attr("rel").toLongOrNull() ?: return@forEach
|
val id = item.attr("rel").toLongOrNull() ?: return@forEach
|
||||||
@ -47,15 +51,20 @@ class MobidziennikWebMessagesInbox(override val data: DataMobidziennik,
|
|||||||
}
|
}
|
||||||
val subject = subjectEl?.ownText() ?: ""
|
val subject = subjectEl?.ownText() ?: ""
|
||||||
|
|
||||||
val addedDateEl = item.select("td:eq(1) small").first()
|
val addedDateEl = item.select("td:eq(4)").first()
|
||||||
val addedDate = Date.fromIsoHm(addedDateEl?.text())
|
val (date, time) = data.parseDateTime(addedDateEl?.text()?.trim() ?: "")
|
||||||
|
if (date.month > currentMonth) {
|
||||||
|
currentYear--
|
||||||
|
}
|
||||||
|
currentMonth = date.month
|
||||||
|
date.year = currentYear
|
||||||
|
|
||||||
val senderEl = item.select("td:eq(2)").first()
|
val senderEl = item.select("td:eq(3)").first()
|
||||||
val senderName = senderEl?.ownText().fixName()
|
val senderName = senderEl?.ownText().fixName()
|
||||||
val senderId = data.teacherList.singleOrNull { it.fullNameLastFirst == senderName }?.id
|
val senderId = data.teacherList.singleOrNull { it.fullNameLastFirst == senderName }?.id
|
||||||
data.messageRecipientIgnoreList.add(MessageRecipient(profileId, -1, id))
|
data.messageRecipientIgnoreList.add(MessageRecipient(profileId, -1, id))
|
||||||
|
|
||||||
val isRead = item.select("td:eq(3) span").first()?.hasClass("wiadomosc_przeczytana") == true
|
val isRead = item.select("td:eq(5) span").first()?.hasClass("wiadomosc_przeczytana") == true
|
||||||
|
|
||||||
val message = Message(
|
val message = Message(
|
||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
@ -64,7 +73,7 @@ class MobidziennikWebMessagesInbox(override val data: DataMobidziennik,
|
|||||||
subject = subject,
|
subject = subject,
|
||||||
body = null,
|
body = null,
|
||||||
senderId = senderId,
|
senderId = senderId,
|
||||||
addedDate = addedDate
|
addedDate = date.combineWith(time)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (hasAttachments)
|
if (hasAttachments)
|
||||||
|
@ -40,23 +40,29 @@ class MobidziennikWebMessagesSent(override val data: DataMobidziennik,
|
|||||||
|
|
||||||
val doc = Jsoup.parse(text)
|
val doc = Jsoup.parse(text)
|
||||||
|
|
||||||
|
val today = Date.getToday()
|
||||||
|
var currentYear = today.year
|
||||||
|
var currentMonth = today.month
|
||||||
|
|
||||||
val list = doc.getElementsByClass("spis").first()?.getElementsByClass("podswietl")
|
val list = doc.getElementsByClass("spis").first()?.getElementsByClass("podswietl")
|
||||||
list?.forEach { item ->
|
list?.forEach { item ->
|
||||||
val id = item.attr("rel").toLongOrNull() ?: return@forEach
|
val id = item.attr("rel").toLongOrNull() ?: return@forEach
|
||||||
|
|
||||||
val subjectEl = item.select("td:eq(0)").first()
|
val subjectEl = item.select("td:eq(0)").first()
|
||||||
var hasAttachments = false
|
|
||||||
if (subjectEl?.getElementsByTag("a")?.size ?: 0 > 0) {
|
|
||||||
hasAttachments = true
|
|
||||||
}
|
|
||||||
val subject = subjectEl?.ownText() ?: ""
|
val subject = subjectEl?.ownText() ?: ""
|
||||||
|
|
||||||
val readByString = item.select("td:eq(2)").first()?.text() ?: ""
|
val attachmentsEl = item.select("td:eq(1)").first()
|
||||||
|
var hasAttachments = false
|
||||||
|
if (attachmentsEl?.getElementsByTag("a")?.size ?: 0 > 0) {
|
||||||
|
hasAttachments = true
|
||||||
|
}
|
||||||
|
|
||||||
|
val readByString = item.select("td:eq(4)").first()?.text() ?: ""
|
||||||
val (readBy, sentTo) = Regexes.MOBIDZIENNIK_MESSAGE_SENT_READ_BY.find(readByString).let {
|
val (readBy, sentTo) = Regexes.MOBIDZIENNIK_MESSAGE_SENT_READ_BY.find(readByString).let {
|
||||||
(it?.get(1)?.toIntOrNull() ?: 0) to (it?.get(2)?.toIntOrNull() ?: 0)
|
(it?.get(1)?.toIntOrNull() ?: 0) to (it?.get(2)?.toIntOrNull() ?: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
val recipientEl = item.select("td:eq(1) a span").first()
|
val recipientEl = item.select("td:eq(2) a span").first()
|
||||||
val recipientNames = recipientEl?.ownText()?.split(", ")
|
val recipientNames = recipientEl?.ownText()?.split(", ")
|
||||||
val readState = when (readBy) {
|
val readState = when (readBy) {
|
||||||
0 -> 0
|
0 -> 0
|
||||||
@ -69,8 +75,13 @@ class MobidziennikWebMessagesSent(override val data: DataMobidziennik,
|
|||||||
data.messageRecipientIgnoreList.add(MessageRecipient(profileId, recipientId, -1, readState, id))
|
data.messageRecipientIgnoreList.add(MessageRecipient(profileId, recipientId, -1, readState, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
val addedDateEl = item.select("td:eq(3) small").first()
|
val addedDateEl = item.select("td:eq(3)").first()
|
||||||
val addedDate = Date.fromIsoHm(addedDateEl?.text())
|
val (date, time) = data.parseDateTime(addedDateEl?.text()?.trim() ?: "")
|
||||||
|
if (date.month > currentMonth) {
|
||||||
|
currentYear--
|
||||||
|
}
|
||||||
|
currentMonth = date.month
|
||||||
|
date.year = currentYear
|
||||||
|
|
||||||
val message = Message(
|
val message = Message(
|
||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
@ -79,7 +90,7 @@ class MobidziennikWebMessagesSent(override val data: DataMobidziennik,
|
|||||||
subject = subject,
|
subject = subject,
|
||||||
body = null,
|
body = null,
|
||||||
senderId = null,
|
senderId = null,
|
||||||
addedDate = addedDate
|
addedDate = date.combineWith(time)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (hasAttachments)
|
if (hasAttachments)
|
||||||
|
Loading…
Reference in New Issue
Block a user