コード例 #1
0
  public static MoviesFragment newInstance(TmdbCategory category) {
    MoviesFragment f = new MoviesFragment();

    Bundle args = new Bundle();
    args.putInt(InitBundle.TMDB_CATEGORY, category.index);
    f.setArguments(args);

    return f;
  }
コード例 #2
0
  @TargetApi(9)
  @Override
  public boolean onNavigationItemSelected(int itemPosition, long itemId) {
    Fragment newFragment = null;
    switch (itemPosition) {
      case 0:
      default:
        // popular (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.POPULAR);
        break;
      case 1:
        // top rated (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.TOPRATED);
        break;
      case 2:
        // now playing (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.NOWPLAYING);
        break;
      case 3:
        // upcoming (TMDb)
        newFragment = MoviesFragment.newInstance(TmdbCategory.UPCOMING);
        break;
      case 4:
        // watchlist (trakt)
        newFragment = LocalMoviesFragment.newInstance(TraktCategory.WATCHLIST);
        break;
    }
    if (newFragment != null) {
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.replace(R.id.fragment_list, newFragment);
      ft.commit();

      // save the selected filter back to settings
      Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
      editor.putInt(AppPreferences.KEY_NAVSELECTION, itemPosition);
      if (AndroidUtils.isGingerbreadOrHigher()) {
        editor.apply();
      } else {
        editor.commit();
      }

      return true;
    } else {
      return false;
    }
  }