mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:25:10 +01:00
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"
This commit is contained in:
parent
4dae06803c
commit
0244e1edb4
@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.ui.library
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import eu.davidea.fastscroller.FastScroller
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.dpToPxEnd
|
||||
@ -13,6 +15,7 @@ import kotlin.math.abs
|
||||
class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
FastScroller(context, attrs) {
|
||||
|
||||
var scrollOffset = 0
|
||||
init {
|
||||
setViewsToUse(
|
||||
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() {
|
||||
onScrollListener = object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
|
@ -71,7 +71,7 @@ class MangaDetailsAdapter(
|
||||
else R.string.volume_, volume
|
||||
)
|
||||
} else {
|
||||
recyclerView.context.getString(R.string.unknown)
|
||||
getChapterName(chapter)
|
||||
}
|
||||
}
|
||||
MangaDetailsPresenter.TENS_OF_CHAPTERS -> recyclerView.context.getString(
|
||||
@ -79,13 +79,17 @@ class MangaDetailsAdapter(
|
||||
chapter.chapter_number
|
||||
)
|
||||
)
|
||||
else -> if (chapter.chapter_number > 0) {
|
||||
recyclerView.context.getString(
|
||||
R.string.chapter_, decimalFormat.format(chapter.chapter_number)
|
||||
)
|
||||
} else {
|
||||
chapter.name
|
||||
}
|
||||
else -> getChapterName(chapter)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getChapterName(item: ChapterItem): String {
|
||||
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)
|
||||
setPaletteColor()
|
||||
adapter?.fastScroller = fast_scroller2
|
||||
adapter?.fastScroller = fast_scroller
|
||||
fast_scroller.addOnScrollStateChangeListener {
|
||||
activity?.appbar?.y = 0f
|
||||
}
|
||||
|
||||
presenter.onCreate()
|
||||
swipe_refresh.isRefreshing = presenter.isLoading
|
||||
@ -264,10 +267,11 @@ class MangaDetailsController : BaseController,
|
||||
swipe_refresh.setProgressViewOffset(false, (-40).dpToPx, headerHeight + offset)
|
||||
// 1dp extra to line up chapter header and manga header
|
||||
getHeader()?.setTopHeight(headerHeight)
|
||||
fast_scroller2.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
fast_scroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = headerHeight
|
||||
bottomMargin = insets.systemWindowInsetBottom
|
||||
}
|
||||
fast_scroller.scrollOffset = headerHeight
|
||||
}
|
||||
|
||||
/** Set the toolbar to fully transparent or colored and translucent */
|
||||
|
@ -29,7 +29,7 @@
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<eu.kanade.tachiyomi.ui.library.MaterialFastScroll
|
||||
android:id="@+id/fast_scroller2"
|
||||
android:id="@+id/fast_scroller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:fastScrollerBubbleEnabled="true" />
|
||||
|
Loading…
Reference in New Issue
Block a user