RxRecyclerAdapter


Source link: https://github.com/ahmedrizwan/RxRecyclerAdapter

RxRecyclerAdapter

Rx based generic RecyclerView Adapter Library.

How to use it?

Example!

  • Enable Databinding by adding these lines to your build.gradle
dataBinding {

 enabled = true 
}
  • Create the layout file
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="@dimen/activity_horizontal_margin">

 <TextView android:id="@+id/textViewItem"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 tools:text="Recycler Item"/>

</LinearLayout> </layout>
  • Create your dataSet
//Dummy DataSet List<String> dataSet = new ArrayList<>();
 dataSet.add("This");
 dataSet.add("is");
 dataSet.add("an");
 dataSet.add("example");
 dataSet.add("of RX!");
  • Create RxDataSource
RxDataSource<String> rxDataSource = new RxDataSource<>(dataSet);
 //compose, bind and subscribe! rxDataSource.map(String::toLowerCase)

 .repeat(10)

 //cast call this method with the binding Layout

 .<ItemLayoutBinding>bindRecyclerView(recyclerView, R.layout.item_layout)

  .subscribe(viewHolder -> {

ItemLayoutBinding b = viewHolder.getViewDataBinding();

b.textViewItem.setText(viewHolder.getItem());

 
}
);

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
List<ViewHolderInfo> viewHolderInfoList = new ArrayList<>();
 viewHolderInfoList.add(new ViewHolderInfo(R.layout.item_layout, TYPE_ITEM));
 //TYPE_ITEM = 1 viewHolderInfoList.add(new ViewHolderInfo(R.layout.item_header_layout, TYPE_HEADER));
 //TYPE_HEADER = 0
  • Create an instance of OnGetItemViewType implementation
OnGetItemViewType viewTypeCallback = new OnGetItemViewType() {

 @Override public int getItemViewType(int position) {

if (position % 2 == 0) //headers are at even pos

  return TYPE_HEADER;

return TYPE_ITEM;

 
}

  
}
;
  • Compose and call bindRecyclerView passing in recyclerView, viewHolderInfoList and viewTypeCallBack
rxDataSource.map(...).filter(...)

.bindRecyclerView(recyclerView, viewHolderInfoList, viewTypeCallback)

.subscribe(vH -> {

 //Check instance type and bind!

 final ViewDataBinding b = vH.getViewDataBinding();

 if (b instanceof ItemLayoutBinding) {

final ItemLayoutBinding iB = (ItemLayoutBinding) b;

iB.textViewItem.setText("ITEM: " + vH.getItem());

 
}
 else if (b instanceof ItemHeaderLayoutBinding) {

ItemHeaderLayoutBinding hB = (ItemHeaderLayoutBinding) b;

hB.textViewHeader.setText("HEADER: " + vH.getItem());

 
}

  
}
);

And the output would look something like

More examples and details here

Download

Repository available on jCenter

compile 'com.minimize.android:rxrecycler-adapter:1.2.2'

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

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. 

Resources

This is a very simple library for Android that allows you to stick an header to a ListView and easily apply animation to it.

The StikkyHeader supports:

  • ListView
  • RecyclerView
  • ScrollView

A Gradle plugin witch automatically packs texture for a libgdx game, using libgdx texture packer. Before packing, the plugin can do some actions on the resources provided, such as:

  • Resize images for variants
  • Generate 1 pixel 9-patches automatically
  • Convert SVG to PNG images

Gradle tasks for easy integration with ImageMagick.

The code brings up an easy way of using recyclerView, with the new recycler adapters. It also contains a BaseRecyclerFragment and a RecyclerStandalone that removes a lot of boiler plate for fragments that contains either grids or lists. It also offers out of the box a DividerItemDecoration that handles the drawing of the divider in the recycler view. As well selectors for the items in your lists are handled.

RecyclerView-FlexibleDivider - Android library providing simple way to control divider items of RecyclerView.

JDeferred is a Java Deferred/Promise library similar to JQuery's Deferred Object.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes