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


Java ChildEventListener類代碼示例

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


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

示例1: testObserveChildEvent_Added

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEvent_Added() throws InterruptedException {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildAdded(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventAdded));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
開發者ID:nmoskalenko,項目名稱:RxFirebase,代碼行數:19,代碼來源:RxFirebaseDatabaseTests.java

示例2: testObserveChildEvent_Changed

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEvent_Changed() throws InterruptedException {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildChanged(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventChanged));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
開發者ID:nmoskalenko,項目名稱:RxFirebase,代碼行數:19,代碼來源:RxFirebaseDatabaseTests.java

示例3: testObserveChildEvent_Removed

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEvent_Removed() throws InterruptedException {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildRemoved(mockFirebaseDataSnapshot);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventRemoved));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
開發者ID:nmoskalenko,項目名稱:RxFirebase,代碼行數:19,代碼來源:RxFirebaseDatabaseTests.java

示例4: testObserveChildEvent_Moved

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEvent_Moved() throws InterruptedException {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildMoved(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventMoved));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
開發者ID:nmoskalenko,項目名稱:RxFirebase,代碼行數:19,代碼來源:RxFirebaseDatabaseTests.java

示例5: testObserveChildEvent_Cancelled

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEvent_Cancelled() throws InterruptedException {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onCancelled(DatabaseError.zzqv(DatabaseError.DISCONNECTED));

    testSubscriber.assertError(RxFirebaseDataException.class);
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
開發者ID:nmoskalenko,項目名稱:RxFirebase,代碼行數:17,代碼來源:RxFirebaseDatabaseTests.java

示例6: registerFeedChangedEvent

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Override
public Observable<FeedChangedInfoEntity> registerFeedChangedEvent() {

    return Observable.fromAsync(new Action1<AsyncEmitter<FeedChangedInfoEntity>>() {
        @Override
        public void call(AsyncEmitter<FeedChangedInfoEntity> feedChangedInfoEntityAsyncEmitter) {

            Timber.v(String.format("fromAsync create : %s", Thread.currentThread().getName()));

            // those of registered method will be called in a background thread
            final Query query = database.child(Firebase.QUERY_FEEDS);
            final ChildEventListener listener = new FeedChangeListener(feedChangedInfoEntityAsyncEmitter);

            query.addChildEventListener(listener);

            feedChangedInfoEntityAsyncEmitter.setCancellation(new AsyncEmitter.Cancellable() {
                @Override
                public void cancel() throws Exception {
                    database.removeEventListener(listener);
                }
            });
        }
    }, AsyncEmitter.BackpressureMode.BUFFER);


}
 
開發者ID:roscrazy,項目名稱:Android-RealtimeUpdate-CleanArchitecture,代碼行數:27,代碼來源:FirebaseImpl.java

示例7: shouldBufferChildEvents

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void shouldBufferChildEvents() throws Exception {
  ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
  TestSubscriber<ChildEvent> subscriber = rx.onChildEvent().test(1);
  then(query).should().addChildEventListener(captor.capture());

  ChildEventListener listener = captor.getValue();
  DataSnapshot snapshot = mock(DataSnapshot.class);

  listener.onChildAdded(snapshot, null);
  listener.onChildAdded(snapshot, null);

  subscriber
      .assertValueCount(1)
      .assertNoErrors();
}
 
開發者ID:ashdavies,項目名稱:rx-firebase,代碼行數:17,代碼來源:RxFirebaseDatabaseTest.java

示例8: shouldFilterChildEvent

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void shouldFilterChildEvent() throws Exception {
  ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
  TestSubscriber<ChildEvent> subscriber = rx.onChildEvent(ChildEvent.Type.CHILD_ADDED).test();
  then(query).should().addChildEventListener(captor.capture());

  ChildEventListener listener = captor.getValue();
  DataSnapshot snapshot = mock(DataSnapshot.class);

  listener.onChildAdded(snapshot, null);
  listener.onChildChanged(snapshot, null);

  subscriber
      .assertValueCount(1)
      .assertNoErrors();
}
 
開發者ID:ashdavies,項目名稱:rx-firebase,代碼行數:17,代碼來源:RxFirebaseDatabaseTest.java

示例9: shouldParseChildEventValue

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void shouldParseChildEventValue() throws Exception {
  ArgumentCaptor<ChildEventListener> captor = forClass(ChildEventListener.class);
  TestSubscriber<String> subscriber = rx
      .onChildEventValue(ChildEvent.Type.CHILD_ADDED, String.class)
      .test();

  then(query).should().addChildEventListener(captor.capture());

  ChildEventListener listener = captor.getValue();
  DataSnapshot snapshot = mock(DataSnapshot.class);

  given(snapshot.getValue(String.class)).willReturn("biscuits");
  listener.onChildAdded(snapshot, null);

  subscriber
      .assertValue("biscuits")
      .assertNoErrors();
}
 
開發者ID:ashdavies,項目名稱:rx-firebase,代碼行數:20,代碼來源:RxFirebaseDatabaseTest.java

示例10: testObserveChildEventAdded

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEventAdded() throws InterruptedException {

   TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
      .observeChildEvent(databaseReference, ChildData.class)
      .test();

   ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
   verify(databaseReference).addChildEventListener(argument.capture());
   argument.getValue().onChildAdded(dataSnapshot, PREVIOUS_CHILD_NAME);

   testObserver.assertNoErrors()
      .assertValueCount(1)
      .assertValueSet(Collections.singletonList(childEventAdded))
      .assertNotComplete()
      .dispose();
}
 
開發者ID:FrangSierra,項目名稱:Rx2Firebase,代碼行數:18,代碼來源:RxFirebaseDatabaseTest.java

示例11: testObserveChildEventChanged

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEventChanged() throws InterruptedException {

   TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
      .observeChildEvent(databaseReference, ChildData.class)
      .test();

   ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
   verify(databaseReference).addChildEventListener(argument.capture());
   argument.getValue().onChildChanged(dataSnapshot, PREVIOUS_CHILD_NAME);

   testObserver.assertNoErrors()
      .assertValueCount(1)
      .assertValueSet(Collections.singletonList(childEventChanged))
      .assertNotComplete()
      .dispose();
}
 
開發者ID:FrangSierra,項目名稱:Rx2Firebase,代碼行數:18,代碼來源:RxFirebaseDatabaseTest.java

示例12: testObserveChildEventRemoved

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEventRemoved() throws InterruptedException {

   TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
      .observeChildEvent(databaseReference, ChildData.class)
      .test();

   ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
   verify(databaseReference).addChildEventListener(argument.capture());
   argument.getValue().onChildRemoved(dataSnapshot);

   testObserver.assertNoErrors()
      .assertValueCount(1)
      .assertValueSet(Collections.singletonList(childEventRemoved))
      .assertNotComplete()
      .dispose();
}
 
開發者ID:FrangSierra,項目名稱:Rx2Firebase,代碼行數:18,代碼來源:RxFirebaseDatabaseTest.java

示例13: testObserveChildEventMoved

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testObserveChildEventMoved() throws InterruptedException {

   TestSubscriber<RxFirebaseChildEvent<ChildData>> testObserver = RxFirebaseDatabase
      .observeChildEvent(databaseReference, ChildData.class)
      .test();

   ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
   verify(databaseReference).addChildEventListener(argument.capture());
   argument.getValue().onChildMoved(dataSnapshot, PREVIOUS_CHILD_NAME);

   testObserver.assertNoErrors()
      .assertValueCount(1)
      .assertValueSet(Collections.singletonList(childEventMoved))
      .assertNotComplete()
      .dispose();
}
 
開發者ID:FrangSierra,項目名稱:Rx2Firebase,代碼行數:18,代碼來源:RxFirebaseDatabaseTest.java

示例14: testChildAddedEvents

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
@Test
public void testChildAddedEvents() throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  Map<String, Object> initial =
      new MapBuilder()
          .put("a", MapBuilder.of("value", 5L))
          .put("c", MapBuilder.of("value", 3L))
          .build();

  final List<String> snapshotNames = new ArrayList<>();
  final List<String> prevNames = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  final ChildEventListener testListener =
      ref.orderByChild("value")
          .addChildEventListener(
              new TestChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot snap, String prevName) {
                  snapshotNames.add(snap.getKey());
                  prevNames.add(prevName);
                  semaphore.release();
                }
              });

  ref.setValueAsync(initial);
  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c"), prevNames);

  Map<String, Object> updates = new HashMap<>();
  updates.put("b", MapBuilder.of("value", 4));
  updates.put("d", MapBuilder.of("value", 2));
  ref.updateChildrenAsync(updates);

  TestHelpers.waitFor(semaphore, 2);
  Assert.assertEquals(Arrays.asList("c", "a", "d", "b"), snapshotNames);
  Assert.assertEquals(Arrays.asList(null, "c", null, "c"), prevNames);
  ref.removeEventListener(testListener);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:41,代碼來源:OrderByTestIT.java

示例15: breakCombo

import com.google.firebase.database.ChildEventListener; //導入依賴的package包/類
/** Remove the saved listener from the saved ref.*/
public void breakCombo(){
    DatabaseReference comboRef = FirebaseDatabase.getInstance().getReferenceFromUrl(ref);

    listener.killEvent();

    if (listener.getType() == FirebaseGeneralEvent.ChildEvent)
    {
        comboRef.removeEventListener((ChildEventListener) listener);
    }
    else if (listener.getType() == FirebaseGeneralEvent.ValueEvent)
    {
        comboRef.removeEventListener((ValueEventListener) listener);
    }
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:16,代碼來源:FirebaseEventCombo.java


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