Small fix webtoon reader
This commit is contained in:
@@ -15,6 +15,7 @@ class MangaGridHolder(parent: ViewGroup) : BaseViewHolder<Manga, MangaHistory?>(
|
||||
|
||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||
coverRequest?.dispose()
|
||||
imageView_cover.setImageDrawable(null)
|
||||
textView_title.text = data.title
|
||||
coverRequest = imageView_cover.load(data.coverUrl) {
|
||||
placeholder(R.drawable.ic_placeholder)
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.fragment_reader_webtoon.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
@@ -12,7 +11,7 @@ import org.koitharu.kotatsu.ui.reader.base.AbstractReader
|
||||
import org.koitharu.kotatsu.ui.reader.base.BaseReaderAdapter
|
||||
import org.koitharu.kotatsu.ui.reader.base.GroupedList
|
||||
import org.koitharu.kotatsu.utils.ext.doOnCurrentItemChanged
|
||||
import org.koitharu.kotatsu.utils.ext.findMiddleVisibleItemPosition
|
||||
import org.koitharu.kotatsu.utils.ext.findCenterViewPosition
|
||||
import org.koitharu.kotatsu.utils.ext.firstItem
|
||||
import org.koitharu.kotatsu.utils.ext.withArgs
|
||||
|
||||
@@ -43,7 +42,7 @@ class WebtoonReaderFragment : AbstractReader(R.layout.fragment_reader_webtoon) {
|
||||
get() = adapter?.itemCount ?: 0
|
||||
|
||||
override fun getCurrentItem(): Int {
|
||||
return (recyclerView.layoutManager as LinearLayoutManager).findMiddleVisibleItemPosition()
|
||||
return recyclerView.findCenterViewPosition()
|
||||
}
|
||||
|
||||
override fun setCurrentItem(position: Int, isSmooth: Boolean) {
|
||||
|
||||
@@ -182,9 +182,8 @@ fun RecyclerView.doOnCurrentItemChanged(callback: (Int) -> Unit) {
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val item = (recyclerView.layoutManager as? LinearLayoutManager)
|
||||
?.findMiddleVisibleItemPosition()
|
||||
if (item != null && item != RecyclerView.NO_POSITION && item != lastItem) {
|
||||
val item = recyclerView.findCenterViewPosition()
|
||||
if (item != RecyclerView.NO_POSITION && item != lastItem) {
|
||||
lastItem = item
|
||||
callback(item)
|
||||
}
|
||||
@@ -222,6 +221,14 @@ fun ViewPager2.callOnPageChaneListeners() {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
fun LinearLayoutManager.findMiddleVisibleItemPosition(): Int {
|
||||
return ((findFirstVisibleItemPosition() + findLastVisibleItemPosition()) / 2.0).roundToInt()
|
||||
}
|
||||
|
||||
fun RecyclerView.findCenterViewPosition(): Int {
|
||||
val centerX = width / 2f
|
||||
val centerY = height / 2f
|
||||
val view = findChildViewUnder(centerX, centerY) ?: return RecyclerView.NO_POSITION
|
||||
return getChildAdapterPosition(view)
|
||||
}
|
||||
Reference in New Issue
Block a user