diff --git a/common/src/main/java/com/yunbao/common/CommonAppContext.java b/common/src/main/java/com/yunbao/common/CommonAppContext.java index f511106fc..61be02d65 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppContext.java +++ b/common/src/main/java/com/yunbao/common/CommonAppContext.java @@ -83,6 +83,9 @@ public class CommonAppContext extends MultiDexApplication { } + public static Activity getTopActivity() { + return activityWeakReference.get(); + } @Override protected void attachBaseContext(Context base) { @@ -100,7 +103,7 @@ public class CommonAppContext extends MultiDexApplication { @Override public void onActivityStarted(Activity activity) { mCount++; - activityWeakReference=new WeakReference<>(activity); + activityWeakReference = new WeakReference<>(activity); if (!mFront) { mFront = true; L.e("AppContext------->处于前台"); diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index 2f36c14e1..30b3562e6 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -132,6 +132,7 @@ public class Constants { public static final int LIVE_FUNC_MIC = 2013;//語音 public static final int LIVE_FUNC_WKS = 2014;//語音 public static final int LIVE_FUNC_ZSLK = 2015;//語音 + public static final int LIVE_FUNC_RANDOM_PK = 2016;//随机PK //socket public static final String SOCKET_CONN = "conn"; @@ -145,6 +146,7 @@ public class Constants { public static final String SOCKET_ALL_SERVER_NOTIFY = "AllServerNotify";//全服通知 public static final String SOCKET_SEND_BARRAGE = "SendBarrage";//发弹幕 public static final String SOCKET_LIVE_DRPK = "LiveDRPK";//多人PK + public static final String SOCKET_LIVE_DRPK_RANDOM = "LiveRandomPK";//多人PK public static final String SOCKET_LEAVE_ROOM = "disconnect";//用户离开房间 public static final String SOCKET_LIVE_END = "StartEndLive";//主播关闭直播 public static final String SOCKET_SYSTEM = "SystemNot";//系统消息 diff --git a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java index 8856fff3a..0801887be 100644 --- a/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java +++ b/common/src/main/java/com/yunbao/common/activity/WebViewActivity.java @@ -73,7 +73,7 @@ public class WebViewActivity extends AbsActivity { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); params.topMargin = DpUtil.dp2px(1); - // mWebView.setLayoutParams(params); + // mWebView.setLayoutParams(params); //mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER); mWebView.setWebViewClient(new WebViewClient() { @Override @@ -96,9 +96,11 @@ public class WebViewActivity extends AbsActivity { if (url.contains("for")) { mWebView.loadUrl("javascript:goAnchorTab()"); } - //屏幕高度-ft_title的paddingTop - int height = DeviceUtils.getScreenHeight(mContext)-DpUtil.dp2px(24); - view.loadUrl("javascript:window.androidObject.setHeight("+height+",0,false)"); + //真实屏幕高度-(ft_title的高度+导航栏高度) + int height = DeviceUtils.getScreenRealHeight(mContext) - DpUtil.dp2px(72) - getCurrentNavigationBarHeight(mContext); + if (!navigationGestureEnabled(mContext)) { + view.loadUrl("javascript:window.androidObject.setHeight(" + height + ",0,false)"); + } } }); diff --git a/common/src/main/java/com/yunbao/common/bean/HttpCallbackModel.java b/common/src/main/java/com/yunbao/common/bean/HttpCallbackModel.java new file mode 100644 index 000000000..c2369455f --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/HttpCallbackModel.java @@ -0,0 +1,23 @@ +package com.yunbao.common.bean; + + +public class HttpCallbackModel extends BaseModel{ + private int code; + private String msg; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/RandomPkUserBean.java b/common/src/main/java/com/yunbao/common/bean/RandomPkUserBean.java new file mode 100644 index 000000000..d50d8b0c6 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/RandomPkUserBean.java @@ -0,0 +1,89 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 随机PK UserBean + */ +public class RandomPkUserBean extends UserBean { + @SerializedName("is_pk") + private int pk; + @SerializedName("isattention") + private String attention; + @SerializedName("user_nicename") + private String userNiceName; + + public RandomPkUserBean() { + } + + public boolean isPk() { + return pk==1; + } + + public boolean isAttention() { + return attention.equals("1"); + } + + public String getAttention() { + return attention; + } + + public void setAttention(String attention) { + this.attention = attention; + } + + public int getPk() { + return pk; + } + + public void setPk(int pk) { + this.pk = pk; + } + + @Override + public String getUserNiceName() { + return userNiceName; + } + + @Override + public void setUserNiceName(String userNiceName) { + this.userNiceName = userNiceName; + } + + @Override + public String toString() { + return "RandomPkUserBean{" + + "pk=" + pk + + ", attention='" + attention + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", id='" + id + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", avatar='" + avatar + '\'' + + ", avatarThumb='" + avatarThumb + '\'' + + ", sex=" + sex + + ", signature='" + signature + '\'' + + ", coin='" + coin + '\'' + + ", gold='" + gold + '\'' + + ", votes='" + votes + '\'' + + ", consumption='" + consumption + '\'' + + ", votestotal='" + votestotal + '\'' + + ", province='" + province + '\'' + + ", city='" + city + '\'' + + ", location='" + location + '\'' + + ", birthday='" + birthday + '\'' + + ", level=" + level + + ", levelAnchor=" + levelAnchor + + ", lives=" + lives + + ", follows=" + follows + + ", fans=" + fans + + ", vip=" + vip + + ", liang=" + liang + + ", car=" + car + + ", medal_level=" + medal_level + + ", medal_name='" + medal_name + '\'' + + ", Dress=" + Dress + + ", noble_id='" + noble_id + '\'' + + ", yuanbao='" + yuanbao + '\'' + + '}'; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/RankPkInfoBean.java b/common/src/main/java/com/yunbao/common/bean/RankPkInfoBean.java new file mode 100644 index 000000000..eca93951b --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/RankPkInfoBean.java @@ -0,0 +1,128 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +public class RankPkInfoBean extends BaseModel { + private int id; + @SerializedName("start_time") + private String startTime; + @SerializedName("end_time") + private String endTime; + @SerializedName("pk_start_hour1") + private String pkStartHour1; + @SerializedName("pk_end_hour1") + private String pkEndHour1; + @SerializedName("pk_start_hour2") + private String pkStartHour2; + @SerializedName("pk_end_hour2") + private String pkEndHour2; + + public RankPkInfoBean() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public String getPkStartHour1() { + return pkStartHour1; + } + + public void setPkStartHour1(String pkStartHour1) { + this.pkStartHour1 = pkStartHour1; + } + + public String getPkEndHour1() { + return pkEndHour1; + } + + public void setPkEndHour1(String pkEndHour1) { + this.pkEndHour1 = pkEndHour1; + } + + public String getPkStartHour2() { + return pkStartHour2; + } + + public void setPkStartHour2(String pkStartHour2) { + this.pkStartHour2 = pkStartHour2; + } + + public String getPkEndHour2() { + return pkEndHour2; + } + + public void setPkEndHour2(String pkEndHour2) { + this.pkEndHour2 = pkEndHour2; + } + + /** + * 判断是否在排位赛时间范围内 + */ + public boolean isRankPKTime() { + try { + Date now =new Date(); + Date startDate = simpleDateToDate(startTime, "yyyy-MM-dd HH:mm:ss"); + Date endDate = simpleDateToDate(endTime, "yyyy-MM-dd HH:mm:ss"); + if (startDate == null || endDate == null) { + return false; + } + Calendar calendarStart = Calendar.getInstance(Locale.CHINA); + Calendar calendarEnd = Calendar.getInstance(Locale.CHINA); + Calendar calendarNow = Calendar.getInstance(Locale.CHINA); + calendarNow.setTime(now); + calendarStart.setTime(startDate); + calendarEnd.setTime(endDate); + if (calendarStart.before(calendarNow) && calendarEnd.after(calendarNow)) { + calendarNow.setTime(simpleDateToDate(dateToSimpleDate(now,"HH:mm:ss"),"HH:mm:ss")); + calendarStart.setTime(simpleDateToDate(pkStartHour1, "HH:mm:ss")); + calendarEnd.setTime(simpleDateToDate(pkEndHour1, "HH:mm:ss")); + if (calendarStart.before(calendarNow) && calendarEnd.after(calendarNow)) { + return true; + } else { + calendarNow.setTime(simpleDateToDate(dateToSimpleDate(now,"HH:mm:ss"),"HH:mm:ss")); + calendarStart.setTime(simpleDateToDate(pkStartHour2, "HH:mm:ss")); + calendarEnd.setTime(simpleDateToDate(pkEndHour2, "HH:mm:ss")); + return calendarStart.before(calendarNow) && calendarEnd.after(calendarNow); + } + } + } catch (ParseException e) { + e.printStackTrace(); + } + return false; + } + + + private Date simpleDateToDate(String time, String pattern) throws ParseException { + return new SimpleDateFormat(pattern, Locale.CHINA).parse(time); + } + private String dateToSimpleDate(Date date,String pattern){ + return new SimpleDateFormat(pattern,Locale.CHINA).format(date); + } +} 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..0134c53a5 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,26 @@ public class UserBean implements Parcelable { private int praise; //是否隐藏 private boolean isHide = false; + //是否为随机PK,仅在主播PK时使用 + private boolean randomPk; + //随机天梯排位赛PK img,仅在主播PK时使用 + private String mRankPkImgUrl; + + public boolean isRandomPk() { + return randomPk; + } + + public void setRandomPk(boolean randomPk) { + this.randomPk = randomPk; + } + + public String getRankPkImgUrl() { + return mRankPkImgUrl; + } + + public void setRankPkImgUrl(String mRankPkImgUrl) { + this.mRankPkImgUrl = mRankPkImgUrl; + } 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 255462408..090ee0e81 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -9,6 +9,7 @@ import com.yunbao.common.bean.CustomSidebarInfoModel; import com.yunbao.common.bean.EnterRoomNewModel; import com.yunbao.common.bean.FaceBookUpModel; import com.yunbao.common.bean.HourRank; +import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.LiveInfoModel; @@ -18,6 +19,8 @@ import com.yunbao.common.bean.NewPeopleInfo; import com.yunbao.common.bean.NobleRankHideUserListModel; import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.PkRankBean; +import com.yunbao.common.bean.RandomPkUserBean; +import com.yunbao.common.bean.RankPkInfoBean; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SlideInBannerModel; @@ -177,7 +180,7 @@ public interface PDLiveApi { * 获取多人连麦列表 */ @GET("/api/public/?service=live.getDrLm") - Observable>> getDrLm(@Query("uid")String uid); + Observable>> getDrLm(@Query("uid") String uid); /** * 获取日榜、周榜数据 @@ -286,8 +289,9 @@ public interface PDLiveApi { Observable> delDrLm(); /** - * 多人连麦-踢出用户 - * @param uid 对方uid + * 多人连麦-踢出用户 + * + * @param uid 对方uid * @param roomId 当前房间号 */ @GET("/api/public/?service=Live.killDrLm") @@ -338,4 +342,56 @@ public interface PDLiveApi { @Query("GroupId") String GroupId, @Query("stream") String stream ); + + /** + * 获取随机PK开关 + * + * @return 1=开,0=关 + */ + @GET("/api/public/?service=Livepk.getRandomPKType") + Observable>> getRandomPkSwitch(); + + /** + * 设置随机PK开关 + * @param pk 1=开,0=关 + */ + @GET("/api/public/?service=Livepk.setRandomPKType") + Observable>> changeRandomPkSwitch(@Query("random_pk") int pk); + /** + * 获取随机PK次数 + */ + @GET("/api/public/?service=Livepk.getRandomPKType") + Observable> getRandomPkNumber(); + /** + * 发起随机PK + */ + @GET("/api/public/?service=Livepk.setRandomPK") + Observable> randomPK(); + /** + * 随机PK后调用接口给后台记录 + */ + @GET("/api/public/?service=Livepk.startRandomPK") + Observable> startRandomPK(@Query("pkuid")String pkuid); + /** + * 自由PK开始后调用接口扣掉次数 + */ + @GET("/api/public/?service=Livepk.setActivePkNum") + Observable> setRandomPkNum(); + /** + * 随机PK搜索用户 + * @param cs 简体关键字/uid + * @param ct 繁体关键字/uid + */ + @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(); + /** + * 拒绝随机PK + */ + @GET("/api/public/?service=Ranking.getRankingInfo") + Observable> getRankingInfo(); } 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 e35962d1d..ce73964ab 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 @@ -4,6 +4,7 @@ import android.content.Context; import android.text.TextUtils; import android.util.Log; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.bean.ActiveModel; @@ -11,6 +12,7 @@ import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.CheckLiveModel; import com.yunbao.common.bean.CustomSidebarInfoModel; import com.yunbao.common.bean.EnterRoomNewModel; +import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.LiveInfoModel; @@ -18,6 +20,8 @@ import com.yunbao.common.bean.LiveRoomActivityBanner; import com.yunbao.common.bean.NobleRankHideUserListModel; import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.PkRankBean; +import com.yunbao.common.bean.RandomPkUserBean; +import com.yunbao.common.bean.RankPkInfoBean; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.VipModel; @@ -484,6 +488,9 @@ public class LiveNetManager { private Disposable randomPkApi; + /** + * PK排位赛接口 + */ public void getRandomPk(String mLiveUid, String pkUid, HttpCallback callback) { randomPkApi = API.get().pdLiveApi(mContext) .getPkRanksList(mLiveUid, pkUid) @@ -501,6 +508,246 @@ public class LiveNetManager { }); } + /** + * 获取随机PK开关 + * 1=开,0=关 + */ + public void getRandomPkSwitch(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getRandomPkSwitch() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(listResponseModel -> { + if (callback != null) { + callback.onSuccess(listResponseModel.getData().getInfo().get(0)); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + + } + + /** + * 设置随机PK开关 + * + * @param pk 1=开,0=关 + * @param callback @{@link HttpCallbackModel#getCode()} 0=成功 + */ + public void changeRandomPkSwitch(int pk, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .changeRandomPkSwitch(pk) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> responseModel) throws Exception { + if (callback != null) { + HttpCallbackModel model = new HttpCallbackModel(); + model.setCode(responseModel.getData().getCode()); + model.setMsg(responseModel.getData().getMsg()); + callback.onSuccess(model); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 获取随机PK次数 + */ + public void getRandomPkNumber(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getRandomPkNumber() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel responseModel) throws Exception { + if (callback != null) { + callback.onSuccess(responseModel.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 发起随机PK + */ + public void randomPK(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .randomPK() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel responseModel) throws Exception { + if (callback != null) { + if(CommonAppConfig.getInstance().getUid().equals("98196")) { + callback.onSuccess("98274"); + }else{ + callback.onSuccess("98196"); + } + // callback.onSuccess(responseModel.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 自由PK开始后调用接口扣掉次数 + */ + public void setRandomPkNum(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .setRandomPkNum() + .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(); + } + + /** + * 随机PK后调用接口给后台记录 + */ + public void startRandomPK(String pkuid, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .startRandomPK(pkuid) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel responseModel) throws Exception { + if (responseModel.getData().getCode() == 0) { + if (callback != null) { + callback.onSuccess(true); + } + } else { + callback.onSuccess(false); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).isDisposed(); + } + + /** + * 随机PK后调用接口给后台记录 + * + * @param cs 简体关键字/uid + * @param ct 繁体关键字/uid + */ + public void randomPkSearchUser(String cs, String ct, HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .randomPkSearchUser(cs, ct) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>>() { + @Override + public void accept(ResponseModel> responseModel) throws Exception { + if (responseModel.getData().getCode() == 0) { + if (callback != null) { + callback.onSuccess(responseModel.getData().getInfo()); + } + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(throwable.getMessage()); + } + } + }).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(); + } + + /** + * 获取随机排位赛信息 + */ + public void getRankPkInfoBean(HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getRankingInfo() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel rankPkInfoBeanResponseModel) throws Exception { + if (callback != null) { + callback.onSuccess(rankPkInfoBeanResponseModel.getData().getInfo()); + } + } + }, 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/IMRTCManager.java b/common/src/main/java/com/yunbao/common/manager/IMRTCManager.java new file mode 100644 index 000000000..bffa567cd --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/IMRTCManager.java @@ -0,0 +1,91 @@ +package com.yunbao.common.manager; + +import com.yunbao.common.utils.ToastUtil; + +import cn.rongcloud.rtc.api.RCRTCRoom; +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.base.RTCErrorCode; + +/** + * RTC管理类,负责管理申请、同意、拒绝PK + */ +public class IMRTCManager { + private static IMRTCManager manager; + private RCRTCRoom rtcRoom; + + private IMRTCManager() { + + } + + public static IMRTCManager getInstance() { + if (manager == null) { + manager = new IMRTCManager(); + } + return manager; + } + + public void setRtcRoom(RCRTCRoom rtcRoom) { + this.rtcRoom = rtcRoom; + } + + /** + * 响应PK请求 + * @param liveUid 对方房间号 + * @param agree 是否同意 + * @param extra 扩展参数 + * @param callback 回调 + */ + public void responseJoinOtherRoom(String liveUid, boolean agree, String extra, IRCRTCResultCallback callback) { + if (rtcRoom != null) { + /* + inviterRoomId - 邀请者所在房间 id, + inviterUserId - 邀请者用户 id + agree - 被邀请者是否同意连麦邀请 + inviteeAutoMix - 是否将被邀请者音视频资源发送到邀请人房间中合流 + 1:inviteeAutoMix 为true时: + 1.1:如果邀请方在发送连麦请求之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把邀请方流资源合并到被邀请方视图(默认仅悬浮布局合流)上。 + 1.2:如果邀请方在发送连麦请求之前没有发布资源,将会在邀请方发布资源成功后,服务器才会把邀请方的资源合并到被邀请方视图(默认仅悬浮布局合流)上。 + 2: 无论为true或false,双方都可以使用RCRTCLiveInfo.setMixConfig(RCRTCMixConfig, IRCRTCResultCallback) 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + extra - 扩展字段,默认为空 + */ + rtcRoom.getLocalUser().responseJoinOtherRoom(liveUid, liveUid, agree, agree, extra, callback); + } else { + callback.onFailed(RTCErrorCode.RongRTCCodeIMError); + } + } + + /** + * 申请PK + * @param liveUid 对方房间号 + * @param inviterAutoMix 是否将邀请者音视频资源发送到被邀请人房间中合流 + * @param extra 扩展参数 + * @param callback 回调 + */ + public void requestJoinOtherRoom(String liveUid,boolean inviterAutoMix,String extra,IRCRTCResultCallback callback){ + if(rtcRoom!=null){ + /* + inviteeRoomId - 被邀请者所在房间 id + inviteeUserId - 被邀请用户 id + inviterAutoMix - 是否将邀请者音视频资源发送到被邀请人房间中合流 + 1: inviterAutoMix为true时: + 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + 2:无论为true或false,双方都可以使用RCRTCLiveInfo.setMixConfig(RCRTCMixConfig, IRCRTCResultCallback) 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + extra - 扩展字段,默认为空 + */ + rtcRoom.getLocalUser().requestJoinOtherRoom(liveUid, liveUid, inviterAutoMix, extra, new IRCRTCResultCallback() { + @Override + public void onSuccess() { + callback.onSuccess(); + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + callback.onFailed(errorCode); + } + }); + }else{ + callback.onFailed(RTCErrorCode.RongRTCCodeIMError); + } + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java new file mode 100644 index 000000000..032445ad7 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/RandomPkManager.java @@ -0,0 +1,403 @@ +package com.yunbao.common.manager; + +import android.os.Handler; +import android.os.Looper; + +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.RankPkInfoBean; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.ToastUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; + +/** + * 随机PK管理类 + */ +public class RandomPkManager { + public final static int PK_STATUS_DEFAULT = -1;//默认状态,一般为为开始匹配 + public final static int PK_STATUS_REQUEST = 0;//已发出匹配请求 + public final static int PK_STATUS_START = 1;//匹配到用户 + public final static int PK_STATUS_CLOSE = 2;//PK结束 + public final static int PK_STATUS_REFUSE = 3;//对方拒绝 + public final static int PK_STATUS_EXIT_ING = 4;//退出匹配中 + + private static RandomPkManager manager; + private int min = -1;//匹配计时器 分钟 + private int sec = -1;//匹配计时器 秒钟 + private int status = PK_STATUS_DEFAULT; + private Timer timer; + private TimerTask task; + private final List randomPkTimer = new ArrayList<>();//监听器集合 + private String pkUid;//对方房间ID + private RankPkInfoBean rankPkInfoBean;//排位赛信息 + Handler handler = new Handler(Looper.getMainLooper()); + + private RandomPkManager() { + getRankInfo(); + initTask(); + } + + public static RandomPkManager getInstance() { + if (manager == null) { + manager = new RandomPkManager(); + } + return manager; + } + + /** + * 添加监听器 + */ + public void addOnRandomPkTimer(OnRandomPkTimer randomPkTimer) { + if (randomPkTimer != null) { + this.randomPkTimer.add(randomPkTimer); + } + } + + /** + * 移除监听器 + */ + public void unregisterOnRandomPkTimer(OnRandomPkTimer randomPkTimer) { + if (randomPkTimer != null) { + this.randomPkTimer.remove(randomPkTimer); + } + } + + /** + * 初始化参数 + */ + private void initVal() { + min = -1; + sec = -1; + } + + /** + * 初始化任务 + */ + private void initTask() { + if (task != null) { + return; + } + task = new TimerTask() { + + @Override + public void run() { + status = PK_STATUS_REQUEST; + sec++; + if (sec % 60 == 0) { + min++; + sec = 0; + } + handler.post(() -> { + for (OnRandomPkTimer onRandomPkTimer : randomPkTimer) { + onRandomPkTimer.onTimer(String.format(Locale.CHINA, "%02d:%02d", min, sec)); + } + if (sec == 2) { + nextPk(); + } + }); + } + }; + } + + /** + * 格式化匹配时间 + */ + public String getTimer() { + return String.format(Locale.CHINA, "%02d:%02d", min, sec); + } + + /** + * 对方拒绝,开始下一轮匹配 + */ + private void nextPk() { + if (status != PK_STATUS_REQUEST && status != PK_STATUS_REFUSE) { + return; + } + LiveNetManager.get(CommonAppContext.getTopActivity()) + .randomPK(new HttpCallback() { + @Override + public void onSuccess(String data) { + pkUid = data; + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onStartPK(data); + } + } + + @Override + public void onError(String error) { + + } + }); + } + + /** + * 是否为排位赛模式 + */ + public boolean isRankModel() { + return rankPkInfoBean != null && rankPkInfoBean.isRankPKTime(); + } + + /** + * 开始匹配 + */ + public boolean start() { + if (status == PK_STATUS_START) { + ToastUtil.show("PK中"); + return false; + } + if (status == PK_STATUS_EXIT_ING) { + return false; + } + if (task != null) { + task.cancel(); + } + task = null; + initTask(); + initVal(); + timer = new Timer(); + timer.schedule(task, 0, 1000); + return true; + } + private void getRankInfo(){ + LiveNetManager.get(CommonAppContext.getTopActivity()) + .getRankPkInfoBean(new HttpCallback() { + @Override + public void onSuccess(RankPkInfoBean data) { + rankPkInfoBean = data; + } + + @Override + public void onError(String error) { + } + + }); + } + + /** + * 通知所有监听者,开始退出匹配 + */ + private void callEndPkStart() { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onPkEndStart(); + } + } + + /** + * 通知所有监听者,退出匹配倒计时 + */ + private void callEndPkTimer(String time) { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onPkEndTimer(time); + } + } + + /** + * 通知所有监听者,退出匹配成功 + */ + private void callEndPkSuccess() { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onPkEndSuccess(); + } + status = PK_STATUS_DEFAULT; + rankPkInfoBean = null; + } + + private int exitTimer; + + /** + * 退出匹配 + */ + public void exitPk() { + if (status == PK_STATUS_EXIT_ING) { + return; + } + callEndPkStart(); + status = PK_STATUS_EXIT_ING; + exitTimer = 11; + new Timer().schedule(new TimerTask() { + + Handler handler = new Handler(Looper.getMainLooper()); + + @Override + public void run() { + + handler.post(() -> { + exitTimer--; + callEndPkTimer(exitTimer + ""); + if (exitTimer == 0) { + end(); + callEndPkSuccess(); + cancel(); + } + }); + } + }, 0, 1000); + } + + /** + * 退出连麦 + */ + public void end() { + if (task != null) { + task.cancel(); + } + task = null; + status = PK_STATUS_DEFAULT; + pkUid = null; + callEnd(); + } + + /** + * 是否正在匹配中 + */ + public boolean isRequestPk() { + return status == PK_STATUS_REQUEST; + } + + /** + * 通知所有监听者,结束匹配 + */ + private void callEnd() { + if (task != null) { + task.cancel(); + task = null; + } + handler.post(() -> { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onPkEnd(); + } + }); + } + + /** + * 通知所有监听者,开始匹配 + */ + private void callStart() { + if (task != null) { + task.cancel(); + task = null; + } + handler.post(() -> { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onPking(); + } + }); + LiveNetManager.get(CommonAppContext.getTopActivity()) + .startRandomPK(pkUid, new HttpCallback() { + @Override + public void onSuccess(Boolean data) { + + } + + @Override + public void onError(String error) { + + } + }); + } + + /** + * 通知所有监听者,对方拒绝PK + */ + private void callRefuse() { + handler.post(() -> { + for (OnRandomPkTimer pkTimer : randomPkTimer) { + pkTimer.onRefuse(); + } + }); + } + + /** + * 设置PK状态 + */ + public void setPkStatus(int status) { + if (this.status == PK_STATUS_DEFAULT || this.status == PK_STATUS_EXIT_ING) {//默认状态下不响应随机PK接口 + return; + } + this.status = status; + switch (status) { + case PK_STATUS_START: + callStart(); + break; + case PK_STATUS_CLOSE: + callEnd(); + break; + case PK_STATUS_REFUSE: + //callRefuse(); + nextPk(); + break; + } + } + + /** + * 是否正在退出匹配中 + */ + public boolean isExiting() { + return status == PK_STATUS_EXIT_ING; + } + + /** + * 获取退出匹配倒计时 + */ + public String getExitTimer() { + return exitTimer + ""; + } + + + public static abstract class OnRandomPkTimer { + /** + * 匹配倒计时 + */ + public void onTimer(String time) { + } + + /** + * 匹配到对方 + * @param pkUid 对方uid + */ + public void onStartPK(String pkUid) { + } + + /** + * 匹配中 + */ + public void onPking() { + } + + /** + * 连麦结束 + */ + public void onPkEnd() { + } + + /** + * 对方拒绝PK + */ + public void onRefuse() { + } + + /** + * 退出匹配倒计时 + */ + public void onPkEndTimer(String time) { + + } + + /** + * 开始退出匹配 + */ + public void onPkEndStart() { + } + + /** + * 退出匹配成功 + */ + public void onPkEndSuccess() { + } + } +} diff --git a/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java index 282fc17c2..40f76b35d 100644 --- a/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java @@ -5,8 +5,10 @@ import android.app.ActivityManager; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.graphics.Point; import android.text.format.Formatter; import android.util.DisplayMetrics; +import android.view.WindowManager; /** * 设备通用类 @@ -36,6 +38,19 @@ public class DeviceUtils { return displayMetrics.heightPixels; } + /** + * 获取屏幕真实高度 + * + * @param activity activity + * @return 屏幕高度 + */ + public static int getScreenRealHeight(Activity activity) { + WindowManager service = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); + Point point = new Point(); + service.getDefaultDisplay().getRealSize(point); + return point.y; + } + /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) * @@ -63,7 +78,7 @@ public class DeviceUtils { public static String getVersionName(Context context) { try { PackageManager manager = context.getPackageManager(); - PackageInfo info = manager.getPackageInfo(context.getPackageName(),0); + PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (Exception e) { e.printStackTrace(); @@ -81,6 +96,7 @@ public class DeviceUtils { am.getMemoryInfo(mi); return mi.lowMemory; } + public static String getMemory(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); 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_new_function.xml b/common/src/main/res/layout/dialog_live_new_function.xml index 234b8cb67..c60106ebf 100644 --- a/common/src/main/res/layout/dialog_live_new_function.xml +++ b/common/src/main/res/layout/dialog_live_new_function.xml @@ -256,6 +256,27 @@ android:textColor="#FF9A9A9A" android:textSize="12sp" /> + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/mipmap-xxhdpi/icon_live_random_pk.png b/common/src/main/res/mipmap-xxhdpi/icon_live_random_pk.png new file mode 100644 index 000000000..6a1c4c610 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_live_random_pk.png differ diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index b2b9d3a5c..454aeb05e 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -723,6 +723,7 @@ 心願單 娛樂整蠱 多人PK + 随机PK 語音連麥 周星榜 暫時離開 @@ -971,4 +972,9 @@ 邀請\n主播 結束\nPK 時間 %s + + 接受 + 拒绝 + 坚持拒绝 + 随机PK提示 diff --git a/config.gradle b/config.gradle index 49107385a..d9d2c3a12 100644 --- a/config.gradle +++ b/config.gradle @@ -4,15 +4,15 @@ ext { buildToolsVersion: "28.0.3", minSdkVersion : 21, targetSdkVersion : 31, - versionCode : 311, - versionName : "6.4.6" + versionCode : 310, + versionName : "6.4.7" ] manifestPlaceholders = [ //正式 - serverHost : "https://napi.yaoulive.com", +// serverHost : "https://napi.yaoulive.com", //測試 -// serverHost : "https://ceshi.yaoulive.com", + serverHost : "https://ceshi.yaoulive.com", //腾讯地图 txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB", diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index cf5954bb7..1ad584cfa 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -705,7 +705,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL */ @Override public void onLinkMicPkStart(final String pkUid, final String pkhead, final String pkname, String isLadders) { - Log.e("ry", "pkUid" + pkUid + "pkhead" + pkhead + "pkname" + pkname); + Log.e("ry", "pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); Handler handler = new Handler(); 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 a652e9beb..299ed3c87 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveRyAnchorActivity.java @@ -4,7 +4,9 @@ import static com.blankj.utilcode.util.SnackbarUtils.dismiss; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE; import static com.tencent.trtc.TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_ENABLE; import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK; -import static com.yunbao.live.views.LivePushRyViewHolder.rtcRoom; +import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK_RANDOM; +import static com.yunbao.live.views.AbsRyLivePushViewHolder.mPreView; +import static com.yunbao.live.views.LivePushRyViewHolder.dr_pk_view; import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_dr_pk_nub; import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk; import static com.yunbao.live.views.LiveRyAnchorViewHolder.btn_start_dr_pk_view; @@ -48,6 +50,7 @@ import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.utils.BitmapUtil; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DateFormatUtil; @@ -63,10 +66,14 @@ import com.yunbao.live.R; import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.live.bean.LiveReceiveGiftBean; +import com.yunbao.common.bean.LiveUserGiftBean; +import com.yunbao.common.bean.MicUserBean; +import com.yunbao.live.dialog.FreePkDialogFragment; import com.yunbao.live.dialog.LiveLinkMicListDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; import com.yunbao.live.dialog.LiveNewWishListDialogFragment; import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience; +import com.yunbao.live.dialog.RandomPkDialogFragment; import com.yunbao.live.event.LinkMicTxMixStreamEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.http.LiveHttpConsts; @@ -80,6 +87,8 @@ import com.yunbao.live.presenter.LiveRyLinkMicPkPresenter; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketSendBean; +import com.yunbao.common.utils.MicStatusManager; +import com.yunbao.common.manager.RandomPkManager; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LiveMusicViewHolder; import com.yunbao.live.views.LiveNewReadyRyViewHolder; @@ -91,7 +100,9 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.io.File; +import java.util.ArrayList; import java.util.List; +import java.util.TreeMap; import cn.rongcloud.rtc.api.RCRTCEngine; import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; @@ -142,6 +153,39 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl public static int pk_nub; public static int backIndex = 0;//0=未判断,1=已判断 private FaceManager manager; + private final RandomPkManager.OnRandomPkTimer onRandomPkTimer = new RandomPkManager.OnRandomPkTimer() { + @Override + public void onTimer(String time) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(String.format(WordUtil.getString(R.string.random_pk_info_btn_ing), time)); + } + } + + @Override + public void onStartPK(String pkUid) { + ToastUtil.show("发起随机PK:" + pkUid); + JSONObject msg1 = buildLinkMicJSON(); + msg1.put("random_pk", "1"); + if(RandomPkManager.getInstance().isRankModel()){ + msg1.put("is_ladders","https://downs.yaoulive.com/rank_top_box.png"); + } + linkMicAnchorApply(pkUid, pkUid, msg1.toString()); + } + + @Override + public void onPking() { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(null); + } + } + + @Override + public void onPkEnd() { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.setRandomPkTimer(null); + } + } + }; @Override protected int getLayoutId() { @@ -180,6 +224,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl mContainer = (ViewGroup) findViewById(R.id.container); mLiveRyLinkMicPkPresenter = new LiveRyLinkMicPkPresenter(mContext, mLivePushViewHolder, true, mContainer); + RandomPkManager.getInstance().addOnRandomPkTimer(onRandomPkTimer); //添加开播前设置控件 mLiveReadyViewHolder = new LiveNewReadyRyViewHolder(mContext, mContainer, mLiveSDK); @@ -349,7 +394,8 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl break; case Constants.LIVE_FUNC_LINK_MIC://连麦 if (isDRPK != 1) { - openLinkMicAnchorWindow(false); + //openLinkMicAnchorWindow(false); + openFreePkWindow(); } else { ToastUtil.show("您已在PK中"); } @@ -368,6 +414,9 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl t.mirrorType = TRTC_VIDEO_MIRROR_TYPE_DISABLE; } break; + case Constants.LIVE_FUNC_RANDOM_PK: + openRandomPkWindow(); + break; default: break; } @@ -547,7 +596,22 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl fragment.setArguments(bundle); fragment.show(getSupportFragmentManager(), "LiveLinkMicListDialogFragment"); } + public void openFreePkWindow(){ + FreePkDialogFragment fragment = new FreePkDialogFragment(); + Bundle bundle = new Bundle(); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "FreePkDialogFragment"); + } + /** + * 随机PK + */ + public void openRandomPkWindow() { + RandomPkDialogFragment fragment = new RandomPkDialogFragment(); + Bundle bundle = new Bundle(); + fragment.setArguments(bundle); + fragment.show(getSupportFragmentManager(), "RandomPkDialogFragment"); + } /** * 打开选择游戏窗口 @@ -881,6 +945,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl MicStatusManager.getInstance().closeMic(mContext); } L.e("LiveAnchorActivity-------onDestroy------->"); + RandomPkManager.getInstance().unregisterOnRandomPkTimer(onRandomPkTimer); Bus.getOff(this); } @@ -997,7 +1062,20 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl * @param pkUid 对方主播的uid * @param stream 对方主播的stream */ - public void linkMicAnchorApply(final String pkUid, String stream) { + public void linkMicAnchorApply(String pkUid, String stream) { + JSONObject msg1 = buildLinkMicJSON(); + linkMicAnchorApply(pkUid, stream, msg1.toString()); + } + public JSONObject buildLinkMicJSON(){ + JSONObject msg1 = new JSONObject(); + msg1.put("uid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); + msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); + msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); + return msg1; + } + + public void linkMicAnchorApply(final String pkUid, String stream, String extra) { LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { @Override @@ -1006,15 +1084,11 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl JSONObject obj = JSON.parseObject(info[0]); if (obj != null) { if (obj.getString("ispk").equals("0")) { - JSONObject msg1 = new JSONObject(); - msg1.put("uid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); - msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - rtcRoom.getLocalUser().requestJoinOtherRoom(pkUid, pkUid, true, msg1.toString(), new IRCRTCResultCallback() { + + IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override public void onSuccess() { - ToastUtil.show("邀请 " + pkUid + " 发送成功"); + // ToastUtil.show("邀请 " + pkUid + " 发送成功"); runOnUiThread(new Runnable() { @Override public void run() { @@ -1048,14 +1122,24 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } + /** + * 发起多人主播连麦PK申请 + * + * @param pkUid 对方主播的uid + * @param stream 对方主播的stream (无需steam) + */ + public void linkDrMicAnchorApply(String pkUid, String stream) { + linkDrMicAnchorApply(pkUid, stream, SOCKET_LIVE_DRPK); + } /** * 发起多人主播连麦PK申请 * * @param pkUid 对方主播的uid - * @param stream 对方主播的stream + * @param stream 对方主播的stream (无需steam) + * @param extra PK类型 */ - public void linkDrMicAnchorApply(final String pkUid, String stream) { + public void linkDrMicAnchorApply(final String pkUid, String stream, String extra) { LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() { @Override @@ -1065,10 +1149,12 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (obj != null) { if (obj.getString("ispk").equals("0")) { - rtcRoom.getLocalUser().requestJoinOtherRoom(pkUid, pkUid, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(pkUid, true, extra, new IRCRTCResultCallback() { @Override public void onSuccess() { - ToastUtil.show("邀请 " + pkUid + " 发送成功"); + if (!extra.equals(SOCKET_LIVE_DRPK_RANDOM)) { + ToastUtil.show("邀请 " + pkUid + " 发送成功"); + } runOnUiThread(new Runnable() { @Override public void run() { diff --git a/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java new file mode 100644 index 000000000..ffacaeae0 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/adapter/RandomPkRecyclerAdapter.java @@ -0,0 +1,143 @@ +package com.yunbao.live.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.makeramen.roundedimageview.RoundedImageView; +import com.yunbao.common.adapter.RefreshAdapter; +import com.yunbao.common.bean.RandomPkUserBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.manager.IMRTCManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.live.R; +import com.yunbao.live.activity.LiveRyAnchorActivity; + +import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; +import cn.rongcloud.rtc.base.RTCErrorCode; + +public class RandomPkRecyclerAdapter extends RefreshAdapter { + private static final int HEAD = 0; + private static final int ITEM = 2; + + public RandomPkRecyclerAdapter(Context context) { + super(context); + } + + + @NonNull + @Override + public HeadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + if (viewType == HEAD) { + return new HeadViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_random_pk_rv_head, parent, false)); + } + return new ItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_random_pk_rv, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (getItemViewType(position) == ITEM) { + ((ItemViewHolder) holder).setData(mList.get(position-1)); + }else{ + ((HeadViewHolder) holder).setData(mList.get(position)); + } + } + + + @Override + public int getItemCount() { + return mList.size(); + } + + @Override + public int getItemViewType(int position) { + if (position == 0) { + return HEAD; + } + return ITEM; + } + + private class HeadViewHolder extends RecyclerView.ViewHolder { + + public HeadViewHolder(@NonNull View itemView) { + super(itemView); + } + + public void setData(RandomPkUserBean bean) { + + } + } + + + public class ItemViewHolder extends HeadViewHolder { + private TextView mNum; + private TextView mName; + private TextView mId; + private TextView mStatus; + private RoundedImageView mAvatar; + private ImageView mPkStatus; + private ImageView mFollow; + + public ItemViewHolder(@NonNull View itemView) { + super(itemView); + mNum = itemView.findViewById(R.id.item_id); + mName = itemView.findViewById(R.id.item_name); + mId = itemView.findViewById(R.id.item_uid); + mStatus = itemView.findViewById(R.id.item_status); + mAvatar = itemView.findViewById(R.id.item_avatar); + mPkStatus = itemView.findViewById(R.id.item_pk); + mFollow = itemView.findViewById(R.id.item_follow); + mPkStatus.setOnClickListener(v -> { + RandomPkUserBean bean = (RandomPkUserBean) itemView.getTag(); + if (bean.isPk()) { + ToastUtil.show(R.string.free_pk_user_pking); + return; + } + ((LiveRyAnchorActivity) mContext).linkMicAnchorApply(bean.getId(), bean.getId(), + ((LiveRyAnchorActivity) mContext).buildLinkMicJSON().toString() + ); + }); + } + + @Override + public void setData(RandomPkUserBean bean) { + super.setData(bean); + int position = getAbsoluteAdapterPosition(); + if (bean == null) { + return; + } + itemView.setTag(bean); + mNum.setText((position) + ""); + if (position % 2 == 0) { + itemView.setBackgroundResource(R.drawable.bg_item_random_pk_type_1); + } else { + itemView.setBackgroundResource(R.drawable.bg_item_random_pk_type_2); + } + ImgLoader.display(mContext, bean.getAvatar(), mAvatar); + if (bean.getUserNiceName().length() > 4) { + mName.setText(bean.getUserNiceName().substring(0, 4) + "..."); + } else { + mName.setText(bean.getUserNiceName()); + } + mId.setText(bean.getId()); + if (bean.isPk()) { + mStatus.setText("PK中"); + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk, mPkStatus); + } else { + mStatus.setText("空闲"); + ImgLoader.display(mContext, R.mipmap.ic_random_pk_pk_unselect, mPkStatus); + } + if (bean.isAttention()) { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_like, mFollow); + } else { + ImgLoader.display(mContext, R.mipmap.ic_random_pk_like_unselect, mFollow); + } + } + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java new file mode 100644 index 000000000..bb82dda15 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/FreePkDialogFragment.java @@ -0,0 +1,272 @@ +package com.yunbao.live.dialog; + +import android.app.Dialog; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; + +import com.alibaba.fastjson.JSON; +import com.google.android.material.tabs.TabLayout; +import com.yunbao.common.adapter.RefreshAdapter; +import com.yunbao.common.bean.HttpCallbackModel; +import com.yunbao.common.bean.RandomPkUserBean; +import com.yunbao.common.custom.CommonRefreshView; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.RandomPkManager; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.common.utils.WordsTypeUtil; +import com.yunbao.live.R; +import com.yunbao.live.adapter.RandomPkRecyclerAdapter; +import com.yunbao.live.bean.LivePkBean; +import com.yunbao.live.http.LiveHttpUtil; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +/** + * 自由PK + */ +public class FreePkDialogFragment extends AbsDialogFragment implements View.OnClickListener { + private static final int TAB_STATUS_SEARCH = 1; + private static final int TAB_STATUS_FOLLOW = 2; + + private static final String TAG = "自由PK"; + private int mLiveUid; + private TabLayout tabLayout; + private View reset; + private CommonRefreshView mRecyclerView; + private View mSearchLayout; + private EditText mSearch; + private ImageView mClear; + private RandomPkRecyclerAdapter adapter; + private DataHelper helper; + private int tabStatus; + + + @Override + protected int getLayoutId() { + return R.layout.dialog_live_free_pk_function; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + window.setWindowAnimations(R.style.bottomToTopAnim); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = DpUtil.dp2px(330); + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + public void setLiveUid(int mLiveUid) { + this.mLiveUid = mLiveUid; + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + initView(); + initTab(); + initData(); + } + + private void initView() { + tabLayout = (TabLayout) findViewById(R.id.menu_tab); + reset = findViewById(R.id.menu_reset); + mRecyclerView = (CommonRefreshView) findViewById(R.id.random_container_view); + mSearchLayout = findViewById(R.id.random_pk_search_layout); + mSearch = (EditText) findViewById(R.id.search_edit); + mClear = (ImageView) findViewById(R.id.search_clear); + mClear.setOnClickListener(this); + mSearch.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + helper.search(s.toString()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + initRecycler(); + } + + private void initRecycler() { + helper = new DataHelper(); + adapter = new RandomPkRecyclerAdapter(mContext); + mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); + mRecyclerView.setDataHelper(helper); + mRecyclerView.initData(); + } + + + private void initData() { + } + + private void initTab() { + TabLayout.Tab searchTag = tabLayout.newTab(); + TabLayout.Tab listTag = tabLayout.newTab(); + searchTag.setTag(TAB_STATUS_SEARCH); + searchTag.setText("主播搜索"); + listTag.setTag(TAB_STATUS_FOLLOW); + listTag.setText("關注列表"); + tabLayout.addTab(searchTag); + tabLayout.addTab(listTag); + tabStatus = TAB_STATUS_SEARCH; + tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + if (tab.getTag() != null) { + tabStatus = (int) tab.getTag(); + mRecyclerView.setVisibility(View.GONE); + mSearchLayout.setVisibility(View.GONE); + switch (tabStatus) { + case TAB_STATUS_SEARCH: + mSearchLayout.setVisibility(View.VISIBLE); + mRecyclerView.setVisibility(View.VISIBLE); + mRecyclerView.initData(); + break; + case TAB_STATUS_FOLLOW: + mRecyclerView.setVisibility(View.VISIBLE); + mRecyclerView.initData(); + break; + } + } + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + + @Override + public void onTabReselected(TabLayout.Tab tab) { + + } + }); + } + + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.live_random_pk_switch) { + + } else if (id == R.id.search_clear) { + mSearch.setText(""); + } + } + + public class DataHelper implements CommonRefreshView.DataHelper { + + public void search(String key) { + LiveNetManager.get(mContext) + .randomPkSearchUser(key, WordsTypeUtil.changeTraditional(key), new com.yunbao.common.http.base.HttpCallback>() { + @Override + public void onSuccess(List data) { + List list = new ArrayList<>(); + list.add(null); + list.addAll(data); + adapter.setList(list); + adapter.notifyDataSetChanged(); + } + + @Override + public void onError(String error) { + } + }); + } + + @Override + public RefreshAdapter getAdapter() { + return adapter; + } + + @Override + public void loadData(int p, HttpCallback callback) { + LiveHttpUtil.getLivePkList(p, callback); + } + + @Override + public List processData(String[] info) { + Log.i(TAG, "processData: 获取数据成功"); + List beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class); + List list = new ArrayList<>(); + for (LivePkBean bean : beans) { + RandomPkUserBean userBean = new RandomPkUserBean(); + userBean.setId(bean.getUid()); + userBean.setSex(bean.getSex()); + userBean.setUserNiceName(bean.getUserNiceName()); + userBean.setAvatar(bean.getAvatar()); + userBean.setPk(bean.getPkUid().equals("0") ? 0 : 1); + userBean.setAttention("0"); + list.add(userBean); + } + return list; + } + + @Override + public void onRefreshSuccess(List list, int listCount) { + + } + + @Override + public void onRefreshFailure() { + + } + + @Override + public void onLoadMoreSuccess(List loadItemList, int loadItemCount) { + + } + + @Override + public void onLoadMoreFailure() { + + } + } +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java index 63db923f8..364ea23fd 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewFunctionDialogFragment.java @@ -25,6 +25,7 @@ import com.yunbao.live.interfaces.LiveFunctionClickListener; public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements View.OnClickListener { private View mWishView, mPrankView, mWksView, mBeautyView, mCameraView, mLeaveView, mOnePkView, mMultiPkView, mMicView; + private View mRandomPk; private LiveFunctionClickListener mFunctionClickListener; private int leave = 0; private boolean isPk; @@ -79,6 +80,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements mOnePkView = findViewById(R.id.live_tool_one_pk); mMultiPkView = findViewById(R.id.live_tool_multi_pk); mMicView = findViewById(R.id.live_tool_mic); + mRandomPk = findViewById(R.id.live_tool_random_pk); mWishView.setOnClickListener(this); mPrankView.setOnClickListener(this); @@ -89,6 +91,7 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements mOnePkView.setOnClickListener(this); mMultiPkView.setOnClickListener(this); mMicView.setOnClickListener(this); + mRandomPk.setOnClickListener(this); if (leave == 0) { ((ImageView) mLeaveView.findViewById(R.id.live_tool_leave_img)).setImageResource(R.mipmap.icon_leave); @@ -140,6 +143,8 @@ public class LiveNewFunctionDialogFragment extends AbsDialogFragment implements mFunctionClickListener.onClick(LIVE_FUNC_DR); } else if (id == R.id.live_tool_mic) { mFunctionClickListener.onClick(LIVE_FUNC_MIC); + } else if (id == R.id.live_tool_random_pk) { + mFunctionClickListener.onClick(LIVE_FUNC_RANDOM_PK); } } } diff --git a/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java new file mode 100644 index 000000000..72ab30e93 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/RandomPkDialogFragment.java @@ -0,0 +1,255 @@ +package com.yunbao.live.dialog; + +import android.app.Dialog; +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.Nullable; + +import com.yunbao.common.bean.HttpCallbackModel; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.live.R; +import com.yunbao.common.manager.RandomPkManager; + +/** + * 随机PK + */ +public class RandomPkDialogFragment extends AbsDialogFragment implements View.OnClickListener { + private static final String TAG = "随机PK"; + private View mPkBtn; + private TextView mPkBtnTitle; + private TextView mPkBtnDesc; + private ImageView mRandomPkSwitch; + + + private final RandomPkManager.OnRandomPkTimer randomPkTimer = new RandomPkManager.OnRandomPkTimer() { + @Override + public void onTimer(String time) { + if (!mPkBtn.isEnabled()) { + return; + } + Log.i(TAG, "onTimer: " + time); + mPkBtnTitle.setText(String.format(WordUtil.getString(R.string.random_pk_info_btn_ing), time)); + mPkBtnDesc.setText(R.string.random_pk_info_btn_end_desc); + mPkBtnDesc.setVisibility(View.VISIBLE); + mPkBtn.setBackgroundResource(R.drawable.bg_live_room_random_pk_timer); + } + + @Override + public void onPking() { + resetPkBtn(); + dismiss(); + } + + @Override + public void onPkEnd() { + resetPkBtn(); + } + + @Override + public void onPkEndStart() { + super.onPkEndStart(); + mPkBtn.setEnabled(false); + } + + @Override + public void onPkEndTimer(String time) { + super.onPkEndTimer(time); + mPkBtnTitle.setText(String.format(WordUtil.getString(R.string.random_pk_info_btn_end), time)); + mPkBtnDesc.setText(R.string.random_pk_info_btn_end_desc); + mPkBtn.setEnabled(false); + } + + @Override + public void onPkEndSuccess() { + super.onPkEndSuccess(); + resetPkBtn(); + mPkBtn.setTag(false); + mPkBtn.setEnabled(true); + } + }; + + @Override + protected int getLayoutId() { + return R.layout.dialog_live_random_pk_function; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + protected void setWindowAttributes(Window window) { + WindowManager.LayoutParams params = window.getAttributes(); + window.setWindowAnimations(R.style.bottomToTopAnim); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + + @Override + public void onDestroy() { + super.onDestroy(); + RandomPkManager.getInstance().unregisterOnRandomPkTimer(randomPkTimer); + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + initView(); + initData(); + } + + private void initView() { + mPkBtn = findViewById(R.id.random_pk_info_btn); + mPkBtnTitle = (TextView) findViewById(R.id.random_pk_btn_title); + mPkBtnDesc = (TextView) findViewById(R.id.random_pk_btn_desc); + mRandomPkSwitch = (ImageView) findViewById(R.id.live_random_pk_switch); + mRandomPkSwitch.setTag(true); + mRandomPkSwitch.setOnClickListener(this); + mPkBtn.setOnClickListener(this); + } + + private void initData() { + RandomPkManager.getInstance().addOnRandomPkTimer(randomPkTimer); + initPkSwitch(); + if (RandomPkManager.getInstance().isRequestPk()) { + mPkBtnTitle.setText(String.format(WordUtil.getString(R.string.random_pk_info_btn_ing), RandomPkManager.getInstance().getTimer())); + mPkBtnDesc.setText(R.string.random_pk_info_btn_end_desc); + mPkBtnDesc.setVisibility(View.VISIBLE); + mPkBtn.setBackgroundResource(R.drawable.bg_live_room_random_pk_timer); + } else if (RandomPkManager.getInstance().isExiting()) { + mPkBtnTitle.setText(String.format(WordUtil.getString(R.string.random_pk_info_btn_end), RandomPkManager.getInstance().getExitTimer())); + mPkBtnDesc.setText(R.string.random_pk_info_btn_end_desc); + mPkBtn.setEnabled(false); + } + } + + + /** + * 设置随机PK开关状态 + * + * @param open on/off + */ + private void setSwitchBtn(boolean open) { + if (open) { + ImgLoader.display(mContext, com.yunbao.common.R.mipmap.special_icon_on, mRandomPkSwitch); + mRandomPkSwitch.setTag(true); + } else { + ImgLoader.display(mContext, com.yunbao.common.R.mipmap.special_icon_off, mRandomPkSwitch); + mRandomPkSwitch.setTag(false); + } + } + + /** + * 获取随机PK状态 + */ + private void initPkSwitch() { + LiveNetManager.get(mContext) + .getRandomPkSwitch(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(Integer data) { + if (data != null) { + setSwitchBtn(data == 1); + } + } + + @Override + public void onError(String error) { + + } + }); + } + + private Dialog loadDialog; + + /** + * 设置随机PK状态 + * + * @param pk 1=on,0=off + */ + private void setPkSwitch(int pk) { + if (RandomPkManager.getInstance().isRequestPk() || RandomPkManager.getInstance().isExiting()) { + return; + } + loadDialog = DialogUitl.loadingDialog(mContext); + loadDialog.show(); + LiveNetManager.get(mContext) + .changeRandomPkSwitch(pk, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(HttpCallbackModel data) { + loadDialog.dismiss(); + loadDialog = null; + if (data.getCode() == 0) { + setSwitchBtn(!(boolean) mRandomPkSwitch.getTag()); + } else { + ToastUtil.show(data.getMsg()); + } + + } + + @Override + public void onError(String error) { + loadDialog.dismiss(); + loadDialog = null; + } + }); + } + + + private void randomPk() { + if (mRandomPkSwitch.getTag() == null || !(boolean) mRandomPkSwitch.getTag()) { + ToastUtil.show("未开启随机PK开关"); + return; + } + if ((mPkBtn.getTag() != null && (boolean) mPkBtn.getTag()) || RandomPkManager.getInstance().isRequestPk()) { + RandomPkManager.getInstance().exitPk(); + return; + } + + if (RandomPkManager.getInstance().start()) { + mPkBtnDesc.setVisibility(View.VISIBLE); + mPkBtnDesc.setText(R.string.random_pk_info_btn_ing_desc); + mPkBtn.setTag(true); + } + } + + private void resetPkBtn() { + mPkBtnDesc.setVisibility(View.GONE); + mPkBtnTitle.setText(R.string.random_pk_info_btn_start); + mPkBtn.setBackgroundResource(R.drawable.bg_live_random_pk_info_btn); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.live_random_pk_switch) { + if (mRandomPkSwitch.getTag() != null && (boolean) mRandomPkSwitch.getTag()) { + setPkSwitch(0); + } else { + setPkSwitch(1); + } + } else if (id == R.id.random_pk_info_btn) { + randomPk(); + } + } +} 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 fbe9f509f..d18ce963a 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 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; @@ -19,6 +20,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; @@ -41,8 +43,12 @@ import com.yunbao.common.glide.ImgLoader; 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.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; 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; @@ -63,9 +69,14 @@ import com.yunbao.live.views.LiveRoomPlayViewHolder; import org.greenrobot.eventbus.EventBus; +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; @@ -630,7 +641,11 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { mApplyNmae = u.getUserNiceName(); if (by != 1) { if (mIsApplyDialogShow == false) { - showApplyDialog(u); + if (u.isRandomPk()) { + showPkDialog(u); + } else { + showApplyDialog(u); + } } } else { isPK(); @@ -651,7 +666,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * @param callBack 加入房间回调 * @group 房间管理 */ - + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback() { @Override public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) { @@ -803,7 +818,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatarThumb()); msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); - rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, true, true, msg1.toString(), new IRCRTCResultCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, true, msg1.toString(), new IRCRTCResultCallback() { @Override public void onSuccess() { RCRTCEngine.getInstance().joinOtherRoom(mApplyUid, new IRCRTCResultDataCallback() { @@ -1044,46 +1059,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()); - } - }); - } - }); + refusePk(u); } mApplyUid = null; mApplyStream = null; @@ -1218,6 +1194,134 @@ 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 -> { + refusePk(u); + dialog.dismiss(); + }); + } + + + void apply() { + isPK(); + } + }) + .build().show(); + } + + private void refusePk(UserBean u) { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra_randm_pk", new IRCRTCResultCallback() { + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + + @Override + public void onSuccess() { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LINK_MIC_PK) + // .param("randomPk",u.isRandomPk()+"") + .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); + } + /** * 显示申请多人PK的弹窗 */ @@ -1264,7 +1368,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { agree = false; } boolean finalAgree = agree; - rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, agree, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(mApplyUid, agree, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { @Override public void onSuccess() { if (finalAgree == true) { @@ -1311,7 +1415,12 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } JSONObject obj = JSONObject.parseObject(info[0]); JSONArray users = obj.getJSONArray("userlist"); + + //添加水印 +// RCRTCRect rect = new RCRTCRect(0.5f, 0.5f, 0.2f); +// RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(fromText(50, mNameText), rect); dRjoinOtherRoom(u.getId(), 1); + for (int i = 0; i < users.size(); i++) { JSONObject user = users.getJSONObject(i); Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); @@ -1329,7 +1438,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 *

*/ - rtcRoom.getLocalUser().requestJoinOtherRoom(user.getString("id"), user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { @Override public void onSuccess() { } @@ -1363,7 +1472,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { } else { if (mPkWaitCount < 0) { - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { @Override public void onFailed(RTCErrorCode errorCode) { @@ -1405,7 +1514,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { }); } else { - rtcRoom.getLocalUser().responseJoinOtherRoom(u.getId(), u.getId(), false, false, "extra", new IRCRTCResultCallback() { + IMRTCManager.getInstance().responseJoinOtherRoom(u.getId(), false, "extra", new IRCRTCResultCallback() { @Override public void onFailed(RTCErrorCode errorCode) { @@ -2122,7 +2231,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) { @@ -2241,7 +2350,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/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index 2a5eb60ee..d7b7ac978 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -30,6 +30,7 @@ import com.yunbao.common.bean.SocketModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.manager.IMRTCManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ToastUtil; @@ -47,6 +48,7 @@ import com.yunbao.live.bean.LiveLuckGiftWinBean; import com.yunbao.live.bean.LivePKUserListBean; import com.yunbao.live.bean.LiveReceiveGiftBean; import com.yunbao.live.event.LiveAudienceEvent; +import com.yunbao.common.manager.RandomPkManager; import com.yunbao.live.views.LiveEndViewHolder; import com.yunbao.live.views.LivePlayKsyViewHolder; import com.yunbao.live.views.LivePlayRyViewHolder; @@ -264,6 +266,7 @@ public class SocketRyClient { // case Constants.SOCKET_SEND_GIFT://送礼物 // ////////pk // break; + case Constants.SOCKET_LIVE_DRPK_RANDOM: case Constants.SOCKET_LIVE_DRPK://多人PK int action3 = map.getIntValue("action"); //收到多人PK邀请 @@ -323,7 +326,7 @@ public class SocketRyClient { isDRPK = 1; } else if (action3 == 10) { if (!map.getString("uid").equals(CommonAppConfig.getInstance().getUid())) { - // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); + // LiveAudienceActivity.getmLivePlayViewHolder().setPkview(); Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.SOCKET_LIVE_DRPK_SET_PK_VIEW) ); @@ -473,7 +476,7 @@ public class SocketRyClient { LiveChatBean chatBean = new LiveChatBean(); chatBean.setId(jsonObject.getString("uid")); chatBean.setUserNiceName(jsonObject.getString("user_nicename")); - if ("1".equals(map.getString("msgtype"))) { + if ("1" .equals(map.getString("msgtype"))) { chatBean.setType(-3); } else { chatBean.setType(-4); @@ -660,7 +663,7 @@ public class SocketRyClient { private static void sendActiveMsg(JSONObject map, SocketReceiveBean received) { String msgtype = map.getString("msgtype"); - if ("1".equals(msgtype)) {//新年大作战活动 + if ("1" .equals(msgtype)) {//新年大作战活动 LiveChatBean chatBean = new LiveChatBean(); chatBean.setId(map.getString("uid")); chatBean.setMedalLevelImageUrl(map.getString("monster_str"));//昵称暂时做为活动图片地址 @@ -673,14 +676,14 @@ public class SocketRyClient { private static void wordLightEnterRoom(JSONObject map, SocketReceiveBean received) { String msgtype = map.getString("msgtype"); - if ("2".equals(msgtype)) {//发言,点亮 - if ("409002".equals(received.getRetcode())) { + if ("2" .equals(msgtype)) {//发言,点亮 + if ("409002" .equals(received.getRetcode())) { ToastUtil.show(R.string.live_you_are_shut); return; } //禁言别人,自己发言只能自己看到 - if ("409100".equals(received.getRetcode())) { + if ("409100" .equals(received.getRetcode())) { String uid = map.getString("uid"); if (!uid.equals(CommonAppConfig.getInstance().getUid())) { return; @@ -725,12 +728,12 @@ public class SocketRyClient { e.printStackTrace(); } - if (!"".equals(map.getString("prankIcon")) && map.getString("prankIcon") != null) { + if (!"" .equals(map.getString("prankIcon")) && map.getString("prankIcon") != null) { chatBean.setPrankIcon(map.getString("prankIcon")); chatBean.setType(-5); } mListener.onChat(chatBean, 1); - } else if ("0".equals(msgtype)) {//用户进入房间 + } else if ("0" .equals(msgtype)) {//用户进入房间 JSONObject obj = JSON.parseObject(map.getString("ct")); LiveUserGiftBean u = GsonUtils.fromJson(obj.toJSONString(), LiveUserGiftBean.class); UserBean.Vip vip = new UserBean.Vip(); @@ -877,7 +880,7 @@ public class SocketRyClient { chatBean.setMedal_new(map.getString("medal_new")); chatBean.setGood_nub(map.getString("good_num")); chatBean.setType(LiveChatBean.GIFT); - if (map.get("guard_type") != null && !"".equals(map.get("guard_type")) && !"null".equals(map.get("guard_type"))) { + if (map.get("guard_type") != null && !"" .equals(map.get("guard_type")) && !"null" .equals(map.get("guard_type"))) { chatBean.setGuardType(map.getInteger("guard_type")); } if (CommonAppContext.lang.equals("chinese")) { @@ -1053,23 +1056,27 @@ public class SocketRyClient { mListener.onLinkMicPkApply(u, map.getString("stream"), 1); break; case 2://收到对方主播PK回调 + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); mListener.onLinkMicToPk(map.getString("uid"), map.getString("pkhead"), map.getString("pkname")); mListener.onLinkMicPkStart(map.getString("uid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders"));// mListener.onLinkMicPkStart(map.getString("uid")); break; case 3://对方主播拒绝PK的回调 + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_REFUSE); mListener.onLinkMicPkRefuse(); break; case 4://所有人收到PK开始址的回调 + // RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START); mListener.onLinkMicPkStart(map.getString("pkuid"), map.getString("pkhead"), map.getString("pkname"), map.getString("is_ladders")); break; case 5://PK时候断开连麦的回调 if (rtcRoom != null) { -// if (LivePushRyViewHolder.mPreView1 != null) { -// LivePushRyViewHolder.mPreView1.removeAllViews(); -// LivePushRyViewHolder.mPreView1.setVisibility(View.GONE); -// isDRPK = 0; -// leaveDRRoom(); -// } + RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_CLOSE); + /* if (LivePushRyViewHolder.mPreView1 != null) { + LivePushRyViewHolder.mPreView1.removeAllViews(); + LivePushRyViewHolder.mPreView1.setVisibility(View.GONE); + isDRPK = 0; + leaveDRRoom(); + }*/ LivePushRyViewHolder.btn_close.setVisibility(View.GONE); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); params.topMargin = 0; @@ -1101,10 +1108,7 @@ public class SocketRyClient { msg1.put("pkuid", CommonAppConfig.getInstance().getUid()); msg1.put("pkname", CommonAppConfig.getInstance().getUserBean().getUserNiceName()); msg1.put("pkhead", CommonAppConfig.getInstance().getUserBean().getAvatar()); - if (rtcRoom == null) { - return; - } - rtcRoom.getLocalUser().requestJoinOtherRoom(map.getString("uid"), map.getString("uid"), true, msg1.toString(), new IRCRTCResultCallback() { + IMRTCManager.getInstance().requestJoinOtherRoom(map.getString("uid"), true, msg1.toString(), new IRCRTCResultCallback() { @Override public void onSuccess() { ToastUtil.show("邀请 " + map.getString("uid") + " 发送成功"); 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 8841eac82..d0db3ba18 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushRyViewHolder.java @@ -34,6 +34,8 @@ import com.yunbao.common.Constants; import com.yunbao.common.bean.UserBean; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.manager.IMRTCManager; +import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; @@ -223,9 +225,22 @@ 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("random_pk") && map.getString("random_pk").equals("1")); + userBean1.setRankPkImgUrl(map.containsKey("is_ladders") ? map.getString("is_ladders") : null); userBean1.setId(map.getString("uid")); userBean1.setUserNiceName(map.getString("pkname")); userBean1.setAvatar(map.getString("pkhead")); @@ -484,7 +499,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX // 保存房间对象 rtcRoom = room; - + IMRTCManager.getInstance().setRtcRoom(room); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { @@ -544,6 +559,7 @@ public class LivePushRyViewHolder extends AbsRyLivePushViewHolder implements ITX return; } rtcRoom = room; + IMRTCManager.getInstance().setRtcRoom(room); } rtcRoom.getLocalUser().publishDefaultLiveStreams(new IRCRTCResultDataCallback() { @Override 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 06f5f9a32..aa7dd30ba 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -86,6 +86,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.RandomPkManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; @@ -96,6 +97,7 @@ import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.utils.ScreenDimenUtil; import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.formatBigNum; import com.yunbao.common.views.AbsViewHolder; @@ -323,6 +325,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis //接口整合新加参数 private GuardUserModel guardUserModel; private ViewFlipper flipper; + private TextView mRandomPkTimer; + public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager) { super(context, parentView); @@ -737,6 +741,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis lt_trickery.setOnClickListener(this); dialog = new Dialog(mContext, R.style.dialog); + mRandomPkTimer = (TextView) findViewById(R.id.random_pk_timer); if (!SpUtil.getInstance().getBooleanValue("private_chat_message_switch")) { msgLayout.setVisibility(View.GONE); @@ -1181,7 +1186,14 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis showBanner2(); } } - + public void setRandomPkTimer(String timer){ + if(timer==null){ + mRandomPkTimer.setVisibility(View.GONE); + return; + } + mRandomPkTimer.setVisibility(View.VISIBLE); + mRandomPkTimer.setText(timer); + } private synchronized void showBanner2() { if (mBannerList2 != null && mBanner2 != null) { btn_event2.setVisibility(View.VISIBLE); @@ -1615,6 +1627,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = DpUtil.dp2px(3); textParams.setMarginStart(DpUtil.dp2px(3)); + textParams.setMarginEnd(DpUtil.dp2px(2)); View hourView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); View titleView = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); @@ -1781,7 +1794,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_l1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidL1 != null && !"".equals(uidL1)) { + if (uidL1 != null && !"" .equals(uidL1)) { showUserDialog(uidL1); } } @@ -1789,7 +1802,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_l2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidL2 != null && !"".equals(uidL2)) { + if (uidL2 != null && !"" .equals(uidL2)) { showUserDialog(uidL2); } } @@ -1797,7 +1810,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_l3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidL3 != null && !"".equals(uidL3)) { + if (uidL3 != null && !"" .equals(uidL3)) { showUserDialog(uidL3); } } @@ -1805,7 +1818,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_r1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidR1 != null && !"".equals(uidR1)) { + if (uidR1 != null && !"" .equals(uidR1)) { showUserDialog(uidR1); } } @@ -1813,7 +1826,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_r2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidR2 != null && !"".equals(uidR2)) { + if (uidR2 != null && !"" .equals(uidR2)) { showUserDialog(uidR2); } } @@ -1821,7 +1834,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis avatar_r3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (uidR3 != null && !"".equals(uidR3)) { + if (uidR3 != null && !"" .equals(uidR3)) { showUserDialog(uidR3); } } @@ -3018,7 +3031,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0 && info.length > 0) { - if ("1".equals(info[0])) { + if ("1" .equals(info[0])) { ft_hot_add.setVisibility(View.VISIBLE); } else { ft_hot_add.setVisibility(View.GONE); @@ -3033,7 +3046,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis */ public static void getIsHot(String isUseHotCard) { ImgLoader.display2(Contexts, "https://downs.yaoulive.com/img_hot_gif.gif", img_hot_gif); - if ("1".equals(isUseHotCard)) { + if ("1" .equals(isUseHotCard)) { ft_hot_add.setVisibility(View.VISIBLE); } else { ft_hot_add.setVisibility(View.GONE); @@ -3331,7 +3344,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } else if (bean.getActivityId() == 0) { openWebDialog(bean.getLink()); } else { - LiveGameDialogFragment fragment = new LiveGameDialogFragment("1".equals(bean.getShow_type())); + LiveGameDialogFragment fragment = new LiveGameDialogFragment("1" .equals(bean.getShow_type())); fragment.setActivityId(bean.getActivityId()); fragment.setRoomId(mLiveUid); fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveGameDialogFragment"); @@ -3382,7 +3395,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis nowTime = time; tv_trickery_time.setText("" + nowTime); openType = 0; - if ("1".equals(msgtype)) { + if ("1" .equals(msgtype)) { nums = jsonObject.getString("nums"); prankid = jsonObject.getString("prankid"); content = jsonObject.getString("content"); @@ -3546,21 +3559,21 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis @Subscribe(threadMode = ThreadMode.MAIN) public void onUpdata(String str) { - if ("svga_new_user_gif".equals(str)) { + if ("svga_new_user_gif" .equals(str)) { if (fastMsgRecyclerView == null) return; RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) fastMsgRecyclerView.getLayoutParams(); params1.rightMargin = DeviceUtils.getScreenWidth((Activity) mContext) / 3; fastMsgRecyclerView.setLayoutParams(params1); - } else if ("stop_svga_new_user_gif".equals(str)) { + } else if ("stop_svga_new_user_gif" .equals(str)) { if (fastMsgRecyclerView == null) return; RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) fastMsgRecyclerView.getLayoutParams(); params1.rightMargin = 0; fastMsgRecyclerView.setLayoutParams(params1); - } else if ("showBanner".equals(str)) { + } else if ("showBanner" .equals(str)) { showBanner3(bean1); - } else if ("stop_svga_new_user_double".equals(str) && mBannerList3.size() > 2) { + } else if ("stop_svga_new_user_double" .equals(str) && mBannerList3.size() > 2) { mBannerList3.get(2).setLink("1"); mBanner3.update(mBannerList3); @@ -3571,7 +3584,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } } - } else if ("stop_svga_new_user_follow".equals(str) && mBannerList3.size() > 1) { + } else if ("stop_svga_new_user_follow" .equals(str) && mBannerList3.size() > 1) { mBannerList3.get(1).setLink("1"); mBanner3.update(mBannerList3); @@ -3582,7 +3595,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis } } } - } else if ("stop_new_user_gif".equals(str) && mBannerList3.size() > 0) { + } else if ("stop_new_user_gif" .equals(str) && mBannerList3.size() > 0) { IMLoginManager.get(mContext).setNewUserGif(false); mBannerList3.get(0).setLink("1"); mBanner3.update(mBannerList3); diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 9d63388ce..95a514d8c 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -1216,6 +1216,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onLinkMicPkStart(String pkUid, String pkhead, String pkname, String isLadders) { + System.out.println("PK测试 pkUid = " + pkUid + ", pkhead = " + pkhead + ", pkname = " + pkname + ", isLadders = " + isLadders); if (mLiveRyLinkMicPkPresenter != null && mLiveRoomViewHolder != null) { mLiveRyLinkMicPkPresenter.onLinkMicPkStart(pkUid, 1); Handler handler = new Handler(); diff --git a/live/src/main/res/drawable/background_7792d0.xml b/live/src/main/res/drawable/background_7792d0.xml new file mode 100644 index 000000000..47c4546ce --- /dev/null +++ b/live/src/main/res/drawable/background_7792d0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_item_random_pk_type_1.xml b/live/src/main/res/drawable/bg_item_random_pk_type_1.xml new file mode 100644 index 000000000..ce9ea1e40 --- /dev/null +++ b/live/src/main/res/drawable/bg_item_random_pk_type_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_item_random_pk_type_2.xml b/live/src/main/res/drawable/bg_item_random_pk_type_2.xml new file mode 100644 index 000000000..61fcb5aa2 --- /dev/null +++ b/live/src/main/res/drawable/bg_item_random_pk_type_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_random_pk_info_btn.xml b/live/src/main/res/drawable/bg_live_random_pk_info_btn.xml new file mode 100644 index 000000000..497f84aeb --- /dev/null +++ b/live/src/main/res/drawable/bg_live_random_pk_info_btn.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_random_pk_info_switch.xml b/live/src/main/res/drawable/bg_live_random_pk_info_switch.xml new file mode 100644 index 000000000..8235463e9 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_random_pk_info_switch.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_random_pk_info_switch_thumb.xml b/live/src/main/res/drawable/bg_live_random_pk_info_switch_thumb.xml new file mode 100644 index 000000000..518dfbf19 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_random_pk_info_switch_thumb.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_random_pk_info_switch_track.xml b/live/src/main/res/drawable/bg_live_random_pk_info_switch_track.xml new file mode 100644 index 000000000..5816955f5 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_random_pk_info_switch_track.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_live_room_random_pk_timer.xml b/live/src/main/res/drawable/bg_live_room_random_pk_timer.xml new file mode 100644 index 000000000..f20a8dac9 --- /dev/null +++ b/live/src/main/res/drawable/bg_live_room_random_pk_timer.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/bg_random_pk_rv_search.xml b/live/src/main/res/drawable/bg_random_pk_rv_search.xml new file mode 100644 index 000000000..aae6625dd --- /dev/null +++ b/live/src/main/res/drawable/bg_random_pk_rv_search.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/drawable/random_pk_shape_tab_indicator.xml b/live/src/main/res/drawable/random_pk_shape_tab_indicator.xml new file mode 100644 index 000000000..53176bb53 --- /dev/null +++ b/live/src/main/res/drawable/random_pk_shape_tab_indicator.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_live_free_pk_function.xml b/live/src/main/res/layout/dialog_live_free_pk_function.xml new file mode 100644 index 000000000..1c5b0422b --- /dev/null +++ b/live/src/main/res/layout/dialog_live_free_pk_function.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/dialog_live_random_pk_function.xml b/live/src/main/res/layout/dialog_live_random_pk_function.xml new file mode 100644 index 000000000..9bef25c80 --- /dev/null +++ b/live/src/main/res/layout/dialog_live_random_pk_function.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_random_pk_info.xml b/live/src/main/res/layout/item_random_pk_info.xml new file mode 100644 index 000000000..86f6ccea9 --- /dev/null +++ b/live/src/main/res/layout/item_random_pk_info.xml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_random_pk_rv.xml b/live/src/main/res/layout/item_random_pk_rv.xml new file mode 100644 index 000000000..b43334e37 --- /dev/null +++ b/live/src/main/res/layout/item_random_pk_rv.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_random_pk_rv_head.xml b/live/src/main/res/layout/item_random_pk_rv_head.xml new file mode 100644 index 000000000..5dd6e1431 --- /dev/null +++ b/live/src/main/res/layout/item_random_pk_rv_head.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/item_random_pk_rv_search.xml b/live/src/main/res/layout/item_random_pk_rv_search.xml new file mode 100644 index 000000000..642dd4fde --- /dev/null +++ b/live/src/main/res/layout/item_random_pk_rv_search.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index 1df2a9721..5116de5fe 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -607,7 +607,7 @@ android:id="@+id/live_time" android:layout_width="wrap_content" android:layout_height="20dp" - android:layout_alignTop="@id/hour_rank_layout" + android:layout_below="@id/hour_rank_layout" android:layout_alignParentRight="true" android:layout_marginEnd="10dp" android:background="@drawable/bg_live_push_time" @@ -623,6 +623,20 @@ app:dt_left_height="4dp" app:dt_left_width="4dp" /> + + @@ -1274,9 +1289,9 @@ android:layout_marginBottom="10dp" android:background="@drawable/bg_live_item_pk_rank_red" android:paddingStart="17dp" - android:paddingTop="8dp" + android:paddingTop="5dp" android:paddingEnd="17dp" - android:paddingBottom="8dp" + android:paddingBottom="5dp" android:textColor="#FFFFFF" android:textSize="15sp" android:textStyle="bold" @@ -1292,9 +1307,9 @@ android:layout_marginBottom="10dp" android:background="@drawable/bg_live_item_pk_rank_blue" android:paddingStart="17dp" - android:paddingTop="8dp" + android:paddingTop="5dp" android:paddingEnd="17dp" - android:paddingBottom="8dp" + android:paddingBottom="5dp" android:textColor="#FFFFFF" android:textSize="15sp" android:textStyle="bold" diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_clear.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_clear.png new file mode 100644 index 000000000..dd7213a84 Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_clear.png differ diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_like.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_like.png new file mode 100644 index 000000000..9f1096c78 Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_like.png differ diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_like_unselect.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_like_unselect.png new file mode 100644 index 000000000..c7ea4cc39 Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_like_unselect.png differ diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk.png new file mode 100644 index 000000000..3f63b4f96 Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk.png differ diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk_unselect.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk_unselect.png new file mode 100644 index 000000000..345a81b6e Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_pk_unselect.png differ diff --git a/live/src/main/res/mipmap-xhdpi/ic_random_pk_search.png b/live/src/main/res/mipmap-xhdpi/ic_random_pk_search.png new file mode 100644 index 000000000..331ac583a Binary files /dev/null and b/live/src/main/res/mipmap-xhdpi/ic_random_pk_search.png differ diff --git a/live/src/main/res/values/strings.xml b/live/src/main/res/values/strings.xml index 48b776755..316a0b03a 100644 --- a/live/src/main/res/values/strings.xml +++ b/live/src/main/res/values/strings.xml @@ -32,4 +32,22 @@ 已踢下麥 已發出邀請,等待用戶接受 已同意請求,等待用戶接受 + 隨機PK + PK主要規則說明: + 隨機PK排位賽時間 + 12:00~17:00、19:00~23:59 + 1、開始匹配後,系統將自動挑選對手進行PK; + 2、若長時間無法匹配到對手,可嘗試重新匹配; + 3、PK過程中卡頓及延遲,可先檢查個人設備及網絡後,嘗試重新登錄並開播; + 4、安全部門將會24小時巡查,請文明PK,嚴格遵守主播守則; + 隨機PK開關: + 開始匹配 + 匹配中 %s + 再次點擊可取消匹配 + 正在退出匹配 %s + 退出過程中也有可能匹配到對手 + 請輸入您要pk的主播昵稱或id + 對方正在PK中 + + 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 e823ce93f..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,9 +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; @@ -638,7 +642,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //关注 FollowActivity.forward(mContext, CommonAppConfig.getInstance().getUid(), 0); } else if (i == R.id.img_trophy) { - MainListActivity.forward(mContext, 0); + // MainListActivity.forward(mContext, 0); + RandomPkDialogFragment fragment = new RandomPkDialogFragment(); + fragment.show(this.getSupportFragmentManager(), "RandomPkDialogFragment"); }