mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	
							parent
							
								
									215c97e132
								
							
						
					
					
						commit
						01ad0c8c91
					
				
					 3 changed files with 57 additions and 12 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| package fr.free.nrw.commons.notification; | ||||
| 
 | ||||
| import android.annotation.SuppressLint; | ||||
| import android.app.FragmentManager; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.net.Uri; | ||||
|  | @ -10,7 +11,6 @@ import android.support.v7.widget.RecyclerView; | |||
| 
 | ||||
| import com.pedrogomez.renderers.RVRendererAdapter; | ||||
| 
 | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
|  | @ -35,12 +35,16 @@ public class NotificationActivity extends NavigationBaseActivity { | |||
| 
 | ||||
|     @Inject NotificationController controller; | ||||
| 
 | ||||
|     private static final String TAG_NOTIFICATION_WORKER_FRAGMENT = "NotificationWorkerFragment"; | ||||
|     private NotificationWorkerFragment mNotificationWorkerFragment; | ||||
| 
 | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setContentView(R.layout.activity_notification); | ||||
|         ButterKnife.bind(this); | ||||
|         mNotificationWorkerFragment = (NotificationWorkerFragment) getFragmentManager() | ||||
|                                       .findFragmentByTag(TAG_NOTIFICATION_WORKER_FRAGMENT); | ||||
|         initListView(); | ||||
|         initDrawer(); | ||||
|     } | ||||
|  | @ -55,14 +59,18 @@ public class NotificationActivity extends NavigationBaseActivity { | |||
|     private void addNotifications() { | ||||
|         Timber.d("Add notifications"); | ||||
| 
 | ||||
|         Observable.fromCallable(() -> controller.getNotifications()) | ||||
|                 .subscribeOn(Schedulers.io()) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribe(notificationList -> { | ||||
|                     Collections.reverse(notificationList); | ||||
|                     Timber.d("Number of notifications is %d", notificationList.size()); | ||||
|                     setAdapter(notificationList); | ||||
|                 }, throwable -> Timber.e(throwable, "Error occurred while loading notifications")); | ||||
|         if(mNotificationWorkerFragment == null){ | ||||
|             Observable.fromCallable(() -> controller.getNotifications()) | ||||
|                     .subscribeOn(Schedulers.io()) | ||||
|                     .observeOn(AndroidSchedulers.mainThread()) | ||||
|                     .subscribe(notificationList -> { | ||||
|                         Timber.d("Number of notifications is %d", notificationList.size()); | ||||
|                         initializeAndSetNotificationList(notificationList); | ||||
|                         setAdapter(notificationList); | ||||
|                     }, throwable -> Timber.e(throwable, "Error occurred while loading notifications")); | ||||
|         } else { | ||||
|             setAdapter(mNotificationWorkerFragment.getNotificationList()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void handleUrl(String url) { | ||||
|  | @ -85,4 +93,12 @@ public class NotificationActivity extends NavigationBaseActivity { | |||
|         Intent intent = new Intent(context, NotificationActivity.class); | ||||
|         context.startActivity(intent); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|     private void initializeAndSetNotificationList(List<Notification> notificationList){ | ||||
|         FragmentManager fm = getFragmentManager(); | ||||
|         mNotificationWorkerFragment = new NotificationWorkerFragment(); | ||||
|         fm.beginTransaction().add(mNotificationWorkerFragment, TAG_NOTIFICATION_WORKER_FRAGMENT) | ||||
|                 .commit(); | ||||
|         mNotificationWorkerFragment.setNotificationList(notificationList); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,29 @@ | |||
| package fr.free.nrw.commons.notification; | ||||
| 
 | ||||
| import android.app.Fragment; | ||||
| import android.os.Bundle; | ||||
| import android.support.annotation.Nullable; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| /** | ||||
|  * Created by knightshade on 25/2/18. | ||||
|  */ | ||||
| 
 | ||||
| public class NotificationWorkerFragment extends Fragment { | ||||
|     private List<Notification> notificationList; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate(@Nullable Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setRetainInstance(true); | ||||
|     } | ||||
| 
 | ||||
|     public void setNotificationList(List<Notification> notificationList){ | ||||
|         this.notificationList = notificationList; | ||||
|     } | ||||
| 
 | ||||
|     public List<Notification> getNotificationList(){ | ||||
|         return notificationList; | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 knightshade
						knightshade