コード例 #1
0
  public void reloadFromArguments(Bundle arguments) {
    // Teardown from previous arguments
    if (mListPopupWindow != null) {
      mListPopupWindow.setAdapter(null);
    }
    if (mCursor != null) {
      getActivity().stopManagingCursor(mCursor);
      mCursor = null;
    }
    mHandler.cancelOperation(TracksAdapter.TracksQuery._TOKEN);

    // Load new arguments
    final Intent intent = BaseActivity.fragmentArgumentsToIntent(arguments);
    final Uri tracksUri = intent.getData();
    if (tracksUri == null) {
      return;
    }

    mNextType = intent.getStringExtra(EXTRA_NEXT_TYPE);

    // Filter our tracks query to only include those with valid results
    String[] projection = TracksAdapter.TracksQuery.PROJECTION;
    String selection = null;
    if (TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType)) {
      // Only show tracks with at least one session
      projection = TracksAdapter.TracksQuery.PROJECTION_WITH_SESSIONS_COUNT;
      selection = ScheduleContract.Tracks.SESSIONS_COUNT + ">0";

    } else if (TracksFragment.NEXT_TYPE_VENDORS.equals(mNextType)) {
      // Only show tracks with at least one vendor
      projection = TracksAdapter.TracksQuery.PROJECTION_WITH_VENDORS_COUNT;
      selection = ScheduleContract.Tracks.VENDORS_COUNT + ">0";
    }

    // Start background query to load tracks
    mHandler.startQuery(
        TracksAdapter.TracksQuery._TOKEN,
        null,
        tracksUri,
        projection,
        selection,
        null,
        ScheduleContract.Tracks.DEFAULT_SORT);
  }