Exemplo n.º 1
0
    @Override
    public View instantiateItem(ViewGroup container, int position) {

      View imageLayout = inflater.inflate(R.layout.item_show_picture, container, false);
      final PhotoView photoView = (PhotoView) imageLayout.findViewById(R.id.photoview);
      final ProgressBar progress = (ProgressBar) imageLayout.findViewById(R.id.progress);

      final String imgUrl = mPhotos.get(position);
      ImageLoader.getInstance()
          .displayImage(
              imgUrl,
              photoView,
              ImageLoadOptions.getOptions(),
              new SimpleImageLoadingListener() {

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                  // TODO Auto-generated method stub
                  progress.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                  // TODO Auto-generated method stub
                  progress.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  // TODO Auto-generated method stub
                  progress.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                  // TODO Auto-generated method stub
                  progress.setVisibility(View.GONE);
                }
              });

      container.addView(imageLayout, 0);
      return imageLayout;
    }
Exemplo n.º 2
0
  @Override
  public View bindView(int arg0, View convertView, ViewGroup arg2) {
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_friendsstatus, null);
    }

    final String[] islike = new String[1]; // 用来记录是否赞过这条微博
    islike[0] = "false";
    final Blog blog = getList().get(arg0);
    final Context context = convertView.getContext();
    TextView brief = ViewHolder.get(convertView, R.id.edittext);
    TextView time = ViewHolder.get(convertView, R.id.time);
    final TextView name = ViewHolder.get(convertView, R.id.name);
    final TextView num = ViewHolder.get(convertView, R.id.num);
    final RoundImageView head = ViewHolder.get(convertView, R.id.head);
    ImageView photo = ViewHolder.get(convertView, R.id.photo);
    final ImageView like = ViewHolder.get(convertView, R.id.like);
    final User user = BmobUser.getCurrentUser(context, User.class);
    like.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            if (islike[0].equals("false")) {
              // 将当前用户添加到Blog表中的likes字段值中,表明当前用户喜欢该帖子
              BmobRelation relation = new BmobRelation();
              // 将当前用户添加到多对多关联中
              relation.add(user);
              // 多对多关联指向`blog`的`likes`字段
              blog.setLikes(relation);
              blog.update(
                  context,
                  new UpdateListener() {

                    @Override
                    public void onSuccess() {
                      likesnum++;
                      islike[0] = "true";
                      num.setText(likesnum + "");
                    }

                    @Override
                    public void onFailure(int arg0, String arg1) {}
                  });
            } else {
              showTag("你已赞过这条动态!", Effects.standard, R.id.friends_status);
            }
          }
        });

    String photouri = blog.getPhoto().getFileUrl(convertView.getContext());
    if (photouri != null && !photouri.equals("")) {
      ImageLoader.getInstance().displayImage(photouri, photo, ImageLoadOptions.getOptions());
    } else {
      photo.setImageResource(R.drawable.defalutimage);
    }

    // 因为无法直接get到user的头像,所以需要到网络去拿
    String uID = blog.getAuthor().getObjectId();

    BmobQuery<User> query = new BmobQuery<User>();
    query.getObject(
        convertView.getContext(),
        uID,
        new GetListener<User>() {

          @Override
          public void onFailure(int arg0, String arg1) {}

          @Override
          public void onSuccess(User arg0) {
            headuri = arg0.getAvatar();
            if (headuri != null && !headuri.equals("")) {
              ImageLoader.getInstance().displayImage(headuri, head, ImageLoadOptions.getOptions());
            } else {
              head.setImageResource(R.drawable.default_head);
            }
            name.setText(arg0.getUsername());
          }
        });
    // 查询喜欢这个帖子的所有用户,因此查询的是用户表
    BmobQuery<User> query2 = new BmobQuery<User>();
    // likes是Blog表中的字段,用来存储所有喜欢该帖子的用户
    query2.addWhereRelatedTo("likes", new BmobPointer(blog));
    query2.findObjects(
        convertView.getContext(),
        new FindListener<User>() {

          @Override
          public void onSuccess(List<User> object) {
            likesnum = object.size();
            num.setText(likesnum + "");
            for (int i = 0; i < object.size(); i++) {
              if (object.get(i).getObjectId().equals(user.getObjectId())) {
                islike[0] = "true";
                like.setImageResource(R.drawable.youlike);
              }
            }
          }

          @Override
          public void onError(int code, String msg) {}
        });
    brief.setText(blog.getBrief());
    time.setText(blog.getCreatedAt());
    return convertView;
  }