完成随机PK模块

This commit is contained in:
zlzw 2022-12-07 15:36:23 +08:00
parent e134ef8d54
commit 28b4a36800
17 changed files with 824 additions and 372 deletions

View File

@ -598,7 +598,7 @@ public class LiveNetManager {
@Override
public void accept(ResponseModel<String> responseModel) throws Exception {
if (callback != null) {
callback.onSuccess("36956");
callback.onSuccess("98196");
// callback.onSuccess(responseModel.getData().getInfo());
}
}

View File

@ -1,5 +1,7 @@
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;
@ -71,7 +73,17 @@ public class IMRTCManager {
2:无论为true或false双方都可以使用RCRTCLiveInfo.setMixConfig(RCRTCMixConfig, IRCRTCResultCallback) 方法主动设置合流布局一旦主动设置过合流布局后续音视频直播过程中设置的自动合流参数将失效
extra - 扩展字段默认为空
*/
rtcRoom.getLocalUser().requestJoinOtherRoom(liveUid,liveUid,inviterAutoMix,extra,callback);
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);
}

View File

@ -0,0 +1,272 @@
package com.yunbao.common.manager;
import android.os.Handler;
import android.os.Looper;
import com.yunbao.common.CommonAppContext;
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;
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;
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 List<OnRandomPkTimer> randomPkTimer = new ArrayList<>();
Handler handler = new Handler(Looper.getMainLooper());
private RandomPkManager() {
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 == 8) {
nextPk();
}
});
}
};
}
public String getTimer() {
return String.format(Locale.CHINA, "%02d:%02d", min, sec);
}
private void nextPk() {
LiveNetManager.get(CommonAppContext.getTopActivity())
.randomPK(new HttpCallback<String>() {
@Override
public void onSuccess(String data) {
for (OnRandomPkTimer pkTimer : randomPkTimer) {
pkTimer.onStartPK(data);
}
}
@Override
public void onError(String error) {
}
});
}
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 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();
}
}
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();
status = PK_STATUS_DEFAULT;
}
});
}
}, 0, 1000);
}
public void end() {
if (task != null) {
task.cancel();
}
task = null;
status = PK_STATUS_DEFAULT;
callEnd();
}
public boolean isPking() {
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();
}
});
}
private void callRefuse() {
handler.post(() -> {
for (OnRandomPkTimer pkTimer : randomPkTimer) {
pkTimer.onRefuse();
}
});
}
public void setPkStatus(int status) {
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) {
}
public void onStartPK(String pkUid) {
}
public void onPking() {
}
public void onPkEnd() {
}
public void onRefuse() {
}
public void onPkEndTimer(String time) {
}
public void onPkEndStart() {
}
public void onPkEndSuccess() {
}
}
}

View File

