From 834170e2722b7a08d4d33e77bcd8fae63b353b65 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 11 Nov 2022 17:47:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=A8=E9=87=8F=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=87=87=E9=9B=86=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shayu/phonelive/utils/LogUtils.java | 39 ++-- .../java/com/yunbao/common/utils/LogUtil.java | 42 +++++ .../presenter/LiveRyLinkMicPkPresenter.java | 170 ++++++++++-------- .../yunbao/main/adapter/SettingAdapter.java | 4 + 4 files changed, 164 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/utils/LogUtils.java b/app/src/main/java/com/shayu/phonelive/utils/LogUtils.java index 58da15433..4b424b4b4 100644 --- a/app/src/main/java/com/shayu/phonelive/utils/LogUtils.java +++ b/app/src/main/java/com/shayu/phonelive/utils/LogUtils.java @@ -1,14 +1,19 @@ package com.shayu.phonelive.utils; +import static java.text.DateFormat.DEFAULT; + import android.content.Context; -import com.yunbao.common.utils.FileUtil; -import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.CommonAppConfig; import java.io.BufferedReader; import java.io.File; +import java.io.FileOutputStream; import java.io.InputStreamReader; -import java.net.URLEncoder; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; public class LogUtils { public static void start(Context context) { @@ -31,18 +36,26 @@ public class LogUtils { }; Process process = Runtime.getRuntime().exec(exec); - StringBuilder builder = new StringBuilder(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; - File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()); - while ((line = bufferedReader.readLine()) != null) { - builder.append(line).append("\n"); - if (builder.length() > 65500) { - FileUtil.saveAddStringToFile(saveFile, builder.toString(), "logcat.log"); - builder.setLength(0); + PrintWriter writer = null; + String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date()); + File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator); + if (dir.listFiles() != null) { + for (File file : dir.listFiles()) { + if (!file.getName().endsWith(today+".log") && !file.getName().endsWith("error.log")) { + file.delete(); + } } } - + File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log"); + FileOutputStream os = new FileOutputStream(saveFile); + writer = new PrintWriter(os); + while ((line = bufferedReader.readLine()) != null) { + writer.append(line).write("\n"); + } + writer.flush(); + writer.close(); exec = new String[]{ "logcat", "-c" @@ -52,10 +65,10 @@ public class LogUtils { start(context); } catch (Exception e) { e.printStackTrace(); - ToastUtil.show(""); } } }).start(); } + } diff --git a/common/src/main/java/com/yunbao/common/utils/LogUtil.java b/common/src/main/java/com/yunbao/common/utils/LogUtil.java index 44a84f33a..c3407ccc4 100644 --- a/common/src/main/java/com/yunbao/common/utils/LogUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/LogUtil.java @@ -1,9 +1,22 @@ package com.yunbao.common.utils; +import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED; +import static java.text.DateFormat.DEFAULT; + +import android.Manifest; +import android.app.Activity; import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; import android.text.TextUtils; import android.util.Log; +import androidx.core.app.ActivityCompat; +import androidx.core.content.FileProvider; +import androidx.core.content.PermissionChecker; + import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.model.Progress; @@ -16,6 +29,9 @@ import com.yunbao.common.CommonAppConfig; import java.io.File; import java.io.FileWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -119,4 +135,30 @@ public class LogUtil { } return null; } + + + public static void shareFile(Context context) { + if(PermissionChecker.checkCallingOrSelfPermission(context,"android.permission.WRITE_EXTERNAL_STORAGE")!= PERMISSION_GRANTED){ + ActivityCompat.requestPermissions((Activity) context,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100); + return; + } + String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date()); + File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log"); + file.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+file.getName())); + if (file.exists()) { + Intent share = new Intent(Intent.ACTION_SEND); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file); + share.putExtra(Intent.EXTRA_STREAM, contentUri); + share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } else { + share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); + } + share.setType("application/vnd.ms-excel"); + share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + context.startActivity(Intent.createChooser(share, "分享文件")); + } + } + } 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 853e74610..a33315537 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveRyLinkMicPkPresenter.java @@ -1062,7 +1062,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { return bitmap; } - private String TAG="多人PK"; + + private String TAG = "多人PK"; + /** * 退出多人PK */ @@ -1186,101 +1188,113 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener { @Override public void onSuccess(int code, String msgs, String[] info) { if (code == 0) { - Log.i("多人PK","1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info)+" mApplyUid = "+mApplyUid); - if (info.length == 0) { - ToastUtil.show("多人PK次数已用完"); - return; - } - rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, true, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { - @Override - public void onSuccess() { - HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") - .params("uid", CommonAppConfig.getInstance().getUid()) - .params("roomid", u.getId()) - .execute(new HttpCallback() { + Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid); + HttpClient.getInstance().get("live.getdrnum", "live.getdrnum") + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + boolean agree=true; + if (code != 0) { + ToastUtil.show("多人PK次数已用完"); + agree=false; + } + rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, agree, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { @Override - public void onSuccess(int code, String msg, String[] info) { - Log.i("多人PK","code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); + public void onSuccess() { + HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("roomid", u.getId()) + .execute(new HttpCallback() { - final SocketSendBean msg1 = new SocketSendBean() - .param("_method_", SOCKET_LIVE_DRPK) - .param("action", 10) - .param("uid", CommonAppConfig.getInstance().getUid()); - msg1.create(); - String targetId = "g" + CommonAppConfig.getInstance().getUid(); - Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; - TextMessage messageContent = TextMessage.obtain(msg1.mResult.toString()); - io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(targetId, conversationType, messageContent); + @Override + public void onSuccess(int code, String msg, String[] info) { + Log.i("多人PK","code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info)); - RongIMClient.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() { - @Override - public void onAttached(io.rong.imlib.model.Message message) { + final SocketSendBean msg1 = new SocketSendBean() + .param("_method_", SOCKET_LIVE_DRPK) + .param("action", 10) + .param("uid", CommonAppConfig.getInstance().getUid()); + msg1.create(); + String targetId = "g" + CommonAppConfig.getInstance().getUid(); + Conversation.ConversationType conversationType = Conversation.ConversationType.CHATROOM; + 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", "发送失敗"); - } - }); + @Override + public void onSuccess(io.rong.imlib.model.Message message) { + Log.e("ry", "发送成功"); + if (SocketRyClient.mSocketHandler != null) { + SocketRyClient.mSocketHandler.processBroadcast(msg1.mResult.toString() + ""); + } + } - JSONObject obj = JSONObject.parseObject(info[0]); - JSONArray users = obj.getJSONArray("userlist"); + @Override + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + Log.e("ry", "发送失敗"); + } + }); + if(info.length==0){ + return; + } + 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); + 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") + "列表"); - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { - if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { - /** - * 向指定用户发送跨房间连麦请求 - *

- * 1: inviterAutoMix为true时: - * - * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 - * - * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 - * - * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 - *

- */ - rtcRoom.getLocalUser().requestJoinOtherRoom(user.getString("id"), user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { - @Override - public void onSuccess() { + for (int i = 0; i < users.size(); i++) { + JSONObject user = users.getJSONObject(i); + Log.e("ry", mApplyUid + "VS" + user.getString("id") + "列表"); + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid())) { + if (!user.getString("id").equals(CommonAppConfig.getInstance().getUid()) && !user.getString("id").equals(u.getId())) { + /** + * 向指定用户发送跨房间连麦请求 + *

+ * 1: inviterAutoMix为true时: + * + * 1.1:如果被邀请方在加入邀请方房间之前发布了资源,当被邀请方加入邀请者房间成功后,服务器会把被邀请方流资源合并到邀请方视图 ·(默认仅悬浮布局合流)上。 + * + * 1.2:如果被邀请方在加入邀请方房间之前没有发布过资源,将会在被邀请方发布资源成功后,服务器会把被邀请方流资源合并到邀请方视图(默认仅悬浮布局合流)上。 + * + * 2:无论为true或false,双方都可以使用{@link RCRTCLiveInfo#setMixConfig(RCRTCMixConfig, IRCRTCResultCallback)} 方法主动设置合流布局。一旦主动设置过合流布局,后续音视频直播过程中设置的自动合流参数将失效。 + *

+ */ + rtcRoom.getLocalUser().requestJoinOtherRoom(user.getString("id"), user.getString("id"), false, "LiveDRPK1", new IRCRTCResultCallback() { + @Override + public void onSuccess() { + } + + @Override + public void onFailed(RTCErrorCode errorCode) { + + } + }); + } + } } + } + }); - @Override - public void onFailed(RTCErrorCode errorCode) { + } - } - }); - } - } - } + @Override + public void onFailed(RTCErrorCode errorCode) { + ToastUtil.show("接受失败"); } }); + } + }); - } - - @Override - public void onFailed(RTCErrorCode errorCode) { - ToastUtil.show("接受失败"); - } - }); } } diff --git a/main/src/main/java/com/yunbao/main/adapter/SettingAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SettingAdapter.java index 88f5ba1fc..b1ce5e971 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SettingAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SettingAdapter.java @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.Constants; import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DeviceUtils; +import com.yunbao.common.utils.LogUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.main.BuildConfig; import com.yunbao.main.R; @@ -50,6 +51,9 @@ public class SettingAdapter extends RecyclerView.Adapter { if (tag != null) { int position = (int) tag; SettingBean bean = mList.get(position); + if(bean.getId()==19){ + LogUtil.shareFile(context); + } if (mOnItemClickListener != null) { mOnItemClickListener.onItemClick(bean, position); }