@@ -17,8 +17,12 @@ import xyz.sangcomz.stickytimelineview.ext.DP
1717import xyz.sangcomz.stickytimelineview.model.RecyclerViewAttr
1818import xyz.sangcomz.stickytimelineview.model.SectionInfo
1919
20+ /*
21+ */
2022
2123/* *
24+ * Copyright 2017 Timothy Paetz
25+ * Copyright 2017 SeokWon Jeong
2226 * thanks to @tim.paetz
2327 * I was inspired by his code. And I used some of his code in the library.
2428 * https://github.com/paetztm/recycler_view_headers
@@ -36,6 +40,10 @@ class RecyclerSectionItemDecoration(context: Context,
3640 private var headerOffset = defaultOffset * 8
3741
3842
43+ /* *
44+ * Get the offset for each Item.
45+ * There is a difference in top offset between sections and not sections.
46+ */
3947 override fun getItemOffsets (outRect : Rect , view : View , parent : RecyclerView , state : RecyclerView .State ? ) {
4048 super .getItemOffsets(outRect,
4149 view,
@@ -49,7 +57,6 @@ class RecyclerSectionItemDecoration(context: Context,
4957 outRect.top = defaultOffset / 2
5058 }
5159
52-
5360 val leftMargin = defaultOffset * 6
5461 val rightMargin = defaultOffset * 2
5562
@@ -59,26 +66,15 @@ class RecyclerSectionItemDecoration(context: Context,
5966
6067 }
6168
62- override fun onDraw (c : Canvas ? , parent : RecyclerView ? , state : RecyclerView .State ? ) {
63- super .onDraw(c, parent, state)
64- // c?.let {
65- // parent?.let {
66- // val leftMargin = defaultOffset * 6
67- // val rightMargin = defaultOffset * 2
68- // val topMargin = defaultOffset
69- // (0 until parent.childCount)
70- // .map { parent.getChildAt(it) }
71- // .forEach {
72- // val params = it.layoutParams
73- // if (params is RecyclerView.LayoutParams && params.leftMargin != leftMargin) {
74- // params.setMargins(leftMargin, 0, rightMargin, topMargin)
75- // it.layoutParams = params
76- // }
77- // }
78- // }
79- // }
80- }
81-
69+ /* *
70+ * Draw any appropriate decorations into the Canvas supplied to the RecyclerView.
71+ * Any content drawn by this method will be drawn after the item views are drawn
72+ * and will thus appear over the views.
73+ *
74+ * @param c Canvas to draw into
75+ * @param parent RecyclerView this ItemDecoration is drawing into
76+ * @param state The current state of RecyclerView.
77+ */
8278 override fun onDrawOver (c : Canvas , parent : RecyclerView , state : RecyclerView .State ? ) {
8379 super .onDrawOver(c,
8480 parent,
@@ -126,6 +122,9 @@ class RecyclerSectionItemDecoration(context: Context,
126122 }
127123 }
128124
125+ /* *
126+ * First create a header view.
127+ */
129128 private fun getHeaderView (parent : RecyclerView ) {
130129 headerView = inflateHeaderView(parent)
131130 headerView?.let { headerView ->
@@ -154,6 +153,9 @@ class RecyclerSectionItemDecoration(context: Context,
154153 }
155154 }
156155
156+ /* *
157+ * Set a header view for section info.
158+ */
157159 private fun setHeaderView (sectionInfo : SectionInfo ) {
158160 headerTitle?.text = sectionInfo.title
159161 headerSubTitle?.apply {
@@ -167,13 +169,19 @@ class RecyclerSectionItemDecoration(context: Context,
167169
168170 }
169171
172+ /* *
173+ * Draw a line in the timeline.
174+ */
170175 private fun drawLine (c : Canvas , parent : RecyclerView ) {
171176 val paint = Paint ()
172177 paint.color = recyclerViewAttr.sectionLineColor
173178 paint.strokeWidth = recyclerViewAttr.sectionLineWidth
174179 c.drawLines(floatArrayOf(defaultOffset * 3f , 0f , defaultOffset * 3f , parent.height.toFloat()), paint)
175180 }
176181
182+ /* *
183+ *
184+ */
177185 private fun getChildInContact (parent : RecyclerView , contactPoint : Int ): View ? =
178186 (0 until parent.childCount)
179187 .map {
@@ -183,6 +191,9 @@ class RecyclerSectionItemDecoration(context: Context,
183191 it.top in contactPoint / 2 .. contactPoint
184192 }
185193
194+ /* *
195+ * Returns the oval drawable of the timeline.
196+ */
186197 private fun getOvalDrawable (): Drawable {
187198 val strokeWidth = defaultOffset / 2
188199 val roundRadius = defaultOffset * 2
@@ -197,13 +208,19 @@ class RecyclerSectionItemDecoration(context: Context,
197208 return gd
198209 }
199210
211+ /* *
212+ * Moving parts when headers meet
213+ */
200214 private fun moveHeader (c : Canvas , topHeader : View , offset : Float ) {
201215 c.save()
202216 c.translate(0f , offset)
203217 topHeader.draw(c)
204218 c.restore()
205219 }
206220
221+ /* *
222+ * Draw a header
223+ */
207224 private fun drawHeader (c : Canvas , child : View , headerView : View ) {
208225 c.save()
209226 if (sticky) {
@@ -251,6 +268,9 @@ class RecyclerSectionItemDecoration(context: Context,
251268 view.measuredHeight)
252269 }
253270
271+ /* *
272+ * To check if section is
273+ */
254274 private fun getIsSection (position : Int ): Boolean = when (position) {
255275 0 -> {
256276 true
@@ -264,10 +284,20 @@ class RecyclerSectionItemDecoration(context: Context,
264284
265285 }
266286
287+
288+ /* *
289+ * Section-specific callback interface
290+ */
267291 interface SectionCallback {
268292
293+ /* *
294+ * To check if section is
295+ */
269296 fun isSection (position : Int ): Boolean
270297
298+ /* *
299+ * Functions that return a section header in a section
300+ */
271301 fun getSectionHeader (position : Int ): SectionInfo ?
272302 }
273303}
0 commit comments