Java 类com.google.firebase.database.ChildEventListener 实例源码

项目:RxFirebase    文件:RxFirebaseDatabaseTests.java   
@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();
}
项目:RxFirebase    文件:RxFirebaseDatabaseTests.java   
@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();
}
项目:RxFirebase    文件:RxFirebaseDatabaseTests.java   
@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();
}
项目:RxFirebase    文件:RxFirebaseDatabaseTests.java   
@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();
}
项目:RxFirebase    文件:RxFirebaseDatabaseTests.java   
@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();
}
项目:Android-RealtimeUpdate-CleanArchitecture    文件:FirebaseImpl.java   
@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);


}
项目:rx-firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:rx-firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:rx-firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:Rx2Firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:Rx2Firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:Rx2Firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:Rx2Firebase    文件:RxFirebaseDatabaseTest.java   
@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();
}
项目:firebase-admin-java    文件:OrderByTestIT.java   
@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);
}
项目:AndroidBackendlessChat    文件:FirebaseEventCombo.java   
/** 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);
    }
}
项目:chat-sdk-android-push-firebase    文件:FirebaseEventCombo.java   
/** 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);
    }
}
项目:RxFirebase2    文件:RxFirebaseDatabaseTest.java   
@Before public void setup() {
  MockitoAnnotations.initMocks(this);

  childEventListener = ArgumentCaptor.forClass(ChildEventListener.class);
  valueEventListener = ArgumentCaptor.forClass(ValueEventListener.class);
  transactionHandler = ArgumentCaptor.forClass(Transaction.Handler.class);
  onCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
}
项目:Firebase-Chat-Demo    文件:ListenToAddChildEventsOnSubscribe.java   
@Override
public void call(Subscriber<? super T> subscriber) {
    final ChildEventListener listener = query.addChildEventListener(new RxValueListener<>(subscriber, marshaller));
    subscriber.add(Subscriptions.create(new Action0() {
        @Override
        public void call() {
            query.removeEventListener(listener);
        }
    }));
}
项目:TripV1.0    文件:ListenToAddChildEventsOnSubscribe.java   
@Override
public void call(Subscriber<? super T> subscriber) {
    final ChildEventListener listener = query.addChildEventListener(new RxValueListener<>(subscriber, marshaller));
    subscriber.add(Subscriptions.create(new Action0() {
        @Override
        public void call() {
            query.removeEventListener(listener);
        }
    }));
}
项目:Stedroids    文件:AbstractFirebaseViewModel.java   
public void onViewModelDestroyed() {
    if(this.attachValueEventListener() || this.attachSingleValueEventListener()) {
        this.reference.removeEventListener((ValueEventListener) this);
    }

    if(this.attachChildEventListener()) {
        this.reference.removeEventListener((ChildEventListener) this);
    }

    super.onViewModelDestroyed();
}
项目:Rx2Firebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void testObserveChildEventCancelled() 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().onCancelled(DatabaseError.zzfr(DatabaseError.DISCONNECTED));

   testObserver.assertError(RxFirebaseDataException.class)
      .assertNotComplete()
      .dispose();
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    childEventListener = ArgumentCaptor.forClass(ChildEventListener.class);
    valueEventListener = ArgumentCaptor.forClass(ValueEventListener.class);
    transactionHandler = ArgumentCaptor.forClass(Transaction.Handler.class);
    onCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
}
项目:firebase-admin-java    文件:ChildEventRegistration.java   
public ChildEventRegistration(
    @NotNull Repo repo, @NotNull ChildEventListener eventListener, @NotNull QuerySpec spec) {
  this.repo = repo;
  this.eventListener = eventListener;
  this.spec = spec;
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public ChildEventListener attachBookFolderChildEventListener(String userId, String folderId, ChildEventListener listener) {
    return mDatabaseReference.child(userId).child(REF_FOLDERS).child(folderId).child(REF_BOOKS).addChildEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void detachBookFolderChildEventListener(String userId, String folderId, ChildEventListener listener) {
    mDatabaseReference.child(userId).child(REF_FOLDERS).child(folderId).child(REF_BOOKS).removeEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void attachFetchFolders(String userId, ChildEventListener listener) {
    DatabaseReference ref = mDatabaseReference.child(userId).child(REF_FOLDERS);
    ref.addChildEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void detachFetchFolders(String userId, ChildEventListener listener) {
    DatabaseReference ref = mDatabaseReference.child(userId).child(REF_FOLDERS);
    ref.removeEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public ChildEventListener attachBookFolderChildEventListener(String userId, String folderId, ChildEventListener listener) {
    return mDatabaseReference.child(userId).child(REF_FOLDERS).child(folderId).child(REF_BOOKS).addChildEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void detachBookFolderChildEventListener(String userId, String folderId, ChildEventListener listener) {
    mDatabaseReference.child(userId).child(REF_FOLDERS).child(folderId).child(REF_BOOKS).removeEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void attachFetchFolders(String userId, ChildEventListener listener) {
    DatabaseReference ref = mDatabaseReference.child(userId).child(REF_FOLDERS);
    ref.addChildEventListener(listener);
}
项目:BuddyBook    文件:FirebaseDatabaseHelper.java   
public void detachFetchFolders(String userId, ChildEventListener listener) {
    DatabaseReference ref = mDatabaseReference.child(userId).child(REF_FOLDERS);
    ref.removeEventListener(listener);
}
项目:social-app-android    文件:DatabaseHelper.java   
public void onNewLikeAddedListener(ChildEventListener childEventListener) {
    DatabaseReference mLikesReference = database.getReference().child("post-likes");
    mLikesReference.addChildEventListener(childEventListener);
}
项目:AcademApp    文件:FirebaseArray.java   
public void cleanup() {
    mQuery.removeEventListener((ValueEventListener) this);
    mQuery.removeEventListener((ChildEventListener) this);
}
项目:Cheaphlight    文件:FirebaseHelper.java   
public static void removeChildListener(@NonNull DatabaseReference reference, @NonNull ChildEventListener listener) {
    try {
        reference.removeEventListener(listener);
    } catch (Exception ignored) {}
}
项目:rx-firebase    文件:ChildEventCancellable.java   
ChildEventCancellable(Query query, ChildEventListener listener) {
  this.query = query;
  this.listener = listener;
}
项目:rx-firebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void shouldAddChildEventListener() throws Exception {
  rx.onChildEvent().subscribe();

  then(query).should().addChildEventListener(any(ChildEventListener.class));
}
项目:FirebaseUI-Android    文件:FirebaseArray.java   
@Override
protected void onDestroy() {
    super.onDestroy();
    mQuery.removeEventListener((ValueEventListener) this);
    mQuery.removeEventListener((ChildEventListener) this);
}