|
|
@@ -25,11 +25,11 @@ enum class ConnectStatus {
|
|
|
ConnectingOrConnected, //已连接或者连接中
|
|
|
}
|
|
|
|
|
|
-object ConnectionStatusManager: CoroutineScope {
|
|
|
+object ConnectionStatusManager : CoroutineScope {
|
|
|
private val floatViewFactory by fastLazy { FloatViewFactory() }
|
|
|
private var disconnectFloatView: NetworkReconnectFloatView? = null
|
|
|
private var connectType2ConnectStatus = hashMapOf<ConnectType, ConnectStatus>()
|
|
|
- private var connectType2ClickListener = hashMapOf<ConnectType, (()->Unit)?>()
|
|
|
+ private var connectType2ClickListener = hashMapOf<ConnectType, (() -> Unit)?>()
|
|
|
val serialHandler = Dispatcher.getSerialHandler()
|
|
|
override val coroutineContext = SupervisorJob() + serialHandler.asCoroutineDispatcher()
|
|
|
private val connectStatusListeners = ConcurrentList<ConnectStatusListener>()
|
|
|
@@ -37,11 +37,12 @@ object ConnectionStatusManager: CoroutineScope {
|
|
|
fun addConnectStatusListener(listener: ConnectStatusListener) {
|
|
|
connectStatusListeners.add(listener)
|
|
|
}
|
|
|
+
|
|
|
fun removeConnectStatusListener(listener: ConnectStatusListener) {
|
|
|
connectStatusListeners.remove(listener)
|
|
|
}
|
|
|
|
|
|
- fun addReconnectClickListener(type: ConnectType, clickListener: (()->Unit)?) {
|
|
|
+ fun addReconnectClickListener(type: ConnectType, clickListener: (() -> Unit)?) {
|
|
|
launch {
|
|
|
connectType2ClickListener[type] = clickListener
|
|
|
}
|
|
|
@@ -49,9 +50,17 @@ object ConnectionStatusManager: CoroutineScope {
|
|
|
|
|
|
fun notifyConnectStatus(type: ConnectType, status: ConnectStatus) {
|
|
|
launch {
|
|
|
+ Log.i(TAG_DISCONNECT_TIP, "notifyConnectStatus, type:${type}, status:${status}")
|
|
|
+ if (connectType2ConnectStatus[type] == status) {
|
|
|
+ Log.e(
|
|
|
+ TAG_DISCONNECT_TIP,
|
|
|
+ "notifyConnectStatus return, status no change. type:${type}, status:${status}"
|
|
|
+ )
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
connectType2ConnectStatus[type] = status
|
|
|
updateFloatView()
|
|
|
- runOnUiThread{
|
|
|
+ runOnUiThread {
|
|
|
connectStatusListeners.dispatch { it.onConnectStatusChanged(type, status) }
|
|
|
}
|
|
|
}
|
|
|
@@ -63,6 +72,7 @@ object ConnectionStatusManager: CoroutineScope {
|
|
|
* 如果都没有断开,不显示任何状态
|
|
|
*/
|
|
|
private fun updateFloatView() {
|
|
|
+ Log.i(TAG_DISCONNECT_TIP, "updateFloatView")
|
|
|
val bizConnectStatus = connectType2ConnectStatus[ConnectType.BIZ]
|
|
|
if (bizConnectStatus == ConnectStatus.Disconnected) {
|
|
|
addDisconnectFloatView(ConnectType.BIZ)
|
|
|
@@ -89,9 +99,9 @@ object ConnectionStatusManager: CoroutineScope {
|
|
|
removeDisconnectFloatView()
|
|
|
connectType2ClickListener[type]?.invoke()
|
|
|
}
|
|
|
- Log.d(
|
|
|
+ Log.i(
|
|
|
TAG_DISCONNECT_TIP,
|
|
|
- "addDisconnectFloatView, disconnectFloatView:${disconnectFloatView}"
|
|
|
+ "addDisconnectFloatView, type:${type}"
|
|
|
)
|
|
|
if (disconnectFloatView != null) {
|
|
|
WindowManagerProxy.getWindowManager().addView(disconnectFloatView!!)
|
|
|
@@ -102,9 +112,9 @@ object ConnectionStatusManager: CoroutineScope {
|
|
|
|
|
|
fun removeDisconnectFloatView() {
|
|
|
runOnUiThread {
|
|
|
- Log.d(
|
|
|
+ Log.i(
|
|
|
TAG_DISCONNECT_TIP,
|
|
|
- "removeDisconnectFloatView, disconnectFloatView:${disconnectFloatView}"
|
|
|
+ "removeDisconnectFloatView, disconnectFloatView is null:${disconnectFloatView == null}"
|
|
|
)
|
|
|
if (disconnectFloatView != null) {
|
|
|
WindowManagerProxy.getWindowManager().removeView(disconnectFloatView!!)
|