README.md 3.16 KB
Newer Older
Kirill Zhukov's avatar
Kirill Zhukov committed
1 2
# Adept

Kirill Zhukov's avatar
Kirill Zhukov committed
3
Simple multiview adapter for RecyclerView without ViewHolder written in Kotlin
Kirill Zhukov's avatar
Kirill Zhukov committed
4 5 6 7

# Features

* Multiview support
Kirill Zhukov's avatar
Kirill Zhukov committed
8
* AndroidX compatible
Kirill Zhukov's avatar
Kirill Zhukov committed
9 10 11
* No ViewHolder
* Auto DiffUtils
* Fluent API
12
* Endless scrolling support
Kirill Zhukov's avatar
Kirill Zhukov committed
13
* Nested RecyclerView state saving support
Kirill Zhukov's avatar
Kirill Zhukov committed
14
* Payloads support
Kirill Zhukov's avatar
Kirill Zhukov committed
15
* Easy Picasso, Glide or Fresco usage with extensions
Kirill Zhukov's avatar
Kirill Zhukov committed
16 17 18

# Installation

Kirill Zhukov's avatar
Kirill Zhukov committed
19
### 1. Add the JCenter repository to your build file
Kirill Zhukov's avatar
Kirill Zhukov committed
20
```gradle
Kirill Zhukov's avatar
Kirill Zhukov committed
21 22 23 24 25 26 27 28
allprojects {
	repositories {
		...
		jcenter()
	}
}
```
### 2. Add the dependency
Kirill Zhukov's avatar
Kirill Zhukov committed
29
```gradle
Kirill Zhukov's avatar
Kirill Zhukov committed
30
ext {
Kirill Zhukov's avatar
Kirill Zhukov committed
31
    adept_version = '2.0.1'
Kirill Zhukov's avatar
Kirill Zhukov committed
32 33
}

Kirill Zhukov's avatar
Kirill Zhukov committed
34
dependencies {
Kirill Zhukov's avatar
Kirill Zhukov committed
35
    // Core library module
Kirill Zhukov's avatar
Kirill Zhukov committed
36
    implementation "pro.siper.adept:adept-core:$adept_version"
Kirill Zhukov's avatar
Kirill Zhukov committed
37
    // Picasso extension
Kirill Zhukov's avatar
Kirill Zhukov committed
38
    implementation "pro.siper.adept:adept-extension-picasso:$adept_version"
Kirill Zhukov's avatar
Kirill Zhukov committed
39
    // Glide extension
Kirill Zhukov's avatar
Kirill Zhukov committed
40
    implementation "pro.siper.adept:adept-extension-glide:$adept_version"
Kirill Zhukov's avatar
Kirill Zhukov committed
41
    // Fresco extension
Kirill Zhukov's avatar
Kirill Zhukov committed
42
    implementation "pro.siper.adept:adept-extension-fresco:$adept_version"
Kirill Zhukov's avatar
Kirill Zhukov committed
43 44
    // Kotlin experimental extension
    implementation "pro.siper.adept:adept-extension-experimental:$adept_version"
Kirill Zhukov's avatar
Kirill Zhukov committed
45 46 47 48 49 50
}
```

# Usage

### 1. Create your Adapter
Kirill Zhukov's avatar
Kirill Zhukov committed
51
```kotlin
Kirill Zhukov's avatar
Kirill Zhukov committed
52 53 54
val adapter = Adept()
```
### 2. Register view renderer
Kirill Zhukov's avatar
Kirill Zhukov committed
55
```kotlin
Kirill Zhukov's avatar
Kirill Zhukov committed
56
adapter.addRenderer<SmallImageLeft>(R.layout.small_image_left_item) { data, viewBinder, payloads ->
Kirill Zhukov's avatar
Kirill Zhukov committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70
                           val item = data.unsplashItem
                           viewBinder.apply {
                               text(R.id.created_at, "${item?.createdAt}")
                               text(R.id.width_height, "${item?.width}x${item?.height}")

                               picasso(R.id.image, item?.urls?.regular, picasso) {
                                   it.fit()
                               }

                               click(R.id.card) {
                                   toast(item?.user?.name)
                               }
                           }
                       }
Kirill Zhukov's avatar
Kirill Zhukov committed
71 72
```
### 3. Attach you adapter to RecyclerView
Kirill Zhukov's avatar
Kirill Zhukov committed
73
```kotlin
Kirill Zhukov's avatar
Kirill Zhukov committed
74 75 76 77 78 79 80
recyclerView.adapter = adapter

// or

adapter.attachTo(recyclerView)
```
### 4. Update dataset
Kirill Zhukov's avatar
Kirill Zhukov committed
81
```kotlin
Kirill Zhukov's avatar
Kirill Zhukov committed
82 83
adapter.updateDataset(list)
```
Kirill Zhukov's avatar
Kirill Zhukov committed
84 85 86 87 88 89 90 91 92 93 94
# Kotlin experimental extension
If you want to use ExperimentalViewBinder you should add kotlin-android-extensions plugin into you gradle.build file
```gradle
apply plugin: 'kotlin-android-extensions'
```
and turn on experimental functions:
```gradle
androidExtensions {
    experimental = true
}
```
Kirill Zhukov's avatar
Kirill Zhukov committed
95 96 97
# Third-party libraries used in sample project

* [Picasso](http://square.github.io/picasso/)
Kirill Zhukov's avatar
Kirill Zhukov committed
98
* [Glide](https://github.com/bumptech/glide)
Kirill Zhukov's avatar
Kirill Zhukov committed
99
* [Fresco](http://frescolib.org/)
Kirill Zhukov's avatar
Kirill Zhukov committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
* [Retrofit2](http://square.github.io/retrofit/)
* [Gson](https://github.com/google/gson)

# License

```
Copyright 2018 Kirill Zhukov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```