修复下播后随即PK没有自动取消匹配

This commit is contained in:
zlzw 2022-12-29 16:34:35 +08:00
parent 55f3ac577b
commit 87e3dddac5
2 changed files with 42 additions and 15 deletions

View File

@ -37,6 +37,8 @@ public class RandomPkManager {
private String pkUid;//对方房间ID private String pkUid;//对方房间ID
public static String debugUid; public static String debugUid;
private RankPkInfoBean rankPkInfoBean;//排位赛信息 private RankPkInfoBean rankPkInfoBean;//排位赛信息
private int exitTimer;//退出倒计时
private TimerTask exitTask = null;//退出任务
Handler handler = new Handler(Looper.getMainLooper()); Handler handler = new Handler(Looper.getMainLooper());
private RandomPkManager() { private RandomPkManager() {
@ -118,6 +120,8 @@ public class RandomPkManager {
return String.format(Locale.CHINA, "%02d:%02d", min, sec); return String.format(Locale.CHINA, "%02d:%02d", min, sec);
} }
private Runnable pkRunnable = this::next;
/** /**
* 对方拒绝开始下一轮匹配 * 对方拒绝开始下一轮匹配
*/ */
@ -125,7 +129,7 @@ public class RandomPkManager {
if (status != PK_STATUS_DEFAULT && status != PK_STATUS_REFUSE) { if (status != PK_STATUS_DEFAULT && status != PK_STATUS_REFUSE) {
return; return;
} }
new Handler(Looper.getMainLooper()).postDelayed(this::next, 5000); handler.postDelayed(pkRunnable, 5000);
} }
private void next() { private void next() {
@ -243,19 +247,9 @@ public class RandomPkManager {
} }
} }
private int exitTimer;
/** private TimerTask createExitTask() {
* 退出匹配 return new TimerTask() {
*/
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()); Handler handler = new Handler(Looper.getMainLooper());
@ -269,10 +263,25 @@ public class RandomPkManager {
end(); end();
callEndPkSuccess(); callEndPkSuccess();
cancel(); cancel();
exitTask = null;
} }
}); });
} }
}, 0, 1000); };
}
/**
* 退出匹配
*/
public void exitPk() {
if (status == PK_STATUS_EXIT_ING) {
return;
}
callEndPkStart();
status = PK_STATUS_EXIT_ING;
exitTimer = 11;
exitTask = createExitTask();
new Timer().schedule(exitTask, 0, 1000);
} }
/** /**
@ -387,6 +396,23 @@ public class RandomPkManager {
return exitTimer + ""; return exitTimer + "";
} }
/**
* 清空状态下播时调用
*/
public void release() {
status = PK_STATUS_REQUEST;
if (task != null) {
task.cancel();
}
if (exitTask != null) {
exitTask.cancel();
}
randomPkTimer.clear();
rankPkInfoBean = null;
pkUid = null;
handler.removeCallbacks(pkRunnable);
}
public static abstract class OnRandomPkTimer { public static abstract class OnRandomPkTimer {
/** /**

View File

@ -843,6 +843,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
PKing = false; PKing = false;
isDRPK = 0; isDRPK = 0;
endLive(); endLive();
RandomPkManager.getInstance().release();
} }
}); });
} }