reviews implemented
This commit is contained in:
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
|
||||
import net.headlezz.udacityproject1.moviedetails.MovieDetailsFragment;
|
||||
import net.headlezz.udacityproject1.movielist.MovieListFragment;
|
||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.headlezz.udacityproject1;
|
||||
package net.headlezz.udacityproject1.moviedetails;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@@ -20,6 +20,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.headlezz.udacityproject1.R;
|
||||
import net.headlezz.udacityproject1.favorites.FavoriteProviderHelper;
|
||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
||||
@@ -138,28 +139,32 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
|
||||
|
||||
@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.setMessage(getString(R.string.movie_download_review_progress));
|
||||
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()) {
|
||||
if(response.body().getReviews().size() == 0)
|
||||
Toast.makeText(getContext(), R.string.movie_download_review_not_found, Toast.LENGTH_SHORT).show();
|
||||
else {
|
||||
ReviewDialogFragment frag = ReviewDialogFragment.newInstance(response.body());
|
||||
frag.show(getChildFragmentManager(), ReviewDialogFragment.TAG);
|
||||
} else {
|
||||
Log.e(TAG, "Query not successful.");
|
||||
}
|
||||
if(dialog.isShowing())
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
dialog.dismiss();
|
||||
Log.e(TAG, "something went wrong: " + t.getMessage());
|
||||
if(dialog.isShowing())
|
||||
dialog.dismiss();
|
||||
Toast.makeText(getContext(), R.string.movie_download_review_fail, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +189,7 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getActivity(), "Youtube app not found.", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getActivity(), R.string.movie_share_fail, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -235,12 +240,12 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
|
||||
*/
|
||||
private void shareTrailer() {
|
||||
if(mVideoList == null || mVideoList.getVideos().size() == 0)
|
||||
Toast.makeText(getActivity(), "Nothing to share. :(", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getActivity(), R.string.movie_share_no_trailer_found, Toast.LENGTH_SHORT).show();
|
||||
else {
|
||||
Intent i = new Intent(Intent.ACTION_SEND);
|
||||
i.setType("text/plain");
|
||||
i.putExtra(Intent.EXTRA_TEXT, "https://youtu.be/" + mVideoList.getVideos().get(0).getKey());
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "Check out this movie!");
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.movie_share_title));
|
||||
startActivity(Intent.createChooser(i, "Share"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package net.headlezz.udacityproject1.moviedetails;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
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.view.Window;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.headlezz.udacityproject1.R;
|
||||
import net.headlezz.udacityproject1.tmdbapi.Review;
|
||||
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class ReviewDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String TAG = ReviewDialogFragment.class.getSimpleName();
|
||||
public static final String BUNDLE_ARG_REVIEWS = "reviews";
|
||||
|
||||
ReviewList mReviews;
|
||||
int mCurrentPosition;
|
||||
|
||||
@Bind(R.id.review_tvReview)
|
||||
TextView tvReview;
|
||||
|
||||
@Bind(R.id.review_tvReviewUser)
|
||||
TextView tvReviewUser;
|
||||
|
||||
@Bind(R.id.review_btNext)
|
||||
ImageButton btNext;
|
||||
|
||||
@Bind(R.id.review_btPrevious)
|
||||
ImageButton btPrev;
|
||||
|
||||
@Bind(R.id.review_tvPosition)
|
||||
TextView tvPosition;
|
||||
|
||||
|
||||
public static ReviewDialogFragment newInstance(ReviewList reviews) {
|
||||
ReviewDialogFragment frag = new ReviewDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(BUNDLE_ARG_REVIEWS, reviews);
|
||||
frag.setArguments(args);
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getArguments() != null && getArguments().containsKey(BUNDLE_ARG_REVIEWS))
|
||||
mReviews = getArguments().getParcelable(BUNDLE_ARG_REVIEWS);
|
||||
else
|
||||
throw new RuntimeException("No arguments found");
|
||||
|
||||
if(savedInstanceState != null)
|
||||
mCurrentPosition = savedInstanceState.getInt("position", 0);
|
||||
else
|
||||
mCurrentPosition = 0;
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
updateReview();
|
||||
checkButtonState();
|
||||
return dialogView;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@OnClick(R.id.review_btNext)
|
||||
public void onNextClick(View view) {
|
||||
mCurrentPosition += 1;
|
||||
updateReview();
|
||||
checkButtonState();
|
||||
}
|
||||
|
||||
@OnClick(R.id.review_btPrevious)
|
||||
public void onPreviousClick(View view) {
|
||||
mCurrentPosition -= 1;
|
||||
updateReview();
|
||||
checkButtonState();
|
||||
}
|
||||
|
||||
private void updateReview() {
|
||||
Review rv = mReviews.getReviews().get(mCurrentPosition);
|
||||
tvReview.setText(rv.getContent());
|
||||
tvReviewUser.setText(rv.getAuthor());
|
||||
tvPosition.setText(String.format("%1$s/%2$s", mCurrentPosition + 1, mReviews.getReviews().size()));
|
||||
}
|
||||
|
||||
private void checkButtonState() {
|
||||
if(mCurrentPosition < 1)
|
||||
btPrev.setVisibility(View.GONE);
|
||||
else
|
||||
btPrev.setVisibility(View.VISIBLE);
|
||||
|
||||
if(mCurrentPosition >= mReviews.getReviews().size() - 1)
|
||||
btNext.setVisibility(View.GONE);
|
||||
else
|
||||
btNext.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt("position", mCurrentPosition);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user