Coder Social home page Coder Social logo

bondz / timelineview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jerryokafor/timelineview

1.0 1.0 0.0 1.97 MB

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

License: MIT License

Kotlin 93.65% Java 6.35%

timelineview's Introduction

TimeLineView

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

License

Showcase

ExampleMain      ExampleMain      ExampleMain

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.0'
}

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.0</version>
</dependency>

###2. Usage In your XML layout include the Timeline View as afollows:

 <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

class MyTimeLine(status: Status, var title: String?, var content: String?) : TimeLine(status) {


    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as MyTimeLine

        if (title != other.title) return false
        if (content != other.content) return false

        return true
    }


    override fun hashCode(): Int {
        var result = if (title != null) title!!.hashCode() else 0
        result = 31 * result + if (content != null) content!!.hashCode() else 0
        return result
    }

    override fun toString(): 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 itme you want to represent.

Create an Array of your Timelines

 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> {
            override fun onBindView(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

     fun swapItems(timeLines: List<T>)
  • Update a single item given teh index

     fun updatItem(timeline: T, position: Int) 
  • Adds a list of items to the list

     fun addItems(vararg items: T)

Changelog

See the changelog file.

License

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

timelineview's People

Contributors

jerryokafor avatar

Stargazers

Nosa Clement Obasuyi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.