diff --git a/common/src/main/java/com/yunbao/common/bean/RedPacketInfoModel.java b/common/src/main/java/com/yunbao/common/bean/RedPacketInfoModel.java index 4880dd1c5..888a0dd6d 100644 --- a/common/src/main/java/com/yunbao/common/bean/RedPacketInfoModel.java +++ b/common/src/main/java/com/yunbao/common/bean/RedPacketInfoModel.java @@ -41,11 +41,15 @@ public class RedPacketInfoModel extends BaseModel { private String userExists; @SerializedName("is_attention") private String isAttention; + //0.未领取到 1.领取但是没抢过东西 2.已经领抢到东西 + @SerializedName("receive_status") + private String receiveStatus; public String getIsAttention() { return isAttention; } + public RedPacketInfoModel setIsAttention(String isAttention) { this.isAttention = isAttention; return this; @@ -56,6 +60,26 @@ public class RedPacketInfoModel extends BaseModel { @SerializedName("red_packet_gift") private List packetGiftModels; + @SerializedName("gift") + private List giftModels; + + public String getReceiveStatus() { + return receiveStatus; + } + + public RedPacketInfoModel setReceiveStatus(String receiveStatus) { + this.receiveStatus = receiveStatus; + return this; + } + + public List getGiftModels() { + return giftModels; + } + + public RedPacketInfoModel setGiftModels(List giftModels) { + this.giftModels = giftModels; + return this; + } public List getPacketGiftModels() { return packetGiftModels; diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 15d747ef6..27634d90a 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -751,4 +751,16 @@ public interface PDLiveApi { @Query("liveuid") String liveUid, @Query("red_packet_id") String redPacketId ); + + + + /** + * 获取盲盒礼物当前数据 + */ + @GET("/api/public/?service=Live.getRedPacket") + Observable> getRedPacket( + @Query("liveuid") String liveUid, + @Query("stream") String stream, + @Query("red_packet_id") String redPacketId + ); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index c4000a5e1..d4311ebe7 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -1603,6 +1603,28 @@ public class LiveNetManager { }).isDisposed(); } + /** + * 领取红包 + * + * @param liveUid 直播间id + * @param redPacketId 红包id + */ + public void getRedPacket(String liveUid,String stream, String redPacketId, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getRedPacket(liveUid, stream,redPacketId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(redPacketInfoModelResponseModel -> { + if (callback != null) { + callback.onSuccess(redPacketInfoModelResponseModel.getData().getInfo()); + } + }, throwable -> { + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + }).isDisposed(); + } + /** * 直播间取消网络请求 */ diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 01e644c90..160c4e708 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1226,4 +1226,6 @@ Limited ride And limited avatar frame 倒計時:%s 待開紅包:%s 來自%s的獎勵,齊心協力連成目標 + 很遺憾 + 與紅包擦肩而過 diff --git a/live/src/main/java/com/yunbao/live/dialog/ReceiveRendPacketPopup.java b/live/src/main/java/com/yunbao/live/dialog/ReceiveRendPacketPopup.java index b8f81efdd..eb774e513 100644 --- a/live/src/main/java/com/yunbao/live/dialog/ReceiveRendPacketPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/ReceiveRendPacketPopup.java @@ -24,7 +24,6 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.TimeUtils; -import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.CircleProgress; import com.yunbao.common.views.weight.ClipPathCircleImage; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -37,18 +36,24 @@ public class ReceiveRendPacketPopup extends CenterPopupView { private Button redPacketOpen; private TextView redPacketTimeText, receiveRed, redPacketValue; private FrameLayout redPacketTimeLayout; - private String mLiveUid, redPacketId, userID; + private String mLiveUid,stream, redPacketId, userID; private ClipPathCircleImage headPortrait; private RecyclerView redPacketGiftList; private RedPacketGiftAdapter redPacketGiftAdapter; private ImageView isAttention; + private RedPacketInfoModel redPacketInfoModel; - public ReceiveRendPacketPopup(@NonNull Context context, int time, String mLiveUid, String redPacketId) { + + public ReceiveRendPacketPopup(@NonNull Context context, int time, String mLiveUid,String stream, + String redPacketId, RedPacketInfoModel redPacketInfoModel) { super(context); this.time = time; this.mLiveUid = mLiveUid; + this.stream = stream; this.redPacketId = redPacketId; + this.redPacketInfoModel = redPacketInfoModel; + } // 返回自定义弹窗的布局离开 @@ -66,31 +71,20 @@ public class ReceiveRendPacketPopup extends CenterPopupView { } private void initData() { - LiveNetManager.get(getContext()) - .redPacketInfo(mLiveUid, redPacketId, new HttpCallback() { - @Override - public void onSuccess(RedPacketInfoModel data) { - ImgLoader.displayAvatar(getContext(), data.getAvatar(), headPortrait); - receiveRed.setText(String.format(getContext() - .getString(R.string.together_to_achieve_goal), - data.getUserNicename())); - redPacketValue.setText(data.getAmountDiamond()); - redPacketGiftAdapter.addData(data.getPacketGiftModels()); - IMLoginModel userInfo = IMLoginManager.get(getContext()).getUserInfo(); - if (TextUtils.equals(String.valueOf(userInfo.getId()), data.getUid())) { - isAttention.setVisibility(GONE); - } else { - isAttention.setVisibility(TextUtils.equals(data.getIsAttention(), "0") ? VISIBLE : GONE); - } + ImgLoader.displayAvatar(getContext(), redPacketInfoModel.getAvatar(), headPortrait); + receiveRed.setText(String.format(getContext() + .getString(R.string.together_to_achieve_goal), + redPacketInfoModel.getUserNicename())); + redPacketValue.setText(redPacketInfoModel.getAmountDiamond()); + redPacketGiftAdapter.addData(redPacketInfoModel.getPacketGiftModels()); + IMLoginModel userInfo = IMLoginManager.get(getContext()).getUserInfo(); + if (TextUtils.equals(String.valueOf(userInfo.getId()), redPacketInfoModel.getUid())) { + isAttention.setVisibility(GONE); + } else { + isAttention.setVisibility(TextUtils.equals(redPacketInfoModel.getIsAttention(), "0") ? VISIBLE : GONE); + } - userID = data.getUserId(); - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - } - }); + userID = redPacketInfoModel.getUserId(); } private Handler timeHandler = new Handler(); @@ -147,10 +141,25 @@ public class ReceiveRendPacketPopup extends CenterPopupView { } ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.red_packet_open), () -> { - dismiss(); - new XPopup.Builder(getContext()) - .asCustom(new ResultRendPacketPopup(getContext())) - .show(); + LiveNetManager.get(getContext()) + .getRedPacket(mLiveUid, stream,redPacketId, new HttpCallback() { + @Override + public void onSuccess(RedPacketInfoModel data) { + dismiss(); + new XPopup.Builder(getContext()) + .asCustom(new ResultRendPacketPopup(getContext(), false, data)) + .show(); + } + + @Override + public void onError(String error) { + dismiss(); + new XPopup.Builder(getContext()) + .asCustom(new ResultRendPacketPopup(getContext(), true, null)) + .show(); + } + }); + }); ViewClicksAntiShake.clicksAntiShake(isAttention, new ViewClicksAntiShake.ViewClicksCallBack() { @Override @@ -166,6 +175,7 @@ public class ReceiveRendPacketPopup extends CenterPopupView { } }); + } } diff --git a/live/src/main/java/com/yunbao/live/dialog/ResultRendPacketPopup.java b/live/src/main/java/com/yunbao/live/dialog/ResultRendPacketPopup.java index bef6d0c21..9571efe6b 100644 --- a/live/src/main/java/com/yunbao/live/dialog/ResultRendPacketPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/ResultRendPacketPopup.java @@ -1,29 +1,39 @@ package com.yunbao.live.dialog; import android.content.Context; -import android.os.Bundle; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; import androidx.annotation.NonNull; import com.lxj.xpopup.core.CenterPopupView; -import com.yunbao.common.Constants; +import com.yunbao.common.bean.RedPacketInfoModel; +import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.utils.Bus; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; -import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.event.LiveAudienceEvent; public class ResultRendPacketPopup extends CenterPopupView { + private boolean noData; + private RedPacketInfoModel redPacketInfoModel; - public ResultRendPacketPopup(@NonNull Context context) { + public ResultRendPacketPopup(@NonNull Context context, boolean noData, RedPacketInfoModel redPacketInfoModel) { super(context); + this.redPacketInfoModel = redPacketInfoModel; + this.noData = noData; } // 返回自定义弹窗的布局离开 @Override protected int getImplLayoutId() { - return R.layout.view_result_red_packet; + if (noData) { + return R.layout.view_no_red_packet; + } else { + return R.layout.view_result_red_packet; + } } // 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑 @@ -35,11 +45,45 @@ public class ResultRendPacketPopup extends CenterPopupView { private void initView() { - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.illustrate_close), () -> dismiss()); - ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.anchor_his_heart), () -> { - dismiss(); - Bus.get().post(new LiveAudienceEvent() - .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP)); + if (noData) { + + } else { + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.illustrate_close), () -> dismiss()); + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.anchor_his_heart), () -> { + dismiss(); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.GIFT_POPUP)); + }); + LinearLayout goldenLayout = findViewById(R.id.golden_layout); + TextView goldenName = findViewById(R.id.golden_name); + LinearLayout giftLayout = findViewById(R.id.gift_layout); + TextView giftTitle = findViewById(R.id.gift_title); + ImageView giftImage = findViewById(R.id.gift_image); + ImageView goldenIconBeans = findViewById(R.id.golden_icon_beans); + if (redPacketInfoModel.getGiftModels() != null) { + if (redPacketInfoModel.getGiftModels().size() > 1) { + goldenLayout.setVisibility(VISIBLE); + giftLayout.setVisibility(VISIBLE); + giftTitle.setText(redPacketInfoModel.getGiftModels().get(0).getGiftname()); + ImgLoader.displayAvatar(getContext(), redPacketInfoModel.getGiftModels().get(0).getGifticon(), giftImage); + ImgLoader.displayAvatar(getContext(), redPacketInfoModel.getGiftModels().get(1).getGifticon(), goldenIconBeans); + goldenName.setText(redPacketInfoModel.getGiftModels().get(1).getGiftname()); + } else { + if (redPacketInfoModel.getGiftModels().size() > 0) { + ImgLoader.displayAvatar(getContext(), redPacketInfoModel.getGiftModels().get(0).getGifticon(), goldenIconBeans); + goldenName.setText(redPacketInfoModel.getGiftModels().get(0).getGiftname()); + } + goldenLayout.setVisibility(VISIBLE); + giftLayout.setVisibility(GONE); + + } + } + } + ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.view_lucky_viewers), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + + } }); } 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 648708eca..d64e7c4fd 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -83,6 +83,7 @@ import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.NewPeopleTaskModel; import com.yunbao.common.bean.PkRankBean; import com.yunbao.common.bean.RankHourModel; +import com.yunbao.common.bean.RedPacketInfoModel; import com.yunbao.common.bean.RedPacketModel; import com.yunbao.common.bean.RewardAllModel; import com.yunbao.common.bean.StarChallengeStatusModel; @@ -155,6 +156,7 @@ import com.yunbao.live.dialog.LiveUserAnchorMailBoxWebInfoPopDialog; import com.yunbao.live.dialog.LiveUserDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; import com.yunbao.live.dialog.ReceiveRendPacketPopup; +import com.yunbao.live.dialog.ResultRendPacketPopup; import com.yunbao.live.event.LiveAnchorEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; @@ -1413,7 +1415,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis redPacketQueue.setVisibility(View.GONE); redPacketCountdown.setVisibility(View.VISIBLE); redTimeCountdown = redPacketModel.getCountdown() - 180; - redPacketCountdown.setText(TimeUtils.getTime(redTimeCountdown)); + redPacketCountdown.setText(String.format(mContext.getString(R.string.red_packet_countdown), TimeUtils.getTime(redTimeCountdown))); timeHandler.postDelayed(timeRunnable, 1000); } else { redPacketQueue.setVisibility(View.VISIBLE); @@ -1426,9 +1428,35 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.red_packet), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - new XPopup.Builder(mContext) - .asCustom(new ReceiveRendPacketPopup(mContext, redTimeCountdown, mLiveUid, redPacketModel.getRedPacketId())) - .show(); + LiveNetManager.get(mContext) + .redPacketInfo(mLiveUid, redPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(RedPacketInfoModel data) { + if (TextUtils.equals(data.getReceiveStatus(), "0")) { + new XPopup.Builder(mContext) + .asCustom(new ReceiveRendPacketPopup(mContext, redTimeCountdown, mLiveUid, mStream, redPacketModel.getRedPacketId(), data)) + .show(); + } else if (TextUtils.equals(data.getReceiveStatus(), "1")) { + new XPopup.Builder(mContext) + .asCustom(new ResultRendPacketPopup(mContext, true, null)) + .show(); + } else { + new XPopup.Builder(mContext) + .asCustom(new ResultRendPacketPopup(mContext, false, data)) + .show(); + } + + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + new XPopup.Builder(mContext) + .asCustom(new ResultRendPacketPopup(mContext, true, null)) + .show(); + } + }); + } }); } diff --git a/live/src/main/res/layout/view_no_red_packet.xml b/live/src/main/res/layout/view_no_red_packet.xml new file mode 100644 index 000000000..507643447 --- /dev/null +++ b/live/src/main/res/layout/view_no_red_packet.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_result_red_packet.xml b/live/src/main/res/layout/view_result_red_packet.xml index ae3a95066..d98f87e34 100644 --- a/live/src/main/res/layout/view_result_red_packet.xml +++ b/live/src/main/res/layout/view_result_red_packet.xml @@ -30,21 +30,63 @@ android:textSize="18sp" android:textStyle="bold" /> - + android:layout_height="wrap_content"> - + + + + + + + + + + + + + +