FirebaseRecyclerAdapter to populate object with other object inside












0















I'm new to Android development and need help with populating data from Firebase Realtime database into the FirebaseRecyclerAdapter.



My app has a list of workshops. A user can log in to my test app with a GitHub auth and I get a user email to sign in or out from the workshop if the relevant button is pressed.



So in some point, my workshop contains a list of users as per the example below in Firebase.
enter image description here



The problem is that I need to highlight workshops that users have already signed into in the recycler view.



The main issue I face is when populating the info for each workshop. I can easily get the users to list separately later, but I don't know how to do this within one nice Workshop object from the very beginning.



I'm lost. Please help.



My FirebaseRecyclerAdapter:



public class WorkshopsFirebaseRecyclerAdapter extends FirebaseRecyclerAdapter<Workshop, WorkshopViewHolder> {

private Context mContext;
private ProgressBar progressBar;

public WorkshopsFirebaseRecyclerAdapter(FirebaseRecyclerOptions<Workshop> options, Context context, ProgressBar view) {
super(options);
mContext = context;
progressBar = view;
}

@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

@Override
protected void onBindViewHolder(@NonNull final WorkshopViewHolder holder, final int position, @NonNull final Workshop model) {

final Workshop workshop = getItem(position);
final String id = getRef(position).getKey();

holder.date.setText(getUserFriendlyDate(workshop.getDate()));
holder.description.setText(workshop.getDescription());

if (workshop.getWorkshopAttendants() != null){
Timber.i("onBindViewHolder workshop is %s", workshop.toString());
}

holder.getView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TinyDB tinyDB = new TinyDB(mContext);
tinyDB.putObject(mContext.getString(R.string.workshop_tinydb_key), workshop);
Intent intent = new Intent(mContext, WorkshopDetailsActivity.class);
intent.putExtra(mContext.getString(R.string.open_workshop_details_intent_key),
WorkshopDetailsActivity.INTENT_OPEN_UPDATE_WORKSHOP_DETAILS);
intent.putExtra(mContext.getString(R.string.current_workshop_id_key), id);
mContext.startActivity(intent);
}
});
}

@Override
public WorkshopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.workshop_rv_item, viewGroup, false);
return new WorkshopViewHolder(itemView);
}

private String getUserFriendlyDate(String dateOld){
Date date = new Date();
SimpleDateFormat oldDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.UK);
try {
date = oldDateFormat.parse(dateOld);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.UK);
return newDateFormat.format(date);
}

}


My method where I set adapter and query:



 private void loadWorkshopsForCity(String city) {
Query query;
if (city.equals(getString(R.string.spinner_cities_all_value))) {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.limitToLast(50);
} else {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.orderByChild(getString(R.string.firebase_workshop_city_name_key))
.equalTo(city);
}

query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot workshopSnapshot : dataSnapshot.getChildren()) {
Workshop workshop = workshopSnapshot.getValue(Workshop.class);
for(DataSnapshot usersSnapshot : workshopSnapshot.child("users").getChildren()){
if (usersSnapshot.exists()){
WorkshopAttendant user = usersSnapshot.getValue(WorkshopAttendant.class);
if (user!=null){
users.add(user);
}
}
}
if (users.size()!=0){
workshop.setWorkshopAttendants(users);
}
}
}


@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Timber.i(databaseError.toException());
}
});

FirebaseRecyclerOptions<Workshop> options =
new FirebaseRecyclerOptions.Builder<Workshop>()
.setQuery(query, Workshop.class)
.build();

if (adapter != null) {
adapter.stopListening();
}

adapter = new WorkshopsFirebaseRecyclerAdapter(options, this, progressBar);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(adapter);
adapter.startListening();

}


my Workshop that contains Attendants list:



