ValueEventListener returning null?

0

I'm moving with the API of a website and from there I get information about an item from a list of items that came from the API and saved in the Firebase database, now I'm trying to get this information from Firebase to use it, but I can not do it at all ... Now the Log I have there is not printing and when I can get it printed it shows null. If you can help me, I'll be grateful!

Firebase

ComicVineModel

privateLongid;privateStringname;privateStringapi_detail_url;publicComicVineModel(){}publicLonggetId(){returnid;}publicvoidsetId(Longid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetApi_detail_url(){returnapi_detail_url;}publicvoidsetApi_detail_url(Stringapi_detail_url){this.api_detail_url=api_detail_url;}

VolumeAdapter(whereI'mtryingtogetthedata)

privateArrayList<VolumeModel>volume=newArrayList<>();privateContextcontext;privateFirebaseAuthautenticacao;privateDatabaseReferencefirebase;privateVolumeModelvolumeModel=newVolumeModel();privateComicVineModelcomicVineModel=newComicVineModel();privateArrayList<ComicVineModel>listaVineModel=newArrayList<ComicVineModel>();;privateValueEventListenereventListenerVolume;publicVolumeAdapter(Contextc,ArrayList<VolumeModel>volume){this.volume=volume;this.context=c;}@NonNull@OverridepublicMyViewHolderonCreateViewHolder(@NonNullViewGroupparent,intviewType){ViewitemLista=LayoutInflater.from(parent.getContext()).inflate(R.layout.card_volume,parent,false);returnnewMyViewHolder(itemLista);}@OverridepublicvoidonBindViewHolder(@NonNullfinalMyViewHolderholder,finalintposition){volumeModel=volume.get(position);firebase=FirebaseDatabase.getInstance().getReference("volume");

    holder.nome.setText(volumeModel.getName());
    Picasso.with(context)
            .load(volume.get(position).getImage().getThumb_url())
            //.placeholder(R.drawable.default_hero)
            .error(R.drawable.default_hero)
            .into(holder.imageView);
    holder.ano.setText(volumeModel.getStart_year());
    holder.edicoes.setText(volumeModel.getCount_of_issues());
    holder.editora.setText(volumeModel.getPublisher().getName());


    holder.estrela.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            holder.estrela.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_star_black_24dp));

            //pega a posição marcada e seta essas informações para irem pro banco
            comicVineModel.setId(volume.get(position).getId());
            comicVineModel.setName(volume.get(position).getName());
            comicVineModel.setApi_detail_url(volume.get(position).getApi_detail_url());

            //salva a revista no Firebase no formato de: colecao - id da revista - dados do volume
            DatabaseReference firebaseSalvaRevista = FirebaseDatabase.getInstance().getReference(usuario());
            firebaseSalvaRevista.child("colecao").child(comicVineModel.getId().toString()).setValue(comicVineModel);

            Toast.makeText(context, comicVineModel.getName() + " está nos favoritos!", Toast.LENGTH_LONG).show();
        }
    });

    eventListenerVolume = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot dados : dataSnapshot.getChildren()) {
                comicVineModel = dados.getValue(ComicVineModel.class);
                listaVineModel.add(comicVineModel);
                Log.i("teste", "teste: " + comicVineModel);
            }
            VolumeAdapter.this.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };
    firebase.addValueEventListener(eventListenerVolume);

}

@Override
public int getItemCount() {
    return volume.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder{
    private TextView nome;
    private ImageView imageView;
    private TextView ano;
    private TextView edicoes;
    private TextView editora;
    private ImageView estrela;

    public MyViewHolder(View itemView) {
        super(itemView);
        nome = itemView.findViewById(R.id.idNomeRevista);
        imageView = itemView.findViewById(R.id.idImagemVolume);
        ano = itemView.findViewById(R.id.idAno);
        edicoes = itemView.findViewById(R.id.idEdicoes);
        editora = itemView.findViewById(R.id.idEditora);
        estrela = itemView.findViewById(R.id.idEstrela);
    }
}

public String usuario(){
    autenticacao = ConfigFirebase.getFirebaseAutenticacao();
    String usuario = autenticacao.getCurrentUser().getEmail().toString();

    usuario = Base64Custom.codificarBase64(usuario);

    return usuario;
}
    
asked by anonymous 15.08.2018 / 17:38

0 answers