public static List<Product> getAllProductes(){ final List<Product> Productes=new ArrayList<Product>(); // Attach a listener to read the data at our posts reference ProductRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Product post = dataSnapshot.getValue(Product.class); Productes.add(post); } @Override public void onCancelled(DatabaseError databaseError) { System.out.println("The read failed: " + databaseError.getCode()); } }); return Productes; }
public Observable<Void> push() { final DatabaseReference child = easyFirebaseDb.databaseReference.child(name); for (Map.Entry<String, Object> entry : values.entrySet()) { child.child(entry.getKey()).setValue(entry.getValue()); } return Observable.create(new Observable.OnSubscribe<Void>() { @Override public void call(final Subscriber<? super Void> subscriber) { child.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { subscriber.onNext(null); subscriber.onCompleted(); } @Override public void onCancelled(DatabaseError databaseError) { subscriber.onError(databaseError.toException()); } }); } }); }
@Test public void canGetProfilePicUrl() { final String testUserForPic = "Test User for Pic"; final String url = "http://url.test.ch"; firebaseHelper.addOrUpdateUser(TEST_USER, testUserForPic); firebaseHelper.setOrUpdateProfilePicUrl(testUserForPic, url); firebaseHelper.getProfilePicUrl(testUserForPic, new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String fetchedUrl = (String) dataSnapshot.getValue(); Assert.assertTrue(url.equals(fetchedUrl)); } @Override public void onCancelled(DatabaseError databaseError) { throw databaseError.toException(); } }); }
public void notifyContactsOfConnectionChange(final boolean online, final boolean signoff) { final String myEmail = getAuthUserEmail(); getMyContactsReference().addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { for (DataSnapshot child : snapshot.getChildren()) { String email = child.getKey(); DatabaseReference reference = getOneContactReference(email, myEmail); reference.setValue(online); } if (signoff){ FirebaseAuth.getInstance().signOut(); } } @Override public void onCancelled(DatabaseError firebaseError) { } }); }
public <T> Observable<T> getObjects(final Query query, final Class<T> objectClass, final boolean useRootElement) { return Observable.create(new Observable.OnSubscribe<T>() { @Override public void call(final Subscriber<? super T> subscriber) { query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(useRootElement) { converter.convert(dataSnapshot, objectClass, subscriber); } else { for (DataSnapshot entry : dataSnapshot.getChildren()) { converter.convert(entry, objectClass, subscriber); } } subscriber.onCompleted(); } @Override public void onCancelled(DatabaseError databaseError) { } }); } }); }
/** * Add a new user * @param userId - the user's ID * @param name - the user's name * @param email - the user's email */ public void addUserRecords(final String userId, final String name, final String email) { mDatabase.child("users").child(userId).addListenerForSingleValueEvent(new ValueEventListener() { /** * Handle data change event * @param snapshot - current database contents */ @Override public void onDataChange(DataSnapshot snapshot) { if (!snapshot.exists()) { User user = new User(userId, name, email, 0); mDatabase.child("users").child(userId).setValue(user); } } /** * Do nothing when the process is cancelled * @param databaseError - Ignored error */ @Override public void onCancelled(DatabaseError databaseError) { } }); setMemberData(); }
@Test public void testSubscribeThenUnsubscribeWithoutProblems() throws InterruptedException { DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ; ValueEventListener listener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) {} @Override public void onCancelled(DatabaseError error) { fail("Should not be cancelled"); } }; ValueEventListener listenerHandle = ref.addValueEventListener(listener); ZombieVerifier.verifyRepoZombies(ref); ref.removeEventListener(listenerHandle); ZombieVerifier.verifyRepoZombies(ref); ValueEventListener listenerHandle2 = ref.addValueEventListener(listener); ZombieVerifier.verifyRepoZombies(ref); ref.removeEventListener(listenerHandle2); ZombieVerifier.verifyRepoZombies(ref); }
private Observable<DataSnapshot> observe(final Query ref) { return Observable.create(emitter -> { final ValueEventListener listener = ref.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { emitter.onNext(dataSnapshot); } @Override public void onCancelled(DatabaseError databaseError) { emitter.onError(new FirebaseException(databaseError.getMessage())); } }); emitter.setCancellable(() -> ref.removeEventListener(listener)); }); }
@Test public void testAttachingListener() { DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp); ValueEventListener listener = ref.limitToLast(1) .addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { // No-op } @Override public void onCancelled(DatabaseError error) { } }); assertNotNull(listener); }
public void removeDetectiveProcess(ViewAppHolder.UserProfileViewHolder userProfileViewHolder, Context context){ FirebaseHelper.getUserAccountSettings(USER_LINK_FIREBASE) .child(Constants.DETECTION_MODE).setValue(Constants.USER_DETECTION_INACTIVE); userProfileViewHolder.DETECTION_ICON.setImageTintList( context.getResources().getColorStateList(R.color.safe_color)); FirebaseHelper.getUserFriendList(USER_LINK_FIREBASE) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){ FirebaseHelper.getUserDetection(Utility.encodeUserEmail(dataSnapshot1.getValue(String.class))) .child(USER_LINK_FIREBASE).removeValue(); } FirebaseHelper.getUserLocation(USER_LINK_FIREBASE) .removeEventListener(userDetectionLocationListener); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
private void displayCityStateCountry() { dbHelper.getDb().getReference( dbHelper.getUserPath() ).child( currUserID ).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for ( DataSnapshot field : dataSnapshot.getChildren() ) { switch ( field.getKey() ) { case "city": cityEditText.setText( ( field.getValue() != null ) ? field.getValue().toString() : "" ); break; case "state": stateEditText.setText( ( field.getValue() != null ) ? field.getValue().toString() : "" ); break; case "country": countryEditText.setText( ( field.getValue() != null ) ? field.getValue().toString() : "" ); break; } } } @Override public void onCancelled(DatabaseError databaseError) {} }); }
private void removeFriendRequestAFromB(final String USER_A_EMAIL, final String USER_B_EMAIL){ FirebaseHelper.getUserFriendRequestList(Utility.encodeUserEmail(USER_B_EMAIL)) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){ if(dataSnapshot1.getValue().equals(USER_A_EMAIL)){ FirebaseHelper.getUserFriendRequestList(Utility.encodeUserEmail(USER_B_EMAIL)) .child(dataSnapshot1.getKey()).removeValue(); break; } } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
@Test public void listenUserAvailabilityCorrectlyAttachesListener() { firebaseHelper.setUserAvailable(TEST_USER, false, true); ValueEventListener listener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Assert.assertTrue(dataSnapshot.exists()); Assert.assertTrue((boolean)dataSnapshot.getValue()); } @Override public void onCancelled(DatabaseError databaseError) { } }; firebaseHelper.listenUserAvailability(TEST_USER, false, listener); }
@Test public void testUpdateAfterSetLeafNodeWorks() throws InterruptedException { DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp); final Semaphore semaphore = new Semaphore(0); final Map<String, Object> expected = new MapBuilder().put("a", 1L).put("b", 2L).build(); ref.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { if (DeepEquals.deepEquals(snapshot.getValue(), expected)) { semaphore.release(); } } @Override public void onCancelled(DatabaseError error) { } }); ref.setValueAsync(42); ref.updateChildrenAsync(expected); TestHelpers.waitFor(semaphore); }
public void checkForData(final FirebaseActionListenerCallback listener){ ValueEventListener postListener = new ValueEventListener() { @Override public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) { if (dataSnapshot.getChildrenCount() > 0) { listener.onSuccess(); } else { listener.onError(null); } } @Override public void onCancelled(DatabaseError databaseError) { Log.d("FIREBASE API", databaseError.getMessage()); } }; mPhotoDatabaseReference.addValueEventListener(postListener); }
private void loadProfile() { String Uid = mAuth.getCurrentUser().getUid(); DatabaseReference current_user = mDatabase.child(Uid); current_user.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { etFirstName.setText(dataSnapshot.child("firstname").getValue(String.class)); etLastName.setText(dataSnapshot.child("lastname").getValue(String.class)); etAge.setText(dataSnapshot.child("age").getValue(String.class)); etPhone.setText(dataSnapshot.child("phone").getValue(String.class)); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
public void setCreateNewFlagListenerAction(final Context context){ FirebaseHelper.getUserFlag(USER_LINK_FIREBASE) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot.getValue() == null){ Intent flagIntent = new Intent(context, CreateNewFlag.class); flagIntent.putExtra(Constants.USER_EXTRA,USER_LINK_FIREBASE); context.startActivity(flagIntent); }else{ Toast.makeText(context, "You created one before, Please remove it first", Toast.LENGTH_SHORT).show(); } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
public ValueEventListener hasCurrentUserLike(String postId, String userId, final OnObjectExistListener<Like> onObjectExistListener) { DatabaseReference databaseReference = database.getReference("post-likes").child(postId).child(userId); ValueEventListener valueEventListener = databaseReference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { onObjectExistListener.onDataChanged(dataSnapshot.exists()); } @Override public void onCancelled(DatabaseError databaseError) { LogUtil.logError(TAG, "hasCurrentUserLike(), onCancelled", new Exception(databaseError.getMessage())); } }); activeListeners.put(valueEventListener, databaseReference); return valueEventListener; }
private void loaditems() { mDatabase.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { items.clear(); for(DataSnapshot snap : dataSnapshot.getChildren()) { items.add(snap.getValue(String.class)); } loadListView(); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
private void loaditems() { mDatabase.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { items.clear(); itemKeys.clear(); for(DataSnapshot snap : dataSnapshot.getChildren()) { if(!snap.child("createdBy").getValue(String.class).equals(mAuth.getCurrentUser().getUid())) { if(snap.child("isItemSold").getValue(String.class)==null){ items.add(snap.child("itemName").getValue(String.class)); itemKeys.add(snap.getKey()); } } } loadListView(); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
public void setUserRelation(final String USER_EMAIL, final ViewAppHolder.SearchViewHolder searchViewHolder){ FirebaseHelper.getUserDatabaseReference(USER_LINK_FIREBASE) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean userInFriendList = checkUserInFriendList(dataSnapshot,USER_EMAIL); boolean userInFriendRequest = checkUserInFriendRequest(dataSnapshot,USER_EMAIL); boolean currentUserSendFriendRequest = checkCurrentUserRequestSend(dataSnapshot,USER_EMAIL); userSearchUi.setUserView(userInFriendList, userInFriendRequest, currentUserSendFriendRequest, searchViewHolder, USER_EMAIL); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
/** * Parse location to fetch matching events * @param key the geoindex key * @param location the corresponding location */ @Override public void onKeyEntered(String key, GeoLocation location) { String[] parts = key.split("@"); String userId = parts[0]; String eventId = parts[1]; if(users.contains(userId)) { FirebaseDatabase.getInstance().getReference("events/"+userId+"/"+eventId).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { HabitEventDataModel model = dataSnapshot.getValue(HabitEventDataModel.class); if (model != null) { HabitEvent habitEvent = model.getHabitEvent(); nearbyEvents.add(habitEvent); datasetChanged(); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } }
public void findBookSearch(String userId, String folderId, final ValueEventListener valueEventListener) { if (folderId == null) { mDatabaseReference.child(userId) .child(REF_FOLDERS) .child(REF_MY_BOOKS_FOLDER) .child(REF_BOOKS) .orderByChild("volumeInfo/searchField") .addListenerForSingleValueEvent(valueEventListener); } else { mDatabaseReference.child(userId) .child(REF_FOLDERS) .child(folderId) .child(REF_BOOKS) .orderByChild("volumeInfo/searchField") .addListenerForSingleValueEvent(valueEventListener); } }
/** * Get how long the user has been a botanist * @return Returns the total number of deleted plants */ public long getDeletedCount() { getUserReference().child("plantsDeleted").addListenerForSingleValueEvent(new ValueEventListener() { /** * Handle a change in the database contents * @param snapshot - current database contents */ @Override public void onDataChange(DataSnapshot snapshot) { if (snapshot.exists()) { mPlantsDeleted = (long) snapshot.getValue(); } } /** * Do nothing when the process is cancelled * @param databaseError - Ignored error */ @Override public void onCancelled(DatabaseError databaseError) { } }); return mPlantsDeleted; }
public void getUser(String userID, IGetUserListener userListener) { mGetUserListener = userListener; DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference(); dbRef.child("users").child(userID).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { mUser = dataSnapshot.getValue(User.class); mGetUserListener.onGetSingleUser(mUser); } @Override public void onCancelled(DatabaseError databaseError) { mGetUserListener.onFailedSingleUser(); } }); }
public static void addConversationToInbox(Conversation conversation) { // Firebase Serializer chokes on InboxItem, goes into some recursive black hole and OOMs // InboxItem inboxItem = new InboxItem(conversation.getMeta().getId(), conversation.getMeta().getName()); DatabaseRouter.getInboxRef().addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (!dataSnapshot.exists()) { Inbox inbox = new Inbox(Fire.auth.getCurrentUser()); dataSnapshot.getRef().child(META).setValue(inbox.getMeta()); } String text = "Brand spankin new conversation"; if (conversation.getData().size() > 0) { // TODO: replace this horrible hack String key = conversation.getData().keySet().toArray(new String[0])[0]; text = conversation.getData().get(key).getText(); } dataSnapshot.getRef().child(DATA).child(conversation.getMeta().getId()) .setValue(new ChatMessage(text, conversation.getMeta().getId(), Fire.auth.getCurrentUser())); } @Override public void onCancelled(DatabaseError databaseError) { Timber.e(databaseError.getDetails()); } }); }
/** * Get the number of plants a user owns * @return Returns the number of plants the user owns */ public long getPlantsNumber() { getUserReference().child("plantsNumber").addListenerForSingleValueEvent(new ValueEventListener() { /** * Handle a change in the user data * @param snapshot - the current database contents */ @Override public void onDataChange(DataSnapshot snapshot) { if (snapshot.exists()) { mPlantsNumber = (long) snapshot.getValue(); } } /** * Do nothing when the process cancels * @param databaseError - Ignored error */ @Override public void onCancelled(DatabaseError databaseError) { } }); return mPlantsNumber; }
private void postComment() { final String uid = getUid(); FirebaseDatabase.getInstance().getReference().child("users").child(uid) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // Get user information String authorName = user.getDisplayName(); // Create new comment object String commentText = mCommentField.getText().toString(); Comment comment = new Comment(uid, authorName, commentText); // Push the comment, it will appear in the list mCommentsReference.push().setValue(comment); // Clear the field mCommentField.setText(null); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
public void getNowListening(String uid, final OnCompleteGetNowListening listener) { rdm.getUsersReference().child(uid).child("now").addValueEventListener( new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String state = dataSnapshot.getValue(String.class); if (state == null) return; Log.e(TAG, "getNowListening:complete, " + state); listener.onComplete(state); } @Override public void onCancelled(DatabaseError databaseError) { Log.e(TAG, "getNowListening:onCancelled", databaseError.toException()); } }); }
public static List<Address> getAllAddresses(){ final List<Address> Addresses=new ArrayList<Address>(); // Attach a listener to read the data at our posts reference AddressRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Address post = dataSnapshot.getValue(Address.class); Addresses.add(post); } @Override public void onCancelled(DatabaseError databaseError) { System.out.println("The read failed: " + databaseError.getCode()); } }); return Addresses; }
public static void getMusic(PraclerSong song, final OnCompleteGetFirebaseMusicListener listener) { RemoteDatabaseManager rdm = new RemoteDatabaseManager(); rdm.getSongsReference().child(song.artist).child(song.album).child(song.title).child("&info").addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { MusicRes musicRes = dataSnapshot.getValue(MusicRes.class); listener.onComplete(musicRes); } @Override public void onCancelled(DatabaseError databaseError) { Log.e(TAG, "getMusic method canceled."); return; } }); }
private void publicFlagUi(final ViewAppHolder.FlagDetailsViewHolder flagDetailsViewHolder, final Context context){ FirebaseHelper.getPublicFlags() .child(FLAG_KEY).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { FlagsMarkers flagsMarkers = dataSnapshot.getValue(FlagsMarkers.class); setDetailsFlagUi(flagDetailsViewHolder, context, flagsMarkers); } @Override public void onCancelled(DatabaseError databaseError) { } }); }
public void GetRegistredOnes(Map<String, String> alle_deine_kontakte, String uids) { uid = uids; alle_deine = alle_deine_kontakte; all_downloaded = new LinkedHashMap<String, String>(); DatabaseReference dbr_nummbern = FirebaseDatabase.getInstance().getReference().getRoot().child("users").child("telefonnummern"); dbr_nummbern.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) { String single_downloaded_nummer = childDataSnapshot.getKey(); //displays the key for the node String single_downloaded_uid = (String) childDataSnapshot.getValue(); //gives the value for given keyname all_downloaded.put(single_downloaded_nummer, single_downloaded_uid); }; GetYourRegistredOnes(alle_deine, all_downloaded, uid); } @Override public void onCancelled(DatabaseError databaseError) { // ... } }); // return all_downloaded; }
/** * Fetch habit event from the database * @param key the habit event key * @param resultListener result callback */ @Override public void get(String key, final OnResultListener<HabitEvent> resultListener) { mHabitEventsRef.child(key).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { HabitEventDataModel model = dataSnapshot.getValue(HabitEventDataModel.class); if(model != null) { resultListener.onResult(model.getHabitEvent()); } else { resultListener.onResult(null); } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
@Override public void getMessages(final User u, final DatabaseCallback<List<Message>> dbCallback) { ValueEventListener listener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { List<Message> messages = new ArrayList<>(); if (dataSnapshot.getChildrenCount() > 0) { for (DataSnapshot s : dataSnapshot.getChildren()) { messages.add(s.getValue(Message.class)); } } dbReference.child(u.getUid()) .child(MESSAGES).removeEventListener(this); dbCallback.onSuccess(messages); } @Override public void onCancelled(DatabaseError databaseError) { dbCallback.onFailure(databaseError.toException()); } }; dbReference.child(u.getUid()) .child(MESSAGES) .addValueEventListener(listener); }
public LightSettings(){ database = FirebaseDatabase.getInstance(); lightSettingsRef = database.getReference("lightsettings"); lightSettingsRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Log.e("db", "dbok in lightsettings.java"); active = ((boolean) dataSnapshot.child("active").getValue()); onH = ((Number) dataSnapshot.child("onH").getValue()).intValue(); onM = ((Number) dataSnapshot.child("onM").getValue()).intValue(); offH = ((Number) dataSnapshot.child("offH").getValue()).intValue(); offM = ((Number) dataSnapshot.child("offM").getValue()).intValue(); } @Override public void onCancelled(DatabaseError databaseError) { Log.e("db", "dberror in lightsettings.java"); Log.e("db",databaseError.toString()); active = false; } }); }
public Promise<Boolean, BError, Void> isOnline(){ final Deferred<Boolean, BError, Void> deferred = new DeferredObject<>(); if (currentUserModel() == null) { return deferred.reject(BError.getError(BError.Code.NULL, "Current user is null")); } FirebasePaths.userOnlineRef(currentUserModel().getEntityID()).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { updateLastOnline(); deferred.resolve((Boolean) snapshot.getValue()); } @Override public void onCancelled(DatabaseError firebaseError) { deferred.reject(getFirebaseError(firebaseError)); } }); return deferred.promise(); }
private void setListenerToUserLocation(){ FirebaseHelper.getUserLocation(USER_LINK_FIREBASE) .addValueEventListener(userLocationGeofenceListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { CurrentLocation currentUserLocation = dataSnapshot.getValue(CurrentLocation.class); // get user location. final Location userLocation = new Location(Constants.CURRENT_USER_LOCATION_PROVIDER); if(currentUserLocation != null) { userLocation.setLongitude(currentUserLocation.getLocationLongitude()); userLocation.setLatitude(currentUserLocation.getLocationLatitude()); Log.e("location called","changed"); checkLocationWithRespectToFlags(userLocation); checkLocationWithRespectToDetections(userLocation); } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
private void addPointToDatabase(final DatabaseReference databaseReference, final FirebaseUser firebaseUser) { databaseReference.child("users") .child(firebaseUser.getUid()) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // Update the cloud database addPointToDatabase(databaseReference, firebaseUser, (dataSnapshot.getValue(User.class).getNumberOfPoints() + 1)); } @Override public void onCancelled(DatabaseError databaseError) { Log.e(TAG, "Database Error Occurred", databaseError.toException()); FirebaseCrash.report(databaseError.toException()); } }); }
private void setUser(){ reference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot snapshot : dataSnapshot.getChildren()) { User user = snapshot.getValue(User.class); users.add(user); } name.setText(users.get(0).getResults().get(0).getName().getFirst()); } @Override public void onCancelled(DatabaseError databaseError) { } }); }