public class Workshop {

private String date;
private String time;
private String description;
private String name;
private String address;
private String city;
private List<WorkshopAttendant> workshopAttendants;

private boolean isChecked;

// empty constructor for firebase
public Workshop() {
}

public Workshop(String date, String time, String description, String name, String address, String city,
List<WorkshopAttendant> workshopAttendants) {
this.date = date;
this.time = time;
this.description = description;
this.name = name;
this.address = address;
this.city = city;
this.workshopAttendants = workshopAttendants;
} .....


and other WorkshopAttendant that should be inside Workshop object.



public class WorkshopAttendant {

private String email;
private int role; // 1 - coach ; 0 - organiser ; 2 - student

public WorkshopAttendant(String userEmail, int role) {
this.email = userEmail;
this.role = role;
}

// for firebase
public WorkshopAttendant() {
}









share|improve this question

























  • Have you tried to use workshop.getWorkshopAttendants to get the list?

    – Alex Mamo
    Nov 26 '18 at 8:34











  • hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

    – Tania Kolesnik
    Nov 26 '18 at 14:13













  • You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

    – Alex Mamo
    Nov 26 '18 at 14:14











  • you are very quick in replying. thank you :)) please see my edited comment above.

    – Tania Kolesnik
    Nov 26 '18 at 14:16











  • What does workshop.getWorkshopAttendants() return?

    – Alex Mamo
    Nov 26 '18 at 14:18
















0















I'm new to Android development and need help with populating data from Firebase Realtime database into the FirebaseRecyclerAdapter.



My app has a list of workshops. A user can log in to my test app with a GitHub auth and I get a user email to sign in or out from the workshop if the relevant button is pressed.



So in some point, my workshop contains a list of users as per the example below in Firebase.
enter image description here



The problem is that I need to highlight workshops that users have already signed into in the recycler view.



The main issue I face is when populating the info for each workshop. I can easily get the users to list separately later, but I don't know how to do this within one nice Workshop object from the very beginning.



I'm lost. Please help.



My FirebaseRecyclerAdapter:



public class WorkshopsFirebaseRecyclerAdapter extends FirebaseRecyclerAdapter<Workshop, WorkshopViewHolder> {

private Context mContext;
private ProgressBar progressBar;

public WorkshopsFirebaseRecyclerAdapter(FirebaseRecyclerOptions<Workshop> options, Context context, ProgressBar view) {
super(options);
mContext = context;
progressBar = view;
}

@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

@Override
protected void onBindViewHolder(@NonNull final WorkshopViewHolder holder, final int position, @NonNull final Workshop model) {

final Workshop workshop = getItem(position);
final String id = getRef(position).getKey();

holder.date.setText(getUserFriendlyDate(workshop.getDate()));
holder.description.setText(workshop.getDescription());

if (workshop.getWorkshopAttendants() != null){
Timber.i("onBindViewHolder workshop is %s", workshop.toString());
}

holder.getView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TinyDB tinyDB = new TinyDB(mContext);
tinyDB.putObject(mContext.getString(R.string.workshop_tinydb_key), workshop);
Intent intent = new Intent(mContext, WorkshopDetailsActivity.class);
intent.putExtra(mContext.getString(R.string.open_workshop_details_intent_key),
WorkshopDetailsActivity.INTENT_OPEN_UPDATE_WORKSHOP_DETAILS);
intent.putExtra(mContext.getString(R.string.current_workshop_id_key), id);
mContext.startActivity(intent);
}
});
}

@Override
public WorkshopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.workshop_rv_item, viewGroup, false);
return new WorkshopViewHolder(itemView);
}

private String getUserFriendlyDate(String dateOld){
Date date = new Date();
SimpleDateFormat oldDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.UK);
try {
date = oldDateFormat.parse(dateOld);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.UK);
return newDateFormat.format(date);
}

}


