@Override
 public void onLoaderReset(Loader<Cursor> loader) {
   switch (loader.getId()) {
     case MOVIE_TRAILER_LOADER:
       mTrailersListAdapter.swapCursor(null);
       break;
     case MOVIE_REVIEW_LOADER:
       mReviewsListAdapter.swapCursor(null);
       break;
   }
 }
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
   switch (loader.getId()) {
     case MOVIE_TRAILER_LOADER:
       mTrailersListAdapter.swapCursor(cursor);
       Utility.setDynamicHeight(mMovieTrailersListView);
       break;
     case MOVIE_REVIEW_LOADER:
       mReviewsListAdapter.swapCursor(cursor);
       Utility.setDynamicHeight(mMovieReviewsListView);
       break;
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_movie_details, container, false);
    Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar_detail);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

    mContext = container.getContext();
    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);

    Bundle arguments = getArguments();
    String data[] = null;
    if (arguments != null) {
      data = arguments.getStringArray(Intent.EXTRA_TEXT);
    }

    mTrailersListAdapter = new CustomTrailersListAdapter(getActivity(), null, 0);
    mReviewsListAdapter = new CustomReviewsListAdapter(getActivity(), null, 0);

    mMovieNameView = (TextView) rootView.findViewById(R.id.movie_name);
    mBackgroundImageView = (ImageView) rootView.findViewById(R.id.background_imageView);
    mMovieImageView = (ImageView) rootView.findViewById(R.id.movie_image);
    mMovieYearView = (TextView) rootView.findViewById(R.id.detail_year);
    mMovieRatingsView = (RatingBar) rootView.findViewById(R.id.detail_ratings);
    mMovieTrailersListView = (ListView) rootView.findViewById(R.id.listview_trailers);
    mMovieReviewsListView = (ListView) rootView.findViewById(R.id.listview_reviews);
    mFavoriteButton = (Button) rootView.findViewById(R.id.button_favorite);
    mMovieOverviewView = (TextView) rootView.findViewById(R.id.detail_overview);

    // empty views for ListViews
    mTrailersEmptyView = (TextView) rootView.findViewById(R.id.listview_trailers_empty);
    mReviewsEmptyView = (TextView) rootView.findViewById(R.id.listview_reviews_empty);

    fixRatingsViewColorScheme();

    if (data != null) {

      String backdropPath = data[0];
      String posterPath = data[1];
      String dateValue = data[2];
      String ratings = data[4];
      String overview = data[5];
      String movieName = data[6];
      String movieIdStr = data[7];

      if (!Utility.isStringEmpty(backdropPath)) {
        Picasso.with(mContext)
            .load(Utility.getImageURL(backdropPath))
            .error(R.drawable.no_image_available)
            .into(mBackgroundImageView);
      }

      Picasso.with(mContext)
          .load(Utility.getImageURL(posterPath))
          .error(R.drawable.no_image_available)
          .into(mMovieImageView);

      if (Utility.isStringEmpty(dateValue)) {
        mMovieYearView.setText(getString(R.string.label_text_view_no_date));
      } else {
        mMovieYearView.setText(dateValue);
      }

      if (Utility.isStringEmpty(overview)) {
        mMovieOverviewView.setText(getString(R.string.label_text_view_no_overview));
      } else {
        mMovieOverviewView.setText(overview);
      }

      mMovieRatingsView.setRating(Float.valueOf(ratings) / 2f);
      mMovieNameView.setText(movieName);
      movieId = Integer.valueOf(movieIdStr);

      CollapsingToolbarLayout collapsingToolbarLayout =
          (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
      collapsingToolbarLayout.setTitle(movieName);
      collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white));
    } // end of data if

    mMovieTrailersListView.setAdapter(mTrailersListAdapter);
    mMovieReviewsListView.setAdapter(mReviewsListAdapter);

    mTrailersListAdapter.registerDataSetObserver(
        new DataSetObserver() {
          @Override
          public void onChanged() {
            super.onChanged();
            if (mTrailersListAdapter.getCount() <= 0) {
              mTrailersEmptyView.setText(R.string.label_text_view_empty_trailers);
              mMovieTrailersListView.setEmptyView(mTrailersEmptyView);
            }
          }
        });

    mReviewsListAdapter.registerDataSetObserver(
        new DataSetObserver() {
          @Override
          public void onChanged() {
            super.onChanged();
            if (mReviewsListAdapter.getCount() <= 0) {
              mReviewsEmptyView.setText(R.string.label_text_view_empty_reviews);
              mMovieReviewsListView.setEmptyView(mReviewsEmptyView);
            }
          }
        });

    mFavoriteButton.setOnClickListener(this);

    if (isMovieFavorite()) {
      mFavoriteButton.setBackgroundColor(getResources().getColor(R.color.favorite_selected));
      mFavoriteButton.setTextColor(getResources().getColor(R.color.text_favorite_selected));
    }

    return rootView;
  }