mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
parent
215c97e132
commit
01ad0c8c91
3 changed files with 57 additions and 12 deletions
|
|
@ -49,7 +49,7 @@ dependencies {
|
|||
compile 'com.facebook.stetho:stetho:1.5.0'
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.robolectric:robolectric:3.4'
|
||||
testCompile 'org.robolectric:robolectric:3.7.1'
|
||||
|
||||
testCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||
|
|
@ -78,7 +78,7 @@ dependencies {
|
|||
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.robolectric:robolectric:3.4'
|
||||
testImplementation 'org.robolectric:robolectric:3.7.1'
|
||||
testImplementation 'org.mockito:mockito-all:1.10.19'
|
||||
|
||||
testImplementation 'com.squareup.okhttp3:mockwebserver:3.8.1'
|
||||
|
|
|
|||
|
|
@ -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