Commit 631307b0 by 霍志良

feat:im-灵犀2.0-多选UI完成

parent a076cb9c
...@@ -8,6 +8,7 @@ import com.yidianling.common.tools.ToastUtil; ...@@ -8,6 +8,7 @@ import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion; import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion;
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.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.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter; import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
...@@ -17,9 +18,12 @@ import org.jetbrains.annotations.NotNull; ...@@ -17,9 +18,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener { public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener, AdapterLingxiMultipleChoice.OnMultiplelItemClickListener {
private RecyclerView recycleviewWhichQuestion; private RecyclerView recycleviewWhichQuestion;
private RecyclerView recycleviewMultipleChoice;
private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion; private AdapterLingxiWhichQuestion adapterLingxiWhichQuestion;
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
ArrayList<String> questionList = new ArrayList<String>(); ArrayList<String> questionList = new ArrayList<String>();
Integer maxItemSize = 6; Integer maxItemSize = 6;
Boolean isSingleChoice=true; Boolean isSingleChoice=true;
...@@ -47,6 +51,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -47,6 +51,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
protected void inflateContentView() { protected void inflateContentView() {
recycleviewWhichQuestion = findViewById(R.id.which_question_rv); recycleviewWhichQuestion = findViewById(R.id.which_question_rv);
recycleviewMultipleChoice = findViewById(R.id.multiple_question_rv);
} }
...@@ -58,21 +63,39 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -58,21 +63,39 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
questionList.add("aaa"); questionList.add("aaa");
questionList.add("aaa"); questionList.add("aaa");
questionList.add("aaa"); questionList.add("aaa");
//您想要咨询下列哪类的问题?(单选)
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion(); adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
adapterLingxiWhichQuestion.setTagData(questionList); adapterLingxiWhichQuestion.setTagData(questionList);
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);
gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewWhichQuestion.setLayoutManager(gridLayoutManager); recycleviewWhichQuestion.setLayoutManager(gridLayoutManager);
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion); 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);
} }
@Override @Override
public void onItemClick(@NotNull LingxiWhichQuestionBean string, int position) { public void onItemClick(@NotNull LingxiWhichQuestionBean string, int position) {
ToastUtil.toastShort("点击了" + position); ToastUtil.toastShort("单选点击了" + position);
//todo发送消息 //todo发送消息
} }
@Override
public void onMultipleItemClick(@NotNull LingxiWhichQuestionBean string, int position) {
ToastUtil.toastShort("多选点击了" + position);
//多选发送消息
}
} }
package com.yidianling.im.session.viewholder.adapter
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.yidianling.im.R
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean
/**
* @author huozhiliang
* @描述:
* @Copyright Copyright (c) 2018
* @Company 壹点灵
* @date 2021/6/21
*/
class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleChoice.ViewHolder>() {
private lateinit var tagList:List<String>
private var onItemClickListener: OnMultiplelItemClickListener? = null
class ViewHolder(itemView: View) :
RecyclerView.ViewHolder(itemView) {
val tv_which_question: TextView = itemView.findViewById(R.id.tv_which_question)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.im_lingxi_which_question_item,
parent,
false
)
)
}
override fun getItemCount(): Int {
return tagList.size?:0
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// holder.tv_which_question.setText("")
holder.tv_which_question.setOnClickListener {
onItemClickListener?.onMultipleItemClick(
LingxiWhichQuestionBean(
true,
"aa",
"aaa"
),position)
}
}
fun setTagData(data: List<String>) {
tagList = data
notifyDataSetChanged()
}
interface OnMultiplelItemClickListener {
fun onMultipleItemClick(string: LingxiWhichQuestionBean, position: Int)
}
}
\ 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