Option to always show the current category in the title

This commit is contained in:
Jay 2020-05-19 01:40:05 -04:00
parent cb2223d47a
commit 8700b6f0a3
7 changed files with 107 additions and 34 deletions

View file

@ -273,6 +273,8 @@ class PreferencesHelper(val context: Context) {
fun groupLibraryBy() = flowPrefs.getInt("group_library_by", 0)
fun showCategoryInTitle() = flowPrefs.getBoolean("category_in_title", false)
// Tutorial preferences
fun shownFilterTutorial() = flowPrefs.getBoolean("shown_filter_tutorial", false)

View file

@ -85,6 +85,11 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
}
show_all.bindToPreference(preferences.showAllCategories()) {
controller.presenter.getLibrary()
category_show.isEnabled = it
}
category_show.isEnabled = show_all.isChecked
category_show.bindToPreference(preferences.showCategoryInTitle()) {
controller.showMiniBar()
}
hide_hopper.bindToPreference(preferences.hideHopper()) {
controller.hideHopper(it)

View file

@ -177,17 +177,22 @@ class LibraryController(
private var isAnimatingHopper: Boolean? = null
var hasMovedHopper = preferences.shownHopperSwipeTutorial().get()
private var shouldScrollToTop = false
private val showCategoryInTitle
get() = preferences.showCategoryInTitle().get() && presenter.showAllCategories
private lateinit var elevateAppBar: ((Boolean) -> Unit)
override fun getTitle(): String? {
return view?.context?.getString(R.string.library)
return if (!showCategoryInTitle || header_title.text.isNullOrBlank() || recycler_cover?.isClickable == true) {
view?.context?.getString(R.string.library)
} else {
header_title.text.toString()
}
}
private var scrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val recyclerCover = recycler_cover ?: return
val order = getCategoryOrder()
if (!recyclerCover.isClickable && isAnimatingHopper != true) {
category_hopper_frame.translationY += dy
category_hopper_frame.translationY =
@ -202,13 +207,11 @@ class LibraryController(
scrollDistance = 0f
}
} else scrollDistance = 0f
if (order != null && order != activeCategory && lastItem == null) {
preferences.lastUsedCategory().set(order)
activeCategory = order
setActiveCategory()
if (presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) {
val headerItem = getHeader() ?: return
showCategoryText(headerItem.category.name)
val currentCategory = getHeader()?.category ?: return
if (currentCategory.order != activeCategory) {
saveActiveCategory(currentCategory)
if (!showCategoryInTitle && presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) {
showCategoryText(currentCategory.name)
}
}
}
@ -235,6 +238,30 @@ class LibraryController(
}
}
fun saveActiveCategory(category: Category) {
preferences.lastUsedCategory().set(category.order)
activeCategory = category.order
val headerItem = getHeader() ?: return
header_title.text = headerItem.category.name
setActiveCategory()
}
private fun setActiveCategory() {
val currentCategory = presenter.categories.indexOfFirst {
if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id
}
if (currentCategory > -1) {
category_recycler.setCategories(currentCategory)
header_title.text = presenter.categories[currentCategory].name
setTitle()
}
}
fun showMiniBar() {
header_title.visibleIf(showCategoryInTitle)
setTitle()
}
fun showCategoryText(name: String) {
textAnim?.cancel()
textAnim = jumper_category_text.animate().alpha(0f).setDuration(250L).setStartDelay(2000)
@ -316,7 +343,7 @@ class LibraryController(
category_recycler.onCategoryClicked = {
recycler.itemAnimator = null
scrollToHeader(it)
showCategories(show = false, scroll = false)
showCategories(show = false)
}
category_recycler.onShowAllClicked = { isChecked ->
preferences.showAllCategories().set(isChecked)
@ -378,6 +405,8 @@ class LibraryController(
topMargin = recycler?.paddingTop ?: 0
}
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
}, onLeavingController = {
header_title?.gone()
})
swipe_refresh.setOnRefreshListener {
@ -690,6 +719,11 @@ class LibraryController(
if (justStarted && freshStart) {
scrollToHeader(activeCategory)
}
recycler.post {
elevateAppBar(recycler.canScrollVertically(-1))
setActiveCategory()
}
category_hopper_frame.visibleIf(!singleCategory && !preferences.hideHopper().get())
filter_bottom_sheet.updateButtons(
showExpand = !singleCategory && presenter.showAllCategories, groupType = presenter.groupType
@ -697,22 +731,25 @@ class LibraryController(
adapter.isLongPressDragEnabled = canDrag()
category_recycler.setCategories(presenter.categories)
filter_bottom_sheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty())
setActiveCategory()
if (shouldScrollToTop) {
recycler.scrollToPosition(0)
shouldScrollToTop = false
}
if (onRoot) {
activity?.toolbar?.setOnClickListener {
val recycler = recycler ?: return@setOnClickListener
if (singleCategory) {
recycler.scrollToPosition(0)
} else {
showCategories(recycler.translationY == 0f)
listOf(activity?.toolbar, header_title).forEach {
it?.setOnClickListener {
val recycler = recycler ?: return@setOnClickListener
if (singleCategory) {
recycler.scrollToPosition(0)
} else {
showCategories(recycler.translationY == 0f)
}
}
if (!hasMovedHopper && isAnimatingHopper == null) {
showSlideAnimation()
}
}
if (!hasMovedHopper && isAnimatingHopper == null) {
showSlideAnimation()
showMiniBar()
}
}
@ -750,7 +787,7 @@ class LibraryController(
.setDuration(duration)
}
private fun showCategories(show: Boolean, scroll: Boolean = true) {
private fun showCategories(show: Boolean) {
recycler_cover.isClickable = show
recycler_cover.isFocusable = show
val full = category_layout.height.toFloat() + recycler.paddingTop
@ -761,6 +798,7 @@ class LibraryController(
recycler_cover.animate().alpha(if (show) 0.75f else 0f).start()
recycler.suppressLayout(show)
activity?.toolbar?.showDropdown(!show)
setTitle()
if (show) {
category_recycler.scrollToCategory(activeCategory)
fast_scroller?.hideScrollbar()
@ -773,13 +811,6 @@ class LibraryController(
}
}
fun setActiveCategory() {
val currentCategory = presenter.categories.indexOfFirst {
if (presenter.showAllCategories) it.order == activeCategory else presenter.currentCategory == it.id
}
category_recycler.setCategories(currentCategory)
}
private fun scrollToHeader(pos: Int) {
if (!presenter.showAllCategories) {
presenter.switchSection(pos)
@ -803,6 +834,11 @@ class LibraryController(
else -> (-30).dpToPx
}) + appbarOffset
)
(adapter.getItem(headerPosition) as? LibraryHeaderItem)?.category?.let {
saveActiveCategory(it)
}
activeCategory = pos
preferences.lastUsedCategory().set(pos)
recycler.suppressLayout(false)
}
}
@ -984,7 +1020,6 @@ class LibraryController(
val position = viewHolder?.adapterPosition ?: return
swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_DRAG
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
activity?.appbar?.y = 0f
if (lastItemPosition != null && position != lastItemPosition && lastItem == adapter.getItem(
position
)
@ -1022,7 +1057,6 @@ class LibraryController(
) {
recycler.scrollBy(0, recycler.paddingTop)
}
activity?.appbar?.y = 0f
if (lastItemPosition == toPosition) lastItemPosition = null
else if (lastItemPosition == null) lastItemPosition = fromPosition
}

View file

@ -61,7 +61,8 @@ fun Controller.scrollViewWith(
customPadding: Boolean = false,
swipeRefreshLayout: SwipeRefreshLayout? = null,
afterInsets: ((WindowInsets) -> Unit)? = null,
liftOnScroll: ((Boolean) -> Unit)? = null
liftOnScroll: ((Boolean) -> Unit)? = null,
onLeavingController: (() -> Unit)? = null
): ((Boolean) -> Unit) {
var statusBarHeight = -1
activity?.appbar?.y = 0f
@ -119,7 +120,7 @@ fun Controller.scrollViewWith(
if (changeType.isEnter) {
elevateFunc(elevate)
if (fakeToolbarView?.parent != null) {
val parent = recycler.parent as? ViewGroup ?: return
val parent = fakeToolbarView?.parent as? ViewGroup ?: return
parent.removeView(fakeToolbarView)
fakeToolbarView = null
}
@ -145,6 +146,7 @@ fun Controller.scrollViewWith(
params?.width = MATCH_PARENT
v.setBackgroundColor(v.context.getResourceColor(R.attr.colorSecondary))
v.layoutParams = params
onLeavingController?.invoke()
}
elevationAnim?.cancel()
if (activity!!.toolbar.tag == randomTag) activity!!.toolbar.setOnClickListener(null)

View file

@ -27,7 +27,7 @@
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="12dp"
android:text="@string/display_as" />
android:text="@string/display" />
<LinearLayout
android:layout_width="match_parent"
@ -68,6 +68,14 @@
android:layout_marginEnd="12dp"
android:text="@string/show_all_categories" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/category_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/always_show_current_category" />
</LinearLayout>
<com.google.android.material.textview.MaterialTextView

View file

@ -26,8 +26,7 @@
android:id="@+id/category_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?actionBarSize"
android:orientation="vertical">
android:layout_marginTop="?actionBarSize" >
<eu.kanade.tachiyomi.ui.library.category.CategoryRecyclerView
android:id="@+id/category_recycler"
@ -69,6 +68,28 @@
android:layout_height="match_parent"
app:fastScrollerBubbleEnabled="true" />
<TextView
android:id="@+id/header_title"
style="@style/TextAppearance.MaterialComponents.Headline6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:background="@drawable/list_item_selector"
android:backgroundTint="?colorSecondary"
android:clickable="true"
android:elevation="5dp"
android:ellipsize="end"
android:focusable="true"
android:gravity="center"
android:inputType="none"
android:maxLines="1"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="6dp"
android:textColor="?actionBarTintColor"
android:textSize="14sp"
tools:text="Category" />
<eu.kanade.tachiyomi.widget.EmptyView
android:id="@+id/empty_view"
android:layout_width="wrap_content"

View file

@ -114,6 +114,7 @@
library from the browse tab.</string>
<string name="no_matches_for_filters">No matches found for your current filters</string>
<string name="show_all_categories">Show all categories</string>
<string name="always_show_current_category">Always show current category</string>
<string name="expand_all_categories">Expand all categories</string>
<string name="collapse_all_categories">Collapse all categories</string>
<string name="reorder_filters">Reorder filters</string>