diff --git a/common/src/main/java/com/yunbao/common/bean/NewGuardLevelModel.java b/common/src/main/java/com/yunbao/common/bean/NewGuardLevelModel.java new file mode 100644 index 000000000..8433114de --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/NewGuardLevelModel.java @@ -0,0 +1,37 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class NewGuardLevelModel extends BaseModel{ + + @SerializedName("guard_type") + private int guardType; + @SerializedName("cn") + private String cn; + @SerializedName("en") + private String en; + + public int getGuardType() { + return guardType; + } + + public void setGuardType(int guardType) { + this.guardType = guardType; + } + + public String getCn() { + return cn; + } + + public void setCn(String cn) { + this.cn = cn; + } + + public String getEn() { + return en; + } + + public void setEn(String en) { + this.en = en; + } +} diff --git a/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java b/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java index 444ce4b92..f7ed008c6 100644 --- a/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/CommonHttpUtil.java @@ -208,6 +208,10 @@ public class CommonHttpUtil { JSONArray levelArray = obj.getJSONArray("liveclass"); new LiveClassManager(context).UpDataLiveClass(levelArray.toJSONString()); } + if (obj.containsKey("guard_type")) { + JSONArray levelArray = obj.getJSONArray("guard_type"); + new NewLevelManager(context).upDataGuardLevel(levelArray.toJSONString()); + } if (obj.containsKey("apk_ver")) { APKManager.get().setApkVer(obj.getString("apk_ver")); } diff --git a/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java b/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java index 62585d204..28c6fb71f 100644 --- a/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java +++ b/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java @@ -54,6 +54,15 @@ public class IMLoginManager extends BaseCacheManager { private final String KEY_LANGUAGE = "language"; private final String KEY_GAME = "key_game"; + private final String GUARD_TYPE = "key_GUARD_TYPE"; + + public void setGuardType(int guardType) { + put(GUARD_TYPE, guardType); + } + + public int getGuardType() { + return getInt(GUARD_TYPE, 0); + } public void setRedPoint() { put("RedPoint", "1"); diff --git a/common/src/main/java/com/yunbao/common/manager/NewLevelManager.java b/common/src/main/java/com/yunbao/common/manager/NewLevelManager.java index 359dc032d..86ad9039b 100644 --- a/common/src/main/java/com/yunbao/common/manager/NewLevelManager.java +++ b/common/src/main/java/com/yunbao/common/manager/NewLevelManager.java @@ -5,6 +5,7 @@ import android.content.Context; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.yunbao.common.bean.FansModel; +import com.yunbao.common.bean.NewGuardLevelModel; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.manager.base.BaseCacheManager; @@ -19,10 +20,12 @@ public class NewLevelManager extends BaseCacheManager { private final String KEY_ANCHOR_LEVEL = "keyAnchorLevel"; private final String KEY_LIVE_LEVEL = "keyLiveLevel"; private final String KEY_FANS_LEVEL = "keyFansLevel"; + private final String KEY_GUARD_LEVEL = "keyGuardLevel"; private List newLevelModels = new ArrayList<>(); private List keyAnchorLevel = new ArrayList<>(); private List fansModels = new ArrayList<>(); + private List newGuardLevelModels = new ArrayList<>(); public NewLevelManager(Context context) { super(context); @@ -62,6 +65,29 @@ public class NewLevelManager extends BaseCacheManager { return fansModel; } + public void upDataGuardLevel(String json) { + newGuardLevelModels = new Gson().fromJson(json, new TypeToken>() { + }.getType()); + put(KEY_GUARD_LEVEL, newGuardLevelModels); + } + + public List getGuardLevel() { + newGuardLevelModels = getList(KEY_GUARD_LEVEL, new TypeToken>() { + }.getType()); + return newGuardLevelModels; + } + + public NewGuardLevelModel getGuardModel(int type) { + getGuardLevel(); + NewGuardLevelModel guardLevelModel = null; + for (NewGuardLevelModel model : newGuardLevelModels) { + if (model.getGuardType() == type) { + guardLevelModel = model; + } + } + return guardLevelModel; + } + /** * 获取等级数据 * diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java index ee76c9d37..2a94111d3 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java @@ -286,7 +286,7 @@ public class LiveBuyGuardDialog extends AbsDialogPopupWindow { .isDestroyOnDismiss(true) .isLightStatusBar(false) .popupPosition(PopupPosition.Top) - .asCustom(new LiveBuyGuardSelectPopup(getContext(), price,guardPriceModel) + .asCustom(new LiveBuyGuardSelectPopup(getContext(), price, guardPriceModel) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -373,6 +373,7 @@ public class LiveBuyGuardDialog extends AbsDialogPopupWindow { } }).build().show(); } else { + IMLoginManager.get(mContext).setGuardType(dataTipModel.getGuardType()); ToastUtil.show(data); dismiss(); if (dataTipModel.getGuardType() == 3) { diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java index 25171f7d0..6192c56cc 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyChatUtil.java @@ -102,7 +102,7 @@ public class SocketRyChatUtil { .param("uid", u.getId()) .param("liangname", u.getGoodName()) .param("vip_type", u.getVip().getType()) - .param("guard_type", guardType) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) .param("medal_name", u.getMedalName()) .param("medal_level", model.getMedalLevel()) .param("good_num", u.getGoodnum()) @@ -180,7 +180,7 @@ public class SocketRyChatUtil { .param("bubble", u.getDress().getBubble()) .param("medal", u.getDress().getMedal()) .param("medal_new", u.getDress().getMedal_new()) - .param("guard_type", guardType) + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()) .param("medal_name", u.getMedalName()) .param("medal_level", u.getMedalLevel()) .param("good_num", u.getGoodnum()) @@ -716,7 +716,7 @@ public class SocketRyChatUtil { .param("uhead", u.getAvatar()) .param("votestotal", votes) .param("guard_nums", guardNum) - .param("guard_type", guardType); + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()); msg.create(); } @@ -742,7 +742,7 @@ public class SocketRyChatUtil { .param("bubble", u.getDress().getBubble()) .param("medal", u.getDress().getMedal()) .param("medal_new", u.getDress().getMedal_new()) - .param("guard_type", guardType); + .param("guard_type", IMLoginManager.get(CommonAppContext.sInstance.getApplicationContext()).getGuardType()); msg.create(); } 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 9b599b029..a6f75a2b8 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -391,7 +391,7 @@ public class SocketRyClient { } else if (action2 == 61) {//赠送礼物 sendGiftByNotify(map); } else if (action2 == 62) {//购买守护 - buyGuardByNotify(map); +// buyGuardByNotify(map); // }else if (action2 == 63){ } else if (action2 == 63) {//购买vip buyVipByNotify(map); @@ -443,6 +443,7 @@ public class SocketRyClient { } else if (action2 == 90) { NewAllServerNotifyGuardEvent notifyGuardEvent = GsonUtils.fromJson(map.toString(), NewAllServerNotifyGuardEvent.class); Bus.get().post(notifyGuardEvent); + buyGuardInSameRoom(map); } break; case Constants.SOCKET_SEND_BARRAGE://发弹幕 @@ -820,16 +821,16 @@ public class SocketRyClient { } private void buyGuardInSameRoom(JSONObject map) { - String guardName = WordUtil.isNewZh() ? "周守護" : "Week Guardian"; + String guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; switch (map.getIntValue("guard_type")) { case 1: - guardName = WordUtil.isNewZh() ? "周守護" : "Week Guardian"; + guardName = WordUtil.isNewZh() ? "星之守護" : "Star Guardian"; break; case 2: - guardName = WordUtil.isNewZh() ? "月守護" : "Month Guardian"; + guardName = WordUtil.isNewZh() ? "王之守護" : "King Guardian"; break; case 3: - guardName = WordUtil.isNewZh() ? "年守護" : "Year Guardian"; + guardName = WordUtil.isNewZh() ? "神之守護" : "God Guardian"; break; } String content = WordUtil.isNewZh() ? "%s在%s的直播間開通了%s" : "%s has been opened in %s live broadcast room %s"; @@ -845,7 +846,7 @@ public class SocketRyClient { private void buyGuardByNotify(JSONObject map) { if (mLiveUid.equals(map.getString("liveuid"))) { - buyGuardInSameRoom(map); +// buyGuardInSameRoom(map); //同一直播间,玩家自己开通,也能看到全服通知 String userId = CommonAppConfig.getInstance().getUid(); String uid = map.getString("uid"); diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index 33b049c19..d7fa2ed03 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -32,9 +32,9 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; import com.yunbao.common.CommonAppContext; -import com.yunbao.common.Constants; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; +import com.yunbao.common.bean.NewGuardLevelModel; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.custom.VerticalImageSpan; import com.yunbao.common.glide.ImgLoader; @@ -262,95 +262,170 @@ public class LiveTextRender { } + public interface CreatePrefixCallback { + void onPrefixCallback(SpannableStringBuilder builder); + } + /** * 生成前缀 */ - private SpannableStringBuilder createPrefix(Drawable levelDrawable, LiveChatBean bean) { - SpannableStringBuilder builder = new SpannableStringBuilder(); - int index = 0; + private void createPrefix(Drawable levelDrawable, LiveChatBean bean, CreatePrefixCallback createPrefixCallback) { - if (levelDrawable != null) { - builder.append(" "); - 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(); - } - if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); - gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); - builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); - } +// if (bean.getGuardType() != Constants.GUARD_TYPE_NONE) {//守护图标 +// Drawable drawable; +// if (bean.getGuardType() == Constants.GUARD_TYPE_MONTH) { +// drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_1); +// } else if (bean.getGuardType() == Constants.GUARD_TYPE_YEAR) { +// drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_2); +// } else { +// drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_0); +// } + getGuardImage(CommonAppContext.sInstance, bean.getGuardType(), new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { + SpannableStringBuilder builder = new SpannableStringBuilder(); + int index = 0; - if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); - ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); - builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); - } + if (levelDrawable != null) { + builder.append(" "); + 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(); + } - if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); - nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); - builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); - } + if (gzDrawablesMap.containsKey(bean)) {//贵族 + builder.append(" "); + gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); + builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } - if (bean.getGuardType() != Constants.GUARD_TYPE_NONE) {//守护图标 - Drawable drawable; - if (bean.getGuardType() == Constants.GUARD_TYPE_MONTH) { - drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_1); - } else if (bean.getGuardType() == Constants.GUARD_TYPE_YEAR) { - drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_2); - } else { - drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_guard_type_0); + if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 + builder.append(" "); + ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); + builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + + if (nhDrawablesMap.containsKey(bean)) {//靓号 + builder.append(" "); + nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + //在这里添加粉丝徽章的图片 + if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) + && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 + Drawable drawable2 = getMedalImage(bean); + if (drawable2 != null) { + builder.append(" "); + drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + } + + + if (bean.isManager()) {//直播间管理员图标 + Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); + if (drawable3 != null) { + builder.append(" "); + drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); + builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + } + + if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 + Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); + if (drawable4 != null) { + builder.append(" "); + drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); + builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + // new add + index = builder.length(); + } + } + createPrefixCallback.onPrefixCallback(builder); } - if (drawable != null) { - builder.append(" "); - drawable.setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(16)); - builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); + @Override + public void onLoadFailed() { + SpannableStringBuilder builder = new SpannableStringBuilder(); + int index = 0; + + if (levelDrawable != null) { + builder.append(" "); + 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(); + } + + if (gzDrawablesMap.containsKey(bean)) {//贵族 + builder.append(" "); + gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); + builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + + if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 + builder.append(" "); + ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); + builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + + if (nhDrawablesMap.containsKey(bean)) {//靓号 + builder.append(" "); + nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + //在这里添加粉丝徽章的图片 + if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) + && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 + Drawable drawable = getMedalImage(bean); + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + } + + + if (bean.isManager()) {//直播间管理员图标 + Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + } + } + + if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 + Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + // new add + index = builder.length(); + } + } + createPrefixCallback.onPrefixCallback(builder); } - } - - //在这里添加粉丝徽章的图片 - if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) - && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 - Drawable drawable = getMedalImage(bean); - if (drawable != null) { - builder.append(" "); - drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); - builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); - } - } + }); - if (bean.isManager()) {//直播间管理员图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); - if (drawable != null) { - builder.append(" "); - drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); - builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - index = builder.length(); - } - } - - if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 - Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); - if (drawable != null) { - builder.append(" "); - drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); - builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - // new add - index = builder.length(); - } - } - - - return builder; } private Drawable getMedalImage(final LiveChatBean bean) { @@ -439,6 +514,36 @@ public class LiveTextRender { }); } + public void getGuardImage(Context mContext, int guardType, ImgLoader.DrawableCallback callback) { + if (guardType==0){ + callback.onLoadFailed(); + }else { + if (mContext instanceof Activity) { + if (((Activity) mContext).isDestroyed()) { + mContext = CommonAppContext.getTopActivity(); + } + } + List models = new NewLevelManager(mContext).getGuardLevel(); + String imgUrl = WordUtil.isNewZh() ? "https://downs.yaoulive.com/%E6%98%9F%E4%B9%8B%E5%AE%88%E6%8A%A4%E9%93%AD%E7%89%8C.png" : "https://downs.yaoulive.com/%E6%98%9F%E5%AE%88%E9%8A%98%E7%89%8C-2.png"; + for (NewGuardLevelModel newGuardLevelModel : models) { + if (newGuardLevelModel.getGuardType() == guardType) { + imgUrl = WordUtil.isNewZh() ? newGuardLevelModel.getCn() : newGuardLevelModel.getEn(); + } + } + ImgLoader.displayDrawable(mContext, imgUrl, new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { + callback.onLoadSuccess(drawable); + } + + @Override + public void onLoadFailed() { + callback.onLoadFailed(); + } + }); + } + + } /** * 等级设置 @@ -576,42 +681,53 @@ public class LiveTextRender { getLiveLevelImage(context, bean.getLevel(), false, new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { - SpannableStringBuilder builder = createPrefix(drawable, bean); - int color = Color.parseColor("#68F1F4"); - if (bean.isAnchor()) { - color = Color.parseColor("#FBEABF"); - } else { - color = Color.parseColor("#68F1F4"); - } - switch (bean.getType()) { - case LiveChatBean.GIFT: - builder = renderGift(color, builder, bean); - break; - default: - builder = renderChat(color, builder, bean); - break; - } - textView.setText(builder); + + createPrefix(drawable, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder) { + int color = Color.parseColor("#68F1F4"); + if (bean.isAnchor()) { + color = Color.parseColor("#FBEABF"); + } else { + color = Color.parseColor("#68F1F4"); + } + switch (bean.getType()) { + case LiveChatBean.GIFT: + builder = renderGift(color, builder, bean); + break; + default: + builder = renderChat(color, builder, bean); + break; + } + textView.setText(builder); + } + }); + } @Override public void onLoadFailed() { - SpannableStringBuilder builder = createPrefix(null, bean); - int color = 0; - if (bean.isAnchor()) { - color = 0xffffdd00; - } else { - color = Color.parseColor("#68F1F4"); - } - switch (bean.getType()) { - case LiveChatBean.GIFT: - builder = renderGift(color, builder, bean); - break; - default: - builder = renderChat(color, builder, bean); - break; - } - textView.setText(builder); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder) { + int color = 0; + if (bean.isAnchor()) { + color = 0xffffdd00; + } else { + color = Color.parseColor("#68F1F4"); + } + switch (bean.getType()) { + case LiveChatBean.GIFT: + builder = renderGift(color, builder, bean); + break; + default: + builder = renderChat(color, builder, bean); + break; + } + textView.setText(builder); + } + }); + } }); @@ -771,23 +887,33 @@ public class LiveTextRender { @Override public void onLoadSuccess(Drawable drawable) { if (textView != null) { - SpannableStringBuilder builder = createPrefix(drawable, bean); - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - builder.append(bean.getContent()); - textView.setText(builder); + createPrefix(drawable, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + builder.append(bean.getContent()); + textView.setText(builder); + } + }); + } } @Override public void onLoadFailed() { if (textView != null) { - SpannableStringBuilder builder = createPrefix(null, bean); - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - textView.setText(builder); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + textView.setText(builder); + } + }); + } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 6d952b43d..0d03a89a0 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -393,6 +393,12 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private LinearLayout combo_layout; private TextView combo_number; private View quick_gift_reminder; + private int guardType = 0; + + public LiveRoomViewHolder setGuardType(int guardType) { + this.guardType = guardType; + return this; + } @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 8d4c35790..87b56ad96 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -696,6 +696,17 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe upDataPkScore(pkInfo.getJSONArray("userlist"), pkInfo.getIntValue("drpk_time")); } + if (data.getGuardUserAvatar() != null) { + if (mLiveRoomViewHolder != null) { + if (TextUtils.isEmpty(data.getGuardUserAvatar().getGuardType())) { + mLiveRoomViewHolder.setGuardType(0); + } else { + int guardType = Integer.parseInt(data.getGuardUserAvatar().getGuardType()); + IMLoginManager.get(mContext).setGuardType(guardType); + } + + } + } // mLivePlayViewHolder.setLayoutInterface(new LivePlayRyViewHolder.PlayViewLayoutInterface() { // @Override // public void playViewLayout(int width, int height) { @@ -2228,8 +2239,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.onSendMoneyLongEndEvent(moneyLongEndEvent); } } - public void onGuardRed(){ - if (mLiveAudienceViewHolder!=null){ + + public void onGuardRed() { + if (mLiveAudienceViewHolder != null) { mLiveAudienceViewHolder.onGuardRed(); } }