fix: 修复房间管理增删改;优化 UI 性能与交互
This commit is contained in:
parent
e2c6741afc
commit
bba4e3abb7
@ -4,6 +4,9 @@ import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import com.example.smarthome.ui.theme.SmartHomeTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.LocalOverscrollConfiguration
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.material3.Surface
|
||||
@ -72,6 +75,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun AppRoot() {
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
@ -79,6 +83,8 @@ fun AppRoot() {
|
||||
// 监听登录状态
|
||||
val isLoggedIn by UserManager.isLoggedIn.collectAsState()
|
||||
|
||||
// 禁用上下滑到边界时的拉伸回弹效果,降低滑动重绘开销
|
||||
CompositionLocalProvider(LocalOverscrollConfiguration provides null) {
|
||||
if (!isLoggedIn) {
|
||||
// 未登录,显示登录页面
|
||||
LoginScreen(
|
||||
@ -91,6 +97,7 @@ fun AppRoot() {
|
||||
MainContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainContent() {
|
||||
|
||||
@ -132,7 +132,8 @@ fun MainScaffold(
|
||||
selectedNavItem = selectedNavItem,
|
||||
onNavItemSelect = onNavItemSelect,
|
||||
modifier = Modifier.fillMaxHeight(),
|
||||
hazeState = hazeState
|
||||
hazeState = hazeState,
|
||||
rooms = rooms
|
||||
)
|
||||
|
||||
// 间距
|
||||
@ -2347,18 +2348,12 @@ fun GlassSidebar(
|
||||
selectedNavItem: Int = 0,
|
||||
onNavItemSelect: (Int) -> Unit = {},
|
||||
modifier: Modifier = Modifier,
|
||||
hazeState: HazeState
|
||||
hazeState: HazeState,
|
||||
rooms: List<String> = listOf("总览", "客厅", "厨房", "卧室", "影音室", "游戏房")
|
||||
) {
|
||||
|
||||
// 房间列表 - 放在总览上面
|
||||
val roomNavItems = listOf(
|
||||
"总览",
|
||||
"客厅",
|
||||
"厨房",
|
||||
"卧室",
|
||||
"影音室",
|
||||
"游戏房"
|
||||
)
|
||||
// 房间列表 - 使用外部传入,支持动态增删改
|
||||
val roomNavItems = rooms
|
||||
|
||||
// 导航项列表
|
||||
val navItems = listOf(
|
||||
|
||||
@ -485,6 +485,7 @@ fun SettingsContent(
|
||||
onRenameRoom: (Int, String) -> Unit = { _, _ -> }
|
||||
) {
|
||||
var showEditRoomsDialog by remember { mutableStateOf(false) }
|
||||
var showAddRoomDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -517,7 +518,18 @@ fun SettingsContent(
|
||||
onDismiss = { showEditRoomsDialog = false },
|
||||
onRenameRoom = onRenameRoom,
|
||||
onDeleteRoom = onDeleteRoom,
|
||||
onAddRoom = { /* 添加房间通过对话框内的按钮处理 */ }
|
||||
onAddRoom = { showAddRoomDialog = true }
|
||||
)
|
||||
}
|
||||
|
||||
// 添加房间对话框
|
||||
if (showAddRoomDialog) {
|
||||
AddRoomDialog(
|
||||
onDismiss = { showAddRoomDialog = false },
|
||||
onConfirm = { roomName ->
|
||||
onAddRoom(roomName)
|
||||
showAddRoomDialog = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
9
app/src/main/res/drawable/ic_add.xml
Normal file
9
app/src/main/res/drawable/ic_add.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
BIN
app/src/main/res/drawable/taozhi_icon_v3.png
Normal file
BIN
app/src/main/res/drawable/taozhi_icon_v3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 392 KiB |
Loading…
Reference in New Issue
Block a user