mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(debug): add a toggle to AND/OR all filters. (#2265)
This commit is contained in:
parent
ea25a8198a
commit
dd50cf230e
6 changed files with 66 additions and 15 deletions
|
|
@ -108,12 +108,24 @@ internal fun DebugScreen(
|
|||
val filterTexts by viewModel.filterTexts.collectAsStateWithLifecycle()
|
||||
val selectedLogId by viewModel.selectedLogId.collectAsStateWithLifecycle()
|
||||
|
||||
val filteredLogs = remember(logs, filterTexts) {
|
||||
var filterMode by remember { mutableStateOf(FilterMode.OR) }
|
||||
|
||||
val filteredLogs = remember(logs, filterTexts, filterMode) {
|
||||
logs.filter { log ->
|
||||
filterTexts.isEmpty() || filterTexts.any { filterText ->
|
||||
log.logMessage.contains(filterText, ignoreCase = true) ||
|
||||
log.messageType.contains(filterText, ignoreCase = true) ||
|
||||
log.formattedReceivedDate.contains(filterText, ignoreCase = true)
|
||||
if (filterTexts.isEmpty()) {
|
||||
true
|
||||
} else { when (filterMode) {
|
||||
FilterMode.OR -> filterTexts.any { filterText ->
|
||||
log.logMessage.contains(filterText, ignoreCase = true) ||
|
||||
log.messageType.contains(filterText, ignoreCase = true) ||
|
||||
log.formattedReceivedDate.contains(filterText, ignoreCase = true)
|
||||
}
|
||||
FilterMode.AND -> filterTexts.all { filterText ->
|
||||
log.logMessage.contains(filterText, ignoreCase = true) ||
|
||||
log.messageType.contains(filterText, ignoreCase = true) ||
|
||||
log.formattedReceivedDate.contains(filterText, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.toImmutableList()
|
||||
}
|
||||
|
|
@ -136,7 +148,6 @@ internal fun DebugScreen(
|
|||
listState.requestScrollToItem(searchState.allMatches[searchState.currentMatchIndex].logIndex)
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
|
@ -156,9 +167,10 @@ internal fun DebugScreen(
|
|||
searchState = searchState,
|
||||
filterTexts = filterTexts,
|
||||
presetFilters = viewModel.presetFilters,
|
||||
filterMode = filterMode,
|
||||
onFilterModeChange = { filterMode = it }
|
||||
)
|
||||
}
|
||||
|
||||
items(filteredLogs, key = { it.uuid }) { log ->
|
||||
DebugItem(
|
||||
modifier = Modifier.animateItem(),
|
||||
|
|
@ -708,7 +720,6 @@ fun DebugMenuActions(
|
|||
contentDescription = "Clear All"
|
||||
)
|
||||
}
|
||||
|
||||
if (showDeleteLogsDialog) {
|
||||
SimpleAlertDialog(
|
||||
title = R.string.debug_clear,
|
||||
|
|
|
|||
|
|
@ -215,10 +215,13 @@ internal fun DebugFilterBar(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
@Composable
|
||||
internal fun DebugActiveFilters(
|
||||
filterTexts: List<String>,
|
||||
onFilterTextsChange: (List<String>) -> Unit,
|
||||
filterMode: FilterMode,
|
||||
onFilterModeChange: (FilterMode) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
|
|
@ -237,6 +240,20 @@ internal fun DebugActiveFilters(
|
|||
text = stringResource(R.string.debug_active_filters),
|
||||
style = TextStyle(fontWeight = FontWeight.Bold)
|
||||
)
|
||||
TextButton(
|
||||
onClick = {
|
||||
onFilterModeChange(
|
||||
if (filterMode == FilterMode.OR) FilterMode.AND else FilterMode.OR
|
||||
)
|
||||
}
|
||||
) {
|
||||
Text(if (filterMode == FilterMode.OR) {
|
||||
stringResource(R.string.match_any)
|
||||
} else {
|
||||
stringResource(R.string.match_all)
|
||||
}
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
onClick = { onFilterTextsChange(emptyList()) }
|
||||
) {
|
||||
|
|
@ -278,3 +295,5 @@ internal fun DebugActiveFilters(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class FilterMode { OR, AND }
|
||||
|
|
|
|||
|
|
@ -163,6 +163,8 @@ internal fun DebugSearchState(
|
|||
onPreviousMatch: () -> Unit,
|
||||
onClearSearch: () -> Unit,
|
||||
onFilterTextsChange: (List<String>) -> Unit,
|
||||
filterMode: FilterMode,
|
||||
onFilterModeChange: (FilterMode) -> Unit,
|
||||
) {
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
var customFilterText by remember { mutableStateOf("") }
|
||||
|
|
@ -198,7 +200,9 @@ internal fun DebugSearchState(
|
|||
}
|
||||
DebugActiveFilters(
|
||||
filterTexts = filterTexts,
|
||||
onFilterTextsChange = onFilterTextsChange
|
||||
onFilterTextsChange = onFilterTextsChange,
|
||||
filterMode = filterMode,
|
||||
onFilterModeChange = onFilterModeChange
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -209,6 +213,8 @@ fun DebugSearchStateviewModelDefaults(
|
|||
searchState: SearchState,
|
||||
filterTexts: List<String>,
|
||||
presetFilters: List<String>,
|
||||
filterMode: FilterMode,
|
||||
onFilterModeChange: (FilterMode) -> Unit,
|
||||
) {
|
||||
val viewModel: DebugViewModel = hiltViewModel()
|
||||
DebugSearchState(
|
||||
|
|
@ -221,6 +227,8 @@ fun DebugSearchStateviewModelDefaults(
|
|||
onPreviousMatch = viewModel.searchManager::goToPreviousMatch,
|
||||
onClearSearch = viewModel.searchManager::clearSearch,
|
||||
onFilterTextsChange = viewModel.filterManager::setFilterTexts,
|
||||
filterMode = filterMode,
|
||||
onFilterModeChange = onFilterModeChange
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue