9
9
import android .view .MenuInflater ;
10
10
import android .view .MenuItem ;
11
11
import android .view .View ;
12
- import android .widget .ProgressBar ;
13
- import android .widget .RelativeLayout ;
14
- import android .widget .TextView ;
15
- import android .widget .Toast ;
16
- import androidx .appcompat .widget .Toolbar ;
17
- import androidx .constraintlayout .widget .ConstraintLayout ;
18
12
import androidx .recyclerview .widget .DividerItemDecoration ;
19
13
import androidx .recyclerview .widget .LinearLayoutManager ;
20
- import androidx .recyclerview .widget .RecyclerView ;
21
- import butterknife .BindView ;
22
- import butterknife .ButterKnife ;
23
14
import com .google .android .material .snackbar .Snackbar ;
24
15
import fr .free .nrw .commons .R ;
25
16
import fr .free .nrw .commons .Utils ;
17
+ import fr .free .nrw .commons .databinding .ActivityNotificationBinding ;
26
18
import fr .free .nrw .commons .notification .models .Notification ;
27
19
import fr .free .nrw .commons .theme .BaseActivity ;
28
20
import fr .free .nrw .commons .utils .NetworkUtils ;
44
36
*/
45
37
46
38
public class NotificationActivity extends BaseActivity {
47
- @ BindView (R .id .listView )
48
- RecyclerView recyclerView ;
49
- @ BindView (R .id .progressBar )
50
- ProgressBar progressBar ;
51
- @ BindView (R .id .container )
52
- RelativeLayout relativeLayout ;
53
- @ BindView (R .id .no_notification_background )
54
- ConstraintLayout no_notification ;
55
- @ BindView (R .id .no_notification_text )
56
- TextView noNotificationText ;
57
- @ BindView (R .id .toolbar )
58
- Toolbar toolbar ;
59
-
39
+ private ActivityNotificationBinding binding ;
60
40
61
41
@ Inject
62
42
NotificationController controller ;
@@ -75,13 +55,13 @@ public class NotificationActivity extends BaseActivity {
75
55
protected void onCreate (Bundle savedInstanceState ) {
76
56
super .onCreate (savedInstanceState );
77
57
isRead = getIntent ().getStringExtra ("title" ).equals ("read" );
78
- setContentView ( R . layout . activity_notification );
79
- ButterKnife . bind ( this );
58
+ binding = ActivityNotificationBinding . inflate ( getLayoutInflater () );
59
+ setContentView ( binding . getRoot () );
80
60
mNotificationWorkerFragment = (NotificationWorkerFragment ) getFragmentManager ()
81
61
.findFragmentByTag (TAG_NOTIFICATION_WORKER_FRAGMENT );
82
62
initListView ();
83
63
setPageTitle ();
84
- setSupportActionBar (toolbar );
64
+ setSupportActionBar (binding . toolbar . toolbar );
85
65
getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
86
66
}
87
67
@@ -115,36 +95,33 @@ public void removeNotification(Notification notification) {
115
95
notificationList .remove (notification );
116
96
setItems (notificationList );
117
97
adapter .notifyDataSetChanged ();
118
- Snackbar snackbar = Snackbar
119
- .make (relativeLayout , getString (R .string .notification_mark_read ), Snackbar .LENGTH_LONG );
120
-
121
- snackbar .show ();
98
+ ViewUtil .showLongSnackbar (binding .container ,getString (R .string .notification_mark_read ));
122
99
if (notificationList .size () == 0 ) {
123
100
setEmptyView ();
124
- relativeLayout .setVisibility (View .GONE );
125
- no_notification .setVisibility (View .VISIBLE );
101
+ binding . container .setVisibility (View .GONE );
102
+ binding . noNotificationBackground .setVisibility (View .VISIBLE );
126
103
}
127
104
} else {
128
105
adapter .notifyDataSetChanged ();
129
106
setItems (notificationList );
130
- Toast . makeText ( NotificationActivity . this , getString (R .string .some_error ), Toast . LENGTH_SHORT ). show ( );
107
+ ViewUtil . showLongToast ( this ,getString (R .string .some_error ));
131
108
}
132
109
}, throwable -> {
133
110
134
111
Timber .e (throwable , "Error occurred while loading notifications" );
135
112
throwable .printStackTrace ();
136
- ViewUtil .showShortSnackbar (relativeLayout , R .string .error_notifications );
137
- progressBar .setVisibility (View .GONE );
113
+ ViewUtil .showShortSnackbar (binding . container , R .string .error_notifications );
114
+ binding . progressBar .setVisibility (View .GONE );
138
115
});
139
116
compositeDisposable .add (disposable );
140
117
}
141
118
142
119
143
120
144
121
private void initListView () {
145
- recyclerView .setLayoutManager (new LinearLayoutManager (this ));
146
- DividerItemDecoration itemDecor = new DividerItemDecoration (recyclerView .getContext (), DividerItemDecoration .VERTICAL );
147
- recyclerView .addItemDecoration (itemDecor );
122
+ binding . listView .setLayoutManager (new LinearLayoutManager (this ));
123
+ DividerItemDecoration itemDecor = new DividerItemDecoration (binding . listView .getContext (), DividerItemDecoration .VERTICAL );
124
+ binding . listView .addItemDecoration (itemDecor );
148
125
if (isRead ) {
149
126
refresh (true );
150
127
} else {
@@ -156,27 +133,27 @@ private void initListView() {
156
133
removeNotification (item );
157
134
return Unit .INSTANCE ;
158
135
});
159
- recyclerView . setAdapter (this . adapter );
136
+ binding . listView . setAdapter (adapter );
160
137
}
161
138
162
139
private void refresh (boolean archived ) {
163
140
if (!NetworkUtils .isInternetConnectionEstablished (this )) {
164
- progressBar .setVisibility (View .GONE );
165
- Snackbar .make (relativeLayout , R .string .no_internet , Snackbar .LENGTH_INDEFINITE )
141
+ binding . progressBar .setVisibility (View .GONE );
142
+ Snackbar .make (binding . container , R .string .no_internet , Snackbar .LENGTH_INDEFINITE )
166
143
.setAction (R .string .retry , view -> refresh (archived )).show ();
167
144
} else {
168
145
addNotifications (archived );
169
146
}
170
- progressBar .setVisibility (View .VISIBLE );
171
- no_notification .setVisibility (View .GONE );
172
- relativeLayout .setVisibility (View .VISIBLE );
147
+ binding . progressBar .setVisibility (View .VISIBLE );
148
+ binding . noNotificationBackground .setVisibility (View .GONE );
149
+ binding . container .setVisibility (View .VISIBLE );
173
150
}
174
151
175
152
@ SuppressLint ("CheckResult" )
176
153
private void addNotifications (boolean archived ) {
177
154
Timber .d ("Add notifications" );
178
155
if (mNotificationWorkerFragment == null ) {
179
- progressBar .setVisibility (View .VISIBLE );
156
+ binding . progressBar .setVisibility (View .VISIBLE );
180
157
compositeDisposable .add (controller .getNotifications (archived )
181
158
.subscribeOn (Schedulers .io ())
182
159
.observeOn (AndroidSchedulers .mainThread ())
@@ -186,16 +163,16 @@ private void addNotifications(boolean archived) {
186
163
this .notificationList = notificationList ;
187
164
if (notificationList .size ()==0 ){
188
165
setEmptyView ();
189
- relativeLayout .setVisibility (View .GONE );
190
- no_notification .setVisibility (View .VISIBLE );
166
+ binding . container .setVisibility (View .GONE );
167
+ binding . noNotificationBackground .setVisibility (View .VISIBLE );
191
168
} else {
192
169
setItems (notificationList );
193
170
}
194
- progressBar .setVisibility (View .GONE );
171
+ binding . progressBar .setVisibility (View .GONE );
195
172
}, throwable -> {
196
173
Timber .e (throwable , "Error occurred while loading notifications" );
197
- ViewUtil .showShortSnackbar (relativeLayout , R .string .error_notifications );
198
- progressBar .setVisibility (View .GONE );
174
+ ViewUtil .showShortSnackbar (binding . container , R .string .error_notifications );
175
+ binding . progressBar .setVisibility (View .GONE );
199
176
}));
200
177
} else {
201
178
notificationList = mNotificationWorkerFragment .getNotificationList ();
@@ -237,16 +214,16 @@ private void handleUrl(String url) {
237
214
238
215
private void setItems (List <Notification > notificationList ) {
239
216
if (notificationList == null || notificationList .isEmpty ()) {
240
- ViewUtil .showShortSnackbar (relativeLayout , R .string .no_notifications );
217
+ ViewUtil .showShortSnackbar (binding . container , R .string .no_notifications );
241
218
/*progressBar.setVisibility(View.GONE);
242
219
recyclerView.setVisibility(View.GONE);*/
243
- relativeLayout .setVisibility (View .GONE );
220
+ binding . container .setVisibility (View .GONE );
244
221
setEmptyView ();
245
- no_notification .setVisibility (View .VISIBLE );
222
+ binding . noNotificationBackground .setVisibility (View .VISIBLE );
246
223
return ;
247
224
}
248
- relativeLayout .setVisibility (View .VISIBLE );
249
- no_notification .setVisibility (View .GONE );
225
+ binding . container .setVisibility (View .VISIBLE );
226
+ binding . noNotificationBackground .setVisibility (View .GONE );
250
227
adapter .setItems (notificationList );
251
228
}
252
229
@@ -269,9 +246,9 @@ private void setPageTitle() {
269
246
270
247
private void setEmptyView () {
271
248
if (isRead ) {
272
- noNotificationText .setText (R .string .no_read_notification );
249
+ binding . noNotificationText .setText (R .string .no_read_notification );
273
250
}else {
274
- noNotificationText .setText (R .string .no_notification );
251
+ binding . noNotificationText .setText (R .string .no_notification );
275
252
}
276
253
}
277
254
0 commit comments