From f19889c222ed8fe02577d1c244279949d4369fd7 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 29 Jan 2016 16:17:26 +0100 Subject: [PATCH] Avoid OutOfMemory crashes on webtoon viewer increasing view holders height --- .../ui/reader/viewer/webtoon/WebtoonHolder.java | 13 +++++++++++-- .../ui/reader/viewer/webtoon/WebtoonReader.java | 2 +- app/src/main/res/layout/item_webtoon_reader.xml | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java index 181cca3c0c..0ed8ba700d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.java @@ -30,7 +30,7 @@ public class WebtoonHolder extends RecyclerView.ViewHolder { super(view); this.adapter = adapter; ButterKnife.bind(this, view); - + int maxDim = ((ReaderActivity)adapter.getReader().getActivity()).getMaxBitmapSize(); imageView.setParallelLoadingEnabled(true); @@ -40,8 +40,17 @@ public class WebtoonHolder extends RecyclerView.ViewHolder { imageView.setMaxScale(10); imageView.setOnTouchListener(touchListener); imageView.setMaxDimensions(maxDim, maxDim); + imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() { + @Override + public void onImageLoaded() { + // When the image is loaded, reset the minimum height to avoid gaps + container.setMinimumHeight(0); + } + }); - progressBar.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels); + // Avoid to create a lot of view holders taking all the screen height, + // saving memory and a possible OOM + container.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels); container.setOnTouchListener(touchListener); retryButton.setOnTouchListener((v, event) -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java index d4e2359581..c59d93a615 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.java @@ -35,7 +35,7 @@ public class WebtoonReader extends BaseReader { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { adapter = new WebtoonAdapter(this); layoutManager = new PreCachingLayoutManager(getActivity()); - layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels); + layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels / 2); recycler = new RecyclerView(getActivity()); recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); diff --git a/app/src/main/res/layout/item_webtoon_reader.xml b/app/src/main/res/layout/item_webtoon_reader.xml index 4d3fe8870e..37d553ba7a 100644 --- a/app/src/main/res/layout/item_webtoon_reader.xml +++ b/app/src/main/res/layout/item_webtoon_reader.xml @@ -6,7 +6,7 @@