Procházet zdrojové kódy

Fix a leak when rotating screen while reading

inorichi před 9 roky
rodič
revize
11563e6f95

+ 0 - 3
app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java

@@ -66,9 +66,6 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
     }
     
     public void onPageListReady(List<Page> pages) {
-        if (viewer != null)
-            viewer.destroySubscriptions();
-        viewer = getViewer();
         viewer.onPageListReady(pages);
         viewer.updatePageNumber();
     }

+ 3 - 5
app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java

@@ -11,16 +11,14 @@ public class ViewPagerReaderAdapter extends SmartFragmentStatePagerAdapter {
 
     private List<Page> pages;
 
-    public ViewPagerReaderAdapter(FragmentManager fragmentManager) {
+    public ViewPagerReaderAdapter(FragmentManager fragmentManager, List<Page> pages) {
         super(fragmentManager);
+        this.pages = pages;
     }
 
     @Override
     public int getCount() {
-        if (pages != null)
-            return pages.size();
-
-        return 0;
+        return pages.size();
     }
 
     @Override

+ 3 - 3
app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java

@@ -24,8 +24,6 @@ public abstract class HorizontalReader extends BaseReader {
         activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container);
         ButterKnife.bind(this, container);
 
-        adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager());
-        viewPager.setAdapter(adapter);
         viewPager.setOffscreenPageLimit(3);
         viewPager.addOnPageChangeListener(new HorizontalViewPager.SimpleOnPageChangeListener() {
             @Override
@@ -60,7 +58,9 @@ public abstract class HorizontalReader extends BaseReader {
 
     @Override
     public void onPageListReady(List<Page> pages) {
-        adapter.setPages(pages);
+        currentPosition = 0;
+        adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
+        viewPager.setAdapter(adapter);
     }
 
     @Override

+ 1 - 1
app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/RightToLeftReader.java

@@ -19,7 +19,7 @@ public class RightToLeftReader extends HorizontalReader {
     public void onPageListReady(List<Page> pages) {
         ArrayList<Page> inversedPages = new ArrayList<>(pages);
         Collections.reverse(inversedPages);
-        adapter.setPages(inversedPages);
+        super.onPageListReady(inversedPages);
         viewPager.setCurrentItem(adapter.getCount() - 1, false);
     }
 

+ 3 - 3
app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java

@@ -25,8 +25,6 @@ public class VerticalReader extends BaseReader {
         activity.getLayoutInflater().inflate(R.layout.reader_vertical, container);
         ButterKnife.bind(this, container);
 
-        adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager());
-        viewPager.setAdapter(adapter);
         viewPager.setOffscreenPageLimit(3);
         viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
             @Override
@@ -49,7 +47,9 @@ public class VerticalReader extends BaseReader {
 
     @Override
     public void onPageListReady(List<Page> pages) {
-        adapter.setPages(pages);
+        currentPosition = 0;
+        adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
+        viewPager.setAdapter(adapter);
     }
 
     @Override