Tworząc adapter pobieram dane z dwóch tabel w firebase. Niestety zanim dane trafią do mUploads, tworzony jest adapter z pustym "mUploads".
Logcat pokazuje: zero,first,fifth ,second, third,fourth. Stąd wiem że mUploads jest pusty w momencie tworzenia adaptera. Prosiłbym o pomoc w temacie, straciłem cierpliwość do tego, próbowałem nawet z wątkami.
databaseReference.collection("advertisements")
.whereEqualTo("userId",FirebaseAuth.getInstance().getUid())
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable QuerySnapshot snapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
if (e != null) {
System.err.println("Listen failed:" + e);
return;
}
Log.d(TAG, "Zero" );
for (final DocumentSnapshot doc : snapshots) {
Log.d(TAG, "First");
final Upload upload = new Upload();
databaseReferenceUsers.collection("users").document(doc.getString("userId")).addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable DocumentSnapshot documentSnapshot, @javax.annotation.Nullable FirebaseFirestoreException e) {
upload.setPhone(Integer.toString(documentSnapshot.getLong("phone").intValue()));
Log.d(TAG, "Second" );
Log.d(TAG, "Third" );
upload.setName(doc.getString("text"));
upload.setImageUrl(doc.getString("photo"));
upload.setKind(doc.getString("kind"));
upload.setType(doc.getString("type"));
upload.setPrice(doc.getString("price") + "zł");
upload.setVoivodeship(doc.getString("voivodeship"));
upload.setVariety(doc.getString("variety"));
mUploads.add(upload);
Log.d(TAG, "fourth" );
}
});
}
Log.d(TAG, "fifth" );
imageAdapter = new ImageAdapter(MyAdvertisementsActivity.this,mUploads);
recyclerView.setAdapter(imageAdapter);
progressCircle.setVisibility(View.INVISIBLE);
}
});