diff --git a/common/src/main/java/com/yunbao/common/event/AllServerNotifyEvent.java b/common/src/main/java/com/yunbao/common/event/AllServerNotifyEvent.java
index c4baf0d10..c4580cd8b 100644
--- a/common/src/main/java/com/yunbao/common/event/AllServerNotifyEvent.java
+++ b/common/src/main/java/com/yunbao/common/event/AllServerNotifyEvent.java
@@ -34,6 +34,17 @@ public class AllServerNotifyEvent extends BaseModel {
//主播名字
@SerializedName("ancherName")
private String anchorName;
+ // 是否是红包
+ private boolean isRedPacket = false;
+
+ public boolean isRedPacket() {
+ return isRedPacket;
+ }
+
+ public AllServerNotifyEvent setRedPacket(boolean redPacket) {
+ isRedPacket = redPacket;
+ return this;
+ }
public String getAnchorName() {
return anchorName;
@@ -137,6 +148,6 @@ public class AllServerNotifyEvent extends BaseModel {
", blindBoxId='" + blindBoxId + '\'' + "\n" +
", boxType='" + boxType + '\'' + "\n" +
", displaySrc='" + displaySrc + '\'' + "\n" +
- '}' + "\n" ;
+ '}' + "\n";
}
}
diff --git a/common/src/main/java/com/yunbao/common/views/CenterImageSpan.java b/common/src/main/java/com/yunbao/common/views/CenterImageSpan.java
new file mode 100644
index 000000000..73b6ed654
--- /dev/null
+++ b/common/src/main/java/com/yunbao/common/views/CenterImageSpan.java
@@ -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();
+ }
+}
+
+
diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml
index 118d24ee2..dfc5465a4 100644
--- a/common/src/main/res/values/strings.xml
+++ b/common/src/main/res/values/strings.xml
@@ -1247,4 +1247,5 @@ Limited ride And limited avatar frame
很遺憾
與紅包擦肩而過
查看大家手氣
+ %s 在 好運紅包 中抽到了 %s
diff --git a/gradle.properties b/gradle.properties
index 3265ac671..a5066c177 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -19,8 +19,8 @@ org.gradle.configureondemand=true
android.useAndroidX=true
android.enableJetifier=true
-systemProp.http.proxyHost=127.0.0.1
-systemProp.https.proxyHost=127.0.0.1
-systemProp.https.proxyPort=7890
-systemProp.http.proxyPort=7890
+#systemProp.http.proxyHost=127.0.0.1
+#systemProp.https.proxyHost=127.0.0.1
+#systemProp.https.proxyPort=7890
+#systemProp.http.proxyPort=7890
#android.enableR8.fullMode=true
\ No newline at end of file
diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java
index f0e3bfa81..214e22522 100644
--- a/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java
+++ b/live/src/main/java/com/yunbao/live/presenter/LiveGiftAnimPresenter.java
@@ -913,24 +913,32 @@ public class LiveGiftAnimPresenter {
mGifGiftTipGroupAllServer.setVisibility(View.VISIBLE);
AllServerNotifyEvent serverNotifyEvent = bean.getEvent();
- switch (Integer.parseInt(serverNotifyEvent.getBoxType())) {
- case 1:
- bgAllServer.setBackgroundResource(R.mipmap.bg_kirin_notify);
- mIvLook.setBackgroundResource(R.drawable.bg_all_server_336cf7);
- break;
- case 2:
- bgAllServer.setBackgroundResource(R.mipmap.bg_phoenix_notify);
- mIvLook.setBackgroundResource(R.drawable.bg_all_server_fd5a9d);
- break;
- default:
- bgAllServer.setBackgroundResource(R.mipmap.bg_dragon_notify);
- mIvLook.setBackgroundResource(R.drawable.bg_all_server_fcb50e);
- break;
+ 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())) {
+ case 1:
+ bgAllServer.setBackgroundResource(R.mipmap.bg_kirin_notify);
+ mIvLook.setBackgroundResource(R.drawable.bg_all_server_336cf7);
+ break;
+ case 2:
+ bgAllServer.setBackgroundResource(R.mipmap.bg_phoenix_notify);
+ mIvLook.setBackgroundResource(R.drawable.bg_all_server_fd5a9d);
+ break;
+
+ default:
+ bgAllServer.setBackgroundResource(R.mipmap.bg_dragon_notify);
+ mIvLook.setBackgroundResource(R.drawable.bg_all_server_fcb50e);
+ break;
+ }
+ mIvLook.setText(R.string.participate_in);
+ mIvLook.setVisibility(View.VISIBLE);
+ superNotice.setBackgroundResource(R.mipmap.icon_blind_box_headlines);
+ textRender.blindBoxText(mContext, mGifGiftTipAllServer, serverNotifyEvent);
}
- mIvLook.setText(R.string.participate_in);
- superNotice.setBackgroundResource(R.mipmap.icon_blind_box_headlines);
- mIvLook.setVisibility(View.VISIBLE);
- textRender.blindBoxText(mContext, mGifGiftTipAllServer, serverNotifyEvent);
mGifGiftTipShowAnimatorAllServer.start();
mGifGiftTipAllServer.postDelayed(() -> {
if (mGifGiftTipAllServer != null) {
diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java
index 66360c995..427a8439a 100644
--- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java
+++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java
@@ -384,6 +384,17 @@ public class SocketRyClient {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.BLIND_BOX)
.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;
case Constants.SOCKET_SEND_BARRAGE://发弹幕
@@ -834,7 +845,7 @@ public class SocketRyClient {
chatBean.setContentColor(map.getString("contentColor"));//文字内容颜色
chatBean.setAtUserName(map.getString("atUserName"));//@名字
chatBean.setAtUserID(map.getString("atUserID"));//@ID
- if (map.containsKey("guard_type")&&!map.getString("guard_type").equals("undefined")) {
+ if (map.containsKey("guard_type") && !map.getString("guard_type").equals("undefined")) {
chatBean.setGuardType(map.getIntValue("guard_type"));
}
try {
diff --git a/live/src/main/java/com/yunbao/live/utils/AllMsgTextRender.java b/live/src/main/java/com/yunbao/live/utils/AllMsgTextRender.java
index 8c3d979b5..2f82bff2e 100644
--- a/live/src/main/java/com/yunbao/live/utils/AllMsgTextRender.java
+++ b/live/src/main/java/com/yunbao/live/utils/AllMsgTextRender.java
@@ -15,6 +15,7 @@ import com.yunbao.common.custom.VerticalImageSpan;
import com.yunbao.common.event.AllServerNotifyEvent;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.DpUtil;
+import com.yunbao.common.views.CenterImageSpan;
import com.yunbao.live.R;
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);
+ }
+ });
+ }
+
/**
* 盲盒字体组装
*
@@ -161,12 +202,12 @@ public class AllMsgTextRender {
//用这个drawable对象代替字符串easy
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
spannableStringBuilder.setSpan(span, indexImage, endImage, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
- blind(spannableStringBuilder,textView,serverNotifyEvent,giftNameIndex,endName);
+ blind(spannableStringBuilder, textView, serverNotifyEvent, giftNameIndex, endName);
}
@Override
public void onLoadFailed() {
- blind(spannableStringBuilder,textView,serverNotifyEvent,giftNameIndex,endName);
+ blind(spannableStringBuilder, textView, serverNotifyEvent, giftNameIndex, endName);
}
});
} else {
@@ -181,19 +222,19 @@ public class AllMsgTextRender {
//用这个drawable对象代替字符串easy
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
spannableStringBuilder.setSpan(span, indexImage, endImage, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
- blind(spannableStringBuilder,textView,serverNotifyEvent,giftNameIndex,endName);
+ blind(spannableStringBuilder, textView, serverNotifyEvent, giftNameIndex, endName);
}
@Override
public void onLoadFailed() {
- blind(spannableStringBuilder,textView,serverNotifyEvent,giftNameIndex,endName);
+ blind(spannableStringBuilder, textView, serverNotifyEvent, giftNameIndex, endName);
}
});
}
}
- private void blind( SpannableStringBuilder spannableStringBuilder, TextView textView, AllServerNotifyEvent serverNotifyEvent, int giftNameIndex,int endName) {
+ private void blind(SpannableStringBuilder spannableStringBuilder, TextView textView, AllServerNotifyEvent serverNotifyEvent, int giftNameIndex, int endName) {
switch (Integer.parseInt(serverNotifyEvent.getBoxType())) {
case 1:
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#336DF7")),
diff --git a/live/src/main/res/mipmap-mdpi/backdrop_luck.png b/live/src/main/res/mipmap-mdpi/backdrop_luck.png
new file mode 100644
index 000000000..e3d2e84b4
Binary files /dev/null and b/live/src/main/res/mipmap-mdpi/backdrop_luck.png differ
diff --git a/live/src/main/res/mipmap-mdpi/icon_luck.png b/live/src/main/res/mipmap-mdpi/icon_luck.png
new file mode 100644
index 000000000..cc92f11fe
Binary files /dev/null and b/live/src/main/res/mipmap-mdpi/icon_luck.png differ