From 11563e6f95f0462a1066cc38cbcfec78c3a37e3f Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 16 Nov 2015 21:22:17 +0100 Subject: [PATCH] Fix a leak when rotating screen while reading --- .../eu/kanade/mangafeed/ui/reader/ReaderActivity.java | 3 --- .../ui/reader/viewer/common/ViewPagerReaderAdapter.java | 8 +++----- .../ui/reader/viewer/horizontal/HorizontalReader.java | 6 +++--- .../ui/reader/viewer/horizontal/RightToLeftReader.java | 2 +- .../ui/reader/viewer/vertical/VerticalReader.java | 6 +++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index 5bdab93fd..7bc07278c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -66,9 +66,6 @@ public class ReaderActivity extends BaseRxActivity { } public void onPageListReady(List pages) { - if (viewer != null) - viewer.destroySubscriptions(); - viewer = getViewer(); viewer.onPageListReady(pages); viewer.updatePageNumber(); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java index 9d4d2d3fe..52ced5b7a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java @@ -11,16 +11,14 @@ public class ViewPagerReaderAdapter extends SmartFragmentStatePagerAdapter { private List pages; - public ViewPagerReaderAdapter(FragmentManager fragmentManager) { + public ViewPagerReaderAdapter(FragmentManager fragmentManager, List pages) { super(fragmentManager); + this.pages = pages; } @Override public int getCount() { - if (pages != null) - return pages.size(); - - return 0; + return pages.size(); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java index aac13c961..5d76d5bd3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java +++ b/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 pages) { - adapter.setPages(pages); + currentPosition = 0; + adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages); + viewPager.setAdapter(adapter); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/RightToLeftReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/RightToLeftReader.java index d8327adee..4cf4d0c4f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/RightToLeftReader.java +++ b/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 pages) { ArrayList inversedPages = new ArrayList<>(pages); Collections.reverse(inversedPages); - adapter.setPages(inversedPages); + super.onPageListReady(inversedPages); viewPager.setCurrentItem(adapter.getCount() - 1, false); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java index a4969ad4e..216c8199b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java +++ b/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 pages) { - adapter.setPages(pages); + currentPosition = 0; + adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages); + viewPager.setAdapter(adapter); } @Override