Android development recovering data firebase

0

HelloIhaveadatabaseonfirebasethathassomemoviesandseriesandeventvshows,Iwantedtoseparatetheseattributesintogenres,forexample:whateverseriesisfixedinseriesandwhatevermovieisfixedinMoviesetc...butthisIwantedtoputincardsusingrecyclerviewtolistandinthatrecyclerviewaseparationofeachgenreusinghorizontally.Iwantedalight,couldanyonehelpme?

publicclassSalaActivityextendsAppCompatActivityimplementsICRUDAction{privateMyAdapterappListCenterAdapter,appListStartAdapter;privateList<ConteudoSala>conteudoSala,conteudoSala1;privateStringname;privateStringa;privateProgressDialogprogressDialog;

//privateRecyclerViewmRecyclerView;

privatebooleanmHorizontal;publicRecyclerViewrecyclerView;publicRecyclerViewrecyclerView2;DatabaseReferencemDatabase=FirebaseDatabase.getInstance().getReference(DATABASE_PATH_ANIME);@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.sala_lista);ButterKnife.bind(this);progressDialog=newProgressDialog(this);progressDialog.setMessage("Por favor, espere...");
    progressDialog.show();

    getAnime();
    getFilmes();
    request_user_name();

}
public void getAnime(){
    conteudoSala = new ArrayList<>();
    recyclerView = (RecyclerView)findViewById(R.id.recyclerView);




    mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {

            Log.i("onDataChange", snapshot.toString());

            for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                ConteudoSala produto = postSnapshot.getValue(ConteudoSala.class);
                conteudoSala.add(produto);
            }

            LinearLayoutManager layoutManagerCenter
                    = new LinearLayoutManager(SalaActivity.this, LinearLayoutManager.HORIZONTAL, false);
            recyclerView.setLayoutManager(layoutManagerCenter);
            SnapHelper snapHelperCenter = new LinearSnapHelper();
            snapHelperCenter.attachToRecyclerView(recyclerView);

            appListCenterAdapter = new MyAdapter(SalaActivity.this, conteudoSala);

            recyclerView.setAdapter(appListCenterAdapter);

            appListCenterAdapter.notifyDataSetChanged();
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
            progressDialog.dismiss();
        }
    });
}
public void getFilmes() {
    conteudoSala1 = new ArrayList<>();

    recyclerView2 = (RecyclerView)findViewById(R.id.recyclerView2);

    DatabaseReference mDatabase2 = FirebaseDatabase.getInstance().getReference(DATABASE_PATH_FILME);
    mDatabase2.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {

            progressDialog.dismiss();
            Log.i("onDataChange", snapshot.toString());
            for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                ConteudoSala produto1 = postSnapshot.getValue(ConteudoSala.class);
                conteudoSala1.add(produto1);
            }

           appListStartAdapter = new MyAdapter(SalaActivity.this, conteudoSala1);

            LinearLayoutManager layoutManagerStart = new LinearLayoutManager(SalaActivity.this, LinearLayoutManager.HORIZONTAL, false);
            recyclerView2.setLayoutManager(layoutManagerStart);
            SnapHelper snapHelperStart = new StartSnapHelper();
            snapHelperStart.attachToRecyclerView(recyclerView2);

            recyclerView2.setAdapter(appListStartAdapter);

            appListStartAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            progressDialog.dismiss();
        }
    });
    progressDialog.hide();
}
    
asked by anonymous 02.10.2017 / 17:54

1 answer

0

1. Create a reference and list for each category. (Series, Movies, Animes)

    public ArrayList<Objeto> filmes;
    public ArrayList<Objeto> animes;
    public ArrayList<Objeto> series;
    public DatabaseReference database;
    public Query query;


public void getAnimes()
{

    animes = new ArrayList<>();
    database = FirebaseDatabase.getInstance().getReference();
    query = database.child("projetofirebase-32c0b/addAnime");

    query.addChildEventListener(new ChildEventListener()
    {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName)
        {
            Objeto object = dataSnapshot.getValue(Objeto.class);
            animes.add(object);

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}

public void getFilmes()
{

    filmes = new ArrayList<>();
    database = FirebaseDatabase.getInstance().getReference();
    query = database.child("projetofirebase-32c0b/addFilme");

    query.addChildEventListener(new ChildEventListener()
    {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName)
        {
            Objeto object = dataSnapshot.getValue(Objeto.class);
            filmes.add(object);

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}


public void getSeries()
{

    series = new ArrayList<>();
    database = FirebaseDatabase.getInstance().getReference();
    query = database.child("projetofirebase-32c0b/addSerie");

    query.addChildEventListener(new ChildEventListener()
    {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName)
        {
            Objeto object = dataSnapshot.getValue(Objeto.class);
            series.add(object);

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

}

2. Create a class for object model

    public class Objeto
{
    String nome;
    String url;
    String valor;

    public Objeto ()
    {

    }
    public Objeto(String nome,
           String url,
           String valor)
    {
        this.nome = nome;
        this.url = url;
        this.valor = valor;
    }
}

3. Run the getAnimes (), getFilmes (), getSeries ()

4. Check the list of animations, series and movies in your recyclerview

    
02.10.2017 / 23:27