Skip to content

Commit edd3df3

Browse files
committed
Merge branch 'release/v0.0.16'
2 parents 0437436 + 2b45bac commit edd3df3

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
StickyTimeLine is timeline view for android.
66

7-
## What's New in 0.0.15?
7+
## What's New in 0.0.16?
88
- Fix Problems when recycler view is not added to dependency [#5](https://github.com/sangcomz/StickyTimeLine/issues/5)
99

1010
## How to Use
@@ -16,7 +16,7 @@ StickyTimeLine is timeline view for android.
1616
}
1717
1818
dependencies {
19-
compile 'com.github.sangcomz:StickyTimeLine:v0.0.15'
19+
compile 'com.github.sangcomz:StickyTimeLine:v0.0.16'
2020
}
2121
```
2222
### Usage

stickytimelineview/src/main/java/xyz/sangcomz/stickytimelineview/RecyclerSectionItemDecoration.kt

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import xyz.sangcomz.stickytimelineview.ext.DP
1717
import xyz.sangcomz.stickytimelineview.model.RecyclerViewAttr
1818
import 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
}

stickytimelineview/src/main/java/xyz/sangcomz/stickytimelineview/TimeLineRecyclerView.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ import android.util.AttributeSet
77
import xyz.sangcomz.stickytimelineview.model.RecyclerViewAttr
88

99

10-
/**
11-
* Created by seokwon.jeong on 16/11/2017.
10+
/*
11+
* Copyright 2018 SeokWon Jeong.
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
1224
*/
1325

1426
class TimeLineRecyclerView(context: Context?, attrs: AttributeSet?) : RecyclerView(context, attrs) {
@@ -47,15 +59,17 @@ class TimeLineRecyclerView(context: Context?, attrs: AttributeSet?) : RecyclerVi
4759
}
4860
}
4961

62+
/**
63+
* Add RecyclerSectionItemDecoration for Sticky TimeLineView
64+
*
65+
* @param callback SectionCallback
66+
*/
5067
fun addItemDecoration(callback: RecyclerSectionItemDecoration.SectionCallback) {
5168
recyclerViewAttr?.let {
5269
this.addItemDecoration(RecyclerSectionItemDecoration(context,
5370
true,
5471
callback,
5572
it))
5673
}
57-
58-
5974
}
60-
6175
}

0 commit comments

Comments
 (0)