private void handleJsonList(ViewHolder holder, int position) {
    ThreadPageInfo entry = getEntry(position);
    // this.topicListInfo.getArticleEntryList().get(position);

    if (entry == null) {
      return;
    }
    Resources res = inflater.getContext().getResources();
    ThemeManager theme = ThemeManager.getInstance();
    boolean night = false;
    int nightLinkColor = res.getColor(R.color.night_link_color);
    if (theme.getMode() == ThemeManager.MODE_NIGHT) night = true;
    holder.author.setText(entry.getAuthor());
    if (night) holder.author.setTextColor(nightLinkColor);

    String lastPoster = entry.getLastposter_org();
    if (StringUtil.isEmpty(lastPoster)) lastPoster = entry.getLastposter();
    holder.lastReply.setText(lastPoster);
    holder.num.setText("" + entry.getReplies());
    if (night) {
      holder.lastReply.setTextColor(nightLinkColor);
      holder.num.setTextColor(nightLinkColor);
    }

    holder.title.setTextColor(res.getColor(theme.getForegroundColor()));
    float size = PhoneConfiguration.getInstance().getTextSize();

    String titile = entry.getContent();
    if (StringUtil.isEmpty(titile)) {
      titile = entry.getSubject();
      holder.title.setText(StringUtil.unEscapeHtml(titile));

    } else {
      holder.title.setText(StringUtil.removeBrTag(StringUtil.unEscapeHtml(titile)));
    }

    holder.title.setTextSize(size);
    final TextPaint tp = holder.title.getPaint();
    tp.setFakeBoldText(false);

    if (!StringUtil.isEmpty(entry.getTitlefont())) {
      final String font = entry.getTitlefont();
      if (font.equals("~1~~") || font.equals("~~~1")) {
        tp.setFakeBoldText(true);
      } else if (font.startsWith("green")) {
        holder.title.setTextColor(res.getColor(R.color.title_green));
      } else if (font.startsWith("blue")) {
        holder.title.setTextColor(res.getColor(R.color.title_blue));
      } else if (font.startsWith("red")) {
        holder.title.setTextColor(res.getColor(R.color.title_red));
      } else if (font.startsWith("orange")) {
        holder.title.setTextColor(res.getColor(R.color.title_orange));
      }
    }
  }
 @Override
 public void finishLoad(ThreadData data) {
   int exactCount = 1 + data.getThreadInfo().getReplies() / 20;
   if (mTabsAdapter.getCount() != exactCount && this.authorid == 0) {
     if (this.pid != 0) exactCount = 1;
     mTabsAdapter.setCount(exactCount);
   }
   if (this.authorid > 0) {
     exactCount = 1 + data.get__ROWS() / 20;
     mTabsAdapter.setCount(exactCount);
   }
   if (tid != data.getThreadInfo().getTid()) // mirror thread
   tid = data.getThreadInfo().getTid();
   fid = data.getThreadInfo().getFid();
   setTitle(StringUtil.unEscapeHtml(data.getThreadInfo().getSubject()));
 }
  @Override
  public void finishLoad(ThreadData data) {
    /*int exactCount = 1 + data.getThreadInfo().getReplies()/20;
    if(father.getmTabsAdapter().getCount() != exactCount
    		&&this.authorid == 0){
    	father.getmTabsAdapter().setCount(exactCount);
    }
    father.setTitle(StringUtil.unEscapeHtml(data.getThreadInfo().getSubject()));
    */

    Fragment articleContainer =
        getSupportFragmentManager().findFragmentById(R.id.item_detail_container);

    OnThreadPageLoadFinishedListener listener = null;
    try {
      listener = (OnThreadPageLoadFinishedListener) articleContainer;
      if (listener != null) {
        listener.finishLoad(data);
        setTitle(StringUtil.unEscapeHtml(data.getThreadInfo().getSubject()));
      }
    } catch (ClassCastException e) {
      Log.e(TAG, "detailContainer should implements OnThreadPageLoadFinishedListener");
    }
  }
