예제 #1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder h = null;
      if (convertView == null) {
        convertView =
            LayoutInflater.from(getActivity()).inflate(R.layout.item_lv_acty_messagecenter, null);
        h = new ViewHolder();
        h.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_avatar);
        h.tv_username = (TextView) convertView.findViewById(R.id.tv_username);
        h.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
        h.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
        h.tv_unreadCount = (TextView) convertView.findViewById(R.id.tv_unreadcount);
        convertView.setTag(h);
      } else {
        h = (ViewHolder) convertView.getTag();
      }
      MMessage mm = data_message.get(position);

      if (mm.getSenderavatar() != null) {
        ImageLoader.getInstance()
            .displayImage(RestClient.BASE_URL + mm.getSenderavatar(), h.iv_avatar);
      } else {
        ImageLoader.getInstance()
            .displayImage("drawalbe://" + R.drawable.ic_image_load_normal, h.iv_avatar);
      }
      h.tv_content.setText(mm.getBody());
      h.tv_username.setText(mm.getSendername());
      h.tv_time.setText(
          CalendarUtils.getTimeFromat(
              data_message.get(position).getSendtime(), CalendarUtils.TYPE_timeline));
      h.tv_unreadCount.setVisibility(View.GONE);

      if (mm.getSenderid() == 8) { // 系统消息
        h.tv_username.setTextColor(getResources().getColor(R.color.blue_lv_two));
      } else {
        h.tv_username.setTextColor(getResources().getColor(R.color.black));
      }
      if (mm.getUnreadcount() > 0) {
        h.tv_unreadCount.setText(mm.getUnreadcount() + "");
        h.tv_unreadCount.setVisibility(View.VISIBLE);
      }
      return convertView;
    }
  @Override
  protected void initLayout() {
    tv_notify = (TextView) _getView(R.id.acty_communicationdetail_tv_notify);
    tv_username = (TextView) _getView(R.id.acty_communicationdetail_tv_name);
    tv_time = (TextView) _getView(R.id.acty_communicationdetail_tv_posttime);
    tv_title = (TextView) _getView(R.id.item_lv_acty_comminication_title);
    tv_body = (TextView) _getView(R.id.item_lv_acty_comminication_body);
    iv_avater = (ImageView) _getView(R.id.acty_communicationdetail_iv_avater);

    owner = _getView(R.id.owner);
    vistor = _getView(R.id.visitor);
    if (issue.getUser().getId() == user.getId()) {
      owner.setVisibility(View.VISIBLE);
      vistor.setVisibility(View.GONE);
    } else {
      owner.setVisibility(View.GONE);
      vistor.setVisibility(View.VISIBLE);
    }

    // 头像
    if (issue.getUser().getAvatar() != null) {
      ImageLoader.getInstance()
          .displayImage(RestClient.BASE_URL + issue.getUser().getAvatar(), iv_avater);
    } else {
      ImageLoader.getInstance()
          .displayImage("drawable://" + R.drawable.ic_image_load_normal, iv_avater);
    }
    tv_username.setText(issue.getUser().getProfile().getName());
    tv_time.setText(CalendarUtils.getTimeFromat(issue.getPosttime(), CalendarUtils.TYPE_timeline));
    tv_title.setText(issue.getTitle());
    tv_body.setText(issue.getBody());

    btn_back = _getView(R.id.acty_head_btn_back);
    btn_space = _getView(R.id.acty_communicationdetail_btn_space);
    btn_share = _getView(R.id.acty_communicationdetail_footer_share);
    btn_comment = _getView(R.id.acty_communicationdetail_footer_comment);
    btn_favourite = _getView(R.id.acty_communicationdetail_footer_favourite);
    btn_delete = _getView(R.id.btn_delete);
    btn_edit = _getView(R.id.btn_edit);

    btn_back.setOnClickListener(this);
    btn_space.setOnClickListener(this);
    btn_share.setOnClickListener(this);
    btn_comment.setOnClickListener(this);
    btn_favourite.setOnClickListener(this);
    btn_delete.setOnClickListener(this);
    btn_edit.setOnClickListener(this);

    lv_comment = (CommentView) _getView(R.id.item_lv_acty_comminication_lv_comment);
    adapter_commet = new CommentAdapter(getContext(), data_commet);
    lv_comment.setAdapter(adapter_commet);

    api.view(
        issue.getId(),
        new JsonResponseHandler() {
          @Override
          public void onStart() {
            tv_notify.setText("评论加载中....");
            tv_notify.setVisibility(View.VISIBLE);
          }

          @Override
          public void onOK(Header[] headers, JSONObject obj) {
            tv_notify.setVisibility(View.GONE);
            List<Comment> newData_comment = Comment.create_by_jsonarray(obj.toString());
            if (newData_comment != null && newData_comment.size() > 0) {
              data_commet.addAll(newData_comment);
              lv_comment.setAdapter(new CommentAdapter(getContext(), data_commet));
            } else {
              if (newData_comment == null) {
                tv_notify.setVisibility(View.VISIBLE);
                tv_notify.setText("网络异常,解析错误");
                toast("网络异常,解析错误");
              } else if (newData_comment.size() == 0) {
                toast("还没有人评论!");
                tv_notify.setText("还没有人评论!");
                tv_notify.setVisibility(View.VISIBLE);
              }
            }
          }

          @Override
          public void onFaild(int errorType, int errorCode) {
            toast(ErrorCode.errorList.get(errorCode));
            tv_notify.setVisibility(View.GONE);
          }
        });
  }