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.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import net.headlezz.udacityproject1.moviedetails.MovieDetailsFragment;
|
||||||
import net.headlezz.udacityproject1.movielist.MovieListFragment;
|
import net.headlezz.udacityproject1.movielist.MovieListFragment;
|
||||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
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.app.ProgressDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
@@ -20,6 +20,7 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.headlezz.udacityproject1.R;
|
||||||
import net.headlezz.udacityproject1.favorites.FavoriteProviderHelper;
|
import net.headlezz.udacityproject1.favorites.FavoriteProviderHelper;
|
||||||
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
import net.headlezz.udacityproject1.tmdbapi.Movie;
|
||||||
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
import net.headlezz.udacityproject1.tmdbapi.ReviewList;
|
||||||
@@ -138,28 +139,32 @@ public class MovieDetailsFragment extends Fragment implements Callback<VideoList
|
|||||||
|
|
||||||
@OnClick(R.id.movie_details_btReviews)
|
@OnClick(R.id.movie_details_btReviews)
|
||||||
public void onReviewButtonClick(View view) {
|
public void onReviewButtonClick(View view) {
|
||||||
// TODO progressdialogs are bad because of rotation
|
|
||||||
final ProgressDialog dialog = new ProgressDialog(getContext());
|
final ProgressDialog dialog = new ProgressDialog(getContext());
|
||||||
dialog.setIndeterminate(true);
|
dialog.setIndeterminate(true);
|
||||||
|
dialog.setMessage(getString(R.string.movie_download_review_progress));
|
||||||
dialog.show();
|
dialog.show();
|
||||||
TMDBApi.getReviewsForMovie(mMovie, getString(R.string.api_key)).enqueue(new Callback<ReviewList>() {
|
TMDBApi.getReviewsForMovie(mMovie, getString(R.string.api_key)).enqueue(new Callback<ReviewList>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Response<ReviewList> response, Retrofit retrofit) {
|
public void onResponse(Response<ReviewList> response, Retrofit retrofit) {
|
||||||
dialog.dismiss();
|
if(response.body().getReviews().size() == 0)
|
||||||
if(response.isSuccess()) {
|
Toast.makeText(getContext(), R.string.movie_download_review_not_found, Toast.LENGTH_SHORT).show();
|
||||||
|
else {
|
||||||
ReviewDialogFragment frag = ReviewDialogFragment.newInstance(response.body());
|
ReviewDialogFragment frag = ReviewDialogFragment.newInstance(response.body());
|
||||||
frag.show(getChildFragmentManager(), ReviewDialogFragment.TAG);
|
frag.show(getChildFragmentManager(), ReviewDialogFragment.TAG);
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Query not successful.");
|
|
||||||
}
|
}
|
||||||
|
if(dialog.isShowing())
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
dialog.dismiss();
|
if(dialog.isShowing())
|
||||||
Log.e(TAG, "something went wrong: " + t.getMessage());
|
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 {
|
try {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} 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() {
|
private void shareTrailer() {
|
||||||
if(mVideoList == null || mVideoList.getVideos().size() == 0)
|
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 {
|
else {
|
||||||
Intent i = new Intent(Intent.ACTION_SEND);
|
Intent i = new Intent(Intent.ACTION_SEND);
|
||||||
i.setType("text/plain");
|
i.setType("text/plain");
|
||||||
i.putExtra(Intent.EXTRA_TEXT, "https://youtu.be/" + mVideoList.getVideos().get(0).getKey());
|
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"));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +1,74 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:id="@+id/review_tvReviewUser"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
tools:text="Username" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="250dp">
|
android:layout_height="200dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/review_tvReview"
|
android:id="@+id/review_tvReview"
|
||||||
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."
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
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." />
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:tint="@android:color/white"
|
android:id="@+id/review_btPrevious"
|
||||||
android:background="@android:color/transparent"
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
android:layout_gravity="left"
|
android:layout_gravity="left"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:padding="12dp"
|
||||||
android:src="@drawable/ic_action_arrow_left"
|
android:src="@drawable/ic_action_arrow_left"
|
||||||
|
android:tint="@android:color/white" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/review_tvPosition"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
tools:text="5/10" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:tint="@color/colorAccent"
|
android:id="@+id/review_btNext"
|
||||||
android:background="@android:color/transparent"
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:padding="12dp"
|
||||||
android:src="@drawable/ic_action_arrow_right"
|
android:src="@drawable/ic_action_arrow_right"
|
||||||
android:layout_width="wrap_content"
|
android:tint="@color/colorAccent" />
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -10,4 +10,10 @@
|
|||||||
<string name="list_action_favorites">Favorites</string>
|
<string name="list_action_favorites">Favorites</string>
|
||||||
<string name="details_no_movies_found">No videos found.</string>
|
<string name="details_no_movies_found">No videos found.</string>
|
||||||
<string name="details_frag_placeholder_text">Please select a movie</string>
|
<string name="details_frag_placeholder_text">Please select a movie</string>
|
||||||
|
<string name="movie_download_review_progress">Downloading...</string>
|
||||||
|
<string name="movie_download_review_not_found">No reviews found</string>
|
||||||
|
<string name="movie_download_review_fail">Review download failed.</string>
|
||||||
|
<string name="movie_share_fail">Youtube app not found.</string>
|
||||||
|
<string name="movie_share_no_trailer_found">Nothing to share. :(</string>
|
||||||
|
<string name="movie_share_title">Check out this movie!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user