机器人Im消息

This commit is contained in:
18401019693 2022-10-11 18:31:10 +08:00
parent 310fe91a19
commit c118a7c999
3 changed files with 51 additions and 2 deletions

View File

@ -35,7 +35,7 @@ public class AiAutomaticSpeechModel extends BaseModel {
}
public String getAiName() {
return aiName;
return aiName+":";
}
public AiAutomaticSpeechModel setAiName(String aiName) {

View File

@ -335,6 +335,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
} else if (bean.getType() == AI_AUTOMATIC_SPEECH) {
//加载.9图聊天气泡
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getAiAutomaticSpeechModel().getSystemBubble(), 1);
LiveTextRender.aiAutomaticSpeech(mContext,mTextView,bean.getAiAutomaticSpeechModel());
} else {
if (bean.getBubble() != null && !bean.getBubble().equals("")) {
//加载.9图聊天气泡

View File

@ -25,6 +25,7 @@ import androidx.core.content.ContextCompat;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.AiAutomaticSpeechModel;
import com.yunbao.common.bean.LevelBean;
import com.yunbao.common.custom.VerticalImageSpan;
import com.yunbao.common.glide.ImgLoader;
@ -92,6 +93,53 @@ public class LiveTextRender {
textView.setText(spannableString);
}
public static void aiAutomaticSpeech(Context activity, TextView textView, AiAutomaticSpeechModel model) {
ImgLoader.displayDrawable(activity, model.getIcon(), new ImgLoader.DrawableCallback() {
@Override
public void onLoadSuccess(Drawable drawable) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
String userName = model.getUserName();
String content = model.getContent();
String aiName = model.getAiName();
String nameColor = model.getNameColor();
spannableStringBuilder.append(" ");//图片占位
spannableStringBuilder.append(aiName);//图片占位
spannableStringBuilder.append(" ");
spannableStringBuilder.append(content);
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor(nameColor)),
4, 4+aiName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!TextUtils.isEmpty(userName) && !userName.contains(",")) {
String mContext = content;
userName = "@" + userName;
int startIndex = 6 + aiName.length();
while (mContext.contains(userName)) {
int index = mContext.indexOf(userName);
int end = index + userName.length();
int endIndex = startIndex + userName.length();
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#fffe9b")),
startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContext = mContext.substring(end + 1, mContext.length());
startIndex = startIndex + end + 1;
}
drawable.setBounds(0, 0, DpUtil.dp2px(39), DpUtil.dp2px(15));
//用这个drawable对象代替字符串easy
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
spannableStringBuilder.setSpan(span, 0, 3, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
textView.setText(spannableStringBuilder);
}
}
@Override
public void onLoadFailed() {
}
});
}
/**
* 生成前缀
*/