fix(ui): use TopAppBar with icon badge for updates to prevent online count shift
This commit is contained in:
@@ -27,7 +27,7 @@ import androidx.compose.material.icons.filled.Add
|
|||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material.icons.filled.SystemUpdate
|
import androidx.compose.material.icons.filled.SystemUpdate
|
||||||
import androidx.compose.material.icons.filled.Terminal
|
import androidx.compose.material.icons.filled.Terminal
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@@ -239,33 +239,37 @@ fun MainScreen(
|
|||||||
modifier = modifier.fillMaxSize(),
|
modifier = modifier.fillMaxSize(),
|
||||||
containerColor = BgBase,
|
containerColor = BgBase,
|
||||||
topBar = {
|
topBar = {
|
||||||
CenterAlignedTopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.padding(start = 2.dp)
|
||||||
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Terminal,
|
Icons.Default.Terminal,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = GreenVibrant,
|
tint = GreenVibrant,
|
||||||
modifier = Modifier.size(18.dp)
|
modifier = Modifier.size(18.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "DEVICE TRIGGER",
|
text = "DEVICE TRIGGER",
|
||||||
fontSize = 14.sp,
|
fontSize = 13.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
letterSpacing = 2.sp,
|
letterSpacing = 1.5.sp,
|
||||||
color = TextPrimary,
|
color = TextPrimary,
|
||||||
fontFamily = FontFamily.Monospace
|
fontFamily = FontFamily.Monospace,
|
||||||
|
maxLines = 1
|
||||||
)
|
)
|
||||||
val onlineCount = devices.count { nodeStatuses[it.id]?.isOnline == true }
|
val onlineCount = devices.count { nodeStatuses[it.id]?.isOnline == true }
|
||||||
if (devices.isNotEmpty() && onlineCount > 0) {
|
if (devices.isNotEmpty() && onlineCount > 0) {
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(OnlineBg)
|
.background(OnlineBg)
|
||||||
.border(1.dp, OnlineBorder, CircleShape)
|
.border(1.dp, OnlineBorder, CircleShape)
|
||||||
.padding(horizontal = 8.dp, vertical = 2.dp)
|
.padding(horizontal = 7.dp, vertical = 2.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"$onlineCount online",
|
"$onlineCount online",
|
||||||
@@ -280,27 +284,31 @@ fun MainScreen(
|
|||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (availableUpdate != null) {
|
if (availableUpdate != null) {
|
||||||
Row(
|
IconButton(
|
||||||
modifier = Modifier
|
onClick = { showUpdateDialog = true },
|
||||||
.clip(RoundedCornerShape(8.dp))
|
modifier = Modifier.size(40.dp)
|
||||||
.background(GreenVibrant.copy(alpha = 0.15f))
|
|
||||||
.border(1.dp, GreenVibrant.copy(alpha = 0.4f), RoundedCornerShape(8.dp))
|
|
||||||
.clickable { showUpdateDialog = true }
|
|
||||||
.padding(horizontal = 8.dp, vertical = 5.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
Icon(Icons.Default.SystemUpdate, null, tint = GreenVibrant, modifier = Modifier.size(13.dp))
|
Box(contentAlignment = Alignment.TopEnd) {
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
Icon(
|
||||||
Text(
|
Icons.Default.SystemUpdate,
|
||||||
"v${availableUpdate!!.versionName}",
|
contentDescription = "Update available",
|
||||||
color = GreenVibrant,
|
tint = GreenVibrant,
|
||||||
fontSize = 11.sp,
|
modifier = Modifier.size(20.dp)
|
||||||
fontWeight = FontWeight.Bold
|
)
|
||||||
)
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(7.dp)
|
||||||
|
.background(GreenVibrant, CircleShape)
|
||||||
|
.border(1.dp, BgSurface, CircleShape)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
}
|
}
|
||||||
IconButton(onClick = { syncEndpoints(true) }, enabled = !isSyncing) {
|
IconButton(
|
||||||
|
onClick = { syncEndpoints(true) },
|
||||||
|
enabled = !isSyncing,
|
||||||
|
modifier = Modifier.size(40.dp)
|
||||||
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Refresh,
|
Icons.Default.Refresh,
|
||||||
"Sync",
|
"Sync",
|
||||||
@@ -309,12 +317,13 @@ fun MainScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { coroutineScope.launch { pagerState.animateScrollToPage(devices.size) } }
|
onClick = { coroutineScope.launch { pagerState.animateScrollToPage(devices.size) } },
|
||||||
|
modifier = Modifier.size(40.dp)
|
||||||
) {
|
) {
|
||||||
Icon(Icons.Default.Add, "Add Device", tint = GreenVibrant)
|
Icon(Icons.Default.Add, "Add Device", tint = GreenVibrant)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
containerColor = BgSurface
|
containerColor = BgSurface
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user