last day (15 days later) » 

7:16 PM
0
A: Picasso only loading single image but the size is 20

KrunalTry Context context = holder.itemView.getContext(); in your onBindViewHolder, so that you don't pass context around. Also try adding popularMoviesAdapter.notifyDataSetChanged() in your fragment. Do you mind uploading your POJO? in your adapter public PopularMoviesAdapter(List<Movie> movies)...

 
@Override public void onBindViewHolder(MoviesViewHolder holder, int position) { Context context = holder.itemView.getContext(); List<Movies> movies = movieItems.get(position).getResults(); String imageUrl = IntentKeys.MOVIES_POSTER_ENDPOINT + movies.get(position).getPosterPath(); Picasso.with(context).load(imageUrl).into(holder.imageView); } movieItems has size of 1 and the getResults() has the size of 20. No luck, only displays single image
 
Assuming you are able to see 20 image urls in your adapter. Can you try moving popularMoviesAdapter = new PopularMoviesAdapter(getContext(), responses); recyclerView.setAdapter(popularMoviesAdapter); in onCreateView? And add a null check in your getItemCount()? Later add popularMoviesAdapter.notifyDataSetChanged() in your Action 1 . Remove the Action 0 from your chain.
 
Well, What I meant was, when I debug, the size for the movies.get(position).getPosterPath() is 20. I see 20 images in the list for the getResults posters. And when I do that, I get the json response and all the data in console, but nothing on the view. (I did what you suggested no luck)
UPDATE movieItems.size() is 0, with your suggestion. Without any change to above mentioned details movieItems.size() is 1.
 
movieItems.size() is initially 0 , as you are moving popularMoviesAdapter = new PopularMoviesAdapter(getContext(), responses); recyclerView.setAdapter(popularMoviesAdapter); in onCreateView. Now when you are setting responses.add(movies); in your Action1 make sure to investigate the response. It should contain 20 List<Movies> results. You POJO suggest you only get 1 Movie Response and n Movies, so you need to pass List<Movies> to the adapter. That should solve your problem. Size of your MovieResponse would be 1 per call. Also be sure to popularMoviesAdapter.notifyDataSetChanged()
Check the updated answer
Check the updated answer
please let me know if you have any q
 
7:26 PM
@Override
public void onBindViewHolder(MoviesViewHolder holder, int position) {

Context context = holder.itemView.getContext();
List<Movies> movies = movieItems.get(position).getResults();
String imageUrl = IntentKeys.MOVIES_POSTER_ENDPOINT + movies.get(position).getPosterPath();
Picasso.with(context).load(imageUrl).into(holder.imageView);
// Glide.with(context).load(imageUrl).into(holder.imageView);
}
@Kru
@Krunal shouldn't this get this list of the Movies.
MoviesResponse is 1, but the List<Movies> movies = movieItems.get(position).getResults
To me, the adapter onBindViewHolder, the movieItems.get(position).getPosterPath() should get the list of the Movies, that is 20.
and while investigating the responses.add(movies), in the subscription response, I get this Object has been collected Cannot evaluate MoviesResponse.toString()
popularMoviesAdapter = new PopularMoviesAdapter(getContext(), responseList);
recyclerView.setAdapter(popularMoviesAdapter);
popularMoviesAdapter.notifyDataSetChanged(); is inside the onCreateView()
the debug pic link
 
7:58 PM
@Ronan To me, the adapter onBindViewHolder, the movieItems.get(position).getPosterPath() should get the list of the Movies, that is 20., thats not correct
it should get List<Movie> as that's what your movies_grid_item_image needs, url per movie
responses.add(movies.getResult) should be the case recyclerView.setAdapter(popularMoviesAdapter); should be following this line
popularMoviesAdapter = new PopularMoviesAdapter(getContext(), responseList);
recyclerView.setAdapter(popularMoviesAdapter); this can go to onCreateView
Change your adapter signature to List<Movie>
movieItems in your adapter is List<Movie> and not List<MovieResponse>
*movieItems.get(position).getResults(); * this is incorrect in your binder
So the flow is that make your rest call - Get List<Movie> from MovieResponse , pass this to your adapter and do notify data set change in your getMoviesSubscription
After which , in your adapter you get the :List<Movie> , in your bindeview method, just do movies.get(position);
responseList = ArrayList<Movie>
responseList = ArrayList<Movie> in your fragment
 
