Java Code Examples for io.realm.RealmResults.addChangeListener()

The following are Jave code examples for showing how to use addChangeListener() of the io.realm.RealmResults class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaravelNewsApp   File: PostsFragment.java   View Source Code Vote up 6 votes
public void setupAdapter(RealmResults<Post> posts) {
    posts.addChangeListener(changeListener);
    adapter = new PostAdapter(posts);
    recyclerView.setLayoutManager(new LinearLayoutManager(App.getAppContext()));
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

}
 
Example 2
Project: devsuite-android   File: MassDataServiceImpl.java   View Source Code Vote up 6 votes
@Override
public void subscribeDataChange(Object dataIdentity, final DataChangeListener listener) {
    if (dataIdentity instanceof RealmResults) {
        RealmResults<RealmObject> realmResults = (RealmResults<RealmObject>) dataIdentity;
        realmResults.addChangeListener(new RealmChangeListener<RealmResults<RealmObject>>() {
            @Override
            public void onChange(RealmResults<RealmObject> element) {
                if (listener != null) {
                    listener.onChange();
                }
            }
        });
    }
}
 
Example 3
Project: GitHub   File: ProcessCommitTests.java   View Source Code Vote up 5 votes
@Test
@RunTestInLooperThread
@RunTestWithRemoteService(remoteService = SimpleCommitRemoteService.class, onLooperThread = true)
public void expectSimpleCommit() {
    looperThread.runAfterTest(remoteService.afterRunnable);
    remoteService.createHandler(Looper.myLooper());

    final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl)
            .directory(looperThread.getRoot())
            .build();
    final Realm realm = Realm.getInstance(syncConfig);
    final RealmResults<ProcessInfo> all = realm.where(ProcessInfo.class).findAll();
    looperThread.keepStrongReference(all);
    all.addChangeListener(new RealmChangeListener<RealmResults<ProcessInfo>>() {
        @Override
        public void onChange(RealmResults<ProcessInfo> element) {
            assertEquals(1, all.size());
            assertEquals("Background_Process1", all.get(0).getName());
            realm.close();
            user.logout();

            remoteService.triggerServiceStep(SimpleCommitRemoteService.stepB_closeRealmAndLogOut);

            looperThread.testComplete();
        }
    });

    remoteService.triggerServiceStep(SimpleCommitRemoteService.stepA_openRealmAndCreateOneObject);
}
 
Example 4
Project: GitHub   File: ProcessCommitTests.java   View Source Code Vote up 4 votes
@Test
@RunTestWithRemoteService(remoteService = ALotCommitsRemoteService.class, onLooperThread = true)
@RunTestInLooperThread
public void expectALot() throws Throwable {
    looperThread.runAfterTest(remoteService.afterRunnable);
    remoteService.createHandler(Looper.myLooper());

    final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl)
            .directory(looperThread.getRoot())
            .build();
    final Realm realm = Realm.getInstance(syncConfig);
    final RealmResults<TestObject> all = realm.where(TestObject.class).findAllSorted("intProp");
    looperThread.keepStrongReference(all);
    final AtomicInteger listenerCalledCounter = new AtomicInteger(0);
    all.addChangeListener(new RealmChangeListener<RealmResults<TestObject>>() {
        @Override
        public void onChange(RealmResults<TestObject> element) {
            int counter = listenerCalledCounter.incrementAndGet();
            int size = all.size();
            if (size == 0) {
                listenerCalledCounter.decrementAndGet();
                return;
            }
            assertEquals(0, size % 100); // Added 100 objects every time.
            assertEquals(counter * 100 - 1, all.last().getIntProp());
            assertEquals("Str" + (counter * 100 - 1), all.last().getStringProp());
            if (counter == 10) {
                remoteService.triggerServiceStep(ALotCommitsRemoteService.stepC_closeRealm);
                realm.close();
                user.logout();
                looperThread.testComplete();
            } else {
                remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
            }
        }
    });

    remoteService.triggerServiceStep(ALotCommitsRemoteService.stepA_openRealm);
    remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
}
 
Example 5
Project: LaravelNewsApp   File: PostsFragment.java   View Source Code Vote up 4 votes
public void setPosts(String criteria) {

        POSTS = criteria;

        //change the title
        Title = (POSTS);


        RealmResults<Post> posts = getPosts();

        posts.addChangeListener(changeListener);

        adapter = new PostAdapter(posts);

        recyclerView.setAdapter(adapter);
    }
 
Example 6
Project: A.scribe   File: MainPresenter.java   View Source Code Vote up 4 votes
@Override
public void start() {
    sortOrder = appPreferences.getSortOrder();
    RealmResults<Note> results = noteDataSource.loadNotes();
    results.addChangeListener(callback);
}