Skip to content

Commit

Permalink
Merge pull request #2 from lriccardo/dev
Browse files Browse the repository at this point in the history
Release 1.0.3
  • Loading branch information
lriccardo authored Dec 9, 2021
2 parents 807564f + 6c2acc9 commit 34be797
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 120 deletions.
94 changes: 75 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A customizable and easy-to-use Timeline View library for Android

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

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

### 1. Add Jitpack to your root build.gradle
Expand Down Expand Up @@ -34,28 +34,34 @@ dependencies {
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:timeline_item_type="first"
app:indicator_radius="12dp"
app:indicator_size="12dp"
app:line_width="8dp"
app:indicator_color="@color/teal_700"
app:line_color="@color/teal_700" />
```
- View types
- Previews
<table>
<th>View type</th>
<th>Preview</th>
<th>View type</th>
<th>Preview</th>
<th>View type</th>
<th>Preview</th>
<tr>
<td>first</td>
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/first.jpg" alt="first" width="200"/></td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/first.jpg" alt="first" width="200"/></td>
<td>middle</td>
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/middle.jpg" alt="middle" width="200"/></td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle.jpg" alt="middle" width="200"/></td>
<td>checked</td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle_checked.jpg" alt="checked" width="200"/></td>
</tr>
<tr>
<td>last</td>
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/last.jpg" alt="last" width="200"/></td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/last.jpg" alt="last" width="200"/></td>
<td>spacer</td>
<td><img src="https://github.com/lriccardo/TimelineView/blob/main/screens/spacer.jpg" alt="spacer" width="200"/></td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/spacer.jpg" alt="spacer" width="200"/></td>
<td>dashed</td>
<td><img src="https://github.com/lriccardo/TimelineView/raw/main/screens/middle_dashed.jpg" alt="dashed" width="200"/></td>
</tr>
</table>

Expand All @@ -71,34 +77,64 @@ dependencies {
<td>first</td>
</tr>
<tr>
<td>app:indicator_radius</td>
<td>Dimension</td>
<td>12dp</td>
<td>app:indicator_style</td>
<td>filled | empty | checked</td>
<td>filled</td>
</tr>
<tr>
<td>app:line_width</td>
<td>app:indicator_size</td>
<td>Dimension</td>
<td>indicator_radius/1.61</td>
<td>12dp</td>
</tr>
</tr>
<tr>
<td>app:indicator_color</td>
<td>Color</td>
<td>Color.RED</td>
</tr>
<tr>
<td>app:checked_indicator_size</td>
<td>Dimension</td>
<td>6dp</td>
</tr>
<tr>
<td>app:checked_indicator_stroke_width</td>
<td>Dimension</td>
<td>4dp</td>
</tr>
<tr>
<td>app:line_style</td>
<td>normal | dashed</td>
<td>normal</td>
</tr>
<tr>
<td>app:line_width</td>
<td>Dimension</td>
<td>8dp</td>
</tr>
</tr>
<tr>
<td>app:line_color</td>
<td>Color</td>
<td>Color.RED</td>
</tr>
<tr>
<td>app:line_dash_length</td>
<td>Dimension</td>
<td>18</td>
</tr>
<tr>
<td>app:line_dash_gap</td>
<td>Dimension</td>
<td>12</td>
</tr>
</table>

### RecyclerView Decorator
```
recyclerView.addItemDecoration(
TimelineDecorator(
indicatorRadius = 24f,
indicatorSize = 24f,
lineWidth = 15f,
padding = 48f,
position = TimelineDecorator.Position.Left,
Expand All @@ -115,19 +151,39 @@ recyclerView.addItemDecoration(
<th>Accepted values</th>
<th>Default</th>
<tr>
<td>indicatorRadius</td>
<td>indicatorStyle</td>
<td>IndicatorStyle (Filled | Empty | Checked)</td>
<td>Filled</td>
</tr>
<tr>
<td>indicatorSize</td>
<td>Float</td>
<td>24f</td>
</tr>
<tr>
<td>checkedIndicatorSize</td>
<td>Float</td>
<td>TimelineView default value</td>
</tr>
<tr>
<td>checkedIndicatorStrokeWidth</td>
<td>Float</td>
<td>4dp</td>
</tr>
<tr>
<td>lineStyle</td>
<td>Normal (Normal | Dashed)</td>
<td>TimelineView default value</td>
</tr>
<tr>
<td>lineWidth</td>
<td>Float</td>
<td>indicatorRadius/1.61</td>
<td>TimelineView default value</td>
</tr>
<tr>
<td>padding</td>
<td>Float</td>
<td>indicatorRadius*2</td>
<td>16dp/td>
</tr>
<tr>
<td>position</td>
Expand All @@ -137,12 +193,12 @@ recyclerView.addItemDecoration(
<tr>
<td>indicatorColor</td>
<td>@ColorInt</td>
<td>Color.RED</td>
<td>TimelineView default value</td>
</tr>
</tr>
<tr>
<td>lineColorr</td>
<td>lineColor</td>
<td>@ColorInt</td>
<td>Color.RED</td>
<td>TimelineView default value</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lriccardo.timelineview

import androidx.annotation.ColorInt

interface TimelineAdapter {
fun getTimelineViewType(position: Int): TimelineView.ViewType? = null
fun getIndicatorStyle(position: Int): TimelineView.IndicatorStyle? = null
fun getIndicatorColor(position: Int): Int? = null
fun getLineColor(position: Int): Int? = null
fun getLineStyle(position: Int): TimelineView.LineStyle? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView

class TimelineDecorator(
val indicatorRadius: Float = 24f,
val lineWidth: Float = indicatorRadius / 1.61f,
val padding: Float = indicatorRadius * 2,
val indicatorStyle: TimelineView.IndicatorStyle = TimelineView.IndicatorStyle.Filled,
val indicatorSize: Float = 12.toPx().toFloat(),
val checkedIndicatorSize: Float? = null,
val checkedIndicatorStrokeWidth: Float = 4.toPx().toFloat(),
val lineStyle: TimelineView.LineStyle? = null,
val lineWidth: Float? = null,
val padding: Float = 16.toPx().toFloat(),
val position: Position = Position.Left,
@ColorInt val indicatorColor: Int? = null,
@ColorInt val lineColor: Int? = null
) : RecyclerView.ItemDecoration() {

val width = ((indicatorRadius * 2) + (padding * 2))
val width = ((indicatorSize * 2) + (padding * 2))

enum class Position {
Left,
Expand All @@ -29,11 +33,17 @@ class TimelineDecorator(
parent: RecyclerView,
s: RecyclerView.State
) {
val size = when(indicatorStyle){
TimelineView.IndicatorStyle.Filled -> indicatorSize*2
TimelineView.IndicatorStyle.Empty -> (indicatorSize*2) + checkedIndicatorStrokeWidth
TimelineView.IndicatorStyle.Checked -> (indicatorSize*2) + checkedIndicatorStrokeWidth
}.toInt()

when (position) {
Position.Left ->
rect.left = width.toInt()
rect.left = size
Position.Right ->
rect.right = width.toInt()
rect.right = size
}
}

Expand All @@ -45,20 +55,46 @@ class TimelineDecorator(
return

val timelineView = TimelineView(context = parent.context)
timelineView.setType(itemPosition, parent.adapter?.itemCount ?: -1)
timelineView.indicatorRadius = indicatorRadius
timelineView.lineWidth = lineWidth
indicatorColor?.let {
timelineView.indicatorColor = it
(parent.adapter as? TimelineAdapter)?.run {
getTimelineViewType(itemPosition)?.let {
timelineView.viewType = it
} ?: timelineView.setType(itemPosition, parent.adapter?.itemCount ?: -1)

(getIndicatorColor(itemPosition) ?: indicatorColor)?.let {
timelineView.indicatorColor = it
}

(getLineColor(itemPosition) ?: lineColor)?.let {
timelineView.lineColor = it
}

(getIndicatorStyle(itemPosition) ?: indicatorStyle)?.let {
timelineView.indicatorStyle = it
}

(getLineStyle(itemPosition) ?: lineStyle)?.let {
timelineView.lineStyle = it
}
}
timelineView.indicatorSize = indicatorSize

checkedIndicatorSize?.let {
timelineView.checkedIndicatorSize = it
}
lineColor?.let {
timelineView.lineColor = it

checkedIndicatorStrokeWidth?.let {
timelineView.checkedIndicatorStrokeWidth = it
}

lineWidth?.let {
timelineView.lineWidth = it
}

timelineView.measure(
View.MeasureSpec.getSize(width.toInt()),
View.MeasureSpec.getSize(it.measuredHeight)
)

c.save()
when (position) {
Position.Left -> {
Expand Down
Loading

0 comments on commit 34be797

Please sign in to comment.