@@ -65,10 +65,15 @@ public class NotificationActivity extends BaseActivity {
65
65
private NotificatinAdapter adapter ;
66
66
private List <Notification > notificationList ;
67
67
MenuItem notificationMenuItem ;
68
+ /**
69
+ * Boolean isRead is true if this notification activity is for read section of notification.
70
+ */
71
+ private boolean isRead ;
68
72
69
73
@ Override
70
74
protected void onCreate (Bundle savedInstanceState ) {
71
75
super .onCreate (savedInstanceState );
76
+ isRead = getIntent ().getStringExtra ("title" ).equals ("read" );
72
77
setContentView (R .layout .activity_notification );
73
78
ButterKnife .bind (this );
74
79
mNotificationWorkerFragment = (NotificationWorkerFragment ) getFragmentManager ()
@@ -85,8 +90,21 @@ public boolean onSupportNavigateUp() {
85
90
return true ;
86
91
}
87
92
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
+ */
88
103
@ SuppressLint ("CheckResult" )
89
104
public void removeNotification (Notification notification ) {
105
+ if (isRead ) {
106
+ return ;
107
+ }
90
108
Disposable disposable = Observable .defer ((Callable <ObservableSource <Boolean >>)
91
109
() -> controller .markAsRead (notification ))
92
110
.subscribeOn (Schedulers .io ())
@@ -126,7 +144,7 @@ private void initListView() {
126
144
recyclerView .setLayoutManager (new LinearLayoutManager (this ));
127
145
DividerItemDecoration itemDecor = new DividerItemDecoration (recyclerView .getContext (), DividerItemDecoration .VERTICAL );
128
146
recyclerView .addItemDecoration (itemDecor );
129
- if (getIntent (). getStringExtra ( "title" ). equals ( "read" ) ) {
147
+ if (isRead ) {
130
148
refresh (true );
131
149
} else {
132
150
refresh (false );
@@ -240,7 +258,7 @@ public static void startYourself(Context context, String title) {
240
258
241
259
private void setPageTitle () {
242
260
if (getSupportActionBar () != null ) {
243
- if (getIntent (). getStringExtra ( "title" ). equals ( "read" ) ) {
261
+ if (isRead ) {
244
262
getSupportActionBar ().setTitle (R .string .read_notifications );
245
263
} else {
246
264
getSupportActionBar ().setTitle (R .string .notifications );
@@ -249,15 +267,15 @@ private void setPageTitle() {
249
267
}
250
268
251
269
private void setEmptyView () {
252
- if (getIntent (). getStringExtra ( "title" ). equals ( "read" ) ) {
270
+ if (isRead ) {
253
271
noNotificationText .setText (R .string .no_read_notification );
254
272
}else {
255
273
noNotificationText .setText (R .string .no_notification );
256
274
}
257
275
}
258
276
259
277
private void setMenuItemTitle () {
260
- if (getIntent (). getStringExtra ( "title" ). equals ( "read" ) ) {
278
+ if (isRead ) {
261
279
notificationMenuItem .setTitle (R .string .menu_option_unread );
262
280
263
281
}else {
0 commit comments