Skip to content

Commit

Permalink
Prepare for release 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
drakeet committed Dec 9, 2019
1 parent fb84f1a commit 72a7296
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# MultiType Releases

### Version 4.1.0 - Dec 9, 2019

- Add `ItemViewDelegate` & `onCreateViewHolder(context, _)` (#292)
- Kotlin 1.3.61

### Version 4.0.0 - Sep 7, 2019

- Migrate to com.drakeet group (#267)
Expand Down
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ An Android library makes it easier and more flexible to create multiple types of

[![Build Status](https://travis-ci.org/drakeet/MultiType.svg?branch=3.x)](https://travis-ci.org/drakeet/MultiType)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/drakeet/MultiType/blob/master/LICENSE)
![maven-central](https://img.shields.io/maven-central/v/me.drakeet.multitype/multitype.svg)
![maven-central](https://img.shields.io/maven-central/v/com.drakeet.multitype/multitype.svg)
![jetbrains-plugin](https://img.shields.io/jetbrains/plugin/v/9202-a8translate.svg)

Previously, when we need to develop a complex RecyclerView / ListView, it is difficult and
Expand All @@ -23,7 +23,7 @@ _In addition, since 4.0.0 we have migrated to fully build with Kotlin. If you do

```groovy
dependencies {
implementation 'com.drakeet.multitype:multitype:4.0.0'
implementation 'com.drakeet.multitype:multitype:4.1.0'
}
```

Expand All @@ -37,20 +37,22 @@ data class Foo(
)
```

#### Step 2. Create a class extends `ItemViewBinder<T, VH : ViewHolder>`, for example:
#### Step 2. Create a class extends `ItemViewDelegate<T, VH : ViewHolder>`, for example:

```kotlin
class FooViewBinder: ItemViewBinder<Foo, FooViewBinder.ViewHolder>() {
class FooViewDelegate: ItemViewDelegate<Foo, FooViewDelegate.ViewHolder>() {

override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
return ViewHolder(inflater.inflate(R.layout.item_foo, parent, false))
override fun onCreateViewHolder(context: Context, parent: ViewGroup): ViewHolder {
// If you want a LayoutInflater parameter instead of a Context,
// you can use ItemViewBinder as the parent of this class.
return ViewHolder(FooView(context))
}

override fun onBindViewHolder(holder: ViewHolder, item: Foo) {
holder.fooView.text = item.value
Log.d("ItemViewBinder API", "position: ${getPosition(holder)}")
Log.d("ItemViewBinder API", "items: $adapterItems")
Log.d("ItemViewBinder API", "adapter: $adapter")
Log.d("ItemViewDelegate API", "position: ${getPosition(holder)}")
Log.d("ItemViewDelegate API", "items: $adapterItems")
Log.d("ItemViewDelegate API", "adapter: $adapter")
Log.d("More", "Context: ${holder.itemView.context}")
}

Expand All @@ -73,9 +75,9 @@ class SampleActivity : AppCompatActivity() {
setContentView(R.layout.activity_list)
val recyclerView = findViewById<RecyclerView>(R.id.list)

adapter.register(TextItemViewBinder())
adapter.register(ImageItemViewBinder())
adapter.register(RichItemViewBinder())
adapter.register(TextItemViewDelegate())
adapter.register(ImageItemViewDelegate())
adapter.register(RichItemViewDelegate())
recyclerView.adapter = adapter

val textItem = TextItem("world")
Expand All @@ -101,19 +103,19 @@ class SampleActivity : AppCompatActivity() {

```kotlin
adapter.register(Data::class).to(
DataType1ViewBinder(),
DataType2ViewBinder()
DataType1ViewDelegate(),
DataType2ViewDelegate()
).withKotlinClassLinker { _, data ->
when (data.type) {
Data.TYPE_2 -> DataType2ViewBinder::class
else -> DataType1ViewBinder::class
Data.TYPE_2 -> DataType2ViewDelegate::class
else -> DataType1ViewDelegate::class
}
}
```

See `OneDataToManyActivity`, `OneToManyFlow` and `OneToManyEndpoint` for more details.

**More methods that you can override from [ItemViewBinder](library/src/main/kotlin/me/drakeet/multitype/ItemViewBinder.kt)**:
**More methods that you can override from [ItemViewDelegate](library/src/main/kotlin/me/drakeet/multitype/ItemViewDelegate.kt)**:

```kotlin
open fun onBindViewHolder(holder: VH, item: T, payloads: List<Any>)
Expand All @@ -128,7 +130,7 @@ open fun onViewDetachedFromWindow(holder: VH)

- **[drakeet/MultiTypeTemplates](https://github.com/drakeet/MultiTypeTemplates)**

An intellij idea plugin for Android to generate `MultiType` `Item` and `ItemViewBinder` easily.
An intellij idea plugin for Android to generate `MultiType` `Item` and `ItemViewDelegate` easily.

<img src="http://ww4.sinaimg.cn/large/86e2ff85gw1f8yj0sejd6j21340ben1s.jpg" width=640/>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ buildscript {
ext.annotationVersion = '1.1.0'
ext.appcompatVersion = '1.0.2'
ext.buildConfig = [
'versionCode': 405,
'versionName': "4.0.0",
'versionCode': 410,
'versionName': "4.1.0",
'compileSdkVersion': 29,
'minSdkVersion': 14,
'targetSdkVersion': 28
Expand Down

0 comments on commit 72a7296

Please sign in to comment.