@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); // inject this activity's dependencies ((App) getActivity().getApplication()).getDaggerComponent().inject(this); mView = inflater.inflate(R.layout.fragment_detailed, container, false); ButterKnife.bind(this, mView); if (savedInstanceState != null) { mMovie = savedInstanceState.getParcelable(PARAMS_MOVIE); } if (mMovie != null) { Log.d(TAG, "movie is not null in detail fragment."); Picasso.with(getContext()).load(Utils.getImageUrl(mMovie.getPosterPath())).into(mImageView); mTitle.setText(mMovie.getTitle()); mReleaseDate.setText("Release date: " + mMovie.getReleaseDate()); mVoteAverage.setText("Average vote: " + Math.round(mMovie.getmVoteAverage()) + "/10"); mOverview.setText("Plot Synopsis: " + mMovie.getOverview()); mMarkFavorite.setVisibility(View.VISIBLE); } else { Log.d(TAG, "movie is null in detail fragment."); mTitle.setText("Nothing has been selected yet"); } return mView; }
@OnClick(R.id.mark_favorite) protected void onClickFavorite() { Snackbar.make(mView, "Item favorited", Snackbar.LENGTH_SHORT).show(); ContentValues contentValues = new ContentValues(); contentValues.put(MoviesContract.MovieEntry.COLUMN_MOVIE_ID, mMovie.getId()); contentValues.put(MoviesContract.MovieEntry.COLUMN_TITLE, mMovie.getTitle()); contentValues.put(MoviesContract.MovieEntry.COLUMN_POSTER_PATH, mMovie.getPosterPath()); contentValues.put(MoviesContract.MovieEntry.COLUMN_RELEASE_DATE, mMovie.getReleaseDate()); contentValues.put(MoviesContract.MovieEntry.COLUMN_VOTE_AVERAGE, mMovie.getmVoteAverage()); getActivity().getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, contentValues); }