Commit 5d070de9 by 霍志良

feat:im-灵犀2.0-更新本地消息

parent a358fcc2
......@@ -2,6 +2,7 @@ package com.yidianling.im.session.extension;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean;
import com.yidianling.im.session.viewholder.bean.QuestionItemBean;
import com.yidianling.uikit.custom.http.response.RecommendExpertBean;
......@@ -36,6 +37,7 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
this.questionId = data.getString(QUESTIONID);
this.questionTitle = data.getString(QUESTIONTITLE);
this.selectType = data.getString(SELECTTYPE);
LogUtil.e("aaaaa"+data.getString(SELECTVALS));
this.selectVals=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(SELECTVALS), QuestionItemBean.class);
}
......@@ -51,4 +53,5 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
data.put(SELECTVALS, selectVals);
return data;
}
}
......@@ -2,15 +2,23 @@ package com.yidianling.im.session.viewholder;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.RequestCallback;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.event.MultipleSelectedEvent;
import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion;
import com.yidianling.im.session.extension.CustomAttachmentConfirmOrder;
import com.yidianling.im.session.extension.CustomAttachmentOrderStatus;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiMultipleChoice;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiWhichQuestion;
......@@ -22,6 +30,9 @@ import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.greenrobot.event.EventBus;
......@@ -29,6 +40,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private RecyclerView recycleviewWhichQuestion;
private RecyclerView recycleviewMultipleChoice;
private TextView confirm_multiple_choice;
private TextView which_question_title;
private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion;
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
......@@ -37,6 +50,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
private StringBuffer stringBuffer=new StringBuffer("已选:");
ArrayList<String> selectedStr=new ArrayList<String>();
private Boolean isClickable=true;
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter);
}
......@@ -46,8 +60,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){
case 1://您想要咨询下列哪类的问题?(单选)
// return R.layout.im_nim_lingxi_which_question;
return R.layout.im_nim_lingxi_multiple_choice;
return R.layout.im_nim_lingxi_which_question;
// return R.layout.im_nim_lingxi_multiple_choice;
case 2://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice;
case 3://您是先生还是女生
......@@ -62,6 +76,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewWhichQuestion = findViewById(R.id.which_question_rv);
recycleviewMultipleChoice = findViewById(R.id.multiple_question_rv);
confirm_multiple_choice = findViewById(R.id.confirm_multiple_choice);
which_question_title = findViewById(R.id.which_question_title);
}
......@@ -69,19 +84,21 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
protected void bindContentView() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
//您想要咨询下列哪类的问题?(单选)
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
for (int i=0;i<8;i++){
questionList.add(new QuestionItemBean("1","婚姻情感试"+i,false));
if (customAttachLingxiWhichQuestion.selectVals!=null){
questionList= (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.selectVals;
}
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
which_question_title.setText(customAttachLingxiWhichQuestion.xquestionPaperName);
for (int i=0;i<questionList.size();i++){
if (questionList.get(i).getName().length()>5){
questionList.get(i).setSelected(false);
if (questionList.get(i).getValue().length()>5){
isSingleChoice=true;
break;
}
}
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){
case 1://您想要咨询下列哪类的问题?(单选)
if (questionList!=null&&questionList.size()!=0){
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
adapterLingxiWhichQuestion.setItemListener(this);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
......@@ -90,6 +107,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewWhichQuestion.setLayoutManager(gridLayoutManager);
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
}
break;
case 2://请问是发生了什么事情导致的呢?(多选)
// //请问是发生了什么事情导致的呢?(多选)
......@@ -108,17 +126,45 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
default:
break;
}
try {
Map<String, Object> map = message.getLocalExtension();
if (map != null) {
Object obj = map.get("isSure");
Object position = map.get("position");
if (obj != null) {
boolean b = (boolean) obj;
Integer posi=(Integer) position;
if (b) {
//不可点击
isClickable=false;
questionList.get(posi).setSelected(true);
}
} else {
//可点击
}
} else {
//可点击
}
} catch (Exception e) {
}
}
@Override
public void onItemClick(@NotNull QuestionItemBean itemBean, int position) {
if (isClickable){
for (int i=0;i<questionList.size();i++){
questionList.get(i).setSelected(i==position);
}
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
isClickable=false;
//请求接口发送所选题目
updateLocalMsg(position);
}
}
@Override
......@@ -128,12 +174,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (questionList.get(i).isSelected()){
if (i==position){
questionList.get(i).setSelected(false);
selectedStr.remove(questionList.get(i).getName());
selectedStr.remove(questionList.get(i).getValue());
}
}else{
if (i==position){
questionList.get(i).setSelected(true);
selectedStr.add(questionList.get(i).getName());
selectedStr.add(questionList.get(i).getValue());
}
}
}
......@@ -145,6 +191,55 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString()));
adapterLingxiMultipleChoice.setTagData(questionList);
}
private void updateLocalMsg(Integer position) {
//更新本地消息
Map<String, Object> map = message.getLocalExtension();
if (map == null) {
map = new HashMap();
}
map.put("isSure", true);
map.put("position", position);
message.setLocalExtension(map);
NIMClient.getService(MsgService.class).updateIMMessage(message);
//同时更新历史同订单未确认的消息状态
NIMClient.getService(MsgService.class).queryMessageList(message.getSessionId(), SessionTypeEnum.P2P, 0, 100).setCallback(new RequestCallback<List<IMMessage>>() {
@Override
public void onSuccess(List<IMMessage> param) {
if (param != null && param.size() > 0) {
for (IMMessage msg : param) {
MsgAttachment attachment = msg.getAttachment();
if (attachment instanceof CustomAttachLingxiWhichQuestion) {
CustomAttachLingxiWhichQuestion customattachlingxiwhichquestion = (CustomAttachLingxiWhichQuestion) attachment;
// if (customattachlingxiwhichquestion) {
//已经筛选过答案
//修改历史消息状态为已失效
Map map1 = msg.getLocalExtension();
if (map1 == null) {
map1 = new HashMap();
map1.put("isExpired", true);
map1.put("position", position);
msg.setLocalExtension(map1);
NIMClient.getService(MsgService.class).updateIMMessage(msg);
//通知ui刷新
getMsgAdapter().updateItemAtLocalExtension(msg);
}
// }
}
}
}
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
}
}
......@@ -41,7 +41,7 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text=tagList[position].name
holder.tvWhichQuestion.text=tagList[position].value
holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onMultipleItemClick(
tagList[position], position
......
......@@ -23,7 +23,6 @@ import kotlin.properties.Delegates
class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuestion.ViewHolder>() {
private lateinit var tagList:List<QuestionItemBean>
private var isSingleOrMultiple by Delegates.notNull<Boolean>()
private var onItemClickListener: OnQuestionlItemClickListener? = null
class ViewHolder(itemView: View) :
......@@ -46,7 +45,7 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text = tagList[position].name
holder.tvWhichQuestion.text = tagList[position].value
if (tagList[position].isSelected!!){
holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_1da1f2)
holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.white))
......
......@@ -13,6 +13,6 @@ data class LingxiWhichQuestionBean(
)
data class QuestionItemBean(
var id:String?,
var name:String?,
var value:String?,
var isSelected: Boolean?=false
)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment