Commit 69d2343d by 霍志良

feat:im-灵犀2.0-多选逻辑

parent f0294026
...@@ -26,8 +26,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -26,8 +26,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice; private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
ArrayList<QuestionItemBean> questionList = new ArrayList<QuestionItemBean>(); ArrayList<QuestionItemBean> questionList = new ArrayList<QuestionItemBean>();
Integer maxItemSize = 5; Boolean isSingleChoice=false;
Boolean isSingleChoice=true;
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion; CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) { public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter); super(adapter);
...@@ -38,8 +37,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -38,8 +37,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://您是先生还是女生
...@@ -61,29 +60,35 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -61,29 +60,35 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
//您想要咨询下列哪类的问题?(单选) //您想要咨询下列哪类的问题?(单选)
// adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion(); adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
for (int i=0;i<8;i++){ for (int i=0;i<8;i++){
questionList.add(new QuestionItemBean("1","婚姻情感试",false)); questionList.add(new QuestionItemBean("1","婚姻情感试",false));
} }
adapterLingxiWhichQuestion.setTagData(questionList); for (int i=0;i<questionList.size();i++){
if (questionList.get(i).getName().length()>5){
isSingleChoice=true;
break;
}
}
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
adapterLingxiWhichQuestion.setItemListener(this); 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(isSingleChoice ? 1 : 2);
gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL); gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewWhichQuestion.setLayoutManager(gridLayoutManager); recycleviewWhichQuestion.setLayoutManager(gridLayoutManager);
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion); recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
//请问是发生了什么事情导致的呢?(多选) // //请问是发生了什么事情导致的呢?(多选)
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice(); // adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
adapterLingxiMultipleChoice.setTagData(questionList); // adapterLingxiMultipleChoice.setTagData(questionList);
adapterLingxiMultipleChoice.setItemListener(this); // adapterLingxiMultipleChoice.setItemListener(this);
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);
recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager); // recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager);
recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice); // recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice);
} }
...@@ -92,7 +97,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -92,7 +97,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
for (int i=0;i<questionList.size();i++){ for (int i=0;i<questionList.size();i++){
questionList.get(i).setSelected(i==position); questionList.get(i).setSelected(i==position);
} }
adapterLingxiWhichQuestion.setTagData(questionList); adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
} }
@Override @Override
......
...@@ -6,9 +6,12 @@ import android.view.View ...@@ -6,9 +6,12 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.ydl.ydlcommon.data.http.RxUtils
import com.yidianling.common.tools.RxImageTool
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 import com.yidianling.im.session.viewholder.bean.QuestionItemBean
import kotlin.properties.Delegates
/** /**
* @author huozhiliang * @author huozhiliang
...@@ -19,6 +22,8 @@ import com.yidianling.im.session.viewholder.bean.QuestionItemBean ...@@ -19,6 +22,8 @@ import com.yidianling.im.session.viewholder.bean.QuestionItemBean
*/ */
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 onItemClickListener: OnQuestionlItemClickListener? = null private var onItemClickListener: OnQuestionlItemClickListener? = null
class ViewHolder(itemView: View) : class ViewHolder(itemView: View) :
...@@ -53,9 +58,13 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti ...@@ -53,9 +58,13 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
onItemClickListener?.onItemClick( onItemClickListener?.onItemClick(
tagList[position],position) tagList[position],position)
} }
if(isSingleOrMultiple){
holder.tvWhichQuestion.setPadding(RxImageTool.dip2px(62f),RxImageTool.dp2px(8f),RxImageTool.dip2px(62f),RxImageTool.dp2px(8f))
}
} }
fun setTagData(data: List<QuestionItemBean>) { fun setTagData(data: List<QuestionItemBean>,isSingleOrMultiple:Boolean) {
tagList = data tagList = data
this.isSingleOrMultiple=isSingleOrMultiple
notifyDataSetChanged() notifyDataSetChanged()
} }
interface OnQuestionlItemClickListener { interface OnQuestionlItemClickListener {
......
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