Giter VIP home page Giter VIP logo

realm-recyclerview's Introduction

A RecyclerView that is powered by Realm

Latest 0.9.25 is built with Realm 2.2.1.

A powerful Recyclerview wrapper for working with Realm as your datastore. It supports the following features out of the box:

  • Custom adapter that automatically refreshes the list when the realm changes and animates the new items in.
  • Empty state
  • Pull-to-refresh (backed by SwipeRefreshLayout)
  • Infinite scrolling (callback for more data fetching)
  • Section headers (backed by SuperSLiM)

##How To Include It:

    allprojects {
        repositories {
            // ...
            maven { url "https://jitpack.io" }
        }
    }
	dependencies {
	        compile 'com.github.thorbenprimke:realm-recyclerview:0.9.25'
	}

##Demo

Screenshot

How To Get Started:

The RealmRecyclerView has a few attributes that can be set in XML in order to customize it's look and feel and most importanlty which layoutType is used. In addition, it relies on an extended RecyclerView.Adapter called RealmBasedRecyclerViewAdapter to provide support for animation and headers.

##RealmRecyclerView

The snippet below shows how to include the RealmRecyclerView in your layout file.

    <co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
        android:id="@+id/realm_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:rrvIsRefreshable="true"
        app:rrvEmptyLayoutId="@layout/empty_view"
        app:rrvLayoutType="LinearLayout"
        />

Important to note here is that the app:rrvLayoutType attribute has to be set. It determines which LayoutManager will be used. The options are:

  • LinearLayout
  • Grid
  • LinearLayoutWithHeaders

All these will yield vertical linear or grid layouts.

###Other Attributes:

rrvIsRefreshable: Adds the pull-to-refresh feature to the recyclerView. In order to receive the refresh events, a listner has to be set via setOnRefreshListener and setRefreshing is used to control either turn the refersh animation on/off.

rrvEmptyLayoutId: A custom empty state view can be provided via this attribute. Whenever the list has no item, the empty state is shown.

rrvGridLayoutSpanCount: This attribute has to be set with an integer greater than zero when the rrvLayoutType is set to Grid unless rrvGridLayoutItemWidth is set.

rrvGridLayoutItemWidth: This attribute has to be set with a size value that represents the width of a grid column when the rrvLayoutType is set to Grid unless rrvGridLayoutSpanCount is set.

rrvSwipeToDelete: This attribute is only supported with rrvLayoutType of LinearLayout. If set to true, swiping a row to delete is enabled. The row is deleted from the Realm directly.

##RealmBasedRecyclerViewAdapter:

The heart of the RealmRecyclerView's functionality comes from this custom RecyclerView.Adapter. It includes support for insertion/deletion animation whenever the Realm changes. It also inculde the logic to generate the headers for the list's contents if it's of type LinearLayoutWithHeaders.

  • automaticUpdate: If automaticUpdate is set, the RealmResults are automatially updated and the list is refershed with new results.

  • animateResults: If animateResults is set together with automaticUpdate, the automatic updates are animated. This is limited to a single deletion or insertion. If it's more than one item, it will simply refresh the list. The animation leverages the resuls primary key column in order as a unique identifier for each row. Therefore your Realm's schema needs to include a primary key column of type Integer or String.

  • addSectionHeaders: When the rrvLayoutType is LinearLayoutWithHeaders, addSectionHeaders needs be set in order for the adapter to generate the headers. The headerColumnName needs to be set as well in order to look up the header column programmatically your Realm's schema. Note: There is currently no support for customizing the header and it is always inline|sticky.

##Feedback/More Features: I would love to hear your feedback. Do you find the RealmRecyclerView useful? What functionality are you missing? Open a Github issue and let me know. Thanks!

License

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.

