From 28a4f0e237867f89c46c1698b42add346957c126 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 13 Nov 2019 23:19:09 -0800 Subject: [PATCH] Automatic newest chapter placement on recently read to manga chapters --- .../ui/recently_read/RecentlyReadAdapter.kt | 2 +- .../ui/recently_read/RecentlyReadController.kt | 4 ++-- .../ui/recently_read/RecentlyReadHolder.kt | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadAdapter.kt index 766ce466db..2a7f082003 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadAdapter.kt @@ -43,6 +43,6 @@ class RecentlyReadAdapter(controller: RecentlyReadController) } interface OnCoverClickListener { - fun onCoverClick(position: Int) + fun onCoverClick(position: Int, lastTouchY: Float) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 46340d82e8..0e25601bc4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -102,9 +102,9 @@ class RecentlyReadController : NucleusController(), RemoveHistoryDialog(this, manga, history).showDialog(router) } - override fun onCoverClick(position: Int) { + override fun onCoverClick(position: Int, lastTouchY: Float) { val manga = adapter?.getItem(position)?.mch?.manga ?: return - router.pushController(MangaController(manga).withFadeTransaction()) + router.pushController(MangaController(manga, lastTouchY).withFadeTransaction()) } override fun removeHistory(manga: Manga, history: History, all: Boolean) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt index 64eab1a9b1..0514b66155 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.ui.recently_read +import android.os.Build +import android.view.MotionEvent import android.view.View import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.R @@ -8,6 +10,7 @@ import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import kotlinx.android.synthetic.main.recently_read_item.* import java.util.Date +import kotlin.math.max /** * Holder that contains recent manga item @@ -23,6 +26,7 @@ class RecentlyReadHolder( val adapter: RecentlyReadAdapter ) : BaseFlexibleViewHolder(view, adapter) { + private var lastTouchUpY = 0f init { remove.setOnClickListener { adapter.removeClickListener.onRemoveClick(adapterPosition) @@ -33,7 +37,17 @@ class RecentlyReadHolder( } cover.setOnClickListener { - adapter.coverClickListener.onCoverClick(adapterPosition) + adapter.coverClickListener.onCoverClick(adapterPosition, lastTouchUpY) + } + cover.setOnTouchListener { v, event -> + when (event?.action) { + MotionEvent.ACTION_UP -> { + val topH = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + v.rootWindowInsets.systemWindowInsetTop else 38 + lastTouchUpY = max(topH + 175f, event.rawY - topH - 154f) + } + } + false } }