My method where I set adapter and query:



 private void loadWorkshopsForCity(String city) {
Query query;
if (city.equals(getString(R.string.spinner_cities_all_value))) {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.limitToLast(50);
} else {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.orderByChild(getString(R.string.firebase_workshop_city_name_key))
.equalTo(city);
}

query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot workshopSnapshot : dataSnapshot.getChildren()) {
Workshop workshop = workshopSnapshot.getValue(Workshop.class);
for(DataSnapshot usersSnapshot : workshopSnapshot.child("users").getChildren()){
if (usersSnapshot.exists()){
WorkshopAttendant user = usersSnapshot.getValue(WorkshopAttendant.class);
if (user!=null){
users.add(user);
}
}
}
if (users.size()!=0){
workshop.setWorkshopAttendants(users);
}
}
}


@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Timber.i(databaseError.toException());
}
});

FirebaseRecyclerOptions<Workshop> options =
new FirebaseRecyclerOptions.Builder<Workshop>()
.setQuery(query, Workshop.class)
.build();

if (adapter != null) {
adapter.stopListening();
}

adapter = new WorkshopsFirebaseRecyclerAdapter(options, this, progressBar);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(adapter);
adapter.startListening();

}


my Workshop that contains Attendants list:



public class Workshop {

private String date;
private String time;
private String description;
private String name;
private String address;
private String city;
private List<WorkshopAttendant> workshopAttendants;

private boolean isChecked;

// empty constructor for firebase
public Workshop() {
}

public Workshop(String date, String time, String description, String name, String address, String city,
List<WorkshopAttendant> workshopAttendants) {
this.date = date;
this.time = time;
this.description = description;
this.name = name;
this.address = address;
this.city = city;
this.workshopAttendants = workshopAttendants;
} .....


and other WorkshopAttendant that should be inside Workshop object.



public class WorkshopAttendant {

private String email;
private int role; // 1 - coach ; 0 - organiser ; 2 - student

public WorkshopAttendant(String userEmail, int role) {
this.email = userEmail;
this.role = role;
}

// for firebase
public WorkshopAttendant() {
}









share|improve this question

























  • Have you tried to use workshop.getWorkshopAttendants to get the list?

    – Alex Mamo
    Nov 26 '18 at 8:34











  • hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

    – Tania Kolesnik
    Nov 26 '18 at 14:13













  • You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

    – Alex Mamo
    Nov 26 '18 at 14:14











  • you are very quick in replying. thank you :)) please see my edited comment above.

    – Tania Kolesnik
    Nov 26 '18 at 14:16











  • What does workshop.getWorkshopAttendants() return?

    – Alex Mamo
    Nov 26 '18 at 14:18














0












0








0








I'm new to Android development and need help with populating data from Firebase Realtime database into the FirebaseRecyclerAdapter.



My app has a list of workshops. A user can log in to my test app with a GitHub auth and I get a user email to sign in or out from the workshop if the relevant button is pressed.



So in some point, my workshop contains a list of users as per the example below in Firebase.
enter image description here



The problem is that I need to highlight workshops that users have already signed into in the recycler view.



The main issue I face is when populating the info for each workshop. I can easily get the users to list separately later, but I don't know how to do this within one nice Workshop object from the very beginning.



I'm lost. Please help.



My FirebaseRecyclerAdapter:



public class WorkshopsFirebaseRecyclerAdapter extends FirebaseRecyclerAdapter<Workshop, WorkshopViewHolder> {

private Context mContext;
private ProgressBar progressBar;

public WorkshopsFirebaseRecyclerAdapter(FirebaseRecyclerOptions<Workshop> options, Context context, ProgressBar view) {
super(options);
mContext = context;
progressBar = view;
}

@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

@Override
protected void onBindViewHolder(@NonNull final WorkshopViewHolder holder, final int position, @NonNull final Workshop model) {

final Workshop workshop = getItem(position);
final String id = getRef(position).getKey();

holder.date.setText(getUserFriendlyDate(workshop.getDate()));
holder.description.setText(workshop.getDescription());

if (workshop.getWorkshopAttendants() != null){
Timber.i("onBindViewHolder workshop is %s", workshop.toString());
}

holder.getView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TinyDB tinyDB = new TinyDB(mContext);
tinyDB.putObject(mContext.getString(R.string.workshop_tinydb_key), workshop);
Intent intent = new Intent(mContext, WorkshopDetailsActivity.class);
intent.putExtra(mContext.getString(R.string.open_workshop_details_intent_key),
WorkshopDetailsActivity.INTENT_OPEN_UPDATE_WORKSHOP_DETAILS);
intent.putExtra(mContext.getString(R.string.current_workshop_id_key), id);
mContext.startActivity(intent);
}
});
}