Included dependencies are:
Realm (https://github.com/realm/realm-java)
SuperSLiM/Tonic Artos (https://github.com/TonicArtos/SuperSLiM)

realm-recyclerview's People

Contributors

4xes avatar allsimon avatar callmepeanut avatar carlbenson avatar dereklucas avatar dkpalmer avatar donnfelker avatar eyecreate avatar fabioranieri avatar jkreiser avatar lujop avatar mplacona avatar papjohn24 avatar sirrah avatar skhaz avatar thorbenprimke avatar vitas avatar xoex 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

realm-recyclerview's Issues

EmptyLayout issues while using Footers and/or Headers

While using Footers (by addFooter):
The emptyLayout is never shown even when list size is 0.

Another issue I found is when using Headers.
If the list starts from 0 objects and I add objects, let's say by pressing a button, the view does not update and remains empty (with or without an emptyLayout). But when i close and reopen that activity, the list populates, and if we start from a list that already has objects in it, there is no problem. But if I call mRealm.delete(Object.class) and start adding again, the same problems occurs and nothing populates.

Change Loading text color (when enabling loadmore)

Hello,

I am using RealmRecyclerView in my app, the problem is that the default background of my application is black, and so i can not see the "Loading" text when the recycler is loading more views.

How can one change the text color of the "Loading" text?

With regards,
Hay.

Error at the dependencies

Error:(29, 13) Failed to resolve: com.github.thorbenprimke:realm-recycler-view:0.9.5

Then what min SDK does the project support?

A better swipe to delete

Hello thobenprimke, first of all , awesome efforts put into making something that works with Realm. Since you mentioned "What functionality are you missing? Open a Github issue and let me know." I thought I'd suggest an improvement.

I do notice that the item gets deleted on the screen when you swipe it, though its not that obvious yet. One of the first and simplest improvements you can do is to let people remove items using this https://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.html from the RecyclerView , Here is a detailed usage guide https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf just in case. I am playing with the samples currently, if I find something I'll let you know. Thanks and keep up the good work

Pull-to-refresh only works once.

I am using the following code to create a refresh listener
But this works only the first time. When I pull-to-refresh again the onRefresh() method is not called.
Am I doing something wrong.

mForecastRecyclerView.setOnRefreshListener(new RealmRecyclerView.OnRefreshListener() {
        @Override public void onRefresh() {
            Toast.makeText(activity, "Refreshing", Toast.LENGTH_LONG).show();

            // refresh work

            mForecastRecyclerView.setRefreshing(false);
        }
    });

How to access addItemDecoration (To add line separators)?

Hey, was just curious what the best way to go about adding decorations/line separators between each item in the RecyclerView?

I'm new to Java and Android, so I may be missing another solution that would work better in this situation. But, I came across these examples:

However, in the case of RealmRecyclerView the addItemDecoration method is not exposed. My thinking was it could be exposed right about here: https://github.com/thorbenprimke/realm-recyclerview/blob/master/library/src/main/java/co/moonmonkeylabs/realmrecyclerview/RealmRecyclerView.java#L330

I'd be up for forking and adding a wrapper method to expose addItemDecoration but I am not sure about best practices in terms of variable arguments? Is method overloading the way to go? Or varargs?

Appreciate any help (and thanks for the great library!)

Add header

Adding header support(Not section headers). I need to create "classic construction list" with header and footer.

Section headers?

I'm having a really hard time trying to implement section headers with the realm recycler view.. Is there any chance you could upload an example? I'm looking to create different sections with separate realm queries.

hasLoadMoreFired never set back to false after loading more

Right before onLoadMore() is triggered, the flag boolean hasLoadMoreFired is set to true to avoid calling this method several times. Problem is its never set to false again so onLoadMore() only is going to be called once.

Since it is a private member, it needs to be exposed so we can set it back to false when we finish the load of more data.

notifyItemChanged() question

hello thorbenprimke,
first of all thank you for your great work, I'm quite new to realm and your library is working quite well for me.
I was wondering if when editing an item I'm supposed to be using notifyItemChanged() (like I would do normally) or there is a better way to do it. Without it the item isn't refreshed automatically.

can not build library

Android Studio was unable to sync the gradle files of this library.

java.lang.NullPointerException
    at com.intellij.openapi.util.io.FileUtilRt.toSystemIndependentName(FileUtilRt.java:207)

The only useful info I could find outside that is that running gradle using the shell wrapper fails at this step: :library:processDebugResources

build error

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.company.suits.yourweek"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'joda-time:joda-time:2.9.2'
compile 'com.github.thorbenprimke:realm-recyclerview:0.9.12'
}

Upgrade Realm to 0.88.X

This is (probably) a big change since it Realm has changed to a gradle plugin. I'm starting to upgrade my app to 0.88.2 so as I do that, I'll take a stab at this as well. (Unless @Sirrah wants to!)
Unfortunately none of the other add-ons listed on Realm.io have upgraded to 0.88, so I don't see any similar libraries to cargo cult from.

clipToPadding="false" Is not working.

Hey everyone, I'm trying to add a paddind in the top and bottom and use the atribute clipToPadding="false" on xml to prevent my floating Action Button to overlap my RealmRecyclerView's information.
On the RecyclerView it's works okay, but it's don't seems to work on RealmRecyclerView.
It's a bug or I'm doing something wrong?

Crash when adding "Belgium" in section example

Crash if inserting place far from visible area.
For repeat exception:

  1. Open "SEСTION HEADER LAYOUT EXAMPLE"
  2. Scroll to D.
  3. Click "ADD BELGIUM"
  4. See crash.
 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: co.moonmonkeylabs.realmrecyclerview.example, PID: 20150
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
        at com.tonicartos.superslim.LayoutManager.getAnchorAtEnd(LayoutManager.java:1038)
        at com.tonicartos.superslim.LayoutManager.fillNextSectionToEnd(LayoutManager.java:725)
        at com.tonicartos.superslim.LayoutManager.layoutChildren(LayoutManager.java:1369)
        at com.tonicartos.superslim.LayoutManager.onLayoutChildren(LayoutManager.java:276)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
        at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1482)
        at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:147)
        at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:294)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
        at android.view.Choreographer.doFrame(Choreographer.java:603)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

