Skip to content

Instantly share code, notes, and snippets.

@marius-m
Created May 20, 2022 07:16
Show Gist options
  • Save marius-m/67da6f4191e33a5ca932e27d2dd01e25 to your computer and use it in GitHub Desktop.
Save marius-m/67da6f4191e33a5ca932e27d2dd01e25 to your computer and use it in GitHub Desktop.
Helper class to define offset values in ItemDecorator
data class ItemDecoratorOffset private constructor(
val top: Int,
val bottom: Int,
val start: Int,
val end: Int,
) {
companion object {
fun asEmpty(): ItemDecoratorOffset {
return ItemDecoratorOffset(
top = 0,
bottom = 0,
start = 0,
end = 0,
)
}
fun new(
top: Int = 0,
bottom: Int = 0,
start: Int = 0,
end: Int = 0,
): ItemDecoratorOffset {
return ItemDecoratorOffset(
top = top,
bottom = bottom,
start = start,
end = end,
)
}
fun ItemDecoratorOffset.withDp(context: Context): ItemDecoratorOffset {
return ItemDecoratorOffset(
top = context.dpToPx(top),
bottom = context.dpToPx(bottom),
start = context.dpToPx(start),
end = context.dpToPx(end),
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment