mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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:
parent
e43aa9c043
commit
a37002876e
5 changed files with 42 additions and 2 deletions
|
|
@ -54,9 +54,10 @@ import fr.free.nrw.commons.databinding.CustomSelectorBottomLayoutBinding
|
||||||
import fr.free.nrw.commons.databinding.CustomSelectorToolbarBinding
|
import fr.free.nrw.commons.databinding.CustomSelectorToolbarBinding
|
||||||
import fr.free.nrw.commons.media.ZoomableActivity
|
import fr.free.nrw.commons.media.ZoomableActivity
|
||||||
import fr.free.nrw.commons.theme.BaseActivity
|
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.upload.FileUtilsWrapper
|
||||||
import fr.free.nrw.commons.utils.CustomSelectorUtils
|
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.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
@ -199,7 +200,8 @@ class CustomSelectorActivity :
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
applyEdgeToEdgeAllInsets(binding.root)
|
applyEdgeToEdgeTopInsets(toolbarBinding.toolbarLayout)
|
||||||
|
bottomSheetBinding.bottomLayout.applyEdgeToEdgeBottomPaddingInsets()
|
||||||
val view = binding.root
|
val view = binding.root
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import fr.free.nrw.commons.databinding.FragmentCustomSelectorBinding
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.upload.FileProcessor
|
import fr.free.nrw.commons.upload.FileProcessor
|
||||||
|
import fr.free.nrw.commons.utils.applyEdgeToEdgeBottomPaddingInsets
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -99,6 +100,7 @@ class FolderFragment : CommonsDaggerSupportFragment() {
|
||||||
selectorRV = binding?.selectorRv
|
selectorRV = binding?.selectorRv
|
||||||
loader = binding?.loader
|
loader = binding?.loader
|
||||||
with(binding?.selectorRv) {
|
with(binding?.selectorRv) {
|
||||||
|
this?.applyEdgeToEdgeBottomPaddingInsets()
|
||||||
this?.layoutManager = gridLayoutManager
|
this?.layoutManager = gridLayoutManager
|
||||||
this?.setHasFixedSize(true)
|
this?.setHasFixedSize(true)
|
||||||
this?.adapter = folderAdapter
|
this?.adapter = folderAdapter
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.theme.BaseActivity
|
import fr.free.nrw.commons.theme.BaseActivity
|
||||||
import fr.free.nrw.commons.upload.FileProcessor
|
import fr.free.nrw.commons.upload.FileProcessor
|
||||||
import fr.free.nrw.commons.upload.FileUtilsWrapper
|
import fr.free.nrw.commons.upload.FileUtilsWrapper
|
||||||
|
import fr.free.nrw.commons.utils.applyEdgeToEdgeBottomPaddingInsets
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
@ -217,6 +218,7 @@ class ImageFragment :
|
||||||
imageAdapter.setSingleSelection(singleSelection)
|
imageAdapter.setSingleSelection(singleSelection)
|
||||||
gridLayoutManager = GridLayoutManager(context, getSpanCount())
|
gridLayoutManager = GridLayoutManager(context, getSpanCount())
|
||||||
with(binding?.selectorRv) {
|
with(binding?.selectorRv) {
|
||||||
|
this?.applyEdgeToEdgeBottomPaddingInsets()
|
||||||
this?.layoutManager = gridLayoutManager
|
this?.layoutManager = gridLayoutManager
|
||||||
this?.setHasFixedSize(true)
|
this?.setHasFixedSize(true)
|
||||||
this?.adapter = imageAdapter
|
this?.adapter = imageAdapter
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import androidx.core.view.marginLeft
|
||||||
import androidx.core.view.marginRight
|
import androidx.core.view.marginRight
|
||||||
import androidx.core.view.marginTop
|
import androidx.core.view.marginTop
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
|
|
||||||
fun View.applyEdgeToEdgeInsets(
|
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 ->
|
fun applyEdgeToEdgeAllInsets(view: View) = view.applyEdgeToEdgeInsets { insets ->
|
||||||
leftMargin = insets.left
|
leftMargin = insets.left
|
||||||
rightMargin = insets.right
|
rightMargin = insets.right
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/switchWidget"
|
app:layout_constraintTop_toBottomOf="@id/switchWidget"
|
||||||
|
android:clipToPadding="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue