Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ContentObservable] Added loadCursor and registerContentObserver #174

Closed
wants to merge 2 commits into from
Closed

Conversation

henrytao-me
Copy link

Hi all, I think it's quite interesting and useful to have these two methods when you want to handle cursor outside loaderManager lifecycle. I will write more test cases then.

Current code

public void loadCursorInBackground(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, final AsyncCallback<Cursor> callback) {
    start(callback);
    execute(new Runnable() {
      @Override
      public void run() {
        try {
          Cursor cursor = mContext.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
          success(callback, cursor);
        } catch (Exception e) {
          failure(callback, e);
        }
      }
    });
}

Rx code

ContentObservable.loadCursor(getActivity(), uri, projection, selection, selectionArgs, sortOrder)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(cursor -> onCursorLoaded(cursor))

Current code

ContentResolver contentResolver = activity.getContentResolver();
contentResolver.registerContentObserver(ChatMessageProvider.CONTENT_URI, false, mChatRoomContentObserver);

Rx code

ContentObservable.registerContentObserver(getActivity(), ChatMessageProvider.CONTENT_URI, false)
          .subscribeOn(Schedulers.io())
          .subscribe(selfChange -> loadChatRoomInBackground())

@lykhonis
Copy link

This ties to ContentResolver specifically, but we can have SQLiteDatabase and other potential Cursor providers. What about this way: #180 ?

@JakeWharton
Copy link
Member

As part of #172 this functionality has been removed from future releases. SqlBrite is about to have a 0.2 (probably today) and has functionality like this.

@Rainer-Lang
Copy link

@JakeWharton Should we all use SqlBrite? Is this the way to get functionality for ContentObservable back? What do you suggest?

@mttkay
Copy link
Collaborator

mttkay commented Aug 28, 2015

We’re also in the process of open sourcing a storage API that has natural
mappings to Rx (and comes with an Rx wrapper). It doesn’t use
ContentProvider though if that’s what you’re looking for.

On Fri, Aug 28, 2015 at 4:46 PM, Rainer-Lang notifications@github.com
wrote:

@JakeWharton https://github.com/JakeWharton Should we all use SqlBrite?
Is this the way to get functionality for ContentObservable back? What do
you suggest?


Reply to this email directly or view it on GitHub
#174 (comment).

Matthias Käppler

Engineer

Twitter: https://twitter.com/mttkay

Skype: matthias-sc

SoundCloud Ltd. | Rheinsberger Str. 76/77, 10115 Berlin, Germany | +49
(0)172 2345679

Managing Director: Alexander Ljung | Incorporated in England & Wales
with Company
No. 6343600 | Local Branch Office | AG Charlottenburg | HRB 110657B

Capture and share your music & audio on SoundCloud
http://soundcloud.com/creators

@erickok
Copy link

erickok commented Aug 28, 2015

There are many solutions already available, with more or less features and more or less Rx foxus, such as SqlBrite, RxCupboard, StorIO. Also looking forward to see mtkay's solution. But typically NOT as part of RxAndroid.

@Rainer-Lang
Copy link

@mttkay Could you give me some informations?
@erickok Thanks. I know the 3 libs - and maybe I'm using StorIO. But it's lot of work to migrate from an orm-lib....

@artem-zinnatullin
Copy link
Contributor

BTW, if somebody has questions about StorIO — feel free to ask me (or file a question on SO) .

Main difference from SQLBrite and RxCupboard — all operations (Put, Get, Delete) can be executed as Observable, so you don't need to do manual multithreading. + Builders, Immutability and so on.

@Rainer-Lang
Copy link

I decided to use StorIO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants