消息气泡位置,关注消息默认消息,样式更改

This commit is contained in:
18401019693 2023-03-22 16:55:51 +08:00
parent be608fd90b
commit 554bfa137a
14 changed files with 272 additions and 63 deletions

View File

@ -2,6 +2,7 @@ package com.yunbao.common.bean;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
/**
@ -17,6 +18,17 @@ public class NewLevelModel extends BaseModel {
private String levemax;
@SerializedName("thumb")
private String thumb;
@SerializedName("icon")
private String icon;
@SerializedName("colour")
private String colour;
@SerializedName("live_icon")
private String liveIcon;
public static NewLevelModel objectFromData(String str) {
return new Gson().fromJson(str, NewLevelModel.class);
}
public String getId() {
return id;
@ -67,4 +79,28 @@ public class NewLevelModel extends BaseModel {
this.thumb = thumb;
return this;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getColour() {
return colour;
}
public void setColour(String colour) {
this.colour = colour;
}
public String getLiveIcon() {
return liveIcon;
}
public void setLiveIcon(String liveIcon) {
this.liveIcon = liveIcon;
}
}

View File

@ -16,6 +16,8 @@ import java.util.List;
public class NewLevelManager extends BaseCacheManager {
private final String KEY_USER_LEVEL = "keyUserLevel";
private final String KEY_ANCHOR_LEVEL = "keyAnchorLevel";
private final String KEY_LIVE_LEVEL = "keyLiveLevel";
private List<NewLevelModel> newLevelModels = new ArrayList<>();
private List<NewLevelModel> keyAnchorLevel = new ArrayList<>();

View File

@ -735,7 +735,7 @@
<string name="live_close_exit">Exit</string>
<string name="user">User</string>
<string name="automatic_chat">If you don\'t take the initiative,how can we have a story?\nTell the anchor say hi~</string>
<string name="automatic_chat">If you don\'t take the initiative,how can we have a story?Tell the anchor say hi~</string>
<string name="add_follow">+ follow</string>
<string name="add_into_active">Enter activity</string>

View File

@ -780,7 +780,7 @@
<string name="live_close_exit">直接退出</string>
<string name="user">用戶</string>
<string name="automatic_chat">你都不主動我們怎麼會有故事,\n跟主播Say Hi吧~</string>
<string name="automatic_chat">你都不主動我們怎麼會有故事跟主播Say Hi吧~</string>
<string name="add_follow">+ 關注</string>
<string name="add_into_active">進入活動</string>

View File

@ -9,9 +9,9 @@ ext {
]
manifestPlaceholders = [
//
serverHost : "https://napi.yaoulive.com",
// serverHost : "https://napi.yaoulive.com",
//
// serverHost : "https://ceshi.yaoulive.com",
serverHost : "https://ceshi.yaoulive.com",
//
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 540 B

After

Width:  |  Height:  |  Size: 712 B

View File

@ -14,11 +14,13 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -37,6 +39,7 @@ import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.views.weight.ClipPathCircleImage;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveChatBean;
@ -176,12 +179,16 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
RoundedImageView avatar;
View v_chat_active_close;
RecyclerView rv_chat_active;
ImageView img_zg_img;
ImageView img_zg_img, btnAttention;
FrameLayout attentionLayout;
ClipPathCircleImage clipImage2;
public Vh(View itemView) {
super(itemView);
mBg = (LinearLayout) itemView.findViewById(R.id.bg);
mTextView = (TextView) itemView.findViewById(R.id.text_txt);
attentionLayout = (FrameLayout) itemView.findViewById(R.id.attention_layout);
clipImage2 = (ClipPathCircleImage) itemView.findViewById(R.id.clip_image2);
itemView.setOnClickListener(mOnClickListener);
view_follow = (LinearLayout) itemView.findViewById(R.id.view_follow);
@ -196,6 +203,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
view_zg = (LinearLayout) itemView.findViewById(R.id.view_zg);
tv_zg_anchorname = (TextView) itemView.findViewById(R.id.tv_zg_anchorname);
img_zg_img = (ImageView) itemView.findViewById(R.id.img_zg_img);
btnAttention = (ImageView) itemView.findViewById(R.id.btn_attention);
}
@ -203,7 +211,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
itemView.setTag(bean);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, DpUtil.dp2px(95), 12);
params.setMargins(0, 0, DpUtil.dp2px(95), 0);
params.gravity = Gravity.CENTER_VERTICAL;
mBg.setLayoutParams(params);
if (bean.getType() == 6) {//大作战活动
view_action_game.setVisibility(View.VISIBLE);
@ -241,7 +250,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
} else {
// mBg.setBackgroundResource(R.drawable.bg_live_chat_item);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg,1);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg, 1);
}
SpannableStringBuilder builder = new SpannableStringBuilder();
if (bean.getType() == -3) {
@ -282,7 +291,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
} else {
// mBg.setBackgroundResource(R.drawable.bg_live_chat_item);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg,1);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg, 1);
}
String str1 = "火力四射,魅力無限!感謝";
String str2 = "為本直播間加成熱度";
@ -302,7 +311,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
} else {
// mBg.setBackgroundResource(R.drawable.bg_live_chat_item);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg,1);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg, 1);
}
String str1 = "甜蜜不停,愛意不斷!恭喜";
String str2 = "在甜蜜約會中搶購到了";
@ -329,33 +338,48 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
}
if (isContains) {
mTextView.setTextColor(0xffffffff);
mBg.setBackground(null);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg, 1);
mTextView.setText(bean.getContent());
}
} else if (bean.getType() == LiveChatBean.SYSTEM2) {
mTextView.setTextColor(0xffffffff);
mBg.setBackground(null);
mTextView.setText(bean.getContent());
} else if (bean.getType() == -1) {//自动消息关注
boolean isContains = false;
for (LiveChatBean model : mList) {
if (bean.getType() == -1) {
isContains = true;
}
}
if (isContains) {
mBg.setBackground(null);
mTextView.setVisibility(View.GONE);
view_follow.setVisibility(View.VISIBLE);
ImgLoader.display(mContext, bean.getId(), avatar);
bean.setHeart(position);
}
} else if (bean.getType() == -2) {//自动消息点击发言
mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item);
mTextView.setText(R.string.automatic_chat);
}
// else if (bean.getType() == -1) {//自动消息关注
// boolean isContains = false;
// for (LiveChatBean model : mList) {
// if (bean.getType() == -1) {
// isContains = true;
// }
// }
// if (isContains) {
// mBg.setBackground(null);
// mTextView.setVisibility(View.GONE);
// view_follow.setVisibility(View.VISIBLE);
// ImgLoader.display(mContext, bean.getId(), avatar);
// bean.setHeart(position);
// }
//
// }
else if (bean.getType() == -2) {//自动消息点击发言
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params3.setMargins(0, 8, DpUtil.dp2px(95), 8);
params3.gravity = Gravity.CENTER_VERTICAL;
mBg.setLayoutParams(params3);
mBg.setBackground(null);
mTextView.setVisibility(View.GONE);
bean.setHeart(position);
ImgLoader.display(mContext, bean.getId(), clipImage2);
attentionLayout.setVisibility(View.VISIBLE);
btnAttention.setVisibility(bean.isAttention() ? View.GONE : View.VISIBLE);
btnAttention.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LiveRoomViewHolder.follow();
btnAttention.setVisibility(View.GONE);
}
});
} else if (bean.getType() == MSG_HOUR_RANK_CHANGE) {
mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item);
mTextView.setText(bean.getContent());
@ -382,21 +406,20 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
new LiveTextRender().luckyAngel(mContext, mTextView, bean.getMsgModel());
}
}else if(bean.getType() == LUCKY_100_CHECK){
} else if (bean.getType() == LUCKY_100_CHECK) {
if (!TextUtils.isEmpty(bean.getMsgModel().getSystem_bubble())) {
bean.setId(bean.getMsgModel().getUserId());
itemView.setTag(bean);
new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getMsgModel().getSystem_bubble(), 1);
new LiveTextRender().lucky100(mContext, mTextView, bean.getMsgModel());
}
}
else {
} else {
if (bean.getBubble() != null && !bean.getBubble().equals("")) {
//加载.9图聊天气泡
new LoadDian9TuUtil().loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
} else {
// mBg.setBackgroundResource(R.drawable.bg_live_chat_item);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg,1);
new LoadDian9TuUtil().loadDian9TuAssets(mContext, mBg, 1);
}
if (bean.getType() == LiveChatBean.ENTER_ROOM || bean.getType() == LiveChatBean.LIGHT) {
mTextView.setTextColor(0xffc8c8c8);
@ -406,7 +429,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
new LiveTextRender().render(mContext, mTextView, bean);
}
Animation animation = AnimationUtils.loadAnimation(itemView.getContext(),R.anim.live_chat_msg_in);
Animation animation = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.live_chat_msg_in);
itemView.startAnimation(animation);
}
}

View File

@ -83,6 +83,17 @@ public class LiveChatBean {
//@ID
@SerializedName("atUserID")
private String atUserID = "";
//用户是否关注主播
private boolean isAttention = false;
public boolean isAttention() {
return isAttention;
}
public LiveChatBean setAttention(boolean attention) {
isAttention = attention;
return this;
}
public String getAtUserName() {
return atUserName;

View File

@ -158,10 +158,11 @@ public class LiveTextRender {
builder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFF86C")), giftIndexOf, giftIndexOf + giftSize, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(builder);
}
/**
* 幸运100%活动
*/
public void lucky100(Context mContext, TextView mTextView, MsgModel msgModel){
public void lucky100(Context mContext, TextView mTextView, MsgModel msgModel) {
String msg = mContext.getString(R.string.lucky_100);
msg = String.format(msg, msgModel.getUserName(), msgModel.getGiftName());
int unameIndexOf = msg.indexOf(msgModel.getUserName());
@ -199,7 +200,7 @@ public class LiveTextRender {
int index = mContext.indexOf(userName);
int end = index + userName.length();
int endIndex = startIndex + userName.length();
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#fffe9b")),
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FBEABF")),
startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContext = mContext.substring(end + 1, mContext.length());
startIndex = startIndex + end + 1;
@ -215,7 +216,7 @@ public class LiveTextRender {
int end = index + name.length();
startIndex = index + startIndex;
int endIndex = startIndex + name.length();
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#fffe9b")),
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FBEABF")),
startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mContext = mContext.substring(end, mContext.length());
startIndex = endIndex;
@ -248,7 +249,7 @@ public class LiveTextRender {
if (levelDrawable != null) {
builder.append(" ");
levelDrawable.setBounds(0, 0, DpUtil.dp2px(32), DpUtil.dp2px(14));
levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length();
}
@ -416,7 +417,6 @@ public class LiveTextRender {
});
}
private ImgLoader.DrawableCallback mCallback;
/**
* 等级设置
@ -424,10 +424,9 @@ public class LiveTextRender {
* @return
*/
public void getLevelImage(Context mContext, int userLevel, ImgLoader.DrawableCallback callback) {
mCallback = callback;
if(mContext instanceof Activity){
if(((Activity)mContext).isDestroyed()){
mContext=CommonAppContext.getTopActivity();
if (mContext instanceof Activity) {
if (((Activity) mContext).isDestroyed()) {
mContext = CommonAppContext.getTopActivity();
}
}
List<NewLevelModel> models = new NewLevelManager(mContext).getNewLevelModels();
@ -484,18 +483,76 @@ public class LiveTextRender {
});
}
public void getLiveLevelImage(Context mContext, int userLevel, ImgLoader.DrawableCallback callback) {
if (mContext instanceof Activity) {
if (((Activity) mContext).isDestroyed()) {
mContext = CommonAppContext.getTopActivity();
}
}
List<NewLevelModel> models = new NewLevelManager(mContext).getNewLevelModels();
String imgUrl = "https://downs.yaoulive.com/level1/img_1-9.png";
for (NewLevelModel newLevelModel : models) {
if (newLevelModel.getLeveMin() <= userLevel && userLevel <= newLevelModel.getLeveMax()) {
imgUrl = newLevelModel.getLiveIcon();
}
}
Glide.with(mContext).asBitmap().load(imgUrl).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
Observable.create(new ObservableOnSubscribe<Bitmap>() {
@Override
public void subscribe(ObservableEmitter<Bitmap> emitter) throws Exception {
emitter.onNext(AddTimeLiveWatermark(resource, String.valueOf(userLevel)));//
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Bitmap>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Bitmap bitmap) {
BitmapDrawable drawable = new BitmapDrawable(bitmap);
if (callback != null) {
callback.onLoadSuccess(drawable);
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
if (callback != null) {
callback.onLoadFailed();
}
}
});
}
private void renderTMP(Context context, final TextView textView, final LiveChatBean bean) {
if (textView != null) {
getLevelImage(context, bean.getLevel(), new ImgLoader.DrawableCallback() {
getLiveLevelImage(context, bean.getLevel(), new ImgLoader.DrawableCallback() {
@Override
public void onLoadSuccess(Drawable drawable) {
SpannableStringBuilder builder = createPrefix(drawable, bean);
int color = Color.parseColor("#68F1F4");
if (bean.isAnchor()) {
color = 0xffffdd00;
color =Color.parseColor("#FBEABF");
} else {
color = Color.parseColor("#68F1F4");
}
@ -535,6 +592,43 @@ public class LiveTextRender {
}
/**
* bitmap添加文字
*
* @param mBitmap
* @return
*/
private Bitmap AddTimeLiveWatermark(Bitmap mBitmap, String level) {
//获取原始图片与水印图片的宽与高
int mBitmapWidth = mBitmap.getWidth();
int mBitmapHeight = mBitmap.getHeight();
Bitmap mNewBitmap = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.ARGB_8888);
Canvas mCanvas = new Canvas(mNewBitmap);
//向位图中开始画入MBitmap原始图片
mCanvas.drawBitmap(mBitmap, 0, 0, null);
//添加文字
Paint mPaint = new Paint();
Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
mPaint.setColor(Color.WHITE);
if (level.length() == 3) {
mPaint.setTextSize(27);
mPaint.setTypeface(font);
mCanvas.drawText(level, 3, 38, mPaint);
} else if (level.length() == 2) {
mPaint.setTextSize(30 );
mPaint.setTypeface(font);
mCanvas.drawText(level, 10, 38, mPaint);
}else if (level.length() == 1) {
mPaint.setTextSize(37 );
mPaint.setTypeface(font);
mCanvas.drawText(level, 16, 38, mPaint);
}
mCanvas.save();
mCanvas.restore();
return mNewBitmap;
}
/**
* bitmap添加文字
*

View File

@ -448,15 +448,11 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
if (!liveUid.equals(mLiveUid)) {
return;
}
if (isattention == 0) {
LiveChatBean lvBean = new LiveChatBean();
lvBean.setType(-1);
lvBean.setId(url);
LiveRoomViewHolder.insertChat(lvBean, 1);
}
LiveChatBean lvBean2 = new LiveChatBean();
lvBean2.setType(-2);
LiveRoomViewHolder.insertChat(lvBean2, 1);
LiveChatBean lvBean = new LiveChatBean();
lvBean.setType(-2);
lvBean.setId(url);
lvBean.setAttention(isattention == 0);
LiveRoomViewHolder.insertChat(lvBean, 1);
Log.i("chatMgs", liveUid + "|" + mLiveUid);
}
}, 10000);//3秒后执行Runnable中的run方法

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="8dp" />
<solid android:color="#30000000" />
</shape>

View File

@ -3,22 +3,20 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bg"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/text_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="9dp"
android:layout_marginTop="4dp"
android:layout_marginRight="9dp"
android:layout_marginBottom="6dp"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:paddingBottom="7dp"
android:textColor="#fff"
android:textSize="12sp"
android:visibility="visible"
tools:ignore="RtlHardcoded" />
@ -182,4 +180,40 @@
android:layout_width="90dp"
android:layout_height="45dp" />
</LinearLayout>
<FrameLayout
android:id="@+id/attention_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/chat_message_bg"
android:visibility="gone">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="9dp"
android:scaleType="centerCrop" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="48dp"
android:layout_marginEnd="73dp"
android:text="@string/automatic_chat"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<ImageView
android:id="@+id/btn_attention"
android:layout_width="54dp"
android:layout_height="26dp"
android:layout_gravity="end"
android:layout_margin="11dp"
android:clickable="true"
android:focusable="true"
android:src="@mipmap/btn_attention" />
</FrameLayout>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -70,6 +70,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* Created by cxf on 2018/9/22.
@ -302,8 +303,15 @@ public class MainMeViewHolder extends AbsMainViewHolder implements OnItemClickLi
user_noble_time.setText(mContext.getResources().getString(R.string.open_noble_text));
}
String singnature = u.getSignature();
if (TextUtils.equals(singnature, "這個人很懶,什麼也沒留下") ||TextUtils.equals(singnature, "这家伙很懒,什么都没留下") || TextUtils.isEmpty(singnature)) {
singnature ="The guy was lazy and didn't write anything.";
if (TextUtils.equals(singnature, "這個人很懶,什麼也沒留下") || TextUtils.equals(singnature, "这家伙很懒,什么都没留下") || TextUtils.isEmpty(singnature)) {
String ct = Locale.getDefault().getCountry();
ct = TextUtils.equals("CN", ct) ? "HK" : ct;
if (TextUtils.equals(ct, "CN")) {
singnature = "這個人很懶,什麼也沒留下";
} else {
singnature = "The guy was lazy and didn't write anything.";
}
}
signature.setText(singnature);
CommonAppConfig appConfig = CommonAppConfig.getInstance();