mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Fix extra spacing in module list
This commit is contained in:
parent
125ee46685
commit
a39577c44d
@ -10,6 +10,23 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
|
|
||||||
|
fun RecyclerView.addInvalidateItemDecorationsObserver() {
|
||||||
|
|
||||||
|
adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||||
|
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||||
|
invalidateItemDecorations()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||||
|
invalidateItemDecorations()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
|
||||||
|
invalidateItemDecorations()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fun RecyclerView.addVerticalPadding(paddingTop: Int = 0, paddingBottom: Int = 0) {
|
fun RecyclerView.addVerticalPadding(paddingTop: Int = 0, paddingBottom: Int = 0) {
|
||||||
addItemDecoration(VerticalPaddingDecoration(paddingTop, paddingBottom))
|
addItemDecoration(VerticalPaddingDecoration(paddingTop, paddingBottom))
|
||||||
}
|
}
|
||||||
@ -20,11 +37,9 @@ private class VerticalPaddingDecoration(private val paddingTop: Int = 0, private
|
|||||||
private var allowBottom: Boolean = true
|
private var allowBottom: Boolean = true
|
||||||
|
|
||||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
||||||
if (parent.adapter == null) {
|
val adapter = parent.adapter ?: return
|
||||||
return
|
|
||||||
}
|
|
||||||
val position = parent.getChildAdapterPosition(view)
|
val position = parent.getChildAdapterPosition(view)
|
||||||
val count = parent.adapter!!.itemCount
|
val count = adapter.itemCount
|
||||||
if (position == 0 && allowTop) {
|
if (position == 0 && allowTop) {
|
||||||
outRect.top = paddingTop
|
outRect.top = paddingTop
|
||||||
} else if (position == count - 1 && allowBottom) {
|
} else if (position == count - 1 && allowBottom) {
|
||||||
|
@ -13,10 +13,7 @@ import com.topjohnwu.magisk.arch.ReselectionTarget
|
|||||||
import com.topjohnwu.magisk.arch.ViewEvent
|
import com.topjohnwu.magisk.arch.ViewEvent
|
||||||
import com.topjohnwu.magisk.core.download.BaseDownloader
|
import com.topjohnwu.magisk.core.download.BaseDownloader
|
||||||
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
||||||
import com.topjohnwu.magisk.ktx.addSimpleItemDecoration
|
import com.topjohnwu.magisk.ktx.*
|
||||||
import com.topjohnwu.magisk.ktx.addVerticalPadding
|
|
||||||
import com.topjohnwu.magisk.ktx.fixEdgeEffect
|
|
||||||
import com.topjohnwu.magisk.ktx.hideKeyboard
|
|
||||||
import com.topjohnwu.magisk.ui.MainActivity
|
import com.topjohnwu.magisk.ui.MainActivity
|
||||||
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
|
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
|
||||||
import com.topjohnwu.magisk.utils.MotionRevealHelper
|
import com.topjohnwu.magisk.utils.MotionRevealHelper
|
||||||
@ -72,7 +69,7 @@ class ModuleFragment : BaseUIFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
|||||||
binding.moduleList.apply {
|
binding.moduleList.apply {
|
||||||
addVerticalPadding(
|
addVerticalPadding(
|
||||||
l_50,
|
l_50,
|
||||||
l1 + resource.getDimensionPixelSize(R.dimen.internal_action_bar_size)
|
l1 + l_50 + resource.getDimensionPixelSize(R.dimen.internal_action_bar_size)
|
||||||
)
|
)
|
||||||
addSimpleItemDecoration(
|
addSimpleItemDecoration(
|
||||||
left = l1,
|
left = l1,
|
||||||
@ -81,6 +78,9 @@ class ModuleFragment : BaseUIFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
|||||||
bottom = l_50,
|
bottom = l_50,
|
||||||
)
|
)
|
||||||
fixEdgeEffect()
|
fixEdgeEffect()
|
||||||
|
post {
|
||||||
|
addInvalidateItemDecorationsObserver()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.moduleFilterInclude.moduleFilterList.apply {
|
binding.moduleFilterInclude.moduleFilterList.apply {
|
||||||
|
Loading…
Reference in New Issue
Block a user