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 {