Created
May 20, 2022 07:16
-
-
Save marius-m/67da6f4191e33a5ca932e27d2dd01e25 to your computer and use it in GitHub Desktop.
Helper class to define offset values in ItemDecorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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