diff --git a/common/src/main/java/com/yunbao/common/bean/UserBean.java b/common/src/main/java/com/yunbao/common/bean/UserBean.java index 2f8df56aa..14e3fc896 100644 --- a/common/src/main/java/com/yunbao/common/bean/UserBean.java +++ b/common/src/main/java/com/yunbao/common/bean/UserBean.java @@ -61,6 +61,16 @@ public class UserBean implements Parcelable { private int praise; //是否隐藏 private boolean isHide = false; + //是否为随机PK,仅在主播PK时使用 + private boolean randomPk; + + public boolean isRandomPk() { + return randomPk; + } + + public void setRandomPk(boolean randomPk) { + this.randomPk = randomPk; + } public boolean isHide() { return isHide; 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 9a6ec7d76..a80b29725 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -370,7 +370,7 @@ public interface PDLiveApi { * 随机PK后调用接口给后台记录 */ @GET("/api/public/?service=Livepk.startRandomPK") - Observable> startRandomPK(); + Observable> startRandomPK(@Query("pkuid")String pkuid); /** * 自由PK开始后调用接口扣掉次数 */ @@ -383,4 +383,9 @@ public interface PDLiveApi { */ @GET("/api/public/?service=Livepk.searchUser") Observable>> randomPkSearchUser(@Query("jian_key")String cs,@Query("fan_key")String ct); + /** + * 拒绝随机PK + */ + @GET("/api/public/?service=Livepk.setBanRandomPK") + Observable> setBanRandomPK(); } 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 21540654c..fca57f4f1 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 @@ -637,9 +637,9 @@ public class LiveNetManager { /** * 随机PK后调用接口给后台记录 */ - public void startRandomPK(HttpCallback callback) { + public void startRandomPK(String pkuid,HttpCallback callback) { API.get().pdLiveApi(mContext) - .startRandomPK() + .startRandomPK(pkuid) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer>() { @@ -691,7 +691,28 @@ public class LiveNetManager { } }).isDisposed(); } + /** + * 拒绝随机PK + */ + public void setBanRandomPK(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .setBanRandomPK() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel responseModel) throws Exception { + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } /** * 直播间取消网络请求 */ diff --git a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java index d16825de6..a8c29ca16 100644 --- a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java +++ b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java @@ -29,6 +29,7 @@ public class RandomPkManager { private Timer timer; private TimerTask task; private List randomPkTimer = new ArrayList<>(); + private String pkUid; Handler handler = new Handler(Looper.getMainLooper()); private RandomPkManager() { @@ -94,6 +95,7 @@ public class RandomPkManager { .randomPK(new HttpCallback() { @Override public void onSuccess(String data) { + pkUid = data; for (OnRandomPkTimer pkTimer : randomPkTimer) { pkTimer.onStartPK(data); } @@ -179,6 +181,7 @@ public class RandomPkManager { } task = null; status = PK_STATUS_DEFAULT; + pkUid = null; callEnd(); } @@ -208,6 +211,18 @@ public class RandomPkManager { pkTimer.onPking(); } }); + LiveNetManager.get(CommonAppContext.getTopActivity()) + .startRandomPK(pkUid, new HttpCallback() { + @Override + public void onSuccess(Boolean data) { + + } + + @Override + public void onError(String error) { + + } + }); } private void callRefuse() { @@ -228,8 +243,8 @@ public class RandomPkManager { callEnd(); break; case PK_STATUS_REFUSE: - callRefuse(); - //nextPk(); + //callRefuse(); + nextPk(); break; } } diff --git a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java index b8b2583f7..9ddea94c3 100644 --- a/common/src/main/java/com/yunbao/common/utils/DialogUitl.java +++ b/common/src/main/java/com/yunbao/common/utils/DialogUitl.java @@ -3,8 +3,10 @@ package com.yunbao.common.utils; import android.app.Activity; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.text.InputFilter; import android.text.InputType; +import android.text.Spanned; import android.text.TextUtils; import android.text.format.DateFormat; import android.util.SparseArray; @@ -322,7 +324,9 @@ public class DialogUitl { private int mLength; private SimpleCallback mClickCallback; private SimpleCallback3 mClickCallback3; + private SimpleCallbackView mSimpleCallbackView; private int mView = 0; + private CharSequence mSpanned; public Builder(Context context) { mContext = context; @@ -335,6 +339,18 @@ public class DialogUitl { public Builder setContent(String content) { mContent = content; + this.mSpanned = null;//设置文本则不是使用HTML代码 + return this; + } + + public Builder setHtmlCode(CharSequence mSpanned) { + this.mSpanned = mSpanned; + this.mContent = null;//设置HTML代码则不使用文本 + return this; + } + + public Builder setSimpleCallbackView(SimpleCallbackView mSimpleCallbackView) { + this.mSimpleCallbackView = mSimpleCallbackView; return this; } @@ -413,6 +429,9 @@ public class DialogUitl { if (!TextUtils.isEmpty(mContent)) { content.setText(mContent); } + if (mSpanned != null) { + content.setText(mSpanned); + } if (mInputType == INPUT_TYPE_NUMBER) { content.setInputType(InputType.TYPE_CLASS_NUMBER); } else if (mInputType == INPUT_TYPE_NUMBER_PASSWORD) { @@ -443,23 +462,33 @@ public class DialogUitl { mClickCallback.onConfirmClick(dialog, ""); } } else { - dialog.dismiss(); + if (mClickCallback3 != null) { mClickCallback3.onConfirmClick(dialog); } + if (mSimpleCallbackView != null) { + mSimpleCallbackView.onConfirmClick(dialog,titleView, content, btnConfirm, btnCancel); + }else{ + dialog.dismiss(); + } } } else { - dialog.dismiss(); + if (mClickCallback3 != null) { mClickCallback3.onCancel(); - + dialog.dismiss(); } else { if (mClickCallback instanceof SimpleCallback2) { ((SimpleCallback2) mClickCallback).onCancelClick(); } + if (mSimpleCallbackView != null) { + mSimpleCallbackView.onCancel(dialog,titleView, content, btnConfirm, btnCancel); + }else{ + dialog.dismiss(); + } } } @@ -467,6 +496,14 @@ public class DialogUitl { }; btnConfirm.setOnClickListener(listener); btnCancel.setOnClickListener(listener); + dialog.setOnShowListener(new DialogInterface.OnShowListener() { + @Override + public void onShow(DialogInterface dialogInterface) { + if (mSimpleCallbackView != null) { + mSimpleCallbackView.onShow(dialog,titleView, content, btnConfirm, btnCancel); + } + } + }); return dialog; } @@ -494,6 +531,14 @@ public class DialogUitl { void onCancel(); } + public interface SimpleCallbackView { + void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn); + + void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn); + + void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn); + } + /** * 城市选择 diff --git a/common/src/main/res/layout/dialog_live_random_pk.xml b/common/src/main/res/layout/dialog_live_random_pk.xml new file mode 100644 index 000000000..fb9722722 --- /dev/null +++ b/common/src/main/res/layout/dialog_live_random_pk.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index bcb7f4c6c..68e547f56 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -966,4 +966,9 @@ 更多設置 查看更多 礼物正在获取中... + + 接受 + 拒绝 + 坚持拒绝 + 随机PK提示 diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java index f8e9d3078..711d73b03 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1,5 +1,6 @@ package com.yunbao.live.presenter; +import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -10,6 +11,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; +import android.text.Html; import android.text.TextUtils; import android.util.Log; import android.view.Gravity; @@ -18,6 +20,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.PopupWindow; +import android.widget.TextView; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -26,9 +29,11 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.StringUtil; @@ -47,9 +52,14 @@ import com.yunbao.live.socket.SocketSendBean; import com.yunbao.live.views.LiveLinkMicPkViewHolder; import com.yunbao.live.views.LivePushRyViewHolder; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.RCRTCMixConfig; @@ -76,7 +86,6 @@ import static com.lzy.okgo.utils.HttpUtils.runOnUiThread; import static com.yunbao.common.Constants.SOCKET_LINK_MIC_PK; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; import static com.yunbao.live.activity.LiveRyAnchorActivity.isDRPK; -import static com.yunbao.live.views.AbsRyLivePushViewHolder.leave; import static com.yunbao.live.views.AbsRyLivePushViewHolder.mPreView; import static com.yunbao.live.views.AbsRyLivePushViewHolder.mPreView1; import static com.yunbao.live.views.LivePushRyViewHolder.contexts; @@ -579,7 +588,8 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mApplyNmae = u.getUserNiceName(); if (by != 1) { if (mIsApplyDialogShow == false) { - showApplyDialog(u); + // showApplyDialog(u); + showPkDialog(u); } } else { isPK(); @@ -993,46 +1003,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { }); } else { - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { - @Override - public void onFailed(RTCErrorCode errorCode) { - - } - - @Override - public void onSuccess() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LINK_MIC_PK) - .param("action", 3); - msg1.create(); - - String targetId = u.getId(); - Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); - - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { - - } - - @Override - public void onSuccess(io.rong.imlib.model.Message message) { - Log.e("ry", "发送成功"); - if (SocketRyClient.mSocketHandler != null) { - SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); - } - } - - @Override - public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { - Log.e("ry", "发送失敗" + u.getId()); - } - }); - } - }); } mApplyUid = null; mApplyStream = null; @@ -1160,6 +1131,132 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } + /** + * 随机PK拒绝对话框 + */ + public void showPkDialog(UserBean u) { + new DialogUitl.Builder(mContext) + .setHtmlCode(Html.fromHtml( + "有人向您发起PK请求。
" + + "若拒绝PK,将会120分钟内不会再收到任何随机PK请求。" + )) + .setConfrimString("接受") + .setCancelString("拒絕") + .setView(R.layout.dialog_live_random_pk) + .setSimpleCallbackView(new DialogUitl.SimpleCallbackView() { + boolean clickCancel = false; + String titleVal; + TimerTask task; + + @Override + public void onShow(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task = new TimerTask() { + int time = 11; + final Handler handler = new Handler(Looper.getMainLooper()); + + @Override + public void run() { + if (titleVal == null) { + titleVal = ((TextView) title).getText().toString(); + } + handler.post(() -> ((TextView) title).setText(titleVal + " " + time)); + if (time-- == 0) { + handler.post(() -> showClose(dialog, title, context, confirmBtn, cancelBtn)); + cancel(); + } + } + }; + new Timer().schedule(task, 1000, 1000); + } + + @Override + public void onConfirmClick(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + dialog.dismiss(); + apply(); + } + + @Override + public void onCancel(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + if (!clickCancel) { + titleVal = "拒絕PK提示"; + ((TextView) context).setText(Html.fromHtml( + "若拒絕PK,將會關閉你的隨機PK開關。
" + + "並且120分鍾不會收到任何隨機PK請求。
" + )); + ((TextView) cancelBtn).setText("堅持拒絕"); + clickCancel = true; + return; + } + showClose(dialog, title, context, confirmBtn, cancelBtn); + } + + void showClose(Dialog dialog, View title, View context, View confirmBtn, View cancelBtn) { + task.cancel(); + ((TextView) title).setText("您因拒絕隨機PK,被限制關閉中"); + ((TextView) confirmBtn).setText("确定"); + ((TextView) context).setText("隨機PK可打開時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis() + 7200000)));//7200000ms=120m=2h + ((TextView) context).setTextSize(12); + ((TextView) context).setTextColor(Color.parseColor("#999999")); + + cancelBtn.setVisibility(View.GONE); + confirmBtn.setOnClickListener(v -> { + refuse(); + dialog.dismiss(); + }); + } + + void refuse() { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + .param("action", 3); + msg1.create(); + + String targetId = u.getId(); + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + + RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { + @Override + public void onAttached(io.rong.imlib.model.Message message) { + + } + + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } + + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗" + u.getId()); + } + }); + } + }); + + LiveNetManager.get(mContext).setBanRandomPK(null); + } + + void apply() { + isPK(); + } + }) + .build().show(); + } + /** * 显示申请多人PK的弹窗 */ @@ -1276,7 +1373,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 *

