Commit c843762f by 霍志良

feat:im-灵犀2.0-Json字段调整

parent 604a6502
package com.yidianling.im.session.extension; package com.yidianling.im.session.extension;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean;
import com.yidianling.im.session.viewholder.bean.QuestionItemBean;
import com.yidianling.uikit.custom.http.response.RecommendExpertBean;
import java.util.ArrayList;
import java.util.List;
public class CustomAttachLingxiWhichQuestion extends CustomAttachment { public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
private final String XQUESTIONPAPERID = "xquestionPaperId";//试卷id private final String XQUESTIONPAPERID = "xquestionPaperId";//试卷id
...@@ -11,12 +18,12 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment { ...@@ -11,12 +18,12 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
private final String SELECTVALS = "selectVals";//选项 private final String SELECTVALS = "selectVals";//选项
private String xquestionPaperId; public String xquestionPaperId;
private String xquestionPaperName; public String xquestionPaperName;
private String questionId; public String questionId;
private String questionTitle; public String questionTitle;
private String selectType; public String selectType;
private String selectVals; public List<QuestionItemBean> selectVals;
public CustomAttachLingxiWhichQuestion() { public CustomAttachLingxiWhichQuestion() {
super(CustomAttachmentType.TYPE_LINGXI_WHICH_QUESTION); super(CustomAttachmentType.TYPE_LINGXI_WHICH_QUESTION);
...@@ -25,6 +32,12 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment { ...@@ -25,6 +32,12 @@ public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
@Override @Override
protected void parseData(JSONObject data) { protected void parseData(JSONObject data) {
this.xquestionPaperId = data.getString(XQUESTIONPAPERID); this.xquestionPaperId = data.getString(XQUESTIONPAPERID);
this.xquestionPaperName = data.getString(XQUESTIONPAPERNAME);
this.questionId = data.getString(QUESTIONID);
this.questionTitle = data.getString(QUESTIONTITLE);
this.selectType = data.getString(SELECTTYPE);
this.selectVals=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(SELECTVALS), QuestionItemBean.class);
} }
@Override @Override
......
...@@ -11,6 +11,7 @@ import com.yidianling.im.session.extension.CustomAttachmentOrderStatus; ...@@ -11,6 +11,7 @@ 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;
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.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter; import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase; import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
...@@ -24,17 +25,18 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -24,17 +25,18 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion; private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion;
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice; private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
ArrayList<String> questionList = new ArrayList<String>(); ArrayList<QuestionItemBean> questionList = new ArrayList<QuestionItemBean>();
Integer maxItemSize = 6; Integer maxItemSize = 6;
Boolean isSingleChoice=true; Boolean isSingleChoice=true;
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) { public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter); super(adapter);
} }
@Override @Override
protected int getContentResId() { protected int getContentResId() {
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
switch (customAttachLingxiWhichQuestion.getType()){ 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;
case 2://请问是发生了什么事情导致的呢?(多选) case 2://请问是发生了什么事情导致的呢?(多选)
...@@ -55,16 +57,15 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -55,16 +57,15 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
protected void bindContentView() { protected void bindContentView() {
questionList.add("aaa"); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
questionList.add("aaa");
questionList.add("aaa");
questionList.add("aaa");
questionList.add("aaa");
questionList.add("aaa");
//您想要咨询下列哪类的问题?(单选) //您想要咨询下列哪类的问题?(单选)
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion(); adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
for (int i=0;i<8;i++){
questionList.add(new QuestionItemBean("1","婚姻情感"));
}
adapterLingxiWhichQuestion.setTagData(questionList); adapterLingxiWhichQuestion.setTagData(questionList);
adapterLingxiWhichQuestion.setItemListener(this);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2); GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
//当list中字段大于6个显示单行,否则显示双行 //当list中字段大于6个显示单行,否则显示双行
gridLayoutManager.setSpanCount(maxItemSize > 6 ? 1 : 2); gridLayoutManager.setSpanCount(maxItemSize > 6 ? 1 : 2);
...@@ -73,19 +74,19 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -73,19 +74,19 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion); recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
//请问是发生了什么事情导致的呢?(多选) //请问是发生了什么事情导致的呢?(多选)
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice(); // adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
adapterLingxiMultipleChoice.setTagData(questionList); //// adapterLingxiMultipleChoice.setTagData(questionList);
GridLayoutManager multipleChoiceManager = new GridLayoutManager(context, 2); // GridLayoutManager multipleChoiceManager = new GridLayoutManager(context, 2);
//当list中字段大于6个显示单行,否则显示双行 // //当list中字段大于6个显示单行,否则显示双行
multipleChoiceManager.setSpanCount(maxItemSize > 6 ? 1 : 2); // multipleChoiceManager.setSpanCount(maxItemSize > 6 ? 1 : 2);
multipleChoiceManager.setOrientation(GridLayoutManager.VERTICAL); // multipleChoiceManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewWhichQuestion.setLayoutManager(multipleChoiceManager); // recycleviewWhichQuestion.setLayoutManager(multipleChoiceManager);
recycleviewWhichQuestion.setAdapter(adapterLingxiMultipleChoice); // recycleviewWhichQuestion.setAdapter(adapterLingxiMultipleChoice);
} }
@Override @Override
public void onItemClick(@NotNull LingxiWhichQuestionBean string, int position) { public void onItemClick(@NotNull QuestionItemBean string, int position) {
ToastUtil.toastShort("单选点击了" + position); ToastUtil.toastShort("单选点击了" + position);
//todo发送消息 //todo发送消息
...@@ -93,7 +94,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -93,7 +94,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
} }
@Override @Override
public void onMultipleItemClick(@NotNull LingxiWhichQuestionBean string, int position) { public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) {
ToastUtil.toastShort("多选点击了" + position); ToastUtil.toastShort("多选点击了" + position);
//多选发送消息 //多选发送消息
......
...@@ -7,6 +7,7 @@ import android.view.ViewGroup ...@@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import com.yidianling.im.R import com.yidianling.im.R
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
import com.yidianling.im.session.viewholder.bean.QuestionItemBean
/** /**
* @author huozhiliang * @author huozhiliang
...@@ -16,7 +17,7 @@ import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean ...@@ -16,7 +17,7 @@ import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
* @date 2021/6/21 * @date 2021/6/21
*/ */
class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleChoice.ViewHolder>() { class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleChoice.ViewHolder>() {
private lateinit var tagList:List<String> private lateinit var tagList: List<String>
private var onItemClickListener: OnMultiplelItemClickListener? = null private var onItemClickListener: OnMultiplelItemClickListener? = null
class ViewHolder(itemView: View) : class ViewHolder(itemView: View) :
...@@ -35,25 +36,32 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh ...@@ -35,25 +36,32 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return tagList.size?:0 return tagList.size ?: 0
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// holder.tv_which_question.setText("") // holder.tv_which_question.setText("")
holder.tv_which_question.setOnClickListener { // holder.tv_which_question.setOnClickListener {
onItemClickListener?.onMultipleItemClick( // onItemClickListener?.onMultipleItemClick(
LingxiWhichQuestionBean( // LingxiWhichQuestionBean(
true, // isSelected = true,
"aa", // xquestionPaperId = "0",
"aaa" // xquestionPaperName = "l",
),position) // questionId = "1",
} // questionTitle = "1",
// selectType = "1",
// selectVals = listOf<QuestionItemBean>(QuestionItemBean(id = "1",name = "2"))
// ), position
// )
// }
} }
fun setTagData(data: List<String>) { fun setTagData(data: List<String>) {
tagList = data tagList = data
notifyDataSetChanged() notifyDataSetChanged()
} }
interface OnMultiplelItemClickListener { interface OnMultiplelItemClickListener {
fun onMultipleItemClick(string: LingxiWhichQuestionBean, position: Int) fun onMultipleItemClick(string: QuestionItemBean, position: Int)
} }
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ import android.view.ViewGroup ...@@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import com.yidianling.im.R import com.yidianling.im.R
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
import com.yidianling.im.session.viewholder.bean.QuestionItemBean
/** /**
* @author huozhiliang * @author huozhiliang
...@@ -16,12 +17,12 @@ import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean ...@@ -16,12 +17,12 @@ import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
* @date 2021/6/21 * @date 2021/6/21
*/ */
class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuestion.ViewHolder>() { class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuestion.ViewHolder>() {
private lateinit var tagList:List<String> private lateinit var tagList:List<QuestionItemBean>
private var onItemClickListener: OnQuestionlItemClickListener? = null private var onItemClickListener: OnQuestionlItemClickListener? = null
class ViewHolder(itemView: View) : class ViewHolder(itemView: View) :
RecyclerView.ViewHolder(itemView) { RecyclerView.ViewHolder(itemView) {
val tv_which_question: TextView = itemView.findViewById(R.id.tv_which_question) val tvWhichQuestion: TextView = itemView.findViewById(R.id.tv_which_question)
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
...@@ -39,21 +40,20 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti ...@@ -39,21 +40,20 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// holder.tv_which_question.setText("") holder.tvWhichQuestion.text = tagList[position].name
holder.tv_which_question.setOnClickListener { holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onItemClick( onItemClickListener?.onItemClick(
LingxiWhichQuestionBean( tagList[position],position)
true,
"aa",
"aaa"
),position)
} }
} }
fun setTagData(data: List<String>) { fun setTagData(data: List<QuestionItemBean>) {
tagList = data tagList = data
notifyDataSetChanged() notifyDataSetChanged()
} }
interface OnQuestionlItemClickListener { interface OnQuestionlItemClickListener {
fun onItemClick(string: LingxiWhichQuestionBean, position: Int) fun onItemClick(string: QuestionItemBean, position: Int)
}
fun setItemListener(listener: OnQuestionlItemClickListener) {
this.onItemClickListener = listener
} }
} }
\ No newline at end of file
package com.yidianling.im.session.viewholder.bean package com.yidianling.im.session.viewholder.bean
data class LingxiWhichQuestionBean ( import com.google.gson.annotations.SerializedName
var isSelected:Boolean,
var name:String, data class LingxiWhichQuestionBean(
var id:String var isSelected: Boolean,
var xquestionPaperId: String?,//试卷ID
var xquestionPaperName: String?,//试卷名称
var questionId:String?,//问题ID
var questionTitle:String?,//问题题目
var selectType:String?,//试卷type 1单选 2多选
var selectVals:ArrayList<QuestionItemBean>?//选项
)
data class QuestionItemBean(
var id:String?,
var name:String?
) )
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="260dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
......
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