Skip to content

Commit 34be797

Browse files
authored
Merge pull request #2 from lriccardo/dev
Release 1.0.3
2 parents 807564f + 6c2acc9 commit 34be797

21 files changed

+526
-120
lines changed

README.md

+75-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A customizable and easy-to-use Timeline View library for Android
55

66
Can be used as a standalone view or as a RecyclerView decorator
77

8-
![header](https://github.com/lriccardo/TimelineView/blob/main/screens/header.png)
8+
![header](https://raw.githubusercontent.com/lriccardo/TimelineView/main/screens/header.png)
99
## Setup
1010

1111
### 1. Add Jitpack to your root build.gradle
@@ -34,28 +34,34 @@ dependencies {
3434
android:layout_width="wrap_content"
3535
android:layout_height="match_parent"
3636
app:timeline_item_type="first"
37-
app:indicator_radius="12dp"
37+
app:indicator_size="12dp"
3838
app:line_width="8dp"
3939
app:indicator_color="@color/teal_700"
4040
app:line_color="@color/teal_700" />
4141
```
42-
- View types
42+
- Previews
4343
<table>
44+
<th>View type</th>
45+
<th>Preview</th>
4446
<th>View type</th>
4547
<th>Preview</th>
4648
<th>View type</th>
4749
<th>Preview</th>
4850
<tr>
4951
<td>first</td>
50-
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/first.jpg" alt="first" width="200"/></td>
52+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/first.jpg" alt="first" width="200"/></td>
5153
<td>middle</td>
52-
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/middle.jpg" alt="middle" width="200"/></td>
54+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle.jpg" alt="middle" width="200"/></td>
55+
<td>checked</td>
56+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle_checked.jpg" alt="checked" width="200"/></td>
5357
</tr>
5458
<tr>
5559
<td>last</td>
56-
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/last.jpg" alt="last" width="200"/></td>
60+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/last.jpg" alt="last" width="200"/></td>
5761
<td>spacer</td>
58-
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/spacer.jpg" alt="spacer" width="200"/></td>
62+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/spacer.jpg" alt="spacer" width="200"/></td>
63+
<td>dashed</td>
64+
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle_dashed.jpg" alt="dashed" width="200"/></td>
5965
</tr>
6066
</table>
6167

@@ -71,34 +77,64 @@ dependencies {
7177
<td>first</td>
7278
</tr>
7379
<tr>
74-
<td>app:indicator_radius</td>
75-
<td>Dimension</td>
76-
<td>12dp</td>
80+
<td>app:indicator_style</td>
81+
<td>filled | empty | checked</td>
82+
<td>filled</td>
7783
</tr>
7884
<tr>
79-
<td>app:line_width</td>
85+
<td>app:indicator_size</td>
8086
<td>Dimension</td>
81-
<td>indicator_radius/1.61</td>
87+
<td>12dp</td>
8288
</tr>
8389
</tr>
8490
<tr>
8591
<td>app:indicator_color</td>
8692
<td>Color</td>
8793
<td>Color.RED</td>
8894
</tr>
95+
<tr>
96+
<td>app:checked_indicator_size</td>
97+
<td>Dimension</td>
98+
<td>6dp</td>
99+
</tr>
100+
<tr>
101+
<td>app:checked_indicator_stroke_width</td>
102+
<td>Dimension</td>
103+
<td>4dp</td>
104+
</tr>
105+
<tr>
106+
<td>app:line_style</td>
107+
<td>normal | dashed</td>
108+
<td>normal</td>
109+
</tr>
110+
<tr>
111+
<td>app:line_width</td>
112+
<td>Dimension</td>
113+
<td>8dp</td>
114+
</tr>
89115
</tr>
90116
<tr>
91117
<td>app:line_color</td>
92118
<td>Color</td>
93119
<td>Color.RED</td>
94120
</tr>
121+
<tr>
122+
<td>app:line_dash_length</td>
123+
<td>Dimension</td>
124+
<td>18</td>
125+
</tr>
126+
<tr>
127+
<td>app:line_dash_gap</td>
128+
<td>Dimension</td>
129+
<td>12</td>
130+
</tr>
95131
</table>
96132

97133
### RecyclerView Decorator
98134
```
99135
recyclerView.addItemDecoration(
100136
TimelineDecorator(
101-
indicatorRadius = 24f,
137+
indicatorSize = 24f,
102138
lineWidth = 15f,
103139
padding = 48f,
104140
position = TimelineDecorator.Position.Left,
@@ -115,19 +151,39 @@ recyclerView.addItemDecoration(
115151
<th>Accepted values</th>
116152
<th>Default</th>
117153
<tr>
118-
<td>indicatorRadius</td>
154+
<td>indicatorStyle</td>
155+
<td>IndicatorStyle (Filled | Empty | Checked)</td>
156+
<td>Filled</td>
157+
</tr>
158+
<tr>
159+
<td>indicatorSize</td>
119160
<td>Float</td>
120161
<td>24f</td>
121162
</tr>
163+
<tr>
164+
<td>checkedIndicatorSize</td>
165+
<td>Float</td>
166+
<td>TimelineView default value</td>
167+
</tr>
168+
<tr>
169+
<td>checkedIndicatorStrokeWidth</td>
170+
<td>Float</td>
171+
<td>4dp</td>
172+
</tr>
173+
<tr>
174+
<td>lineStyle</td>
175+
<td>Normal (Normal | Dashed)</td>
176+
<td>TimelineView default value</td>
177+
</tr>
122178
<tr>
123179
<td>lineWidth</td>
124180
<td>Float</td>
125-
<td>indicatorRadius/1.61</td>
181+
<td>TimelineView default value</td>
126182
</tr>
127183
<tr>
128184
<td>padding</td>
129185
<td>Float</td>
130-
<td>indicatorRadius*2</td>
186+
<td>16dp/td>
131187
</tr>
132188
<tr>
133189
<td>position</td>
@@ -137,12 +193,12 @@ recyclerView.addItemDecoration(
137193
<tr>
138194
<td>indicatorColor</td>
139195
<td>@ColorInt</td>
140-
<td>Color.RED</td>
196+
<td>TimelineView default value</td>
141197
</tr>
142198
</tr>
143199
<tr>
144-
<td>lineColorr</td>
200+
<td>lineColor</td>
145201
<td>@ColorInt</td>
146-
<td>Color.RED</td>
202+
<td>TimelineView default value</td>
147203
</tr>
148204
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.lriccardo.timelineview
2+
3+
import androidx.annotation.ColorInt
4+
5+
interface TimelineAdapter {
6+
fun getTimelineViewType(position: Int): TimelineView.ViewType? = null
7+
fun getIndicatorStyle(position: Int): TimelineView.IndicatorStyle? = null
8+
fun getIndicatorColor(position: Int): Int? = null
9+
fun getLineColor(position: Int): Int? = null
10+
fun getLineStyle(position: Int): TimelineView.LineStyle? = null
11+
}

TimelineView/src/main/java/com/lriccardo/timelineview/TimelineDecorator.kt

+49-13
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import androidx.core.view.children
88
import androidx.recyclerview.widget.RecyclerView
99

1010
class TimelineDecorator(
11-
val indicatorRadius: Float = 24f,
12-
val lineWidth: Float = indicatorRadius / 1.61f,
13-
val padding: Float = indicatorRadius * 2,
11+
val indicatorStyle: TimelineView.IndicatorStyle = TimelineView.IndicatorStyle.Filled,
12+
val indicatorSize: Float = 12.toPx().toFloat(),
13+
val checkedIndicatorSize: Float? = null,
14+
val checkedIndicatorStrokeWidth: Float = 4.toPx().toFloat(),
15+
val lineStyle: TimelineView.LineStyle? = null,
16+
val lineWidth: Float? = null,
17+
val padding: Float = 16.toPx().toFloat(),
1418
val position: Position = Position.Left,
1519
@ColorInt val indicatorColor: Int? = null,
1620
@ColorInt val lineColor: Int? = null
1721
) : RecyclerView.ItemDecoration() {
1822

19-
val width = ((indicatorRadius * 2) + (padding * 2))
23+
val width = ((indicatorSize * 2) + (padding * 2))
2024

2125
enum class Position {
2226
Left,
@@ -29,11 +33,17 @@ class TimelineDecorator(
2933
parent: RecyclerView,
3034
s: RecyclerView.State
3135
) {
36+
val size = when(indicatorStyle){
37+
TimelineView.IndicatorStyle.Filled -> indicatorSize*2
38+
TimelineView.IndicatorStyle.Empty -> (indicatorSize*2) + checkedIndicatorStrokeWidth
39+
TimelineView.IndicatorStyle.Checked -> (indicatorSize*2) + checkedIndicatorStrokeWidth
40+
}.toInt()
41+
3242
when (position) {
3343
Position.Left ->
34-
rect.left = width.toInt()
44+
rect.left = size
3545
Position.Right ->
36-
rect.right = width.toInt()
46+
rect.right = size
3747
}
3848
}
3949

@@ -45,20 +55,46 @@ class TimelineDecorator(
4555
return
4656

4757
val timelineView = TimelineView(context = parent.context)
48-
timelineView.setType(itemPosition, parent.adapter?.itemCount ?: -1)
49-
timelineView.indicatorRadius = indicatorRadius
50-
timelineView.lineWidth = lineWidth
51-
indicatorColor?.let {
52-
timelineView.indicatorColor = it
58+
(parent.adapter as? TimelineAdapter)?.run {
59+
getTimelineViewType(itemPosition)?.let {
60+
timelineView.viewType = it
61+
} ?: timelineView.setType(itemPosition, parent.adapter?.itemCount ?: -1)
62+
63+
(getIndicatorColor(itemPosition) ?: indicatorColor)?.let {
64+
timelineView.indicatorColor = it
65+
}
66+
67+
(getLineColor(itemPosition) ?: lineColor)?.let {
68+
timelineView.lineColor = it
69+
}
70+
71+
(getIndicatorStyle(itemPosition) ?: indicatorStyle)?.let {
72+
timelineView.indicatorStyle = it
73+
}
74+
75+
(getLineStyle(itemPosition) ?: lineStyle)?.let {
76+
timelineView.lineStyle = it
77+
}
78+
}
79+
timelineView.indicatorSize = indicatorSize
80+
81+
checkedIndicatorSize?.let {
82+
timelineView.checkedIndicatorSize = it
5383
}
54-
lineColor?.let {
55-
timelineView.lineColor = it
84+
85+
checkedIndicatorStrokeWidth?.let {
86+
timelineView.checkedIndicatorStrokeWidth = it
87+
}
88+
89+
lineWidth?.let {
90+
timelineView.lineWidth = it
5691
}
5792

5893
timelineView.measure(
5994
View.MeasureSpec.getSize(width.toInt()),
6095
View.MeasureSpec.getSize(it.measuredHeight)
6196
)
97+
6298
c.save()
6399
when (position) {
64100
Position.Left -> {

0 commit comments

Comments
 (0)