Pārlūkot izejas kodu

Use BehaviorSubject instead of PublishSubject to observe page progress

inorichi 9 gadi atpakaļ
vecāks
revīzija
cd456d2186

+ 3 - 3
app/src/main/java/eu/kanade/mangafeed/data/models/Page.java

@@ -1,7 +1,7 @@
 package eu.kanade.mangafeed.data.models;
 
 import eu.kanade.mangafeed.data.helpers.NetworkHelper;
-import rx.subjects.PublishSubject;
+import rx.subjects.BehaviorSubject;
 
 public class Page implements NetworkHelper.ProgressListener {
 
@@ -12,7 +12,7 @@ public class Page implements NetworkHelper.ProgressListener {
     private transient int status;
     private transient int progress;
 
-    private transient PublishSubject<Integer> statusSubject;
+    private transient BehaviorSubject<Integer> statusSubject;
 
     public static final int QUEUE = 0;
     public static final int LOAD_PAGE = 1;
@@ -83,7 +83,7 @@ public class Page implements NetworkHelper.ProgressListener {
         progress = (int) ((100 * bytesRead) / contentLength);
     }
 
-    public void setStatusSubject(PublishSubject<Integer> subject) {
+    public void setStatusSubject(BehaviorSubject<Integer> subject) {
         this.statusSubject = subject;
     }
 

+ 8 - 11
app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java

@@ -24,7 +24,7 @@ import rx.Observable;
 import rx.Subscription;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
-import rx.subjects.PublishSubject;
+import rx.subjects.BehaviorSubject;
 
 public class ReaderPageFragment extends Fragment {
 
@@ -104,17 +104,18 @@ public class ReaderPageFragment extends Fragment {
 
     private void processStatus(int status) {
         switch (status) {
-            case Page.READY:
-                showImage();
-                unsubscribeProgress();
-                unsubscribeStatus();
-                break;
             case Page.LOAD_PAGE:
                 showLoading();
                 break;
             case Page.DOWNLOAD_IMAGE:
+                observeProgress();
                 showDownloading();
                 break;
+            case Page.READY:
+                showImage();
+                unsubscribeProgress();
+                unsubscribeStatus();
+                break;
             case Page.ERROR:
                 showError();
                 unsubscribeProgress();
@@ -129,13 +130,9 @@ public class ReaderPageFragment extends Fragment {
         if (page.getStatus() == Page.READY) {
             showImage();
         } else {
-            processStatus(page.getStatus());
-
-            PublishSubject<Integer> statusSubject = PublishSubject.create();
+            BehaviorSubject<Integer> statusSubject = BehaviorSubject.create();
             page.setStatusSubject(statusSubject);
 
-            observeProgress();
-
             statusSubscription = statusSubject
                     .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(this::processStatus);