aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
new file mode 100644
index 0000000..f80c85e
--- /dev/null
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt
@@ -0,0 +1,25 @@
+package ca.allanwang.kau.utils
+
+import android.graphics.Rect
+import android.support.v7.widget.RecyclerView
+import android.view.View
+
+/**
+ * Created by Allan Wang on 2017-07-11.
+ */
+fun RecyclerView.withMarginDecoration(sizeDp: Int, edgeFlags: Int) {
+ addItemDecoration(MarginItemDecoration(sizeDp, edgeFlags))
+}
+
+class MarginItemDecoration(sizeDp: Int, val edgeFlags: Int) : RecyclerView.ItemDecoration() {
+
+ val sizePx = sizeDp.dpToPx
+
+ override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
+ super.getItemOffsets(outRect, view, parent, state)
+ if (edgeFlags and KAU_LEFT > 0) outRect.left += sizePx
+ if (edgeFlags and KAU_TOP > 0) outRect.top += sizePx
+ if (edgeFlags and KAU_RIGHT > 0) outRect.right += sizePx
+ if (edgeFlags and KAU_BOTTOM > 0) outRect.bottom += sizePx
+ }
+} \ No newline at end of file