Esempio n. 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;
 }
Esempio n. 2
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;
  }
Esempio n. 3
0
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
   BmobRecent recent = adapter.getItem(position);
   // 重置未读消息
   BmobDB.create(this).resetUnread(recent.getTargetid());
   // 组装聊天对象
   BmobChatUser user = new BmobChatUser();
   user.setAvatar(recent.getAvatar());
   user.setNick(recent.getNick());
   user.setUsername(recent.getUserName());
   user.setObjectId(recent.getTargetid());
   Intent intent = new Intent(this, ChatActivity.class);
   intent.putExtra("user", user);
   startAnimActivity(intent);
 }
Esempio n. 4
0
 private void initView() {
   title.setText(getString(R.string.chat_title, targetUser.getNick()));
   mListView = (XListView) findViewById(R.id.mListView);
   initBottomView();
   initXListView();
   initVoiceView();
 }
  // 发送评论
  private void sendComment() {
    if (TextUtils.isEmpty(comment_text.getText())) {
      ShowToast("至少说一个字嘛");
      return;
    }
    final Comment comment = new Comment();
    comment.setUser(BmobChatUser.getCurrentUser(getApplicationContext(), MyUser.class));
    comment.setContent(comment_text.getText().toString());
    comment.setGoods(good); // 设置为当前商品
    comment.setTouser(user);
    // 将当前要评论的内容先添加至本地数据源,更行UI,然后再在网络上更新
    data.add(0, comment);
    adapter.notifyDataSetChanged();
    comment.save(
        DetailActivity.this,
        new SaveListener() {

          @Override
          public void onSuccess() {
            ShowToast("评论成功");
            comment_text.setText("");
            addCommentToGoods(comment);
          }

          @Override
          public void onFailure(int arg0, String arg1) {}
        });
  }
Esempio n. 6
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;
  }
 @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;
 }
Esempio n. 8
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   manager = BmobChatManager.getInstance(this);
   MsgPagerNum = 0;
   // 组装聊天对象
   targetUser = (BmobChatUser) getIntent().getSerializableExtra("user");
   targetId = targetUser.getObjectId();
   //		BmobLog.i("聊天对象:" + targetUser.getUsername() + ",targetId = "
   //				+ targetId);
   // 注册广播接收器
   initNewMessageBroadCast();
   initView();
 }
Esempio n. 9
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();
  }