Fix log screen search input and always show toolbar actions

- Fix search TextField cursor issue by immediately updating searchQuery
  in uiState, keeping debounce only for log filtering
- Always show toolbar buttons regardless of log list empty state
This commit is contained in:
世界
2025-12-24 16:29:57 +08:00
parent 456d35d969
commit 0376ceb9d9
2 changed files with 4 additions and 9 deletions

View File

@@ -525,13 +525,10 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
}
}
// Show actions only for Log screen and when logs are not empty
if (currentScreen == Screen.Log && logViewModel != null) {
val logUiState by logViewModel.uiState.collectAsState()
// Only show toolbar actions if logs are not empty and not in selection mode
if (logUiState.logs.isNotEmpty() && !logUiState.isSelectionMode) {
// Pause/Resume button
if (!logUiState.isSelectionMode) {
IconButton(onClick = { logViewModel.togglePause() }) {
Icon(
imageVector =
@@ -551,7 +548,6 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
)
}
// Search button
IconButton(onClick = { logViewModel.toggleSearch() }) {
Icon(
imageVector =
@@ -577,7 +573,6 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
)
}
// Options menu button
IconButton(onClick = { logViewModel.toggleOptionsMenu() }) {
Icon(
imageVector = Icons.Default.MoreVert,
@@ -585,7 +580,7 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
tint = MaterialTheme.colorScheme.onSurface,
)
}
} // End of logs.isNotEmpty() check
}
}
},
colors = TopAppBarDefaults.topAppBarColors(),

View File

@@ -83,8 +83,7 @@ class LogViewModel : ViewModel(), CommandClient.Handler {
_searchQueryInternal
.debounce(300)
.distinctUntilChanged()
.collect { query ->
_uiState.update { it.copy(searchQuery = query) }
.collect { _ ->
updateDisplayedLogs()
}
}
@@ -201,6 +200,7 @@ class LogViewModel : ViewModel(), CommandClient.Handler {
}
fun updateSearchQuery(query: String) {
_uiState.update { it.copy(searchQuery = query) }
_searchQueryInternal.value = query
}