@Override
public WorkshopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.workshop_rv_item, viewGroup, false);
return new WorkshopViewHolder(itemView);
}

private String getUserFriendlyDate(String dateOld){
Date date = new Date();
SimpleDateFormat oldDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.UK);
try {
date = oldDateFormat.parse(dateOld);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.UK);
return newDateFormat.format(date);
}

}


My method where I set adapter and query:



 private void loadWorkshopsForCity(String city) {
Query query;
if (city.equals(getString(R.string.spinner_cities_all_value))) {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.limitToLast(50);
} else {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.orderByChild(getString(R.string.firebase_workshop_city_name_key))
.equalTo(city);
}

query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot workshopSnapshot : dataSnapshot.getChildren()) {
Workshop workshop = workshopSnapshot.getValue(Workshop.class);
for(DataSnapshot usersSnapshot : workshopSnapshot.child("users").getChildren()){
if (usersSnapshot.exists()){
WorkshopAttendant user = usersSnapshot.getValue(WorkshopAttendant.class);
if (user!=null){
users.add(user);
}
}
}
if (users.size()!=0){
workshop.setWorkshopAttendants(users);
}
}
}


@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Timber.i(databaseError.toException());
}
});

FirebaseRecyclerOptions<Workshop> options =
new FirebaseRecyclerOptions.Builder<Workshop>()
.setQuery(query, Workshop.class)
.build();

if (adapter != null) {
adapter.stopListening();
}

adapter = new WorkshopsFirebaseRecyclerAdapter(options, this, progressBar);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(adapter);
adapter.startListening();

}


my Workshop that contains Attendants list:



public class Workshop {

private String date;
private String time;
private String description;
private String name;
private String address;
private String city;
private List<WorkshopAttendant> workshopAttendants;

private boolean isChecked;

// empty constructor for firebase
public Workshop() {
}

public Workshop(String date, String time, String description, String name, String address, String city,
List<WorkshopAttendant> workshopAttendants) {
this.date = date;
this.time = time;
this.description = description;
this.name = name;
this.address = address;
this.city = city;
this.workshopAttendants = workshopAttendants;
} .....


and other WorkshopAttendant that should be inside Workshop object.



public class WorkshopAttendant {

private String email;
private int role; // 1 - coach ; 0 - organiser ; 2 - student

public WorkshopAttendant(String userEmail, int role) {
this.email = userEmail;
this.role = role;
}

// for firebase
public WorkshopAttendant() {
}









share|improve this question
















I'm new to Android development and need help with populating data from Firebase Realtime database into the FirebaseRecyclerAdapter.



My app has a list of workshops. A user can log in to my test app with a GitHub auth and I get a user email to sign in or out from the workshop if the relevant button is pressed.



So in some point, my workshop contains a list of users as per the example below in Firebase.
enter image description here



The problem is that I need to highlight workshops that users have already signed into in the recycler view.



The main issue I face is when populating the info for each workshop. I can easily get the users to list separately later, but I don't know how to do this within one nice Workshop object from the very beginning.



I'm lost. Please help.



My FirebaseRecyclerAdapter:



public class WorkshopsFirebaseRecyclerAdapter extends FirebaseRecyclerAdapter<Workshop, WorkshopViewHolder> {

private Context mContext;
private ProgressBar progressBar;

public WorkshopsFirebaseRecyclerAdapter(FirebaseRecyclerOptions<Workshop> options, Context context, ProgressBar view) {
super(options);
mContext = context;
progressBar = view;
}

@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

@Override
protected void onBindViewHolder(@NonNull final WorkshopViewHolder holder, final int position, @NonNull final Workshop model) {

final Workshop workshop = getItem(position);
final String id = getRef(position).getKey();

holder.date.setText(getUserFriendlyDate(workshop.getDate()));
holder.description.setText(workshop.getDescription());

if (workshop.getWorkshopAttendants() != null){
Timber.i("onBindViewHolder workshop is %s", workshop.toString());
}

holder.getView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TinyDB tinyDB = new TinyDB(mContext);
tinyDB.putObject(mContext.getString(R.string.workshop_tinydb_key), workshop);
Intent intent = new Intent(mContext, WorkshopDetailsActivity.class);
intent.putExtra(mContext.getString(R.string.open_workshop_details_intent_key),
WorkshopDetailsActivity.INTENT_OPEN_UPDATE_WORKSHOP_DETAILS);
intent.putExtra(mContext.getString(R.string.current_workshop_id_key), id);
mContext.startActivity(intent);
}
});
}

