feat: enhance MainActivity UI with edge-to-edge support and improved TopAppBar layout in HistoryScreen
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "org.noxylva.lbjconsole"
|
applicationId = "org.noxylva.lbjconsole"
|
||||||
minSdk = 29
|
minSdk = 29
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 3
|
versionCode = 4
|
||||||
versionName = "0.0.3"
|
versionName = "0.0.4"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import androidx.activity.ComponentActivity
|
|||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@@ -27,6 +29,7 @@ import androidx.compose.material.icons.filled.*
|
|||||||
import androidx.compose.material.icons.filled.LocationOn
|
import androidx.compose.material.icons.filled.LocationOn
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -219,6 +222,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
saveSettings()
|
saveSettings()
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
|
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||||
|
isAppearanceLightStatusBars = false
|
||||||
|
}
|
||||||
setContent {
|
setContent {
|
||||||
LBJReceiverTheme {
|
LBJReceiverTheme {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -707,6 +714,7 @@ fun MainContent(
|
|||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
|
Box {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text("LBJ Console") },
|
title = { Text("LBJ Console") },
|
||||||
actions = {
|
actions = {
|
||||||
@@ -738,6 +746,51 @@ fun MainContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (historyEditMode && currentTab == 0) {
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
"已选择 ${historySelectedRecords.size} 条记录",
|
||||||
|
color = MaterialTheme.colorScheme.onPrimary
|
||||||
|
)
|
||||||
|
},
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = {
|
||||||
|
onHistoryStateChange(false, emptySet(), historyExpandedStates, historyScrollPosition, historyScrollOffset)
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Close,
|
||||||
|
contentDescription = "取消",
|
||||||
|
tint = MaterialTheme.colorScheme.onPrimary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
IconButton(
|
||||||
|
onClick = {
|
||||||
|
if (historySelectedRecords.isNotEmpty()) {
|
||||||
|
val recordsToDelete = allRecords.filter {
|
||||||
|
historySelectedRecords.contains(it.timestamp.time.toString())
|
||||||
|
}
|
||||||
|
onDeleteRecords(recordsToDelete)
|
||||||
|
onHistoryStateChange(false, emptySet(), historyExpandedStates, historyScrollPosition, historyScrollOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Delete,
|
||||||
|
contentDescription = "删除所选记录",
|
||||||
|
tint = MaterialTheme.colorScheme.onPrimary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
NavigationBar {
|
NavigationBar {
|
||||||
@@ -777,7 +830,6 @@ fun MainContent(
|
|||||||
temporaryStatusMessage = temporaryStatusMessage,
|
temporaryStatusMessage = temporaryStatusMessage,
|
||||||
locoInfoUtil = locoInfoUtil,
|
locoInfoUtil = locoInfoUtil,
|
||||||
onClearRecords = onClearRecords,
|
onClearRecords = onClearRecords,
|
||||||
|
|
||||||
onRecordClick = onRecordClick,
|
onRecordClick = onRecordClick,
|
||||||
onClearLog = onClearMonitorLog,
|
onClearLog = onClearMonitorLog,
|
||||||
onDeleteRecords = onDeleteRecords,
|
onDeleteRecords = onDeleteRecords,
|
||||||
|
|||||||
@@ -95,11 +95,6 @@ fun HistoryScreen(
|
|||||||
records
|
records
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exitEditMode() {
|
|
||||||
isInEditMode = false
|
|
||||||
selectedRecordsList.clear()
|
|
||||||
onStateChange(false, emptySet(), expandedStatesMap.toMap(), listState.firstVisibleItemIndex, listState.firstVisibleItemScrollOffset)
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(isInEditMode, selectedRecordsList.size) {
|
LaunchedEffect(isInEditMode, selectedRecordsList.size) {
|
||||||
val selectedIds = selectedRecordsList.map { it.timestamp.time.toString() }.toSet()
|
val selectedIds = selectedRecordsList.map { it.timestamp.time.toString() }.toSet()
|
||||||
@@ -122,7 +117,8 @@ fun HistoryScreen(
|
|||||||
|
|
||||||
LaunchedEffect(selectedRecordsList.size) {
|
LaunchedEffect(selectedRecordsList.size) {
|
||||||
if (selectedRecordsList.isEmpty() && isInEditMode) {
|
if (selectedRecordsList.isEmpty() && isInEditMode) {
|
||||||
exitEditMode()
|
isInEditMode = false
|
||||||
|
onStateChange(false, emptySet(), expandedStatesMap.toMap(), listState.firstVisibleItemIndex, listState.firstVisibleItemScrollOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,57 +541,4 @@ fun HistoryScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInEditMode) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.TopCenter
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(56.dp)
|
|
||||||
.background(MaterialTheme.colorScheme.primary)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
IconButton(onClick = { exitEditMode() }) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Close,
|
|
||||||
contentDescription = "取消",
|
|
||||||
tint = MaterialTheme.colorScheme.onPrimary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
"已选择 ${selectedRecordsList.size} 条记录",
|
|
||||||
color = MaterialTheme.colorScheme.onPrimary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
if (selectedRecordsList.isNotEmpty()) {
|
|
||||||
onDeleteRecords(selectedRecordsList.toList())
|
|
||||||
exitEditMode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Delete,
|
|
||||||
contentDescription = "删除所选记录",
|
|
||||||
tint = MaterialTheme.colorScheme.onPrimary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user