mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[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
|
val profile
|
||||||
get() = data.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")
|
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
|
"Nieprawidłowy węzeł." -> ERROR_LIBRUS_API_INCORRECT_ENDPOINT
|
||||||
else -> ERROR_LIBRUS_API_OTHER
|
else -> ERROR_LIBRUS_API_OTHER
|
||||||
}.let { errorCode ->
|
}.let { errorCode ->
|
||||||
data.error(ApiError(tag, errorCode)
|
if (errorCode !in ignoreErrors) {
|
||||||
.withApiResponse(json)
|
data.error(ApiError(tag, errorCode)
|
||||||
.withResponse(response))
|
.withApiResponse(json)
|
||||||
return
|
.withResponse(response))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
|
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
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.POST
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||||
@ -22,7 +23,8 @@ class LibrusApiAnnouncementMarkAsRead(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
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
|
announcement.seen = true
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(AnnouncementGetEvent(announcement))
|
EventBus.getDefault().postSticky(AnnouncementGetEvent(announcement))
|
||||||
|
@ -70,7 +70,7 @@ class LibrusLoginSynergia(override val data: DataLibrus, val onSuccess: () -> Un
|
|||||||
loginWithToken(json.getString("Token"))
|
loginWithToken(json.getString("Token"))
|
||||||
}
|
}
|
||||||
|
|
||||||
apiGet(TAG, "AutoLoginToken", POST, null, onSuccess)
|
apiGet(TAG, "AutoLoginToken", POST, onSuccess = onSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loginWithToken(token: String?) {
|
private fun loginWithToken(token: String?) {
|
||||||
|
@ -109,7 +109,7 @@ public class AnnouncementsFragment extends Fragment {
|
|||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
AnnouncementsAdapter announcementsAdapter = new AnnouncementsAdapter(activity, announcements, (v, announcement) -> {
|
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());
|
EdziennikTask.Companion.announcementGet(App.profileId, announcement).enqueue(requireContext());
|
||||||
} else {
|
} else {
|
||||||
showAnnouncementDetailsDialog(announcement);
|
showAnnouncementDetailsDialog(announcement);
|
||||||
@ -157,7 +157,7 @@ public class AnnouncementsFragment extends Fragment {
|
|||||||
.show();
|
.show();
|
||||||
DialogAnnouncementBinding b = DialogAnnouncementBinding.bind(dialog.getCustomView());
|
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);
|
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;
|
announcement.seen = true;
|
||||||
AsyncTask.execute(() -> app.db.metadataDao().setSeen(App.profileId, announcement, true));
|
AsyncTask.execute(() -> app.db.metadataDao().setSeen(App.profileId, announcement, true));
|
||||||
if (recyclerView.getAdapter() != null)
|
if (recyclerView.getAdapter() != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user