當前位置: 首頁>>代碼示例>>Java>>正文


Java RealmChangeListener類代碼示例

本文整理匯總了Java中io.realm.RealmChangeListener的典型用法代碼示例。如果您正苦於以下問題:Java RealmChangeListener類的具體用法?Java RealmChangeListener怎麽用?Java RealmChangeListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RealmChangeListener類屬於io.realm包,在下文中一共展示了RealmChangeListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addListener_shouldBeCalledToReturnTheQueryResults

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
@RunTestInLooperThread
public void addListener_shouldBeCalledToReturnTheQueryResults() {
    final OsSharedRealm sharedRealm = getSharedRealmForLooper();
    populateData(sharedRealm);
    Table table = getTable(sharedRealm);

    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    looperThread.keepStrongReference(osResults);
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults osResults1) {
            assertEquals(osResults, osResults1);
            assertEquals(4, osResults1.size());
            sharedRealm.close();
            looperThread.testComplete();
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:OsResultsTests.java

示例2: addListener_shouldBeCalledWhenRefreshToReturnTheQueryResults

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
public void addListener_shouldBeCalledWhenRefreshToReturnTheQueryResults() {
    final AtomicBoolean onChangeCalled = new AtomicBoolean(false);
    final OsSharedRealm sharedRealm = getSharedRealm();
    Table table = getTable(sharedRealm);

    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults osResults1) {
            assertEquals(osResults, osResults1);
            assertEquals(4, osResults1.size());
            sharedRealm.close();
            onChangeCalled.set(true);
        }
    });
    sharedRealm.refresh();
    assertTrue(onChangeCalled.get());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:OsResultsTests.java

示例3: addListener_shouldBeCalledWhenRefreshAfterLocalCommit

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
public void addListener_shouldBeCalledWhenRefreshAfterLocalCommit() {
    final CountDownLatch latch = new CountDownLatch(2);
    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    assertEquals(4, osResults.size()); // See `populateData()`
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults element) {
            if (latch.getCount() == 2) {
                // triggered by beginTransaction
                assertEquals(4, osResults.size());
            } else if (latch.getCount() == 1) {
                // triggered by refresh
                assertEquals(5, osResults.size());
            } else {
                fail();
            }
            latch.countDown();
        }
    });
    sharedRealm.beginTransaction();
    OsObject.createRow(table);
    sharedRealm.commitTransaction();
    sharedRealm.refresh();
    TestHelper.awaitOrFail(latch);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:OsResultsTests.java

示例4: addListener_triggeredByRefresh

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
public void addListener_triggeredByRefresh() {
    final CountDownLatch latch = new CountDownLatch(1);
    OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    osResults.size();
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults element) {
            assertEquals(1, latch.getCount());
            latch.countDown();
        }
    });

    addRowAsync(sharedRealm);

    sharedRealm.waitForChange();
    sharedRealm.refresh();
    TestHelper.awaitOrFail(latch);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:OsResultsTests.java

示例5: addListener_queryNotReturned

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
@RunTestInLooperThread
public void addListener_queryNotReturned() {
    final OsSharedRealm sharedRealm = getSharedRealmForLooper();
    populateData(sharedRealm);
    Table table = getTable(sharedRealm);

    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    looperThread.keepStrongReference(osResults);
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults osResults1) {
            assertEquals(osResults, osResults1);
            assertEquals(5, osResults1.size());
            sharedRealm.close();
            looperThread.testComplete();
        }
    });

    addRowAsync(sharedRealm);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:OsResultsTests.java

示例6: addListener_queryReturned

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
@RunTestInLooperThread
public void addListener_queryReturned() {
    final OsSharedRealm sharedRealm = getSharedRealmForLooper();
    populateData(sharedRealm);
    Table table = getTable(sharedRealm);

    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    looperThread.keepStrongReference(osResults);
    assertEquals(4, osResults.size()); // Trigger the query to run.
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults osResults1) {
            assertEquals(osResults, osResults1);
            assertEquals(5, osResults1.size());
            sharedRealm.close();
            looperThread.testComplete();
        }
    });

    addRowAsync(sharedRealm);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:OsResultsTests.java

示例7: collectionIterator_invalid_looperThread_byRemoteTransaction

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
@RunTestInLooperThread
public void collectionIterator_invalid_looperThread_byRemoteTransaction() {
    final OsSharedRealm sharedRealm = getSharedRealmForLooper();
    populateData(sharedRealm);
    Table table = getTable(sharedRealm);
    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    final TestIterator iterator = new TestIterator(osResults);
    looperThread.keepStrongReference(osResults);
    assertFalse(iterator.isDetached(sharedRealm));
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults element) {
            try {
                iterator.checkValid();
                fail();
            } catch (ConcurrentModificationException ignored) {
            }
            sharedRealm.close();
            looperThread.testComplete();
        }
    });

    addRowAsync(sharedRealm);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:OsResultsTests.java

