stashing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.headlezz.udacityproject1;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -21,6 +22,7 @@ import android.widget.Toast;
|
||||
|
||||
import net.headlezz.udacityproject1.favorites.FavoriteProviderHelper;
|
||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
||||
import net.headlezz.udacityproject1.tmdbapi.TMDBApi;
|
||||
import net.headlezz.udacityproject1.tmdbapi.Video;
|
||||
import net.headlezz.udacityproject1.tmdbapi.VideoList;
|
||||
@@ -29,6 +31,7 @@ import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import retrofit.Call;
|
||||
import retrofit.Callback;
|
||||
import retrofit.Response;
|
||||
@@ -133,6 +136,32 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
|
||||
|
||||
// TODO high res image for video link
|
||||
|
||||
@OnClick(R.id.movie_details_btReviews)
|
||||
public void onReviewButtonClick(View view) {
|
||||
// TODO progressdialogs are bad because of rotation
|
||||
final ProgressDialog dialog = new ProgressDialog(getContext());
|
||||
dialog.setIndeterminate(true);
|
||||
dialog.show();
|
||||
TMDBApi.getReviewsForMovie(mMovie, getString(R.string.api_key)).enqueue(new Callback<ReviewList>() {
|
||||
@Override
|
||||
public void onResponse(Response<ReviewList> response, Retrofit retrofit) {
|
||||
dialog.dismiss();
|
||||
if(response.isSuccess()) {
|
||||
ReviewDialogFragment frag = ReviewDialogFragment.newInstance(response.body());
|
||||
frag.show(getChildFragmentManager(), ReviewDialogFragment.TAG);
|
||||
} else {
|
||||
Log.e(TAG, "Query not successful.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
dialog.dismiss();
|
||||
Log.e(TAG, "something went wrong: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* shows a list of links to youtube videos for the selected movie
|
||||
* if the videolist has no videos, the user sees a message that there are no.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.headlezz.udacityproject1;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ReviewDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String TAG = ReviewDialogFragment.class.getSimpleName();
|
||||
public static final String BUNDLE_ARG_REVIEWLIST = "reviewlist";
|
||||
|
||||
ReviewList mReviewList;
|
||||
|
||||
@Bind(R.id.review_tvReview)
|
||||
TextView tvReview;
|
||||
|
||||
public static ReviewDialogFragment newInstance(ReviewList reviews) {
|
||||
ReviewDialogFragment frag = new ReviewDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(BUNDLE_ARG_REVIEWLIST, reviews);
|
||||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getArguments() != null && getArguments().containsKey(BUNDLE_ARG_REVIEWLIST))
|
||||
mReviewList = getArguments().getParcelable(BUNDLE_ARG_REVIEWLIST);
|
||||
else
|
||||
throw new RuntimeException("No arguments found");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View dialogView = inflater.inflate(R.layout.movie_details_review_dialog, container, false);
|
||||
ButterKnife.bind(this, dialogView);
|
||||
tvReview.setText(mReviewList.getReviews().get(0).getContent());
|
||||
return dialogView;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.headlezz.udacityproject1.tmdbapi;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Review implements Parcelable {
|
||||
|
||||
String author;
|
||||
String content;
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeString(author);
|
||||
parcel.writeString(content);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Review> CREATOR = new Parcelable.Creator<Review>() {
|
||||
public Review createFromParcel(Parcel src) {
|
||||
return new Review(src);
|
||||
}
|
||||
|
||||
public Review[] newArray(int size) {
|
||||
return new Review[size];
|
||||
}
|
||||
};
|
||||
|
||||
Review(Parcel in) {
|
||||
this.author = in.readString();
|
||||
this.content = in.readString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.headlezz.udacityproject1.tmdbapi;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReviewList implements Parcelable {
|
||||
|
||||
List<Review> reviews;
|
||||
|
||||
public ReviewList(List<Review> reviews) {
|
||||
this.reviews = reviews;
|
||||
}
|
||||
|
||||
public List<Review> getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeList(reviews);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ReviewList> CREATOR = new Parcelable.Creator<ReviewList>() {
|
||||
public ReviewList createFromParcel(Parcel src) {
|
||||
return new ReviewList(src);
|
||||
}
|
||||
|
||||
public ReviewList[] newArray(int size) {
|
||||
return new ReviewList[size];
|
||||
}
|
||||
};
|
||||
|
||||
private ReviewList(Parcel src) {
|
||||
this.reviews = src.readArrayList(Review.class.getClassLoader());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.headlezz.udacityproject1.tmdbapi;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReviewListDeserializer implements JsonDeserializer<ReviewList> {
|
||||
@Override
|
||||
public ReviewList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
Gson gson = new Gson();
|
||||
List<Review> reviews = new ArrayList<>();
|
||||
for(JsonElement elem : json.getAsJsonObject().getAsJsonArray("results")) {
|
||||
reviews.add(gson.fromJson(elem, Review.class));
|
||||
}
|
||||
return new ReviewList(reviews);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ public class TMDBApi {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(MovieList.class, new MovieListDeserializer())
|
||||
.registerTypeAdapter(VideoList.class, new VideoListDeserializer())
|
||||
.registerTypeAdapter(ReviewList.class, new ReviewListDeserializer())
|
||||
.create();
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
@@ -69,6 +70,10 @@ public class TMDBApi {
|
||||
return apiService.getVideosForMovie(movie.getId(), apiKey);
|
||||
}
|
||||
|
||||
public static Call<ReviewList> getReviewsForMovie(Movie movie, String apiKey) {
|
||||
return apiService.getReviewsForMovie(movie.getId(), apiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api interface for retrofit
|
||||
*/
|
||||
@@ -80,6 +85,10 @@ public class TMDBApi {
|
||||
@Headers("Accept: application/json")
|
||||
@GET("movie/{id}/videos")
|
||||
Call<VideoList> getVideosForMovie(@Path("id") long id, @Query("api_key") String apiKey);
|
||||
|
||||
@Headers("Accept: application/json")
|
||||
@GET("movie/{id}/reviews")
|
||||
Call<ReviewList> getReviewsForMovie(@Path("id") long id, @Query("api_key") String apiKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user