1
1
package fr .free .nrw .commons .notification ;
2
2
3
3
import android .annotation .SuppressLint ;
4
+ import android .app .FragmentManager ;
4
5
import android .content .Context ;
5
6
import android .content .Intent ;
6
7
import android .net .Uri ;
12
13
13
14
import com .pedrogomez .renderers .RVRendererAdapter ;
14
15
15
- import java .util .Collections ;
16
16
import java .util .List ;
17
17
18
18
import javax .inject .Inject ;
@@ -39,12 +39,16 @@ public class NotificationActivity extends NavigationBaseActivity {
39
39
40
40
@ Inject NotificationController controller ;
41
41
42
+ private static final String TAG_NOTIFICATION_WORKER_FRAGMENT = "NotificationWorkerFragment" ;
43
+ private NotificationWorkerFragment mNotificationWorkerFragment ;
42
44
43
45
@ Override
44
46
protected void onCreate (Bundle savedInstanceState ) {
45
47
super .onCreate (savedInstanceState );
46
48
setContentView (R .layout .activity_notification );
47
49
ButterKnife .bind (this );
50
+ mNotificationWorkerFragment = (NotificationWorkerFragment ) getFragmentManager ()
51
+ .findFragmentByTag (TAG_NOTIFICATION_WORKER_FRAGMENT );
48
52
initListView ();
49
53
initDrawer ();
50
54
}
@@ -60,14 +64,18 @@ private void initListView() {
60
64
private void addNotifications () {
61
65
Timber .d ("Add notifications" );
62
66
63
- Observable .fromCallable (() -> controller .getNotifications ())
64
- .subscribeOn (Schedulers .io ())
65
- .observeOn (AndroidSchedulers .mainThread ())
66
- .subscribe (notificationList -> {
67
- Collections .reverse (notificationList );
68
- Timber .d ("Number of notifications is %d" , notificationList .size ());
69
- setAdapter (notificationList );
70
- }, throwable -> Timber .e (throwable , "Error occurred while loading notifications" ));
67
+ if (mNotificationWorkerFragment == null ){
68
+ Observable .fromCallable (() -> controller .getNotifications ())
69
+ .subscribeOn (Schedulers .io ())
70
+ .observeOn (AndroidSchedulers .mainThread ())
71
+ .subscribe (notificationList -> {
72
+ Timber .d ("Number of notifications is %d" , notificationList .size ());
73
+ initializeAndSetNotificationList (notificationList );
74
+ setAdapter (notificationList );
75
+ }, throwable -> Timber .e (throwable , "Error occurred while loading notifications" ));
76
+ } else {
77
+ setAdapter (mNotificationWorkerFragment .getNotificationList ());
78
+ }
71
79
}
72
80
73
81
private void handleUrl (String url ) {
@@ -98,4 +106,12 @@ public static void startYourself(Context context) {
98
106
intent .addFlags (Intent .FLAG_ACTIVITY_REORDER_TO_FRONT );
99
107
context .startActivity (intent );
100
108
}
101
- }
109
+
110
+ private void initializeAndSetNotificationList (List <Notification > notificationList ){
111
+ FragmentManager fm = getFragmentManager ();
112
+ mNotificationWorkerFragment = new NotificationWorkerFragment ();
113
+ fm .beginTransaction ().add (mNotificationWorkerFragment , TAG_NOTIFICATION_WORKER_FRAGMENT )
114
+ .commit ();
115
+ mNotificationWorkerFragment .setNotificationList (notificationList );
116
+ }
117
+ }
0 commit comments