/**
   * Builds a new {@link CheckInDialogFragment} setting all values based on the given episode TVDb
   * id. Might return null.
   */
  public static CheckInDialogFragment newInstance(Context context, int episodeTvdbId) {
    CheckInDialogFragment f = null;

    final Cursor episode =
        context
            .getContentResolver()
            .query(
                Episodes.buildEpisodeWithShowUri(episodeTvdbId),
                CheckInQuery.PROJECTION,
                null,
                null,
                null);
    if (episode != null) {
      if (episode.moveToFirst()) {
        f = new CheckInDialogFragment();
        Bundle args = new Bundle();
        args.putString(InitBundle.TITLE, episode.getString(CheckInQuery.SHOW_TITLE));
        args.putInt(InitBundle.SHOW_TVDB_ID, episode.getInt(CheckInQuery.SHOW_TVDB_ID));
        args.putInt(InitBundle.SEASON, episode.getInt(CheckInQuery.SEASON));
        args.putInt(InitBundle.EPISODE, episode.getInt(CheckInQuery.NUMBER));
        args.putString(InitBundle.SHOW_GETGLUE_ID, episode.getString(CheckInQuery.SHOW_GETGLUE_ID));

        String episodeTitleWithNumbers = ShareUtils.onCreateShareString(context, episode);
        args.putString(InitBundle.ITEM_TITLE, episodeTitleWithNumbers);
        args.putString(InitBundle.DEFAULT_MESSAGE, episodeTitleWithNumbers);
        f.setArguments(args);
      }
      episode.close();
    }

    return f;
  }
Esempio n. 2
0
  @Override
  public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
      case CONTEXT_CHECKIN_ID:
        {
          fireTrackerEventContext("Check in");

          Cursor show = (Cursor) mAdapter.getItem(info.position);
          int episodeTvdbId = show.getInt(ShowsQuery.NEXTEPISODE);
          if (episodeTvdbId <= 0) {
            return true;
          }

          // display a check-in dialog
          CheckInDialogFragment f = CheckInDialogFragment.newInstance(getActivity(), episodeTvdbId);
          f.show(getFragmentManager(), "checkin-dialog");

          return true;
        }
      case CONTEXT_FAVORITE_ID:
        {
          onFavoriteShow(String.valueOf(info.id), true);
          return true;
        }
      case CONTEXT_UNFAVORITE_ID:
        {
          onFavoriteShow(String.valueOf(info.id), false);
          return true;
        }
      case CONTEXT_HIDE_ID:
        {
          fireTrackerEventContext("Hide show");

          ContentValues values = new ContentValues();
          values.put(Shows.HIDDEN, true);
          getActivity()
              .getContentResolver()
              .update(Shows.buildShowUri(String.valueOf(info.id)), values, null, null);
          Toast.makeText(getActivity(), getString(R.string.hidden), Toast.LENGTH_SHORT).show();
          return true;
        }
      case CONTEXT_UNHIDE_ID:
        {
          fireTrackerEventContext("Unhide show");

          ContentValues values = new ContentValues();
          values.put(Shows.HIDDEN, false);
          getActivity()
              .getContentResolver()
              .update(Shows.buildShowUri(String.valueOf(info.id)), values, null, null);
          Toast.makeText(getActivity(), getString(R.string.unhidden), Toast.LENGTH_SHORT).show();
          return true;
        }
      case CONTEXT_DELETE_ID:
        if (!SgSyncAdapter.isSyncActive(getActivity(), true)) {
          showDeleteDialog(info.id);
        }

        fireTrackerEventContext("Delete show");
        return true;
      case CONTEXT_UPDATE_ID:
        SgSyncAdapter.requestSync(getActivity(), (int) info.id);

        fireTrackerEventContext("Update show");
        return true;
      case CONTEXT_FLAG_NEXT_ID:
        fireTrackerEventContext("Mark next episode");

        Cursor show = (Cursor) mAdapter.getItem(info.position);
        DBUtils.markNextEpisode(getActivity(), (int) info.id, show.getInt(ShowsQuery.NEXTEPISODE));

        return true;
      case CONTEXT_MANAGE_LISTS_ID:
        {
          fireTrackerEventContext("Manage lists");

          ListsDialogFragment.showListsDialog(
              String.valueOf(info.id), ListItemTypes.SHOW, getFragmentManager());
          return true;
        }
    }
    return super.onContextItemSelected(item);
  }