feat(android): T-AND-007/008 连接页/运行页/关于页 + 骨架叠加
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.opendance.studio
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.opendance.studio.data.AppSettings
|
||||
import com.opendance.studio.ui.AboutScreen
|
||||
import com.opendance.studio.ui.ConnectScreen
|
||||
import com.opendance.studio.ui.RunningScreen
|
||||
import com.opendance.studio.ui.theme.OpenDanceTheme
|
||||
|
||||
/**
|
||||
* 应用入口与页面导航(T-AND-001 / 006 / 007 / 008)。
|
||||
*
|
||||
* 只有三个页面,用简单的状态机导航,不引入 Navigation 组件:
|
||||
* Connect ──开始推流──▶ Running ──结束/返回──▶ Connect
|
||||
* Connect ──关于──▶ About ──返回──▶ Connect
|
||||
*/
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
OpenDanceTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background,
|
||||
) {
|
||||
OpenDanceRoot()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum class Screen { CONNECT, RUNNING, ABOUT }
|
||||
|
||||
@Composable
|
||||
private fun OpenDanceRoot() {
|
||||
val context = LocalContext.current
|
||||
val settings = remember { AppSettings(context.applicationContext) }
|
||||
var screen by remember { mutableStateOf(Screen.CONNECT) }
|
||||
|
||||
// 推流中按返回键等同于结束推流,避免相机在后台继续占用
|
||||
BackHandler(enabled = screen == Screen.RUNNING) {
|
||||
screen = Screen.CONNECT
|
||||
}
|
||||
|
||||
when (screen) {
|
||||
Screen.CONNECT -> ConnectScreen(
|
||||
settings = settings,
|
||||
onStart = { screen = Screen.RUNNING },
|
||||
onAbout = { screen = Screen.ABOUT },
|
||||
)
|
||||
|
||||
Screen.RUNNING -> RunningScreen(
|
||||
settings = settings,
|
||||
onStop = { screen = Screen.CONNECT },
|
||||
)
|
||||
|
||||
Screen.ABOUT -> AboutScreen(
|
||||
onBack = { screen = Screen.CONNECT },
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user