Skip to content

Commit

Permalink
Configurable margin for dialog option items
Browse files Browse the repository at this point in the history
  • Loading branch information
FikriMilano committed Feb 7, 2023
1 parent 0e38ff7 commit f55c1a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.recyclerview.widget.RecyclerView
* a margin to the item's layout.
* @param margin Int value for the desired margin used as item offset
*/
class MarginItemDecoration(private val margin: Int) : RecyclerView.ItemDecoration() {
class MarginItemDecoration(private val marginVertical: Int, private val marginHorizontal: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
Expand All @@ -34,11 +34,11 @@ class MarginItemDecoration(private val margin: Int) : RecyclerView.ItemDecoratio
) {
outRect.apply {
if (parent.getChildAdapterPosition(view) == 0) {
top = margin
top = marginVertical
}
left = margin
right = margin
bottom = margin
left = marginHorizontal
right = marginHorizontal
bottom = marginVertical
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ internal class OptionSelectDialogFragment(
val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.addItemDecoration(
MarginItemDecoration(resources.getDimensionPixelOffset(R.dimen.item_margin_vertical))
MarginItemDecoration(
marginVertical = resources.getDimensionPixelOffset(R.dimen.dialog_option_item_margin_vertical),
marginHorizontal = resources.getDimensionPixelOffset(R.dimen.dialog_option_item_margin_horizontal)
)
)

val adapter = OptionSelectAdapter(multiSelectEnabled = config.multiSelect)
Expand Down
2 changes: 2 additions & 0 deletions datacapture/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<dimen name="padding_quarter_size">4dp</dimen>
<dimen name="radio_button_item_gap">16dp</dimen>
<dimen name="dialog_button_text_size_default">14sp</dimen>
<dimen name="dialog_option_item_margin_vertical">8dp</dimen>
<dimen name="dialog_option_item_margin_horizontal">8dp</dimen>
<dimen name="auto_complete_chip_group_margin">10dp</dimen>
<dimen name="auto_complete_chip_group_bottom_margin">50dp</dimen>
<dimen name="instructions_top_margin">4dp</dimen>
Expand Down

0 comments on commit f55c1a5

Please sign in to comment.