@Override
public WorkshopViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.workshop_rv_item, viewGroup, false);
return new WorkshopViewHolder(itemView);
}

private String getUserFriendlyDate(String dateOld){
Date date = new Date();
SimpleDateFormat oldDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.UK);
try {
date = oldDateFormat.parse(dateOld);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.UK);
return newDateFormat.format(date);
}

}


My method where I set adapter and query:



 private void loadWorkshopsForCity(String city) {
Query query;
if (city.equals(getString(R.string.spinner_cities_all_value))) {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.limitToLast(50);
} else {
query = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_root_name))
.child(getString(R.string.firebase_workshops_root_name))
.orderByChild(getString(R.string.firebase_workshop_city_name_key))
.equalTo(city);
}

query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot workshopSnapshot : dataSnapshot.getChildren()) {
Workshop workshop = workshopSnapshot.getValue(Workshop.class);
for(DataSnapshot usersSnapshot : workshopSnapshot.child("users").getChildren()){
if (usersSnapshot.exists()){
WorkshopAttendant user = usersSnapshot.getValue(WorkshopAttendant.class);
if (user!=null){
users.add(user);
}
}
}
if (users.size()!=0){
workshop.setWorkshopAttendants(users);
}
}
}


@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Timber.i(databaseError.toException());
}
});

FirebaseRecyclerOptions<Workshop> options =
new FirebaseRecyclerOptions.Builder<Workshop>()
.setQuery(query, Workshop.class)
.build();

if (adapter != null) {
adapter.stopListening();
}

adapter = new WorkshopsFirebaseRecyclerAdapter(options, this, progressBar);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(adapter);
adapter.startListening();

}


my Workshop that contains Attendants list:



public class Workshop {

private String date;
private String time;
private String description;
private String name;
private String address;
private String city;
private List<WorkshopAttendant> workshopAttendants;

private boolean isChecked;

// empty constructor for firebase
public Workshop() {
}

public Workshop(String date, String time, String description, String name, String address, String city,
List<WorkshopAttendant> workshopAttendants) {
this.date = date;
this.time = time;
this.description = description;
this.name = name;
this.address = address;
this.city = city;
this.workshopAttendants = workshopAttendants;
} .....


and other WorkshopAttendant that should be inside Workshop object.



public class WorkshopAttendant {

private String email;
private int role; // 1 - coach ; 0 - organiser ; 2 - student

public WorkshopAttendant(String userEmail, int role) {
this.email = userEmail;
this.role = role;
}

// for firebase
public WorkshopAttendant() {
}






android firebase firebase-realtime-database android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 13:25









KENdi

5,8292921




5,8292921










asked Nov 25 '18 at 17:49









Tania KolesnikTania Kolesnik

113




113













  • Have you tried to use workshop.getWorkshopAttendants to get the list?

    – Alex Mamo
    Nov 26 '18 at 8:34











  • hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

