So folks, it's a half-hit question I know, but I could not find any solution here for my code. I need to get the information that is inside node 5883, but apparently it populates my class with the information that is outside and ends up giving the error W/ClassMapper: No setter/field for 5883 found on class com.mycomics.rest.model.ComicVineIssueModel
and I can not make the comparison that I need.
Firebase:
ComicVineModel:
publicclassComicVineModel{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;}}
ComicVineIssueModel
publicclassComicVineIssueModelextendsComicVineModel{privateComicVineModelvolume;privateIntegerissue_number;privateStringstore_date;privateStringcover_date;privateComicVineImageModelimage;privateStringdescription;publicComicVineIssueModel(){}publicIntegergetIssue_number(){returnissue_number;}publicvoidsetIssue_number(Integerissue_number){this.issue_number=issue_number;}@ExcludepublicComicVineModelgetVolume(){returnvolume;}publicvoidsetVolume(ComicVineModelvolume){this.volume=volume;}@ExcludepublicStringgetStore_date(){returnstore_date;}publicvoidsetStore_date(Stringstore_date){this.store_date=store_date;}@ExcludepublicComicVineImageModelgetImage(){returnimage;}publicvoidsetImage(ComicVineImageModelimage){this.image=image;}@ExcludepublicStringgetDescription(){returndescription;}publicvoidsetDescription(Stringdescription){this.description=description;}@ExcludepublicStringgetCover_date(){returncover_date;}publicvoidsetCover_date(Stringcover_date){this.cover_date=cover_date;}
}
IssueAdapter(whereI'msavingandfetchingthedata)
publicclassIssueAdapterextendsRecyclerView.Adapter<IssueAdapter.MyViewHolder>{privateList<ComicVineIssueModel>issue;privateContextcontext;privatebooleanisExpand;privateStringtextoFormatado="";
private FirebaseAuth autenticacao;
private DatabaseReference firebase;
private ChildEventListener childListenerEdicao;
private ComicVineIssueModel issueModel = new ComicVineIssueModel();
private ArrayList<ComicVineIssueModel> listIssue = new ArrayList();
private String volume;
private String idEdicao;
public IssueAdapter(List<ComicVineIssueModel> issue, Context context, String volume) {
this.issue = issue;
this.context = context;
this.volume = volume;
setHasStableIds(true);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemLista = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_issue, parent, false);
firebase = ConfigFirebase.getFirebase();
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {
issueModel = issue.get(position);
/*Código retirado para uma melhor visualização de onde pode estar o problema*/
idEdicao = issueModel.getId().toString();
holder.check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(holder.check.getTag().equals("isChecked")){
holder.check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.uncheck));
firebase.child(usuario()).child(volume).child(issue.get(position).getId().toString()).removeValue();
holder.check.setTag("uncheck");
Toast.makeText(context, issue.get(position).getName() + " deletado com sucesso!", Toast.LENGTH_LONG).show();
}else {
holder.check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.check));
holder.check.setTag("isChecked");
issueModel.setIssue_number(issue.get(position).getIssue_number());
issueModel.setName(issue.get(position).getName());
issueModel.setId(issue.get(position).getId());
//salva a revista no Firebase no formato de: usuario - id da revista - id da edição - dados da revista
DatabaseReference firebaseSalvaRevista = FirebaseDatabase.getInstance().getReference(usuario());
firebaseSalvaRevista.child(volume).child(issue.get(position).getId().toString()).setValue(issueModel);
Toast.makeText(context, issue.get(position).getName() + " está nos favoritos!", Toast.LENGTH_LONG).show();
}
}
});
firebase.child(usuario()).child(volume).child(idEdicao);
recuperarDados(idEdicao, holder.check);
firebase.addChildEventListener(childListenerEdicao);
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return issue.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
private TextView ano;
private TextView titulo;
private TextView edicao;
private ImageView capa;
private ImageView check;
private TextView informacoes;
private ImageView seta;
public MyViewHolder(View itemView) {
super(itemView);
ano = itemView.findViewById(R.id.idAnoEdicao);
titulo = itemView.findViewById(R.id.idTitulo);
capa = itemView.findViewById(R.id.idImagemEdicao);
edicao = itemView.findViewById(R.id.idEdicao);
informacoes = itemView.findViewById(R.id.idInformacoes);
seta = itemView.findViewById(R.id.idSetaInformacoes);
check = itemView.findViewById(R.id.idUncheck);
}
}
public String usuario(){
autenticacao = ConfigFirebase.getFirebaseAutenticacao();
String usuario = autenticacao.getCurrentUser().getEmail().toString();
usuario = Base64Custom.codificarBase64(usuario);
return usuario;
}
public void recuperarDados(final String id, final ImageView check){
childListenerEdicao = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
listIssue.clear();
for(DataSnapshot dados : dataSnapshot.getChildren()) {
issueModel = dados.getValue(ComicVineIssueModel.class);
listIssue.add(issueModel);
if(issueModel.getId().toString().equals(id)){
check.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.check));
check.setTag("isChecked");
}
}
IssueAdapter.this.notifyDataSetChanged();
}
@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) {
}
};
}
}