I'm learning MVP design pattern and I have retrieved data from the firebase realtime database in RecyclerView. Now I want to Query Data, how can I do that? I have searched a lot but didn't find any relevant solution to my problem. This is my code which I'm using to simply show data in recyclerview using MVP design pattern
Interface :
public interface DashboardContract {
interface View {
void onEventRead(ArrayList<Events> allEvents);
}
interface Presenter {
void retrieveEvents(DatabaseReference databaseReference);
}
interface Interactor {
void performRetrieveEvent(DatabaseReference databaseReference);
}
interface onOperationListener{
void onRead(ArrayList<Events> allEvents);
}
Interactor :
@Override
public void performRetrieveEvent(DatabaseReference databaseReference) {
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Events events = dataSnapshot.getValue(Events.class);
allEvents.add(events);
mListener.onRead(allEvents);
}
Presenter
private DashboardContract.View mView; private DashboardInteractor interactor;
public DashboardPresenter(DashboardContract.View mView) {
this.mView = mView;
interactor = new DashboardInteractor(this);
}
@Override
public void retrieveEvents(DatabaseReference databaseReference) {
interactor.performRetrieveEvent(databaseReference);
}
@Override
public void onRead(ArrayList<Events> allEvents) {
mView.onEventRead(allEvents);
}
Activity
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("Head").child("Events");
DashboardPresenter mPresenter = new DashboardPresenter(this);
mPresenter.retrieveEvents(databaseReference);
@Override
public void onEventRead(ArrayList<Events> allEvents) {
this.mEvents = allEvents;
dashboardAdapter = new DashboardAdapter(DashboardActivity.this, allEvents);
recyclerView.setAdapter(dashboardAdapter);
}
This is my firebase database snapshot :
Note:
- I want to Query data using charges entity.
- How can I do that, where should I query it?
Aucun commentaire:
Enregistrer un commentaire