|
| 1 | +# TimeLineView |
| 2 | +Android Timeline View Library demostratgin the the power of ConstraintnLayout and RecyclerView. |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +[](https://jitpack.io/#po10cio/TimeLineView) |
| 7 | +[](https://github.com/po10cio/TimeLineView/blob/master/LICENSE.md) |
| 8 | + |
| 9 | + |
| 10 | +##Showcase |
| 11 | +<img src="sc/sc1.png" alt="ExampleMain" width="240"> |
| 12 | +<img src="sc/sc2.png" alt="ExampleMain" width="240"> |
| 13 | + |
| 14 | +##Quick Setup |
| 15 | +### 1. Include library |
| 16 | + |
| 17 | +**Using Gradle** |
| 18 | + |
| 19 | +Timelineview is currently available in on Gitpack so add the following line before every other thing if you have not done that already. |
| 20 | + |
| 21 | +```gradle |
| 22 | +allprojects { |
| 23 | + repositories { |
| 24 | + ... |
| 25 | + maven { url 'https://jitpack.io' } |
| 26 | + } |
| 27 | + } |
| 28 | +``` |
| 29 | + |
| 30 | +Then add the followinf line |
| 31 | + |
| 32 | +``` gradle |
| 33 | +dependencies { |
| 34 | + compile 'com.github.po10cio:TimeLineView:1.0.0' |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +**Using Maven** |
| 39 | + |
| 40 | +Also add the following lines before adding the maven dependency |
| 41 | + |
| 42 | +```maven |
| 43 | +<repositories> |
| 44 | + <repository> |
| 45 | + <id>jitpack.io</id> |
| 46 | + <url>https://jitpack.io</url> |
| 47 | + </repository> |
| 48 | + </repositories> |
| 49 | +``` |
| 50 | +Then add the dependency |
| 51 | + |
| 52 | +``` maven |
| 53 | +<dependency> |
| 54 | + <groupId>com.github.po10cio</groupId> |
| 55 | + <artifactId>TimeLineView</artifactId> |
| 56 | + <version>1.0.0</version> |
| 57 | + </dependency> |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | +#### Manual: |
| 62 | +**Manual - Using [Android Studio](https://developer.android.com/sdk/installing/studio.html):** |
| 63 | + * Download the library folder and import to your root application folder. |
| 64 | +You can manually achieve this step with 3 steps: |
| 65 | + |
| 66 | +1. Paste the folder library into your application at the same level of your app, build and gradle folder |
| 67 | +2. Add to your settings.gradle file the following code line: "include ':app', ':timelineview'" |
| 68 | +3. Rebuild the project |
| 69 | + * File → Project Structure → in Modules section click on "app" → Click on tab "Dependecies" → Click on the green plus → Module Dependecy → Select ":library" |
| 70 | + * Done |
| 71 | + |
| 72 | +###2. Usage |
| 73 | +In your XML layout include the Timeline View as afollows: |
| 74 | + |
| 75 | +```xml |
| 76 | + <me.jerryhanks.stepview.TimeLineView |
| 77 | + android:id="@+id/timelineView" |
| 78 | + android:layout_width="match_parent" |
| 79 | + android:layout_height="match_parent" |
| 80 | + android:layout_marginBottom="8dp" |
| 81 | + android:layout_marginLeft="8dp" |
| 82 | + android:layout_marginRight="8dp" |
| 83 | + android:layout_marginTop="16dp"> |
| 84 | + |
| 85 | +``` |
| 86 | +Then in your kotlin code, do the following: |
| 87 | + |
| 88 | + **Create a class that extends Timeline** |
| 89 | + |
| 90 | +```kotlin |
| 91 | +class MyTimeLine(status: Status, var title: String?, var content: String?) : TimeLine(status) { |
| 92 | + |
| 93 | + |
| 94 | + override fun equals(o: Any?): Boolean { |
| 95 | + if (this === o) return true |
| 96 | + if (o !is MyTimeLine) return false |
| 97 | + |
| 98 | + val that = o as MyTimeLine? |
| 99 | + |
| 100 | + if (if (title != null) title != that!!.title else that!!.title != null) return false |
| 101 | + return if (content != null) content == that.content else that.content == null |
| 102 | + } |
| 103 | + |
| 104 | + override fun hashCode(): Int { |
| 105 | + var result = if (title != null) title!!.hashCode() else 0 |
| 106 | + result = 31 * result + if (content != null) content!!.hashCode() else 0 |
| 107 | + return result |
| 108 | + } |
| 109 | + |
| 110 | + override fun toString(): String { |
| 111 | + return "MyTimeLine{" + |
| 112 | + "title='" + title + '\'' + |
| 113 | + ", content='" + content + '\'' + |
| 114 | + '}' |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +``` |
| 119 | +**Create an Array of your Timelines** |
| 120 | + |
| 121 | +```kotlin |
| 122 | +val timeLines = ArrayList<MyTimeLine>() |
| 123 | + timeLines.add(MyTimeLine(Status.COMPLETED, getString(R.string.title_1), getString(R.string.content_1))) |
| 124 | + timeLines.add(MyTimeLine(Status.UN_COMPLETED, getString(R.string.title_2), getString(R.string.content_2))) |
| 125 | + timeLines.add(MyTimeLine(Status.COMPLETED, getString(R.string.title_3), getString(R.string.content_3))) |
| 126 | + timeLines.add(MyTimeLine(Status.COMPLETED, getString(R.string.title_4), getString(R.string.content_4))) |
| 127 | + timeLines.add(MyTimeLine(Status.ATTENTION, getString(R.string.title_5), getString(R.string.content_5))) |
| 128 | + timeLines.add(MyTimeLine(Status.COMPLETED, getString(R.string.title_6), getString(R.string.content_6))) |
| 129 | + |
| 130 | +``` |
| 131 | + |
| 132 | +**Create the IndicatorAdapter and add it to the TimelineView** |
| 133 | + |
| 134 | +```kotlin |
| 135 | +val adapter = IndicatorAdapter(timeLines, this, object : TimeLineViewCallback<MyTimeLine> { |
| 136 | + override fun onBindView(model: MyTimeLine, container: FrameLayout, position: Int): View { |
| 137 | + val view = layoutInflater |
| 138 | + .inflate(R.layout.sample_time_line, |
| 139 | + container, false) |
| 140 | + (view.findViewById<TextView>(R.id.tv_title)).text = model.title |
| 141 | + (view.findViewById<TextView>(R.id.tv_content)).text = model.content |
| 142 | + |
| 143 | +//Note, you can set your onclick listeners |
| 144 | +//and do other manipulations here |
| 145 | + |
| 146 | + return view |
| 147 | + } |
| 148 | + }) |
| 149 | + timelineView.setIndicatorAdapter(adapter) |
| 150 | + adapter.swapItems(timeLines) |
| 151 | + |
| 152 | +``` |
| 153 | + |
| 154 | +## Changelog |
| 155 | + |
| 156 | +See the [changelog](/CHANGELOG.md) file. |
| 157 | + |
| 158 | + |
| 159 | +## License |
| 160 | + |
| 161 | +Time is distributed under the MIT license. [See LICENSE](https://github.com/po10cio/TimeLineView/blob/master/LICENSE.md) for details. |
0 commit comments