From ee431d0ee2e36ad9b79f5ae5d721e447e827b7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E7=9A=AE?= <14840170+lao-pi123@user.noreply.gitee.com> Date: Fri, 1 Nov 2024 10:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E4=BA=BAPK=E4=BA=BA=E6=95=B0=E5=92=8C?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E4=B8=8D=E5=AF=B9=E5=BA=94=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E5=A4=84=E7=90=86=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/views/LivePushSwViewHolder.java | 5 ++ .../live/views/LiveRyAnchorViewHolder.java | 18 ++++- .../main/java/com/yunbao/main/FileCopier.java | 66 +++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 main/src/main/java/com/yunbao/main/FileCopier.java diff --git a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java index 79724f229..efe2649f3 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -356,6 +356,10 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder { } else { temp = position; } + + L.eSw("PK 人数:" + temp ); + + switch (temp) { case 2: swManager.joinChannelDrEx(dr2_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, uid, SWAuManager.getChannelName(uid), temp); @@ -373,6 +377,7 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder { break; case 4: dr3_preview.setVisibility(View.VISIBLE); + dr4_preview.setVisibility(View.VISIBLE); //先退出这个主播的直播间,在进入该直播间,(视图问题暂时這樣處理) swManager.exitChannelToUid(Integer.parseInt(CommonAppConfig.getInstance().getUid()), drpkUid3); swManager.joinChannelDrEx(dr3_preview, CommonAppConfig.getInstance().getUid(), CommonAppConfig.SWToken, drpkUid3, SWAuManager.getChannelName(drpkUid3), temp); diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index c701be428..57d774bec 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -177,7 +177,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { } }); - //结束多人PK + //发起人 多人PK 强制退出 btn_end_pk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -186,28 +186,40 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { .execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { + Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.LEAVE_DR_ROOM)); PKing = false; } + + @Override + public void onError() { + super.onError(); + + } }); btn_start_dr_pk_view.setVisibility(View.GONE); yaoqing.clear(); } }); + + // 被邀请人退出多人PK btn_end_pk_dr.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - closeEndPkBt(); HttpClient.getInstance().post("tuichuduorenpkfangjian", "tuichuduorenpkfangjian") .params("roomid", drpkRoomId) .params("uid", CommonAppConfig.getInstance().getUid()) .execute(new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + closeEndPkBt(); + }else { + ToastUtil.show(msg); + } L.eSw("tuichuduorenpkfangjian" + code + " info" + new Gson().toJson(info)); - } }); } diff --git a/main/src/main/java/com/yunbao/main/FileCopier.java b/main/src/main/java/com/yunbao/main/FileCopier.java new file mode 100644 index 000000000..73cb35398 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/FileCopier.java @@ -0,0 +1,66 @@ +package com.yunbao.main; + +/** + * Author: plx + * Date: 2024/11/1 + * Description: + */ +import android.Manifest; +import android.app.Activity; +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Environment; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class FileCopier { + + private static final int REQUEST_WRITE_STORAGE = 112; + + public void copyLogsToExternalStorage(Context context) { + // 检查并请求写入外部存储的权限 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE); + return; + } + } + + // 定义源目录和目标目录 + File sourceDir = new File(context.getFilesDir(), "log"); + File targetDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "app_logs"); + + // 确保目标目录存在 + if (!targetDir.exists()) { + targetDir.mkdirs(); + } + + // 复制文件 + File[] logFiles = sourceDir.listFiles((dir, name) -> name.endsWith(".log")); + if (logFiles != null) { + for (File logFile : logFiles) { + File targetFile = new File(targetDir, logFile.getName()); + try (InputStream in = new FileInputStream(logFile); + OutputStream out = new FileOutputStream(targetFile)) { + + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer)) != -1) { + out.write(buffer, 0, read); + } + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } +}