红包全服通知

This commit is contained in:
18401019693 2023-07-04 16:02:45 +08:00
parent f417e4ead8
commit cbe91c84e9
9 changed files with 152 additions and 28 deletions

View File

@ -34,6 +34,17 @@ public class AllServerNotifyEvent extends BaseModel {
//主播名字 //主播名字
@SerializedName("ancherName") @SerializedName("ancherName")
private String anchorName; private String anchorName;
// 是否是红包
private boolean isRedPacket = false;
public boolean isRedPacket() {
return isRedPacket;
}
public AllServerNotifyEvent setRedPacket(boolean redPacket) {
isRedPacket = redPacket;
return this;
}
public String getAnchorName() { public String getAnchorName() {
return anchorName; return anchorName;

View File

@ -0,0 +1,52 @@
package com.yunbao.common.views;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.style.ImageSpan;
import org.jetbrains.annotations.NotNull;
public class CenterImageSpan extends ImageSpan {
public CenterImageSpan(Drawable arg1) {
super(arg1);
}
public int getSize(@NotNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
Drawable d = getDrawable();
Rect rect = d.getBounds();
if (fm != null) {
Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
int fontHeight = fmPaint.bottom - fmPaint.top;
int drHeight = rect.bottom - rect.top;
int top = drHeight / 2 - fontHeight / 4;
int bottom = drHeight / 2 + fontHeight / 4;
fm.ascent = -bottom;
fm.top = -bottom;
fm.bottom = top;
fm.descent = top;
}
return rect.right;
}
@Override
public void draw(@NotNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NotNull Paint paint) {
Drawable b = getDrawable();
canvas.save();
int transY = 0;
transY = ((bottom - top) - b.getBounds().bottom) / 2 + top;
canvas.translate(x, transY);
b.draw(canvas);
canvas.restore();
}
}

View File

@ -1247,4 +1247,5 @@ Limited ride And limited avatar frame</string>
<string name="red_too_bad">很遺憾</string> <string name="red_too_bad">很遺憾</string>
<string name="red_too_bad2">與紅包擦肩而過</string> <string name="red_too_bad2">與紅包擦肩而過</string>
<string name="check_out_your_luck">查看大家手氣</string> <string name="check_out_your_luck">查看大家手氣</string>
<string name="lucky_red_envelope"> %s 在 好運紅包 中抽到了 %s</string>
</resources> </resources>

View File

@ -19,8 +19,8 @@ org.gradle.configureondemand=true
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
systemProp.http.proxyHost=127.0.0.1 #systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyHost=127.0.0.1 #systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890 #systemProp.https.proxyPort=7890
systemProp.http.proxyPort=7890 #systemProp.http.proxyPort=7890
#android.enableR8.fullMode=true #android.enableR8.fullMode=true

View File

@ -913,6 +913,12 @@ public class LiveGiftAnimPresenter {
mGifGiftTipGroupAllServer.setVisibility(View.VISIBLE); mGifGiftTipGroupAllServer.setVisibility(View.VISIBLE);
AllServerNotifyEvent serverNotifyEvent = bean.getEvent(); AllServerNotifyEvent serverNotifyEvent = bean.getEvent();
if (serverNotifyEvent.isRedPacket()) {
mIvLook.setVisibility(View.GONE);
bgAllServer.setBackgroundResource(R.mipmap.backdrop_luck);
superNotice.setBackgroundResource(R.mipmap.icon_luck);
textRender.redPacket(mContext, mGifGiftTipAllServer, serverNotifyEvent);
} else {
switch (Integer.parseInt(serverNotifyEvent.getBoxType())) { switch (Integer.parseInt(serverNotifyEvent.getBoxType())) {
case 1: case 1:
bgAllServer.setBackgroundResource(R.mipmap.bg_kirin_notify); bgAllServer.setBackgroundResource(R.mipmap.bg_kirin_notify);
@ -922,15 +928,17 @@ public class LiveGiftAnimPresenter {
bgAllServer.setBackgroundResource(R.mipmap.bg_phoenix_notify); bgAllServer.setBackgroundResource(R.mipmap.bg_phoenix_notify);
mIvLook.setBackgroundResource(R.drawable.bg_all_server_fd5a9d); mIvLook.setBackgroundResource(R.drawable.bg_all_server_fd5a9d);
break; break;
default: default:
bgAllServer.setBackgroundResource(R.mipmap.bg_dragon_notify); bgAllServer.setBackgroundResource(R.mipmap.bg_dragon_notify);
mIvLook.setBackgroundResource(R.drawable.bg_all_server_fcb50e); mIvLook.setBackgroundResource(R.drawable.bg_all_server_fcb50e);
break; break;
} }
mIvLook.setText(R.string.participate_in); mIvLook.setText(R.string.participate_in);
superNotice.setBackgroundResource(R.mipmap.icon_blind_box_headlines);
mIvLook.setVisibility(View.VISIBLE); mIvLook.setVisibility(View.VISIBLE);
superNotice.setBackgroundResource(R.mipmap.icon_blind_box_headlines);
textRender.blindBoxText(mContext, mGifGiftTipAllServer, serverNotifyEvent); textRender.blindBoxText(mContext, mGifGiftTipAllServer, serverNotifyEvent);
}
mGifGiftTipShowAnimatorAllServer.start(); mGifGiftTipShowAnimatorAllServer.start();
mGifGiftTipAllServer.postDelayed(() -> { mGifGiftTipAllServer.postDelayed(() -> {
if (mGifGiftTipAllServer != null) { if (mGifGiftTipAllServer != null) {

View File

@ -384,6 +384,17 @@ public class SocketRyClient {
Bus.get().post(new LiveAudienceEvent() Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX) .setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX)
.setAllServerNotifyEvent(allServerNotifyEvent)); .setAllServerNotifyEvent(allServerNotifyEvent));
} else if (action2 == 89) {//红包
JSONObject mCt = map.getJSONObject("ct");
AllServerNotifyEvent allServerNotifyEvent
= new AllServerNotifyEvent()
.setUserNiceName(mCt.getString("user_nicename"))
.setGiftName(mCt.getString("giftname"))
.setGiftIcon(mCt.getString("gifticon"))
.setRedPacket(true);
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX)
.setAllServerNotifyEvent(allServerNotifyEvent));
} }
break; break;
case Constants.SOCKET_SEND_BARRAGE://发弹幕 case Constants.SOCKET_SEND_BARRAGE://发弹幕

View File

@ -15,6 +15,7 @@ import com.yunbao.common.custom.VerticalImageSpan;
import com.yunbao.common.event.AllServerNotifyEvent; import com.yunbao.common.event.AllServerNotifyEvent;
import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.views.CenterImageSpan;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.presenter.LiveGiftAnimPresenter; import com.yunbao.live.presenter.LiveGiftAnimPresenter;
@ -128,6 +129,46 @@ public class AllMsgTextRender {
} }
} }
public void redPacket(Context context, TextView textView, AllServerNotifyEvent serverNotifyEvent) {
String space = " ";
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
String extractTo = context.getString(R.string.lucky_red_envelope);
extractTo = String.format(extractTo, serverNotifyEvent.getUserNiceName(), serverNotifyEvent.getGiftName());
spannableStringBuilder.append(extractTo);
int indexImage = spannableStringBuilder.length();
int endImage = indexImage + space.length();
spannableStringBuilder.append(space);
int giftNameIndex = spannableStringBuilder.toString().indexOf(serverNotifyEvent.getGiftName());
int endName = giftNameIndex + serverNotifyEvent.getGiftName().length();
ImgLoader.displayDrawable(context, serverNotifyEvent.getGiftIcon(), new ImgLoader.DrawableCallback() {
@Override
public void onLoadSuccess(Drawable drawable) {
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FBC870")),
giftNameIndex,
endName,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
drawable.setBounds(0, 0, DpUtil.dp2px(25), DpUtil.dp2px(25));
//用这个drawable对象代替字符串easy
CenterImageSpan span = new CenterImageSpan(drawable);
spannableStringBuilder.setSpan(span, indexImage, endImage, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(spannableStringBuilder);
}
@Override
public void onLoadFailed() {
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FBC870")),
giftNameIndex,
endName,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableStringBuilder);
}
});
}
/** /**
* 盲盒字体组装 * 盲盒字体组装
* *

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB