diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
index 85b4f887..e3cb0fcf 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt
@@ -226,8 +226,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
list += NavTarget(TARGET_MESSAGES_DETAILS, R.string.menu_message, MessageFragment::class).withPopTo(DRAWER_ITEM_MESSAGES)
list += NavTarget(TARGET_MESSAGES_COMPOSE, R.string.menu_message_compose, MessagesComposeFragment::class)
list += NavTarget(TARGET_WEB_PUSH, R.string.menu_web_push, WebPushFragment::class)
- list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
- if (App.devMode) {
+ if (App.debugMode) {
+ list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
list += NavTarget(TARGET_LAB, R.string.menu_lab, LabFragment::class)
.withIcon(CommunityMaterial.Icon.cmd_flask_outline)
.isInDrawer(true)
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt
index 004954bc..81cd81cf 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Constants.kt
@@ -111,5 +111,7 @@ const val VULCAN_API_ENDPOINT_MESSAGES_SENT = "mobile-api/Uczen.v3.Uczen/Wiadomo
const val VULCAN_API_ENDPOINT_MESSAGES_CHANGE_STATUS = "mobile-api/Uczen.v3.Uczen/ZmienStatusWiadomosci"
const val VULCAN_API_ENDPOINT_MESSAGES_ADD = "mobile-api/Uczen.v3.Uczen/DodajWiadomosc"
const val VULCAN_API_ENDPOINT_PUSH = "mobile-api/Uczen.v3.Uczen/UstawPushToken"
+const val VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS = "mobile-api/Uczen.v3.Uczen/WiadomosciZalacznik"
+const val VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS = "mobile-api/Uczen.v3.Uczen/ZadaniaDomoweZalacznik"
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt
index ef4e8e5d..b0699b4b 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt
@@ -39,9 +39,9 @@ class MobidziennikWebGetHomework(override val data: DataMobidziennik,
event.attachmentIds = mutableListOf()
event.attachmentNames = mutableListOf()
- Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).onEach {
- event.attachmentIds?.add(it[1].toLongOrNull() ?: return@onEach)
- event.attachmentNames?.add(it[2])
+ Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach {
+ event.attachmentIds?.add(it[2].toLongOrNull() ?: return@forEach)
+ event.attachmentNames?.add(it[3])
}
event.homeworkBody = ""
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt
index 511b6591..a3125b9d 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt
@@ -5,13 +5,17 @@
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan
import com.google.gson.JsonObject
+import org.greenrobot.eventbus.EventBus
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanData
+import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiAttachments
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiMessagesChangeStatus
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiSendMessage
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.firstlogin.VulcanFirstLogin
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLogin
+import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
+import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
import pl.szczodrzynski.edziennik.data.api.models.ApiError
@@ -87,8 +91,29 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
override fun getMessage(message: MessageFull) {
login(LOGIN_METHOD_VULCAN_API) {
- VulcanApiMessagesChangeStatus(data, message) {
- completed()
+ if (message.attachmentIds != null) {
+ VulcanApiMessagesChangeStatus(data, message) {
+ completed()
+ }
+ return@login
+ }
+ val list = data.app.db.messageDao().getAllNow(data.profileId)
+ VulcanApiAttachments(data, list, message, MessageFull::class) { _ ->
+ list.forEach {
+ if (it.attachmentIds == null)
+ it.attachmentIds = mutableListOf()
+ data.messageList.add(it)
+ }
+ data.messageListReplace = true
+
+ if (message.seen) {
+ EventBus.getDefault().postSticky(MessageGetEvent(message))
+ completed()
+ return@VulcanApiAttachments
+ }
+ VulcanApiMessagesChangeStatus(data, message) {
+ completed()
+ }
}
}
}
@@ -105,7 +130,21 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
override fun getAnnouncement(announcement: AnnouncementFull) {}
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {}
override fun getRecipientList() {}
- override fun getEvent(eventFull: EventFull) {}
+ override fun getEvent(eventFull: EventFull) {
+ login(LOGIN_METHOD_VULCAN_API) {
+ val list = data.app.db.eventDao().getAllNow(data.profileId).filter { !it.addedManually }
+ VulcanApiAttachments(data, list, eventFull, EventFull::class) { _ ->
+ list.forEach {
+ it.homeworkBody = ""
+ data.eventList.add(it)
+ }
+ data.eventListReplace = true
+
+ EventBus.getDefault().postSticky(EventGetEvent(eventFull))
+ completed()
+ }
+ }
+ }
override fun firstLogin() { VulcanFirstLogin(data) { completed() } }
override fun cancel() {
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiAttachments.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiAttachments.kt
new file mode 100644
index 00000000..a7b2b23b
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiAttachments.kt
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) Kuba SzczodrzyĆski 2020-4-6.
+ */
+
+package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api
+
+import pl.szczodrzynski.edziennik.asJsonObjectList
+import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS
+import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS
+import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
+import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi
+import pl.szczodrzynski.edziennik.data.db.full.EventFull
+import pl.szczodrzynski.edziennik.data.db.full.MessageFull
+import pl.szczodrzynski.edziennik.getJsonArray
+import pl.szczodrzynski.edziennik.getLong
+import pl.szczodrzynski.edziennik.getString
+import pl.szczodrzynski.edziennik.utils.models.Date
+import kotlin.reflect.KClass
+
+class VulcanApiAttachments(override val data: DataVulcan,
+ val list: List<*>,
+ val owner: Any?,
+ val ownerClass: KClass<*>,
+ val onSuccess: (list: List<*>) -> Unit
+) : VulcanApi(data, null) {
+ companion object {
+ const val TAG = "VulcanApiAttachments"
+ }
+
+ init { run {
+ val endpoint = when (ownerClass) {
+ MessageFull::class -> VULCAN_API_ENDPOINT_MESSAGES_ATTACHMENTS
+ EventFull::class -> VULCAN_API_ENDPOINT_HOMEWORK_ATTACHMENTS
+ else -> null
+ } ?: return@run
+
+ val idName = when (ownerClass) {
+ MessageFull::class -> "IdWiadomosc"
+ EventFull::class -> "IdZadanieDomowe"
+ else -> null
+ } ?: return@run
+
+ val startDate = profile?.getSemesterStart(profile?.currentSemester ?: 1)?.inUnix ?: 0
+ val endDate = Date.getToday().stepForward(0, 1, 0).inUnix
+
+ apiGet(TAG, endpoint, parameters = mapOf(
+ "DataPoczatkowa" to startDate,
+ "DataKoncowa" to endDate,
+ "LoginId" to data.studentLoginId,
+ "IdUczen" to data.studentId
+ )) { json, _ ->
+
+ json.getJsonArray("Data")?.asJsonObjectList()?.forEach { attachment ->
+ val id = attachment.getLong("Id") ?: return@forEach
+ val itemId = attachment.getLong(idName) ?: return@forEach
+ val url = attachment.getString("Url") ?: return@forEach
+ val fileName = "${attachment.getString("NazwaPliku")}:$url"
+
+ list.forEach {
+ if (it is MessageFull
+ && it.profileId == profileId
+ && it.id == itemId
+ && it.attachmentIds?.contains(id) != true) {
+ if (it.attachmentIds == null)
+ it.attachmentIds = mutableListOf()
+ if (it.attachmentNames == null)
+ it.attachmentNames = mutableListOf()
+ it.attachmentIds?.add(id)
+ it.attachmentNames?.add(fileName)
+ }
+
+ if (it is EventFull
+ && it.profileId == profileId
+ && it.id == itemId
+ && it.attachmentIds?.contains(id) != true) {
+ if (it.attachmentIds == null)
+ it.attachmentIds = mutableListOf()
+ if (it.attachmentNames == null)
+ it.attachmentNames = mutableListOf()
+ it.attachmentIds?.add(id)
+ it.attachmentNames?.add(fileName)
+ }
+
+ if (owner is MessageFull
+ && it is MessageFull
+ && owner.profileId == it.profileId
+ && owner.id == it.id) {
+ owner.attachmentIds = it.attachmentIds
+ owner.attachmentNames = it.attachmentNames
+ }
+
+ if (owner is EventFull
+ && it is EventFull
+ && owner.profileId == it.profileId
+ && owner.id == it.id) {
+ owner.attachmentIds = it.attachmentIds
+ owner.attachmentNames = it.attachmentNames
+ }
+ }
+ }
+
+ /*if (owner is MessageFull) {
+ list.forEach {
+ (it as? MessageFull)?.let { message ->
+ data.messageList.add(message)
+ }
+ }
+ data.messageListReplace = true
+ }
+
+ if (owner is EventFull) {
+ list.forEach {
+ (it as? EventFull)?.let { it1 ->
+ it1.homeworkBody = ""
+ data.eventList.add(it1)
+ }
+ }
+ data.eventListReplace = true
+ }*/
+
+ onSuccess(list)
+ }
+ }}
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt
index 83df5e77..b1683ac5 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventDetailsDialog.kt
@@ -244,6 +244,8 @@ class EventDetailsDialog(
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
fun onEventGetEvent(event: EventGetEvent) {
EventBus.getDefault().removeStickyEvent(event)
+ if (event.event.homeworkBody == null)
+ event.event.homeworkBody = ""
update()
}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt
index 35f16c20..45472cf9 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/debug/LabFragment.kt
@@ -60,5 +60,9 @@ class LabFragment : Fragment(), CoroutineScope {
b.rodo.onClick {
app.db.teacherDao().query(SimpleSQLiteQuery("UPDATE teachers SET teacherSurname = \"\" WHERE profileId = ${App.profileId}"))
}
+
+ b.removeHomework.onClick {
+ app.db.eventDao().getRawNow("UPDATE events SET homeworkBody = NULL WHERE profileId = ${App.profileId}")
+ }
}
}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt
index 1a94d4a4..e8a4e343 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt
@@ -108,6 +108,10 @@ class MessageFragment : Fragment(), CoroutineScope {
.setNegativeButton(R.string.cancel, null)
.show()
}
+ b.downloadButton.isVisible = App.debugMode
+ b.downloadButton.onClick {
+ EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
+ }
launch {
@@ -182,14 +186,16 @@ class MessageFragment : Fragment(), CoroutineScope {
}
}
-
- // if a sent msg is not read by everyone, download it again to check the read status
- if (!checkRecipients() && app.profile.loginStoreType != LoginStore.LOGIN_TYPE_VULCAN) {
- EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
- return
+ val readByAll = checkRecipients()
+ if (app.profile.loginStoreType == LoginStore.LOGIN_TYPE_VULCAN) {
+ // vulcan: change message status or download attachments
+ if (message.type == TYPE_RECEIVED && !message.seen || message.attachmentIds == null) {
+ EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
+ return
+ }
}
-
- if(message.type == TYPE_RECEIVED && !message.seen && app.profile.loginStoreType == LoginStore.LOGIN_TYPE_VULCAN) {
+ else if (!readByAll) {
+ // if a sent msg is not read by everyone, download it again to check the read status
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
return
}
diff --git a/app/src/main/res/layout/lab_fragment.xml b/app/src/main/res/layout/lab_fragment.xml
index d6988c69..e1cf029c 100644
--- a/app/src/main/res/layout/lab_fragment.xml
+++ b/app/src/main/res/layout/lab_fragment.xml
@@ -47,6 +47,13 @@
android:layout_height="wrap_content"
android:text="Duh rodo button"
android:textAllCaps="false" />
+
+
diff --git a/app/src/main/res/layout/message_fragment.xml b/app/src/main/res/layout/message_fragment.xml
index 25406413..a58f610f 100644
--- a/app/src/main/res/layout/message_fragment.xml
+++ b/app/src/main/res/layout/message_fragment.xml
@@ -295,6 +295,39 @@
android:textAppearance="@style/NavView.TextView.Small" />
+
+
+
+
+
+
+
+