    – Tania Kolesnik
    Nov 26 '18 at 14:13













  • You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

    – Alex Mamo
    Nov 26 '18 at 14:14











  • you are very quick in replying. thank you :)) please see my edited comment above.

    – Tania Kolesnik
    Nov 26 '18 at 14:16











  • What does workshop.getWorkshopAttendants() return?

    – Alex Mamo
    Nov 26 '18 at 14:18



















  • Have you tried to use workshop.getWorkshopAttendants to get the list?

    – Alex Mamo
    Nov 26 '18 at 8:34











  • hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

    – Tania Kolesnik
    Nov 26 '18 at 14:13













  • You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

    – Alex Mamo
    Nov 26 '18 at 14:14











  • you are very quick in replying. thank you :)) please see my edited comment above.

    – Tania Kolesnik
    Nov 26 '18 at 14:16











  • What does workshop.getWorkshopAttendants() return?

    – Alex Mamo
    Nov 26 '18 at 14:18

















Have you tried to use workshop.getWorkshopAttendants to get the list?

– Alex Mamo
Nov 26 '18 at 8:34





Have you tried to use workshop.getWorkshopAttendants to get the list?

– Alex Mamo
Nov 26 '18 at 8:34













hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

– Tania Kolesnik
Nov 26 '18 at 14:13







hi @AlexMamo, thanks for looking. I saw you replied in other Firebase related topics, so really appreciate you looked at my case too. I tried, but it's null for my loaded workshops. I added logging to each step in my query and I can users info there, but my workshops I get at the end don't have it. I worry I add them the wrong way.

– Tania Kolesnik
Nov 26 '18 at 14:13















You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

– Alex Mamo
Nov 26 '18 at 14:14





You're welcome Tania! Have solved the issue workshop.getWorkshopAttendants?

– Alex Mamo
Nov 26 '18 at 14:14













you are very quick in replying. thank you :)) please see my edited comment above.

– Tania Kolesnik
Nov 26 '18 at 14:16





you are very quick in replying. thank you :)) please see my edited comment above.

– Tania Kolesnik
Nov 26 '18 at 14:16













What does workshop.getWorkshopAttendants() return?

– Alex Mamo
Nov 26 '18 at 14:18





What does workshop.getWorkshopAttendants() return?

– Alex Mamo
Nov 26 '18 at 14:18












1 Answer
1






active

oldest

votes


















0














1) List workshopAttendants in Workshop model to Map users = new HashMap<>();



2) used new SnapshotParser for my Recycler options;



FirebaseRecyclerOptions<Workshop> options =
new FirebaseRecyclerOptions.Builder<Workshop>()
.setQuery(query, new SnapshotParser<Workshop>() {
@NonNull
@Override
public Workshop parseSnapshot(@NonNull DataSnapshot snapshot) {
GenericTypeIndicator<Workshop> t = new GenericTypeIndicator<Workshop>() {};
Workshop workshop = snapshot.getValue(t);
return workshop;
}
})
.build();


3) in my adapter I set check for users so now can mark workshops that have users signed for.



try {
Map<String, User> users = workshop.getValue();
if (users.size()!=0){holder.description.setBackgroundColor(mContext.getColor(R.color.colorPrimaryDark));
}
} catch (NullPointerException e){
Timber.i(e, "no users for %s", workshop.getDescription());
}


