Fix reordering categories

which fixes #1433 and fixes #898
This commit is contained in:
Jays2Kings 2023-04-05 16:31:33 -04:00
parent 27bebe1864
commit 4d3d3df873
2 changed files with 22 additions and 4 deletions

View file

@ -60,7 +60,7 @@ class CategoryController(bundle: Bundle? = null) :
*/
override fun onViewCreated(view: View) {
super.onViewCreated(view)
liftAppbarWith(binding.recycler, true)
liftAppbarWith(binding.recycler, true, changeMarginsInstead = true)
adapter = CategoryAdapter(this@CategoryController)
binding.recycler.layoutManager = LinearLayoutManager(view.context)

View file

@ -32,6 +32,7 @@ import androidx.core.view.WindowInsetsCompat.Type.systemBars
import androidx.core.view.doOnLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePaddingRelative
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.DefaultItemAnimator
@ -128,6 +129,7 @@ fun Controller.removeQueryListener(includeSearchTB: Boolean = true) {
fun <T> Controller.liftAppbarWith(
recyclerOrNested: T,
padView: Boolean = false,
changeMarginsInstead: Boolean = false,
liftOnScroll: ((Boolean) -> Unit)? = null,
) {
val recycler = recyclerOrNested as? RecyclerView ?: recyclerOrNested as? NestedScrollView ?: return
@ -146,20 +148,36 @@ fun <T> Controller.liftAppbarWith(
}
}
recycler.updatePaddingRelative(
top = activityBinding!!.toolbar.y.toInt() + appBarHeight,
top = if (changeMarginsInstead) 0 else activityBinding!!.toolbar.y.toInt() + appBarHeight,
bottom = recycler.rootWindowInsetsCompat?.getInsets(systemBars())?.bottom ?: 0,
)
if (changeMarginsInstead) {
recycler.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = activityBinding!!.toolbar.y.toInt() + appBarHeight
}
}
recycler.applyBottomAnimatedInsets(setPadding = true) { view, insets ->
val headerHeight = insets.getInsets(systemBars()).top + appBarHeight
view.updatePaddingRelative(top = headerHeight)
if (changeMarginsInstead) {
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight
}
} else {
view.updatePaddingRelative(top = headerHeight)
}
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
recycler.doOnApplyWindowInsetsCompat { view, insets, _ ->
val headerHeight = insets.getInsets(systemBars()).top + appBarHeight
view.updatePaddingRelative(
top = headerHeight,
top = if (changeMarginsInstead) 0 else headerHeight,
bottom = insets.getInsets(ime() or systemBars()).bottom,
)
if (changeMarginsInstead) {
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight
}
}
}
}
} else {