It happen after recyclerview was notified about inserting one element.

Cannot connect

I can't connect this library. When I try to connect with it (compile 'com.github.thorbenprimke:realm-recyclerview:0.9.7') in build.gradle I take error
When I try to find it in maven or anywhere also I have no results.

columnIndex is less than 0.

Everytime i try to set the RealmAdapter i get the following error:
Caused by: java.lang.ArrayIndexOutOfBoundsException: columnIndex is less than 0.
Has anyone gone throught this?

Remove refreshing animation

Hi @thorbenprimke, i'm having an issue that i'm struggling to figure out with removing the refreshing animation.

Ok so i'll just do a quick explanation of what i'm doing. When the users pulls to refresh i check to see if they have a network connection and if they don't i show an error message along with realmRecyclerView.setRefreshing(false). This works great the first time, the error is shown and the animation gets removed.

But when this is done a second time the animation is endless and the pull to refresh doesn't seem to trigger my onRefreshListener. I'm using an adapter with automatic updates set to true and i wonder if the fact my data has not changed has anything to do with it as i cannot seen why it would be a problem.

I have no such issues with it when i need to remove the animation when i have a network connection and i get data from my api.

Thanks for your hardwork. I'll have a look at the source in the meantime to see if i can find anything.

AbstractMethodError

Ok,so even your demo project is crashing with :

                          Process: co.moonmonkeylabs.realmrecyclerview.example, PID: 24363
                                                                                         java.lang.AbstractMethodError: abstract method "void io.realm.RealmChangeListener.onChange(java.lang.Object)"
                                                                                             at io.realm.RealmResults.notifyChangeListeners(RealmResults.java:1032)
                                                                                             at io.realm.RealmResults.notifyChangeListeners(RealmResults.java:1018)
                                                                                             at io.realm.HandlerController.notifyRealmResultsCallbacks(HandlerController.java:296)
                                                                                             at io.realm.HandlerController.notifySyncRealmResultsCallbacks(HandlerController.java:277)
                                                                                             at io.realm.HandlerController.notifyTypeBasedListeners(HandlerController.java:268)
                                                                                             at io.realm.HandlerController.notifyAllListeners(HandlerController.java:255)
                                                                                             at io.realm.HandlerController.realmChanged(HandlerController.java:378)
                                                                                             at io.realm.HandlerController.handleMessage(HandlerController.java:110)
                                                                                             at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                                             at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Are you guyz still maintaining this or what ?

getRecyclerView method?

In my app I need to access the recycler view inside the realm recycler view. I am doing this to attach an item touch helper to the recycler view. Is there any way that I can accomplish this?

