forked from github/szkolny
[API/Librus] Add marking announcements as read.
This commit is contained in:
parent
c65872b29b
commit
35d88f8c78
@ -5,11 +5,11 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.api
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.api.IDZIENNIK_API_MESSAGES_INBOX
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.idziennik.data.IdziennikApi
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_DELETED
|
||||
@ -77,7 +77,7 @@ class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
||||
|
||||
data.messageIgnoreList.add(message)
|
||||
data.messageRecipientList.add(messageRecipient)
|
||||
data.messageMetadataList.add(Metadata(
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
message.id,
|
||||
|
@ -8,6 +8,7 @@ import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusData
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api.LibrusApiAnnouncementMarkAsRead
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetAttachment
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetMessage
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaMarkAllAnnouncementsAsRead
|
||||
@ -108,7 +109,13 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
|
||||
override fun getAnnouncement(announcement: AnnouncementFull) {
|
||||
|
||||
LibrusLoginPortal(data) {
|
||||
LibrusLoginApi(data) {
|
||||
LibrusApiAnnouncementMarkAsRead(data, announcement) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAttachment(message: Message, attachmentId: Long, attachmentName: String) {
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-12-27
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
|
||||
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
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.events.AnnouncementGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.announcements.AnnouncementFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
|
||||
class LibrusApiAnnouncementMarkAsRead(
|
||||
override val data: DataLibrus,
|
||||
announcement: AnnouncementFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiAnnouncementMarkAsRead"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "SchoolNotices/MarkAsRead/${announcement.idString}") {
|
||||
announcement.seen = true
|
||||
|
||||
EventBus.getDefault().postSticky(AnnouncementGetEvent(announcement))
|
||||
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
announcement.id,
|
||||
announcement.seen,
|
||||
announcement.notified,
|
||||
announcement.addedDate
|
||||
))
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
||||
)
|
||||
|
||||
data.announcementList.add(announcementObject)
|
||||
data.metadataList.add(Metadata(
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ANNOUNCEMENT,
|
||||
id,
|
||||
|
@ -111,7 +111,7 @@ class LibrusMessagesGetMessage(
|
||||
}
|
||||
|
||||
if (!messageObject.seen) {
|
||||
data.messageMetadataList.add(Metadata(
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
messageObject.profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
|
@ -6,6 +6,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
|
||||
class LibrusSynergiaMarkAllAnnouncementsAsRead(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusSynergia(data) {
|
||||
companion object {
|
||||
@ -14,6 +15,7 @@ class LibrusSynergiaMarkAllAnnouncementsAsRead(override val data: DataLibrus, va
|
||||
|
||||
init {
|
||||
synergiaGet(TAG, "ogloszenia") {
|
||||
data.app.db.metadataDao().setAllSeen(profileId, Metadata.TYPE_ANNOUNCEMENT, true)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ class MobidziennikWebGetMessage(
|
||||
}
|
||||
|
||||
if (!message.seen) { // TODO discover why this monstrosity instead of MetadataDao.setSeen
|
||||
data.messageMetadataList.add(Metadata(
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
message.profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
message.id,
|
||||
|
@ -68,7 +68,7 @@ class MobidziennikWebMessagesInbox(override val data: DataMobidziennik,
|
||||
message.setHasAttachments()
|
||||
|
||||
data.messageIgnoreList.add(message)
|
||||
data.messageMetadataList.add(
|
||||
data.setSeenMetadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
|
@ -32,7 +32,7 @@ class VulcanApiMessagesChangeStatus(
|
||||
)) { _, _ ->
|
||||
|
||||
if (!messageObject.seen) {
|
||||
data.messageMetadataList.add(Metadata(
|
||||
data.setSeenMetadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
|
@ -161,7 +161,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
val messageRecipientIgnoreList = mutableListOf<MessageRecipient>()
|
||||
|
||||
val metadataList = mutableListOf<Metadata>()
|
||||
val messageMetadataList = mutableListOf<Metadata>()
|
||||
val setSeenMetadataList = mutableListOf<Metadata>()
|
||||
|
||||
val db: AppDb by lazy { app.db }
|
||||
|
||||
@ -212,7 +212,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
messageRecipientList.clear()
|
||||
messageRecipientIgnoreList.clear()
|
||||
metadataList.clear()
|
||||
messageMetadataList.clear()
|
||||
setSeenMetadataList.clear()
|
||||
}
|
||||
|
||||
open fun saveData() {
|
||||
@ -291,8 +291,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
|
||||
if (metadataList.isNotEmpty())
|
||||
db.metadataDao().addAllIgnore(metadataList)
|
||||
if (messageMetadataList.isNotEmpty())
|
||||
db.metadataDao().setSeen(messageMetadataList)
|
||||
if (setSeenMetadataList.isNotEmpty())
|
||||
db.metadataDao().setSeen(setSeenMetadataList)
|
||||
|
||||
// not extracted from DB - always new data
|
||||
if (lessonList.isNotEmpty()) {
|
||||
|
@ -23,6 +23,7 @@ public class LoginStore {
|
||||
public final static int LOGIN_TYPE_LIBRUS = 2;
|
||||
public final static int LOGIN_TYPE_VULCAN = 4;
|
||||
public final static int LOGIN_TYPE_IUCZNIOWIE = 3;
|
||||
public final static int LOGIN_TYPE_EDUDZIENNIK = 5;
|
||||
public final static int LOGIN_TYPE_DEMO = 20;
|
||||
@ColumnInfo(name = "loginStoreData")
|
||||
public JsonObject data;
|
||||
|
@ -172,6 +172,12 @@ public abstract class MetadataDao {
|
||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId")
|
||||
public abstract void setAllSeen(int profileId, boolean seen);
|
||||
|
||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND thingType != " + TYPE_MESSAGE)
|
||||
public abstract void setAllSeenExceptMessages(int profileId, boolean seen);
|
||||
|
||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND thingType != " + TYPE_MESSAGE + " AND thingType != " + TYPE_ANNOUNCEMENT)
|
||||
public abstract void setAllSeenExceptMessagesAndAnnouncements(int profileId, boolean seen);
|
||||
|
||||
@Query("UPDATE metadata SET notified = :notified WHERE profileId = :profileId")
|
||||
public abstract void setAllNotified(int profileId, boolean notified);
|
||||
|
||||
|
@ -33,6 +33,7 @@ import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_LIBRUS;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ANNOUNCEMENT;
|
||||
|
||||
public class AnnouncementsFragment extends Fragment {
|
||||
@ -40,7 +41,6 @@ public class AnnouncementsFragment extends Fragment {
|
||||
private App app = null;
|
||||
private MainActivity activity = null;
|
||||
private FragmentAnnouncementsBinding b = null;
|
||||
private boolean dialogOpened = false;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -70,8 +70,12 @@ public class AnnouncementsFragment extends Fragment {
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, TYPE_ANNOUNCEMENT, true));
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
|
||||
if (app.profile.getLoginStoreType() == LOGIN_TYPE_LIBRUS) {
|
||||
EdziennikTask.Companion.announcementsRead(App.profileId).enqueue(requireContext());
|
||||
} else {
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, TYPE_ANNOUNCEMENT, true));
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
@ -105,13 +109,10 @@ public class AnnouncementsFragment extends Fragment {
|
||||
return;
|
||||
}*/
|
||||
AnnouncementsAdapter announcementsAdapter = new AnnouncementsAdapter(activity, announcements, (v, announcement) -> {
|
||||
if (!dialogOpened) {
|
||||
dialogOpened = true;
|
||||
if (announcement.text == null) {
|
||||
EdziennikTask.Companion.announcementGet(App.profileId, announcement).enqueue(requireContext());
|
||||
} else {
|
||||
showAnnouncementDetailsDialog(announcement);
|
||||
}
|
||||
if (announcement.text == null || (app.profile.getLoginStoreType() == LOGIN_TYPE_LIBRUS && !announcement.seen)) {
|
||||
EdziennikTask.Companion.announcementGet(App.profileId, announcement).enqueue(requireContext());
|
||||
} else {
|
||||
showAnnouncementDetailsDialog(announcement);
|
||||
}
|
||||
});
|
||||
|
||||
@ -149,23 +150,18 @@ public class AnnouncementsFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void showAnnouncementDetailsDialog(AnnouncementFull announcement) {
|
||||
if (!dialogOpened) {
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(activity)
|
||||
.title(announcement.subject)
|
||||
.customView(R.layout.dialog_announcement, true)
|
||||
.positiveText(R.string.ok)
|
||||
.dismissListener(v -> dialogOpened = false)
|
||||
.show();
|
||||
DialogAnnouncementBinding b = DialogAnnouncementBinding.bind(dialog.getCustomView());
|
||||
b.text.setText(announcement.teacherFullName+"\n\n"+ (announcement.startDate != null ? announcement.startDate.getFormattedString() : "-")+" do "+ (announcement.endDate != null ? announcement.endDate.getFormattedString() : "-")+"\n\n" +announcement.text);
|
||||
if (!announcement.seen) {
|
||||
announcement.seen = true;
|
||||
AsyncTask.execute(() -> {
|
||||
app.db.metadataDao().setSeen(App.profileId, announcement, true);
|
||||
});
|
||||
if (recyclerView.getAdapter() != null)
|
||||
recyclerView.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(activity)
|
||||
.title(announcement.subject)
|
||||
.customView(R.layout.dialog_announcement, true)
|
||||
.positiveText(R.string.ok)
|
||||
.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) {
|
||||
announcement.seen = true;
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setSeen(App.profileId, announcement, true));
|
||||
if (recyclerView.getAdapter() != null)
|
||||
recyclerView.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.home
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -20,12 +19,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial.Icon
|
||||
import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_LIBRUS
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.home.StudentNumberDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeDebugCard
|
||||
@ -95,7 +93,14 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
.withIcon(Icon.cmd_eye_check_outline)
|
||||
.withOnClickListener(OnClickListener {
|
||||
activity.bottomSheet.close()
|
||||
AsyncTask.execute { app.db.metadataDao().setAllSeen(App.profileId, true) }
|
||||
launch { withContext(Dispatchers.Default) {
|
||||
if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS) {
|
||||
app.db.metadataDao().setAllSeenExceptMessagesAndAnnouncements(App.profileId, true)
|
||||
} else {
|
||||
app.db.metadataDao().setAllSeenExceptMessages(App.profileId, true)
|
||||
}
|
||||
} }
|
||||
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ import kotlinx.coroutines.launch
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.ERROR_LOGIN_EDUDZIENNIK_WEB_INVALID_LOGIN
|
||||
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_EDUDZIENNIK
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_EDUDZIENNIK
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentLoginEdudziennikBinding
|
||||
import pl.szczodrzynski.edziennik.startCoroutineTimer
|
||||
import pl.szczodrzynski.edziennik.ui.modules.error.ErrorSnackbar
|
||||
|
Loading…
x
Reference in New Issue
Block a user