*/ - IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { @Override public void onSuccess() { } @@ -1352,7 +1449,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { }); } else { - IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(),false, "extra", new IRCRTCResultCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { @Override public void onFailed(RTCErrorCode errorCode) { @@ -1878,7 +1975,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } if (mLiveLinkMicPkViewHolder != null) { if (!TextUtils.isEmpty(winUid)) { - if ("0".equals(winUid)) { + if ("0" .equals(winUid)) { mLiveLinkMicPkViewHolder.end(0); mLiveLinkMicPkViewHolder.hideTime(); if (mHandler != null) { @@ -1997,7 +2094,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { if (mIsAnchor) { ((LiveRyAnchorActivity) mContext).setPkBtnVisible(true); } - // ToastUtil.show(R.string.link_mic_refuse_pk); + // ToastUtil.show(R.string.link_mic_refuse_pk); } /** diff --git a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java index b519801fc..d74f4a8e9 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -224,9 +224,21 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX mLiveRyLinkMicPkPresenter.onLinkMicPkApply(userBean1, "", 1); } else { Log.e("ry", extra); + /* + * { + * "pkhead": "https://downs.yaoulive.com/20220906170849_79c553dc1319fb5c215e06e01674eba4?imageView2/2/w/600/h/600", + * "pkname": "用户_98274", + * "pkuid": "98274", + * "randomPk": true, + * "uid": "98274" + * } + */ UserBean userBean1 = new UserBean(); if (!extra.equals("")) { JSONObject map = JSONObject.parseObject(extra); + userBean1.setAvatar(map.getString("pkhead")); + userBean1.setUserNiceName(map.getString("pkname")); + userBean1.setRandomPk(map.containsKey("randomPk") ? map.getBoolean("randomPk") : false); userBean1.setId(map.getString("uid")); userBean1.setUserNiceName(map.getString("pkname")); userBean1.setAvatar(map.getString("pkhead")); diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 6c21cbfb9..226758ba2 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -17,6 +17,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.Display; @@ -91,10 +92,12 @@ import com.yunbao.common.views.AbsMainViewHolder; import com.yunbao.common.views.floatingview.APPEasyFloat; import com.yunbao.common.views.weight.LiveFloatView; import com.yunbao.live.activity.LiveAudienceActivity; +import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.dialog.RandomPkDialogFragment; import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.utils.LiveStorge; import com.yunbao.live.views.ChatListViewHolder; import com.yunbao.main.R;