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_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)
|
||||
|
@ -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}"
|
||||
|
@ -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 = ""
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
fun onEventGetEvent(event: EventGetEvent) {
|
||||
EventBus.getDefault().removeStickyEvent(event)
|
||||
if (event.event.homeworkBody == null)
|
||||
event.event.homeworkBody = ""
|
||||
update()
|
||||
}
|
||||
|
||||
|
@ -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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -47,6 +47,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Duh rodo button"
|
||||
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>
|
||||
</ScrollView>
|
||||
</layout>
|
||||
|
@ -295,6 +295,39 @@
|
||||
android:textAppearance="@style/NavView.TextView.Small" />
|
||||
|
||||
</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>
|
||||
</ScrollView>
|
||||
|
Loading…
Reference in New Issue
Block a user