forked from github/szkolny
[Announcements/Liburs] Fix error on marking as read and make announcement show even when there's no Internet connection.
This commit is contained in:
parent
4b08ea7a89
commit
26eb2e4381
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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?) {
|
||||
|
@ -109,7 +109,7 @@ public class AnnouncementsFragment extends Fragment {
|
||||
return;
|
||||
}*/
|
||||
AnnouncementsAdapter announcementsAdapter = new AnnouncementsAdapter(activity, announcements, (v, announcement) -> {
|
||||
if (announcement.text == null || (app.profile.getLoginStoreType() == LOGIN_TYPE_LIBRUS && !announcement.seen)) {
|
||||
if (announcement.text == null || (app.profile.getLoginStoreType() == LOGIN_TYPE_LIBRUS && !announcement.seen && app.networkUtils.isOnline())) {
|
||||
EdziennikTask.Companion.announcementGet(App.profileId, announcement).enqueue(requireContext());
|
||||
} else {
|
||||
showAnnouncementDetailsDialog(announcement);
|
||||
@ -157,7 +157,7 @@ public class AnnouncementsFragment extends Fragment {
|
||||
.show();
|
||||
DialogAnnouncementBinding b = DialogAnnouncementBinding.bind(dialog.getCustomView());
|
||||
b.text.setText(announcement.teacherFullName+"\n\n"+ (announcement.startDate != null ? announcement.startDate.getFormattedString() : "-") + (announcement.endDate != null ? " do " + announcement.endDate.getFormattedString() : "")+"\n\n" +announcement.text);
|
||||
if (!announcement.seen) {
|
||||
if (!announcement.seen && app.profile.getLoginStoreType() != LOGIN_TYPE_LIBRUS) {
|
||||
announcement.seen = true;
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setSeen(App.profileId, announcement, true));
|
||||
if (recyclerView.getAdapter() != null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user