Skip to content

Repository files navigation

TimeLineView

Android Timeline View Library demonstrate the the power of ConstraintnLayout and RecyclerView.

Build StatuscodecovCodacy BadgeAndroid ArsenalLicense

Showcase

ExampleMainExampleMainExampleMain

Quick Setup

1. Include library

Using Gradle

TimelineView is currently available in on Jitpack so add the following line before every other thing if you have not done that already.

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Then add the following line

dependencies {
compile 'com.github.po10cio:TimeLineView:1.0.2'
}

Using Maven

Also add the following lines before adding the maven dependency

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then add the dependency

<dependency>
<groupId>com.github.po10cio</groupId>
<artifactId>TimeLineView</artifactId>
<version>1.0.2</version>
</dependency>

2. Usage

In your XML layout include the TimelineView as follows:

<me.jerryhanks.stepview.TimeLineView
android:id="@+id/timelineView"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginBottom="8dp"android:layout_marginLeft="8dp"android:layout_marginRight="8dp"android:layout_marginTop="16dp">

Then in your Kotlin code, do the following:

Create a class that extends TimeLine

classMyTimeLine(status:Status, vartitle:String?, varcontent:String?) : TimeLine(status) {
overridefunequals(other:Any?): Boolean {
if (this=== other) returntrueif (javaClass != other?.javaClass) returnfalse
other asMyTimeLineif (title != other.title) returnfalseif (content != other.content) returnfalsereturntrue
}
overridefunhashCode(): Int {
var result =if (title !=null) title!!.hashCode() else0
result =31* result +if (content !=null) content!!.hashCode() else0return result
}
overridefuntoString(): String {
return"MyTimeLine{"+"title='"+ title +'\''+", content='"+ content +'\''+'}'
}
}

TimeLine has three Statuses:

  • Status.COMPLETED
  • Status.UN_COMPLETED
  • Status.ATTENTION

You can choose from any of the statuses depending on the status of the item you want to represent.

Create an Array of your TimeLine

val timeLines = mutableListOf<MyTimeLine>()
.apply {
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_1), getString(R.string.s_content_1)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_2), getString(R.string.s_content_2)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_3), getString(R.string.s_content_3)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_4), getString(R.string.s_content_4)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_5), getString(R.string.s_content_5)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_6), getString(R.string.s_content_6)))
add(MyTimeLine(Status.COMPLETED, getString(R.string.s_title_7), getString(R.string.s_content_7)))
}

Create the IndicatorAdapter and add it to the TimeLineView

val adapter =IndicatorAdapter(mutableListOf(), this, object:TimeLineViewCallback<MyTimeLine> {
overridefunonBindView(model:MyTimeLine, container:FrameLayout, position:Int): View {
val view = layoutInflater
.inflate(R.layout.sample_time_line,
container, false)
(view.findViewById<TextView>(R.id.tv_title)).text = model.title
(view.findViewById<TextView>(R.id.tv_content)).text = model.content
return view
}
})
timelineView.setIndicatorAdapter(adapter)
adapter.swapItems(timeLines)

IndicatorAdapter This extends RecyclerView.Adapter and exposes the following functions:

  • Swaps the old items with the new items
funswapItems(timeLines:List<T>)
  • Update a single item given the index
funupdateItem(timeline:T, position:Int) 
  • Adds a list of items to the list starting from the given index
funaddItems(varargitems:T, index:Int = itemCount)

Changelog

See the changelog file.

License

TimeLineView is distributed under the MIT license. See LICENSE for details.

About

A simple Timeline View that demonstrates the power of ConstraintLayout and RecyclerView. No drawing, just plug in and play.

Topics

Resources

Stars

354 stars

Watchers

13 watching

Forks

Releases

Packages

Contributors

Languages