changed callback
This commit is contained in:
@@ -7,6 +7,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||
import net.headlezz.udacityproject1.tmdbapi.MovieList;
|
||||
import net.headlezz.udacityproject1.tmdbapi.TMDBApi;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,9 +17,9 @@ public class MovieListAdapter extends RecyclerView.Adapter<MovieListAdapter.Movi
|
||||
MovieNavigation mMovieNavigation;
|
||||
List<Movie> mMovies;
|
||||
|
||||
public MovieListAdapter(MovieNavigation mn, List<Movie> movies) {
|
||||
public MovieListAdapter(MovieNavigation mn, MovieList movieList) {
|
||||
mMovieNavigation = mn;
|
||||
mMovies = movies;
|
||||
mMovies = movieList.getList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,19 +16,18 @@ import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||
import net.headlezz.udacityproject1.tmdbapi.MovieList;
|
||||
import net.headlezz.udacityproject1.tmdbapi.MovieListCallback;
|
||||
import net.headlezz.udacityproject1.tmdbapi.TMDBApi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit.Call;
|
||||
import retrofit.Callback;
|
||||
import retrofit.Response;
|
||||
import retrofit.Retrofit;
|
||||
|
||||
/**
|
||||
* A fragment showing a list of movies
|
||||
*/
|
||||
public class MovieListFragment extends Fragment {
|
||||
public class MovieListFragment extends Fragment implements Callback<MovieList> {
|
||||
|
||||
public static final String TAG = MovieListFragment.class.getSimpleName();
|
||||
|
||||
@@ -121,29 +120,29 @@ public class MovieListFragment extends Fragment {
|
||||
* mSortingOrder will be used to determine the sorting
|
||||
*/
|
||||
private void loadMovieList() {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
stopLoadingMovies(); // stop any running query before starting a new one
|
||||
MovieListCallback cb = new MovieListCallback() {
|
||||
@Override
|
||||
protected void onResponse(MovieList movies) {
|
||||
setListToGrid(movies.getList());
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
Log.d(TAG, t.getClass().getSimpleName() + " " + t.getMessage());
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
if(!t.getMessage().equals("Canceled") && getActivity() != null)
|
||||
Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
};
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mMovieListCall = TMDBApi.discoverMovies(mSortingOrder, getString(R.string.api_key));
|
||||
mMovieListCall.enqueue(cb);
|
||||
mMovieListCall.enqueue(this);
|
||||
}
|
||||
|
||||
private void setListToGrid(List<Movie> movies) {
|
||||
mMovieGridView.setAdapter(new MovieListAdapter((MovieNavigation) getActivity(), movies));
|
||||
@Override
|
||||
public void onResponse(Response<MovieList> response, Retrofit retrofit) {
|
||||
if(response.isSuccess())
|
||||
setListToGrid(response.body());
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
Log.d(TAG, t.getClass().getSimpleName() + " " + t.getMessage());
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
if(!t.getMessage().equals("Canceled") && getActivity() != null)
|
||||
Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void setListToGrid(MovieList movieList) {
|
||||
mMovieGridView.setAdapter(new MovieListAdapter((MovieNavigation) getActivity(), movieList));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,8 @@ public abstract class MovieListCallback implements Callback<MovieList> {
|
||||
public void onResponse(Response<MovieList> response, Retrofit retrofit) {
|
||||
if(response.isSuccess())
|
||||
onResponse(response.body());
|
||||
else
|
||||
onFailure(new MovieDownloadException("Something went wrong" + response.code())); // TODO make this better
|
||||
else // we dont want want res
|
||||
onFailure(new MovieDownloadException("Something went wrong" + response.code()));
|
||||
}
|
||||
|
||||
protected abstract void onResponse(MovieList movies);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textStyle="bold"
|
||||
tools:text="Chappie" />
|
||||
|
||||
<ImageView
|
||||
@@ -53,7 +54,7 @@
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/movie_details_ivPoster"
|
||||
android:layout_marginTop="16dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
tools:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
Reference in New Issue
Block a user