[Modify]免费礼物功能开发

This commit is contained in:
wushaocheng
2022-12-14 20:08:08 +08:00
parent 37e32e433f
commit 7a852cf35d
22 changed files with 456 additions and 9 deletions

View File

@@ -4,6 +4,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_MSG_SUB_TYPE_SEND_LUCKY_GIFT;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_SEND_MULTI_LUCK_GIFT;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
@@ -16,6 +17,7 @@ import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.base.BaseModel;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.gift.bean.GiftFreeInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftListInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftMultiReceiverInfo;
@@ -25,7 +27,9 @@ import com.yizhuan.xchat_android_core.gift.bean.GiftType;
import com.yizhuan.xchat_android_core.gift.bean.LuckyBagGifts;
import com.yizhuan.xchat_android_core.gift.bean.MultiGiftReceiveInfo;
import com.yizhuan.xchat_android_core.gift.bean.SimpleVipInfo;
import com.yizhuan.xchat_android_core.gift.event.RoomFreeGiftEvent;
import com.yizhuan.xchat_android_core.gift.event.UpdateKnapEvent;
import com.yizhuan.xchat_android_core.gift.event.UpdateKnapFreeGiftEvent;
import com.yizhuan.xchat_android_core.gift.exception.GiftOutOfDateException;
import com.yizhuan.xchat_android_core.gift.toolbox.GiftToolbox;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
@@ -43,6 +47,7 @@ import com.yizhuan.xchat_android_core.room.giftvalue.bean.GiftValueCommonUpdate;
import com.yizhuan.xchat_android_core.room.giftvalue.helper.GiftValueMrg;
import com.yizhuan.xchat_android_core.user.UserModel;
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
import com.yizhuan.xchat_android_core.utils.Logger;
import com.yizhuan.xchat_android_core.utils.net.BalanceNotEnoughExeption;
import com.yizhuan.xchat_android_core.utils.net.RadishNotEnoughException;
import com.yizhuan.xchat_android_core.utils.net.RxHelper;
@@ -74,12 +79,14 @@ import retrofit2.http.Query;
*/
public class GiftModel extends BaseModel implements IGiftModel {
public static final String TAG = "GiftModel";
private volatile static IGiftModel model;
private Api api;
private UiHandler handler;
private GiftListInfo allGiftListInfo;
private List<GiftInfo> knapList;
private List<CustomAttachment> giftQueue;
private GiftFreeInfo giftFreeInfo;
private GiftModel() {
api = RxNet.create(Api.class);
@@ -619,6 +626,70 @@ public class GiftModel extends BaseModel implements IGiftModel {
.compose(RxHelper.handleSchAndExce());
}
/**
* 免费礼物接口
*
* @return
*/
@Override
public Single<ServiceResult<GiftFreeInfo>> getFreeGift() {
return api.getFreeGift().compose(new Transformer<>()).doOnSuccess(response -> {
if (response.isSuccess()) {
giftFreeInfo = response.getData();
startFreeGiftCountDown(giftFreeInfo.getGiftId());
}
});
}
private CountDownTimer countDownTimer;
private void startFreeGiftCountDown(int giftId) {
cancelCountDownTimer();
if (giftFreeInfo.getCurStage() < giftFreeInfo.getMaxStage()) {
if (giftFreeInfo.getCurStageSecond() > 0) {
countDownTimer = new CountDownTimer(giftFreeInfo.getCurStageSecond() * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
Logger.info(TAG, String.valueOf(millisUntilFinished / 1000));
EventBus.getDefault().post(new UpdateKnapFreeGiftEvent(giftId, (int) (millisUntilFinished / 1000)));
}
@Override
public void onFinish() {
if(giftFreeInfo.getCurStage() == 0){
EventBus.getDefault().post(new RoomFreeGiftEvent(giftFreeInfo));
}
Logger.info(TAG, "FREE_GIFT onTimerFinish");
// 鲜花倒计时结束,去请求
getFreeGift().subscribe();
}
};
countDownTimer.start();
}
}
}
@Override
public void cancelCountDownTimer() {
if (countDownTimer != null) {
countDownTimer.cancel();
}
}
/**
* 获取免费礼物数据
*
* @return
*/
@Override
public GiftFreeInfo getFreeGiftInfo() {
if (giftFreeInfo != null) {
return giftFreeInfo;
} else {
return null;
}
}
private interface Api {
/**
@@ -635,7 +706,7 @@ public class GiftModel extends BaseModel implements IGiftModel {
* @param uid
* @return
*/
@GET("backpack/listUserBackpackV2")
@GET("backpack/listUserBackpackV3")
Single<ServiceResult<List<GiftInfo>>> getGiftKnapList(@Query("uid") String uid);
/**
@@ -678,6 +749,14 @@ public class GiftModel extends BaseModel implements IGiftModel {
@Field("giftSource") int giftSource,
@Field("chatSessionId") String chatSessionId);
/**
* 获取新用户进房礼物
*
* @return
*/
@GET("/roomFreeGift/get")
Single<ServiceResult<GiftFreeInfo>> getFreeGift();
}
private static class UiHandler extends Handler {

View File

@@ -4,6 +4,7 @@ import androidx.annotation.Nullable;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.gift.bean.GiftFreeInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftListInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftMultiReceiverInfo;
@@ -198,4 +199,22 @@ public interface IGiftModel {
*/
Single<ServiceResult<GiftMultiReceiverInfo>> sendFansTeamGift(int giftId,
String targetUid);
/**
* 获取免费礼物
*/
Single<ServiceResult<GiftFreeInfo>> getFreeGift();
/**
* 取消倒计时
*/
public void cancelCountDownTimer();
/**
* 从内存里取出免费礼物
*
* @return
*/
GiftFreeInfo getFreeGiftInfo();
}

View File

@@ -0,0 +1,23 @@
package com.yizhuan.xchat_android_core.gift.bean;
import lombok.Data;
/**
* Created by wushaocheng
* on 2022/12/13.
*/
@Data
public class GiftFreeInfo {
private long uid;//用户id
private int giftId;//礼物id
private String giftName;//礼物名称
private long goldPrice;//礼物价格
private String giftUrl;//礼物icon
private long firstSecond;//首次时长
private long curStage;//当前阶段
private long curStageSecond;//当前阶段剩余多少秒去倒计时
private long maxStage;//最大阶段
private long restTime;//重置时间
}

View File

@@ -17,6 +17,10 @@ public class GiftInfo implements Serializable {
* 钻石礼物
*/
public final static int CONSUME_TYPE_GOLD = 1;
/**
* 免费礼物
*/
public final static int CONSUME_TYPE_FREE_GIFT = 3;
private int count;
private int giftId;
@@ -92,4 +96,15 @@ public class GiftInfo implements Serializable {
private boolean drawGift;
//免费礼物倒计时进度
private int mFreeGiftProgress = 0;
public int getFreeGiftProgress() {
return mFreeGiftProgress;
}
public void setFreeGiftProgress(int freeGiftProgress) {
mFreeGiftProgress = freeGiftProgress;
}
}

View File

@@ -0,0 +1,18 @@
package com.yizhuan.xchat_android_core.gift.event;
import com.yizhuan.xchat_android_core.gift.bean.GiftFreeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 免費禮物彈窗事件
* Created by wushaocheng on 2022/12/14.
*/
@AllArgsConstructor
@Data
public class RoomFreeGiftEvent {
private GiftFreeInfo giftFreeInfo;
}

View File

@@ -0,0 +1,18 @@
package com.yizhuan.xchat_android_core.gift.event;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 更新背包免费礼物事件
* Created by wushaocheng on 2022/12/14.
*/
@AllArgsConstructor
@Data
public class UpdateKnapFreeGiftEvent {
private int giftId;
private int progress;
}

View File

@@ -102,7 +102,6 @@ public class AvRoomModel extends RoomBaseModel implements IAvRoomModel {
return instance;
}
private Map<String, Object> toMap(Map<String, Object> map, String namePlateWord, String namePlatePic) {
if (map == null) {
map = new HashMap<>();

View File

@@ -29,6 +29,7 @@ import com.yizhuan.xchat_android_core.bean.RoomQueueInfo;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.decoration.headwear.bean.HeadWearInfo;
import com.yizhuan.xchat_android_core.exception.ErrorThrowable;
import com.yizhuan.xchat_android_core.gift.bean.GiftFreeInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
import com.yizhuan.xchat_android_core.home.bean.BannerInfo;
import com.yizhuan.xchat_android_core.home.bean.HomeRoomInfo;
@@ -1154,6 +1155,13 @@ public class RoomBaseModel extends BaseModel implements IRoomBaseModel {
@GET("/gift/newUser/inRoom")
Single<ServiceResult<GiftInfo>> getNewUserGift(@Query("roomUid") long roomUid);
/**
* 获取新用户进房礼物
* @return
*/
@GET("/roomFreeGift/get")
Single<ServiceResult<GiftFreeInfo>> getFreeFlower();
}
}

View File

@@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData;
import com.yizhuan.xchat_android_core.base.IModel;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.gift.bean.GiftFreeInfo;
import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
import com.yizhuan.xchat_android_core.home.bean.HomeRoomInfo;
import com.yizhuan.xchat_android_core.room.activitytimer.TimerBean;
@@ -183,4 +184,5 @@ public interface IAvRoomModel extends IModel {
Single<GiftInfo> getNewUserGift();
void loadMessageHistory(long startTime);
}