feat(customselector): improve RecyclerView edge-to-edge inset handling

It allows the last item to sits above the navigation bar while preserving edge-to-edge appearance.
This commit is contained in:
Rohit Verma 2025-08-12 00:12:44 +05:30
parent e43aa9c043
commit a37002876e
5 changed files with 42 additions and 2 deletions

View file

@ -54,9 +54,10 @@ import fr.free.nrw.commons.databinding.CustomSelectorBottomLayoutBinding
import fr.free.nrw.commons.databinding.CustomSelectorToolbarBinding
import fr.free.nrw.commons.media.ZoomableActivity
import fr.free.nrw.commons.theme.BaseActivity
import fr.free.nrw.commons.utils.applyEdgeToEdgeAllInsets
import fr.free.nrw.commons.upload.FileUtilsWrapper
import fr.free.nrw.commons.utils.CustomSelectorUtils
import fr.free.nrw.commons.utils.applyEdgeToEdgeBottomPaddingInsets
import fr.free.nrw.commons.utils.applyEdgeToEdgeTopInsets
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -199,7 +200,8 @@ class CustomSelectorActivity :
.fillMaxWidth(),
)
}
applyEdgeToEdgeAllInsets(binding.root)
applyEdgeToEdgeTopInsets(toolbarBinding.toolbarLayout)
bottomSheetBinding.bottomLayout.applyEdgeToEdgeBottomPaddingInsets()
val view = binding.root
setContentView(view)

View file

@ -18,6 +18,7 @@ import fr.free.nrw.commons.databinding.FragmentCustomSelectorBinding
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
import fr.free.nrw.commons.media.MediaClient
import fr.free.nrw.commons.upload.FileProcessor
import fr.free.nrw.commons.utils.applyEdgeToEdgeBottomPaddingInsets
import javax.inject.Inject
/**
@ -99,6 +100,7 @@ class FolderFragment : CommonsDaggerSupportFragment() {
selectorRV = binding?.selectorRv
loader = binding?.loader
with(binding?.selectorRv) {
this?.applyEdgeToEdgeBottomPaddingInsets()
this?.layoutManager = gridLayoutManager
this?.setHasFixedSize(true)
this?.adapter = folderAdapter

View file

@ -41,6 +41,7 @@ import fr.free.nrw.commons.media.MediaClient
import fr.free.nrw.commons.theme.BaseActivity
import fr.free.nrw.commons.upload.FileProcessor
import fr.free.nrw.commons.upload.FileUtilsWrapper
import fr.free.nrw.commons.utils.applyEdgeToEdgeBottomPaddingInsets
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
@ -217,6 +218,7 @@ class ImageFragment :
imageAdapter.setSingleSelection(singleSelection)
gridLayoutManager = GridLayoutManager(context, getSpanCount())
with(binding?.selectorRv) {
this?.applyEdgeToEdgeBottomPaddingInsets()
this?.layoutManager = gridLayoutManager
this?.setHasFixedSize(true)
this?.adapter = imageAdapter

View file

@ -9,6 +9,7 @@ import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import fr.free.nrw.commons.R
fun View.applyEdgeToEdgeInsets(
@ -65,6 +66,38 @@ fun View.applyEdgeToEdgeInsets(
}
}
fun View.applyEdgeToEdgeTopPaddingInsets(
typeMask: Int = WindowInsetsCompat.Type.systemBars(),
) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
val insets = windowInsets.getInsets(typeMask)
view.updatePadding(
left = insets.left,
right = insets.right,
top = insets.top
)
WindowInsetsCompat.CONSUMED
}
}
fun View.applyEdgeToEdgeBottomPaddingInsets(
typeMask: Int = WindowInsetsCompat.Type.systemBars(),
) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
val insets = windowInsets.getInsets(typeMask)
view.updatePadding(
left = insets.left,
right = insets.right,
bottom = insets.bottom
)
WindowInsetsCompat.CONSUMED
}
}
fun applyEdgeToEdgeAllInsets(view: View) = view.applyEdgeToEdgeInsets { insets ->
leftMargin = insets.left
rightMargin = insets.right

View file

@ -34,6 +34,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/switchWidget"
android:clipToPadding="false"
/>
<TextView