[Announcements/Liburs] Fix error on marking as read and make announcement show even when there's no Internet connection.

This commit is contained in:
Kacper Ziubryniewicz
2020-01-06 18:24:43 +01:00
parent 4b08ea7a89
commit 26eb2e4381
4 changed files with 13 additions and 9 deletions

View File

@ -26,7 +26,7 @@ open class LibrusApi(open val data: DataLibrus) {
val profile
get() = data.profile
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject) -> Unit) {
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, ignoreErrors: List<Int> = emptyList(), onSuccess: (json: JsonObject) -> Unit) {
d(tag, "Request: Librus/Api - ${if (data.fakeLogin) FAKE_LIBRUS_API else LIBRUS_API_URL}/$endpoint")
@ -65,10 +65,12 @@ open class LibrusApi(open val data: DataLibrus) {
"Nieprawidłowy węzeł." -> ERROR_LIBRUS_API_INCORRECT_ENDPOINT
else -> ERROR_LIBRUS_API_OTHER
}.let { errorCode ->
data.error(ApiError(tag, errorCode)
.withApiResponse(json)
.withResponse(response))
return
if (errorCode !in ignoreErrors) {
data.error(ApiError(tag, errorCode)
.withApiResponse(json)
.withResponse(response))
return
}
}
}

View File

@ -5,6 +5,7 @@
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
import org.greenrobot.eventbus.EventBus
import pl.szczodrzynski.edziennik.data.api.ERROR_LIBRUS_API_INVALID_REQUEST_PARAMS
import pl.szczodrzynski.edziennik.data.api.POST
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
@ -22,7 +23,8 @@ class LibrusApiAnnouncementMarkAsRead(
}
init {
apiGet(TAG, "SchoolNotices/MarkAsRead/${announcement.idString}", method = POST) {
apiGet(TAG, "SchoolNotices/MarkAsRead/${announcement.idString}", method = POST,
ignoreErrors = listOf(ERROR_LIBRUS_API_INVALID_REQUEST_PARAMS)) {
announcement.seen = true
EventBus.getDefault().postSticky(AnnouncementGetEvent(announcement))

View File

@ -70,7 +70,7 @@ class LibrusLoginSynergia(override val data: DataLibrus, val onSuccess: () -> Un
loginWithToken(json.getString("Token"))
}
apiGet(TAG, "AutoLoginToken", POST, null, onSuccess)
apiGet(TAG, "AutoLoginToken", POST, onSuccess = onSuccess)
}
private fun loginWithToken(token: String?) {