Search code examples
javaandroidfirebasegoogle-cloud-firestorefirebaseui

How can I include two Model Class Tracks and Artists in one FirestoreRecyclerAdapter in Android?


My android project has two models - Track and Artist.
Track is used to get the information related to Track and Artist is used to get the details related to Artist.

Here is the sample code for the each model:
Track.class

public class Track {
    private int track_ID;
    private String title;
    private String artist;
    private String songWriter;
    private String lyrics;
    private String album;
    private String language;
    private int views;
    private int year;
    private String albumArt;
    private String videoURL;
    private String shareURL;

    public Track(){
        //Empty Constructor
    }

Artist.class

private int artist_ID;
    private String name;
    private boolean verified;
    private String artistProfilePic;

    public Artist(){
        //Empty Constructor
    }

In the code below I am only able to use Track Model

public class SongAdapter extends FirestoreRecyclerAdapter<Track, SongAdapter.SongHolder> {

My problem is I am not able to use both the model in one FirestoreRecyclerAdapter.

How can I do it?


Solution

  • The adapters in FirebaseUI can only show homogeneous results from a single collection.

    If you want to show results from multiple collections, or show heterogenous results from a single collection, you will have to build your own adapter. This is not as complex as some folks think. Give it a try, and post back if you get stuck.

    I recommend having a look at the FirestoreArray class from FirebaseUI if you want to see how it loads the data from the database and keeps it in memory.