From 50fa5831c0e1a3d2ab49da1a61b1963441fedc9d 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: Mon, 11 Nov 2024 16:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E6=92=AD=E5=BC=80=E6=92=AD=E6=97=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BB=9C=E7=8E=AF=E5=A2=83=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=92=8C=E6=8F=90=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 4 +- .../beautyapi/faceunity/agora/SWManager.java | 29 +++++++++ .../live/activity/LiveAudienceActivity.java | 2 + .../yunbao/live/dialog/NetWorkTipDialog.java | 62 +++++++++++++++++++ .../live/views/LivePushSwViewHolder.java | 44 +++++++++++++ .../main/res/layout/dialog_network_tip.xml | 53 ++++++++++++++++ live/src/main/res/values-zh/strings.xml | 3 +- live/src/main/res/values/strings.xml | 2 + 8 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/dialog/NetWorkTipDialog.java create mode 100644 live/src/main/res/layout/dialog_network_tip.xml diff --git a/config.gradle b/config.gradle index 17f2473dc..623237025 100644 --- a/config.gradle +++ b/config.gradle @@ -4,8 +4,8 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 23, targetSdkVersion : 34, - versionCode : 904, - versionName : "6.8.3" + versionCode : 906, + versionName : "6.8.4" ] manifestPlaceholders = [ //正式、 diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 80f408758..a9f008ddb 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -68,6 +68,7 @@ public class SWManager extends BaseCacheManager { private FrameLayout pkContainer; //pk主播视图1 private FrameLayout linkUserContainer;//连麦用户视图 private onRtcEngineListener onRtcEngineListener; + private onNetWorkListener onNetWorkListener; private List drPkUserInfo = new ArrayList<>(); private ImageTrackOptions imageTrackOptions = null; @@ -81,6 +82,9 @@ public class SWManager extends BaseCacheManager { public void setOnRtcEngineListener(SWManager.onRtcEngineListener onRtcEngineListener) { this.onRtcEngineListener = onRtcEngineListener; } + public void setOnNetWorkListener(SWManager.onNetWorkListener onNetWorkListener) { + this.onNetWorkListener = onNetWorkListener; + } public SWManager(Context context) { super(context); @@ -530,6 +534,26 @@ public class SWManager extends BaseCacheManager { super.onLocalVideoStateChanged(source, state, error); L.eSw("onLocalVideoStateChanged_source" + source + " state_" + state + " error_" + error); } + + @Override + public void onConnectionStateChanged(int state, int reason) { + super.onConnectionStateChanged(state, reason); + L.eSw("onConnectionStateChanged: state = " + state + " reason = " + reason ); + + // 使用wifi和数据切换的时候,也会引起这个回调 + if (state == 4 && reason == 2){ + // 断网了 + if (onNetWorkListener != null){ + onNetWorkListener.onConnectionFail(); + } + + }else if (state == 3 && reason == 15){ + // 断网后又恢复了 + if (onNetWorkListener != null){ + onNetWorkListener.onConnectionSuccess(); + } + } + } }; private void refreshToken() { @@ -552,6 +576,11 @@ public class SWManager extends BaseCacheManager { public void release() { } + public interface onNetWorkListener { + void onConnectionSuccess(); + + void onConnectionFail(); + } public interface onRtcEngineListener { void onOpenSuccess(String channel, int uid); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 79ae414fd..a1fafdf2c 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -182,6 +182,8 @@ public class LiveAudienceActivity extends LiveActivity { private LiveBean mLiveBean; //当前直播间下标 private int mCurrentItem, mCurrentPage; + + // 这里集成直播间UI private static PortraitLiveManager manager; private int mLastPosition = -1; diff --git a/live/src/main/java/com/yunbao/live/dialog/NetWorkTipDialog.java b/live/src/main/java/com/yunbao/live/dialog/NetWorkTipDialog.java new file mode 100644 index 000000000..95d925297 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/NetWorkTipDialog.java @@ -0,0 +1,62 @@ +package com.yunbao.live.dialog; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.cardview.widget.CardView; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.dialog.AbsDialogCenterPopupWindow; +import com.yunbao.live.R; + +/** + * Author: plx + * Date: 2024/11/11 + * Description: + */ +@SuppressLint("ViewConstructor") +public class NetWorkTipDialog extends AbsDialogCenterPopupWindow { + // 1 断网 2 恢复 + private int type; + private TextView text_tip; + private CardView close_btn; + + public NetWorkTipDialog(@NonNull Context context,int type) { + super(context); + this.type = type; + } + + @Override + public void buildDialog(XPopup.Builder builder) { + builder.dismissOnTouchOutside(false).dismissOnBackPressed(false); + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_network_tip; + } + + @Override + protected void onCreate() { + super.onCreate(); + text_tip = (TextView)findViewById(R.id.text_tip); + close_btn = (CardView)findViewById(R.id.close_btn); + + if (type == 1){ + text_tip.setText(R.string.connection_fail); + }else { + text_tip.setText(R.string.connection_success); + } + + close_btn.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + } +} 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 efe2649f3..1249fcd00 100644 --- a/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LivePushSwViewHolder.java @@ -45,6 +45,7 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveSwAnchorActivity; import com.yunbao.live.bean.DrPkbean; +import com.yunbao.live.dialog.NetWorkTipDialog; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.common.http.LiveHttpConsts; import com.yunbao.common.http.LiveHttpUtil; @@ -230,6 +231,9 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder { initRtcEngine(); } + private NetWorkTipDialog netWorkTipOkDialog; + private NetWorkTipDialog netWorkTipFailDialog; + /** * 初始化声网SDK */ @@ -247,6 +251,46 @@ public class LivePushSwViewHolder extends AbsRyLivePushViewHolder { @Override public void onUserOffline(int uid) { + } + }); + swManager.setOnNetWorkListener(new SWManager.onNetWorkListener() { + @Override + public void onConnectionSuccess() { + // 显示成功连接网络通知 + if (mContext != null){ + ((Activity) mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + if (netWorkTipFailDialog != null && netWorkTipFailDialog.isShow()){ + netWorkTipFailDialog.dismiss(); + } + if (netWorkTipOkDialog == null){ + netWorkTipOkDialog = new NetWorkTipDialog(mContext, 2); + } + netWorkTipOkDialog.showDialog(); + } + }); + } + } + + @Override + public void onConnectionFail() { + if (mContext != null){ + ((Activity) mContext).runOnUiThread(new Runnable() { + @Override + public void run() { + // 显示断网通知 + if (netWorkTipOkDialog != null && netWorkTipOkDialog.isShow()){ + netWorkTipOkDialog.dismiss(); + } + if (netWorkTipFailDialog == null){ + netWorkTipFailDialog = new NetWorkTipDialog(mContext, 1); + } + netWorkTipFailDialog.showDialog(); + } + }); + } + } }); } diff --git a/live/src/main/res/layout/dialog_network_tip.xml b/live/src/main/res/layout/dialog_network_tip.xml new file mode 100644 index 000000000..07e55c61b --- /dev/null +++ b/live/src/main/res/layout/dialog_network_tip.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/values-zh/strings.xml b/live/src/main/res/values-zh/strings.xml index dadd181ce..7484b94b5 100644 --- a/live/src/main/res/values-zh/strings.xml +++ b/live/src/main/res/values-zh/strings.xml @@ -162,5 +162,6 @@ 詳情 喜歡主播就關注ta吧~ 點擊查看 - + 网络连接中断,请检查您的网络 + 已连接网络 diff --git a/live/src/main/res/values/strings.xml b/live/src/main/res/values/strings.xml index c19c47772..338ab3344 100644 --- a/live/src/main/res/values/strings.xml +++ b/live/src/main/res/values/strings.xml @@ -165,4 +165,6 @@ Details If you like this anchor, please subscribe to him. Click to view + The network connection is interrupted. Please check your network. + The network has been restored. \ No newline at end of file