Exemple #1
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);
    }
  }