I am getting responses from two different JSON API's where a id object is common in both the API's. I want to know how many times does a id from first response occurs in second response. like if id="642" from first response occurs two times in second response, then count =2. Like this for each id and then set it in side the recycler view for each positions for txtCountNo inside adapter.
First Response:
[{
"id": "642"
"Full_name": "Harsh",
},
{
"id": "91"
"Full_name": "Rahul",
}]
Second Response:
[{
"Uniq_id": "36",
"id": "91"
},
{
"Uniq_id": "37",
"id": "642"
},
{
"Uniq_id": "38",
"id": "642"
},
{
"Uniq_id": "39",
"id": "91"
}]
I have shown name using this code inside Adapter:
public class PhotographyAdapter extends RecyclerView.Adapter<PhotographyAdapter.MyViewHolder> {
List<PhotographyModel> photographyList;
public PhotographyAdapter(List<PhotographyModel> photographyList, Context context) {
this.photographyList = photographyList;
this.context = context;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_feed_post, parent, false);
return new MyViewHolder(view);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.txtUserName.setText(photographyList.get(position).getFullName())
}
@Override
public int getItemCount() {
return photographyList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView txtUserName,txtCountNo;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
txtUserName = itemView.findViewById(R.id.txtUserName);
txtCountNo = itemView.findViewById(R.id.txtCountNo);
}
}}
Photography Model:
public class PhotographyModel{
@SerializedName("Full_name")
@Expose
private String fullName;
@SerializedName("id")
@Expose
private String Id;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getId() {
return Id;
}
public void setId(String Id) {
this.Id =Id;
}}
Like Model:
public class LikeModel {
@SerializedName("Uniq_id")
@Expose
private String uniqId;
@SerializedName("id")
@Expose
private String Id;
public String getUniqId() {
return uniqId;
}
public void setUniqId(String uniqId) {
this.uniqId = uniqId;
}
public String getId() {
return Id;
}
public void setId(String Id) {
this.Id = Id;
}}
Calling First API:
public void getFirstApiResponse() {
progressBar.setVisibility(View.VISIBLE);
Call<List<PhotographyModel>> ourSupplierResponseCall = RestClient.getClient().getPhotographyPosts();
ourSupplierResponseCall.enqueue(new Callback<List<PhotographyModel>>() {
@Override
public void onResponse(Call<List<PhotographyModel>> call, Response<List<PhotographyModel>> response) {
if (response.isSuccessful()) {
progressBar.setVisibility(View.GONE);
Log.d(TAG, "onResponse: " + response.toString());
List<Photography> photographyList1;
photographyAdapter = new PhotographyAdapter(photographyList1,getContext());
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
rvPhotographyFragment.setLayoutManager(layoutManager);
rvPhotographyFragment.setAdapter(photographyAdapter);
}
}
@Override
public void onFailure(Call<List<PhotographyModel>> call, Throwable t) {
progressBar.setVisibility(View.GONE);
Toast.makeText(getActivity(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
}
});
}
Calling Second API:
public void getSecondApiResponse() {
Call<List<Like>> responseCall = RestClient.getClient().getLikes();
responseCall.enqueue(new Callback<List<Like>>() {
@Override
public void onResponse(Call<List<Like>> call, Response<List<Like>> responseLike) {
responseLike.body();
Log.d(TAG, "onResponse: " + responseLike.body().toString());
}
@Override
public void onFailure(Call<List<Like>> call, Throwable t) {
}
});
}
Any help would be appreciated. Thanks.