From 82fd35305a447d36c2334b4782165f85585db804 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Tue, 5 Sep 2023 13:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=8B=E7=82=B9=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/bean/LiveGiftBean.java | 24 ++- .../com/yunbao/common/http/LiveHttpUtil.java | 30 ++-- common/src/main/res/values/strings.xml | 2 + .../yunbao/live/adapter/FrameGiftAdapter.java | 10 ++ .../java/com/yunbao/live/bean/CoinModel.java | 15 +- .../com/yunbao/live/dialog/LiveGiftPopup.java | 149 +++++++++++++++--- .../live/event/LiveGiftItemRefreshEvent.java | 17 ++ .../yunbao/live/views/LiveGiftFragment.java | 7 + .../live/views/LiveGiftItemFragment.java | 5 + 9 files changed, 218 insertions(+), 41 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/event/LiveGiftItemRefreshEvent.java diff --git a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java index 2dac9e946..31c65e757 100644 --- a/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java +++ b/common/src/main/java/com/yunbao/common/bean/LiveGiftBean.java @@ -66,6 +66,28 @@ public class LiveGiftBean { private String namingCoin; @JSONField(name = "naming_user_coin") private String namingUserCoin; + @JSONField(name = "blind_box_ticket") + private int blindBoxTicket; + @JSONField(name = "blind_box_ticket_id") + private int blindBoxTicketId; + + public int getBlindBoxTicketId() { + return blindBoxTicketId; + } + + public LiveGiftBean setBlindBoxTicketId(int blindBoxTicketId) { + this.blindBoxTicketId = blindBoxTicketId; + return this; + } + + public int getBlindBoxTicket() { + return blindBoxTicket; + } + + public LiveGiftBean setBlindBoxTicket(int blindBoxTicket) { + this.blindBoxTicket = blindBoxTicket; + return this; + } public String getNamingUserCoin() { return namingUserCoin; @@ -202,7 +224,7 @@ public class LiveGiftBean { return this; } - private int fansGiftLevel=0;//粉丝团礼物等级要求 + private int fansGiftLevel = 0;//粉丝团礼物等级要求 public int getFansGiftLevel() { return fansGiftLevel; diff --git a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java index 77deacb8a..7de5fd2cf 100644 --- a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java +++ b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java @@ -6,10 +6,6 @@ import com.lzy.okgo.request.GetRequest; import com.lzy.okgo.request.PostRequest; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; -import com.yunbao.common.http.CommonHttpUtil; -import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.JsonBean; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.L; import com.yunbao.common.utils.MD5Util; @@ -292,6 +288,7 @@ public class LiveHttpUtil { /** * 主播或管理员禁言 + * * @param time 禁言时间 (分) */ public static void setShutUp(String liveUid, String stream, int type, String touid, String time, HttpCallback callback) { @@ -619,17 +616,19 @@ public class LiveHttpUtil { * 观众给主播送礼物 */ public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, HttpCallback callback) { - sendGift(by, liveUid, stream, giftId, giftCount, 0, false,callback); + sendGift(by, liveUid, stream, giftId, giftCount, 0, false, callback); } - public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, HttpCallback callback) { - sendGift(by, liveUid, stream, giftId, giftCount, isContactGift, false,callback); + + public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, HttpCallback callback) { + sendGift(by, liveUid, stream, giftId, giftCount, isContactGift, false, callback); } + /** * 观众给主播送礼物 * * @param isContactGift 是否为联系方式礼物 */ - public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift,HttpCallback callback) { + public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, boolean isFansGroupGift, HttpCallback callback) { HttpClient.getInstance().get("Live.sendGift", LiveHttpConsts.SEND_GIFT) .params("liveuid", liveUid) .params("stream", stream) @@ -637,7 +636,20 @@ public class LiveHttpUtil { .params("isContactGift", isContactGift) .params("giftcount", giftCount) .params("isprank", by) - .params("fans_exclusive_pack",isFansGroupGift?"1":"0") + .params("fans_exclusive_pack", isFansGroupGift ? "1" : "0") + .params("appVersion", CommonAppConfig.getInstance().getVersion()) + .execute(callback); + } + + public static void sendBlindBoxTicket(String by, String liveUid, String stream, int giftId, HttpCallback callback) { + HttpClient.getInstance().get("Live.sendBlindBoxTicket", LiveHttpConsts.SEND_GIFT) + .params("liveuid", liveUid) + .params("stream", stream) + .params("giftid", giftId) + .params("isContactGift", 0) + .params("giftcount", "1") + .params("isprank", by) + .params("fans_exclusive_pack", "0") .params("appVersion", CommonAppConfig.getInstance().getVersion()) .execute(callback); } diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 0fd4498e8..36c81b4e1 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1313,5 +1313,7 @@ Limited ride And limited avatar frame cancel settings Too many gifts + 是否使用試用劵 + 使用鑽石 diff --git a/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java b/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java index 05e78fd3b..3ff3a7269 100644 --- a/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/FrameGiftAdapter.java @@ -66,4 +66,14 @@ public class FrameGiftAdapter extends RecyclerView.Adapter { public int getItemCount() { return giftJson.size(); } + + public void refreshWrapListAfterSend(LiveGiftBean model) { + for (int i = 0; i < giftJson.size(); i++) { + if (giftJson.get(i).getId() == model.getId()) { + int giftNum = giftJson.get(i).getBlindBoxTicket(); + giftJson.get(i).setBlindBoxTicket(giftNum - 1); + } + } + notifyDataSetChanged(); + } } diff --git a/live/src/main/java/com/yunbao/live/bean/CoinModel.java b/live/src/main/java/com/yunbao/live/bean/CoinModel.java index 67e8595e2..b78325dbd 100644 --- a/live/src/main/java/com/yunbao/live/bean/CoinModel.java +++ b/live/src/main/java/com/yunbao/live/bean/CoinModel.java @@ -34,15 +34,20 @@ public class CoinModel extends BaseModel { public String getCoin() { long coinMoney = Long.parseLong(coin); + String coinStr = coin; if (999999999 < coinMoney && coinMoney <= 999999999999L) { - coin = coin.substring(0, coin.length() - 3); - coin = coin + "k"; + coinStr = coinStr.substring(0, coinStr.length() - 3); + coinStr = coinStr + "k"; } if (999999999999L < coinMoney && coinMoney <= 999999999999999L) { - coin = coin.substring(0, coin.length() - 6); - coin = coin + "M"; + coinStr = coinStr.substring(0, coinStr.length() - 6); + coinStr = coinStr + "M"; } - return coin; + return coinStr; + } + + public Long getCoinLong() { + return Long.parseLong(coin); } public CoinModel setCoin(String coin) { diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java index 6422a5f6d..f810fa39a 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java @@ -230,7 +230,36 @@ public class LiveGiftPopup extends AbsDialogFragment { @Override public void onViewClicks() { MobclickAgent.onEvent(mContext, "gif_list_seed_gif", "用户送礼物"); - sendGiftHandler.post(sendGiftRunnble); + + if (liveGiftModel != null && liveGiftModel.getBlindBoxTicket() > 0) { + BigDecimal needcoin = new BigDecimal(liveGiftModel.getPrice()).multiply(new BigDecimal(mCount)); + + if (needcoin.longValue() > diamond) { + + sendBlindBoxTicket(); + } else { + new DialogUitl.Builder(mContext) + .setView(R.layout.dialog_live_unfollow) + .setConfirmString(mContext.getString(R.string.aristocrat_determine)) + .setCancelString(mContext.getString(R.string.use_diamonds)) + .setContent(mContext.getString(R.string.trial_coupon)) + .setClickCallback(new DialogUitl.SimpleCallback2() { + @Override + public void onCancelClick() { + sendGiftHandler.post(sendGiftRunnble); + } + + @Override + public void onConfirmClick(Dialog dialog, String content) { + sendBlindBoxTicket(); + } + }).setCancelable(true).build().show(); + } + + } else { + sendGiftHandler.post(sendGiftRunnble); + } + } }); @@ -453,6 +482,8 @@ public class LiveGiftPopup extends AbsDialogFragment { /** * 获取砖石和金豆余额 */ + long diamond = 0; + private void getCoin() { LiveHttpUtil.getCoin(new HttpCallback() { @Override @@ -462,6 +493,7 @@ public class LiveGiftPopup extends AbsDialogFragment { CoinModel coinModel = GsonUtils.fromJson(info[0], CoinModel.class); goldText.setText(coinModel.getGold()); diamondText.setText(coinModel.getCoin()); + diamond = coinModel.getCoinLong(); lvStr.setText("Lv." + coinModel.getUserLevel()); findViewById(R.id.red_point).setVisibility((!TextUtils.isEmpty(coinModel.getUsersPackRedDot())) && @@ -528,10 +560,66 @@ public class LiveGiftPopup extends AbsDialogFragment { private Runnable sendGiftRunnble = new Runnable() { @Override public void run() { - sendGift(); + if (isWrap && liveGiftModel.getType() == 7) { + sendBlindBoxTicket(); + } else { + sendGift(); + } + } }; + //使用优惠券 + public void sendBlindBoxTicket() { + if (TextUtils.isEmpty(mLiveUid) || + TextUtils.isEmpty(mStream) || + liveGiftModel == null) + return; + + LiveHttpUtil.sendBlindBoxTicket((by != null ? "1" : "0"), + mLiveUid, + mStream, + isWrap ? liveGiftModel.getId() : liveGiftModel.getBlindBoxTicketId(), new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + if (liveGiftModel.getSwf().contains("svga")) { + dismiss(); + } + if (info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + String coin = obj.getString("coin"); + String goldCoin = obj.getString("gold"); + UserBean u = CommonAppConfig.getInstance().getUserBean(); + if (u != null) { + u.setLevel(obj.getIntValue("level")); + //送礼物后更新粉丝徽章等级 + u.setMedalLevel(obj.getIntValue("medal_level")); + u.setMedalName(obj.getString("medal_name")); + u.setCoin(coin); + } + if (diamondText != null) { + diamondText.setText(coin); + } + if (goldText != null) { + goldText.setText(goldCoin); + } + if (!isWrap) { + liveGiftModel.setBlindBoxTicket(liveGiftModel.getBlindBoxTicket() - 1); + } + isGetNewWrap = true; + if (isWrap) { + Bus.get().post(new LiveParcelItemRefreshEvent().setLiveGiftModel(liveGiftModel)); + } + } + } else { + ToastUtil.show(msg); + } + } + + }); + } + /** * 赠送礼物 */ @@ -655,39 +743,45 @@ public class LiveGiftPopup extends AbsDialogFragment { lianSongHandler.removeCallbacks(lianSongRunnable); mShowLianBtn = false; getCoin(); + LiveNetManager.get(mContext) .getGiftNamingInfo(liveGiftModel.getId() + "", new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(GiftNamingInfoModel data) { - liveGiftModel = JSONObject.parseObject(GsonUtils.toJson(data), LiveGiftBean.class); - if (!TextUtils.isEmpty(liveGiftModel.getNamingLiveuid()) && - !TextUtils.isEmpty(liveGiftModel.getNamingUid()) && - !TextUtils.equals(liveGiftModel.getNamingLiveuid(), "0") && - !TextUtils.equals(liveGiftModel.getNamingUid(), "0")) { - namingLayout.setVisibility(View.VISIBLE); - ImgLoader.display(mContext, liveGiftModel.getNamingLiveAvatar(), namingAvatar); - StringBuffer namingNameText = new StringBuffer(); - if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { - namingNameText.append("获取冠名:") - .append(liveGiftModel.getNamingUserCoin()) - .append(" "); + if (TextUtils.equals(data.getNamingStatus(), "1")) { + liveGiftModel = JSONObject.parseObject(GsonUtils.toJson(data), LiveGiftBean.class); + if (!TextUtils.isEmpty(liveGiftModel.getNamingLiveuid()) && + !TextUtils.isEmpty(liveGiftModel.getNamingUid()) && + !TextUtils.equals(liveGiftModel.getNamingLiveuid(), "0") && + !TextUtils.equals(liveGiftModel.getNamingUid(), "0")) { + namingLayout.setVisibility(View.VISIBLE); + ImgLoader.display(mContext, liveGiftModel.getNamingLiveAvatar(), namingAvatar); + StringBuffer namingNameText = new StringBuffer(); + if (IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) { + namingNameText.append("获取冠名:") + .append(liveGiftModel.getNamingUserCoin()) + .append(" "); + } else { + namingNameText.append("Get title: ") + .append(liveGiftModel.getNamingUserCoin()) + .append(" "); + } + namingNameText.append(mContext.getText(com.yunbao.live.R.string.title_anchor)) + .append(liveGiftModel.getNamingLiveName()) + .append(" ") + .append(mContext.getText(com.yunbao.live.R.string.the_title_financier)) + .append(" ") + .append(liveGiftModel.getNamingUserName()); + namingName.setText(namingNameText.toString()); } else { - namingNameText.append("Get title: ") - .append(liveGiftModel.getNamingUserCoin()) - .append(" "); + namingLayout.setVisibility(View.GONE); + } - namingNameText.append(mContext.getText(com.yunbao.live.R.string.title_anchor)) - .append(liveGiftModel.getNamingLiveName()) - .append(" ") - .append(mContext.getText(com.yunbao.live.R.string.the_title_financier)) - .append(" ") - .append(liveGiftModel.getNamingUserName()); - namingName.setText(namingNameText.toString()); } else { namingLayout.setVisibility(View.GONE); - } + } @Override @@ -800,7 +894,7 @@ public class LiveGiftPopup extends AbsDialogFragment { if (!TextUtils.isEmpty(liveGiftModel.getOperateImage())) { operateImage.setVisibility(View.VISIBLE); ImgLoader.display(getContext(), liveGiftModel.getOperateImage(), operateImage); - }else { + } else { operateImage.setVisibility(View.GONE); } @@ -1185,12 +1279,15 @@ public class LiveGiftPopup extends AbsDialogFragment { if (goldText != null) { goldText.setText(goldCoin); } + if (!mGiftBean.getSwf().contains("svga")) { showLianBtn(); } if (mGiftBean.getType() == 7) { showLianBtn(); + } + // //刷新包裹列表wrap_gift_num -1:表示数量没有变化 // mObjGiftSendback = obj; isGetNewWrap = true; diff --git a/live/src/main/java/com/yunbao/live/event/LiveGiftItemRefreshEvent.java b/live/src/main/java/com/yunbao/live/event/LiveGiftItemRefreshEvent.java new file mode 100644 index 000000000..4101b375f --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/LiveGiftItemRefreshEvent.java @@ -0,0 +1,17 @@ +package com.yunbao.live.event; + +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.LiveGiftBean; + +public class LiveGiftItemRefreshEvent extends BaseModel { + private LiveGiftBean liveGiftModel; + + public LiveGiftBean getLiveGiftModel() { + return liveGiftModel; + } + + public LiveGiftItemRefreshEvent setLiveGiftModel(LiveGiftBean liveGiftModel) { + this.liveGiftModel = liveGiftModel; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java b/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java index 5740c41ea..d198e079e 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java +++ b/live/src/main/java/com/yunbao/live/views/LiveGiftFragment.java @@ -19,6 +19,11 @@ import com.yunbao.common.bean.LiveGiftBean; import com.yunbao.common.fragment.BaseFragment; import com.yunbao.live.R; import com.yunbao.live.adapter.LiveGiftFragmentPagerAdapter; +import com.yunbao.live.event.LiveGiftItemRefreshEvent; +import com.yunbao.live.event.LiveParcelItemRefreshEvent; + +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; @@ -148,4 +153,6 @@ public class LiveGiftFragment extends BaseFragment { liveGiftFragment.setArguments(bundle); return liveGiftFragment; } + + } diff --git a/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java b/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java index f2de5474c..72a927be9 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java +++ b/live/src/main/java/com/yunbao/live/views/LiveGiftItemFragment.java @@ -17,6 +17,7 @@ import com.yunbao.common.utils.Bus; import com.yunbao.live.R; import com.yunbao.live.adapter.FrameGiftAdapter; import com.yunbao.live.event.LiveGiftItemEvent; +import com.yunbao.live.event.LiveGiftItemRefreshEvent; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -79,4 +80,8 @@ public class LiveGiftItemFragment extends BaseFragment { public void onLiveGiftItemEvent(LiveGiftItemEvent event) { frameGiftAdapter.giftSelect(event.getLiveGiftModel()); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLiveGiftItemRefreshEvent(LiveGiftItemRefreshEvent event) { + frameGiftAdapter.refreshWrapListAfterSend(event.getLiveGiftModel()); + } }