Fix a leak when rotating screen while reading

This commit is contained in:
inorichi 2015-11-16 21:22:17 +01:00
parent e177edfee6
commit 11563e6f95
5 changed files with 10 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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