Showing category change via the fastscroll indicator, Library title is now always "Library"

This commit is contained in:
Jay 2020-04-13 02:26:19 -04:00
parent ea0b4c2bc3
commit 60bb7d919d
4 changed files with 57 additions and 18 deletions

View File

@ -139,10 +139,7 @@ class LibraryController(
private var alwaysShowScroller: Boolean = preferences.alwaysShowSeeker().getOrDefault() private var alwaysShowScroller: Boolean = preferences.alwaysShowSeeker().getOrDefault()
override fun getTitle(): String? { override fun getTitle(): String? {
return if (view != null && presenter.categories.size > 1) presenter.categories.find { return view?.context?.getString(R.string.library)
it.order == activeCategory
}?.name ?: view?.context?.getString(R.string.library)
else view?.context?.getString(R.string.library)
} }
private var scrollListener = object : RecyclerView.OnScrollListener() { private var scrollListener = object : RecyclerView.OnScrollListener() {
@ -159,7 +156,22 @@ class LibraryController(
if (order != null && order != activeCategory && lastItem == null) { if (order != null && order != activeCategory && lastItem == null) {
preferences.lastUsedCategory().set(order) preferences.lastUsedCategory().set(order)
activeCategory = order activeCategory = order
setTitle() if (presenter.categories.size > 1 && dy != 0 && abs(dy) > 75) {
val headerItem = getHeader() ?: return
val view = fast_scroller.getChildAt(0) ?: return
val index = adapter.headerItems.indexOf(headerItem)
textAnim?.cancel()
textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(2000)
textAnim?.start()
// fastScroll height * indicator position - center text - fastScroll padding
text_view_m.translationY = view.height *
(index.toFloat() / (adapter.headerItems.size + 1))
- text_view_m.height / 2 + 16.dpToPx
text_view_m.translationX = 50f.dpToPx
text_view_m.alpha = 1f
text_view_m.text = headerItem.category.name
}
} }
} }
@ -206,7 +218,7 @@ class LibraryController(
super.onViewCreated(view) super.onViewCreated(view)
view.applyWindowInsetsForRootController(activity!!.bottom_nav) view.applyWindowInsetsForRootController(activity!!.bottom_nav)
if (!::presenter.isInitialized) presenter = LibraryPresenter(this) if (!::presenter.isInitialized) presenter = LibraryPresenter(this)
fast_scroller.translationX = 25f.dpToPx if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPx
setFastScrollBackground() setFastScrollBackground()
adapter = LibraryCategoryAdapter(this) adapter = LibraryCategoryAdapter(this)
@ -248,9 +260,22 @@ class LibraryController(
textAnim?.start() textAnim?.start()
text_view_m.translationY = indicatorCenterY.toFloat() - text_view_m.height / 2 text_view_m.translationY = indicatorCenterY.toFloat() - text_view_m.height / 2
text_view_m.translationX = 0f
text_view_m.alpha = 1f text_view_m.alpha = 1f
text_view_m.text = adapter.onCreateBubbleText(itemPosition) text_view_m.text = adapter.onCreateBubbleText(itemPosition)
val appbar = activity?.appbar val appbar = activity?.appbar
if (singleCategory) {
val order = when (val item = adapter.getItem(itemPosition)) {
is LibraryHeaderItem -> item
is LibraryItem -> item.header
else -> null
}?.category?.order
if (order != null) {
activeCategory = order
preferences.lastUsedCategory().set(order)
}
}
appbar?.y = 0f appbar?.y = 0f
recycler.suppressLayout(true) recycler.suppressLayout(true)
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
@ -333,6 +358,25 @@ class LibraryController(
} }
} }
private fun getHeader(): LibraryHeaderItem? {
val position =
(recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
if (position > 0) {
when (val item = adapter.getItem(position)) {
is LibraryHeaderItem -> return item
is LibraryItem -> return item.header
}
} else {
val fPosition =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
when (val item = adapter.getItem(fPosition)) {
is LibraryHeaderItem -> return item
is LibraryItem -> return item.header
}
}
return null
}
private fun getCategoryOrder(): Int? { private fun getCategoryOrder(): Int? {
val position = val position =
(recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() (recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
@ -445,13 +489,12 @@ class LibraryController(
adapter.setItems(mangaMap) adapter.setItems(mangaMap)
singleCategory = presenter.categories.size <= 1 singleCategory = presenter.categories.size <= 1
setTitle() progress.gone()
if (!freshStart) { if (!freshStart) {
justStarted = false justStarted = false
if (recycler_layout.alpha == 0f) recycler_layout.animate().alpha(1f).setDuration(500) if (recycler_layout.alpha == 0f) recycler_layout.animate().alpha(1f).setDuration(500)
.start() .start()
} else if (justStarted && freshStart) { } else if (justStarted && freshStart) {
progress.gone()
scrollToHeader(activeCategory) scrollToHeader(activeCategory)
fast_scroller.translationX = 0f fast_scroller.translationX = 0f
view?.post { view?.post {
@ -675,9 +718,6 @@ class LibraryController(
) == null ) == null
) { ) {
recycler.scrollBy(0, recycler.paddingTop) recycler.scrollBy(0, recycler.paddingTop)
view?.post {
setTitle()
}
} }
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
if (lastItemPosition == toPosition) lastItemPosition = null if (lastItemPosition == toPosition) lastItemPosition = null
@ -695,11 +735,11 @@ class LibraryController(
} }
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
lastItem = null
if (adapter.selectedItemCount > 0) { if (adapter.selectedItemCount > 0) {
lastItemPosition = null lastItemPosition = null
return return
} }
lastItem = null
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
// if nothing moved // if nothing moved
if (lastItemPosition == null) return if (lastItemPosition == null) return

View File

@ -55,15 +55,14 @@
tools:alpha="1" tools:alpha="1"
android:layout_marginEnd="50dp" android:layout_marginEnd="50dp"
android:background="@drawable/round_textview_background" android:background="@drawable/round_textview_background"
android:backgroundTint="@color/md_grey_800_50" android:backgroundTint="@color/md_grey_800_85"
android:padding="12dp" android:padding="10dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
app:layout_constraintEnd_toStartOf="@id/fast_scroller" app:layout_constraintEnd_toStartOf="@id/fast_scroller"
app:layout_constraintTop_toTopOf="@id/fast_scroller" app:layout_constraintTop_toTopOf="@id/fast_scroller"
tools:text="sdfsdf" /> tools:text="Category" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<eu.kanade.tachiyomi.widget.EmptyView <eu.kanade.tachiyomi.widget.EmptyView
android:id="@+id/empty_view" android:id="@+id/empty_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -56,7 +56,7 @@
tools:alpha="1" tools:alpha="1"
android:layout_marginEnd="50dp" android:layout_marginEnd="50dp"
android:background="@drawable/round_textview_background" android:background="@drawable/round_textview_background"
android:backgroundTint="@color/md_grey_800_50" android:backgroundTint="@color/md_grey_800_85"
android:padding="8dp" android:padding="8dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
app:layout_constraintEnd_toStartOf="@id/fast_scroller" app:layout_constraintEnd_toStartOf="@id/fast_scroller"

View File

@ -71,7 +71,7 @@
<color name="md_grey_50">#FAFAFA</color> <color name="md_grey_50">#FAFAFA</color>
<color name="md_grey_200">#CCCCCC</color> <color name="md_grey_200">#CCCCCC</color>
<color name="md_grey_800">#424242</color> <color name="md_grey_800">#424242</color>
<color name="md_grey_800_50">#CF424242</color> <color name="md_grey_800_85">#DF424242</color>
<color name="md_blue_A200_50">#80448AFF</color> <color name="md_blue_A200_50">#80448AFF</color>