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

View File

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