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) {
if (viewer != null)
viewer.destroySubscriptions();
viewer = getViewer();
viewer.onPageListReady(pages);
viewer.updatePageNumber();
}

View file

@ -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

View file

@ -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

View file

@ -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);
}

View file

@ -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