Commit 5d070de9 by 霍志良

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

parent a358fcc2
...@@ -2,6 +2,7 @@ package com.yidianling.im.session.extension; ...@@ -2,6 +2,7 @@ package com.yidianling.im.session.extension;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; 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.LingxiWhichQuestionBean;
import com.yidianling.im.session.viewholder.bean.QuestionItemBean; import com.yidianling.im.session.viewholder.bean.QuestionItemBean;
import com.yidianling.uikit.custom.http.response.RecommendExpertBean; import com.yidianling.uikit.custom.http.response.RecommendExpertBean;
...@@ -36,6 +37,7 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment { ...@@ -36,6 +37,7 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
this.questionId = data.getString(QUESTIONID); this.questionId = data.getString(QUESTIONID);
this.questionTitle = data.getString(QUESTIONTITLE); this.questionTitle = data.getString(QUESTIONTITLE);
this.selectType = data.getString(SELECTTYPE); this.selectType = data.getString(SELECTTYPE);
LogUtil.e("aaaaa"+data.getString(SELECTVALS));
this.selectVals=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(SELECTVALS), QuestionItemBean.class); this.selectVals=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(SELECTVALS), QuestionItemBean.class);
} }
...@@ -51,4 +53,5 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment { ...@@ -51,4 +53,5 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
data.put(SELECTVALS, selectVals); data.put(SELECTVALS, selectVals);
return data; return data;
} }
} }
...@@ -2,15 +2,23 @@ package com.yidianling.im.session.viewholder; ...@@ -2,15 +2,23 @@ package com.yidianling.im.session.viewholder;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; 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.LogUtil;
import com.yidianling.common.tools.ToastUtil; import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.event.MultipleSelectedEvent; import com.yidianling.im.event.MultipleSelectedEvent;
import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion; 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.extension.CustomAttachmentOrderStatus;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiMultipleChoice; import com.yidianling.im.session.viewholder.adapter.AdapterLingxiMultipleChoice;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiWhichQuestion; import com.yidianling.im.session.viewholder.adapter.AdapterLingxiWhichQuestion;
...@@ -22,6 +30,9 @@ import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase; ...@@ -22,6 +30,9 @@ import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
...@@ -29,6 +40,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -29,6 +40,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private RecyclerView recycleviewWhichQuestion; private RecyclerView recycleviewWhichQuestion;
private RecyclerView recycleviewMultipleChoice; private RecyclerView recycleviewMultipleChoice;
private TextView confirm_multiple_choice; private TextView confirm_multiple_choice;
private TextView which_question_title;
private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion; private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion;
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice; private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
...@@ -37,6 +50,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -37,6 +50,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion; CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
private StringBuffer stringBuffer=new StringBuffer("已选:"); private StringBuffer stringBuffer=new StringBuffer("已选:");
ArrayList<String> selectedStr=new ArrayList<String>(); ArrayList<String> selectedStr=new ArrayList<String>();
private Boolean isClickable=true;
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) { public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter); super(adapter);
} }
...@@ -46,8 +60,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -46,8 +60,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){ switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){
case 1://您想要咨询下列哪类的问题?(单选) case 1://您想要咨询下列哪类的问题?(单选)
// return R.layout.im_nim_lingxi_which_question; return R.layout.im_nim_lingxi_which_question;
return R.layout.im_nim_lingxi_multiple_choice; // return R.layout.im_nim_lingxi_multiple_choice;
case 2://请问是发生了什么事情导致的呢?(多选) case 2://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice; return R.layout.im_nim_lingxi_multiple_choice;
case 3://您是先生还是女生 case 3://您是先生还是女生
...@@ -62,6 +76,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -62,6 +76,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewWhichQuestion = findViewById(R.id.which_question_rv); recycleviewWhichQuestion = findViewById(R.id.which_question_rv);
recycleviewMultipleChoice = findViewById(R.id.multiple_question_rv); recycleviewMultipleChoice = findViewById(R.id.multiple_question_rv);
confirm_multiple_choice = findViewById(R.id.confirm_multiple_choice); confirm_multiple_choice = findViewById(R.id.confirm_multiple_choice);
which_question_title = findViewById(R.id.which_question_title);
} }
...@@ -69,27 +84,30 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -69,27 +84,30 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
protected void bindContentView() { protected void bindContentView() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
//您想要咨询下列哪类的问题?(单选) //您想要咨询下列哪类的问题?(单选)
if (customAttachLingxiWhichQuestion.selectVals!=null){
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion(); questionList= (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.selectVals;
for (int i=0;i<8;i++){
questionList.add(new QuestionItemBean("1","婚姻情感试"+i,false));
} }
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
which_question_title.setText(customAttachLingxiWhichQuestion.xquestionPaperName);
for (int i=0;i<questionList.size();i++){ 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; isSingleChoice=true;
break; break;
} }
} }
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){ switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){
case 1://您想要咨询下列哪类的问题?(单选) case 1://您想要咨询下列哪类的问题?(单选)
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice); if (questionList!=null&&questionList.size()!=0){
adapterLingxiWhichQuestion.setItemListener(this); adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2); adapterLingxiWhichQuestion.setItemListener(this);
//当list中字段大于6个显示单行,否则显示双行 GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
gridLayoutManager.setSpanCount(isSingleChoice ? 1 : 2); //当list中字段大于6个显示单行,否则显示双行
gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL); gridLayoutManager.setSpanCount(isSingleChoice ? 1 : 2);
recycleviewWhichQuestion.setLayoutManager(gridLayoutManager); gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion); recycleviewWhichQuestion.setLayoutManager(gridLayoutManager);
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
}
break; break;
case 2://请问是发生了什么事情导致的呢?(多选) case 2://请问是发生了什么事情导致的呢?(多选)
// //请问是发生了什么事情导致的呢?(多选) // //请问是发生了什么事情导致的呢?(多选)
...@@ -108,17 +126,45 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -108,17 +126,45 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
default: default:
break; 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 @Override
public void onItemClick(@NotNull QuestionItemBean itemBean, int position) { public void onItemClick(@NotNull QuestionItemBean itemBean, int position) {
for (int i=0;i<questionList.size();i++){ if (isClickable){
questionList.get(i).setSelected(i==position); for (int i=0;i<questionList.size();i++){
questionList.get(i).setSelected(i==position);
}
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
isClickable=false;
//请求接口发送所选题目
updateLocalMsg(position);
} }
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
} }
@Override @Override
...@@ -128,12 +174,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -128,12 +174,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (questionList.get(i).isSelected()){ if (questionList.get(i).isSelected()){
if (i==position){ if (i==position){
questionList.get(i).setSelected(false); questionList.get(i).setSelected(false);
selectedStr.remove(questionList.get(i).getName()); selectedStr.remove(questionList.get(i).getValue());
} }
}else{ }else{
if (i==position){ if (i==position){
questionList.get(i).setSelected(true); 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 ...@@ -145,6 +191,55 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString())); EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString()));
adapterLingxiMultipleChoice.setTagData(questionList); 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 ...@@ -41,7 +41,7 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text=tagList[position].name holder.tvWhichQuestion.text=tagList[position].value
holder.tvWhichQuestion.setOnClickListener { holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onMultipleItemClick( onItemClickListener?.onMultipleItemClick(
tagList[position], position tagList[position], position
......
...@@ -23,7 +23,6 @@ import kotlin.properties.Delegates ...@@ -23,7 +23,6 @@ import kotlin.properties.Delegates
class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuestion.ViewHolder>() { class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuestion.ViewHolder>() {
private lateinit var tagList:List<QuestionItemBean> private lateinit var tagList:List<QuestionItemBean>
private var isSingleOrMultiple by Delegates.notNull<Boolean>() private var isSingleOrMultiple by Delegates.notNull<Boolean>()
private var onItemClickListener: OnQuestionlItemClickListener? = null private var onItemClickListener: OnQuestionlItemClickListener? = null
class ViewHolder(itemView: View) : class ViewHolder(itemView: View) :
...@@ -46,7 +45,7 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti ...@@ -46,7 +45,7 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text = tagList[position].name holder.tvWhichQuestion.text = tagList[position].value
if (tagList[position].isSelected!!){ if (tagList[position].isSelected!!){
holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_1da1f2) 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)) holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.white))
...@@ -54,10 +53,10 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti ...@@ -54,10 +53,10 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_e8f5fe) holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_e8f5fe)
holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.platform_color_1DA1F2)) holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.platform_color_1DA1F2))
} }
holder.tvWhichQuestion.setOnClickListener { holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onItemClick( onItemClickListener?.onItemClick(
tagList[position],position) tagList[position],position)
} }
if(isSingleOrMultiple){ if(isSingleOrMultiple){
holder.tvWhichQuestion.setPadding(RxImageTool.dip2px(62f),RxImageTool.dp2px(8f),RxImageTool.dip2px(62f),RxImageTool.dp2px(8f)) holder.tvWhichQuestion.setPadding(RxImageTool.dip2px(62f),RxImageTool.dp2px(8f),RxImageTool.dip2px(62f),RxImageTool.dp2px(8f))
} }
......
...@@ -13,6 +13,6 @@ data class LingxiWhichQuestionBean( ...@@ -13,6 +13,6 @@ data class LingxiWhichQuestionBean(
) )
data class QuestionItemBean( data class QuestionItemBean(
var id:String?, var id:String?,
var name:String?, var value:String?,
var isSelected: Boolean?=false 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