Skip to content

Commit

Permalink
Added Data change observable
Browse files Browse the repository at this point in the history
  • Loading branch information
hb committed May 17, 2018
1 parent 133c3e0 commit b3adaa8
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ For Kotlin also add
apply plugin: 'kotlin-kapt' //Top at build.gradle
```

## Adapter Creation




## Usage


``` kotlin
class CategoryAdapter() :EasyAdapter<Category, InflaterCategoryBinding>(R.layout.inflater_category) {
Expand All @@ -59,8 +64,6 @@ class CategoryAdapter() :EasyAdapter<Category, InflaterCategoryBinding>(R.layout
}
```

## Usage

#### 1) To Handle recycler View item Events

``` kotlin
Expand All @@ -87,7 +90,7 @@ adapter.performFilter(text, object :EasyAdapter.OnFilter<Category>{
return false //It will not include model if you return false
}

override fun onResult(data: java.util.ArrayList<Category>?) {
override fun onResult(data: ArrayList<Category>?) {
//Filtered List to do any operation
}
})
Expand All @@ -109,19 +112,19 @@ adapter.setOnLoadMoreListener(binding.recyclerView, EasyAdapter.OnLoadMoreListen

#### 4) Swipe Action

```kotlin
``` kotlin
adapter.enableSwipeAction(binding.recyclerView)
```

```kotlin
``` kotlin
override fun onCreatingHolder(binding: InflaterCategoryBinding, baseHolder: BaseHolder) {
binding.llDelete.post {
baseHolder.setEnableSwipeToDelete(binding.llCategory, 0, binding.llDelete.measuredWidth)
}
}

```
```xml
``` xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand Down Expand Up @@ -156,7 +159,7 @@ override fun onCreatingHolder(binding: InflaterCategoryBinding, baseHolder: Base

#### 5) Data Observe

```kotlin
``` kotlin
adapter.setOnDataUpdateListener {
if (it.size <= 0) {
Toast.makeText(this@MainActivity, "No Data Found", Toast.LENGTH_SHORT).show()
Expand All @@ -166,35 +169,36 @@ adapter.setOnDataUpdateListener {

#### Pro Tips

1. Use tools attribute for previewing Layout, so you don't need to always run application

- inside recyclerview
Use tools attribute for previewing Layout, so you don't need to always run application

- **recyclerview**

```xml
``` xml
tools:listitem="@layout/inflater_category"
tools:itemCount="5"
tools:orientation="horizontal"
app:layoutManager="android.support.v7.widget.GridLayoutManager"

```

- inside any layout
- **layout**

```xml
``` xml
tools:text="Sample Text"
tools:visibility="VISIBLE"
tools:background="@color/colorPrimary"
```

- you can also use android predefine sample data by
- **android predefine sample data**

```xml
``` xml
tools:text="@tools:sample/cities,first_names,us_phones,lorem,lorem/random"
tools:background="@tools:sample/backgrounds/scenic"
tools:src="@tools/avatars"
```

- you can also make your own sample data
- **custom sample data**

To create your fake/sample data folder,
just right click on the “app” folder then “new > Sample Data directory” <br />
Expand All @@ -209,15 +213,20 @@ adapter.setOnDataUpdateListener {

so it will randomly pick names and display in layout by

```xml
``` xml
tools:text="@sample/filename"
```

### [Special Thanks to] <br />
(https://github.com/alex-townsend/SwipeOpenItemTouchHelper)

https://github.com/alex-townsend/SwipeOpenItemTouchHelper
<br />
without this person cannot achieve swipe action in recyclerview


https://android.jlelse.eu/android-tools-attributes-listitem-sample-data-rocks-bbf49aaa9f07 <br />
for sharing knowledge of Android Tools attributes

License
=======

Expand Down

0 comments on commit b3adaa8

Please sign in to comment.