Esempio n. 1
0
  public void updateOnBroadcast() {
    LinkedList<Tag> tagList = tags.getTags();

    if (getActivity() == null) return;

    if (tagList.size() > 0) {
      noTagsMsg.setVisibility(View.GONE);
    } else {
      noTagsMsg.setVisibility(View.VISIBLE);
    }

    if (tagListView.getAdapter() == null) {
      adapter = new TagListAdapter(getActivity(), tagList);

      // get and set an ad for the tag list
      LayoutInflater inflater = getActivity().getLayoutInflater();
      header = (ViewGroup) inflater.inflate(R.layout.ad_layout, tagListView, false);
      tagListView.addHeaderView(header, null, false);
      header.requestFocus();
      WebserviceClient.getAnAd(getActivity(), new AdRespHandler());

      tagListView.setAdapter(adapter);
    } else {
      adapter.updateAdapterContents(tagList);
    }
    // hide progress bar
    ((MainActivity) getActivity()).showProgBar(false);
  }
Esempio n. 2
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);
  }
Esempio n. 3
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);
    }
  }
Esempio n. 4
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.tab_tags_layout, container, false);

    // instantiate views
    noTagsMsg = (TextView) view.findViewById(R.id.vt_no_tags_msg);
    tagListView = (ListView) view.findViewById(R.id.vt_tag_list);
    //		tagListView.setOnTouchListener(new touchClickListener());
    createTagEdit = (EditText) view.findViewById(R.id.vt_create_tag_edit);
    editCasttoTextView = (TextView) view.findViewById(R.id.vt_create_tag_edit);
    charCount = (TextView) view.findViewById(R.id.vt_char_count);
    arrowIcon = (ImageView) view.findViewById(R.id.vt_send_arrow);
    arrowIcon.setOnClickListener(new createTagOnClick());

    createTagEdit.addTextChangedListener(
        new TextWatcher() {
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          public void afterTextChanged(Editable s) {
            int remainingCount = charMax - s.length();
            charCount.setText(remainingCount + "");
            if (remainingCount < 0) {
              charCount.setTextColor(0xffed1c24);
              arrowIcon.setColorFilter(0x77ff0000);
            } else {
              charCount.setTextColor(0xff3c3c3c);
              arrowIcon.setColorFilter(0x00000000);
            }
          }
        });

    // set up adapter and ad
    LocStack stack = ((MainActivity) getActivity()).locStack;

    tags = ((TagLocWrapper) ((MainActivity) getActivity()).locStack.getCurrent()).getTagList();
    adapter = new TagListAdapter(getActivity(), tags.getTags());
    // get and set an ad for the tag list
    LayoutInflater adInflater = getActivity().getLayoutInflater();
    header = (ViewGroup) adInflater.inflate(R.layout.ad_layout, tagListView, false);
    tagListView.addHeaderView(header, null, false);
    header.requestFocus();
    WebserviceClient.getAnAd(getActivity(), new AdRespHandler());
    tagListView.setAdapter(adapter);

    // set onKeyListener for tagListView to navigate
    tagListView.setOnKeyListener(
        new OnKeyListener() {

          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && v.hasFocus()) {
              ((MainActivity) getActivity()).focusTagTab();
              return true;
            } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && v.hasFocus()) {
              ((MainActivity) getActivity()).focusEditbox();
              return true;
            }
            return false;
          }
        });

    // get shared preferences
    tagInfo = Ttagit.getAppContext().getSharedPreferences("tag", 0);
    return view;
  }