Commit f0294026 by 霍志良

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

parent 4219dd24
......@@ -26,7 +26,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
ArrayList<QuestionItemBean> questionList = new ArrayList<QuestionItemBean>();
Integer maxItemSize = 6;
Integer maxItemSize = 5;
Boolean isSingleChoice=true;
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
......@@ -38,7 +38,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_which_question;
return R.layout.im_nim_lingxi_multiple_choice;
case 2://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice;
case 3://您是先生还是女生
......@@ -60,9 +61,9 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
//您想要咨询下列哪类的问题?(单选)
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
// adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
for (int i=0;i<8;i++){
questionList.add(new QuestionItemBean("1","婚姻情感",false));
questionList.add(new QuestionItemBean("1","婚姻情感",false));
}
adapterLingxiWhichQuestion.setTagData(questionList);
adapterLingxiWhichQuestion.setItemListener(this);
......@@ -74,14 +75,15 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
//请问是发生了什么事情导致的呢?(多选)
// adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
//// adapterLingxiMultipleChoice.setTagData(questionList);
// GridLayoutManager multipleChoiceManager = new GridLayoutManager(context, 2);
// //当list中字段大于6个显示单行,否则显示双行
// multipleChoiceManager.setSpanCount(maxItemSize > 6 ? 1 : 2);
// multipleChoiceManager.setOrientation(GridLayoutManager.VERTICAL);
// recycleviewWhichQuestion.setLayoutManager(multipleChoiceManager);
// recycleviewWhichQuestion.setAdapter(adapterLingxiMultipleChoice);
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
adapterLingxiMultipleChoice.setTagData(questionList);
adapterLingxiMultipleChoice.setItemListener(this);
GridLayoutManager multipleChoiceManager = new GridLayoutManager(context, 2);
//当list中字段大于6个显示单行,否则显示双行
multipleChoiceManager.setSpanCount(maxItemSize > 6 ? 1 : 2);
multipleChoiceManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager);
recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice);
}
......@@ -95,8 +97,18 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override
public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) {
ToastUtil.toastShort("多选点击了" + position);
//多选发送消息
for (int i=0;i<questionList.size();i++){
if (questionList.get(i).isSelected()){
if (i==position){
questionList.get(i).setSelected(false);
}
}else{
if (i==position){
questionList.get(i).setSelected(true);
}
}
}
adapterLingxiMultipleChoice.setTagData(questionList);
}
}
......@@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.yidianling.im.R
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
import com.yidianling.im.session.viewholder.bean.QuestionItemBean
......@@ -17,12 +18,12 @@ import com.yidianling.im.session.viewholder.bean.QuestionItemBean
* @date 2021/6/21
*/
class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleChoice.ViewHolder>() {
private lateinit var tagList: List<String>
private lateinit var tagList: List<QuestionItemBean>
private var onItemClickListener: OnMultiplelItemClickListener? = null
class ViewHolder(itemView: View) :
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 {
......@@ -40,23 +41,22 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// holder.tv_which_question.setText("")
// holder.tv_which_question.setOnClickListener {
// onItemClickListener?.onMultipleItemClick(
// LingxiWhichQuestionBean(
// isSelected = true,
// xquestionPaperId = "0",
// xquestionPaperName = "l",
// questionId = "1",
// questionTitle = "1",
// selectType = "1",
// selectVals = listOf<QuestionItemBean>(QuestionItemBean(id = "1",name = "2"))
// ), position
// )
// }
holder.tvWhichQuestion.text=tagList[position].name
holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onMultipleItemClick(
tagList[position], position
)
}
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))
}else{
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))
}
}
fun setTagData(data: List<String>) {
fun setTagData(data: List<QuestionItemBean>) {
tagList = data
notifyDataSetChanged()
}
......@@ -64,4 +64,7 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
interface OnMultiplelItemClickListener {
fun onMultipleItemClick(string: QuestionItemBean, position: Int)
}
fun setItemListener(listener: OnMultiplelItemClickListener) {
this.onItemClickListener = listener
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="260dp"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/im_custom_message_round_white_6dp_bg"
android:paddingLeft="@dimen/platform_dp_12"
android:paddingRight="@dimen/platform_dp_3"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/which_question_title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:text="您想要咨询下类哪类问题?"
android:textSize="@dimen/im_text_size_17"
android:textColor="@color/im_color_242424"
>
</TextView>
android:background="@drawable/im_custom_message_round_white_6dp_bg"
android:paddingLeft="@dimen/platform_dp_12"
android:paddingRight="@dimen/platform_dp_3">
<TextView
android:id="@+id/which_question_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/im_color_242424"
android:textSize="@dimen/im_text_size_17"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="您想要咨询下类哪类问题?" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/which_question_rv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/platform_dp_16"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/which_question_title"
app:layout_constraintStart_toStartOf="@id/which_question_title"
tools:itemCount="6"
app:spanCount="2"
tools:listitem="@layout/im_lingxi_which_question_item"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:layout_marginBottom="@dimen/platform_dp_16"
app:layout_constraintBottom_toBottomOf="parent"
/>
app:layout_constraintStart_toStartOf="@id/which_question_title"
app:layout_constraintTop_toBottomOf="@id/which_question_title"
app:spanCount="2"
tools:itemCount="6"
tools:listitem="@layout/im_lingxi_which_question_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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