Commit 6233367b by 霍志良

feat:更新本地消息

parent 6302007a
package com.yidianling.im.event package com.yidianling.im.event
import com.yidianling.im.router.ImIn.getUserInfo
import com.yidianling.im.session.viewholder.bean.AnswersItem import com.yidianling.im.session.viewholder.bean.AnswersItem
public class MultipleSelectedEvent ( public class MultipleSelectedEvent (
......
...@@ -9,6 +9,7 @@ import com.netease.nimlib.sdk.NIMClient ...@@ -9,6 +9,7 @@ import com.netease.nimlib.sdk.NIMClient
import com.netease.nimlib.sdk.RequestCallback import com.netease.nimlib.sdk.RequestCallback
import com.netease.nimlib.sdk.auth.LoginInfo import com.netease.nimlib.sdk.auth.LoginInfo
import com.netease.nimlib.sdk.msg.MsgService import com.netease.nimlib.sdk.msg.MsgService
import com.netease.nimlib.sdk.msg.model.IMMessage
import com.netease.nimlib.sdk.uinfo.UserService import com.netease.nimlib.sdk.uinfo.UserService
import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum
import com.ydl.confide.api.IConfideService import com.ydl.confide.api.IConfideService
...@@ -301,4 +302,12 @@ object ImIn { ...@@ -301,4 +302,12 @@ object ImIn {
fun loginByOneKeyLogin(context: Context, isOpenDialog: Boolean) :Boolean{ fun loginByOneKeyLogin(context: Context, isOpenDialog: Boolean) :Boolean{
return getUserService().loginByOneKeyLogin(context,isOpenDialog) return getUserService().loginByOneKeyLogin(context,isOpenDialog)
} }
lateinit var imMessage:IMMessage
fun setLocalExten(imMessage:IMMessage){
this.imMessage=imMessage
}
fun getImmessage():IMMessage {
return imMessage
}
} }
package com.yidianling.im.session.viewholder; package com.yidianling.im.session.viewholder;
import android.content.ContextWrapper;
import android.os.Build; import android.os.Build;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
...@@ -17,7 +15,6 @@ import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum; ...@@ -17,7 +15,6 @@ import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage; import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.ydl.ydlcommon.data.http.RxUtils; import com.ydl.ydlcommon.data.http.RxUtils;
import com.yidianling.common.tools.LogUtil; import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.event.MultipleAnswerBean; import com.yidianling.im.event.MultipleAnswerBean;
import com.yidianling.im.event.MultipleSelectedEvent; import com.yidianling.im.event.MultipleSelectedEvent;
...@@ -48,7 +45,7 @@ import io.reactivex.schedulers.Schedulers; ...@@ -48,7 +45,7 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.RequestBody; import okhttp3.RequestBody;
public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener, AdapterLingxiMultipleChoice.OnMultiplelItemClickListener { public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener, AdapterLingxiMultipleChoice.OnMultiplelItemClickListener {
private RecyclerView recycleviewWhichQuestion; private RecyclerView recycleviewWhichQuestion;
private RecyclerView recycleviewMultipleChoice; private RecyclerView recycleviewMultipleChoice;
private TextView confirm_multiple_choice; private TextView confirm_multiple_choice;
...@@ -70,6 +67,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -70,6 +67,8 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private String questionPaperId; private String questionPaperId;
private String questionId; private String questionId;
private ArrayList<AnswersItem> answersItems = new ArrayList<>(); private ArrayList<AnswersItem> answersItems = new ArrayList<>();
private ArrayList<String> answersItemsMap = new ArrayList<>();
private ArrayList<String> multipleAnswers=new ArrayList<>();
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) { public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter); super(adapter);
...@@ -107,6 +106,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -107,6 +106,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
protected void bindContentView() { protected void bindContentView() {
ImIn.INSTANCE.setImMessage(message);
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
examId = customAttachLingxiWhichQuestion.examId; examId = customAttachLingxiWhichQuestion.examId;
questionPaperId = customAttachLingxiWhichQuestion.questionPaperId; questionPaperId = customAttachLingxiWhichQuestion.questionPaperId;
...@@ -150,6 +150,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -150,6 +150,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (map != null) { if (map != null) {
Object obj = map.get("isSure"); Object obj = map.get("isSure");
Object position = map.get("position"); Object position = map.get("position");
Object multiple = map.get("multiple");
if (obj != null) { if (obj != null) {
boolean b = (boolean) obj; boolean b = (boolean) obj;
...@@ -157,26 +158,55 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -157,26 +158,55 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (b) { if (b) {
//不可点击 //不可点击
isClickable = false; isClickable = false;
questionList.get(posi).setSelected(true); if (posi!=null){
questionList.get(posi).setSelected(true);
}
} }
} else { } else {
//可点击 //可点击
} }
if (multiple!=null){
multipleAnswers= (ArrayList<String>) multiple;
for (int i=0;i<questionList.size();i++){
for (int j=0;j<multipleAnswers.size();j++){
if (questionList.get(i).getName().contains(multipleAnswers.get(j))){
questionList.get(i).setSelected(true);
}
}
}
if (isClickable){
confirm_multiple_choice.setEnabled(true);
confirm_multiple_choice.setBackground(context.getResources().getDrawable(R.drawable.im_background_18dp_ebebeb));
}else{
confirm_multiple_choice.setEnabled(false);
confirm_multiple_choice.setBackground(context.getResources().getDrawable(R.drawable.im_background_18dp_1da1f2));
confirm_multiple_choice.setText("确定("+multipleAnswers.size()+")");
}
}
} else { } else {
//可点击 //可点击
} }
} catch (Exception e) { } catch (Exception e) {
LogUtil.e("aaaaa"+e.getLocalizedMessage());
} }
} }
private void initMultipleChoice() { private void initMultipleChoice() {
confirm_multiple_choice.setOnClickListener(view -> { confirm_multiple_choice.setOnClickListener(view -> {
//请求接口发送所选题目,通过发通知到YDLMessageFragment统一回答问题。 //请求接口发送所选题目,通过发通知到YDLMessageFragment统一回答问题。
EventBus.getDefault().post(new MultipleSelectedEvent(null, null, EventBus.getDefault().post(new MultipleSelectedEvent(null, null,
new MultipleAnswerBean(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(), new MultipleAnswerBean(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(),
questionId, answersItems,message.getFromAccount()),false)); questionId, answersItems,message.getFromAccount()),false));
/* for (int i=0;i<answersItems.size();i++){
answersItemsMap.add(answersItems.get(i).getName());
}
updateLocalMsg(null,answersItemsMap);*/
}); });
multiple_choice_title.setText(customAttachLingxiWhichQuestion.name); multiple_choice_title.setText(customAttachLingxiWhichQuestion.name);
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice(); adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
...@@ -215,7 +245,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -215,7 +245,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
//请求接口发送所选题目 //请求接口发送所选题目
answerLingxiQuestion(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid().toString(), questionId, answersItems); answerLingxiQuestion(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid().toString(), questionId, answersItems);
//更新本地消息 //更新本地消息
updateLocalMsg(position); updateLocalMsg(position,null);
} }
} }
...@@ -224,7 +254,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -224,7 +254,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
* 用户回答问题接口 * 用户回答问题接口
* */ * */
private void answerLingxiQuestion(String examID, String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems) { 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)); String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID, questionPaperId, uid, questionId, answersItems), uid, "56", message.getFromAccount()));
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str); RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body) Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body)
.compose(RxUtils.INSTANCE.resultJavaData()) .compose(RxUtils.INSTANCE.resultJavaData())
...@@ -240,98 +270,70 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -240,98 +270,70 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) { public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) {
//多选发送消息 if (isClickable){
for (int i = 0; i < questionList.size(); i++) { //多选发送消息
if (questionList.get(i).isSelected()) { for (int i = 0; i < questionList.size(); i++) {
if (i == position) { if (questionList.get(i).isSelected()) {
questionList.get(i).setSelected(false); if (i == position) {
selectedStr.remove(questionList.get(i).getName()); questionList.get(i).setSelected(false);
for (int j=0;j<answersItems.size();j++){ selectedStr.remove(questionList.get(i).getName());
if (questionList.get(i).getName()==answersItems.get(j).getName()){ for (int j=0;j<answersItems.size();j++){
answersItems.remove(j); if (questionList.get(i).getName()==answersItems.get(j).getName()){
break; answersItems.remove(j);
break;
}
} }
}
}
} 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()));
}
}
}
confirm_multiple_choice.setText(String.format("确定(%d)", selectedStr.size()));
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 {
if (i == position) { confirm_multiple_choice.setEnabled(false);
questionList.get(i).setSelected(true); confirm_multiple_choice.setText("确定");
selectedStr.add(questionList.get(i).getName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
answersItems.add(new AnswersItem(questionList.get(position).getId(), confirm_multiple_choice.setBackground(context.getDrawable(R.drawable.im_background_18dp_ebebeb));
questionList.get(position).getName(), "", questionList.get(position).getRelates()));
} }
} }
} stringBuffer.delete(2, stringBuffer.length());
confirm_multiple_choice.setText(String.format("确定(%d)", selectedStr.size())); for (int i = 0; i < selectedStr.size(); i++) {
if (selectedStr.size() > 0) { stringBuffer.append("#").append(selectedStr.get(i));
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 { isOthers = questionList.get(position).getName().contains("其他");
confirm_multiple_choice.setEnabled(false); EventBus.getDefault().post(new MultipleSelectedEvent(stringBuffer.toString(), new OthersState(isOthers, questionList.get(position).isSelected()), new MultipleAnswerBean(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(),
confirm_multiple_choice.setText("确定"); questionId, answersItems,message.getFromAccount()),false));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { adapterLingxiMultipleChoice.setTagData(questionList);
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.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()), new MultipleAnswerBean(examId, questionPaperId, ImIn.INSTANCE.getUserInfo().getUid(),
questionId, answersItems,message.getFromAccount()),false));
adapterLingxiMultipleChoice.setTagData(questionList);
} }
private void updateLocalMsg(Integer position) { private void updateLocalMsg(Integer position,ArrayList<String> selectedPosition) {
//更新本地消息 //更新本地消息
Map<String, Object> map = message.getLocalExtension(); Map<String, Object> map = message.getLocalExtension();
if (map == null) { if (map == null) {
map = new HashMap(); map = new HashMap();
} }
map.put("isSure", true); map.put("isSure", true);
map.put("position", position); if (position!=null){
map.put("position", position);
}
if (selectedPosition!=null){
map.put("multiple", selectedPosition);
}
message.setLocalExtension(map); message.setLocalExtension(map);
NIMClient.getService(MsgService.class).updateIMMessage(message); NIMClient.getService(MsgService.class).updateIMMessage(message);
//同时更新历史同订单未确认的消息状态 //通知ui刷新
NIMClient.getService(MsgService.class).queryMessageList(message.getSessionId(), SessionTypeEnum.P2P, 0, 100).setCallback(new RequestCallback<List<IMMessage>>() { getMsgAdapter().updateItemAtLocalExtension(message);
@Override
public void onSuccess(List<IMMessage> param) {
if (param != null && param.size() > 0) {
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);
}
}
}
}
}
@Override
public void onFailed(int code) {
}
@Override
public void onException(Throwable exception) {
}
});
} }
} }
package com.yidianling.im.session.viewholder.bean package com.yidianling.im.session.viewholder.bean
import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable
data class LingxiWhichQuestionBean( data class LingxiWhichQuestionBean(
var isSelected: Boolean, var isSelected: Boolean,
...@@ -30,18 +34,20 @@ data class AnswerBean( ...@@ -30,18 +34,20 @@ data class AnswerBean(
var questionId:String, var questionId:String,
var answers:ArrayList<AnswersItem> var answers:ArrayList<AnswersItem>
) )
data class AnswersItem( class AnswersItem(
var optionId:String, var optionId:String,
var name: String, var name: String,
var other:String?, var other:String?,
var relates:ArrayList<Relates> var relates:ArrayList<Relates>
) )
data class Relates(
class Relates(
var id: String?, var id: String?,
var category:String?, var category:String?,
var name: String?, var name: String?,
var score:String? var score:String?
) )
data class UserIsIn( data class UserIsIn(
var data: UserIsInPageData, var data: UserIsInPageData,
var fromUid: String, var fromUid: String,
......
...@@ -110,6 +110,7 @@ import org.jetbrains.annotations.NotNull; ...@@ -110,6 +110,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -226,6 +227,8 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy { ...@@ -226,6 +227,8 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
private UserInfoDialog userInfoDialog = null; private UserInfoDialog userInfoDialog = null;
private boolean isOthers; private boolean isOthers;
private MultipleAnswerBean multipleAnswerBean; private MultipleAnswerBean multipleAnswerBean;
private ArrayList<String> answersItemsMap = new ArrayList<>();
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() { private Handler mHandler = new Handler() {
@Override @Override
...@@ -1116,6 +1119,10 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy { ...@@ -1116,6 +1119,10 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
} }
} }
multipleAnswerBean.setAnswersItems(answersItems); multipleAnswerBean.setAnswersItems(answersItems);
for (int i=0;i<answersItems.size();i++){
answersItemsMap.add(i,answersItems.get(i).getName());
}
updateLocalMsg(null,answersItemsMap);
answerMultipleQuestion(multipleAnswerBean); answerMultipleQuestion(multipleAnswerBean);
}else{ }else{
...@@ -1129,14 +1136,37 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy { ...@@ -1129,14 +1136,37 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
} }
multipleAnswerBean=event.getMultipleAnswerBean(); multipleAnswerBean=event.getMultipleAnswerBean();
multipleAnswerBean.setAnswersItems(answersItems); multipleAnswerBean.setAnswersItems(answersItems);
for (int i=0;i<answersItems.size();i++){
answersItemsMap.add(i,answersItems.get(i).getName());
}
updateLocalMsg(null,answersItemsMap);
answerMultipleQuestion(multipleAnswerBean); answerMultipleQuestion(multipleAnswerBean);
} }
} }
private void updateLocalMsg(Integer position,ArrayList<String> selectedPosition) {
IMMessage message=ImIn.INSTANCE.getImMessage();
//更新本地消息
Map<String, Object> map = message.getLocalExtension();
if (map == null) {
map = new HashMap();
}
map.put("isSure", true);
if (position!=null){
map.put("position", position);
}
if (selectedPosition!=null){
map.put("multiple", selectedPosition);
}
message.setLocalExtension(map);
NIMClient.getService(MsgService.class).updateIMMessage(message);
//通知ui刷新
// message.getMsgAdapter().updateItemAtLocalExtension(message);
}
/* /*
* 用户回答问题接口 * 用户回答问题接口
* */ * */
private void answerMultipleQuestion(MultipleAnswerBean multipleAnswerBean){ private void answerMultipleQuestion(MultipleAnswerBean multipleAnswerBean){
inputPanel.setInputContent(""); inputPanel.setInputContent("");
question_multiple.setText(""); question_multiple.setText("");
inputPanel.onlyShowTextEnd(); inputPanel.onlyShowTextEnd();
...@@ -1148,7 +1178,7 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy { ...@@ -1148,7 +1178,7 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
* 用户回答问题接口 * 用户回答问题接口
* */ * */
private void answerLingxiQuestion(String examID, String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems,String fromUID) { 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)); String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID, questionPaperId, uid, questionId, answersItems), uid, "56", fromUID));
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str); RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body) Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body)
.compose(RxUtils.INSTANCE.resultJavaData()) .compose(RxUtils.INSTANCE.resultJavaData())
......
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