コード例 #1
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menuInfo.toString();

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor show =
        getActivity()
            .getContentResolver()
            .query(
                Shows.buildShowUri(String.valueOf(info.id)),
                new String[] {Shows.FAVORITE, Shows.HIDDEN},
                null,
                null,
                null);
    show.moveToFirst();
    if (show.getInt(0) == 0) {
      menu.add(0, CONTEXT_FAVORITE_ID, 2, R.string.context_favorite);
    } else {
      menu.add(0, CONTEXT_UNFAVORITE_ID, 2, R.string.context_unfavorite);
    }
    if (show.getInt(1) == 0) {
      menu.add(0, CONTEXT_HIDE_ID, 3, R.string.context_hide);
    } else {
      menu.add(0, CONTEXT_UNHIDE_ID, 3, R.string.context_unhide);
    }
    show.close();

    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    menu.add(0, CONTEXT_FLAG_NEXT_ID, 1, R.string.context_marknext);
    menu.add(0, CONTEXT_MANAGE_LISTS_ID, 4, R.string.list_item_manage);
    menu.add(0, CONTEXT_UPDATE_ID, 5, R.string.context_updateshow);
    menu.add(0, CONTEXT_DELETE_ID, 6, R.string.delete_show);
  }
コード例 #2
0
  private void onFavoriteShow(String showId, boolean isFavorite) {
    ContentValues values = new ContentValues();
    values.put(Shows.FAVORITE, isFavorite);
    getActivity().getContentResolver().update(Shows.buildShowUri(showId), values, null, null);

    Utils.runNotificationService(getActivity());

    Toast.makeText(
            getActivity(),
            getString(isFavorite ? R.string.favorited : R.string.unfavorited),
            Toast.LENGTH_SHORT)
        .show();

    fireTrackerEventContext(isFavorite ? "Favorite show" : "Unfavorite show");
  }
コード例 #3
0
  @Override
  protected boolean onGetGlueCheckin(String title, String message) {
    boolean isAbortingCheckIn = false;

    // require GetGlue authentication
    if (!GetGlueSettings.isAuthenticated(getActivity())) {
      isAbortingCheckIn = true;
    }

    // always get the latest GetGlue id
    final Cursor show =
        getActivity()
            .getContentResolver()
            .query(
                Shows.buildShowUri(String.valueOf(mShowTvdbId)),
                new String[] {Shows._ID, Shows.GETGLUEID},
                null,
                null,
                null);
    if (show != null) {
      show.moveToFirst();
      mGetGlueId = show.getString(1);
      show.close();
    }

    // check for GetGlue id
    if (TextUtils.isEmpty(mGetGlueId)) {
      isAbortingCheckIn = true;
    }

    if (isAbortingCheckIn) {
      mToggleGetGlueButton.setChecked(false);
      mGetGlueChecked = false;
      updateCheckInButtonState();
    } else {
      // check in, use task on thread pool
      AndroidUtils.executeAsyncTask(
          new CheckInTask(mGetGlueId, message, getActivity()), new Void[] {});
    }

    return isAbortingCheckIn;
  }
コード例 #4
0
ファイル: TheTVDB.java プロジェクト: inmyfree/SeriesGuide
  /**
   * Returns true if the given show has not been updated in the last 12 hours.
   *
   * @param showId
   * @param currentTime
   * @param context
   * @return
   */
  public static boolean isUpdateShow(String showId, long currentTime, Context context) {
    final Cursor show =
        context
            .getContentResolver()
            .query(
                Shows.buildShowUri(showId),
                new String[] {Shows._ID, Shows.LASTUPDATED},
                null,
                null,
                null);

    if (show != null) {
      if (show.moveToFirst()) {
        long lastUpdateTime = show.getLong(1);
        if (currentTime - lastUpdateTime > DateUtils.HOUR_IN_MILLIS * 12) {
          return true;
        }
      }

      show.close();
    }

    return false;
  }
コード例 #5
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);
  }