diff --git a/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt b/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt
index 8d390be..9b26239 100644
--- a/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt
+++ b/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt
@@ -18,6 +18,7 @@ import com.yuanxuan.rokid.databinding.ActivityMainBinding
import com.yuanxuan.rokid.extension.fadeIn
import com.yuanxuan.rokid.extension.fadeOut
import com.yuanxuan.rokid.keeplive.KeepLiveService
+import com.yuanxuan.rokid.network.websocket.WebSocketConnectionState
import com.yuanxuan.rokid.network.websocket.WebSocketEvent
import com.yuanxuan.rokid.ui.NoticeFragment
import kotlinx.coroutines.delay
@@ -47,8 +48,6 @@ class MainActivity : AppCompatActivity() {
* 拦截返回键事件,防止返回到桌面
*/
onBackPressedDispatcher.addCallback {
- viewModel.wakeUp()
- navigationToast("TestMessage")
}
/**
* 这个服务保证心跳包准时发
@@ -119,6 +118,13 @@ class MainActivity : AppCompatActivity() {
binding.lottieVoiceInput.cancelAnimation()
binding.lottieVoiceInput.fadeOut(300)
}
+ if (uiState.connectStatus == WebSocketConnectionState.CONNECTED) {
+ binding.socketStatus.text =
+ resources.getString(R.string.socket_status_connected)
+ } else {
+ binding.socketStatus.text =
+ resources.getString(R.string.socket_status_connecting)
+ }
}
}
}
diff --git a/app/src/main/java/com/yuanxuan/rokid/MainViewModel.kt b/app/src/main/java/com/yuanxuan/rokid/MainViewModel.kt
index 70506fe..8e7542a 100644
--- a/app/src/main/java/com/yuanxuan/rokid/MainViewModel.kt
+++ b/app/src/main/java/com/yuanxuan/rokid/MainViewModel.kt
@@ -2,9 +2,10 @@ package com.yuanxuan.rokid
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
-import com.yuanxuan.rokid.dependencies.AppDependencies
+import com.yuanxuan.rokid.dependencies.AppDependencies.webSocketManager
import com.yuanxuan.rokid.dependencies.AppDependencies.deviceServiceManager
import com.yuanxuan.rokid.device.DeviceServiceManager
+import com.yuanxuan.rokid.network.websocket.WebSocketConnectionState
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asSharedFlow
@@ -21,24 +22,27 @@ class MainViewModel : ViewModel() {
val uiState = combine(
deviceServiceManager.batteryPercentage,
deviceServiceManager.wifiState,
- deviceServiceManager.instructState
- ) { battery, wifi, instruct ->
+ deviceServiceManager.instructState,
+ webSocketManager.connectFlow
+ ) { battery, wifi, instruct, connect ->
MainUiState(
batteryLevel = battery,
wifiLevel = if (wifi is DeviceServiceManager.WifiState.Connected) wifi.level else 0,
- isVoiceInputVisible = instruct == DeviceServiceManager.InstructState.WaitingInstructState
+ isVoiceInputVisible = instruct == DeviceServiceManager.InstructState.WaitingInstructState,
+ connectStatus = connect
)
}.stateIn(
scope = viewModelScope,
initialValue = MainUiState(
batteryLevel = 0,
wifiLevel = 0,
- isVoiceInputVisible = false
+ isVoiceInputVisible = false,
+ connectStatus = WebSocketConnectionState.DISCONNECTED
),
started = SharingStarted.WhileSubscribed(5.seconds.inWholeMilliseconds),
)
- val socketEvent = AppDependencies.webSocketManager.socketEventFlow
+ val socketEvent = webSocketManager.socketEventFlow
fun quitInstructReceived() {
deviceServiceManager.quitInstructReceived()
@@ -68,6 +72,7 @@ class MainViewModel : ViewModel() {
val batteryLevel: Int,
val wifiLevel: Int,
val isVoiceInputVisible: Boolean,
+ val connectStatus: WebSocketConnectionState,
)
}
\ No newline at end of file
diff --git a/app/src/main/java/com/yuanxuan/rokid/network/NetUtils.kt b/app/src/main/java/com/yuanxuan/rokid/network/NetUtils.kt
index 633b589..942e40e 100644
--- a/app/src/main/java/com/yuanxuan/rokid/network/NetUtils.kt
+++ b/app/src/main/java/com/yuanxuan/rokid/network/NetUtils.kt
@@ -6,8 +6,8 @@ import java.net.NetworkInterface
object NetUtils {
- fun getBaseUrl() = "http://${getLocalIPV4address()}.70:7070"
-// fun getBaseUrl() = "http://${getLocalIPV4address()}.52:8765"
+// fun getBaseUrl() = "http://${getLocalIPV4address()}.70:7070"
+ fun getBaseUrl() = "http://${getLocalIPV4address()}.13:8765"
/**
diff --git a/app/src/main/java/com/yuanxuan/rokid/network/websocket/WebSocketManager.kt b/app/src/main/java/com/yuanxuan/rokid/network/websocket/WebSocketManager.kt
index 51770b9..7454eb5 100644
--- a/app/src/main/java/com/yuanxuan/rokid/network/websocket/WebSocketManager.kt
+++ b/app/src/main/java/com/yuanxuan/rokid/network/websocket/WebSocketManager.kt
@@ -11,6 +11,8 @@ class WebSocketManager(context: Context, scope: CoroutineScope) {
val socketEventFlow = webSocketConnection.eventFlow
+ val connectFlow = webSocketConnection.webSocketConnectionStateFlow
+
init {
scope.launch {
webSocketConnection.webSocketConnectionStateFlow.collectLatest { state ->
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 5110b8d..a7f4c80 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -12,20 +12,20 @@
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintBottom_toTopOf="@id/lottie_voice_input"
app:defaultNavHost="true"
+ app:layout_constraintBottom_toTopOf="@id/lottie_voice_input"
+ app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/app_navigation" />
+ app:layout_constraintEnd_toEndOf="parent"
+ tools:text="50%" />
+
+
%d%%
设备SN:%s
APP版本:%s
+ 已连接
+ 连接中
\ No newline at end of file