From 737d3d4282593dd70b523c1f685828bd339971f2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 4 Jan 2016 16:18:18 +0100 Subject: [PATCH] Improve webtoon reader precaching images. Show a badge for the apk. --- README.md | 2 +- .../reader/viewer/webtoon/WebtoonReader.java | 10 +++---- .../widget/PreCachingLayoutManager.java | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/widget/PreCachingLayoutManager.java diff --git a/README.md b/README.md index d78879dd20..96ba13b870 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Mangafeed is a Manga reader for Android that tries to have the same features as Manga Watcher, but being Open Source. -Latest debug build available [here](http://mangafeed.kanade.eu/latest/app-debug.apk) +[![latest debug build](https://img.shields.io/badge/download-latest%20debug%20build-brightgreen.svg)](http://mangafeed.kanade.eu/latest/app-debug.apk) ## License diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java index 3f9c3c2035..1a867fc539 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java @@ -2,7 +2,6 @@ package eu.kanade.mangafeed.ui.reader.viewer.webtoon; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.GestureDetector; import android.view.LayoutInflater; @@ -14,6 +13,7 @@ import java.util.List; import eu.kanade.mangafeed.data.source.model.Page; import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader; +import eu.kanade.mangafeed.widget.PreCachingLayoutManager; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.subjects.PublishSubject; @@ -24,6 +24,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; public class WebtoonReader extends BaseReader { private WebtoonAdapter adapter; + private RecyclerView recycler; private Subscription subscription; private GestureDetector gestureDetector; @@ -31,9 +32,9 @@ public class WebtoonReader extends BaseReader { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { adapter = new WebtoonAdapter(this); - LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); + PreCachingLayoutManager layoutManager = new PreCachingLayoutManager(getActivity()); - RecyclerView recycler = new RecyclerView(getActivity()); + recycler = new RecyclerView(getActivity()); recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); recycler.setLayoutManager(layoutManager); recycler.setItemAnimator(null); @@ -70,8 +71,7 @@ public class WebtoonReader extends BaseReader { @Override public void setSelectedPage(int pageNumber) { - // TODO - return; + recycler.scrollToPosition(getPositionForPage(pageNumber)); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/widget/PreCachingLayoutManager.java b/app/src/main/java/eu/kanade/mangafeed/widget/PreCachingLayoutManager.java new file mode 100644 index 0000000000..7ae40b8aad --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/widget/PreCachingLayoutManager.java @@ -0,0 +1,28 @@ +package eu.kanade.mangafeed.widget; + +import android.content.Context; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +public class PreCachingLayoutManager extends LinearLayoutManager { + + private static final int DEFAULT_EXTRA_LAYOUT_SPACE = 600; + private int extraLayoutSpace = -1; + + public PreCachingLayoutManager(Context context) { + super(context); + } + + public void setExtraLayoutSpace(int extraLayoutSpace) { + this.extraLayoutSpace = extraLayoutSpace; + } + + @Override + protected int getExtraLayoutSpace(RecyclerView.State state) { + if (extraLayoutSpace > 0) { + return extraLayoutSpace; + } + return DEFAULT_EXTRA_LAYOUT_SPACE; + } + +}