@ -5,7 +5,7 @@ ext {
minSdkVersion : 21,
targetSdkVersion : 31,
versionCode : 310,
versionName : "6.4.5"
versionName : "6.4.7"
]
manifestPlaceholders = [
//

View File

@ -7,7 +7,6 @@ import static com.yunbao.common.Constants.SOCKET_LIVE_DRPK;
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.LivePushRyViewHolder.rtcRoom;
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;
@ -49,7 +48,6 @@ import com.yunbao.common.http.CommonHttpConsts;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.manager.IMRTCManager;
import com.yunbao.common.utils.BitmapUtil;
@ -71,7 +69,6 @@ import com.yunbao.live.bean.LiveReceiveGiftBean;
import com.yunbao.common.bean.LiveUserGiftBean;
import com.yunbao.common.bean.MicUserBean;
import com.yunbao.live.dialog.LiveLinkMicListDialogFragment;
import com.yunbao.live.dialog.LiveMicAnchorDialogFragment;
import com.yunbao.live.dialog.LiveNewFunctionDialogFragment;
import com.yunbao.live.dialog.LiveNewWishListDialogFragment;
import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience;
@ -90,7 +87,7 @@ 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.live.utils.RandomPkManager;
import com.yunbao.common.manager.RandomPkManager;
import com.yunbao.live.views.LiveEndViewHolder;
import com.yunbao.live.views.LiveMusicViewHolder;
import com.yunbao.live.views.LiveNewReadyRyViewHolder;
@ -102,9 +99,7 @@ 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;
@ -158,13 +153,35 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
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);
linkDrMicAnchorApply(pkUid, pkUid, SOCKET_LIVE_DRPK_RANDOM);
ToastUtil.show("发起随机PK:" + pkUid);
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());
msg1.put("randomPk", true);
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);
}
}
};
@ -1047,7 +1064,16 @@ 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 = 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());
linkMicAnchorApply(pkUid, stream, msg1.toString());
}
public void linkMicAnchorApply(final String pkUid, String stream, String extra) {
LiveHttpUtil.livePkCheckLive(pkUid, stream, mStream, new HttpCallback() {
@Override
@ -1056,15 +1082,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() {

View File

@ -0,0 +1,271 @@
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.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 String TAG = "自由PK";
private int mLiveUid;
private TabLayout tabLayout;
private View reset;
private CommonRefreshView mRecyclerView;
private View mPkInfoLayout;
private View mSearchLayout;
private EditText mSearch;
private ImageView mClear;
private RandomPkRecyclerAdapter adapter;
private DataHelper helper;
@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 = WindowManager.LayoutParams.WRAP_CONTENT;
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);
mPkInfoLayout = findViewById(R.id.layout_random_pk_info);
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(1);
searchTag.setText("主播搜索");
listTag.setTag(2);
listTag.setText("關注列表");
tabLayout.addTab(searchTag);
tabLayout.addTab(listTag);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (tab.getTag() != null) {
mPkInfoLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.GONE);
mSearchLayout.setVisibility(View.INVISIBLE);
switch ((int) tab.getTag()) {
case 1:
mSearchLayout.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.initData();
break;
case 2:
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<RandomPkUserBean> {
public void search(String key) {
LiveNetManager.get(mContext)
.randomPkSearchUser(key, WordsTypeUtil.changeTraditional(key), new com.yunbao.common.http.base.HttpCallback<List<RandomPkUserBean>>() {
@Override
public void onSuccess(List<RandomPkUserBean> data) {
List<RandomPkUserBean> list = new ArrayList<>();
list.add(null);
list.addAll(data);
adapter.setList(list);
adapter.notifyDataSetChanged();
}
@Override
public void onError(String error) {
}
});
}
@Override
public RefreshAdapter<RandomPkUserBean> getAdapter() {
return adapter;
}
@Override
public void loadData(int p, HttpCallback callback) {
LiveHttpUtil.getLivePkList(p, callback);
}
@Override
public List<RandomPkUserBean> processData(String[] info) {
Log.i(TAG, "processData: 获取数据成功");
List<LivePkBean> beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class);
List<RandomPkUserBean> 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<RandomPkUserBean> list, int listCount) {
}
@Override
public void onRefreshFailure() {
}
@Override
public void onLoadMoreSuccess(List<RandomPkUserBean> loadItemList, int loadItemCount) {
}
@Override
public void onLoadMoreFailure() {
}
}
}

View File

@ -2,11 +2,12 @@ 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.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
@ -18,7 +19,6 @@ import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.android.material.tabs.TabLayout;
import com.yunbao.common.adapter.RefreshAdapter;
import com.yunbao.common.bean.HttpCallbackModel;
@ -36,43 +36,69 @@ import com.yunbao.live.R;
import com.yunbao.live.adapter.RandomPkRecyclerAdapter;
import com.yunbao.live.bean.LivePkBean;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.utils.RandomPkManager;
import com.yunbao.common.manager.RandomPkManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
/**
* 随机PK
*/
public class RandomPkDialogFragment extends AbsDialogFragment implements View.OnClickListener {
private static final String TAG = "随机PK";
private int mLiveUid;
private TabLayout tabLayout;
private View reset;
private CommonRefreshView mRecyclerView;
private View mPkInfoLayout;
private View mSearchLayout;
private View mPkBtn;
private TextView mPkBtnTitle;
private TextView mPkBtnDesc;
private ImageView mRandomPkSwitch;
private EditText mSearch;
private ImageView mClear;
private RandomPkRecyclerAdapter adapter;
private DataHelper helper;
private final RandomPkManager.OnRandomPkTimer randomPkTimer = new RandomPkManager.OnRandomPkTimer() {
@Override
public void onTimer(String time) {
Log.i(TAG, "onTimer: "+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 onStartPK(String pkUid) {
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);
}
};
@ -101,9 +127,6 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On
window.setAttributes(params);
}
public void setLiveUid(int mLiveUid) {
this.mLiveUid = mLiveUid;
}
@Override
public void onDestroy() {
@ -115,110 +138,34 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On
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);
mPkInfoLayout = findViewById(R.id.layout_random_pk_info);
mSearchLayout = findViewById(R.id.random_pk_search_layout);
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);
mSearch = (EditText) findViewById(R.id.search_edit);
mClear = (ImageView) findViewById(R.id.search_clear);
mClear.setOnClickListener(this);
mRandomPkSwitch.setTag(true);
mRandomPkSwitch.setOnClickListener(this);
mPkBtn.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() {
RandomPkManager.getInstance().addOnRandomPkTimer(randomPkTimer);
initPkSwitch();
}
private void initTab() {
TabLayout.Tab randPkTag = tabLayout.newTab();
TabLayout.Tab searchTag = tabLayout.newTab();
TabLayout.Tab listTag = tabLayout.newTab();
randPkTag.setTag(1);
randPkTag.setText("隨機PK");
searchTag.setTag(2);
searchTag.setText("主播搜索");
listTag.setTag(3);
listTag.setText("關注列表");
tabLayout.addTab(randPkTag);
tabLayout.addTab(searchTag);
tabLayout.addTab(listTag);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (tab.getTag() != null) {
mPkInfoLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.GONE);
mSearchLayout.setVisibility(View.INVISIBLE);
switch ((int) tab.getTag()) {
case 1:
mSearch.setText("");
mSearchLayout.setVisibility(View.GONE);
mPkInfoLayout.setVisibility(View.VISIBLE);
break;
case 2:
mSearchLayout.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.initData();
break;
case 3:
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.initData();
break;
}
if (RandomPkManager.getInstance().isPking()) {
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);
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
/**
* 设置随机PK开关状态
@ -287,22 +234,28 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On
});
}
private void randomPk() {
if (mPkBtn.getTag() != null && (boolean) mPkBtn.getTag()) {
RandomPkManager.getInstance().end();
resetPkBtn();
mPkBtn.setTag(false);
if (mRandomPkSwitch.getTag() == null || !(boolean) mRandomPkSwitch.getTag()) {
ToastUtil.show("未开启随机PK开关");
return;
}
if ((mPkBtn.getTag() != null && (boolean) mPkBtn.getTag()) || RandomPkManager.getInstance().isPking()) {
RandomPkManager.getInstance().exitPk();
return;
}
if (RandomPkManager.getInstance().start()) {
mPkBtnDesc.setVisibility(View.VISIBLE);
mPkBtnDesc.setText(R.string.random_pk_info_btn_ing_desc);
RandomPkManager.getInstance().start();
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
@ -314,79 +267,8 @@ public class RandomPkDialogFragment extends AbsDialogFragment implements View.On
} else {
setPkSwitch(1);
}
} else if (id == R.id.search_clear) {
mSearch.setText("");
} else if (id == R.id.random_pk_info_btn) {
randomPk();
}
}
public class DataHelper implements CommonRefreshView.DataHelper<RandomPkUserBean> {
public void search(String key) {
LiveNetManager.get(mContext)
.randomPkSearchUser(key, WordsTypeUtil.changeTraditional(key), new com.yunbao.common.http.base.HttpCallback<List<RandomPkUserBean>>() {
@Override
public void onSuccess(List<RandomPkUserBean> data) {
List<RandomPkUserBean> list = new ArrayList<>();
list.add(null);
list.addAll(data);
adapter.setList(list);
adapter.notifyDataSetChanged();
}
@Override
public void onError(String error) {
}
});
}
@Override
public RefreshAdapter<RandomPkUserBean> getAdapter() {
return adapter;
}
@Override
public void loadData(int p, HttpCallback callback) {
LiveHttpUtil.getLivePkList(p, callback);
}
@Override
public List<RandomPkUserBean> processData(String[] info) {
Log.i(TAG, "processData: 获取数据成功");
List<LivePkBean> beans = JSON.parseArray(Arrays.toString(info), LivePkBean.class);
List<RandomPkUserBean> 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<RandomPkUserBean> list, int listCount) {
}
@Override
public void onRefreshFailure() {
}
@Override
public void onLoadMoreSuccess(List<RandomPkUserBean> loadItemList, int loadItemCount) {
}
@Override
public void onLoadMoreFailure() {
}
}
}

View File

@ -27,6 +27,7 @@ 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.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.ScreenDimenUtil;
@ -599,7 +600,7 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
* @param callBack 加入房间回调
* @group 房间管理
*/
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_START);
RCRTCEngine.getInstance().joinOtherRoom(u.getId(), new IRCRTCResultDataCallback<RCRTCOtherRoom>() {
@Override
public void onSuccess(RCRTCOtherRoom rcrtcOtherRoom) {
@ -1996,7 +1997,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);
}
/**

View File

@ -19,7 +19,6 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.GsonUtils;
import com.google.gson.reflect.TypeToken;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants;
@ -50,6 +49,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;
@ -1048,17 +1048,21 @@ 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) {
RandomPkManager.getInstance().setPkStatus(RandomPkManager.PK_STATUS_CLOSE);
if (LivePushRyViewHolder.mPreView1 != null) {
LivePushRyViewHolder.mPreView1.removeAllViews();
LivePushRyViewHolder.mPreView1.setVisibility(View.GONE);

View File

@ -1,103 +0,0 @@
package com.yunbao.live.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
public class RandomPkManager {
private static RandomPkManager manager;
private int min = -1;
private int sec = -1;
private Timer timer;
private TimerTask task;
private List<OnRandomPkTimer> randomPkTimer = new ArrayList<>();
private RandomPkManager() {
initTask();
}
public static RandomPkManager getInstance() {
if (manager == null) {
manager = new RandomPkManager();
}
return manager;
}
public void addOnRandomPkTimer(OnRandomPkTimer randomPkTimer) {
this.randomPkTimer.add(randomPkTimer);
}
public void unregisterOnRandomPkTimer(OnRandomPkTimer randomPkTimer) {
this.randomPkTimer.remove(randomPkTimer);
}
private void initVal() {
min = -1;
sec = -1;
}
private void initTask() {
task = new TimerTask() {
Handler handler = new Handler(Looper.getMainLooper());
@Override
public void run() {
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 == 5) {
LiveNetManager.get(CommonAppContext.getTopActivity())
.randomPK(new HttpCallback<String>() {
@Override
public void onSuccess(String data) {
for (OnRandomPkTimer pkTimer : randomPkTimer) {
pkTimer.onStartPK(data);
}
}
@Override
public void onError(String error) {
}
});
}
});
}
};
}
public void start() {
task.cancel();
initTask();
initVal();
timer = new Timer();
timer.schedule(task, 0, 1000);
}
public void end() {
task.cancel();
}
public interface OnRandomPkTimer {
void onTimer(String time);
void onStartPK(String pkUid);
}
}

View File

@ -36,6 +36,7 @@ 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;

View File

@ -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,9 @@ 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);
@ -736,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);
@ -1180,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);

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="96dp" android:height="28dp">
<shape android:shape="rectangle">
<solid android:color="#fffa6400" />
<corners android:radius="21dp" />
</shape>
</item>
</selector>

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="330dp"
android:background="@drawable/bg_live_tota">
<LinearLayout
android:id="@+id/random_menu_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/menu_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="0"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@drawable/rc_picture_icon_back" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginEnd="10dp"
android:layout_weight="1">
<com.google.android.material.tabs.TabLayout
android:id="@+id/menu_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabIndicator="@drawable/random_pk_shape_tab_indicator"
app:tabIndicatorColor="#F6F7FB"
app:tabIndicatorFullWidth="false"
app:tabMaxWidth="100dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="#F6F7FB"
app:tabTextColor="#9A9A9A" />
</HorizontalScrollView>
<LinearLayout
android:id="@+id/menu_reset"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="0.1"
android:gravity="center"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@mipmap/icon_reset" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="1dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/dialog_reset"
android:textColor="#9A9A9A"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<include
layout="@layout/item_random_pk_rv_search"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:visibility="visible" />
<com.yunbao.common.custom.CommonRefreshView
android:id="@+id/random_container_view"
android:layout_width="match_parent"
android:layout_height="238dp"
android:layout_marginTop="10dp"
android:visibility="visible">
</com.yunbao.common.custom.CommonRefreshView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -23,69 +23,13 @@
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/menu_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="0"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@drawable/rc_picture_icon_back" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginEnd="10dp"
android:layout_weight="1">
<com.google.android.material.tabs.TabLayout
android:id="@+id/menu_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabIndicator="@drawable/random_pk_shape_tab_indicator"
app:tabIndicatorColor="#F6F7FB"
app:tabIndicatorFullWidth="false"
app:tabMaxWidth="100dp"
app:tabMode="scrollable"
app:tabSelectedTextColor="#F6F7FB"
app:tabTextColor="#9A9A9A" />
</HorizontalScrollView>
<LinearLayout
android:id="@+id/menu_reset"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="0.1"
android:gravity="center"
android:visibility="visible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@mipmap/icon_reset" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="1dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/dialog_reset"
android:textColor="#9A9A9A"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout>
android:text="@string/random_pk_info_view_title"
android:textColor="#F6F7FB"
android:textSize="16sp" />
</LinearLayout>
<include

View File

@ -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" />
<TextView
android:id="@+id/random_pk_timer"
android:layout_width="96dp"
android:layout_height="30dp"
android:layout_below="@id/live_time"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="@drawable/bg_live_room_random_pk_timer"
android:gravity="center"
android:text="@string/random_pk_info_btn_ing"
android:textColor="#FFFFFF"
android:visibility="gone"
android:textSize="10sp" />
<LinearLayout
android:id="@+id/goto_room_view"
android:layout_width="wrap_content"
@ -1231,6 +1245,7 @@
</FrameLayout>
<FrameLayout
android:id="@+id/live_item_view_layout"
android:layout_width="match_parent"
android:layout_height="36dp"
android:translationX="0dp">

View File

@ -32,6 +32,7 @@
<string name="live_mic_user_down" translatable="false">已踢下麥</string>
<string name="live_mic_invite" translatable="false">已發出邀請,等待用戶接受</string>
<string name="live_mic_request" translatable="false">已同意請求,等待用戶接受</string>
<string name="random_pk_info_view_title" translatable="false">隨機PK</string>
<string name="random_pk_info_title" translatable="false">PK主要規則說明</string>
<string name="random_pk_info_desc_1" translatable="false">1、開始匹配後系統將會自動給您挑選對手進行PK</string>
<string name="random_pk_info_desc_2" translatable="false">2、每場PK總時長10分鍾懲罰時間為1分鍾</string>