forked from github/szkolny
[API] Add Vulcan message & homework attachments. Fix Mobidziennik homework attachments.
This commit is contained in:
parent
238250e8c9
commit
12a54e58b5
@ -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_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_MESSAGES_COMPOSE, R.string.menu_message_compose, MessagesComposeFragment::class)
|
||||||
list += NavTarget(TARGET_WEB_PUSH, R.string.menu_web_push, WebPushFragment::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.debugMode) {
|
||||||
if (App.devMode) {
|
list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
|
||||||
list += NavTarget(TARGET_LAB, R.string.menu_lab, LabFragment::class)
|
list += NavTarget(TARGET_LAB, R.string.menu_lab, LabFragment::class)
|
||||||
.withIcon(CommunityMaterial.Icon.cmd_flask_outline)
|
.withIcon(CommunityMaterial.Icon.cmd_flask_outline)
|
||||||
.isInDrawer(true)
|
.isInDrawer(true)
|
||||||
|
@ -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_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_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_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}"
|
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||||
|
@ -39,9 +39,9 @@ class MobidziennikWebGetHomework(override val data: DataMobidziennik,
|
|||||||
|
|
||||||
event.attachmentIds = mutableListOf()
|
event.attachmentIds = mutableListOf()
|
||||||
event.attachmentNames = mutableListOf()
|
event.attachmentNames = mutableListOf()
|
||||||
Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).onEach {
|
Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach {
|
||||||
event.attachmentIds?.add(it[1].toLongOrNull() ?: return@onEach)
|
event.attachmentIds?.add(it[2].toLongOrNull() ?: return@forEach)
|
||||||
event.attachmentNames?.add(it[2])
|
event.attachmentNames?.add(it[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
event.homeworkBody = ""
|
event.homeworkBody = ""
|
||||||
|
@ -5,13 +5,17 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan
|
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_VULCAN_API
|
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.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.VulcanApiMessagesChangeStatus
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.VulcanApiSendMessage
|
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.firstlogin.VulcanFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.login.VulcanLogin
|
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.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
|
||||||
@ -87,8 +91,29 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|
|
||||||
override fun getMessage(message: MessageFull) {
|
override fun getMessage(message: MessageFull) {
|
||||||
login(LOGIN_METHOD_VULCAN_API) {
|
login(LOGIN_METHOD_VULCAN_API) {
|
||||||
VulcanApiMessagesChangeStatus(data, message) {
|
if (message.attachmentIds != null) {
|
||||||
completed()
|
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 getAnnouncement(announcement: AnnouncementFull) {}
|
||||||
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) {
|
||||||
|
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 firstLogin() { VulcanFirstLogin(data) { completed() } }
|
||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
@ -244,6 +244,8 @@ class EventDetailsDialog(
|
|||||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||||
fun onEventGetEvent(event: EventGetEvent) {
|
fun onEventGetEvent(event: EventGetEvent) {
|
||||||
EventBus.getDefault().removeStickyEvent(event)
|
EventBus.getDefault().removeStickyEvent(event)
|
||||||
|
if (event.event.homeworkBody == null)
|
||||||
|
event.event.homeworkBody = ""
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,5 +60,9 @@ class LabFragment : Fragment(), CoroutineScope {
|
|||||||
b.rodo.onClick {
|
b.rodo.onClick {
|
||||||
app.db.teacherDao().query(SimpleSQLiteQuery("UPDATE teachers SET teacherSurname = \"\" WHERE profileId = ${App.profileId}"))
|
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}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,10 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
b.downloadButton.isVisible = App.debugMode
|
||||||
|
b.downloadButton.onClick {
|
||||||
|
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||||
|
}
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
|
|
||||||
@ -182,14 +186,16 @@ class MessageFragment : Fragment(), CoroutineScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val readByAll = checkRecipients()
|
||||||
// if a sent msg is not read by everyone, download it again to check the read status
|
if (app.profile.loginStoreType == LoginStore.LOGIN_TYPE_VULCAN) {
|
||||||
if (!checkRecipients() && app.profile.loginStoreType != LoginStore.LOGIN_TYPE_VULCAN) {
|
// vulcan: change message status or download attachments
|
||||||
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
if (message.type == TYPE_RECEIVED && !message.seen || message.attachmentIds == null) {
|
||||||
return
|
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (!readByAll) {
|
||||||
if(message.type == TYPE_RECEIVED && !message.seen && app.profile.loginStoreType == LoginStore.LOGIN_TYPE_VULCAN) {
|
// if a sent msg is not read by everyone, download it again to check the read status
|
||||||
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Duh rodo button"
|
android:text="Duh rodo button"
|
||||||
android:textAllCaps="false" />
|
android:textAllCaps="false" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/removeHomework"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Remove all homework body (null)"
|
||||||
|
android:textAllCaps="false" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -295,6 +295,39 @@
|
|||||||
android:textAppearance="@style/NavView.TextView.Small" />
|
android:textAppearance="@style/NavView.TextView.Small" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/downloadButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:layout_marginRight="4dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_rounded_ripple"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="4dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingRight="4dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:visibility="visible">
|
||||||
|
|
||||||
|
<com.mikepenz.iconics.view.IconicsImageView
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:padding="4dp"
|
||||||
|
app:iiv_color="?android:textColorSecondary"
|
||||||
|
app:iiv_icon="cmd-download-outline"
|
||||||
|
tools:srcCompat="@android:drawable/ic_menu_delete" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Pobierz ponownie"
|
||||||
|
android:textAppearance="@style/NavView.TextView.Small" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user