示例8: load

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Test
@RunTestInLooperThread
public void load() {
    final OsSharedRealm sharedRealm = getSharedRealmForLooper();
    looperThread.closeAfterTest(sharedRealm);
    populateData(sharedRealm);
    final OsResults osResults = OsResults.createFromQuery(sharedRealm, table.where());
    osResults.addListener(osResults, new RealmChangeListener<OsResults>() {
        @Override
        public void onChange(OsResults element) {
            assertTrue(osResults.isLoaded());
            looperThread.testComplete();
        }
    });
    assertFalse(osResults.isLoaded());
    osResults.load();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:OsResultsTests.java

示例9: init

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Override
public void init() {
    RealmResults<TodoList> listResults = todoRepository.queryList(listId);
    list = listResults.get(0);
    view.initViews(list.getTitle());

    bindData();
    list.addChangeListener(new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {
            if (view != null) {
                bindData();
                view.notifyDataChanged(list.getTitle());
            }
        }
    });
}
 
開發者ID:mengdd,項目名稱:TodoRealm,代碼行數:18,代碼來源:ListDetailPresenter.java

示例10: init

import io.realm.RealmChangeListener; //導入依賴的package包/類
@Override
public void init(long taskId) {
    RealmResults<Task> taskResults = repository.queryTask(taskId);
    if (taskResults.size() > 0) {
        task = taskResults.get(0);
    }
    task.addChangeListener(new RealmChangeListener<RealmModel>() {
        @Override
        public void onChange(RealmModel element) {
            task.getId();
            view.updateViews(task);
        }
    });
    view.initViews();
    view.updateViews(task);
}
 
開發者ID:mengdd,項目名稱:TodoRealm,代碼行數:17,代碼來源:TaskDetailPresenter.java

示例11: Realm

import io.realm.RealmChangeListener; //導入依賴的package包/類
public static Realm Realm() {
    if(realm == null){
        // Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
        Realm.init(getAppContext());
        RealmConfiguration realmConfig = new RealmConfiguration.Builder()
                .deleteRealmIfMigrationNeeded()
                .build();
        Realm.setDefaultConfiguration(realmConfig);

        // Get a Realm instance for this thread
        realm = Realm.getDefaultInstance();

        realm.addChangeListener(new RealmChangeListener<Realm>() {
            @Override
            public void onChange(Realm element) {
                Log.d(Tag,"app realmOnChangeListener");
            }
        });
    }

    return realm;
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:23,代碼來源:App.java

示例12: subscribeDataChange

import io.realm.RealmChangeListener; //導入依賴的package包/類
@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();
                }
            }
        });
    }
}
 
開發者ID:mocircle,項目名稱:devsuite-android,代碼行數:15,代碼來源:MassDataServiceImpl.java

示例13: initializeViews

import io.realm.RealmChangeListener; //導入依賴的package包/類
/**
 * Initialize recyclerview and adapters.
 * call adapter.notifyDataSetChanged if the realm for currency is updated
 * */
private void initializeViews(View rootView) {
    currencyRecycler = (RecyclerView) rootView.findViewById(R.id.converstions);
    currencyRecycler.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager
            .HORIZONTAL, false));

    marketAdapter=new MarketAdapter(getActivity(),rates);
    currencyRecycler.setAdapter(marketAdapter);

    rates.addChangeListener(new RealmChangeListener<RealmResults<Currency>>() {
        @Override
        public void onChange(RealmResults<Currency> currencies) {
            marketAdapter.notifyDataSetChanged();

        }
    });

}
 
開發者ID:nyangate,項目名稱:Crypto-Assistant,代碼行數:22,代碼來源:DashboardFragment.java

示例14: openDatabase

import io.realm.RealmChangeListener; //導入依賴的package包/類
public void openDatabase() {
    subscription = Observable.create(new Observable.OnSubscribe<Realm>() {
        @Override
        public void call(final Subscriber<? super Realm> subscriber) {
            final Realm observableRealm = Realm.getDefaultInstance();
            final RealmChangeListener<Realm> listener = realm -> {
                if(!subscriber.isUnsubscribed()) {
                    subscriber.onNext(observableRealm);
                }
            };
            observableRealm.addChangeListener(listener);
            subscriber.add(Subscriptions.create(() -> {
                observableRealm.removeChangeListener(listener);
                observableRealm.close();
            }));
            subscriber.onNext(observableRealm);
        }
    }).subscribeOn(looperScheduler.getScheduler()).unsubscribeOn(looperScheduler.getScheduler()).subscribe();
}
 
開發者ID:Zhuinden,項目名稱:navigator,代碼行數:20,代碼來源:DatabaseManager.java

示例15: SideArrayAdapter

import io.realm.RealmChangeListener; //導入依賴的package包/類
public SideArrayAdapter(Context context, final ArrayList<FeedWrapper> objects, ListView view) {
    super(context, 0, objects);
    this.objects = objects;
    new RealmChangeListener<Feed>() {
        @Override
        public void onChange(Feed element) {
            SideArrayAdapter.this.objects = new ArrayList<FeedWrapper>(Realm.getDefaultInstance().where(Feed.class).findAllSorted("order"));
            SideArrayAdapter.this.objects.addAll(Realm.getDefaultInstance().where(Category.class).findAllSorted("order"));
            Collections.sort(SideArrayAdapter.this.objects, new Comparator<FeedWrapper>() {
                @Override
                public int compare(FeedWrapper p1, FeedWrapper p2) {
                    return p1.getOrder() - p2.getOrder();// Ascending
                }

            });
            SideArrayAdapter.this.fitems = new ArrayList<>(objects);
        }
    };
    filter = new SubFilter();
    fitems = new ArrayList<>(objects);
    parentL = view;
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:23,代碼來源:SideArrayAdapter.java


注:本文中的io.realm.RealmChangeListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。