forked from github/szkolny
[Announcements] Add idString column and add getting attachments in Edudziennik.
This commit is contained in:
parent
1257596104
commit
e472d34f4d
@ -113,6 +113,10 @@ object Regexes {
|
|||||||
"""\((.+?)\) (.+)""".toRegex()
|
"""\((.+?)\) (.+)""".toRegex()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val EDUDZIENNIK_ANNOUNCEMENT_DESCRIPTION by lazy {
|
||||||
|
"""<div class="desc">.*?<p>(.*?)</p>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
}
|
||||||
|
|
||||||
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
||||||
"""/Courses/([\w-_]+?)/""".toRegex()
|
"""/Courses/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
@ -125,6 +129,9 @@ object Regexes {
|
|||||||
val EDUDZIENNIK_EVENT_TYPE_ID by lazy {
|
val EDUDZIENNIK_EVENT_TYPE_ID by lazy {
|
||||||
"""/GradeLabels/([\w-_]+?)/""".toRegex()
|
"""/GradeLabels/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
|
val EDUDZIENNIK_ANNOUNCEMENT_ID by lazy {
|
||||||
|
"""/Announcement/([\w-_]+?)/""".toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
||||||
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
@ -92,6 +92,9 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
val schoolEndpoint: String
|
val schoolEndpoint: String
|
||||||
get() = "Schools/$schoolId/"
|
get() = "Schools/$schoolId/"
|
||||||
|
|
||||||
|
val schoolClassEndpoint: String
|
||||||
|
get() = "Schools/$classId/"
|
||||||
|
|
||||||
val studentAndClassEndpoint: String
|
val studentAndClassEndpoint: String
|
||||||
get() = "Students/$studentId/Klass/$classId/"
|
get() = "Students/$studentId/Klass/$classId/"
|
||||||
|
|
||||||
|
@ -8,11 +8,14 @@ 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.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.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.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -91,6 +94,14 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
EdudziennikLoginWeb(data) {
|
||||||
|
EdudziennikWebGetAnnouncement(data, announcement) {
|
||||||
|
completed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,33 +13,46 @@ const val ENDPOINT_EDUDZIENNIK_WEB_GRADES = 1011
|
|||||||
const val ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE = 1012
|
const val ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE = 1012
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1013
|
const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1013
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1014
|
const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1014
|
||||||
|
const val ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS = 1015
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1030
|
const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1030
|
||||||
|
|
||||||
val EdudziennikFeatures = listOf(
|
val EdudziennikFeatures = listOf(
|
||||||
|
/* School and team info and subjects */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_STUDENT_INFO, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_STUDENT_INFO, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_START to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_START to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Teachers */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TEACHERS, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TEACHERS, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_TEACHERS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_TEACHERS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Timetable */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TIMETABLE, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_TIMETABLE, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Grades */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_GRADES, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_GRADES, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_GRADES to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_GRADES to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Agenda */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_AGENDA, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_AGENDA, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_EXAMS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_EXAMS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Attendance */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_ATTENDANCE, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_ATTENDANCE, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Announcements */
|
||||||
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_ANNOUNCEMENTS, listOf(
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Lucky number */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_LUCKY_NUMBER, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_LUCKY_NUMBER, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB))
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB))
|
||||||
|
@ -60,6 +60,10 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||||
EdudziennikWebAttendance(data, onSuccess)
|
EdudziennikWebAttendance(data, onSuccess)
|
||||||
}
|
}
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
||||||
|
EdudziennikWebAnnouncements(data, onSuccess)
|
||||||
|
}
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> {
|
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||||
EdudziennikWebLuckyNumber(data, onSuccess)
|
EdudziennikWebLuckyNumber(data, onSuccess)
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import pl.szczodrzynski.edziennik.crc32
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_ANNOUNCEMENT_ID
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.Announcement
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
import pl.szczodrzynski.edziennik.splitName
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class EdudziennikWebAnnouncements(override val data: DataEdudziennik,
|
||||||
|
val onSuccess: () -> Unit) : EdudziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "EdudziennikWebAnnouncements"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.profile?.also { profile ->
|
||||||
|
webGet(TAG, data.schoolClassEndpoint + "Announcements") { text ->
|
||||||
|
val doc = Jsoup.parse(text)
|
||||||
|
|
||||||
|
doc.select("table.list tbody tr").forEach { announcementElement ->
|
||||||
|
val titleElement = announcementElement.child(0).child(0)
|
||||||
|
|
||||||
|
val longId = EDUDZIENNIK_ANNOUNCEMENT_ID.find(titleElement.attr("href"))?.get(1)
|
||||||
|
?: return@forEach
|
||||||
|
val id = longId.crc32()
|
||||||
|
val subject = titleElement.text()
|
||||||
|
|
||||||
|
val teacherName = announcementElement.child(1).text()
|
||||||
|
val teacher = teacherName.splitName()?.let { (teacherFirstName, teacherLastName) ->
|
||||||
|
data.getTeacher(teacherFirstName, teacherLastName)
|
||||||
|
} ?: return@forEach
|
||||||
|
|
||||||
|
val dateString = announcementElement.getElementsByClass("datetime").first().text()
|
||||||
|
val startDate = Date.fromY_m_d(dateString)
|
||||||
|
val addedDate = Date.fromIsoHm(dateString)
|
||||||
|
|
||||||
|
val announcementObject = Announcement(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
subject,
|
||||||
|
null,
|
||||||
|
startDate,
|
||||||
|
null,
|
||||||
|
teacher.id,
|
||||||
|
longId
|
||||||
|
)
|
||||||
|
|
||||||
|
data.announcementIgnoreList.add(announcementObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_ANNOUNCEMENT,
|
||||||
|
id,
|
||||||
|
profile.empty,
|
||||||
|
profile.empty,
|
||||||
|
addedDate
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} ?: onSuccess() }
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
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.AnnouncementGetEvent
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
|
||||||
|
class EdudziennikWebGetAnnouncement(
|
||||||
|
override val data: DataEdudziennik,
|
||||||
|
announcement: AnnouncementFull,
|
||||||
|
val onSuccess: () -> Unit
|
||||||
|
) : EdudziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "EdudziennikWebGetAnnouncement"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
webGet(TAG, "Announcement/${announcement.idString}") { text ->
|
||||||
|
val description = Regexes.EDUDZIENNIK_ANNOUNCEMENT_DESCRIPTION.find(text)?.get(1)?.trim() ?: ""
|
||||||
|
|
||||||
|
announcement.text = description
|
||||||
|
|
||||||
|
EventBus.getDefault().postSticky(AnnouncementGetEvent(announcement))
|
||||||
|
|
||||||
|
data.announcementList.add(announcement)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
|||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
import pl.szczodrzynski.edziennik.data.api.prepare
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -71,6 +72,10 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@ class IdziennikWebAnnouncements(override val data: DataIdziennik,
|
|||||||
jAnnouncement.get("Tresc").asString,
|
jAnnouncement.get("Tresc").asString,
|
||||||
startDate,
|
startDate,
|
||||||
null,
|
null,
|
||||||
rTeacher.id
|
rTeacher.id,
|
||||||
|
null
|
||||||
)
|
)
|
||||||
data.announcementList.add(announcementObject)
|
data.announcementList.add(announcementObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
|
@ -16,6 +16,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.*
|
|||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -106,6 +107,10 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
LibrusLoginPortal(data) {
|
LibrusLoginPortal(data) {
|
||||||
LibrusLoginApi(data) {
|
LibrusLoginApi(data) {
|
||||||
|
@ -24,7 +24,8 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
|||||||
val announcements = json.getJsonArray("SchoolNotices").asJsonObjectList()
|
val announcements = json.getJsonArray("SchoolNotices").asJsonObjectList()
|
||||||
|
|
||||||
announcements?.forEach { announcement ->
|
announcements?.forEach { announcement ->
|
||||||
val id = announcement.getString("Id")?.crc32() ?: return@forEach
|
val longId = announcement.getString("Id") ?: return@forEach
|
||||||
|
val id = longId.crc32()
|
||||||
val subject = announcement.getString("Subject") ?: ""
|
val subject = announcement.getString("Subject") ?: ""
|
||||||
val text = announcement.getString("Content") ?: ""
|
val text = announcement.getString("Content") ?: ""
|
||||||
val startDate = Date.fromY_m_d(announcement.getString("StartDate"))
|
val startDate = Date.fromY_m_d(announcement.getString("StartDate"))
|
||||||
@ -41,7 +42,8 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
|||||||
text,
|
text,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
teacherId
|
teacherId,
|
||||||
|
longId
|
||||||
)
|
)
|
||||||
|
|
||||||
data.announcementList.add(announcementObject)
|
data.announcementList.add(announcementObject)
|
||||||
|
@ -18,6 +18,7 @@ import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
|||||||
import pl.szczodrzynski.edziennik.data.api.mobidziennikLoginMethods
|
import pl.szczodrzynski.edziennik.data.api.mobidziennikLoginMethods
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
import pl.szczodrzynski.edziennik.data.api.prepare
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -80,6 +81,10 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
MobidziennikLoginWeb(data) {
|
MobidziennikLoginWeb(data) {
|
||||||
MobidziennikWebGetAttachment(data, message, attachmentId, attachmentName) {
|
MobidziennikWebGetAttachment(data, message, attachmentId, attachmentName) {
|
||||||
|
@ -15,6 +15,7 @@ import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
|||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
import pl.szczodrzynski.edziennik.data.api.prepare
|
||||||
import pl.szczodrzynski.edziennik.data.api.templateLoginMethods
|
import pl.szczodrzynski.edziennik.data.api.templateLoginMethods
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -71,6 +72,10 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
|||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
import pl.szczodrzynski.edziennik.data.api.prepare
|
||||||
import pl.szczodrzynski.edziennik.data.api.vulcanLoginMethods
|
import pl.szczodrzynski.edziennik.data.api.vulcanLoginMethods
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -77,6 +78,10 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-26
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.events
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
|
|
||||||
|
data class AnnouncementGetEvent(val announcement: AnnouncementFull)
|
@ -5,6 +5,7 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.interfaces
|
package pl.szczodrzynski.edziennik.data.api.interfaces
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ interface EdziennikInterface {
|
|||||||
fun sync(featureIds: List<Int>, viewId: Int? = null, arguments: JsonObject? = null)
|
fun sync(featureIds: List<Int>, viewId: Int? = null, arguments: JsonObject? = null)
|
||||||
fun getMessage(message: MessageFull)
|
fun getMessage(message: MessageFull)
|
||||||
fun markAllAnnouncementsAsRead()
|
fun markAllAnnouncementsAsRead()
|
||||||
|
fun getAnnouncement(announcement: AnnouncementFull)
|
||||||
fun getAttachment(message: Message, attachmentId: Long, attachmentName: String)
|
fun getAttachment(message: Message, attachmentId: Long, attachmentName: String)
|
||||||
fun firstLogin()
|
fun firstLogin()
|
||||||
fun cancel()
|
fun cancel()
|
||||||
|
@ -149,6 +149,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
val attendanceList = mutableListOf<Attendance>()
|
val attendanceList = mutableListOf<Attendance>()
|
||||||
|
|
||||||
val announcementList = mutableListOf<Announcement>()
|
val announcementList = mutableListOf<Announcement>()
|
||||||
|
val announcementIgnoreList = mutableListOf<Announcement>()
|
||||||
|
|
||||||
val luckyNumberList = mutableListOf<LuckyNumber>()
|
val luckyNumberList = mutableListOf<LuckyNumber>()
|
||||||
|
|
||||||
@ -203,8 +204,10 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
noticeList.clear()
|
noticeList.clear()
|
||||||
attendanceList.clear()
|
attendanceList.clear()
|
||||||
announcementList.clear()
|
announcementList.clear()
|
||||||
|
announcementIgnoreList.clear()
|
||||||
luckyNumberList.clear()
|
luckyNumberList.clear()
|
||||||
teacherAbsenceList.clear()
|
teacherAbsenceList.clear()
|
||||||
|
messageList.clear()
|
||||||
messageIgnoreList.clear()
|
messageIgnoreList.clear()
|
||||||
messageRecipientList.clear()
|
messageRecipientList.clear()
|
||||||
messageRecipientIgnoreList.clear()
|
messageRecipientIgnoreList.clear()
|
||||||
@ -315,6 +318,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
|||||||
db.attendanceDao().addAll(attendanceList)
|
db.attendanceDao().addAll(attendanceList)
|
||||||
if (announcementList.isNotEmpty())
|
if (announcementList.isNotEmpty())
|
||||||
db.announcementDao().addAll(announcementList)
|
db.announcementDao().addAll(announcementList)
|
||||||
|
if (announcementIgnoreList.isNotEmpty())
|
||||||
|
db.announcementDao().addAllIgnore(announcementIgnoreList)
|
||||||
if (luckyNumberList.isNotEmpty())
|
if (luckyNumberList.isNotEmpty())
|
||||||
db.luckyNumberDao().addAll(luckyNumberList)
|
db.luckyNumberDao().addAll(luckyNumberList)
|
||||||
if (teacherAbsenceList.isNotEmpty())
|
if (teacherAbsenceList.isNotEmpty())
|
||||||
|
@ -12,6 +12,7 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.template.Template
|
|||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.Vulcan
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.Vulcan
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -26,6 +27,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
fun syncProfileList(profileList: List<Int>) = EdziennikTask(-1, SyncProfileListRequest(profileList))
|
fun syncProfileList(profileList: List<Int>) = EdziennikTask(-1, SyncProfileListRequest(profileList))
|
||||||
fun messageGet(profileId: Int, message: MessageFull) = EdziennikTask(profileId, MessageGetRequest(message))
|
fun messageGet(profileId: Int, message: MessageFull) = EdziennikTask(profileId, MessageGetRequest(message))
|
||||||
fun announcementsRead(profileId: Int) = EdziennikTask(profileId, AnnouncementsReadRequest())
|
fun announcementsRead(profileId: Int) = EdziennikTask(profileId, AnnouncementsReadRequest())
|
||||||
|
fun announcementGet(profileId: Int, announcement: AnnouncementFull) = EdziennikTask(profileId, AnnouncementGetRequest(announcement))
|
||||||
fun attachmentGet(profileId: Int, message: Message, attachmentId: Long, attachmentName: String) = EdziennikTask(profileId, AttachmentGetRequest(message, attachmentId, attachmentName))
|
fun attachmentGet(profileId: Int, message: Message, attachmentId: Long, attachmentName: String) = EdziennikTask(profileId, AttachmentGetRequest(message, attachmentId, attachmentName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
is MessageGetRequest -> edziennikInterface?.getMessage(request.message)
|
is MessageGetRequest -> edziennikInterface?.getMessage(request.message)
|
||||||
is FirstLoginRequest -> edziennikInterface?.firstLogin()
|
is FirstLoginRequest -> edziennikInterface?.firstLogin()
|
||||||
is AnnouncementsReadRequest -> edziennikInterface?.markAllAnnouncementsAsRead()
|
is AnnouncementsReadRequest -> edziennikInterface?.markAllAnnouncementsAsRead()
|
||||||
|
is AnnouncementGetRequest -> edziennikInterface?.getAnnouncement(request.announcement)
|
||||||
is AttachmentGetRequest -> edziennikInterface?.getAttachment(request.message, request.attachmentId, request.attachmentName)
|
is AttachmentGetRequest -> edziennikInterface?.getAttachment(request.message, request.attachmentId, request.attachmentName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,5 +98,6 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
data class SyncProfileListRequest(val profileList: List<Int>)
|
data class SyncProfileListRequest(val profileList: List<Int>)
|
||||||
data class MessageGetRequest(val message: MessageFull)
|
data class MessageGetRequest(val message: MessageFull)
|
||||||
class AnnouncementsReadRequest
|
class AnnouncementsReadRequest
|
||||||
|
data class AnnouncementGetRequest(val announcement: AnnouncementFull)
|
||||||
data class AttachmentGetRequest(val message: Message, val attachmentId: Long, val attachmentName: String)
|
data class AttachmentGetRequest(val message: Message, val attachmentId: Long, val attachmentName: String)
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
|||||||
AttendanceType.class,
|
AttendanceType.class,
|
||||||
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
||||||
ConfigEntry.class,
|
ConfigEntry.class,
|
||||||
Metadata.class}, version = 69)
|
Metadata.class}, version = 70)
|
||||||
@TypeConverters({
|
@TypeConverters({
|
||||||
ConverterTime.class,
|
ConverterTime.class,
|
||||||
ConverterDate.class,
|
ConverterDate.class,
|
||||||
@ -829,6 +829,13 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
database.execSQL("ALTER TABLE loginStores ADD COLUMN loginStoreMode INTEGER NOT NULL DEFAULT 0");
|
database.execSQL("ALTER TABLE loginStores ADD COLUMN loginStoreMode INTEGER NOT NULL DEFAULT 0");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private static final Migration MIGRATION_69_70 = new Migration(69, 70) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("ALTER TABLE announcements ADD COLUMN announcementIdString TEXT DEFAULT NULL");
|
||||||
|
database.execSQL("DELETE FROM announcements");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public static AppDb getDatabase(final Context context) {
|
public static AppDb getDatabase(final Context context) {
|
||||||
@ -895,7 +902,8 @@ public abstract class AppDb extends RoomDatabase {
|
|||||||
MIGRATION_65_66,
|
MIGRATION_65_66,
|
||||||
MIGRATION_66_67,
|
MIGRATION_66_67,
|
||||||
MIGRATION_67_68,
|
MIGRATION_67_68,
|
||||||
MIGRATION_68_69
|
MIGRATION_68_69,
|
||||||
|
MIGRATION_69_70
|
||||||
)
|
)
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
//.fallbackToDestructiveMigration()
|
//.fallbackToDestructiveMigration()
|
||||||
|
@ -5,6 +5,7 @@ import androidx.room.ColumnInfo;
|
|||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.Ignore;
|
import androidx.room.Ignore;
|
||||||
import androidx.room.Index;
|
import androidx.room.Index;
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||||
|
|
||||||
@Entity(tableName = "announcements",
|
@Entity(tableName = "announcements",
|
||||||
@ -18,6 +19,7 @@ public class Announcement {
|
|||||||
|
|
||||||
@ColumnInfo(name = "announcementSubject")
|
@ColumnInfo(name = "announcementSubject")
|
||||||
public String subject;
|
public String subject;
|
||||||
|
@Nullable
|
||||||
@ColumnInfo(name = "announcementText")
|
@ColumnInfo(name = "announcementText")
|
||||||
public String text;
|
public String text;
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -29,10 +31,14 @@ public class Announcement {
|
|||||||
|
|
||||||
public long teacherId;
|
public long teacherId;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@ColumnInfo(name = "announcementIdString")
|
||||||
|
public String idString;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public Announcement() {}
|
public Announcement() {}
|
||||||
|
|
||||||
public Announcement(int profileId, long id, String subject, String text, @Nullable Date startDate, @Nullable Date endDate, long teacherId) {
|
public Announcement(int profileId, long id, String subject, String text, @Nullable Date startDate, @Nullable Date endDate, long teacherId, @Nullable String idString) {
|
||||||
this.profileId = profileId;
|
this.profileId = profileId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
@ -40,6 +46,7 @@ public class Announcement {
|
|||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
this.teacherId = teacherId;
|
this.teacherId = teacherId;
|
||||||
|
this.idString = idString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ public abstract class AnnouncementDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
public abstract void addAll(List<Announcement> announcementList);
|
public abstract void addAll(List<Announcement> announcementList);
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
public abstract void addAllIgnore(List<Announcement> announcementList);
|
||||||
|
|
||||||
@Query("DELETE FROM announcements WHERE profileId = :profileId")
|
@Query("DELETE FROM announcements WHERE profileId = :profileId")
|
||||||
public abstract void clear(int profileId);
|
public abstract void clear(int profileId);
|
||||||
|
|
||||||
|
@ -17,9 +17,16 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App;
|
import pl.szczodrzynski.edziennik.App;
|
||||||
import pl.szczodrzynski.edziennik.MainActivity;
|
import pl.szczodrzynski.edziennik.MainActivity;
|
||||||
import pl.szczodrzynski.edziennik.R;
|
import pl.szczodrzynski.edziennik.R;
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.events.AnnouncementGetEvent;
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.task.EdziennikTask;
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull;
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogAnnouncementBinding;
|
import pl.szczodrzynski.edziennik.databinding.DialogAnnouncementBinding;
|
||||||
import pl.szczodrzynski.edziennik.databinding.FragmentAnnouncementsBinding;
|
import pl.szczodrzynski.edziennik.databinding.FragmentAnnouncementsBinding;
|
||||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration;
|
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration;
|
||||||
@ -33,6 +40,7 @@ public class AnnouncementsFragment extends Fragment {
|
|||||||
private App app = null;
|
private App app = null;
|
||||||
private MainActivity activity = null;
|
private MainActivity activity = null;
|
||||||
private FragmentAnnouncementsBinding b = null;
|
private FragmentAnnouncementsBinding b = null;
|
||||||
|
private boolean dialogOpened = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@ -97,20 +105,13 @@ public class AnnouncementsFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
AnnouncementsAdapter announcementsAdapter = new AnnouncementsAdapter(activity, announcements, (v, announcement) -> {
|
AnnouncementsAdapter announcementsAdapter = new AnnouncementsAdapter(activity, announcements, (v, announcement) -> {
|
||||||
MaterialDialog dialog = new MaterialDialog.Builder(activity)
|
if (!dialogOpened) {
|
||||||
.title(announcement.subject)
|
dialogOpened = true;
|
||||||
.customView(R.layout.dialog_announcement, true)
|
if (announcement.text == null) {
|
||||||
.positiveText(R.string.ok)
|
EdziennikTask.Companion.announcementGet(App.profileId, announcement).enqueue(requireContext());
|
||||||
.show();
|
} else {
|
||||||
DialogAnnouncementBinding b = DialogAnnouncementBinding.bind(dialog.getCustomView());
|
showAnnouncementDetailsDialog(announcement);
|
||||||
b.text.setText(announcement.teacherFullName+"\n\n"+ (announcement.startDate != null ? announcement.startDate.getFormattedString() : "-")+" do "+ (announcement.endDate != null ? announcement.endDate.getFormattedString() : "-")+"\n\n" +announcement.text);
|
}
|
||||||
if (!announcement.seen) {
|
|
||||||
announcement.seen = true;
|
|
||||||
AsyncTask.execute(() -> {
|
|
||||||
app.db.metadataDao().setSeen(App.profileId, announcement, true);
|
|
||||||
});
|
|
||||||
if (recyclerView.getAdapter() != null)
|
|
||||||
recyclerView.getAdapter().notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -128,4 +129,43 @@ public class AnnouncementsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
super.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||||
|
public void onAnnouncementGetEvent(AnnouncementGetEvent event) {
|
||||||
|
EventBus.getDefault().removeStickyEvent(event);
|
||||||
|
showAnnouncementDetailsDialog(event.getAnnouncement());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAnnouncementDetailsDialog(AnnouncementFull announcement) {
|
||||||
|
if (!dialogOpened) {
|
||||||
|
MaterialDialog dialog = new MaterialDialog.Builder(activity)
|
||||||
|
.title(announcement.subject)
|
||||||
|
.customView(R.layout.dialog_announcement, true)
|
||||||
|
.positiveText(R.string.ok)
|
||||||
|
.dismissListener(v -> dialogOpened = false)
|
||||||
|
.show();
|
||||||
|
DialogAnnouncementBinding b = DialogAnnouncementBinding.bind(dialog.getCustomView());
|
||||||
|
b.text.setText(announcement.teacherFullName+"\n\n"+ (announcement.startDate != null ? announcement.startDate.getFormattedString() : "-")+" do "+ (announcement.endDate != null ? announcement.endDate.getFormattedString() : "-")+"\n\n" +announcement.text);
|
||||||
|
if (!announcement.seen) {
|
||||||
|
announcement.seen = true;
|
||||||
|
AsyncTask.execute(() -> {
|
||||||
|
app.db.metadataDao().setSeen(App.profileId, announcement, true);
|
||||||
|
});
|
||||||
|
if (recyclerView.getAdapter() != null)
|
||||||
|
recyclerView.getAdapter().notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user