Binding for everything in library but activity

This commit is contained in:
Jays2Kings 2021-03-28 21:41:22 -04:00
parent ccb7dbb714
commit 63c8775854
3 changed files with 116 additions and 114 deletions

View File

@ -96,13 +96,7 @@ import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.view.visibleIf import eu.kanade.tachiyomi.util.view.visibleIf
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import eu.kanade.tachiyomi.widget.EndAnimatorListener import eu.kanade.tachiyomi.widget.EndAnimatorListener
import kotlinx.android.synthetic.main.filter_bottom_sheet.*
import kotlinx.android.synthetic.main.filter_bottom_sheet.view.*
import kotlinx.android.synthetic.main.library_grid_recycler.*
import kotlinx.android.synthetic.main.library_grid_recycler.recycler
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.android.synthetic.main.rounded_category_hopper.*
import kotlinx.android.synthetic.main.source_controller.*
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -224,13 +218,13 @@ class LibraryController(
if (!preferences.hideBottomNavOnScroll().get()) { if (!preferences.hideBottomNavOnScroll().get()) {
updateFilterSheetY() updateFilterSheetY()
} }
up_category.alpha = if (isAtTop()) 0.25f else 1f binding.roundedCategoryHopper.upCategory.alpha = if (isAtTop()) 0.25f else 1f
down_category.alpha = if (isAtBottom()) 0.25f else 1f binding.roundedCategoryHopper.downCategory.alpha = if (isAtBottom()) 0.25f else 1f
} }
if (!filter_bottom_sheet.sheetBehavior.isHidden()) { if (!binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
scrollDistance += abs(dy) scrollDistance += abs(dy)
if (scrollDistance > scrollDistanceTilHidden) { if (scrollDistance > scrollDistanceTilHidden) {
filter_bottom_sheet.sheetBehavior?.hide() binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
scrollDistance = 0f scrollDistance = 0f
} }
} else scrollDistance = 0f } else scrollDistance = 0f
@ -263,17 +257,16 @@ class LibraryController(
fun updateFilterSheetY() { fun updateFilterSheetY() {
val bottomBar = activity?.bottom_nav val bottomBar = activity?.bottom_nav
filter_bottom_sheet ?: return
if (bottomBar != null) { if (bottomBar != null) {
if (filter_bottom_sheet.sheetBehavior.isHidden()) { if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
val pad = bottomBar.translationY - bottomBar.height val pad = bottomBar.translationY - bottomBar.height
filter_bottom_sheet.translationY = pad binding.filterBottomSheet.filterBottomSheet.translationY = pad
} else { } else {
filter_bottom_sheet.translationY = 0f binding.filterBottomSheet.filterBottomSheet.translationY = 0f
} }
val pad = bottomBar.translationY - bottomBar.height val pad = bottomBar.translationY - bottomBar.height
shadow2.translationY = pad binding.shadow2.translationY = pad
filter_bottom_sheet.updatePaddingRelative( binding.filterBottomSheet.filterBottomSheet.updatePaddingRelative(
bottom = max( bottom = max(
(-pad).toInt(), (-pad).toInt(),
view?.rootWindowInsets?.getBottomGestureInsets() ?: 0 view?.rootWindowInsets?.getBottomGestureInsets() ?: 0
@ -284,7 +277,7 @@ class LibraryController(
(-pad).toInt(), (-pad).toInt(),
view?.rootWindowInsets?.getBottomGestureInsets() ?: 0 view?.rootWindowInsets?.getBottomGestureInsets() ?: 0
) )
filter_bottom_sheet.sheetBehavior?.peekHeight = 60.dpToPx + padding binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.peekHeight = 60.dpToPx + padding
updateHopperY() updateHopperY()
binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = -pad.toInt() bottomMargin = -pad.toInt()
@ -301,7 +294,7 @@ class LibraryController(
val closerToHopperBottom = hopperOffset > 25f.dpToPx val closerToHopperBottom = hopperOffset > 25f.dpToPx
val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2 val halfWayBottom = activity!!.bottom_nav.height.toFloat() / 2
val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom val closerToBottom = activity!!.bottom_nav.translationY > halfWayBottom
val atTop = !recycler.canScrollVertically(-1) val atTop = !binding.libraryGridRecycler.recycler.canScrollVertically(-1)
val closerToEdge = if (preferences.hideBottomNavOnScroll().get()) (closerToBottom && !atTop) else closerToHopperBottom val closerToEdge = if (preferences.hideBottomNavOnScroll().get()) (closerToBottom && !atTop) else closerToHopperBottom
val end = if (closerToEdge) 55f.dpToPx else 0f val end = if (closerToEdge) 55f.dpToPx else 0f
val alphaAnimation = ValueAnimator.ofFloat(hopperOffset, end) val alphaAnimation = ValueAnimator.ofFloat(hopperOffset, end)
@ -353,7 +346,7 @@ class LibraryController(
fun isAtTop(): Boolean { fun isAtTop(): Boolean {
return if (presenter.showAllCategories) { return if (presenter.showAllCategories) {
!recycler.canScrollVertically(-1) !binding.libraryGridRecycler.recycler.canScrollVertically(-1)
} else { } else {
getVisibleHeader()?.category?.order == presenter.categories.minOfOrNull { it.order } getVisibleHeader()?.category?.order == presenter.categories.minOfOrNull { it.order }
} }
@ -361,7 +354,7 @@ class LibraryController(
fun isAtBottom(): Boolean { fun isAtBottom(): Boolean {
return if (presenter.showAllCategories) { return if (presenter.showAllCategories) {
!recycler.canScrollVertically(1) !binding.libraryGridRecycler.recycler.canScrollVertically(1)
} else { } else {
getVisibleHeader()?.category?.order == presenter.categories.maxOfOrNull { it.order } getVisibleHeader()?.category?.order == presenter.categories.maxOfOrNull { it.order }
} }
@ -396,24 +389,24 @@ class LibraryController(
adapter = LibraryCategoryAdapter(this) adapter = LibraryCategoryAdapter(this)
setRecyclerLayout() setRecyclerLayout()
recycler.manager.spanSizeLookup = ( binding.libraryGridRecycler.recycler.manager.spanSizeLookup = (
object : GridLayoutManager.SpanSizeLookup() { object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int { override fun getSpanSize(position: Int): Int {
if (libraryLayout == 0) return 1 if (libraryLayout == 0) return 1
val item = this@LibraryController.adapter.getItem(position) val item = this@LibraryController.adapter.getItem(position)
return if (item is LibraryHeaderItem || item is SearchGlobalItem || (item is LibraryItem && item.manga.isBlank())) { return if (item is LibraryHeaderItem || item is SearchGlobalItem || (item is LibraryItem && item.manga.isBlank())) {
recycler?.manager?.spanCount ?: 1 binding.libraryGridRecycler.recycler.manager.spanCount
} else { } else {
1 1
} }
} }
} }
) )
recycler.setHasFixedSize(true) binding.libraryGridRecycler.recycler.setHasFixedSize(true)
recycler.adapter = adapter binding.libraryGridRecycler.recycler.adapter = adapter
adapter.fastScroller = binding.fastScroller adapter.fastScroller = binding.fastScroller
recycler.addOnScrollListener(scrollListener) binding.libraryGridRecycler.recycler.addOnScrollListener(scrollListener)
binding.swipeRefresh.setStyle() binding.swipeRefresh.setStyle()
@ -421,7 +414,7 @@ class LibraryController(
showCategories(false) showCategories(false)
} }
binding.categoryRecycler.onCategoryClicked = { binding.categoryRecycler.onCategoryClicked = {
recycler.itemAnimator = null binding.libraryGridRecycler.recycler.itemAnimator = null
scrollToHeader(it) scrollToHeader(it)
showCategories(show = false) showCategories(show = false)
} }
@ -434,14 +427,14 @@ class LibraryController(
elevateAppBar = elevateAppBar =
scrollViewWith( scrollViewWith(
recycler, binding.libraryGridRecycler.recycler,
swipeRefreshLayout = binding.swipeRefresh, swipeRefreshLayout = binding.swipeRefresh,
afterInsets = { insets -> afterInsets = { insets ->
binding.categoryRecycler.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.categoryRecycler.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = recycler?.paddingTop ?: 0 topMargin = binding.libraryGridRecycler.recycler.paddingTop
} }
binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = recycler?.paddingTop ?: 0 topMargin = binding.libraryGridRecycler.recycler.paddingTop
} }
binding.headerTitle.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx) binding.headerTitle.updatePaddingRelative(top = insets.systemWindowInsetTop + 2.dpToPx)
}, },
@ -511,9 +504,9 @@ class LibraryController(
} }
private fun setupFilterSheet() { private fun setupFilterSheet() {
filter_bottom_sheet.onCreate(this) binding.filterBottomSheet.filterBottomSheet.onCreate(this)
filter_bottom_sheet.onGroupClicked = { binding.filterBottomSheet.filterBottomSheet.onGroupClicked = {
when (it) { when (it) {
FilterBottomSheet.ACTION_REFRESH -> onRefresh() FilterBottomSheet.ACTION_REFRESH -> onRefresh()
FilterBottomSheet.ACTION_FILTER -> onFilterChanged() FilterBottomSheet.ACTION_FILTER -> onFilterChanged()
@ -558,21 +551,21 @@ class LibraryController(
@SuppressLint("RtlHardcoded", "ClickableViewAccessibility") @SuppressLint("RtlHardcoded", "ClickableViewAccessibility")
private fun setUpHopper() { private fun setUpHopper() {
binding.categoryHopperFrame.gone() binding.categoryHopperFrame.gone()
down_category.setOnClickListener { binding.roundedCategoryHopper.downCategory.setOnClickListener {
jumpToNextCategory(true) jumpToNextCategory(true)
} }
up_category.setOnClickListener { binding.roundedCategoryHopper.upCategory.setOnClickListener {
jumpToNextCategory(false) jumpToNextCategory(false)
} }
down_category.setOnLongClickListener { binding.roundedCategoryHopper.downCategory.setOnLongClickListener {
recycler.scrollToPosition(adapter.itemCount - 1) binding.libraryGridRecycler.recycler.scrollToPosition(adapter.itemCount - 1)
true true
} }
up_category.setOnLongClickListener { binding.roundedCategoryHopper.upCategory.setOnLongClickListener {
recycler.scrollToPosition(0) binding.libraryGridRecycler.recycler.scrollToPosition(0)
true true
} }
category_button.setOnClickListener { binding.roundedCategoryHopper.categoryButton.setOnClickListener {
val items = presenter.categories.map { category -> val items = presenter.categories.map { category ->
MaterialMenuSheet.MenuSheetItem(category.order, text = category.name) MaterialMenuSheet.MenuSheetItem(category.order, text = category.name)
} }
@ -588,7 +581,7 @@ class LibraryController(
}.show() }.show()
} }
category_button.setOnLongClickListener { binding.roundedCategoryHopper.categoryButton.setOnLongClickListener {
activity?.toolbar?.menu?.performIdentifierAction(R.id.action_search, 0) activity?.toolbar?.menu?.performIdentifierAction(R.id.action_search, 0)
true true
} }
@ -609,19 +602,22 @@ class LibraryController(
hopperGravity = gravityPref hopperGravity = gravityPref
val gestureDetector = GestureDetectorCompat(activity, LibraryGestureDetector(this)) val gestureDetector = GestureDetectorCompat(activity, LibraryGestureDetector(this))
listOf(category_hopper_layout, up_category, down_category, category_button).forEach { with(binding.roundedCategoryHopper) {
it.setOnTouchListener { _, event -> listOf(categoryHopperLayout, upCategory, downCategory, categoryButton).forEach {
if (event?.action == MotionEvent.ACTION_DOWN) { it.setOnTouchListener { _, event ->
animatorSet?.end() if (event?.action == MotionEvent.ACTION_DOWN) {
} animatorSet?.end()
if (event?.action == MotionEvent.ACTION_UP) { }
val result = gestureDetector.onTouchEvent(event) if (event?.action == MotionEvent.ACTION_UP) {
if (!result) { val result = gestureDetector.onTouchEvent(event)
binding.categoryHopperFrame.animate().setDuration(150L).translationX(0f).start() if (!result) {
binding.categoryHopperFrame.animate().setDuration(150L).translationX(0f)
.start()
}
result
} else {
gestureDetector.onTouchEvent(event)
} }
result
} else {
gestureDetector.onTouchEvent(event)
} }
} }
} }
@ -630,21 +626,23 @@ class LibraryController(
fun updateHopperY() { fun updateHopperY() {
val view = view ?: return val view = view ?: return
val listOfYs = mutableListOf( val listOfYs = mutableListOf(
filter_bottom_sheet.y, binding.filterBottomSheet.filterBottomSheet.y,
activity?.bottom_nav?.y ?: filter_bottom_sheet.y activity?.bottom_nav?.y ?: binding.filterBottomSheet.filterBottomSheet.y
) )
val insetBottom = view.rootWindowInsets?.systemWindowInsetBottom ?: 0 val insetBottom = view.rootWindowInsets?.systemWindowInsetBottom ?: 0
if (!preferences.autohideHopper().get()) { if (!preferences.autohideHopper().get()) {
listOfYs.add(view.height - (insetBottom).toFloat()) listOfYs.add(view.height - (insetBottom).toFloat())
} }
binding.categoryHopperFrame.y = -binding.categoryHopperFrame.height + binding.categoryHopperFrame.y = -binding.categoryHopperFrame.height +
(listOfYs.minOrNull() ?: filter_bottom_sheet.y) + (listOfYs.minOrNull() ?: binding.filterBottomSheet.filterBottomSheet.y) +
hopperOffset + hopperOffset +
recycler.translationY binding.libraryGridRecycler.recycler.translationY
if (view.height - insetBottom < binding.categoryHopperFrame.y) { if (view.height - insetBottom < binding.categoryHopperFrame.y) {
binding.jumperCategoryText.translationY = -(binding.categoryHopperFrame.y - (view.height - insetBottom)) + recycler.translationY binding.jumperCategoryText.translationY =
-(binding.categoryHopperFrame.y - (view.height - insetBottom))
+binding.libraryGridRecycler.recycler.translationY
} else { } else {
binding.jumperCategoryText.translationY = recycler.translationY binding.jumperCategoryText.translationY = binding.libraryGridRecycler.recycler.translationY
} }
} }
@ -662,7 +660,7 @@ class LibraryController(
if (presenter.showAllCategories) { if (presenter.showAllCategories) {
if (!next) { if (!next) {
val fPosition = val fPosition =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
if (fPosition != adapter.currentItems.indexOf(category)) { if (fPosition != adapter.currentItems.indexOf(category)) {
scrollToHeader(category.category.order) scrollToHeader(category.category.order)
return return
@ -675,7 +673,7 @@ class LibraryController(
scrollToHeader(newOrder) scrollToHeader(newOrder)
showCategoryText(newCategory.name) showCategoryText(newCategory.name)
} else { } else {
recycler.scrollToPosition(if (next) adapter.itemCount - 1 else 0) binding.libraryGridRecycler.recycler.scrollToPosition(if (next) adapter.itemCount - 1 else 0)
} }
} else { } else {
val newOffset = val newOffset =
@ -697,7 +695,7 @@ class LibraryController(
private fun getHeader(firstCompletelyVisible: Boolean = false): LibraryHeaderItem? { private fun getHeader(firstCompletelyVisible: Boolean = false): LibraryHeaderItem? {
val position = if (firstCompletelyVisible) { val position = if (firstCompletelyVisible) {
(recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
} else { } else {
-1 -1
} }
@ -708,7 +706,7 @@ class LibraryController(
} }
} else { } else {
val fPosition = val fPosition =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
when (val item = adapter.getItem(fPosition)) { when (val item = adapter.getItem(fPosition)) {
is LibraryHeaderItem -> return item is LibraryHeaderItem -> return item
is LibraryItem -> return item.header is LibraryItem -> return item.header
@ -719,7 +717,7 @@ class LibraryController(
private fun getVisibleHeader(): LibraryHeaderItem? { private fun getVisibleHeader(): LibraryHeaderItem? {
val fPosition = val fPosition =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
when (val item = adapter.getItem(fPosition)) { when (val item = adapter.getItem(fPosition)) {
is LibraryHeaderItem -> return item is LibraryHeaderItem -> return item
is LibraryItem -> return item.header is LibraryItem -> return item.header
@ -736,7 +734,7 @@ class LibraryController(
return if (binding.categoryHopperFrame.isVisible()) { return if (binding.categoryHopperFrame.isVisible()) {
binding.categoryHopperFrame binding.categoryHopperFrame
} else { } else {
filter_bottom_sheet binding.filterBottomSheet.filterBottomSheet
} }
} }
@ -754,24 +752,24 @@ class LibraryController(
} }
private fun setRecyclerLayout() { private fun setRecyclerLayout() {
recycler.post { binding.libraryGridRecycler.recycler.post {
recycler?.updatePaddingRelative(bottom = 50.dpToPx + (activity?.bottom_nav?.height ?: 0)) binding.libraryGridRecycler.recycler.updatePaddingRelative(bottom = 50.dpToPx + (activity?.bottom_nav?.height ?: 0))
} }
if (libraryLayout == 0) { if (libraryLayout == 0) {
recycler.spanCount = 1 binding.libraryGridRecycler.recycler.spanCount = 1
recycler.updatePaddingRelative( binding.libraryGridRecycler.recycler.updatePaddingRelative(
start = 0, start = 0,
end = 0 end = 0
) )
} else { } else {
recycler.columnWidth = when (preferences.gridSize().getOrDefault()) { binding.libraryGridRecycler.recycler.columnWidth = when (preferences.gridSize().getOrDefault()) {
1 -> 1f 1 -> 1f
2 -> 1.25f 2 -> 1.25f
3 -> 1.66f 3 -> 1.66f
4 -> 3f 4 -> 3f
else -> .75f else -> .75f
} }
recycler.updatePaddingRelative( binding.libraryGridRecycler.recycler.updatePaddingRelative(
start = 5.dpToPx, start = 5.dpToPx,
end = 5.dpToPx end = 5.dpToPx
) )
@ -781,7 +779,7 @@ class LibraryController(
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type) super.onChangeStarted(handler, type)
if (type.isEnter) { if (type.isEnter) {
filter_bottom_sheet.visible() binding.filterBottomSheet.filterBottomSheet.visible()
presenter.getLibrary() presenter.getLibrary()
DownloadService.callListeners() DownloadService.callListeners()
LibraryUpdateService.setListener(this) LibraryUpdateService.setListener(this)
@ -791,8 +789,8 @@ class LibraryController(
} else { } else {
updateFilterSheetY() updateFilterSheetY()
closeTip() closeTip()
if (filter_bottom_sheet.sheetBehavior.isHidden()) { if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden()) {
filter_bottom_sheet.invisible() binding.filterBottomSheet.filterBottomSheet.invisible()
} }
activity?.toolbar?.hideDropdown() activity?.toolbar?.hideDropdown()
} }
@ -827,7 +825,7 @@ class LibraryController(
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
LibraryUpdateService.removeListener(this) LibraryUpdateService.removeListener(this)
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
recycler.removeOnScrollListener(scrollListener) binding.libraryGridRecycler.recycler.removeOnScrollListener(scrollListener)
super.onDestroyView(view) super.onDestroyView(view)
} }
@ -839,14 +837,14 @@ class LibraryController(
} else { } else {
binding.emptyView.show( binding.emptyView.show(
R.drawable.ic_heart_off_24dp, R.drawable.ic_heart_off_24dp,
if (filter_bottom_sheet.hasActiveFilters()) R.string.no_matches_for_filters if (binding.filterBottomSheet.filterBottomSheet.hasActiveFilters()) R.string.no_matches_for_filters
else R.string.library_is_empty_add_from_browse else R.string.library_is_empty_add_from_browse
) )
} }
adapter.setItems(mangaMap) adapter.setItems(mangaMap)
if (recycler.itemAnimator == null) { if (binding.libraryGridRecycler.recycler.itemAnimator == null) {
recycler.post { binding.libraryGridRecycler.recycler.post {
recycler?.itemAnimator = DefaultItemAnimator() binding.libraryGridRecycler.recycler.itemAnimator = DefaultItemAnimator()
} }
} }
singleCategory = presenter.categories.size <= 1 singleCategory = presenter.categories.size <= 1
@ -860,27 +858,27 @@ class LibraryController(
if (justStarted && freshStart) { if (justStarted && freshStart) {
scrollToHeader(activeCategory) scrollToHeader(activeCategory)
} }
recycler?.post { binding.libraryGridRecycler.recycler.post {
elevateAppBar(recycler?.canScrollVertically(-1) == true) elevateAppBar(binding.libraryGridRecycler.recycler.canScrollVertically(-1) == true)
setActiveCategory() setActiveCategory()
} }
binding.categoryHopperFrame.visibleIf(!singleCategory && !preferences.hideHopper().get()) binding.categoryHopperFrame.visibleIf(!singleCategory && !preferences.hideHopper().get())
filter_bottom_sheet.updateButtons( binding.filterBottomSheet.filterBottomSheet.updateButtons(
showExpand = !singleCategory && presenter.showAllCategories, showExpand = !singleCategory && presenter.showAllCategories,
groupType = presenter.groupType groupType = presenter.groupType
) )
adapter.isLongPressDragEnabled = canDrag() adapter.isLongPressDragEnabled = canDrag()
binding.categoryRecycler.setCategories(presenter.categories) binding.categoryRecycler.setCategories(presenter.categories)
filter_bottom_sheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty()) binding.filterBottomSheet.filterBottomSheet.setExpandText(preferences.collapsedCategories().getOrDefault().isNotEmpty())
if (shouldScrollToTop) { if (shouldScrollToTop) {
recycler.scrollToPosition(0) binding.libraryGridRecycler.recycler.scrollToPosition(0)
shouldScrollToTop = false shouldScrollToTop = false
} }
if (onRoot) { if (onRoot) {
listOf(activity?.toolbar, binding.headerTitle).forEach { listOf(activity?.toolbar, binding.headerTitle).forEach {
it?.setOnClickListener { it?.setOnClickListener {
val recycler = recycler ?: return@setOnClickListener val recycler = binding.libraryGridRecycler.recycler
if (singleCategory) { if (singleCategory) {
recycler.scrollToPosition(0) recycler.scrollToPosition(0)
} else { } else {
@ -937,9 +935,9 @@ class LibraryController(
private fun showCategories(show: Boolean) { private fun showCategories(show: Boolean) {
binding.recyclerCover.isClickable = show binding.recyclerCover.isClickable = show
binding.recyclerCover.isFocusable = show binding.recyclerCover.isFocusable = show
val full = binding.categoryRecycler.height.toFloat() + recycler.paddingTop val full = binding.categoryRecycler.height.toFloat() + binding.libraryGridRecycler.recycler.paddingTop
val translateY = if (show) full else 0f val translateY = if (show) full else 0f
recycler.animate().translationY(translateY).apply { binding.libraryGridRecycler.recycler.animate().translationY(translateY).apply {
setUpdateListener { setUpdateListener {
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
updateHopperY() updateHopperY()
@ -948,7 +946,7 @@ class LibraryController(
binding.recyclerShadow.animate().translationY(translateY - 8.dpToPx).start() binding.recyclerShadow.animate().translationY(translateY - 8.dpToPx).start()
binding.recyclerCover.animate().translationY(translateY).start() binding.recyclerCover.animate().translationY(translateY).start()
binding.recyclerCover.animate().alpha(if (show) 0.75f else 0f).start() binding.recyclerCover.animate().alpha(if (show) 0.75f else 0f).start()
recycler.suppressLayout(show) binding.libraryGridRecycler.recycler.suppressLayout(show)
activity?.toolbar?.showDropdown(!show) activity?.toolbar?.showDropdown(!show)
binding.swipeRefresh.isEnabled = !show binding.swipeRefresh.isEnabled = !show
setTitle() setTitle()
@ -957,9 +955,9 @@ class LibraryController(
binding.fastScroller.hideScrollbar() binding.fastScroller.hideScrollbar()
activity?.appbar?.y = 0f activity?.appbar?.y = 0f
elevateAppBar(false) elevateAppBar(false)
filter_bottom_sheet?.sheetBehavior?.hide() binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
} else { } else {
val notAtTop = recycler.canScrollVertically(-1) val notAtTop = binding.libraryGridRecycler.recycler.canScrollVertically(-1)
elevateAppBar(notAtTop) elevateAppBar(notAtTop)
} }
} }
@ -975,14 +973,14 @@ class LibraryController(
val headerPosition = adapter.indexOf(pos) val headerPosition = adapter.indexOf(pos)
if (headerPosition > -1) { if (headerPosition > -1) {
val appbar = activity?.appbar val appbar = activity?.appbar
recycler.suppressLayout(true) binding.libraryGridRecycler.recycler.suppressLayout(true)
val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else ( val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else (
appbar?.y?.plus( appbar?.y?.plus(
view?.rootWindowInsets?.systemWindowInsetTop ?: 0 view?.rootWindowInsets?.systemWindowInsetTop ?: 0
) ?: 0f ) ?: 0f
).roundToInt() + 30.dpToPx ).roundToInt() + 30.dpToPx
val previousHeader = adapter.getItem(adapter.indexOf(pos - 1)) as? LibraryHeaderItem val previousHeader = adapter.getItem(adapter.indexOf(pos - 1)) as? LibraryHeaderItem
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
headerPosition, headerPosition,
( (
when { when {
@ -997,7 +995,7 @@ class LibraryController(
} }
activeCategory = pos activeCategory = pos
preferences.lastUsedCategory().set(pos) preferences.lastUsedCategory().set(pos)
recycler.suppressLayout(false) binding.libraryGridRecycler.recycler.suppressLayout(false)
} }
} }
@ -1021,10 +1019,10 @@ class LibraryController(
libraryLayout = preferences.libraryLayout().getOrDefault() libraryLayout = preferences.libraryLayout().getOrDefault()
setRecyclerLayout() setRecyclerLayout()
val position = val position =
(recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
recycler.adapter = adapter binding.libraryGridRecycler.recycler.adapter = adapter
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0) (binding.libraryGridRecycler.recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0)
} }
fun search(query: String?): Boolean { fun search(query: String?): Boolean {
@ -1034,7 +1032,7 @@ class LibraryController(
adapter.addScrollableHeader(searchItem) adapter.addScrollableHeader(searchItem)
} else if (this.query.isNotBlank()) { } else if (this.query.isNotBlank()) {
searchItem.string = this.query searchItem.string = this.query
(recycler.findViewHolderForAdapterPosition(0) as? SearchGlobalItem.Holder)?.bind(this.query) (binding.libraryGridRecycler.recycler.findViewHolderForAdapterPosition(0) as? SearchGlobalItem.Holder)?.bind(this.query)
} else if (this.query.isBlank() && adapter.scrollableHeaders.isNotEmpty()) { } else if (this.query.isBlank() && adapter.scrollableHeaders.isNotEmpty()) {
adapter.removeAllScrollableHeaders() adapter.removeAllScrollableHeaders()
} }
@ -1068,7 +1066,7 @@ class LibraryController(
} }
positions.forEach { position -> positions.forEach { position ->
adapter.addSelection(position) adapter.addSelection(position)
(recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation() (binding.libraryGridRecycler.recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation()
} }
} }
} else { } else {
@ -1081,7 +1079,7 @@ class LibraryController(
} }
positions.forEach { position -> positions.forEach { position ->
adapter.removeSelection(position) adapter.removeSelection(position)
(recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation() (binding.libraryGridRecycler.recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation()
} }
} }
} }
@ -1094,7 +1092,7 @@ class LibraryController(
if (changedMode) { if (changedMode) {
adapter.notifyItemChanged(it) adapter.notifyItemChanged(it)
} else { } else {
(recycler.findViewHolderForAdapterPosition(it) as? LibraryHeaderHolder)?.setSelection() (binding.libraryGridRecycler.recycler.findViewHolderForAdapterPosition(it) as? LibraryHeaderHolder)?.setSelection()
} }
} }
} }
@ -1120,8 +1118,7 @@ class LibraryController(
} }
override fun canDrag(): Boolean { override fun canDrag(): Boolean {
filter_bottom_sheet ?: return false val filterOff = !binding.filterBottomSheet.filterBottomSheet.hasActiveFilters() && presenter.groupType == BY_DEFAULT
val filterOff = !filter_bottom_sheet.hasActiveFilters() && presenter.groupType == BY_DEFAULT
return filterOff && adapter.mode != SelectableAdapter.Mode.MULTI return filterOff && adapter.mode != SelectableAdapter.Mode.MULTI
} }
@ -1184,7 +1181,7 @@ class LibraryController(
) { ) {
// because for whatever reason you can repeatedly tap on a currently dragging manga // because for whatever reason you can repeatedly tap on a currently dragging manga
adapter.removeSelection(position) adapter.removeSelection(position)
(recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation() (binding.libraryGridRecycler.recycler.findViewHolderForAdapterPosition(position) as? LibraryHolder)?.toggleActivation()
adapter.moveItem(position, lastItemPosition!!) adapter.moveItem(position, lastItemPosition!!)
} else { } else {
lastItem = adapter.getItem(position) lastItem = adapter.getItem(position)
@ -1214,7 +1211,7 @@ class LibraryController(
) || ) ||
adapter.getItem(fromPosition) == null adapter.getItem(fromPosition) == null
) { ) {
recycler.scrollBy(0, recycler.paddingTop) binding.libraryGridRecycler.recycler.scrollBy(0, binding.libraryGridRecycler.recycler.paddingTop)
} }
if (lastItemPosition == toPosition) lastItemPosition = null if (lastItemPosition == toPosition) lastItemPosition = null
else if (lastItemPosition == null) lastItemPosition = fromPosition else if (lastItemPosition == null) lastItemPosition = fromPosition
@ -1362,8 +1359,8 @@ class LibraryController(
override fun showSheet() { override fun showSheet() {
closeTip() closeTip()
when { when {
filter_bottom_sheet.sheetBehavior.isHidden() -> filter_bottom_sheet.sheetBehavior?.collapse() binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.collapse()
!filter_bottom_sheet.sheetBehavior.isExpanded() -> filter_bottom_sheet.sheetBehavior?.expand() !binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isExpanded() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.expand()
else -> TabbedLibraryDisplaySheet(this).show() else -> TabbedLibraryDisplaySheet(this).show()
} }
} }
@ -1371,9 +1368,9 @@ class LibraryController(
override fun toggleSheet() { override fun toggleSheet() {
closeTip() closeTip()
when { when {
filter_bottom_sheet.sheetBehavior.isHidden() -> filter_bottom_sheet.sheetBehavior?.collapse() binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isHidden() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.collapse()
!filter_bottom_sheet.sheetBehavior.isExpanded() -> filter_bottom_sheet.sheetBehavior?.expand() !binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isExpanded() -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.expand()
else -> filter_bottom_sheet.sheetBehavior?.hide() else -> binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
} }
} }
@ -1384,8 +1381,8 @@ class LibraryController(
showCategories(false) showCategories(false)
return true return true
} }
if (filter_bottom_sheet.sheetBehavior.isExpanded()) { if (binding.filterBottomSheet.filterBottomSheet.sheetBehavior.isExpanded()) {
filter_bottom_sheet.sheetBehavior?.collapse() binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.collapse()
return true return true
} }
return false return false
@ -1416,7 +1413,7 @@ class LibraryController(
R.id.action_search -> expandActionViewFromInteraction = true R.id.action_search -> expandActionViewFromInteraction = true
R.id.action_filter -> { R.id.action_filter -> {
hasExpanded = true hasExpanded = true
filter_bottom_sheet.sheetBehavior?.expand() binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.expand()
} }
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
} }

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.annotation.SuppressLint
import android.view.GestureDetector import android.view.GestureDetector
import android.view.Gravity import android.view.Gravity
import android.view.MotionEvent import android.view.MotionEvent
@ -34,6 +35,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
return super.onSingleTapUp(e) return super.onSingleTapUp(e)
} }
@SuppressLint("RtlHardcoded")
override fun onFling( override fun onFling(
e1: MotionEvent, e1: MotionEvent,
e2: MotionEvent, e2: MotionEvent,
@ -55,7 +57,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur
if (diffY <= 0) { if (diffY <= 0) {
controller.showSheet() controller.showSheet()
} else { } else {
controller.filter_bottom_sheet.sheetBehavior?.hide() controller.binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.hide()
} }
} else if (abs(diffX) >= abs(diffY) && } else if (abs(diffX) >= abs(diffY) &&
abs(diffX) > SWIPE_THRESHOLD * 5 && abs(diffX) > SWIPE_THRESHOLD * 5 &&

View File

@ -42,7 +42,8 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<include layout="@layout/library_grid_recycler" /> <include layout="@layout/library_grid_recycler"
android:id="@+id/library_grid_recycler"/>
<View <View
android:id="@+id/recycler_cover" android:id="@+id/recycler_cover"
@ -118,11 +119,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top|center"> android:layout_gravity="top|center">
<include layout="@layout/rounded_category_hopper" /> <include layout="@layout/rounded_category_hopper"
android:id="@+id/rounded_category_hopper" />
</FrameLayout> </FrameLayout>
<!-- Adding bottom sheet after main content --> <!-- Adding bottom sheet after main content -->
<include layout="@layout/filter_bottom_sheet" /> <include layout="@layout/filter_bottom_sheet"
android:id="@+id/filter_bottom_sheet"/>
<View <View
android:id="@+id/shadow2" android:id="@+id/shadow2"