That is in Fragment for setting up the adapter
you were saying movieItems.get(position).getResults(); is wrong. How do I handle that in onBindViewHolder()
` @Override
public void onBindViewHolder(MoviesViewHolder holder, int position) {

Context context = holder.itemView.getContext();
List<Movies> movies = movieItems.get(position).getResults();
String imageUrl = IntentKeys.MOVIES_POSTER_ENDPOINT + movies.get(position).getPosterPath();
Picasso.with(context).load(imageUrl).into(holder.imageView);
// Glide.with(context).load(imageUrl).into(holder.imageView);
}`
you just said that is incorrect. where movies is the List<MoviesResponse>
```@Override
public void onBindViewHolder(MoviesViewHolder holder, int position) {

Context context = holder.itemView.getContext();
List<Movies> movies = movieItems.get(position).getResults();
String imageUrl = IntentKeys.MOVIES_POSTER_ENDPOINT + movies.get(position).getPosterPath();
Picasso.with(context).load(imageUrl).into(holder.imageView);
}```
 
@Ronan check i have updated answer with more code
see Forget MoviewResponse as soon as you rest call gets the results. Then all you care about is List<Movie> , as individual movie object gets you url per adapter item
in your fragment - initialize a arraylist<Movie> , in your Action 1 , add <MovieResponse.getResults>, do notify data chage
in your adapter , pass List<Movie>
in your binder just fetch individual Movie by position
No need to do get Result, as you have a list<Movie> now that contains individual poster per movie
check the code
in the post , i have updated the answer
i am sure it will work after making the change
@Ronan Please upvote and make answer as acceptable once you have it working.
Try to send me your current fragment and Adapter , so that i can review it
 
8:41 PM
`@GET("movie/popular")`
`Observable<MoviesResponse> getPopularMovies(@Query("api_key") String apiKey);`
this is my service interface and I am passing the MoviesResponse
not the fragment will complain and I cannot change List<Movies> in onBindViewHolder()
now
new Action1<MoviesResponse>() {
@Override
public void call(MoviesResponse movies) {
responses.add(movies.getResults());
popularMoviesAdapter.notifyDataSetChanged();
}
}
this throws an error on the movies.getResult where movies is the list<movies>
and by those changes the getItemCount() in the adapter, i will be getting is 0
responseList.add(moviesResponse.getResults()); will not work then. I get incompatible error
Fragment here:
public class PopularMoviesFragment extends Fragment {

private static final int COLUMN_COUNT = 2;
private List<MoviesResponse> responseList;
private List<Movies> movieItems = new ArrayList<Movies>();
private RecyclerView recyclerView;
private PopularMoviesAdapter popularMoviesAdapter;
private Subscription subscription;

public PopularMoviesFragment() {
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
and the adapter:
package com.mchapagai.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.mchapagai.R;
import com.mchapagai.model.Movies;
import com.mchapagai.model.MoviesResponse;
import com.mchapagai.util.IntentKeys;
import com.squareup.picasso.Picasso;

import java.util.List;

public class PopularMoviesAdapter extends RecyclerView.Adapter<PopularMoviesAdapter.MoviesViewHolder> {
pojo:
package com.mchapagai.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class MoviesResponse implements Serializable {

@SerializedName("page")
@Expose
private Integer page;
@SerializedName("results")
@Expose
private List<Movies> results = new ArrayList<Movies>();
@SerializedName("total_results")
@Expose
private Integer totalResults;
@SerializedName("total_pages")
public class Movies implements Serializable {

@SerializedName("poster_path")
@Expose
private String posterPath;
@SerializedName("adult")
@Expose
private Boolean adult;
@SerializedName("overview")
@Expose
private String overview;
@SerializedName("release_date")
@Expose
private String releaseDate;
@SerializedName("genre_ids")
@Expose
private List<Integer> genreIds = new ArrayList<Integer>();
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("original_title")
@Expose
private String originalTitle;
 

last day (15 days later) »