From 895a1c695169a8e00e941d6bae244388c22b5f42 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 3 Jul 2023 17:48:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E4=B8=AD=E5=A5=96=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/http/PDLiveApi.java | 9 ++ .../common/http/live/LiveNetManager.java | 22 +++++ .../live/activity/LiveRyAnchorActivity.java | 6 +- .../yunbao/live/views/LiveRoomViewHolder.java | 93 ++++++++++++++----- .../views/RedPacketLuckUserViewHolder.java | 2 +- live/src/main/res/layout/view_live_room.xml | 5 +- .../res/layout/view_red_packet_luck_user.xml | 2 +- 7 files changed, 109 insertions(+), 30 deletions(-) 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 01579edd5..2da48355c 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -788,4 +788,13 @@ public interface PDLiveApi { Observable>> getRedPacketSuperPrizeReceive( @Query("super_jackpot_id") String superJackpotId ); + + /** + * 获取普通红包的领取记录 + */ + @GET("/api/public/?service=Live.endRedPacket") + Observable> endRedPacket( + @Query("liveuid") String liveUid, + @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 49aebd9a5..400af5a58 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 @@ -1692,6 +1692,28 @@ public class LiveNetManager { }).isDisposed(); } + public void endRedPacket(String liveUid,String redPacketId, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .endRedPacket(liveUid, redPacketId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel objectResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(""); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + /** * 直播间取消网络请求 */ diff --git a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java index e6c2fcfe2..49071acc6 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -1644,7 +1644,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl case LIVE_END: endLive(); break; - + case RED_PACKET: + if (manager != null) { + mLiveRoomViewHolder.redPacketManage(event.getRedPacketModel()); + } + break; } } 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 dcf9709de..88004e20c 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -1404,24 +1404,59 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } }; + //主播倒计时调用接口 + private Handler anchorTimeHandler = new Handler(); + private int mCountdown; + private Runnable anchorTimeRunnable = new Runnable() { + @Override + public void run() { + if (mCountdown > 0) { + mCountdown = mCountdown - 1; + anchorTimeHandler.postDelayed(anchorTimeRunnable, 1000); + Log.e("主播倒计时", String.format(mContext.getString(R.string.red_packet_countdown), TimeUtils.getTime(mCountdown))); + } else { + redPacket.setVisibility(View.GONE); + anchorTimeHandler.removeCallbacks(anchorTimeRunnable); + LiveNetManager.get(mContext). + endRedPacket(mLiveUid, mRedPacketModel.getRedPacketId(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(String data) { + + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + } + }; /** * 红包相关处理 */ public void redPacketManage(RedPacketModel redPacketModel) { + anchorTimeHandler.removeCallbacks(anchorTimeRunnable); + timeHandler.removeCallbacks(timeRunnable); mRedPacketModel = redPacketModel; if (redPacketModel.getIsShow() == 1) { redPacket.setVisibility(View.VISIBLE); if (redPacketModel.getCountdown() > 180) { redPacketQueue.setVisibility(View.GONE); redPacketCountdown.setVisibility(View.VISIBLE); - redTimeCountdown = redPacketModel.getCountdown() - 180; + mCountdown = redPacketModel.getCountdown(); + redTimeCountdown = mCountdown - 180; redPacketCountdown.setText(String.format(mContext.getString(R.string.red_packet_countdown), TimeUtils.getTime(redTimeCountdown))); - timeHandler.postDelayed(timeRunnable, 1000); + timeHandler.post(timeRunnable); } else { redPacketQueue.setVisibility(View.VISIBLE); redPacketCountdown.setVisibility(View.GONE); } + if (IMLoginManager.get(mContext).getUserInfo().anchorUserType() && mContext instanceof LiveRyAnchorActivity) { + anchorTimeHandler.removeCallbacks(anchorTimeRunnable); + anchorTimeHandler.post(anchorTimeRunnable); + } } else { hindeRedPacket(); } @@ -1429,34 +1464,40 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.red_packet), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { - 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, false)) - .show(); - } else if (TextUtils.equals(data.getReceiveStatus(), "1")) { + + if (!(mContext instanceof LiveRyAnchorActivity)) { + 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, false)) + .show(); + } else if (TextUtils.equals(data.getReceiveStatus(), "1")) { + new XPopup.Builder(mContext) + .asCustom(new ResultRendPacketPopup(mContext, true, null, false)) + .show(); + } else { + new XPopup.Builder(mContext) + .asCustom(new ResultRendPacketPopup(mContext, false, data.setRedPacketId(redPacketModel.getRedPacketId()), false)) + .show(); + } + if (TextUtils.equals(data.getConditions(), "1")) { + follow(); + } + } + + @Override + public void onError(String error) { + ToastUtil.show(error); new XPopup.Builder(mContext) .asCustom(new ResultRendPacketPopup(mContext, true, null, false)) .show(); - } else { - new XPopup.Builder(mContext) - .asCustom(new ResultRendPacketPopup(mContext, false, data.setRedPacketId(redPacketModel.getRedPacketId()), false)) - .show(); } + }); + } - } - - @Override - public void onError(String error) { - ToastUtil.show(error); - new XPopup.Builder(mContext) - .asCustom(new ResultRendPacketPopup(mContext, true, null, false)) - .show(); - } - }); } }); @@ -1568,6 +1609,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis */ public void resetView() { timeHandler.removeCallbacks(timeRunnable); + anchorTimeHandler.removeCallbacks(anchorTimeRunnable); resetViewGone(); visibility = false; pkUidTmp = ""; @@ -3681,6 +3723,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void clearData() { timeHandler.removeCallbacks(timeRunnable); + anchorTimeHandler.removeCallbacks(anchorTimeRunnable); LiveHttpUtil.cancel(LiveHttpConsts.GET_USER_LIST); LiveHttpUtil.cancel(LiveHttpConsts.TIME_CHARGE); CommonHttpUtil.cancel(CommonHttpConsts.SET_ATTENTION); diff --git a/live/src/main/java/com/yunbao/live/views/RedPacketLuckUserViewHolder.java b/live/src/main/java/com/yunbao/live/views/RedPacketLuckUserViewHolder.java index f5d4abd96..465df90e3 100644 --- a/live/src/main/java/com/yunbao/live/views/RedPacketLuckUserViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/RedPacketLuckUserViewHolder.java @@ -25,6 +25,6 @@ public class RedPacketLuckUserViewHolder extends RecyclerView.ViewHolder { public void showData(RedPacketGiftModel redPacketGiftModel) { ImgLoader.displayAvatar(itemView.getContext(), redPacketGiftModel.getGifticon(), giftImage); giftName.setText(redPacketGiftModel.getUserNicename()); - giftNumber.setText(redPacketGiftModel.getGiftNum()); + giftNumber.setText(redPacketGiftModel.getNeedcoin()); } } diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index c1db541e4..7e621c3d3 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -716,7 +716,8 @@ android:layout_height="wrap_content" android:layout_below="@+id/live_rank_pk" android:layout_marginStart="12dp" - android:layout_marginTop="15dp" /> + android:layout_marginTop="15dp" + android:visibility="gone" /> - +