Remove Pull Animation and make Setting Item Background working

(1) I am setting my recycler item background to this: android:background="?attr/selectableItemBackground". But it doesnt work when I click on one item.

(2) I am getting an animation when I am pulling down from the top but I havent set it refreshable. How can I turn this off?

pull

Cannot customize header names overriding createHeaderFromColumnValue

Extending RealmBasedRecyclerViewAdapter when writing using Kotlin introduces a problem when overriding createHeaderFromColumnValue because the method is called in the super class constructor. Therefore only hard-coded strings work since any string interpolation is impossible unless you expose the injected context object from the base class or postpone calling createHeaderFromColumnValue until later.

e.g.

class DreamRecyclerViewAdapter(val context: Context,
                               results: RealmResults<Dream>,
                               automaticUpdate: Boolean,
                               animateIdType: Boolean,
                               addSectionHeaders: Boolean = false,
                               headerColumnName: String? = null) :
        RealmBasedRecyclerViewAdapter<Dream, DreamItemViewHolder>(context, results, automaticUpdate, animateIdType, addSectionHeaders, headerColumnName) {

    override fun createHeaderFromColumnValue(columnValue: String) = when (columnValue) {
        // context is null here because this method is called in super class constructor
        // and any value injected will be uninitialized before super constructor has finished.
        "accomplished" -> context.getString(R.string.transaction_dream_accomplished_header)
        "cancelled" -> context.getString(R.string.transaction_dream_cancelled_header)
        else -> context.getString(R.string.transaction_dream_active_header)
    }
}

Store context or expose it as a protected field or method

Use case:
My implementation of adapter needs a context do decode resources for createHeaderFromColumnValue() implementation

The problem is that this method is called from super RealmBasedRecyclerViewAdapter constructor and I've no way to get it.

Is there a way to scroll to the top when I add new Item in the top

Hello

I use realm-recyclerview

And I use .findAllSorted("date", Sort.DESCENDING)

The problem is when I add new Item

well be added in the top but I can see it

I need to scroll up manually

Is there a way to scroll to the top automatically

from realmAdapter or from realmRecyclerview automatically when there is any thing add to the recyclerview

LoadMore

Hello
I have trouble with load more. This method single executed.

How to change ViewHolder type?

Hi
I make chat-like ui and use your awesome library for creating conversaion list.
How to change ViewHolder type on onCreateRealmViewHolder or onBindRealmViewHolder? Example: recycleview with two type items - recived and sent message view (use different resources).

0.87.5

I have an issue coming from this version. I have read the discussion from here. I have got Mutable method call during read transaction when i try to remove one item from the list.

Enhancement: Option to override default dismiss callback

I find the default dismiss callback implementation insufficient for my needs. Is it possible if you can add an option to override the default dismiss callback. This way, we can delete the RealmObject ourselves and will allow us to show a snackbar to the user for a nice action feedback. Thank you.

upgrade to Realm 0.89.0

Please upgrade to Realm 0.89.0.
In my project I use this versione and now I had this error:

FATAL EXCEPTION: 
    java.lang.NoSuchMethodError: No virtual method get(I)Lio/realm/RealmObject; in class Lio/realm/RealmResults; or its super classes (declaration of 'io.realm.RealmResults' appears in /data/data/<package>/files/instant-run/dex/slice-io.realm-realm-android-library-0.89.0_1e0e323ab8ec35a6ebf8c8bfff373693aed24725-classes.dex)
    at io.realm.RealmBasedRecyclerViewAdapter.getRealmRowId(RealmBasedRecyclerViewAdapter.java:376)
    at io.realm.RealmBasedRecyclerViewAdapter.getIdsOfRealmResults(RealmBasedRecyclerViewAdapter.java:367)
    at io.realm.RealmBasedRecyclerViewAdapter.updateRealmResults(RealmBasedRecyclerViewAdapter.java:335)
    at io.realm.RealmBasedRecyclerViewAdapter.<init>(RealmBasedRecyclerViewAdapter.java:198)
    at io.realm.RealmBasedRecyclerViewAdapter.<init>(RealmBasedRecyclerViewAdapter.java:105)

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.