thanks, @AlexMamo for patience






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470233%2ffirebaserecycleradapter-to-populate-object-with-other-object-inside%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    1) List workshopAttendants in Workshop model to Map users = new HashMap<>();



    2) used new SnapshotParser for my Recycler options;



    FirebaseRecyclerOptions<Workshop> options =
    new FirebaseRecyclerOptions.Builder<Workshop>()
    .setQuery(query, new SnapshotParser<Workshop>() {
    @NonNull
    @Override
    public Workshop parseSnapshot(@NonNull DataSnapshot snapshot) {
    GenericTypeIndicator<Workshop> t = new GenericTypeIndicator<Workshop>() {};
    Workshop workshop = snapshot.getValue(t);
    return workshop;
    }
    })
    .build();


    3) in my adapter I set check for users so now can mark workshops that have users signed for.



    try {
    Map<String, User> users = workshop.getValue();
    if (users.size()!=0){holder.description.setBackgroundColor(mContext.getColor(R.color.colorPrimaryDark));
    }
    } catch (NullPointerException e){
    Timber.i(e, "no users for %s", workshop.getDescription());
    }


    thanks, @AlexMamo for patience






    share|improve this answer




























      0














      1) List workshopAttendants in Workshop model to Map users = new HashMap<>();



      2) used new SnapshotParser for my Recycler options;



      FirebaseRecyclerOptions<Workshop> options =
      new FirebaseRecyclerOptions.Builder<Workshop>()
      .setQuery(query, new SnapshotParser<Workshop>() {
      @NonNull
      @Override
      public Workshop parseSnapshot(@NonNull DataSnapshot snapshot) {
      GenericTypeIndicator<Workshop> t = new GenericTypeIndicator<Workshop>() {};
      Workshop workshop = snapshot.getValue(t);
      return workshop;
      }
      })
      .build();


      3) in my adapter I set check for users so now can mark workshops that have users signed for.



      try {
      Map<String, User> users = workshop.getValue();
      if (users.size()!=0){holder.description.setBackgroundColor(mContext.getColor(R.color.colorPrimaryDark));
      }
      } catch (NullPointerException e){
      Timber.i(e, "no users for %s", workshop.getDescription());
      }


      thanks, @AlexMamo for patience






      share|improve this answer


























        0












        0








        0







        1) List workshopAttendants in Workshop model to Map users = new HashMap<>();



        2) used new SnapshotParser for my Recycler options;



        FirebaseRecyclerOptions<Workshop> options =
        new FirebaseRecyclerOptions.Builder<Workshop>()
        .setQuery(query, new SnapshotParser<Workshop>() {
        @NonNull
        @Override
        public Workshop parseSnapshot(@NonNull DataSnapshot snapshot) {
        GenericTypeIndicator<Workshop> t = new GenericTypeIndicator<Workshop>() {};
        Workshop workshop = snapshot.getValue(t);
        return workshop;
        }
        })
        .build();


        3) in my adapter I set check for users so now can mark workshops that have users signed for.



        try {
        Map<String, User> users = workshop.getValue();
        if (users.size()!=0){holder.description.setBackgroundColor(mContext.getColor(R.color.colorPrimaryDark));
        }
        } catch (NullPointerException e){
        Timber.i(e, "no users for %s", workshop.getDescription());
        }


        thanks, @AlexMamo for patience






        share|improve this answer













        1) List workshopAttendants in Workshop model to Map users = new HashMap<>();



        2) used new SnapshotParser for my Recycler options;



        FirebaseRecyclerOptions<Workshop> options =
        new FirebaseRecyclerOptions.Builder<Workshop>()
        .setQuery(query, new SnapshotParser<Workshop>() {
        @NonNull
        @Override
        public Workshop parseSnapshot(@NonNull DataSnapshot snapshot) {
        GenericTypeIndicator<Workshop> t = new GenericTypeIndicator<Workshop>() {};
        Workshop workshop = snapshot.getValue(t);
        return workshop;
        }
        })
        .build();


        3) in my adapter I set check for users so now can mark workshops that have users signed for.



        try {
        Map<String, User> users = workshop.getValue();
        if (users.size()!=0){holder.description.setBackgroundColor(mContext.getColor(R.color.colorPrimaryDark));
        }
        } catch (NullPointerException e){
        Timber.i(e, "no users for %s", workshop.getDescription());
        }


        thanks, @AlexMamo for patience







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 '18 at 22:40









        Tania KolesnikTania Kolesnik

        113




        113
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470233%2ffirebaserecycleradapter-to-populate-object-with-other-object-inside%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'