From 68689980ee10036320915022ab1e3db5f6af6648 Mon Sep 17 00:00:00 2001 From: Aditya-Srivastav <54016427+4D17Y4@users.noreply.github.com> Date: Sat, 20 Feb 2021 06:30:22 +0530 Subject: [PATCH] fixed #4230 'Opening notifications in "Read" section still marks them read and removes them from the list'. (#4249) * notifications fixed * refractored * javadoc --- .../notification/NotificationActivity.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java index 975629047..c8791feab 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java @@ -65,10 +65,15 @@ public class NotificationActivity extends BaseActivity { private NotificatinAdapter adapter; private List notificationList; MenuItem notificationMenuItem; + /** + * Boolean isRead is true if this notification activity is for read section of notification. + */ + private boolean isRead; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + isRead = getIntent().getStringExtra("title").equals("read"); setContentView(R.layout.activity_notification); ButterKnife.bind(this); mNotificationWorkerFragment = (NotificationWorkerFragment) getFragmentManager() @@ -85,8 +90,21 @@ public class NotificationActivity extends BaseActivity { return true; } + /** + * If this is unread section of the notifications, removeNotification method + * Marks the notification as read, + * Removes the notification from unread, + * Displays the Snackbar. + * + * Otherwise returns (read section). + * + * @param notification + */ @SuppressLint("CheckResult") public void removeNotification(Notification notification) { + if (isRead) { + return; + } Disposable disposable = Observable.defer((Callable>) () -> controller.markAsRead(notification)) .subscribeOn(Schedulers.io()) @@ -126,7 +144,7 @@ public class NotificationActivity extends BaseActivity { recyclerView.setLayoutManager(new LinearLayoutManager(this)); DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL); recyclerView.addItemDecoration(itemDecor); - if (getIntent().getStringExtra("title").equals("read")) { + if (isRead) { refresh(true); } else { refresh(false); @@ -240,7 +258,7 @@ public class NotificationActivity extends BaseActivity { private void setPageTitle() { if (getSupportActionBar() != null) { - if (getIntent().getStringExtra("title").equals("read")) { + if (isRead) { getSupportActionBar().setTitle(R.string.read_notifications); } else { getSupportActionBar().setTitle(R.string.notifications); @@ -249,7 +267,7 @@ public class NotificationActivity extends BaseActivity { } private void setEmptyView() { - if (getIntent().getStringExtra("title").equals("read")) { + if (isRead) { noNotificationText.setText(R.string.no_read_notification); }else { noNotificationText.setText(R.string.no_notification); @@ -257,7 +275,7 @@ public class NotificationActivity extends BaseActivity { } private void setMenuItemTitle() { - if (getIntent().getStringExtra("title").equals("read")) { + if (isRead) { notificationMenuItem.setTitle(R.string.menu_option_unread); }else {