Esempio n. 1
0
  @Override
  public View bindView(int position, View convertView, ViewGroup parent) {
    if (null == convertView) {
      convertView = LayoutInflater.from(mContext).inflate(R.layout.my_follows_item, null);
    }

    final NearbyUser user = this.list.get(position);

    final ImageView ivFace = ViewHolder.get(convertView, R.id.iv_user_face);

    TextView tvNickname = ViewHolder.get(convertView, R.id.tv_user_nickname);
    TextView tvAge = ViewHolder.get(convertView, R.id.tv_user_age);

    ImageView ivVip = ViewHolder.get(convertView, R.id.iv_vip);

    // 距离
    //	TextView tvDistance = ViewHolder.get(convertView, R.id.tv_user_distance);

    // vip
    ivVip.setImageResource(user.getVip() != 0 ? R.drawable.vip : R.drawable.vipnot);
    tvNickname.setTextColor(
        mContext.getResources().getColor(user.getVip() != 0 ? R.color.c_vip : R.color.c_not_vip));
    //	ivVip.setVisibility(user.getVip() != 0 ? View.VISIBLE : View.GONE);

    // displayImage 会有刷新闪烁问题
    ImageLoader.getInstance()
        .displayImage(
            user.getFaceUrl().getSmallImageUrl(),
            ivFace,
            ImageLoaderOptions.rounderOptions(),
            new ImageLoadingListener() {

              @Override
              public void onLoadingStarted(String arg0, View arg1) {
                // TODO Auto-generated method stub

              }

              @Override
              public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
                // TODO Auto-generated method stub

              }

              @Override
              public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                // TODO Auto-generated method stub
                notifyDataSetChanged();
              }

              @Override
              public void onLoadingCancelled(String arg0, View arg1) {
                // TODO Auto-generated method stub

              }
            });

    //	ImageLoader.getInstance().loadImage(user.getFaceUrl(), ImageLoaderOptions.rounderOptions(),
    // new ImageLoadingListener() {
    //
    //	    @Override
    //	    public void onLoadingStarted(String arg0, View arg1) {
    //		// TODO Auto-generated method stub
    //
    //	    }
    //
    //	    @Override
    //	    public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
    //		// TODO Auto-generated method stub
    //
    //	    }
    //
    //	    @Override
    //	    public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
    //		ivFace.setImageBitmap(arg2);
    //	    }
    //
    //	    @Override
    //	    public void onLoadingCancelled(String arg0, View arg1) {
    //		// TODO Auto-generated method stub
    //
    //	    }
    //	});
    tvNickname.setText(user.getNickname());
    tvAge.setText(user.getAge() + "");

    //	tvDistance.setText(user.getDistance() + "km");

    int backRes = 0;
    Drawable genderDrawable = null;
    if (user.getGender() == 1) {
      backRes = R.drawable.shape_gender_age_male;
      genderDrawable = mContext.getResources().getDrawable(R.drawable.ic_user_male2);
    } else {
      backRes = R.drawable.shape_gender_age_female;
      genderDrawable = mContext.getResources().getDrawable(R.drawable.ic_user_famale2);
    }
    tvAge.setBackgroundResource(backRes);

    // 必须设置 bounds, 否则不显示
    genderDrawable.setBounds(
        0, 0, genderDrawable.getMinimumWidth(), genderDrawable.getMinimumHeight());
    tvAge.setCompoundDrawables(genderDrawable, null, null, null);

    return convertView;
  }
  private View createArticleView() {

    View convertView = LayoutInflater.from(this).inflate(R.layout.article_item, null);

    final Article article = this.targetArticle;

    // 文章配图
    ImageView ivBackground = ViewHolder.get(convertView, R.id.iv_article_image);

    final ImageView ivFace = ViewHolder.get(convertView, R.id.iv_user_face);

    TextView tvNickname = ViewHolder.get(convertView, R.id.tv_user_nickname);

    TextView tvContent = ViewHolder.get(convertView, R.id.tv_secret_content); // 内容

    TextView tvTime = ViewHolder.get(convertView, R.id.tv_time); // 时间

    ImageView ivVip = ViewHolder.get(convertView, R.id.iv_vip);

    final ImageView ivLoves = ViewHolder.get(convertView, R.id.iv_likes); // 赞图标
    final TextView tvLoves = ViewHolder.get(convertView, R.id.tv_likes); // 赞次数
    TextView tvComments = ViewHolder.get(convertView, R.id.tv_comments); // 评论数

    tvLoves.setText(article.getLove() + "");
    tvComments.setText(article.getComments() + "");

    tvTime.setText(ActivityUtil.convertTimeToString(article.getCreateTime() * 1000L));

    // vip
    ivVip.setImageResource(article.getVip() != 0 ? R.drawable.vip : R.drawable.vipnot);
    tvNickname.setTextColor(
        getResources().getColor(article.getVip() != 0 ? R.color.c_vip : R.color.c_not_vip));
    //	ivVip.setVisibility(user.getVip() != 0 ? View.VISIBLE : View.GONE);

    if (article.getContentImageUrl().getSmallImageUrl() == null
        || article.getContentImageUrl().getSmallImageUrl().trim().length() == 0) {
      ivBackground.setVisibility(View.GONE);
    } else {
      ivBackground.setVisibility(View.VISIBLE);
      String imageUrl = article.getContentImageUrl().getSmallImageUrl();
      // 文章配图
      ImageLoader.getInstance()
          .displayImage(
              imageUrl,
              ivBackground,
              ImageLoaderOptions.normalOptions(),
              new ImageLoadingListener() {

                @Override
                public void onLoadingStarted(String arg0, View arg1) {
                  // TODO Auto-generated method stub

                }

                @Override
                public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
                  // TODO Auto-generated method stub

                }

                @Override
                public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                  // TODO Auto-generated method stub
                  mCommentsAdapter.notifyDataSetChanged();
                }

                @Override
                public void onLoadingCancelled(String arg0, View arg1) {
                  // TODO Auto-generated method stub

                }
              });
    }

    // displayImage 会有刷新闪烁问题
    ImageLoader.getInstance()
        .displayImage(
            article.getFaceUrl().getSmallImageUrl(),
            ivFace,
            ImageLoaderOptions.circleOptions(),
            new ImageLoadingListener() {

              @Override
              public void onLoadingStarted(String arg0, View arg1) {
                // TODO Auto-generated method stub

              }

              @Override
              public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
                // TODO Auto-generated method stub

              }

              @Override
              public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                // TODO Auto-generated method stub
                mCommentsAdapter.notifyDataSetChanged();
              }

              @Override
              public void onLoadingCancelled(String arg0, View arg1) {
                // TODO Auto-generated method stub

              }
            });

    tvNickname.setText(article.getNickname());

    tvContent.setText(article.getContent()); // 秘密的内容

    View love = ViewHolder.get(convertView, R.id.layout_likes);
    love.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            VoteArticleLovePostParams postParams = new VoteArticleLovePostParams();
            postParams.articleId = targetArticle.getId();
            AppServiceExtendImpl.getInstance()
                .loveArticle(
                    postParams,
                    new OnVoteArticleLoveResponseListener() {

                      @Override
                      public void onSuccess() {
                        // TODO Auto-generated method stub
                        tvLoves.setText(
                            Integer.parseInt(tvLoves.getText().toString().trim()) + 1 + "");
                        ivLoves.setBackgroundResource(R.drawable.player_collection_pressed);
                      }

                      @Override
                      public void onFailure(String errorMsg) {
                        // TODO Auto-generated method stub
                        showToast(errorMsg);
                      }
                    });
          }
        });
    // 分享
    View v = ViewHolder.get(convertView, R.id.iv_article_more);
    v.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            testShare();
          }
        });
    return convertView;
  }