public class NotificationFragment extends Fragment {
RecyclerView notificationRv;
private FirebaseAuth firebaseAuth;
private ArrayList<ModelNotification> notificationsList;
private NotificationAdapter notificationAdapter;
public NotificationFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_blank, container, false);
notificationRv = view.findViewById(R.id.notificationRv);
firebaseAuth = FirebaseAuth.getInstance();
getAllNotifications();
return view;
}
private void getAllNotifications() {
notificationsList = new ArrayList<>();
DatabaseReference ref = FirebaseDatabase.getInstance("https://helper-70936-default-rtdb.firebaseio.com/").getReference("users");
ref.child(firebaseAuth.getUid()).child("Notifications")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
notificationsList.clear();
for(DataSnapshot ds: dataSnapshot.getChildren()){
ModelNotification model = ds. getValue(ModelNotification.class);
notificationsList.add(model);
}
notificationAdapter = new NotificationAdapter(getActivity(), notificationsList);
notificationRv.setAdapter(notificationAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}