com.google.firebase.database.ValueEventListener Java Examples

The following examples show how to use com.google.firebase.database.ValueEventListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignIn.java    From Walk-In-Clinic-Android-App with MIT License 7 votes vote down vote up
public void updateUsers(){
    databaseUsers.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            users.clear();  // might need to remove
            for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                DataBaseUser usr = postSnapshot.getValue(DataBaseUser.class);
                users.add(usr);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #2
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void hasCurrentUserLikeSingleValue(String postId, String userId, final OnObjectExistListener<Like> onObjectExistListener) {
    DatabaseReference databaseReference = databaseHelper
            .getDatabaseReference()
            .child(DatabaseHelper.POST_LIKES_DB_KEY)
            .child(postId)
            .child(userId);
    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            onObjectExistListener.onDataChanged(dataSnapshot.exists());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "hasCurrentUserLikeSingleValue(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
}
 
Example #3
Source File: patientsFragment.java    From Doctorave with MIT License 6 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> loader, final Cursor data) {
    adapter.swapCursor(data);

    if(data.getCount() == 0){
        Query hekkQuery = mDatabaseReference;

        hekkQuery.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                if(doctorPreference.getWantToRestoreData(getActivity())){
                    if(dataSnapshot.getChildrenCount() == 0){

                    }else {
                        showAlertToRestoreData(dataSnapshot.getChildrenCount());
                    }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }
}
 
Example #4
Source File: FirebaseHelper.java    From UberClone with MIT License 6 votes vote down vote up
public void registerByGoogleAccount(final GoogleSignInAccount account){
    final User user=new User();
    users.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            User post = dataSnapshot.child(account.getId()).getValue(User.class);

            if(post==null) showRegisterPhone(user, account);
            else loginSuccess();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #5
Source File: ChatFragment.java    From SnapchatClone with MIT License 6 votes vote down vote up
private void listenForData() {
    DatabaseReference receiveDB = FirebaseDatabase.getInstance().getReference().child("users")
            .child(FirebaseAuth.getInstance().getUid()).child("received");

    receiveDB.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                for (DataSnapshot snap : dataSnapshot.getChildren()) {
                    getUserInfo(snap.getKey());
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #6
Source File: HomeActivity.java    From wmn-safety with MIT License 6 votes vote down vote up
public void getUserName(final String UID) {
    final StringBuffer buffer = new StringBuffer("");
    ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                if (snapshot.getKey().equals("name")) {
                    buffer.append(snapshot.getValue());
                }
            }
            mFullName = buffer.toString();
            updateProfile();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
    mDatabaseReference.child("users").child(UID).addListenerForSingleValueEvent(eventListener);

}
 
Example #7
Source File: FirebaseQueryLiveDataElement.java    From budgetto with MIT License 6 votes vote down vote up
public FirebaseQueryLiveDataElement(Class<T> genericTypeClass, Query query) {
    setValue(null);
    listener = new ValueEventListener() {

        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            T item = dataSnapshot.getValue(genericTypeClass);
            setValue(new FirebaseElement<>(item));
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            setValue(new FirebaseElement<>(databaseError));
            removeListener();
            setListener();
        }
    };
    this.query = query;
}
 
Example #8
Source File: GeoQuery.java    From geofire-android with Apache License 2.0 6 votes vote down vote up
private void addValueToReadyListener(final Query firebase, final GeoHashQuery query) {
    firebase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            synchronized (GeoQuery.this) {
                GeoQuery.this.outstandingQueries.remove(query);
                GeoQuery.this.checkAndFireReady();
            }
        }

        @Override
        public void onCancelled(@NonNull final DatabaseError databaseError) {
            synchronized (GeoQuery.this) {
                for (final GeoQueryDataEventListener listener : GeoQuery.this.eventListeners) {
                    GeoQuery.this.geoFire.raiseEvent(new Runnable() {
                        @Override
                        public void run() {
                            listener.onGeoQueryError(databaseError);
                        }
                    });
                }
            }
        }
    });
}
 
Example #9
Source File: SignUp.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
public void updateServices(){
    databaseServices.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            services.clear();  // might need to remove
            for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                DataBaseService service = postSnapshot.getValue(DataBaseService.class);
                services.add(service);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #10
Source File: SignUp.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
public void updateUsers(){
    databaseUsers.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            users.clear();
            for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                DataBaseUser usr = postSnapshot.getValue(DataBaseUser.class);
                users.add(usr);
                usernamesUsed.add(usr.getUsername());
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #11
Source File: Administrator.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
/**
 * Updates bookings reference
 */
public void updateBookings(){
    bookings = new ArrayList<>();

    databaseBookings.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            bookings.clear();
            for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                Booking booking = postSnapshot.getValue(Booking.class);
                bookings.add(booking);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #12
Source File: SignIn.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
public void updateServices(){
    databaseServices.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            services.clear();  // might need to remove
            for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
                DataBaseService service = postSnapshot.getValue(DataBaseService.class);
                services.add(service);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #13
Source File: ChatFragment.java    From SnapchatClone with MIT License 6 votes vote down vote up
private void getUserInfo(String key) {
    DatabaseReference userDB = FirebaseDatabase.getInstance().getReference().child("users").child(key);
    userDB.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                String username = dataSnapshot.child("username").getValue().toString();
                String profileImageUrl = dataSnapshot.child("profileImageUrl").getValue().toString();
                String uid = dataSnapshot.getRef().getKey();

                StoryObject obj = new StoryObject(username, uid, profileImageUrl,"chat");
                if (!results.contains(obj)) {
                    results.add(obj);
                    adapter.notifyDataSetChanged();
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #14
Source File: CallDriver.java    From UberClone with MIT License 6 votes vote down vote up
private void loadDriverInfo(String driverID) {
    FirebaseDatabase.getInstance().getReference(Common.user_driver_tbl)
            .child(driverID).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            User user=dataSnapshot.getValue(User.class);

            if(user.getAvatarUrl()!=null &&
                    !TextUtils.isEmpty(user.getAvatarUrl()))
                Picasso.get().load(user.getAvatarUrl()).into(imgAvatar);
            tvName.setText(user.getName());
            tvPhone.setText(user.getPhone());
            tvRate.setText(user.getRates());
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #15
Source File: Home.java    From UberClone with MIT License 6 votes vote down vote up
private void loadUser(){
    FirebaseDatabase.getInstance().getReference(Common.user_rider_tbl)
            .child(Common.userID)
            .addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    Common.currentUser=dataSnapshot.getValue(User.class);
                    initDrawer();
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });
}
 
Example #16
Source File: FirebaseNotificationStore.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
public static void markAsRead(String notifId) {
  String rootNode = HapRampMain.getFp();
  String username = HaprampPreferenceManager.getInstance().getCurrentSteemUsername();
  if (username.length() > 0) {
    final DatabaseReference notificationRef = FirebaseDatabase.getInstance()
      .getReference()
      .child(rootNode)
      .child(NODE_NOTIFICATIONS)
      .child(getFormattedUserName(username))
      .child(notifId);

    notificationRef.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        if (dataSnapshot.exists()) {
          notificationRef.child(NODE_IS_READ).setValue(true);
        }
      }

      @Override
      public void onCancelled(@NonNull DatabaseError databaseError) {

      }
    });
  }
}
 
Example #17
Source File: TripHistory.java    From UberClone with MIT License 6 votes vote down vote up
private void getHistory(){
    riderHistory.child(Common.userID).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){
                History history = postSnapshot.getValue(History.class);
                listData.add(history);
            }
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

}
 
Example #18
Source File: FollowInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void getFollowingPosts(String userId, OnDataChangedListener<FollowingPost> listener) {
    databaseHelper
            .getDatabaseReference()
            .child(DatabaseHelper.FOLLOWINGS_POSTS_DB_KEY)
            .child(userId)
            .addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    List<FollowingPost> list = new ArrayList<>();
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                        FollowingPost followingPost = snapshot.getValue(FollowingPost.class);
                        list.add(followingPost);
                    }

                    Collections.reverse(list);

                    listener.onListChanged(list);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    LogUtil.logDebug(TAG, "getFollowingPosts, onCancelled");
                }
            });
}
 
Example #19
Source File: FollowInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void getFollowersList(String targetUserId, OnDataChangedListener<String> onDataChangedListener) {
    getFollowersRef(targetUserId).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            List<String> list = new ArrayList<>();
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Follower follower = snapshot.getValue(Follower.class);

                if (follower != null) {
                    String profileId = follower.getProfileId();
                    list.add(profileId);
                }

            }
            onDataChangedListener.onListChanged(list);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logDebug(TAG, "getFollowersList, onCancelled");
        }
    });
}
 
Example #20
Source File: FollowInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void getFollowingsList(String targetUserId, OnDataChangedListener<String> onDataChangedListener) {
    getFollowingsRef(targetUserId).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            List<String> list = new ArrayList<>();
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Following following = snapshot.getValue(Following.class);

                if (following != null) {
                    String profileId = following.getProfileId();
                    list.add(profileId);
                }

            }
            onDataChangedListener.onListChanged(list);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logDebug(TAG, "getFollowingsList, onCancelled");
        }
    });
}
 
Example #21
Source File: ProfileInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public ValueEventListener searchProfiles(String searchText, OnDataChangedListener<Profile> onDataChangedListener) {
    DatabaseReference reference = databaseHelper.getDatabaseReference().child(DatabaseHelper.PROFILES_DB_KEY);
    ValueEventListener valueEventListener = getSearchQuery(reference, "username", searchText).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            List<Profile> list = new ArrayList<>();
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Profile profile = snapshot.getValue(Profile.class);
                list.add(profile);
            }
            onDataChangedListener.onListChanged(list);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "searchProfiles(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });

    databaseHelper.addActiveListener(valueEventListener, reference);
    return valueEventListener;
}
 
Example #22
Source File: ProfileInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public ValueEventListener getProfile(String id, final OnObjectChangedListener<Profile> listener) {
    DatabaseReference databaseReference = databaseHelper.getDatabaseReference().child(DatabaseHelper.PROFILES_DB_KEY).child(id);
    ValueEventListener valueEventListener = databaseReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Profile profile = dataSnapshot.getValue(Profile.class);
            listener.onObjectChanged(profile);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            listener.onError(databaseError.getMessage());
            LogUtil.logError(TAG, "getProfile(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
    databaseHelper.addActiveListener(valueEventListener, databaseReference);
    return valueEventListener;
}
 
Example #23
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void getPostListByUser(final OnDataChangedListener<Post> onDataChangedListener, String userId) {
    DatabaseReference databaseReference = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY);
    Query postsQuery;
    postsQuery = databaseReference.orderByChild("authorId").equalTo(userId);

    postsQuery.keepSynced(true);
    postsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
            onDataChangedListener.onListChanged(result.getPosts());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "getPostListByUser(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
}
 
Example #24
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public ValueEventListener filterPostsByLikes(int  limit, OnDataChangedListener<Post> onDataChangedListener) {
    DatabaseReference reference = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY);
    ValueEventListener valueEventListener = getFilteredQuery(reference,"likesCount", limit).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
            onDataChangedListener.onListChanged(result.getPosts());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "filterPostsByLikes(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });

    databaseHelper.addActiveListener(valueEventListener, reference);

    return valueEventListener;
}
 
Example #25
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public void getSinglePost(final String id, final OnPostChangedListener listener) {
    DatabaseReference databaseReference = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY).child(id);
    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.getValue() != null && dataSnapshot.exists()) {
                if (isPostValid((Map<String, Object>) dataSnapshot.getValue())) {
                    Post post = dataSnapshot.getValue(Post.class);
                    post.setId(id);
                    listener.onObjectChanged(post);
                } else {
                    listener.onError(String.format(context.getString(R.string.error_general_post), id));
                }
            } else {
                listener.onError(context.getString(R.string.message_post_was_removed));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "getSinglePost(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });
}
 
Example #26
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public ValueEventListener searchPostsByTitle(String searchText, OnDataChangedListener<Post> onDataChangedListener) {
    DatabaseReference reference = databaseHelper.getDatabaseReference().child(DatabaseHelper.POSTS_DB_KEY);
    ValueEventListener valueEventListener = getSearchQuery(reference,"title", searchText).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
            onDataChangedListener.onListChanged(result.getPosts());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            LogUtil.logError(TAG, "searchPostsByTitle(), onCancelled", new Exception(databaseError.getMessage()));
        }
    });

    databaseHelper.addActiveListener(valueEventListener, reference);

    return valueEventListener;
}
 
Example #27
Source File: PostInteractor.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public ValueEventListener hasCurrentUserLike(String postId, String userId, final OnObjectExistListener<Like> onObjectExistListener) {
    DatabaseReference databaseReference = databaseHelper
            .getDatabaseReference()
            .child(DatabaseHelper.POST_LIKES_DB_KEY)
            .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()));
        }
    });

    databaseHelper.addActiveListener(valueEventListener, databaseReference);
    return valueEventListener;
}
 
Example #28
Source File: FirebaseHelper.java    From UberClone with MIT License 6 votes vote down vote up
public void registerByGoogleAccount(final GoogleSignInAccount account){
    final User user=new User();
    users.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            User post = dataSnapshot.child(account.getId()).getValue(User.class);

            if(post==null) showRegisterPhone(user, account);
            else loginSuccess();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #29
Source File: SignInActivity.java    From budgetto with MIT License 5 votes vote down vote up
private void updateUI(FirebaseUser currentUser) {
    if (currentUser == null) {
        progressView.setVisibility(View.GONE);
        return;
    }
    showProgressView();
    final DatabaseReference userReference = FirebaseDatabase.getInstance().getReference("users").child(currentUser.getUid());
    userReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            User user = dataSnapshot.getValue(User.class);
            if (user != null) {
                startActivity(new Intent(SignInActivity.this, MainActivity.class));
                finish();
            } else {
                runTransaction(userReference);
            }

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            loginError("Firebase fetch user data failed.");
            hideProgressView();
        }
    });


}
 
Example #30
Source File: MainActivity.java    From RecyclerView with The Unlicense 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView = (RecyclerView) findViewById(R.id.myRecycler);
    recyclerView.setLayoutManager( new LinearLayoutManager(this));


    reference = FirebaseDatabase.getInstance().getReference().child("Profiles");
    reference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            list = new ArrayList<Profile>();
            for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
            {
                Profile p = dataSnapshot1.getValue(Profile.class);
                list.add(p);
            }
            adapter = new MyAdapter(MainActivity.this,list);
            recyclerView.setAdapter(adapter);
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Toast.makeText(MainActivity.this, "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
        }
    });
}