@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_favourites, container, false);

    dbHandler = new MoviesDBHandler(getActivity());
    tvShowsDBHandler = new TVShowsDBHandler(getActivity());

    mFavoritesGridView = (GridView) rootView.findViewById(R.id.favourites_gridview);

    movieList = dbHandler.getAllContacts();

    for (Movie movie : movieList) {

      if (movie.getMovieBackdrop() != null) {
        Log.d("Movie backdrop", movie.getMovieBackdrop().toString());
      } else {
        Log.d("Movie backdrop", "null");
      }

      if (movie.getMoviePoster() != null) {
        Log.d("Movie poster", movie.getMoviePoster().toString());
      } else {
        Log.d("Movie backdrop", "null");
      }
    }

    mAdapter = new GridAdapter(getActivity(), movieList, getScreenDimen());

    mFavoritesGridView.setAdapter(mAdapter);
    mFavoritesGridView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(
                    getActivity(),
                    movieList.get(position).getOriginal_title() + "",
                    Toast.LENGTH_SHORT)
                .show();
            Intent intent =
                new Intent(getActivity().getApplicationContext(), DetailsActivity.class);
            intent.putExtra("MovieDetails", movieList.get(position));
            intent.putExtra("FromDatabase", true);
            startActivityForResult(intent, 1);
          }
        });

    return rootView;
  }
  @Override
  public void onResume() {
    super.onResume();

    movieList = dbHandler.getAllContacts();

    for (Movie movie : movieList) {

      if (movie.getMovieBackdrop() != null) {
        Log.d("Movie backdrop", movie.getMovieBackdrop().toString());
      } else {
        Log.d("Movie backdrop", "null");
      }

      if (movie.getMoviePoster() != null) {
        Log.d("Movie poster", movie.getMoviePoster().toString());
      } else {
        Log.d("Movie backdrop", "null");
      }
    }

    mAdapter = new GridAdapter(getActivity(), movieList, getScreenDimen());

    mFavoritesGridView.setAdapter(mAdapter);
    mFavoritesGridView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(
                    getActivity(),
                    movieList.get(position).getOriginal_title() + "",
                    Toast.LENGTH_SHORT)
                .show();
            Intent intent =
                new Intent(getActivity().getApplicationContext(), DetailsActivity.class);
            intent.putExtra("MovieDetails", movieList.get(position));
            intent.putExtra("FromDatabase", true);
            startActivityForResult(intent, 1);
          }
        });
  }