I've very basic retrofit implementation:
public interface MoviesApi {
@GET(Constants.POPULAR_MOVIES_URL)
Call<AllMovies> getAllMovies(
@Query("api_key") String apiKey
);
}
ViewModel:
Call<AllMovies> call = RetrofitService.getAllMovies().getAllMovies(Constants.API_KEY);
call.enqueue(new Callback<AllMovies>() {
@Override
public void onResponse(Call<AllMovies> call, Response<AllMovies> response) {
staus.setValue(Status.SUCCESS);
Log.i(TAG, "onResponse: " + response.body());
_allMovies.setValue(response.body());
}
@Override
public void onFailure(Call<AllMovies> call, Throwable t) {
Log.i(TAG, "onResponse: " + t.getMessage());
}
});
And I'm using it inside my recyclerView
:
String currentUrl = "https://images-na.ssl-images-amazon.com/images/I/518jo3Xlf8L._AC_.jpg";
holder.title_text.setText(movieItem.getTitle());
Glide.with(holder.itemView.getContext())
.load(currentUrl)
.apply(new RequestOptions().override(400, 600))
.into(holder.imageView);
}
Nothing speical here.
My response contain this field:
"poster_path": "/e1mjopzAS2KNsvpbpahQ1a6SkSn.jpg"
that I should fetch from here:
https://image.tmdb.org/t/p
My question is - where should I fetch this image?
Should I create new image
field in my movie model, and immediately after I call getAllMovies
I should call getPoster
for example and then insert the data to the image
field I created?
Or just fetch directly from glide is enough?
It's worth to mention that I need to pass this image to other screen, when I click on recyclerView item for example
Should I create 2 retrofit instances for 2 base url(image and movies has different base url)?
Reference for tmdb image docs: https://developers.themoviedb.org/3/getting-started/images