Fast scroll on details now has the correct offset for the chapter its on

Also chapters with an unknown volume now show the chapter name instead of just "unknown"
pull/3372/head
Jay 4 years ago
parent 4dae06803c
commit 0244e1edb4

@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.ui.library
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import eu.davidea.fastscroller.FastScroller import eu.davidea.fastscroller.FastScroller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.dpToPxEnd import eu.kanade.tachiyomi.util.system.dpToPxEnd
@ -13,6 +15,7 @@ import kotlin.math.abs
class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FastScroller(context, attrs) { FastScroller(context, attrs) {
var scrollOffset = 0
init { init {
setViewsToUse( setViewsToUse(
R.layout.material_fastscroll, R.id.fast_scroller_bubble, R.id.fast_scroller_handle R.layout.material_fastscroll, R.id.fast_scroller_bubble, R.id.fast_scroller_handle
@ -35,6 +38,20 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
} }
} }
override fun setRecyclerViewPosition(y: Float) {
if (recyclerView != null) {
val targetPos = getTargetPos(y)
if (layoutManager is StaggeredGridLayoutManager) {
(layoutManager as StaggeredGridLayoutManager).scrollToPositionWithOffset(
targetPos, scrollOffset
)
} else {
(layoutManager as LinearLayoutManager).scrollToPositionWithOffset(targetPos, scrollOffset)
}
updateBubbleText(targetPos)
}
}
private fun updateScrollListener() { private fun updateScrollListener() {
onScrollListener = object : RecyclerView.OnScrollListener() { onScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {

@ -71,7 +71,7 @@ class MangaDetailsAdapter(
else R.string.volume_, volume else R.string.volume_, volume
) )
} else { } else {
recyclerView.context.getString(R.string.unknown) getChapterName(chapter)
} }
} }
MangaDetailsPresenter.TENS_OF_CHAPTERS -> recyclerView.context.getString( MangaDetailsPresenter.TENS_OF_CHAPTERS -> recyclerView.context.getString(
@ -79,13 +79,17 @@ class MangaDetailsAdapter(
chapter.chapter_number chapter.chapter_number
) )
) )
else -> if (chapter.chapter_number > 0) { else -> getChapterName(chapter)
recyclerView.context.getString( }
R.string.chapter_, decimalFormat.format(chapter.chapter_number) }
)
} else { private fun getChapterName(item: ChapterItem): String {
chapter.name return if (item.chapter_number > 0) {
} recyclerView.context.getString(
R.string.chapter_, decimalFormat.format(item.chapter_number)
)
} else {
item.name
} }
} }

@ -199,7 +199,10 @@ class MangaDetailsController : BaseController,
setRecycler(view) setRecycler(view)
setPaletteColor() setPaletteColor()
adapter?.fastScroller = fast_scroller2 adapter?.fastScroller = fast_scroller
fast_scroller.addOnScrollStateChangeListener {
activity?.appbar?.y = 0f
}
presenter.onCreate() presenter.onCreate()
swipe_refresh.isRefreshing = presenter.isLoading swipe_refresh.isRefreshing = presenter.isLoading
@ -264,10 +267,11 @@ class MangaDetailsController : BaseController,
swipe_refresh.setProgressViewOffset(false, (-40).dpToPx, headerHeight + offset) swipe_refresh.setProgressViewOffset(false, (-40).dpToPx, headerHeight + offset)
// 1dp extra to line up chapter header and manga header // 1dp extra to line up chapter header and manga header
getHeader()?.setTopHeight(headerHeight) getHeader()?.setTopHeight(headerHeight)
fast_scroller2.updateLayoutParams<ViewGroup.MarginLayoutParams> { fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight topMargin = headerHeight
bottomMargin = insets.systemWindowInsetBottom bottomMargin = insets.systemWindowInsetBottom
} }
fast_scroller.scrollOffset = headerHeight
} }
/** Set the toolbar to fully transparent or colored and translucent */ /** Set the toolbar to fully transparent or colored and translucent */

@ -29,7 +29,7 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<eu.kanade.tachiyomi.ui.library.MaterialFastScroll <eu.kanade.tachiyomi.ui.library.MaterialFastScroll
android:id="@+id/fast_scroller2" android:id="@+id/fast_scroller"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:fastScrollerBubbleEnabled="true" /> app:fastScrollerBubbleEnabled="true" />

Loading…
Cancel
Save