Skip to content

Commit 6868998

Browse files
authored
fixed commons-app#4230 'Opening notifications in "Read" section still marks them read and removes them from the list'. (commons-app#4249)
* notifications fixed * refractored * javadoc
1 parent b8cdc5a commit 6868998

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ public class NotificationActivity extends BaseActivity {
6565
private NotificatinAdapter adapter;
6666
private List<Notification> notificationList;
6767
MenuItem notificationMenuItem;
68+
/**
69+
* Boolean isRead is true if this notification activity is for read section of notification.
70+
*/
71+
private boolean isRead;
6872

6973
@Override
7074
protected void onCreate(Bundle savedInstanceState) {
7175
super.onCreate(savedInstanceState);
76+
isRead = getIntent().getStringExtra("title").equals("read");
7277
setContentView(R.layout.activity_notification);
7378
ButterKnife.bind(this);
7479
mNotificationWorkerFragment = (NotificationWorkerFragment) getFragmentManager()
@@ -85,8 +90,21 @@ public boolean onSupportNavigateUp() {
8590
return true;
8691
}
8792

93+
/**
94+
* If this is unread section of the notifications, removeNotification method
95+
* Marks the notification as read,
96+
* Removes the notification from unread,
97+
* Displays the Snackbar.
98+
*
99+
* Otherwise returns (read section).
100+
*
101+
* @param notification
102+
*/
88103
@SuppressLint("CheckResult")
89104
public void removeNotification(Notification notification) {
105+
if (isRead) {
106+
return;
107+
}
90108
Disposable disposable = Observable.defer((Callable<ObservableSource<Boolean>>)
91109
() -> controller.markAsRead(notification))
92110
.subscribeOn(Schedulers.io())
@@ -126,7 +144,7 @@ private void initListView() {
126144
recyclerView.setLayoutManager(new LinearLayoutManager(this));
127145
DividerItemDecoration itemDecor = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
128146
recyclerView.addItemDecoration(itemDecor);
129-
if (getIntent().getStringExtra("title").equals("read")) {
147+
if (isRead) {
130148
refresh(true);
131149
} else {
132150
refresh(false);
@@ -240,7 +258,7 @@ public static void startYourself(Context context, String title) {
240258

241259
private void setPageTitle() {
242260
if (getSupportActionBar() != null) {
243-
if (getIntent().getStringExtra("title").equals("read")) {
261+
if (isRead) {
244262
getSupportActionBar().setTitle(R.string.read_notifications);
245263
} else {
246264
getSupportActionBar().setTitle(R.string.notifications);
@@ -249,15 +267,15 @@ private void setPageTitle() {
249267
}
250268

251269
private void setEmptyView() {
252-
if (getIntent().getStringExtra("title").equals("read")) {
270+
if (isRead) {
253271
noNotificationText.setText(R.string.no_read_notification);
254272
}else {
255273
noNotificationText.setText(R.string.no_notification);
256274
}
257275
}
258276

259277
private void setMenuItemTitle() {
260-
if (getIntent().getStringExtra("title").equals("read")) {
278+
if (isRead) {
261279
notificationMenuItem.setTitle(R.string.menu_option_unread);
262280

263281
}else {

0 commit comments

Comments
 (0)