feat:完成家族小秘书消息对接(和之前的家族逻辑一样,只是协议码不对)

fix:修复公会小秘书消息文案展示不完整问题
This commit is contained in:
max
2024-05-21 19:13:37 +08:00
parent cab7e3542e
commit 6229ba57be
10 changed files with 439 additions and 80 deletions

View File

@@ -2,6 +2,8 @@ package com.chwl.app.ui.im;
import android.content.Context;
import com.chwl.app.module_hall.im.msgholder.FamilyMsgViewHolder;
import com.chwl.core.module_hall.im.FamilyAttachment;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.api.model.contact.ContactEventListener;
import com.netease.nim.uikit.api.model.session.SessionCustomization;
@@ -144,6 +146,8 @@ public class ImInitHelper {
HallDataManager.get().mainNimOnCreate();
//公会模块
NimUIKit.registerMsgItemViewHolder(ClanAttachment.class, ClanMsgViewHolder.class);
//家族模块
NimUIKit.registerMsgItemViewHolder(FamilyAttachment.class, FamilyMsgViewHolder.class);
//瓜分钻石 三级
NimUIKit.registerMsgItemViewHolder(CarveUpGoldThirdLevelAttachment.class, MsgViewHolderText.class);

View File

@@ -33,7 +33,7 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_tip"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/sure_to_agree_user_join_room"
android:textColor="@color/text_title_color"

View File

@@ -2,6 +2,7 @@ package com.chwl.app.module_hall.im;
import android.text.TextUtils;
import com.chwl.core.module_hall.im.FamilyImMsgInfo;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.msg.MsgService;
@@ -25,6 +26,23 @@ import io.reactivex.SingleOnSubscribe;
*/
public class NimHelper {
/**
* 更新家族消息到本地数据库
*
* @param uuid 消息 UUID
* @param info 家族消息实体
*/
public static void updateFamilyMsgInfoMessage(String uuid, FamilyImMsgInfo info) {
IMMessage message = IMNetEaseManager.get().queryMessageByUuid(uuid);
if (message != null) {
Map<String, Object> localExtension = FamilyImMsgInfo.convertToMap(info);
message.setLocalExtension(localExtension);
NIMClient.getService(MsgService.class)
.updateIMMessage(message);
}
}
/**
* 更新模厅消息到本地数据库
*

View File

@@ -1,6 +1,7 @@
package com.chwl.app.module_hall.im.msgholder;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
@@ -15,6 +16,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import com.alibaba.fastjson.JSON;
import com.coorchice.library.SuperTextView;
import com.example.lib_utils.spannable.SpannableTextBuilder;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
@@ -144,60 +146,33 @@ public class ClanMsgViewHolder extends MsgViewHolderBase{
// content
List<HallMsgComponent> erbanSysMsgLayoutContent = hallMsgLayout.getContents();
if (erbanSysMsgLayoutContent != null) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
SpannableTextBuilder textBuilder = new SpannableTextBuilder(tvContent);
for (HallMsgComponent component : erbanSysMsgLayoutContent) {
int start = spannableStringBuilder.length();
String msgBody = component.getContent();
if (Objects.equals(msgBody, "/r/n")) {
msgBody = "\r\n";
spannableStringBuilder.append(msgBody);
textBuilder.appendText(msgBody,null,null,null,null,null,null);
continue;
}
spannableStringBuilder.append(msgBody);
Integer textColor = null;
Integer textSize = null;
Integer textStyle = null;
if (component.getFontColor() != null) {
try {
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(component.getFontColor())),
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textColor = Color.parseColor(component.getFontColor());
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (component.getFontSize() > 0) {
spannableStringBuilder.setSpan(
new MetricAffectingSpan() {
@Override
public void updateMeasureState(TextPaint p) {
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTextSize(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
component.getFontSize(),
tvContent.getContext().getResources().getDisplayMetrics()));
}
},
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textSize = (int) component.getFontSize();
}
spannableStringBuilder.setSpan(
new MetricAffectingSpan() {
@Override
public void updateMeasureState(TextPaint p) {
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setFakeBoldText(component.isFontBold());
}
},
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if (component.isFontBold()) {
textStyle = Typeface.BOLD;
}
textBuilder.appendText(msgBody, textColor, null, textSize, textStyle, null, null);
}
tvContent.setText(spannableStringBuilder);
textBuilder.apply();
}
}

View File

@@ -0,0 +1,228 @@
package com.chwl.app.module_hall.im.msgholder;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Keep;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.alibaba.fastjson.JSON;
import com.chwl.app.R;
import com.chwl.app.module_hall.im.NimHelper;
import com.chwl.app.ui.im.RouterHandler;
import com.chwl.core.im.custom.bean.CustomAttachment;
import com.chwl.core.manager.IMNetEaseManager;
import com.chwl.core.module_hall.hall.HallModel;
import com.chwl.core.module_hall.hall.bean.ApplyResult;
import com.chwl.core.module_hall.im.FamilyAttachment;
import com.chwl.core.module_hall.im.FamilyImMsgInfo;
import com.chwl.core.module_hall.im.bean.HallMsgComponent;
import com.chwl.core.module_hall.im.bean.HallMsgLayout;
import com.chwl.core.utils.net.BeanObserver;
import com.chwl.library.utils.ResUtil;
import com.chwl.library.utils.SingleToastUtil;
import com.coorchice.library.SuperTextView;
import com.example.lib_utils.spannable.SpannableTextBuilder;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 模厅im消息展示
* Created by lvzebiao on 2019/1/7.
*/
@Keep
public class FamilyMsgViewHolder extends MsgViewHolderBase {
private ConstraintLayout clContainer;
private TextView tvTitle;
private AppCompatTextView stvAgree;
private TextView tvContent;
private View llOpLayout;
private SuperTextView stvReject;
private View llResultLayout;
private SuperTextView tvResult;
public FamilyMsgViewHolder(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter);
}
@Override
protected int getContentResId() {
return R.layout.layout_hall_msg_view_holder;
}
@Override
protected void inflateContentView() {
tvTitle = findViewById(R.id.tv_title);
stvAgree = findViewById(R.id.stv_agree);
stvReject = findViewById(R.id.stv_reject);
llOpLayout = findViewById(R.id.ll_op_layout);
tvContent = findViewById(R.id.tv_content);
clContainer = findViewById(R.id.cl_container);
llResultLayout = findViewById(R.id.ll_result_layout);
tvResult = findViewById(R.id.tv_result);
}
@Override
protected void bindContentView() {
clContainer.getLayoutParams().width = ScreenUtil.screenWidth * 240 / 375;
clContainer.setVisibility(View.GONE);
clContainer.setClickable(false);
if (message == null) {
return;
}
IMMessage imMessage = IMNetEaseManager.get().queryMessageByUuid(message.getUuid());
if (imMessage == null || imMessage.getAttachment() == null) {
return;
}
if (!(imMessage.getAttachment() instanceof FamilyAttachment)) {
return;
}
FamilyAttachment attachment = (FamilyAttachment) imMessage.getAttachment();
FamilyImMsgInfo info = attachment.getFamilyImMsgInfo();
if (info == null) {
return;
}
if (message.getLocalExtension() != null) {
info = FamilyImMsgInfo.convertMapToObject(message.getLocalExtension());
}
clContainer.setVisibility(View.VISIBLE);
if (info.getRouterType() > 0) {
final int routerType = info.getRouterType();
final String routerValue = info.getRouterValue();
clContainer.setClickable(true);
clContainer.setOnClickListener(v ->
RouterHandler.handle(context, routerType, routerValue));
}
stvReject.setVisibility(View.VISIBLE);
int second = attachment.getSecond();
if (second == CustomAttachment.CUSTOM_MSG_FAMILY_INVITE
|| second == CustomAttachment.CUSTOM_MSG_FAMILY_APPLY) {
setMsgTypeView(info, second);
} else {
llResultLayout.setVisibility(View.GONE);
llOpLayout.setVisibility(View.GONE);
}
HallMsgLayout hallMsgLayout = null;
try {
String layout = info.getLayout();
if (!TextUtils.isEmpty(layout)) {
hallMsgLayout = JSON.parseObject(layout, HallMsgLayout.class);
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (hallMsgLayout == null) {
tvTitle.setText("");
tvContent.setText("");
return;
}
// title
tvTitle.setText(hallMsgLayout.getTitle().getContent());
// content
List<HallMsgComponent> erbanSysMsgLayoutContent = hallMsgLayout.getContents();
if (erbanSysMsgLayoutContent != null) {
SpannableTextBuilder textBuilder = new SpannableTextBuilder(tvContent);
for (HallMsgComponent component : erbanSysMsgLayoutContent) {
String msgBody = component.getContent();
if (Objects.equals(msgBody, "/r/n")) {
msgBody = "\r\n";
textBuilder.appendText(msgBody,null,null,null,null,null,null);
continue;
}
Integer textColor = null;
Integer textSize = null;
Integer textStyle = null;
if (component.getFontColor() != null) {
try {
textColor = Color.parseColor(component.getFontColor());
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (component.getFontSize() > 0) {
textSize = (int) component.getFontSize();
}
if (component.isFontBold()) {
textStyle = Typeface.BOLD;
}
textBuilder.appendText(msgBody, textColor, null, textSize, textStyle, null, null);
}
textBuilder.apply();
}
}
private void handleClick(FamilyImMsgInfo info, int second) {
stvAgree.setOnClickListener(view -> {
handleApply(info, second, 1);
});
stvReject.setOnClickListener(view -> {
handleApply(info, second, 0);
});
}
/**
* @param type 1同意0拒绝
*/
private void handleApply(FamilyImMsgInfo info, int second, int type) {
HallModel.get().dealApply(info.getUrl(), type)
.subscribe(new BeanObserver<>() {
@Override
public void onErrorMsg(String error) {
SingleToastUtil.showToast(error);
}
@Override
public void onSuccess(ApplyResult result) {
if (result.getCode() == ApplyResult.CODE_MSG_OUT_OF_DATE) {
info.setType(FamilyImMsgInfo.MSG_TYPE_OUT_OF_DATE);
} else if (result.getCode() == ApplyResult.CODE_MSG_HAS_HANDLE) {
info.setType(FamilyImMsgInfo.MSG_TYPE_HAS_HANDLE);
} else {
info.setType(type == 1 ? FamilyImMsgInfo.MSG_TYPE_HAS_AGREE :
FamilyImMsgInfo.MSG_TYPE_HAS_REJECT);
}
setMsgTypeView(info, second);
Map<String, Object> localExtension = FamilyImMsgInfo.convertToMap(info);
message.setLocalExtension(localExtension);
updateMessageToLocal(info);
}
});
}
private void updateMessageToLocal(FamilyImMsgInfo info) {
NimHelper.updateFamilyMsgInfoMessage(message.getUuid(), info);
}
private void setMsgTypeView(FamilyImMsgInfo info, int second) {
llResultLayout.setVisibility(View.VISIBLE);
llOpLayout.setVisibility(View.GONE);
if (info.getType() == FamilyImMsgInfo.MSG_TYPE_HAS_AGREE) {
tvResult.setText(ResUtil.getString(R.string.im_msgholder_hallmsgviewholder_01));
} else if (info.getType() == FamilyImMsgInfo.MSG_TYPE_HAS_REJECT) {
tvResult.setText(ResUtil.getString(R.string.im_msgholder_hallmsgviewholder_02));
} else if (info.getType() == FamilyImMsgInfo.MSG_TYPE_OUT_OF_DATE) {
tvResult.setText(ResUtil.getString(R.string.im_msgholder_hallmsgviewholder_03));
} else if (info.getType() == FamilyImMsgInfo.MSG_TYPE_HAS_HANDLE) {
tvResult.setText(ResUtil.getString(R.string.im_msgholder_hallmsgviewholder_04));
} else {
llResultLayout.setVisibility(View.GONE);
llOpLayout.setVisibility(View.VISIBLE);
handleClick(info, second);
}
}
}

View File

@@ -1,6 +1,7 @@
package com.chwl.app.module_hall.im.msgholder;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
@@ -16,6 +17,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import com.alibaba.fastjson.JSON;
import com.coorchice.library.SuperTextView;
import com.example.lib_utils.spannable.SpannableTextBuilder;
import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
@@ -155,60 +157,32 @@ public class HallMsgViewHolder extends MsgViewHolderBase {
// content
List<HallMsgComponent> erbanSysMsgLayoutContent = hallMsgLayout.getContents();
if (erbanSysMsgLayoutContent != null) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
SpannableTextBuilder textBuilder = new SpannableTextBuilder(tvContent);
for (HallMsgComponent component : erbanSysMsgLayoutContent) {
int start = spannableStringBuilder.length();
String msgBody = component.getContent();
if (Objects.equals(msgBody, "/r/n")) {
msgBody = "\r\n";
spannableStringBuilder.append(msgBody);
textBuilder.appendText(msgBody,null,null,null,null,null,null);
continue;
}
spannableStringBuilder.append(msgBody);
}Integer textColor = null;
Integer textSize = null;
Integer textStyle = null;
if (component.getFontColor() != null) {
try {
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(component.getFontColor())),
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textColor = Color.parseColor(component.getFontColor());
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (component.getFontSize() > 0) {
spannableStringBuilder.setSpan(
new MetricAffectingSpan() {
@Override
public void updateMeasureState(TextPaint p) {
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setTextSize(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
component.getFontSize(),
tvContent.getContext().getResources().getDisplayMetrics()));
}
},
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textSize = (int) component.getFontSize();
}
spannableStringBuilder.setSpan(
new MetricAffectingSpan() {
@Override
public void updateMeasureState(TextPaint p) {
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setFakeBoldText(component.isFontBold());
}
},
start, spannableStringBuilder.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if (component.isFontBold()) {
textStyle = Typeface.BOLD;
}
textBuilder.appendText(msgBody, textColor, null, textSize, textStyle, null, null);
}
tvContent.setText(spannableStringBuilder);
textBuilder.apply();
}
}