diff --git a/app/src/main/java/com/yizhuan/erban/ui/widget/GiftDialog.java b/app/src/main/java/com/yizhuan/erban/ui/widget/GiftDialog.java index 9b8a26b34..454ad8b98 100644 --- a/app/src/main/java/com/yizhuan/erban/ui/widget/GiftDialog.java +++ b/app/src/main/java/com/yizhuan/erban/ui/widget/GiftDialog.java @@ -69,8 +69,10 @@ import com.yizhuan.xchat_android_core.gift.bean.GiftTab; import com.yizhuan.xchat_android_core.gift.bean.GiftType; import com.yizhuan.xchat_android_core.gift.bean.SimpleUserInfo; import com.yizhuan.xchat_android_core.gift.event.UpdateKnapEvent; +import com.yizhuan.xchat_android_core.gift.event.UpdateKnapFreeGiftDataEvent; import com.yizhuan.xchat_android_core.gift.event.UpdateKnapFreeGiftEvent; import com.yizhuan.xchat_android_core.gift.event.UpdateKnapFreeGiftNumEvent; +import com.yizhuan.xchat_android_core.im.custom.bean.RoomFreeGiftMsgBean; import com.yizhuan.xchat_android_core.initial.InitialModel; import com.yizhuan.xchat_android_core.manager.AvRoomDataManager; import com.yizhuan.xchat_android_core.manager.IMNetEaseManager; @@ -1519,6 +1521,30 @@ public class GiftDialog extends BottomSheetDialog implements View.OnClickListene } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onReceiveFreeGiftData(UpdateKnapFreeGiftDataEvent event){ + //刷新背包礼物 + compositeDisposable.add(GiftModel.get().requestKnapGiftInfos() + .compose(RxHelper.handleSchedulers()) + .subscribe()); + if (giftIndicator.getCurrrentType() == GiftIndicator.TYPE_KNAP) { + RoomFreeGiftMsgBean roomFreeGiftMsgBean = event.getRoomFreeGiftMsgBean(); + if (ListUtils.isListEmpty(pagerList)) { + return; + } + for (List page : pagerList) { + for (GiftInfoVm item : page) { + if (item.data.getGiftId() == roomFreeGiftMsgBean.getGiftId()) { + item.data.setGiftId(roomFreeGiftMsgBean.getGiftId()); + item.data.setGiftName(roomFreeGiftMsgBean.getGiftName()); + item.data.setGiftUrl(roomFreeGiftMsgBean.getGiftUrl()); + break; + } + } + } + } + } + private void onGiftOutOfDate(String message) { ((BaseActivity) getContext()).toast(message); } diff --git a/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/manager/IMNetEaseManager.java b/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/manager/IMNetEaseManager.java index e04415791..74a995d0b 100644 --- a/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/manager/IMNetEaseManager.java +++ b/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/manager/IMNetEaseManager.java @@ -74,6 +74,7 @@ import com.yizhuan.xchat_android_core.family.bean.FamilyInfo; import com.yizhuan.xchat_android_core.family.event.FamilyMineEvent; import com.yizhuan.xchat_android_core.gift.GiftModel; import com.yizhuan.xchat_android_core.gift.bean.GiftInfo; +import com.yizhuan.xchat_android_core.gift.event.UpdateKnapFreeGiftDataEvent; import com.yizhuan.xchat_android_core.helper.AtProxy; import com.yizhuan.xchat_android_core.im.custom.bean.ActivityTimerAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.AssistantAttachment; @@ -99,8 +100,12 @@ import com.yizhuan.xchat_android_core.im.custom.bean.MultiGiftAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.MultiLuckyGiftAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.NobleAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.RoomBoxPrizeAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.RoomFreeGiftAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.RoomFreeGiftMsgBean; import com.yizhuan.xchat_android_core.im.custom.bean.RoomGiftValueAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.RoomInfoAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.RoomLuckySeaAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.RoomLuckySeaMsgBean; import com.yizhuan.xchat_android_core.im.custom.bean.RoomPKAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.RoomPkBean; import com.yizhuan.xchat_android_core.im.custom.bean.RoomTipAttachment; @@ -1337,6 +1342,13 @@ public final class IMNetEaseManager { noticeRoomEvent(msg, RoomEvent.LUCKY_SEA_GIFT_SERVER_NOTIFY); } break; + case ROOM_FREE_GIFT: + if(second == ROOM_FREE_GIFT_CHANGE){ + RoomFreeGiftAttachment freeGiftAttachment = (RoomFreeGiftAttachment) attachment; + RoomFreeGiftMsgBean bean = freeGiftAttachment.getRoomFreeGiftMsgInfo(); + EventBus.getDefault().post(new UpdateKnapFreeGiftDataEvent(bean)); + } + break; default: break; } diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/gift/GiftModel.java b/core/src/main/java/com/yizhuan/xchat_android_core/gift/GiftModel.java index a9103915e..84fd24d48 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/gift/GiftModel.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/gift/GiftModel.java @@ -637,17 +637,17 @@ public class GiftModel extends BaseModel implements IGiftModel { return api.getFreeGift().compose(new Transformer<>()).doOnSuccess(response -> { if (response.isSuccess()) { giftFreeInfo = response.getData(); - startFreeGiftCountDown(giftFreeInfo.getGiftId(), isReset); - if(isReset){ + if (isReset) { EventBus.getDefault().post(new UpdateKnapFreeGiftNumEvent(giftFreeInfo.getGiftId(), true)); } + startFreeGiftCountDown(giftFreeInfo.getGiftId()); } }); } private CountDownTimer countDownTimer; - private void startFreeGiftCountDown(int giftId, boolean isReset) { + private void startFreeGiftCountDown(int giftId) { cancelCountDownTimer(); if (giftFreeInfo.getCurStage() < giftFreeInfo.getMaxStage()) { if (giftFreeInfo.getCurStageSecond() > 0) { diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/gift/event/UpdateKnapFreeGiftDataEvent.java b/core/src/main/java/com/yizhuan/xchat_android_core/gift/event/UpdateKnapFreeGiftDataEvent.java new file mode 100644 index 000000000..f6796981d --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/gift/event/UpdateKnapFreeGiftDataEvent.java @@ -0,0 +1,18 @@ +package com.yizhuan.xchat_android_core.gift.event; + +import com.yizhuan.xchat_android_core.im.custom.bean.RoomFreeGiftMsgBean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * 更新背包免费礼物事件 + * Created by wushaocheng on 2022/12/14. + */ +@AllArgsConstructor +@Data +public class UpdateKnapFreeGiftDataEvent { + + private RoomFreeGiftMsgBean roomFreeGiftMsgBean; + +} diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java index 2eadca174..1726cb6b1 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachParser.java @@ -84,6 +84,7 @@ import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUS import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_NOTI_SUB_GAME_ATTACK; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_NOTI_SUB_GAME_RESULT; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.ROOM_FREE_GIFT; +import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.ROOM_FREE_GIFT_CHANGE; import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.ROOM_FREE_GIFT_REST; import com.alibaba.fastjson.JSON; @@ -619,13 +620,15 @@ public class CustomAttachParser implements MsgAttachmentParser { switch (second) { case CUSTOM_MSG_LUCKY_SEA_GIFT_ROOM_NOTIFY: case CUSTOM_MSG_LUCKY_SEA_GIFT_SERVER_NOTIFY: - attachment = new RoomLuckySeaAttachment(CUSTOM_MSG_LUCKY_SEA, second); + attachment = new RoomLuckySeaAttachment(first, second); break; } break; case ROOM_FREE_GIFT: if (second == ROOM_FREE_GIFT_REST) { GiftModel.get().getFreeGift(true).subscribe(); + }else if(second == ROOM_FREE_GIFT_CHANGE){ + attachment = new RoomFreeGiftAttachment(first, second); } break; default: diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java index 2a4402e90..dbcd6a8e0 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/CustomAttachment.java @@ -426,6 +426,7 @@ public class CustomAttachment implements MsgAttachment { //免费礼物倒计时重置推送 public static final int ROOM_FREE_GIFT = 96; public static final int ROOM_FREE_GIFT_REST = 960; + public static final int ROOM_FREE_GIFT_CHANGE = 961; /** * 自定义消息附件的类型,根据该字段区分不同的自定义消息 diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftAttachment.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftAttachment.java new file mode 100644 index 000000000..59eb59d9b --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftAttachment.java @@ -0,0 +1,33 @@ +package com.yizhuan.xchat_android_core.im.custom.bean; + +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; + +/** + * 免费礼物 + * Created by wushaocheng on 2022/12/16. + */ +public class RoomFreeGiftAttachment extends CustomAttachment { + + private RoomFreeGiftMsgBean roomFreeGiftMsgBean; + + public RoomFreeGiftAttachment(int first, int second) { + super(first, second); + } + + @Override + protected void parseData(JSONObject data) { + roomFreeGiftMsgBean = new Gson().fromJson(data.toJSONString(), RoomFreeGiftMsgBean.class); + } + + @Override + protected JSONObject packData() { + String jsonStr = new Gson().toJson(roomFreeGiftMsgBean); + return JSONObject.parseObject(jsonStr); + } + + public RoomFreeGiftMsgBean getRoomFreeGiftMsgInfo() { + return roomFreeGiftMsgBean; + } + +} diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftMsgBean.java b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftMsgBean.java new file mode 100644 index 000000000..656306102 --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/im/custom/bean/RoomFreeGiftMsgBean.java @@ -0,0 +1,11 @@ +package com.yizhuan.xchat_android_core.im.custom.bean; + +import lombok.Data; + +@Data +public class RoomFreeGiftMsgBean { + private int giftId;//礼物id + private String giftName;//礼物名称 + private String giftUrl;//礼物icon + private long goldPrice;//礼物价格 +}