query = query.startAt(startTimestamp, Keys.Date); query = query.orderByChild(Keys.Date).limitToLast(ChatSDK.config().messageHistoryDownloadLimit); ChildEventListener listener = query.addChildEventListener(new FirebaseEventListener().onChildAdded((snapshot, s, hasValue) -> { if (hasValue) {
.endAt(endDate.getTime() - 1, Keys.Date) .limitToLast(numberOfMessages + 1); query.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if(hasValue) { List<Message> messages = new ArrayList<Message>();
private void removeListener () { if(cel != null) { ref.removeEventListener(cel); } if(vel != null) { ref.removeEventListener(vel); } }
public Observable<Message> messageRemovedOn() { return Observable.create(e -> { Query query = FirebasePaths.threadMessagesRef(model.getEntityID()); query = query.orderByChild(Keys.Date); query = query.limitToLast(ChatSDK.config().messageDeletionListenerLimit); ChildEventListener removedListener = query.addChildEventListener(new FirebaseEventListener().onChildRemoved((snapshot, hasValue) -> { if(hasValue) { MessageWrapper message = new MessageWrapper(snapshot); this.model.removeMessage(message.getModel()); // updateLastMessage().subscribe(new CrashReportingCompletableObserver()); e.onNext(message.getModel()); } })); FirebaseReferenceManager.shared().addRef(query, removedListener); }); }
.startAt(value) .limitToFirst(limit); query.keepSynced(true); query.addListenerForSingleValueEvent(new FirebaseEventListener().onValue((snapshot, hasValue) -> { if (hasValue) { Object valueObject = snapshot.getValue();
@Override public void subscribe(final FlowableEmitter<DataSnapshot> emitter) throws Exception { final ValueEventListener valueEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { emitter.onNext(dataSnapshot); } @Override public void onCancelled(final DatabaseError error) { if (!emitter.isCancelled()) emitter.onError(new RxFirebaseDataException(error)); } }; emitter.setCancellable(new Cancellable() { @Override public void cancel() throws Exception { query.removeEventListener(valueEventListener); } }); query.addValueEventListener(valueEventListener); } }, strategy);
query.addChildEventListener(childEventListener);
private void listenForData() { DatabaseReference usersDB = FirebaseDatabase.getInstance().getReference().child("users"); Query query = usersDB.orderByChild("username").startAt(mInput.getText().toString()).endAt(mInput.getText().toString() + "\uf8ff"); query.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
/** * Create a query constrained to only return the child node with the given key and value. Note * that there is at most one such child as keys are unique. * * @param value The value to query for * @param key The name of the child * @return A query with the new constraint */ public Query equalTo(boolean value, String key) { validateEqualToCall(); return this.startAt(value, key).endAt(value, key); }
public final void getCheckInByEmail(final String _email, final OnLoadCallback<CheckIn> loadCallback) { mDatabaseCheckIn.orderByChild("email").equalTo(_email).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { long count = dataSnapshot.getChildrenCount(); Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Count is: " + count); final List<CheckIn> checkIns = new ArrayList<CheckIn>(); for (final DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) { final CheckIn checkIn = dataSnapshot1.getValue(CheckIn.class); checkIns.add(checkIn); Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Value " + checkIn.checkInMessage); } loadCallback.onDataChange(checkIns); } @Override public void onCancelled(DatabaseError databaseError) { Log.d(TAG, TABLE_CHECK_IN + " | MyCheckIns | Failed to read: ", databaseError.toException()); loadCallback.onCancelled(); } }); }
Query messageQuery = messageRef.orderByKey().endAt(mLastKey).limitToLast(10); messageQuery.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) {
@Override public void fetchResources(int startFrom, int limit, Callback<List<Resource>> callback) { ValueEventListener listener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if (snapshot != null) { List<Resource> resources = new ArrayList<>(); for (DataSnapshot childSnapshot : snapshot.getChildren()) { Resource resource = childSnapshot.getValue(Resource.class); resources.add(resource); } callback.onReponse(resources); } } @Override public void onCancelled(DatabaseError databaseError) { callback.onError(); } }; Query resourcesQuery = mResourcesRef.orderByChild(KEY_TIMESTAMP); if (limit > 0) { resourcesQuery.limitToFirst(limit); } resourcesQuery.addValueEventListener(listener); mValueListeners.add(listener); }
/** * Create a query constrained to only return child nodes with a value less than or equal to the * given value, using the given orderBy directive or priority as default. * * @param value The value to end at, inclusive * @return A Query with the new constraint * @since 2.0 */ public Query endAt(boolean value) { return endAt(value, null); }
@Override public void addListenerForSingleValueEvent(final ValueEventListener listener) { query.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { listener.onDataChange(new DesktopDataSnapshot(dataSnapshot)); } @Override public void onCancelled(DatabaseError databaseError) { listener.onCancelled(new DesktopDatabaseError(databaseError)); } }); }
private void queryRecentScores() { scoresRef.orderByValue().limitToLast(4).addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChild) { scoresRef.orderByValue().limitToLast(2).addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(@NonNull DataSnapshot snapshot, String previousChild) {
mapQuery.get(id).addChildEventListener(mapChildListener.get(id)); mapMark.put(id, true); } else { mapQuery.get(id).removeEventListener(mapChildListener.get(id)); mapQuery.get(id).addChildEventListener(mapChildListener.get(id)); mapMark.put(id, true);
/** * Create a query constrained to only return child nodes with a value greater than or equal to the * given value, using the given orderBy directive or priority as default. * * @param value The value to start at, inclusive * @return A Query with the new constraint */ public Query startAt(String value) { return startAt(value, null); }
public void doRun() throws JobInterruptException { DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); // Top 5 Posts in the database, ordered by stars // [START top_posts_query] Query topPostsQuery = ref.child("posts").orderByChild("starCount").limitToLast(5); // [END top_posts_query] // All Users final DatabaseReference allUsersRef = ref.child("users"); topPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() { public void onDataChange(final DataSnapshot topPostsSnapshot) { allUsersRef.addListenerForSingleValueEvent(new ValueEventListener() { public void onDataChange(DataSnapshot allUsersSnapshot) { // Get users and posts as lists Map<String,User> users = allUsersSnapshot.getValue(new GenericTypeIndicator<Map<String, User>>() {}); List<Post> posts = topPostsSnapshot.getValue(new GenericTypeIndicator<List<Post>>() {}); // Send email to all users about the top 5 posts MyEmailer.sendWeeklyEmail(users, posts); } public void onCancelled(DatabaseError databaseError) { System.out.println("WeeklyEmailJob: could not get all users"); System.out.println("WeeklyEmailJob: " + databaseError.getMessage()); } }); } public void onCancelled(DatabaseError databaseError) { System.out.println("WeeklyEmailJob: could not get top posts"); System.out.println("WeeklyEmailJob: " + databaseError.getMessage()); } }); }
Query likesQuery = database.child("likes").orderByChild("imageId").equalTo(image.key); likesQuery.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Query imagesQuery = database.child("images").orderByKey().limitToFirst(100); imagesQuery.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) {