GithubHelp home page GithubHelp logo

rxrecyclerview's Introduction

NOTE

This library is DEPRECATED and not recommended for utilization, as it uses very old versions of Rx and Gradle. However, I am leaving it here so that you might be able to draw on some of the concepts if you're implementing your own version, or for you to freely fork and modify / update.

Known issues:

The gradle version / bintray version are super duper old. Please remove any references to bintray if you clone this yourself, or update them as necessary.

RxRecyclerViewAdapter Library 2.0

Crazy easy to use RecyclerView Adapter for Reactive Applications

Data Flow Visualization

Interface

  • RxRecyclerViewAdapter::onCreateViewHolder is the same as RecyclerView.Adapter
  • RxRecyclerViewAdapter::onBindViewHolder gives you the Element you are binding to
  • RxRecyclerViewAdapter::preProcessElement gives you the chance to work with elements before they enter the underlying tree set.
  • RxRecyclerViewAdapter::postProcessElement gives you the chance to work with elements after the RecyclerView has been notified of the element.
  • Event<K,V> is Immutable and takes an Event.TYPE, Key, and Value.
  • Event<K,V> also contains an UNKNOWN type and is overridable for custom processing.
  • EventElement<K,V> and it's subclasses wrap Events and contain a view type for easy addition of headers, footers, and "list is empty" view.

Creating an Adapter

You need to have an Observable that you've merged all of your event emitters into. You then need to either map those into EventElements or utilize GroupComparator and it's corresponding Operator via Observable::lift to do the conversion for you.

Sorting and Grouping your stuff

There is an interface called GroupComparator that lets you sort and group your Events. These are passed to an instance of ElementGenerationOperator which will then add in Header and Footer items, as well as handle Empty items per your provided Options. The Adapter uses a TreeSet internally, which allows for automatic sorting by natural keys (Elements subclass Comparator).

View Types

You can create your own new view types by extending the appropriate EventElement subclass, or EventElement itself. Each View type has a corresponding bit mask that are placed in the 11th and 12th bits of the View type integer. This means that when you want to know what kind of view you are looking at, you can simply shift it's view type like so: element.getViewType() >> EventElement.MASK_SHIFT and compare it to the defined static integer masks within EventElement. This allows you to do things like create your own Header elements and whatnot, with unique viewtypes, and rest assured that they'll work properly.

This system allows us to avoid using instanceof calls everywhere, and stick to switch cases.

Examples

Are available in the app module!

Licensing

This work is (C) under the MIT License.

Gradle

This has been released on Bintray

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

dependencies {
    compile 'com.exallium.rxrecyclerview:lib:2.1.2'
}

rxrecyclerview's People

Contributors

exallium avatar maadani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxrecyclerview's Issues

Existing elements are not always get updated

Hi Alex,

The Adapter is using the same set (TreeSet) to hold the data and keeping its order which results a logic when looking for elements problem.

Consider the following case:

  1. We have an Element which contains 2 int attributes: id, value.
  2. We want to display the items according to their values, so we are using the group comparator which compares the values.
  3. After two additions, the tree looks like this: the root element has value = 5 and key = 1 and one right child element with value = 10 and key = 2.
  4. Now, we want to update the element with key = 2 to have the value 3 (=> a new event is emitted with element with key = 2 and value = 3).

Expected result:
The right son of the tree should be removed and a new node (with key = 2 and value = 3) should be inserted to be inserted.

Real result:
A new node with key = 2 and value = 3 is added to the tree BUT the old node (the right child) is not removed from the tree.

This happens because the value of the new element directs the new element to a different sub tree so the old element with the same key is never compared with.

Currently, I didn't find any workaround since I can't add/remove items from my adapter class.

I think the way to go here is to hold a one set for the keys and one for the sorted values.

Thanks,

E.

API to update new items with values from old items with the same key

Hi Alex,

Can you please provide an interface / a way to update the new items with values from the items on the list?

Some UI values, like animation values, are needed to be kept after the item is updated. Since these values are UI related, the update should be done instantly (and not go through the model).

Pre version 2.0, I could have implement my own Container and do the update in the put(..) but on V2.0 I didn't find a way to do it.

At this point, I can't upgrade to 2.0.

Thanks in advance,

E.

New events are always added at the bottom of the view

The position of an item in the RxRecyclerViewAdapter is set according to the position in the key list of the internal container.
Since new keys are always added to the end of the key list, new items are always displayed at the bottom of the view.
Suggestion:
I think the RxRecyclerViewAdapter should supply a constructor which gets a Container as a parameter and use it instead of the default container. This way developers can apply their own display order.
Thanks,
E.

Subgroup Comparator Extension

Create a sub interface of GroupComparator called SectionComparator which allows for groups to be grouped themselves into sections.

Create a new liftable operator that sits between ElementGenerationOperator and the Adapter for listening to the stream and creating these section headers.

Maybe instead spend some time thinking of a more generic solution which allows for an entire hierarchy of information.

Different view types (in the same group) are not supported

According to the docs (and code), to support view types, one should extends the EventElement class.
However, when using the ElementGenerationOperator, it calls directly the EventElement constructor.

The way to work around it is to map the regular EventElement from the Observable to my own EventElement class and use the same event & group comparator and override the getViewType method. This is not a clean workaround as you need to pass the comparator twice.

can't import repo

First I got this error:
image

so I've updated many things and dependencies, but now I get this error:

image

How come? How can I overcome those?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.