public void showDeleteDialog(final BmobRecent recent) { DialogTips dialog = new DialogTips(this, recent.getUserName(), "删除会话", "确定", true, true); // 设置成功事件 dialog.SetOnSuccessListener( new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int userId) { deleteRecent(recent); } }); // 显示确认对话框 dialog.show(); }
@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); }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final BmobRecent item = mData.get(position); if (convertView == null) { convertView = inflater.inflate(R.layout.item_conversation, parent, false); } final ImageView iv_recent_avatar = ViewHolder.get(convertView, R.id.iv_recent_avatar); TextView tv_recent_name = ViewHolder.get(convertView, R.id.tv_recent_name); TextView tv_recent_msg = ViewHolder.get(convertView, R.id.tv_recent_msg); TextView tv_recent_time = ViewHolder.get(convertView, R.id.tv_recent_time); TextView tv_recent_unread = ViewHolder.get(convertView, R.id.tv_recent_unread); bmobUserManager.queryUserById( item.getTargetid(), new FindListener<BmobChatUser>() { @Override public void onSuccess(List<BmobChatUser> list) { if (!CollectionUtils.isNotNull(list)) return; String url = list.get(0).getAvatar(); String avatar = url; if (avatar != null && !avatar.equals("")) { ImageLoader.getInstance() .displayImage(avatar, iv_recent_avatar, ImageLoadOptions.getOptions()); } else { iv_recent_avatar.setImageResource(R.mipmap.ic_launcher); } } @Override public void onError(int i, String s) {} }); tv_recent_name.setText(item.getNick()); tv_recent_time.setText(TimeUtil.getChatTime(item.getTime())); // 显示内容 if (item.getType() == BmobConfig.TYPE_TEXT) { SpannableString spannableString = FaceTextUtils.toSpannableString(mContext, item.getMessage()); tv_recent_msg.setText(spannableString); } else if (item.getType() == BmobConfig.TYPE_IMAGE) { tv_recent_msg.setText("[图片]"); } else if (item.getType() == BmobConfig.TYPE_LOCATION) { String all = item.getMessage(); if (TextUtils.isEmpty(all)) { // 位置类型的信息组装格式:地理位置&维度&经度 String address = all.split("&")[0]; tv_recent_msg.setText("[位置]" + address); } } else if (item.getType() == BmobConfig.TYPE_VOICE) { tv_recent_msg.setText("[语音]"); } int num = BmobDB.create(mContext).getUnreadCount(item.getTargetid()); if (num > 0) { tv_recent_unread.setVisibility(View.VISIBLE); tv_recent_unread.setText(num + ""); } else { tv_recent_unread.setVisibility(View.GONE); } return convertView; }
/** * 删除会话 deleteRecent * * @param recent * @return void */ private void deleteRecent(BmobRecent recent) { adapter.remove(recent); BmobDB.create(this).deleteRecent(recent.getTargetid()); BmobDB.create(this).deleteMessages(recent.getTargetid()); }
private void deleteRecent(BmobRecent recent) { mMessageRecentAdapter.remove(recent); BmobDB.create(getActivity()).deleteRecent(recent.getTargetid()); BmobDB.create(getActivity()).deleteMessages(recent.getTargetid()); }