Пример #1
0
 public static Map<String, BmobChatUser> list2map(List<BmobChatUser> list) {
   Map<String, BmobChatUser> friends = new HashMap<String, BmobChatUser>();
   for (BmobChatUser user : list) {
     friends.put(user.getUsername(), user);
   }
   return friends;
 }
Пример #2
0
  /**
   * 显示移除黑名单对话框 @Title: showRemoveBlackDialog @Description: TODO
   *
   * @param @param position
   * @param @param invite
   * @return void
   * @throws
   */
  public void showRemoveBlackDialog(final int position, final BmobChatUser user) {
    DialogTips dialog =
        new DialogTips(this, "移出黑名单", "你确定将" + user.getUsername() + "移出黑名单吗?", "确定", true, true);
    // 设置成功事件
    dialog.SetOnSuccessListener(
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialogInterface, int userId) {
            adapter.remove(position);
            userManager.removeBlack(
                user.getUsername(),
                new UpdateListener() {

                  @Override
                  public void onSuccess() {
                    // TODO Auto-generated method stub
                    ShowToast("移出黑名单成功");
                    // 重新设置下内存中保存的好友列表
                    CustomApplcation.getInstance()
                        .setContactList(
                            CollectionUtils.list2map(
                                BmobDB.create(getApplicationContext()).getContactList()));
                  }

                  @Override
                  public void onFailure(int arg0, String arg1) {
                    // TODO Auto-generated method stub
                    ShowToast("移出黑名单失败:" + arg1);
                  }
                });
          }
        });
    // 显示确认对话框
    dialog.show();
    dialog = null;
  }
Пример #3
0
  @Override
  public View bindView(int arg0, View convertView, ViewGroup arg2) {
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_add_friend, null);
    }
    final BmobChatUser contract = getList().get(arg0);
    TextView name = ViewHolder.get(convertView, R.id.name);
    ImageView iv_avatar = ViewHolder.get(convertView, R.id.avatar);
    Button btn_add = ViewHolder.get(convertView, R.id.btn_add);
    String avatar = contract.getAvatar();

    if (avatar != null && !avatar.equals("")) {
      ImageLoader.getInstance().displayImage(avatar, iv_avatar, ImageLoadOptions.getOptions());
    } else {
      iv_avatar.setImageResource(R.drawable.default_head);
    }

    name.setText(contract.getUsername());
    btn_add.setText("添加");
    btn_add.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            // 生成进度条
            final ProgressDialog progress = new ProgressDialog(mContext);
            progress.setMessage("正在添加...");
            progress.setCanceledOnTouchOutside(false);
            progress.show();
            // 向陌生人发送添加好友请求
            BmobChatManager.getInstance(mContext)
                .sendTagMessage(
                    BmobConfig.TAG_ADD_CONTACT,
                    contract.getObjectId(),
                    new PushListener() {

                      @Override
                      public void onSuccess() {
                        progress.dismiss();
                        ShowToast("发送请求成功,等待对方验证!");
                      }

                      @Override
                      public void onFailure(int arg0, final String arg1) {
                        progress.dismiss();
                        ShowToast("发送请求失败,请重新添加!");
                        ShowLog("发送请求失败:" + arg1);
                      }
                    });
          }
        });
    return convertView;
  }
 @Override
 public View bindView(int arg0, View convertView, ViewGroup arg2) {
   // TODO Auto-generated method stub
   if (convertView == null) {
     convertView = mInflater.inflate(R.layout.item_blacklist, null);
   }
   final BmobChatUser contract = getList().get(arg0);
   TextView tv_friend_name = ViewHolder.get(convertView, R.id.tv_friend_name);
   ImageView iv_avatar = ViewHolder.get(convertView, R.id.img_friend_avatar);
   String avatar = contract.getAvatar();
   if (avatar != null && !avatar.equals("")) {
     ImageLoader.getInstance().displayImage(avatar, iv_avatar, ImageLoadOptions.getOptions());
   } else {
     iv_avatar.setImageResource(R.drawable.default_head);
   }
   tv_friend_name.setText(contract.getUsername());
   return convertView;
 }
Пример #5
0
  /**
   * 显示移除黑名单对话框 @Title: showRemoveBlackDialog @Description: TODO
   *
   * @param @param position
   * @param @param invite
   * @return void
   * @throws
   */
  public void showRemoveBlackDialog(final int position, final BmobChatUser user) {
    new Builder(this)
        .setTitle("提示")
        .setMessage("你确定将" + user.getUsername() + "移出黑名单吗?")
        .setNegativeButton(
            "取消",
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {}
            })
        .setPositiveButton(
            "确定",
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                adapter.remove(position);
                userManager.removeBlack(
                    user.getUsername(),
                    new UpdateListener() {
                      @Override
                      public void onSuccess() {
                        // TODO Auto-generated method stub
                        ShowToast("移出黑名单成功");
                        // 重新设置下内存中保存的好友列表
                        application.setContactList(
                            CollectionUtil.list2map(
                                BmobDB.create(getApplicationContext()).getContactList()));
                      }

                      @Override
                      public void onFailure(int arg0, String arg1) {
                        // TODO Auto-generated method stub
                        ShowToast("移出黑名单失败:" + arg1);
                      }
                    });
              }
            })
        .show();
  }