feat: 联机送礼功能
This commit is contained in:
@@ -16,6 +16,7 @@ import com.chwl.core.gift.bean.GiftPanelInfo;
|
||||
import com.chwl.core.gift.bean.TagsInfo;
|
||||
import com.chwl.core.home.bean.TabInfo;
|
||||
import com.chwl.core.pay.event.UpdateWalletInfoEvent;
|
||||
import com.chwl.core.utils.ComboUtil;
|
||||
import com.netease.nim.uikit.common.util.log.LogUtil;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
|
||||
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
||||
@@ -439,6 +440,7 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
||||
if (giftId != giftMultiReceiverInfo.getGiftId()) {
|
||||
return Single.error(RxHelper.createThrowable(serviceResult));
|
||||
}
|
||||
giftMultiReceiverInfo.setComboCount(ComboUtil.INSTANCE.getComboCount());
|
||||
switch (sendType) {
|
||||
case GiftSendType.TYPE_ANCHOR:
|
||||
case GiftSendType.TYPE_MIC:
|
||||
@@ -493,6 +495,8 @@ public class GiftModel extends BaseModel implements IGiftModel {
|
||||
SingleToastUtil.showToast(serviceResult.getMessage());
|
||||
return Single.error(new RadishNotEnoughException(serviceResult.getMessage()));
|
||||
}
|
||||
|
||||
|
||||
return Single.error(RxHelper.createThrowable(serviceResult));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,8 +5,11 @@ public class GiftComboInfo {
|
||||
public String sentUserName;
|
||||
public String sentAvatar;
|
||||
public String giftImgUrl;
|
||||
public int giftId;
|
||||
public int giftNumber;
|
||||
public int receiverNumber;
|
||||
public String receiverUserName;
|
||||
public int comboCount;
|
||||
public boolean isMulti;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class GiftMultiReceiverInfo implements Serializable {
|
||||
private List<GiftReceiver> targetUsers;
|
||||
private int giftId;
|
||||
private int giftNum;
|
||||
private int comboCount;
|
||||
private GiftInfo gift;
|
||||
private List<GiftInfo> displayGift;
|
||||
private List<IndexGiftValue> giftValueVos;
|
||||
@@ -28,4 +29,5 @@ public class GiftMultiReceiverInfo implements Serializable {
|
||||
private List<Long> targetUids;
|
||||
private LuckyGiftList luckyGiftList;
|
||||
private WalletInfo userPurse;
|
||||
public boolean isMulti;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public class GiftReceiveInfo implements Serializable {
|
||||
private long targetUid;
|
||||
private int giftId;
|
||||
private int giftNum;
|
||||
private int comboCount;
|
||||
private String targetNick;
|
||||
private String targetAvatar;
|
||||
private String nick;
|
||||
|
||||
@@ -18,6 +18,7 @@ public class MultiGiftReceiveInfo implements Serializable {
|
||||
private List<GiftReceiver> targetUsers;
|
||||
private int giftId;
|
||||
private int giftNum;
|
||||
private int comboCount;
|
||||
private String nick;
|
||||
private String avatar;
|
||||
private GiftInfo gift;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.chwl.core.gift.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
//处理 礼物联机相关消息
|
||||
@Data
|
||||
public class GiftComboEvent {
|
||||
private int action ;
|
||||
|
||||
private int giftNumber;
|
||||
|
||||
|
||||
public int getGiftNumber() {
|
||||
return giftNumber;
|
||||
}
|
||||
|
||||
public void setGiftNumber(int giftNumber) {
|
||||
this.giftNumber = giftNumber;
|
||||
}
|
||||
|
||||
public GiftComboEvent() {
|
||||
}
|
||||
|
||||
public GiftComboEvent(int action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public int getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(int action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public @interface Action{
|
||||
int ACT_GIFT_BEGIN = 1; //准备送礼
|
||||
int ACT_GIFT_END = 2; //送礼完毕 显示连击按钮
|
||||
int ACT_GIFT_START = 3; // 连击按钮点击 发送礼物
|
||||
int ACT_GIFT_SHOW = 4; // 连击按钮消失 通知显示礼物弹窗
|
||||
int ACT_GIFT_CANCEL = 5; // 连击按钮消失
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.chwl.core.gift.toolbox;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.chwl.core.gift.bean.GiftType;
|
||||
import com.google.gson.Gson;
|
||||
@@ -103,24 +104,57 @@ public class GiftToolbox {
|
||||
//礼物值
|
||||
giftReceiveInfo.setGiftValueVos(giftMultiReceiverInfo.getGiftValueVos());
|
||||
giftReceiveInfo.setCurrentTime(giftMultiReceiverInfo.getCurrentTime());
|
||||
giftReceiveInfo.setComboCount(giftMultiReceiverInfo.getComboCount());
|
||||
return giftReceiveInfo;
|
||||
}
|
||||
|
||||
public static GiftMultiReceiverInfo transformToGiftMultiReceiverInfo(MultiGiftReceiveInfo multiGiftReceiveInfo) {
|
||||
GiftMultiReceiverInfo giftMultiReceiverInfo = null;
|
||||
try {
|
||||
giftMultiReceiverInfo = new GiftMultiReceiverInfo();
|
||||
giftMultiReceiverInfo.setUid(multiGiftReceiveInfo.getUid());
|
||||
giftMultiReceiverInfo.setAvatar(multiGiftReceiveInfo.getAvatar());
|
||||
giftMultiReceiverInfo.setNick(multiGiftReceiveInfo.getNick());
|
||||
giftMultiReceiverInfo.setGiftId(multiGiftReceiveInfo.getGiftId());
|
||||
giftMultiReceiverInfo.setGiftNum(multiGiftReceiveInfo.getGiftNum());
|
||||
giftMultiReceiverInfo.setGift(multiGiftReceiveInfo.getGift());
|
||||
giftMultiReceiverInfo.setLuckyBagGifts(multiGiftReceiveInfo.getLuckyBagGifts());
|
||||
giftMultiReceiverInfo.setDisplayGift(multiGiftReceiveInfo.getDisplayGift());
|
||||
giftMultiReceiverInfo.setTargetUsers(multiGiftReceiveInfo.getTargetUsers());
|
||||
List<Long> targetUids = new ArrayList<>();
|
||||
if (multiGiftReceiveInfo.getTargetUsers() != null){
|
||||
for (GiftReceiver targetUser : multiGiftReceiveInfo.getTargetUsers()) {
|
||||
targetUids.add(targetUser.getUid());
|
||||
}
|
||||
}
|
||||
giftMultiReceiverInfo.setTargetUids(targetUids);
|
||||
//礼物值
|
||||
giftMultiReceiverInfo.setGiftValueVos(multiGiftReceiveInfo.getGiftValueVos());
|
||||
giftMultiReceiverInfo.setCurrentTime(multiGiftReceiveInfo.getCurrentTime());
|
||||
giftMultiReceiverInfo.setComboCount(multiGiftReceiveInfo.getComboCount());
|
||||
} catch (Exception e) {
|
||||
Log.e("error", ""+e.getMessage());
|
||||
}
|
||||
return giftMultiReceiverInfo;
|
||||
}
|
||||
|
||||
|
||||
public static GiftMultiReceiverInfo transformToGiftMultiReceiverInfo(GiftReceiveInfo giftReceiveInfo) {
|
||||
GiftMultiReceiverInfo giftMultiReceiverInfo = new GiftMultiReceiverInfo();
|
||||
giftMultiReceiverInfo.setUid(giftReceiveInfo.getUid());
|
||||
giftMultiReceiverInfo.setNick(giftReceiveInfo.getNick());
|
||||
giftMultiReceiverInfo.setAvatar(giftMultiReceiverInfo.getAvatar());
|
||||
giftMultiReceiverInfo.setAvatar(giftReceiveInfo.getAvatar());
|
||||
giftMultiReceiverInfo.setGift(giftReceiveInfo.getGift());
|
||||
giftMultiReceiverInfo.setGiftId(giftReceiveInfo.getGiftId());
|
||||
giftMultiReceiverInfo.setGiftNum(giftMultiReceiverInfo.getGiftNum());
|
||||
giftMultiReceiverInfo.setGiftNum(giftReceiveInfo.getGiftNum());
|
||||
giftMultiReceiverInfo.setLuckyBagGifts(giftReceiveInfo.getLuckyBagGifts());
|
||||
giftMultiReceiverInfo.setDisplayGift(giftReceiveInfo.getDisplayGift());
|
||||
giftMultiReceiverInfo.setComboCount(giftReceiveInfo.getComboCount());
|
||||
List<GiftReceiver> targetUsers = new ArrayList<>();
|
||||
GiftReceiver receiver = new GiftReceiver();
|
||||
receiver.setUid(giftReceiveInfo.getTargetUid());
|
||||
receiver.setNick(giftReceiveInfo.getTargetNick());
|
||||
receiver.setAvatar(giftMultiReceiverInfo.getAvatar());
|
||||
receiver.setAvatar(giftReceiveInfo.getTargetAvatar());
|
||||
targetUsers.add(receiver);
|
||||
giftMultiReceiverInfo.setTargetUsers(targetUsers);
|
||||
return giftMultiReceiverInfo;
|
||||
@@ -144,9 +178,12 @@ public class GiftToolbox {
|
||||
giftReceiveInfo.setDisplayGift(giftMultiReceiverInfo.getDisplayGift());
|
||||
giftReceiveInfo.setGiftValueVos(giftMultiReceiverInfo.getGiftValueVos());
|
||||
giftReceiveInfo.setCurrentTime(giftMultiReceiverInfo.getCurrentTime());
|
||||
giftReceiveInfo.setComboCount(giftMultiReceiverInfo.getComboCount());
|
||||
return giftReceiveInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 转换 ServiceResult<GiftMultiReceiverInfo> 成 ServiceResult<GiftReceiveInfo>
|
||||
*/
|
||||
|
||||
@@ -50,6 +50,7 @@ public class GiftAttachment extends CustomAttachment {
|
||||
giftReceiveInfo.setNick(data.getString("nick"));
|
||||
giftReceiveInfo.setTargetUid(data.getLong("targetUid"));
|
||||
giftReceiveInfo.setGiftNum(data.getIntValue("giftNum"));
|
||||
giftReceiveInfo.setComboCount(data.getIntValue("comboCount"));
|
||||
giftReceiveInfo.setTargetNick(data.getString("targetNick"));
|
||||
giftReceiveInfo.setTargetAvatar(data.getString("targetAvatar"));
|
||||
if (data.containsKey("isRoomAlbum")) {
|
||||
@@ -92,6 +93,7 @@ public class GiftAttachment extends CustomAttachment {
|
||||
object.put("nick", giftReceiveInfo.getNick());
|
||||
object.put("targetUid", giftReceiveInfo.getTargetUid());
|
||||
object.put("giftNum", giftReceiveInfo.getGiftNum());
|
||||
object.put("comboCount", giftReceiveInfo.getComboCount());
|
||||
object.put("targetNick", giftReceiveInfo.getTargetNick());
|
||||
object.put("targetAvatar", giftReceiveInfo.getTargetAvatar());
|
||||
object.put("giftInfo", giftReceiveInfo.getGift());
|
||||
|
||||
@@ -46,6 +46,7 @@ public class GiftBatchAttachment extends CustomAttachment {
|
||||
new TypeReference<List<GiftReceiver>>() {
|
||||
}));
|
||||
giftMultiReceiverInfo.setGiftNum(data.getIntValue("giftNum"));
|
||||
giftMultiReceiverInfo.setComboCount(data.getIntValue("comboCount"));
|
||||
JSONObject giftJson = null;
|
||||
if (data.containsKey("gift")) {
|
||||
giftJson = data.getJSONObject("gift");
|
||||
@@ -81,6 +82,7 @@ public class GiftBatchAttachment extends CustomAttachment {
|
||||
object.put("nick", giftMultiReceiverInfo.getNick());
|
||||
object.put("targetUsers", giftMultiReceiverInfo.getTargetUsers());
|
||||
object.put("giftNum", giftMultiReceiverInfo.getGiftNum());
|
||||
object.put("comboCount", giftMultiReceiverInfo.getComboCount());
|
||||
object.put("gift", giftMultiReceiverInfo.getGift());
|
||||
//礼物值
|
||||
if (giftMultiReceiverInfo.getGiftValueVos() != null) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class MultiGiftAttachment extends CustomAttachment {
|
||||
multiGiftReceiveInfo.setAvatar(data.getString("avatar"));
|
||||
multiGiftReceiveInfo.setNick(data.getString("nick"));
|
||||
multiGiftReceiveInfo.setGiftNum(data.getIntValue("giftNum"));
|
||||
multiGiftReceiveInfo.setComboCount(data.getIntValue("comboCount"));
|
||||
JSONArray jsonArray = data.getJSONArray("targetUids");
|
||||
List<Long> targetUids = new ArrayList<>();
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
@@ -75,6 +76,7 @@ public class MultiGiftAttachment extends CustomAttachment {
|
||||
object.put("avatar", multiGiftReceiveInfo.getAvatar());
|
||||
object.put("nick", multiGiftReceiveInfo.getNick());
|
||||
object.put("giftNum", multiGiftReceiveInfo.getGiftNum());
|
||||
object.put("comboCount", multiGiftReceiveInfo.getComboCount());
|
||||
object.put("gift", multiGiftReceiveInfo.getGift());
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
31
core/src/main/java/com/chwl/core/utils/ComboUtil.kt
Normal file
31
core/src/main/java/com/chwl/core/utils/ComboUtil.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.chwl.core.utils
|
||||
|
||||
import android.graphics.Point
|
||||
import android.view.View
|
||||
import com.chwl.library.utils.ScreenUtils
|
||||
import com.example.lib_utils.UiUtils.isRtl
|
||||
|
||||
object ComboUtil {
|
||||
var comboCount = 1
|
||||
var point = Point(0,0)
|
||||
fun setPoint(child: View) {
|
||||
if (point.x>0 || point.y>0) return
|
||||
val density: Float = child.context.resources.displayMetrics.density
|
||||
val giftWidth = (80 * density + 0.5).toInt()
|
||||
val location = IntArray(2)
|
||||
|
||||
child.getLocationInWindow(location)
|
||||
val x: Int
|
||||
if (isRtl(child.context)) {
|
||||
location[0] = ScreenUtils.getScreenWidth(child.context) - location[0]
|
||||
x = (location[0] - child.width / 2) - giftWidth / 2
|
||||
} else {
|
||||
x = (location[0] + child.width / 2) - giftWidth / 2
|
||||
}
|
||||
val y = (location[1] + child.height / 3) - giftWidth / 2
|
||||
point = Point(x, y)
|
||||
LogUtils.d("ComboUtil x= $x y= $y")
|
||||
}
|
||||
|
||||
fun isChangePoint() = comboCount > 2
|
||||
}
|
||||
Reference in New Issue
Block a user