コード例 #4
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {

    Log.d(TAG, "onContextItemSelected,tid=" + tid + ",page=" + page);
    PagerOwnner father = null;
    try {
      father = (PagerOwnner) getActivity();
    } catch (ClassCastException e) {
      Log.e(TAG, "father activity does not implements interface " + PagerOwnner.class.getName());
      return true;
    }

    if (father == null) return false;

    if (father.getCurrentPage() != page) {
      return false;
    }

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int position = this.listview.getCheckedItemPosition();
    if (info != null) {
      position = info.position;
    }
    if (position < 0 || position >= listview.getAdapter().getCount()) {
      Toast.makeText(getActivity(), R.string.floor_error, Toast.LENGTH_LONG).show();
      position = 0;
    }
    StringBuffer postPrefix = new StringBuffer();
    String tidStr = String.valueOf(this.tid);

    ThreadRowInfo row = (ThreadRowInfo) listview.getItemAtPosition(position);
    if (row == null) {
      Toast.makeText(getActivity(), R.string.unknow_error, Toast.LENGTH_LONG).show();
      return true;
    }
    String content = row.getContent();
    final String name = row.getAuthor();
    String mention = null;
    Intent intent = new Intent();
    switch (item.getItemId())
    // if( REPLY_POST_ORDER ==item.getItemId())
    {
      case R.id.quote_subject:
        final String quote_regex = "\\[quote\\]([\\s\\S])*\\[/quote\\]";
        final String replay_regex =
            "\\[b\\]Reply to \\[pid=\\d+,\\d+,\\d+\\]Reply\\[/pid\\] Post by .+?\\[/b\\]";
        content = content.replaceAll(quote_regex, "");
        content = content.replaceAll(replay_regex, "");
        final String postTime = row.getPostdate();

        if (!content.trim().endsWith("[/url]")) {
          if (content.length() > 100) content = content.substring(0, 99) + ".......";
        }
        content = StringUtil.unEscapeHtml(content);

        if (row.getPid() != 0) {
          mention = name;
          postPrefix.append("[quote][pid=");
          postPrefix.append(row.getPid());
          postPrefix.append(',').append(tidStr).append(",").append(page);
          postPrefix.append("]"); // Topic
          postPrefix.append("Reply");
          postPrefix.append("[/pid] [b]Post by ");
          postPrefix.append(name);
          postPrefix.append(" (");
          postPrefix.append(postTime);
          postPrefix.append("):[/b]\n");
          postPrefix.append(content);
          postPrefix.append("[/quote]\n");
        }

        // case R.id.r:

        if (!StringUtil.isEmpty(mention)) intent.putExtra("mention", mention);
        intent.putExtra("prefix", StringUtil.removeBrTag(postPrefix.toString()));
        intent.putExtra("tid", tidStr);
        intent.putExtra("action", "reply");
        intent.setClass(getActivity(), PostActivity.class);
        startActivity(intent);
        if (PhoneConfiguration.getInstance().showAnimation)
          getActivity().overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
        break;
      case R.id.edit:
        if (isComment(row)) {
          Toast.makeText(getActivity(), R.string.cannot_eidt_comment, Toast.LENGTH_SHORT).show();
          break;
        }
        Intent intentModify = new Intent();
        intentModify.putExtra("prefix", StringUtil.unEscapeHtml(StringUtil.removeBrTag(content)));
        intentModify.putExtra("tid", tidStr);
        String pid = String.valueOf(row.getPid()); // getPid(map.get("url"));
        intentModify.putExtra("pid", pid);
        intentModify.putExtra("title", StringUtil.unEscapeHtml(row.getSubject()));
        intentModify.putExtra("action", "modify");
        intentModify.setClass(getActivity(), PostActivity.class);
        startActivity(intentModify);
        if (PhoneConfiguration.getInstance().showAnimation)
          getActivity().overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
        break;
      case R.id.copy_to_clipboard:
        // if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB )
        // {
        android.text.ClipboardManager cbm =
            (android.text.ClipboardManager)
                getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
        cbm.setText(StringUtil.removeBrTag(content));
        // }else{
        // android.content.ClipboardManager  cbm = (android.content.ClipboardManager)
        // getSystemService(CLIPBOARD_SERVICE);
        // cbm.setPrimaryClip(ClipData.newPlainText("content", content));
        // }

        Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
        break;
      case R.id.show_this_person_only:
        Intent intentThis = new Intent();
        intentThis.putExtra("tab", "1");
        intentThis.putExtra("tid", tid);
        intentThis.putExtra("authorid", row.getAuthorid());

        intentThis.setClass(getActivity(), PhoneConfiguration.getInstance().articleActivityClass);
        startActivity(intentThis);
        if (PhoneConfiguration.getInstance().showAnimation)
          getActivity().overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);

        // restNotifier.reset(0, row.getAuthorid());
        // ActivityUtil.getInstance().noticeSaying(getActivity());

        break;
      case R.id.show_whole_thread:
        ResetableArticle restNotifier = null;
        try {
          restNotifier = (ResetableArticle) getActivity();
        } catch (ClassCastException e) {
          Log.e(
              TAG,
              "father activity does not implements interface " + ResetableArticle.class.getName());
          return true;
        }
        restNotifier.reset(0, 0, row.getLou());
        ActivityUtil.getInstance().noticeSaying(getActivity());
        break;
      case R.id.post_comment:
        final String dialog_tag = "post comment";
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        Fragment prev = getActivity().getSupportFragmentManager().findFragmentByTag(dialog_tag);
        if (prev != null) {
          ft.remove(prev);
        }
        DialogFragment df = new PostCommentDialogFragment();
        Bundle b = new Bundle();
        b.putInt("pid", row.getPid());
        b.putInt("tid", this.tid);
        df.setArguments(b);
        df.show(ft, dialog_tag);

        break;
      case R.id.report:
        handleReport(row);
        break;
      case R.id.search_post:
        intent.putExtra("searchpost", 1);
      case R.id.search_subject:
        intent.putExtra("authorid", row.getAuthorid());
        intent.setClass(getActivity(), PhoneConfiguration.getInstance().topicActivityClass);
        startActivity(intent);
        if (PhoneConfiguration.getInstance().showAnimation)
          getActivity().overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);

        break;
      case R.id.item_share:
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");
        String shareUrl = "http://bbs.ngacn.cc/read.php?";
        if (row.getPid() != 0) {
          shareUrl = shareUrl + "pid=" + row.getPid();
        } else {
          shareUrl = shareUrl + "tid=" + tid;
        }
        intent.putExtra(Intent.EXTRA_TEXT, shareUrl);
        String text = getResources().getString(R.string.share);
        getActivity().startActivity(Intent.createChooser(intent, text));
        break;
    }
    return true;
  }