Need help with RxRecyclerAdapter?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

ahmedrizwan
194 Stars 29 Forks 73 Commits 4 Opened issues

Description

Rx based RecyclerView Adapter

Services available

!
?

Need anything else?

Contributors list

# 19,270
Android
Kotlin
android...
Shell
47 commits
# 128,497
Kotlin
kotlin-...
pairing
Android
6 commits
# 128,295
excel
data-fr...
dtw
scalajs
1 commit
# 1,620
image-f...
assembl...
netfram...
residua...
1 commit

RxRecyclerAdapter

Release GitHub license Android Arsenal

Rx based generic RecyclerView Adapter Library.

How to use it?

Example!

  • Enable Databinding by adding these lines to your build.gradle
    kotlin
    dataBinding {
      enabled = true
    }
    
  • Create the layout file ```xml <?xml version="1.0" encoding="utf-8"?>

    
    

    </li>
    <li>
    <p>Create your dataSet
    </p>
    <pre>kotlin
    //Dummy DataSet
    val dataSet = mutableListOf<string>()
    dataSet.add("Lorem")
    dataSet.add("ipsum")
    dataSet.add("dolor")
    dataSet.add("sit")
    dataSet.add("amet")
    </string></pre>
    </li>
    <li><p>Create RxDataSource
    ```kotlin
    // Simple data source
    val rxDataSource = RxDataSource<itemlayoutbinding string>(R.layout.item_layout, dataSet)</itemlayoutbinding></p></li>
    </ul>
    
    <p>rxDataSource
            .map { it.toUpperCase() }
            .repeat(4)
            .asObservable()
            .subscribe {
                val binding = it.viewDataBinding ?: [email protected]
                binding.textViewItem.text = it.item
            }

    And that's it! The recyclerView is going to show

    Changing the data dynamically

    Simply call updateAdapter after making changes to the dataSet and that'll do the trick!

    rxDataSource.map(...).filter(...).take(...).updateAdapter();
    

    Adapter for multiple View Types

    If multiple view types are required for your recyclerView, let's say, we have two types HEADER and ITEM then the coding steps will be :- - Enable Databinding - Create a list of ViewHolderInfo

    kotlin
    //ViewHolderInfo List
    val viewHolderInfoList = ArrayList()
    viewHolderInfoList.add(ViewHolderInfo(R.layout.item_layout, TYPE_ITEM))
    viewHolderInfoList.add(ViewHolderInfo(R.layout.item_header_layout, TYPE_HEADER))
    
    - Create an instance of RxDataSourceSectioned implementation
    kotlin
     // Sectioned data source
    val rxDataSourceSectioned = RxDataSourceSectioned(dataSet, viewHolderInfoList, object : OnGetItemViewType() {
        override fun getItemViewType(position: Int): Int {
            if (position % 2 == 0) { // even are headers
                return TYPE_HEADER
            }
            return TYPE_ITEM
        }
    })
    
    - Compose and call bindRecyclerView passing in recyclerView, viewHolderInfoList and viewTypeCallBack ```kotlin rxDataSourceSectioned .asObservable() .subscribe { val viewDataBinding = it.viewDataBinding val data = it.item
        when (viewDataBinding) {
            is ItemLayoutBinding -> viewDataBinding.textViewItem.text = "ITEM: " + data
            is ItemHeaderLayoutBinding -> viewDataBinding.textViewHeader.text = "HEADER: " + data
        }
    }
    
    And the output would look something like
    
    
    
    

    More examples and details here

    How to update adapter?

    You can update all the data set by call updateDataSet(), then call updateUdapter() to update the adapter (get "notifiyDataSetChange()" effect)

    ```kotlin rxDataSource.updateDataSet(newDataSet) rxDataSource.updateAdapter()

    If you want to update one item of the data set, you can use updateDataSet(updatedList, effectedPosition, transactionType),

    kotlin
    rxDataSource.updateDataSet(
      dataSet.apply { removeAt(deletedPosition) },
      deletedPosition,
      RxDataSource.TransactionTypes.DELETE
    )
    

    Download

    Repository available on jCenter

    implementation 'com.minimize.android:rxrecycler-adapter:1.3.2'
    

    If the dependency fails to resolve, add this to your project repositories

    Gradle
    repositories {
      maven {
          url  "http://dl.bintray.com/ahmedrizwan/maven"
      }
    }
    

    License

    Copyright 2015 Ahmed Rizwan
    
    

    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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.