Option to always show the current category in the title
This commit is contained in:
parent
cb2223d47a
commit
8700b6f0a3
@ -273,6 +273,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun groupLibraryBy() = flowPrefs.getInt("group_library_by", 0)
|
fun groupLibraryBy() = flowPrefs.getInt("group_library_by", 0)
|
||||||
|
|
||||||
|
fun showCategoryInTitle() = flowPrefs.getBoolean("category_in_title", false)
|
||||||
|
|
||||||
// Tutorial preferences
|
// Tutorial preferences
|
||||||
fun shownFilterTutorial() = flowPrefs.getBoolean("shown_filter_tutorial", false)
|
fun shownFilterTutorial() = flowPrefs.getBoolean("shown_filter_tutorial", false)
|
||||||
|
|
||||||
|
@ -85,6 +85,11 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
|
|||||||
}
|
}
|
||||||
show_all.bindToPreference(preferences.showAllCategories()) {
|
show_all.bindToPreference(preferences.showAllCategories()) {
|
||||||
controller.presenter.getLibrary()
|
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()) {
|
hide_hopper.bindToPreference(preferences.hideHopper()) {
|
||||||
controller.hideHopper(it)
|
controller.hideHopper(it)
|
||||||
|
@ -177,17 +177,22 @@ class LibraryController(
|
|||||||
private var isAnimatingHopper: Boolean? = null
|
private var isAnimatingHopper: Boolean? = null
|
||||||
var hasMovedHopper = preferences.shownHopperSwipeTutorial().get()
|
var hasMovedHopper = preferences.shownHopperSwipeTutorial().get()
|
||||||
private var shouldScrollToTop = false
|
private var shouldScrollToTop = false
|
||||||
|
private val showCategoryInTitle
|
||||||
|
get() = preferences.showCategoryInTitle().get() && presenter.showAllCategories
|
||||||
private lateinit var elevateAppBar: ((Boolean) -> Unit)
|
private lateinit var elevateAppBar: ((Boolean) -> Unit)
|
||||||
|
|
||||||
override fun getTitle(): String? {
|
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() {
|
private var scrollListener = object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
super.onScrolled(recyclerView, dx, dy)
|
super.onScrolled(recyclerView, dx, dy)
|
||||||
val recyclerCover = recycler_cover ?: return
|
val recyclerCover = recycler_cover ?: return
|
||||||
val order = getCategoryOrder()
|
|
||||||
if (!recyclerCover.isClickable && isAnimatingHopper != true) {
|
if (!recyclerCover.isClickable && isAnimatingHopper != true) {
|
||||||
category_hopper_frame.translationY += dy
|
category_hopper_frame.translationY += dy
|
||||||
category_hopper_frame.translationY =
|
category_hopper_frame.translationY =
|
||||||
@ -202,13 +207,11 @@ class LibraryController(
|
|||||||
scrollDistance = 0f
|
scrollDistance = 0f
|
||||||
}
|
}
|
||||||
} else scrollDistance = 0f
|
} else scrollDistance = 0f
|
||||||
if (order != null && order != activeCategory && lastItem == null) {
|
val currentCategory = getHeader()?.category ?: return
|
||||||
preferences.lastUsedCategory().set(order)
|
if (currentCategory.order != activeCategory) {
|
||||||
activeCategory = order
|
saveActiveCategory(currentCategory)
|
||||||
setActiveCategory()
|
if (!showCategoryInTitle && presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) {
|
||||||
if (presenter.categories.size > 1 && dy != 0 && recyclerView.translationY == 0f) {
|
showCategoryText(currentCategory.name)
|
||||||
val headerItem = getHeader() ?: return
|
|
||||||
showCategoryText(headerItem.category.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) {
|
fun showCategoryText(name: String) {
|
||||||
textAnim?.cancel()
|
textAnim?.cancel()
|
||||||
textAnim = jumper_category_text.animate().alpha(0f).setDuration(250L).setStartDelay(2000)
|
textAnim = jumper_category_text.animate().alpha(0f).setDuration(250L).setStartDelay(2000)
|
||||||
@ -316,7 +343,7 @@ class LibraryController(
|
|||||||
category_recycler.onCategoryClicked = {
|
category_recycler.onCategoryClicked = {
|
||||||
recycler.itemAnimator = null
|
recycler.itemAnimator = null
|
||||||
scrollToHeader(it)
|
scrollToHeader(it)
|
||||||
showCategories(show = false, scroll = false)
|
showCategories(show = false)
|
||||||
}
|
}
|
||||||
category_recycler.onShowAllClicked = { isChecked ->
|
category_recycler.onShowAllClicked = { isChecked ->
|
||||||
preferences.showAllCategories().set(isChecked)
|
preferences.showAllCategories().set(isChecked)
|
||||||
@ -378,6 +405,8 @@ class LibraryController(
|
|||||||
topMargin = recycler?.paddingTop ?: 0
|
topMargin = recycler?.paddingTop ?: 0
|
||||||
}
|
}
|
||||||
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
|
header_title?.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
|
||||||
|
}, onLeavingController = {
|
||||||
|
header_title?.gone()
|
||||||
})
|
})
|
||||||
|
|
||||||
swipe_refresh.setOnRefreshListener {
|
swipe_refresh.setOnRefreshListener {
|
||||||
@ -690,6 +719,11 @@ class LibraryController(
|
|||||||
if (justStarted && freshStart) {
|
if (justStarted && freshStart) {
|
||||||
scrollToHeader(activeCategory)
|
scrollToHeader(activeCategory)
|
||||||
}
|
}
|
||||||
|
recycler.post {
|
||||||
|
elevateAppBar(recycler.canScrollVertically(-1))
|
||||||
|
setActiveCategory()
|
||||||
|
}
|
||||||
|
|
||||||
category_hopper_frame.visibleIf(!singleCategory && !preferences.hideHopper().get())
|
category_hopper_frame.visibleIf(!singleCategory && !preferences.hideHopper().get())
|
||||||
filter_bottom_sheet.updateButtons(
|
filter_bottom_sheet.updateButtons(
|
||||||
showExpand = !singleCategory && presenter.showAllCategories, groupType = presenter.groupType
|
showExpand = !singleCategory && presenter.showAllCategories, groupType = presenter.groupType
|
||||||
@ -697,13 +731,13 @@ class LibraryController(
|
|||||||
adapter.isLongPressDragEnabled = canDrag()
|
adapter.isLongPressDragEnabled = canDrag()
|
||||||
category_recycler.setCategories(presenter.categories)
|
category_recycler.setCategories(presenter.categories)
|
||||||
filter_bottom_sheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty())
|
filter_bottom_sheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty())
|
||||||
setActiveCategory()
|
|
||||||
if (shouldScrollToTop) {
|
if (shouldScrollToTop) {
|
||||||
recycler.scrollToPosition(0)
|
recycler.scrollToPosition(0)
|
||||||
shouldScrollToTop = false
|
shouldScrollToTop = false
|
||||||
}
|
}
|
||||||
if (onRoot) {
|
if (onRoot) {
|
||||||
activity?.toolbar?.setOnClickListener {
|
listOf(activity?.toolbar, header_title).forEach {
|
||||||
|
it?.setOnClickListener {
|
||||||
val recycler = recycler ?: return@setOnClickListener
|
val recycler = recycler ?: return@setOnClickListener
|
||||||
if (singleCategory) {
|
if (singleCategory) {
|
||||||
recycler.scrollToPosition(0)
|
recycler.scrollToPosition(0)
|
||||||
@ -715,6 +749,9 @@ class LibraryController(
|
|||||||
showSlideAnimation()
|
showSlideAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
showMiniBar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showDropdown() {
|
private fun showDropdown() {
|
||||||
if (onRoot) {
|
if (onRoot) {
|
||||||
@ -750,7 +787,7 @@ class LibraryController(
|
|||||||
.setDuration(duration)
|
.setDuration(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showCategories(show: Boolean, scroll: Boolean = true) {
|
private fun showCategories(show: Boolean) {
|
||||||
recycler_cover.isClickable = show
|
recycler_cover.isClickable = show
|
||||||
recycler_cover.isFocusable = show
|
recycler_cover.isFocusable = show
|
||||||
val full = category_layout.height.toFloat() + recycler.paddingTop
|
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_cover.animate().alpha(if (show) 0.75f else 0f).start()
|
||||||
recycler.suppressLayout(show)
|
recycler.suppressLayout(show)
|
||||||
activity?.toolbar?.showDropdown(!show)
|
activity?.toolbar?.showDropdown(!show)
|
||||||
|
setTitle()
|
||||||
if (show) {
|
if (show) {
|
||||||
category_recycler.scrollToCategory(activeCategory)
|
category_recycler.scrollToCategory(activeCategory)
|
||||||
fast_scroller?.hideScrollbar()
|
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) {
|
private fun scrollToHeader(pos: Int) {
|
||||||
if (!presenter.showAllCategories) {
|
if (!presenter.showAllCategories) {
|
||||||
presenter.switchSection(pos)
|
presenter.switchSection(pos)
|
||||||
@ -803,6 +834,11 @@ class LibraryController(
|
|||||||
else -> (-30).dpToPx
|
else -> (-30).dpToPx
|
||||||
}) + appbarOffset
|
}) + appbarOffset
|
||||||
)
|
)
|
||||||
|
(adapter.getItem(headerPosition) as? LibraryHeaderItem)?.category?.let {
|
||||||
|
saveActiveCategory(it)
|
||||||
|
}
|
||||||
|
activeCategory = pos
|
||||||
|
preferences.lastUsedCategory().set(pos)
|
||||||
recycler.suppressLayout(false)
|
recycler.suppressLayout(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -984,7 +1020,6 @@ class LibraryController(
|
|||||||
val position = viewHolder?.adapterPosition ?: return
|
val position = viewHolder?.adapterPosition ?: return
|
||||||
swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_DRAG
|
swipe_refresh.isEnabled = actionState != ItemTouchHelper.ACTION_STATE_DRAG
|
||||||
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
|
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
|
||||||
activity?.appbar?.y = 0f
|
|
||||||
if (lastItemPosition != null && position != lastItemPosition && lastItem == adapter.getItem(
|
if (lastItemPosition != null && position != lastItemPosition && lastItem == adapter.getItem(
|
||||||
position
|
position
|
||||||
)
|
)
|
||||||
@ -1022,7 +1057,6 @@ class LibraryController(
|
|||||||
) {
|
) {
|
||||||
recycler.scrollBy(0, recycler.paddingTop)
|
recycler.scrollBy(0, recycler.paddingTop)
|
||||||
}
|
}
|
||||||
activity?.appbar?.y = 0f
|
|
||||||
if (lastItemPosition == toPosition) lastItemPosition = null
|
if (lastItemPosition == toPosition) lastItemPosition = null
|
||||||
else if (lastItemPosition == null) lastItemPosition = fromPosition
|
else if (lastItemPosition == null) lastItemPosition = fromPosition
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,8 @@ fun Controller.scrollViewWith(
|
|||||||
customPadding: Boolean = false,
|
customPadding: Boolean = false,
|
||||||
swipeRefreshLayout: SwipeRefreshLayout? = null,
|
swipeRefreshLayout: SwipeRefreshLayout? = null,
|
||||||
afterInsets: ((WindowInsets) -> Unit)? = null,
|
afterInsets: ((WindowInsets) -> Unit)? = null,
|
||||||
liftOnScroll: ((Boolean) -> Unit)? = null
|
liftOnScroll: ((Boolean) -> Unit)? = null,
|
||||||
|
onLeavingController: (() -> Unit)? = null
|
||||||
): ((Boolean) -> Unit) {
|
): ((Boolean) -> Unit) {
|
||||||
var statusBarHeight = -1
|
var statusBarHeight = -1
|
||||||
activity?.appbar?.y = 0f
|
activity?.appbar?.y = 0f
|
||||||
@ -119,7 +120,7 @@ fun Controller.scrollViewWith(
|
|||||||
if (changeType.isEnter) {
|
if (changeType.isEnter) {
|
||||||
elevateFunc(elevate)
|
elevateFunc(elevate)
|
||||||
if (fakeToolbarView?.parent != null) {
|
if (fakeToolbarView?.parent != null) {
|
||||||
val parent = recycler.parent as? ViewGroup ?: return
|
val parent = fakeToolbarView?.parent as? ViewGroup ?: return
|
||||||
parent.removeView(fakeToolbarView)
|
parent.removeView(fakeToolbarView)
|
||||||
fakeToolbarView = null
|
fakeToolbarView = null
|
||||||
}
|
}
|
||||||
@ -145,6 +146,7 @@ fun Controller.scrollViewWith(
|
|||||||
params?.width = MATCH_PARENT
|
params?.width = MATCH_PARENT
|
||||||
v.setBackgroundColor(v.context.getResourceColor(R.attr.colorSecondary))
|
v.setBackgroundColor(v.context.getResourceColor(R.attr.colorSecondary))
|
||||||
v.layoutParams = params
|
v.layoutParams = params
|
||||||
|
onLeavingController?.invoke()
|
||||||
}
|
}
|
||||||
elevationAnim?.cancel()
|
elevationAnim?.cancel()
|
||||||
if (activity!!.toolbar.tag == randomTag) activity!!.toolbar.setOnClickListener(null)
|
if (activity!!.toolbar.tag == randomTag) activity!!.toolbar.setOnClickListener(null)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:text="@string/display_as" />
|
android:text="@string/display" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -68,6 +68,14 @@
|
|||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:text="@string/show_all_categories" />
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
android:id="@+id/category_layout"
|
android:id="@+id/category_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="?actionBarSize"
|
android:layout_marginTop="?actionBarSize" >
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.ui.library.category.CategoryRecyclerView
|
<eu.kanade.tachiyomi.ui.library.category.CategoryRecyclerView
|
||||||
android:id="@+id/category_recycler"
|
android:id="@+id/category_recycler"
|
||||||
@ -69,6 +68,28 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:fastScrollerBubbleEnabled="true" />
|
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
|
<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"
|
||||||
|
@ -114,6 +114,7 @@
|
|||||||
library from the browse tab.</string>
|
library from the browse tab.</string>
|
||||||
<string name="no_matches_for_filters">No matches found for your current filters</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="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="expand_all_categories">Expand all categories</string>
|
||||||
<string name="collapse_all_categories">Collapse all categories</string>
|
<string name="collapse_all_categories">Collapse all categories</string>
|
||||||
<string name="reorder_filters">Reorder filters</string>
|
<string name="reorder_filters">Reorder filters</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user