A powerful android library coded in kotlin. It's like recyclerview but eliminated some steps of implementation.
- No more adapter implemantation
- Act like single widget
- Support muli-layout
- Add, insert, edit, remove by Item id (recommended) and item position without headache
- Support Load more
- Support custom pages like empty, preload, errors, ...
- Support vertical & horizontal orientation
- Add it in your root
build.gradle
(app level) at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency:
dependencies {
...
implementation 'com.github.ebdulrehmandemya:LinearView:v5.2'
}
For other build files, see here
class Note(val id: Long, val title: String) : Item {
companion object {
const val TYPE_ID = 1
fun bind(item: ItemText, view: View, position: Int) {
view.title.text = item.title
}
}
override fun type(): Int = TYPE_ID // required, must be unique per classe
override fun id(): Long = id // optional, should be unique per instance in the same type
}
Repeat this action for other classes that you want to use them in LinearView
- Add
org.dahatu.libs.linearview.LinearView
in layout
<!-- activity_main.xml -->
...
<org.dahatu.libs.linearview.LinearView
android:id="@+id/dlv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
...
- Somewhere in your code like
onCreate(...)
// MainActivity class
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
dlv.onManageListener(this) // set a listener, see next section
dlv.addItem(Note.createMock(id=1)) // add an item to LinearView
val items = listOf(Note.createMock(id=2), Note.createMock(id=3))
dlv.addItems(items) // add a list of items to LinearView
}
...
class MainActivity : AppCompatActivity(), OnManageListener {
...
}
- Override
OnManageListener
Methods
Method | Required | arguments | retrun | Description |
---|---|---|---|---|
layout | Yes | type : Int | @LayoutRes Int | determines the item's layout per type |
onBind | Yes | item: Item, view: View, position: Int | determines how to bind item's view and item's data together | |
preloadLayout | No | @LayoutRes Int? = null | determines a layout to show first time at once | |
emptyLayout | No | @LayoutRes Int? = null | determines a layout to show when LinearView goes empty (has no items) | |
loadMoreLayout | No | @LayoutRes Int? = null | determines a layout when the 'loadmore' action happens | |
hasMore | No | Boolean = false | determines if there is any more items to add ( loadmore's looping condition) | |
onMore | No | determines what action must be done when the loadmore calls | ||
onPageLayout | No | code: Int | @LayoutRes Int? = null | determines custom layouts such as showing error pages when working with Restful Api,... |
onPageBind | No | code: Int, view: View | determines any changes in custom page view |