From 4d14f56fa84b660932a6696b919ef4f57acb76d5 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 9 Apr 2017 18:24:52 +0200 Subject: [PATCH] Improve webtoon reader scroll up --- .../ui/reader/viewer/webtoon/WebtoonHolder.kt | 4 ++-- .../ui/reader/viewer/webtoon/WebtoonReader.kt | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt index b9acac1580..3fcbe0f5b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonHolder.kt @@ -76,10 +76,10 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter) }) } - view.progress_container.minimumHeight = view.resources.displayMetrics.heightPixels * 2 + view.progress_container.minimumHeight = webtoonReader.screenHeight view.setOnTouchListener(adapter.touchListener) - view.retry_button.setOnTouchListener { v, event -> + view.retry_button.setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_UP) { readerActivity.presenter.retryPage(page) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt index edb46e8d72..72cae4e109 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt @@ -1,7 +1,9 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon +import android.os.Build import android.os.Bundle import android.support.v7.widget.RecyclerView +import android.util.DisplayMetrics import android.view.* import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT @@ -64,6 +66,19 @@ class WebtoonReader : BaseReader() { private var scrollDistance: Int = 0 + val screenHeight by lazy { + val display = activity.windowManager.defaultDisplay + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + val metrics = DisplayMetrics() + display.getRealMetrics(metrics) + metrics.heightPixels + } else { + val field = Display::class.java.getMethod("getRawHeight") + field.invoke(display) as Int + } + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? { adapter = WebtoonAdapter(this) @@ -108,12 +123,12 @@ class WebtoonReader : BaseReader() { /** * Uses two ways to scroll to the last page read. */ - private fun scrollToLastPageRead(last_page_read: Int) { + private fun scrollToLastPageRead(page: Int) { // Scrolls to the correct page initially, but isn't reliable beyond that. recycler.addOnLayoutChangeListener(object: View.OnLayoutChangeListener { override fun onLayoutChange(p0: View?, p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int) { if(pages.isEmpty()) { - setActivePage(last_page_read) + setActivePage(page) } else { recycler.removeOnLayoutChangeListener(this) } @@ -121,7 +136,7 @@ class WebtoonReader : BaseReader() { }) // Scrolls to the correct page after app has been in use, but can't do it the very first time. - recycler.post { setActivePage(last_page_read) } + recycler.post { setActivePage(page) } } override fun onDestroyView() {