Commit 7a524767 by 霍志良

feat:im-灵犀2.0-其他选项

parent d3d0e5ec
package com.yidianling.im.event
import com.yidianling.im.router.ImIn.getUserInfo
import com.yidianling.im.session.viewholder.bean.AnswersItem
public class MultipleSelectedEvent (
val strSelected:String,
var othersState:OthersState
val strSelected:String?,
var othersState:OthersState?,
var multipleAnswerBean:MultipleAnswerBean?
)
data class OthersState(
var isOthers:Boolean,
var othersSelect:Boolean
)
data class MultipleAnswerBean(
var examId:String,
var questionPaperId:String,
var uid:String,
var questionId:String,
var answersItems:ArrayList<AnswersItem>,
var fromUid:String
)
\ No newline at end of file
......@@ -5,13 +5,17 @@ import android.widget.TextView;
import com.yidianling.im.R;
import com.yidianling.im.session.extension.CustomAttachLingxiAnswerQuestion;
import com.yidianling.im.session.viewholder.bean.QuestionItemBean;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
import java.util.ArrayList;
public class MsgViewHolderLingxiAnswerQuestion extends MsgViewHolderBase {
private TextView answer_question;
CustomAttachLingxiAnswerQuestion customattachLingxiAnswerQuestion;
private ArrayList<QuestionItemBean> itemBeans;
private StringBuffer sb;
public MsgViewHolderLingxiAnswerQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter);
}
......@@ -36,7 +40,21 @@ public class MsgViewHolderLingxiAnswerQuestion extends MsgViewHolderBase {
@Override
protected void bindContentView() {
customattachLingxiAnswerQuestion = ((CustomAttachLingxiAnswerQuestion) message.getAttachment());
answer_question.setText(customattachLingxiAnswerQuestion.answers.get(0).getName());
itemBeans=customattachLingxiAnswerQuestion.answers;
sb=new StringBuffer();
for (int i=0;i<itemBeans.size();i++){
if (i==(itemBeans.size()-1)&&itemBeans.get(i).getName().contains("其他")){
sb.append("#"+itemBeans.get(i).getName()+"\r\n ").append(itemBeans.get(i).getOther());
}else{
sb.append("#"+itemBeans.get(i).getName()+" ");
}
}
if (itemBeans.size()==1){
answer_question.setText(itemBeans.get(0).getName());
}else{
answer_question.setText(sb.toString());
}
}
}
......@@ -19,6 +19,7 @@ import com.ydl.ydlcommon.data.http.RxUtils;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.event.MultipleAnswerBean;
import com.yidianling.im.event.MultipleSelectedEvent;
import com.yidianling.im.event.OthersState;
import com.yidianling.im.http.ImRetrofitApi;
......@@ -58,38 +59,39 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private AdapterLingxiMultipleChoice adapterLingxiMultipleChoice;
ArrayList<QuestionItemBean> questionList = new ArrayList<QuestionItemBean>();
Boolean isSingleChoice=false;
Boolean isSingleChoice = false;
CustomAttachLingxiWhichQuestion customAttachLingxiWhichQuestion;
private StringBuffer stringBuffer=new StringBuffer("已选:");
ArrayList<String> selectedStr=new ArrayList<String>();
private Boolean isClickable=true;
private StringBuffer stringBuffer = new StringBuffer("已选:");
ArrayList<String> selectedStr = new ArrayList<String>();
private Boolean isClickable = true;
private Boolean isOthers;
//回答试卷接口
private String examId;
private String questionPaperId;
private String questionId;
private ArrayList<AnswersItem> answersItems=new ArrayList<>();
private ArrayList<AnswersItem> answersItems = new ArrayList<>();
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter);
}
@Override
protected int getContentResId() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
if (customAttachLingxiWhichQuestion.type!=null){
switch (customAttachLingxiWhichQuestion.type){
case "radio"://您想要咨询下列哪类的问题?(单选)
return R.layout.im_nim_lingxi_which_question;
case "check"://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice;
case "3"://您是先生还是女生
return R.layout.im_nim_lingxi_men_female;
default:
return R.layout.im_nim_lingxi_which_question;
}
}else{
return R.layout.im_nim_lingxi_which_question;
}
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
if (customAttachLingxiWhichQuestion.type != null) {
switch (customAttachLingxiWhichQuestion.type) {
case "radio"://您想要咨询下列哪类的问题?(单选)
return R.layout.im_nim_lingxi_which_question;
case "check"://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice;
case "3"://您是先生还是女生
return R.layout.im_nim_lingxi_men_female;
default:
return R.layout.im_nim_lingxi_which_question;
}
} else {
return R.layout.im_nim_lingxi_which_question;
}
}
......@@ -106,34 +108,32 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override
protected void bindContentView() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
examId=customAttachLingxiWhichQuestion.examId;
questionPaperId=customAttachLingxiWhichQuestion.questionPaperId;
questionId=customAttachLingxiWhichQuestion.id;
examId = customAttachLingxiWhichQuestion.examId;
questionPaperId = customAttachLingxiWhichQuestion.questionPaperId;
questionId = customAttachLingxiWhichQuestion.id;
//您想要咨询下列哪类的问题?(单选)
if (customAttachLingxiWhichQuestion.options!=null){
questionList= (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.options;
if (customAttachLingxiWhichQuestion.options != null) {
questionList = (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.options;
}
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
for (int i=0;i<questionList.size();i++){
for (int i = 0; i < questionList.size(); i++) {
questionList.get(i).setSelected(false);
if (questionList.get(i).getName().length()>5){
isSingleChoice=true;
if (questionList.get(i).getName().length() > 5) {
isSingleChoice = true;
break;
}
}
if (customAttachLingxiWhichQuestion.type!=null){
switch (customAttachLingxiWhichQuestion.type){
if (customAttachLingxiWhichQuestion.type != null) {
switch (customAttachLingxiWhichQuestion.type) {
case "radio"://您想要咨询下列哪类的问题?(单选)
if (questionList!=null&&questionList.size()!=0){
if (questionList != null && questionList.size() != 0) {
initSingleChoice();
}
break;
case "check"://请问是发生了什么事情导致的呢?(多选)
initMultipleChoice();
break;
case "3"://您是先生还是女生
break;
default:
break;
}
......@@ -153,18 +153,18 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (obj != null) {
boolean b = (boolean) obj;
Integer posi=(Integer) position;
Integer posi = (Integer) position;
if (b) {
//不可点击
isClickable=false;
isClickable = false;
questionList.get(posi).setSelected(true);
}
} else {
} else {
//可点击
}
} else {
//可点击
//可点击
}
} catch (Exception e) {
......@@ -173,8 +173,10 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private void initMultipleChoice() {
confirm_multiple_choice.setOnClickListener(view -> {
//请求接口发送所选题目
answerLingxiQuestion(examId,questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(),questionId,answersItems);
//请求接口发送所选题目,通过发通知到YDLMessageFragment统一回答问题。
EventBus.getDefault().post(new MultipleSelectedEvent(null, null,
new MultipleAnswerBean(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(),
questionId, answersItems,message.getFromAccount())));
});
multiple_choice_title.setText(customAttachLingxiWhichQuestion.name);
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
......@@ -182,7 +184,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
adapterLingxiMultipleChoice.setItemListener(this);
GridLayoutManager multipleChoiceManager = new GridLayoutManager(context, 2);
//当list中字段大于6个显示单行,否则显示双行
multipleChoiceManager.setSpanCount( isSingleChoice ? 1 : 2);
multipleChoiceManager.setSpanCount(isSingleChoice ? 1 : 2);
multipleChoiceManager.setOrientation(GridLayoutManager.VERTICAL);
recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager);
recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice);
......@@ -190,7 +192,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private void initSingleChoice() {
which_question_title.setText(customAttachLingxiWhichQuestion.name);
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
adapterLingxiWhichQuestion.setTagData(questionList, isSingleChoice);
adapterLingxiWhichQuestion.setItemListener(this);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2);
//当list中字段大于6个显示单行,否则显示双行
......@@ -202,16 +204,16 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override
public void onItemClick(@NotNull QuestionItemBean itemBean, int position) {
if (isClickable){
for (int i=0;i<questionList.size();i++){
questionList.get(i).setSelected(i==position);
if (isClickable) {
for (int i = 0; i < questionList.size(); i++) {
questionList.get(i).setSelected(i == position);
}
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
isClickable=false;
adapterLingxiWhichQuestion.setTagData(questionList, isSingleChoice);
isClickable = false;
answersItems.add(new AnswersItem(questionList.get(position).getId(),
questionList.get(position).getName(),"其他",questionList.get(position).getRelates()));
questionList.get(position).getName(), "", questionList.get(position).getRelates()));
//请求接口发送所选题目
answerLingxiQuestion(examId,questionPaperId, ImIn.INSTANCE.getUserInfo().getUid().toString(),questionId,answersItems);
answerLingxiQuestion(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid().toString(), questionId, answersItems);
//更新本地消息
updateLocalMsg(position);
......@@ -221,15 +223,15 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
/*
* 用户回答问题接口
* */
private void answerLingxiQuestion(String examID , String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems) {
String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID,questionPaperId,uid,questionId,answersItems),message.getFromAccount(),"56",uid));
private void answerLingxiQuestion(String examID, String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems) {
String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID, questionPaperId, uid, questionId, answersItems), message.getFromAccount(), "56", uid));
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body)
.compose(RxUtils.INSTANCE.resultJavaData())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(it -> {
LogUtil.e("answerQuestion"+it.toString());
LogUtil.e("answerQuestion" + it.toString());
}, throwable ->
LogUtil.e(throwable.getMessage())
);
......@@ -239,46 +241,46 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override
public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) {
//多选发送消息
for (int i=0;i<questionList.size();i++){
if (questionList.get(i).isSelected()){
if (i==position){
for (int i = 0; i < questionList.size(); i++) {
if (questionList.get(i).isSelected()) {
if (i == position) {
questionList.get(i).setSelected(false);
selectedStr.remove(questionList.get(i).getName());
answersItems.remove(position);
}
}else{
if (i==position){
} else {
if (i == position) {
questionList.get(i).setSelected(true);
selectedStr.add(questionList.get(i).getName());
answersItems.add(new AnswersItem(questionList.get(position).getId(),
questionList.get(position).getName(),"其他",questionList.get(position).getRelates()));
questionList.get(position).getName(), "", questionList.get(position).getRelates()));
}
}
}
confirm_multiple_choice.setText(String.format("确定(%d)", selectedStr.size()));
if (selectedStr.size()>0){
if (selectedStr.size() > 0) {
confirm_multiple_choice.setEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
confirm_multiple_choice.setBackground(context.getResources().getDrawable(R.drawable.im_background_18dp_1da1f2));
}
}else{
} else {
confirm_multiple_choice.setEnabled(false);
confirm_multiple_choice.setText("确定");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
confirm_multiple_choice.setBackground(context.getDrawable(R.drawable.im_background_18dp_ebebeb));
}
}
stringBuffer.delete(2,stringBuffer.length());
for (int i=0;i<selectedStr.size();i++){
stringBuffer.delete(2, stringBuffer.length());
for (int i = 0; i < selectedStr.size(); i++) {
stringBuffer.append("#").append(selectedStr.get(i));
}
isOthers=questionList.get(position).getName().contains("其他");
EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString(),new OthersState(isOthers,questionList.get(position).isSelected())));
isOthers = questionList.get(position).getName().contains("其他");
EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString(), new OthersState(isOthers, questionList.get(position).isSelected()), null));
adapterLingxiMultipleChoice.setTagData(questionList);
}
private void updateLocalMsg(Integer position) {
//更新本地消息
Map<String, Object> map = message.getLocalExtension();
......@@ -298,16 +300,16 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
for (IMMessage msg : param) {
MsgAttachment attachment = msg.getAttachment();
if (attachment instanceof 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);
}
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);
}
}
}
}
......
......@@ -12,6 +12,7 @@ data class LingxiWhichQuestionBean(
data class QuestionItemBean(
var id:String?,
var name:String?,
var other:String?,
var relates:ArrayList<Relates>?,
var isSelected: Boolean=false
)
......@@ -32,7 +33,7 @@ data class AnswerBean(
data class AnswersItem(
var optionId:String,
var name: String,
var other:String,
var other:String?,
var relates:ArrayList<Relates>
)
data class Relates(
......
......@@ -64,6 +64,9 @@ import com.yidianling.im.event.MultipleSelectedEvent;
import com.yidianling.im.helper.IMChatUtil;
import com.yidianling.im.http.ImRetrofitApi;
import com.yidianling.im.router.ImIn;
import com.yidianling.im.session.viewholder.bean.AnswerBean;
import com.yidianling.im.session.viewholder.bean.AnswersItem;
import com.yidianling.im.session.viewholder.bean.LingxiAnswerBean;
import com.yidianling.im.session.viewholder.bean.UserIsIn;
import com.yidianling.im.session.viewholder.bean.UserIsInPageData;
import com.yidianling.nimbase.api.UIKitOptions;
......@@ -1079,25 +1082,57 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
}
public void onEvent(MultipleSelectedEvent event){
if (event.getOthersState().isOthers()){
//用户点击了其他事件
if (event.getOthersState().getOthersSelect()){
//其他是选中状态
isOthers=event.getOthersState().getOthersSelect();
rootView.postDelayed(new Runnable() {
@Override
public void run() {
inputPanel.onlyShowTextStart();
}
}, 500);
if (event.getOthersState()!=null){
if (event.getOthersState().isOthers()){
//用户点击了其他事件
if (event.getOthersState().getOthersSelect()){
//其他是选中状态
isOthers=event.getOthersState().getOthersSelect();
rootView.postDelayed(new Runnable() {
@Override
public void run() {
inputPanel.onlyShowTextStart();
}
}, 500);
}else{
//其他是未选中状态
isOthers=event.getOthersState().getOthersSelect();
inputPanel.onlyShowTextEnd();
}
}else{
//其他是未选中状态
isOthers=event.getOthersState().getOthersSelect();
inputPanel.onlyShowTextEnd();
question_multiple.setText(event.getStrSelected());
}
}else{
question_multiple.setText(event.getStrSelected());
//请求接口发送消息为56的答案
ArrayList<AnswersItem> answersItems=event.getMultipleAnswerBean().getAnswersItems();
for (int i=0;i<answersItems.size();i++){
if (answersItems.get(i).getName().contains("其他")){
answersItems.get(i).setOther(inputPanel.getInputContent());
break;
}
}
answerLingxiQuestion(event.getMultipleAnswerBean().getExamId(),event.getMultipleAnswerBean().getQuestionPaperId(),
event.getMultipleAnswerBean().getUid(),event.getMultipleAnswerBean().getQuestionId(),answersItems,
event.getMultipleAnswerBean().getFromUid());
}
}
/*
* 用户回答问题接口
* */
private void answerLingxiQuestion(String examID, String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems,String fromUID) {
String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID, questionPaperId, uid, questionId, answersItems), fromUID, "56", uid));
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body)
.compose(RxUtils.INSTANCE.resultJavaData())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(it -> {
LogUtil.e("answerQuestion" + it.toString());
}, throwable ->
com.yidianling.common.tools.LogUtil.e(throwable.getMessage())
);
}
public boolean onBackPressed() {
return inputPanel.collapse(true) || messageListPanel.onBackPressed() || openOrCloseCommonQuestionLayout(false);
......
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