机器人Im消息
This commit is contained in:
parent
310fe91a19
commit
c118a7c999
@ -35,7 +35,7 @@ public class AiAutomaticSpeechModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getAiName() {
|
public String getAiName() {
|
||||||
return aiName;
|
return aiName+":";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AiAutomaticSpeechModel setAiName(String aiName) {
|
public AiAutomaticSpeechModel setAiName(String aiName) {
|
||||||
|
@ -335,6 +335,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
|
|||||||
} else if (bean.getType() == AI_AUTOMATIC_SPEECH) {
|
} else if (bean.getType() == AI_AUTOMATIC_SPEECH) {
|
||||||
//加载.9图聊天气泡
|
//加载.9图聊天气泡
|
||||||
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getAiAutomaticSpeechModel().getSystemBubble(), 1);
|
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getAiAutomaticSpeechModel().getSystemBubble(), 1);
|
||||||
|
LiveTextRender.aiAutomaticSpeech(mContext,mTextView,bean.getAiAutomaticSpeechModel());
|
||||||
} else {
|
} else {
|
||||||
if (bean.getBubble() != null && !bean.getBubble().equals("")) {
|
if (bean.getBubble() != null && !bean.getBubble().equals("")) {
|
||||||
//加载.9图聊天气泡
|
//加载.9图聊天气泡
|
||||||
|
@ -25,6 +25,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
import com.yunbao.common.CommonAppConfig;
|
import com.yunbao.common.CommonAppConfig;
|
||||||
import com.yunbao.common.CommonAppContext;
|
import com.yunbao.common.CommonAppContext;
|
||||||
import com.yunbao.common.Constants;
|
import com.yunbao.common.Constants;
|
||||||
|
import com.yunbao.common.bean.AiAutomaticSpeechModel;
|
||||||
import com.yunbao.common.bean.LevelBean;
|
import com.yunbao.common.bean.LevelBean;
|
||||||
import com.yunbao.common.custom.VerticalImageSpan;
|
import com.yunbao.common.custom.VerticalImageSpan;
|
||||||
import com.yunbao.common.glide.ImgLoader;
|
import com.yunbao.common.glide.ImgLoader;
|
||||||
@ -92,6 +93,53 @@ public class LiveTextRender {
|
|||||||
textView.setText(spannableString);
|
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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成前缀
|
* 生成前缀
|
||||||
*/
|
*/
|
||||||
@ -254,7 +302,7 @@ public class LiveTextRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void gz(final Context context, final TextView textView, final LiveChatBean bean) {
|
public static void gz(final Context context, final TextView textView, final LiveChatBean bean) {
|
||||||
ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new())?bean.getMedal():bean.getMedal_new(), new ImgLoader.DrawableCallback() {
|
ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new()) ? bean.getMedal() : bean.getMedal_new(), new ImgLoader.DrawableCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadSuccess(Drawable drawable) {
|
public void onLoadSuccess(Drawable drawable) {
|
||||||
gzDrawables = null;
|
gzDrawables = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user