@Override public void onClick(View v) { if (((ToggleButton) v).isChecked()) { // handle toggle on curd.addToFavoriateList(); } else { // handle toggle off curd.removeFromFavoriateList(); } }
@Override public void onResume() { super.onResume(); movie = getArguments().getParcelable("movie"); Log.i("movie", movie == null ? "ok" : movie.getTitle()); overviewText.setText(movie.getOverview()); dateText.setText(movie.getReleaseDate()); voteText.setText(movie.getVoteAverage()); durationText.setText(""); posterText.setText(movie.getTitle()); if (curd.isInFavList(movie)) { toggleBtn.setChecked(true); movie.setIsFave(1); } else { movie.setIsFave(0); toggleBtn.setChecked(false); } Log.i("isfav", "" + isFav); if (movie.getIsFave() == 0) { poster_path = MovieAdapter.POSTER_URL + movie.getPosterPath(); Picasso.with(getActivity()).load(poster_path).fit().into(posterBar); toggleBtn.setChecked(false); } else { File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) .getAbsolutePath() + "/popularMoviesImage"); Picasso.with(getActivity()) .load(new File(file.getAbsolutePath() + File.separator + movie.getPosterPath())) .into(posterBar); toggleBtn.setChecked(true); } Log.i("mm", movie.getMovieId() + "/videos"); Uri trailersURI = Uri.parse(MOVIE_URL) .buildUpon() .appendPath(movie.getMovieId()) .appendPath("videos") .appendQueryParameter( MainActivityFragment.API_KEY_NAME, MainActivityFragment.API_KEY_VALUE) .build(); String moviesTrailerURL = trailersURI.toString(); Uri reviewssURI = Uri.parse(MOVIE_URL) .buildUpon() .appendPath(movie.getMovieId()) .appendPath("reviews") .appendQueryParameter( MainActivityFragment.API_KEY_NAME, MainActivityFragment.API_KEY_VALUE) .build(); moviesReviewsURL = reviewssURI.toString(); Log.i("trailers_url", moviesTrailerURL); Log.i("reviews_url", moviesReviewsURL); // if (NetworkUtil.isNetworkAvailable(getActivity())) { new FetchMoviesTrailers().execute(moviesTrailerURL); } }