9
9
import android .support .v7 .widget .DividerItemDecoration ;
10
10
import android .support .v7 .widget .LinearLayoutManager ;
11
11
import android .support .v7 .widget .RecyclerView ;
12
- import android .widget .Toast ;
12
+ import android .view .View ;
13
+ import android .widget .ProgressBar ;
14
+ import android .widget .RelativeLayout ;
13
15
14
16
import com .pedrogomez .renderers .RVRendererAdapter ;
15
17
18
+ import java .util .Collections ;
16
19
import java .util .List ;
17
20
18
21
import javax .inject .Inject ;
19
22
20
23
import butterknife .BindView ;
21
24
import butterknife .ButterKnife ;
22
25
import fr .free .nrw .commons .R ;
26
+ import fr .free .nrw .commons .Utils ;
23
27
import fr .free .nrw .commons .theme .NavigationBaseActivity ;
28
+ import fr .free .nrw .commons .utils .ViewUtil ;
24
29
import io .reactivex .Observable ;
25
30
import io .reactivex .android .schedulers .AndroidSchedulers ;
26
31
import io .reactivex .schedulers .Schedulers ;
27
32
import timber .log .Timber ;
28
33
29
- import static android .widget .Toast .LENGTH_SHORT ;
30
-
31
34
/**
32
35
* Created by root on 18.12.2017.
33
36
*/
@@ -36,6 +39,8 @@ public class NotificationActivity extends NavigationBaseActivity {
36
39
NotificationAdapterFactory notificationAdapterFactory ;
37
40
38
41
@ BindView (R .id .listView ) RecyclerView recyclerView ;
42
+ @ BindView (R .id .progressBar ) ProgressBar progressBar ;
43
+ @ BindView (R .id .container ) RelativeLayout relativeLayout ;
39
44
40
45
@ Inject NotificationController controller ;
41
46
@@ -65,14 +70,22 @@ private void addNotifications() {
65
70
Timber .d ("Add notifications" );
66
71
67
72
if (mNotificationWorkerFragment == null ){
68
- Observable .fromCallable (() -> controller .getNotifications ())
73
+ Observable .fromCallable (() -> {
74
+ progressBar .setVisibility (View .VISIBLE );
75
+ return controller .getNotifications ();
76
+ })
69
77
.subscribeOn (Schedulers .io ())
70
78
.observeOn (AndroidSchedulers .mainThread ())
71
79
.subscribe (notificationList -> {
80
+ Collections .reverse (notificationList );
72
81
Timber .d ("Number of notifications is %d" , notificationList .size ());
73
- initializeAndSetNotificationList (notificationList );
74
82
setAdapter (notificationList );
75
- }, throwable -> Timber .e (throwable , "Error occurred while loading notifications" ));
83
+ progressBar .setVisibility (View .GONE );
84
+ }, throwable -> {
85
+ Timber .e (throwable , "Error occurred while loading notifications" );
86
+ ViewUtil .showSnackbar (relativeLayout , R .string .error_notifications );
87
+ progressBar .setVisibility (View .GONE );
88
+ });
76
89
} else {
77
90
setAdapter (mNotificationWorkerFragment .getNotificationList ());
78
91
}
@@ -82,17 +95,14 @@ private void handleUrl(String url) {
82
95
if (url == null || url .equals ("" )) {
83
96
return ;
84
97
}
85
- Intent browser = new Intent (Intent .ACTION_VIEW , Uri .parse (url ));
86
- //check if web browser available
87
- if (browser .resolveActivity (this .getPackageManager ()) != null ){
88
- startActivity (browser );
89
- } else {
90
- Toast toast = Toast .makeText (this , getString (R .string .no_web_browser ), LENGTH_SHORT );
91
- toast .show ();
92
- }
98
+ Utils .handleWebUrl (this , Uri .parse (url ));
93
99
}
94
100
95
101
private void setAdapter (List <Notification > notificationList ) {
102
+ if (notificationList == null || notificationList .isEmpty ()) {
103
+ ViewUtil .showSnackbar (relativeLayout , R .string .no_notifications );
104
+ return ;
105
+ }
96
106
notificationAdapterFactory = new NotificationAdapterFactory (notification -> {
97
107
Timber .d ("Notification clicked %s" , notification .link );
98
108
handleUrl (notification .link );
0 commit comments