// 删除关注提示 public void addOrDeleteFriendsAlert(final int index) { FriendModel friend = dataList.get(index); // 取消关注或者关注 if (friend.isOrHasAttent()) { final CustomAlertDialog confirmDialog = new CustomAlertDialog(this, "确定要取消关注“" + friend.getName() + "”吗?", "确定", "取消"); confirmDialog.show(); confirmDialog.setClicklistener( new CustomAlertDialog.ClickListenerInterface() { @Override public void doConfirm() { deleteFriendConfirm(index); confirmDialog.dismiss(); } @Override public void doCancel() { confirmDialog.dismiss(); } }); } else { addFriendConfirm(index); } }
// 数据模型转换 private void jsonToPersonData(JSONArray jPersonList) { List<FriendModel> list = new ArrayList<FriendModel>(); for (int index = 0; index < jPersonList.size(); index++) { JSONObject jsonObject = jPersonList.getJSONObject(index); FriendModel friend = new FriendModel(); friend.setUid(JLXCUtils.stringToInt(jsonObject.getString("uid"))); friend.setName(jsonObject.getString("name")); friend.setHead_image(jsonObject.getString("head_image")); friend.setHead_sub_image(jsonObject.getString("head_sub_image")); friend.setSchool(jsonObject.getString("school")); if ("0".equals(jsonObject.getString("isAttent"))) { friend.setOrHasAttent(false); } else { friend.setOrHasAttent(true); } list.add(friend); } if (isPullDown) { dataList = list; friendAdapter.replaceAll(dataList); } else { dataList.addAll(list); friendAdapter.replaceAll(dataList); } if (null != jPersonList) { jPersonList.clear(); } }
// 关注别人 private void addFriendConfirm(int index) { final FriendModel friend = dataList.get(index); // 参数设置 RequestParams params = new RequestParams(); params.addBodyParameter("user_id", UserManager.getInstance().getUser().getUid() + ""); params.addBodyParameter("friend_id", friend.getUid() + ""); // showLoading("添加中^_^", false); HttpManager.post( JLXCConst.Add_FRIEND, params, new JsonRequestCallBack<String>( new LoadDataHandler<String>() { @Override public void onSuccess(JSONObject jsonResponse, String flag) { super.onSuccess(jsonResponse, flag); hideLoading(); int status = jsonResponse.getInteger(JLXCConst.HTTP_STATUS); ToastUtil.show( OtherAttentOrFansActivity.this, jsonResponse.getString(JLXCConst.HTTP_MESSAGE)); if (status == JLXCConst.STATUS_SUCCESS) { // 本地数据持久化 IMModel imModel = new IMModel(); imModel.setTargetId(JLXCConst.JLXC + friend.getUid()); imModel.setAvatarPath(friend.getHead_image()); imModel.setTitle(friend.getName()); MessageAddFriendHelper.addFriend(imModel); friend.setOrHasAttent(true); friendAdapter.replaceAll(dataList); } } @Override public void onFailure(HttpException arg0, String arg1, String flag) { super.onFailure(arg0, arg1, flag); hideLoading(); ToastUtil.show(OtherAttentOrFansActivity.this, "网络异常"); } }, null)); }
private void deleteFriendConfirm(int index) { final FriendModel friend = dataList.get(index); // 参数设置 RequestParams params = new RequestParams(); params.addBodyParameter("user_id", UserManager.getInstance().getUser().getUid() + ""); params.addBodyParameter("friend_id", friend.getUid() + ""); showLoading("取消中..", false); HttpManager.post( JLXCConst.DELETE_FRIEND, params, new JsonRequestCallBack<String>( new LoadDataHandler<String>() { @Override public void onSuccess(JSONObject jsonResponse, String flag) { super.onSuccess(jsonResponse, flag); hideLoading(); int status = jsonResponse.getInteger(JLXCConst.HTTP_STATUS); ToastUtil.show( OtherAttentOrFansActivity.this, jsonResponse.getString(JLXCConst.HTTP_MESSAGE)); if (status == JLXCConst.STATUS_SUCCESS) { RongIMClient.getInstance() .removeConversation( ConversationType.PRIVATE, JLXCConst.JLXC + friend.getUid(), null); friend.setOrHasAttent(false); // UI变化 friendAdapter.replaceAll(dataList); } } @Override public void onFailure(HttpException arg0, String arg1, String flag) { super.onFailure(arg0, arg1, flag); hideLoading(); } }, null)); }