I have 2 queries that pull from the different source (both firebase database realtime) that I would like to appear in my FirebaseRecyclerAdapter. I have been banging my head against this particular issue for a bit but i couldn't think of anything.
How can i achieve this and merge it to the below code.
Likes JSON structure
"Likes" : {
"-LAJRnaAaCGrbv8-cXvD" : {
"5SWi7kiLTdW4WS1MDV5Knxeo0qt1" : {
"-LDqyWmTa-sbgKpxOztv" : {
"Likes" : "5SWi7kiLTdW4WS1MDV5Knxeo0qt1"
}
},
"6Zv4wIWV3WOyHxgABXkecK18IJ03" : {
"-LDlj87M--DZVBgBJTUT" : {
"Likes" : "6Zv4wIWV3WOyHxgABXkecK18IJ03"
}
},
"ktLMV4x9kGN43Ggrx5YWhkaG7BL2" : {
"-LDkQ-jAwb7oI3N4T__R" : {
"Likes" : "ktLMV4x9kGN43Ggrx5YWhkaG7BL2"
}
}
}
},
Recipe JSON structure
"PostRecipe" : {
"-LAJRnaAaCGrbv8-cXvD" : {
"appetizer" : "Appetizer",
"cooking_time" : "40 mins",
"desert" : "Dessert",
"difficult_level" : "5",
"main_course" : "Main course",
"name" : "Smokey Party Jollof",
"number_of_people" : "5",
"photo1" : "https://firebasestorage.googleapis.com/v0/b/chefcook-1865d.appspot.com/o/recipe_photos%2F43262?alt=media&token=07103c5d-9924-4e02-985c-fbc02920228f",
"photo2" : "https://firebasestorage.googleapis.com/v0/b/chefcook-1865d.appspot.com/o/recipe_photos%2F43237?alt=media&token=1d398256-0058-4f78-a13f-66301acc4f75",
"photo3" : "something",
"photo4" : "something",
"pizza_fritas" : "Pizza, fritas",
"prepare_time" : "3hrs",
"side_dish" : "Side dish",
"tips" : "Blended stew base is the best base for making traditional stew.",
"userId" : "5SWi7kiLTdW4WS1MDV5Knxeo0qt1",
"vegetarian" : "Vegetarian"
}
}
},
MainRecipeFragment.java
...
mDatabase = FirebaseDatabase.getInstance().
getReference().child("Post").child("PostRecipe").orderByChild("photo1").startAt(n);
@Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
mAdapter = new FirebaseRecyclerAdapter<RecipeModel, NewViewHolder>(RecipeModel.class, R.layout
.activty_content_list,
NewViewHolder.class, mDatabase) {
@Override
protected void populateViewHolder(final NewViewHolder viewHolder, final RecipeModel model,
final int
position) {
final DatabaseReference postRef = getRef(position);
Log.e(TAG , "adpter" + model.getName() + model.getPhoto1());
// Set click listener for the whole post view
final String cheeseKey = postRef.getKey();
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Launch PostDetailActivity
Intent intent = new Intent(getActivity(), RecipeDetails.class);
intent.putExtra(RecipeDetails.EXTRA_CHEESE_KEY, cheeseKey);
startActivity(intent);
}
});
// Bind Post to ViewHolder
Context context = getActivity();
viewHolder.bindToCheese(model, context);
}
};
ViewHolder
public class ViewHolder extends RecyclerView.ViewHolder {
String LOG_TAG = ViewHolder.class.getSimpleName();
private View mView;
private ImageView mImageView;
private TextView mTextView;
private static final String TAG = ViewHolder.class.getSimpleName();
public ViewHolder(View view) {
super(view);
mView = view;
mImageView = view.findViewById(R.id.soup_thumbnail);
mTextView = view.findViewById(R.id.soup_title);
//getActivity();
}
public void bindToCheese(Cheeses cheeses, Context c) {
mTextView.setText(cheeses.getTitle());
Log.d(TAG, "title"+ cheeses.getTitle());
Picasso.with(c).load(String.valueOf(cheeses.getImagerUrl())).placeholder(R.mipmap.ic_launcher).fit().into(mImageView);
Log.e(LOG_TAG, "imageurl"+ cheeses.getImagerUrl() + " title" + cheeses.getTitle()) ;
//Here, how do i reach Like and extract information inside.
//I tried the below log, but it is returning null
Log.e(LOG_TAG, "likes"+ cheeses.getLikes());
}