Skip to content

Commit

Permalink
Implement Mark all as read
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarvis Lin committed Feb 7, 2024
1 parent 8bfcb50 commit 9bebd86
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.wordpress.android.widgets.WPViewPagerTransformer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -214,7 +215,7 @@ private void updateUIAndNote(boolean doRefresh) {

// set title
setActionBarTitleForNote(note);
markNoteAsRead(note);
mViewModel.markNoteAsRead(this, Collections.singletonList(note));

// If `note.getTimestamp()` is not the most recent seen note, the server will discard the value.
NotificationsActions.updateSeenTimestamp(note);
Expand Down Expand Up @@ -250,7 +251,8 @@ public void onPageSelected(int position) {
Note currentNote = mAdapter.getNoteAtPosition(position);
if (currentNote != null) {
setActionBarTitleForNote(currentNote);
markNoteAsRead(currentNote);
mViewModel.markNoteAsRead(NotificationsDetailActivity.this,
Collections.singletonList(currentNote));
NotificationsActions.updateSeenTimestamp(currentNote);
// track subsequent comment note views
trackCommentNote(currentNote);
Expand Down Expand Up @@ -336,10 +338,6 @@ private void showErrorToastAndFinish() {
finish();
}

private void markNoteAsRead(@NonNull Note... note) {
mViewModel.markNoteAsRead(this, note);
}

private void setActionBarTitleForNote(Note note) {
if (getSupportActionBar() != null) {
String title = note.getTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment)
popupWindow.contentView = LayoutInflater.from(requireContext())
.inflate(R.layout.notification_actions, null).apply {
findViewById<View>(R.id.text_mark_all_as_read).setOnClickListener {
markAllAsRead()
analyticsTrackerWrapper.track(NOTIFICATIONS_MARK_ALL_READ_TAPPED)
(childFragmentManager.fragments[binding!!.viewPager.currentItem] as NotificationsListFragmentPage)
.markAllNotesAsRead()
popupWindow.dismiss()
}
findViewById<View>(R.id.text_settings).setOnClickListener {
Expand All @@ -325,16 +327,6 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment)
popupWindow.showAsDropDown(anchorView)
}

/**
* For marking the status of every notification as read
*/
private fun markAllAsRead() {
analyticsTrackerWrapper.track(NOTIFICATIONS_MARK_ALL_READ_TAPPED)
viewModel.markNoteAsRead(requireContext(), * viewModel.notes.toTypedArray())
(childFragmentManager.fragments[binding!!.viewPager.currentItem - 1] as NotificationsListFragmentPage)
.markAllNotesAsRead()
}

companion object {
const val NOTE_ID_EXTRA = "noteId"
const val NOTE_INSTANT_REPLY_EXTRA = "instantReply"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.wordpress.android.datasets.NotificationsTable
import org.wordpress.android.fluxc.model.CommentStatus
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.models.Note
import org.wordpress.android.push.GCMMessageHandler
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.PagePostCreationSourcesDetail.POST_FROM_NOTIFS_EMPTY_VIEW
Expand Down Expand Up @@ -412,7 +411,7 @@ class NotificationsListFragmentPage : ViewPagerFragment(R.layout.notifications_l
}

fun markAllNotesAsRead() {
viewModel.markNoteAsRead(requireContext(), notesAdapter.notes)
viewModel.markNoteAsRead(requireContext(), createOrGetNotesAdapter().notes)
}

@Subscribe(sticky = true, threadMode = MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class NotificationsListViewModel @Inject constructor(
appPrefsWrapper.notificationPermissionsWarningDismissed = false
}

fun markNoteAsRead(context: Context, vararg notes: Note) {
fun markNoteAsRead(context: Context, notes: List<Note>) {
notes.filter { it.isUnread }
.map {
gcmMessageHandler.removeNotificationWithNoteIdFromSystemBar(context, it.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class NotesAdapter(
private val textIndentSize: Int
private val dataLoadedListener: DataLoadedListener
private val onLoadMoreListener: OnLoadMoreListener?
private val notes = ArrayList<Note>()
private val filteredNotes = ArrayList<Note>()
val notes = ArrayList<Note>()

@JvmField
@Inject
Expand Down

0 comments on commit 9bebd86

Please sign in to comment.