예제 #1
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    int actualPos = info.position - tagListView.getHeaderViewsCount();
    if (actualPos < 0) return;
    Tag tagClicked = tags.getTags().get(actualPos);

    // Log.i("occm", tagClicked.getParent_id() + " " +
    // tagClicked.getComment().toString());

    String userId = tagInfo.getString("user_id", "error");

    boolean isOwnTag = (tagClicked.getUser_id().equals(userId));

    menu.setHeaderTitle(R.string.context_menu_header);
    menu.add(0, v.getId(), 6, R.string.context_menu_reply);
    if (!tagClicked.getParent_id().equals("0")) {
      menu.add(0, v.getId(), 5, R.string.context_menu_show_orig);
    }
    if (isOwnTag) return;

    if (!tagClicked.getIs_thumbedup()) menu.add(0, v.getId(), 1, R.string.context_menu_thumbup);

    if (Session.getFollowerSet().contains(tagClicked.getUser_id()))
      menu.add(0, v.getId(), 3, R.string.context_menu_unfollow);
    else menu.add(0, v.getId(), 4, R.string.context_menu_follow);
  }
예제 #2
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    Tag currentTag = null;
    int actualPos = 0;
    try {
      if (UpdateTagService.tagUpdateLock.tryLock(500, TimeUnit.MILLISECONDS)) {
        actualPos = info.position - tagListView.getHeaderViewsCount();
        if (actualPos < 0) {
          return false;
        }
        currentTag = tags.getTags().get(actualPos);
      } else return false;
    } catch (InterruptedException e) {
      e.printStackTrace();
      return false;
    }

    TagRequestHandler tagHandler = new TagRequestHandler();

    if (item.getTitle().equals("Thumb Up")) {
      currentTag.setIs_thumbedup(true);
      currentTag.setThumbup_count(currentTag.getThumbup_count() + 1);
      adapter.notifyDataSetChanged();
      tagHandler.thumbupAction(
          currentTag.get_id(), currentTag.getLocation(), currentTag.getLocation_type());
      return true;
    } else if (item.getTitle().equals("Follow")) {
      tagHandler.createFollowing(currentTag.getUser_id(), currentTag.getLocation_type());
      return true;
    } else if (item.getTitle().equals("Unfollow")) {
      tagHandler.unfollow(currentTag.getUser_id());
      return true;
    } else if (item.getTitle().equals("Show Original")) {
      tagHandler.showOrig(currentTag.getParent_id(), currentTag.get_id());
      return true;
    } else if (item.getTitle().equals("Reply")) {
      tagHandler.loadReply(currentTag);
      return true;
    } else {
      return super.onContextItemSelected(item);
    }
  }