@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setUpToolbar();

    // default display order
    setSortOrderFromPrefs();

    FragmentPopularMovies fpm =
        (FragmentPopularMovies)
            getSupportFragmentManager().findFragmentById(R.id.mainScreenFragmentPopularMovies);

    // show TwoPane layout if there is popular movies fragment present
    if (fpm != null) {
      mTwoPane = true;

      if (savedInstanceState != null) {
        activeFragment = savedInstanceState.getInt(SAVED_INSTANCE_ACTIVE_FRAGMENT);
        selectedMovie = savedInstanceState.getParcelable(SAVED_INSTANCE_MOVIE);
        if (movies == null || movies.isEmpty())
          movies = savedInstanceState.getParcelableArrayList(SAVED_INSTANCE_MOVIES);
        if (selectedMovie != null && activeFragment == UtilFragment.FRAGMENT_MOVIE_DETAIL)
          toolbarImageShow();
      } else {
        fpm.setCallback(this);
        // set callback popular movies and start download movies
        mDataSetChange = fpm;
        // open detail
        openFragment(UtilFragment.FRAGMENT_MOVIE_DETAIL);
        //                downloadMoviesSortedByPreferences();
      }
    }
    // one pane layout
    else {
      mTwoPane = false;
      openFragment(UtilFragment.FRAGMENT_POPULAR_MOVIES);
      downloadMovies();
    }
  }
 @Nullable
 private Fragment getFragment(int fragmentType) {
   Fragment frag;
   switch (fragmentType) {
     case UtilFragment.FRAGMENT_POPULAR_MOVIES:
       if (movies == null) movies = new LinkedList<>();
       frag = FragmentPopularMovies.newInstance(movies, this);
       mDataSetChange = (FragmentPopularMovies) frag;
       return frag;
     case UtilFragment.FRAGMENT_MOVIE_DETAIL:
       toolbarImageShow();
       frag =
           FragmentMovieDetail.newInstance(
               this, selectedMovie, mSelectedMovieReviews, mSelectedMovieTrailers);
       mSelectedMovieChange = (FragmentMovieDetail) frag;
       return frag;
     default:
       Log.d("test", "I cant find fragment to open");
       break;
   }
   return null;
 }