mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat/2482 Make decoded payload accessible to filters/search/copies (#2483)
This commit is contained in:
parent
d208314758
commit
c665b5528c
2 changed files with 114 additions and 47 deletions
|
|
@ -48,6 +48,7 @@ import com.geeksville.mesh.TelemetryProtos
|
|||
import com.geeksville.mesh.AdminProtos
|
||||
import com.geeksville.mesh.PaxcountProtos
|
||||
import com.geeksville.mesh.StoreAndForwardProtos
|
||||
import com.geeksville.mesh.ui.debug.FilterMode
|
||||
|
||||
data class SearchMatch(
|
||||
val logIndex: Int,
|
||||
|
|
@ -140,7 +141,11 @@ class LogSearchManager {
|
|||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "type") }
|
||||
val dateMatches = regex.findAll(log.formattedReceivedDate)
|
||||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "date") }
|
||||
messageMatches + typeMatches + dateMatches
|
||||
val decodedPayloadMatches = log.decodedPayload?.let { decoded ->
|
||||
regex.findAll(decoded)
|
||||
.map { match -> SearchMatch(logIndex, match.range.first, match.range.last, "decodedPayload") }
|
||||
} ?: emptySequence()
|
||||
messageMatches + typeMatches + dateMatches + decodedPayloadMatches
|
||||
}
|
||||
}.sortedBy { it.start }
|
||||
}
|
||||
|
|
@ -160,6 +165,30 @@ class LogFilterManager {
|
|||
fun updateFilteredLogs(logs: List<DebugViewModel.UiMeshLog>) {
|
||||
_filteredLogs.value = logs
|
||||
}
|
||||
|
||||
fun filterLogs(
|
||||
logs: List<DebugViewModel.UiMeshLog>,
|
||||
filterTexts: List<String>,
|
||||
filterMode: FilterMode
|
||||
): List<DebugViewModel.UiMeshLog> {
|
||||
if (filterTexts.isEmpty()) return logs
|
||||
return logs.filter { log ->
|
||||
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) ||
|
||||
(log.decodedPayload?.contains(filterText, ignoreCase = true) == true)
|
||||
}
|
||||
FilterMode.AND -> filterTexts.all { filterText ->
|
||||
log.logMessage.contains(filterText, ignoreCase = true) ||
|
||||
log.messageType.contains(filterText, ignoreCase = true) ||
|
||||
log.formattedReceivedDate.contains(filterText, ignoreCase = true) ||
|
||||
(log.decodedPayload?.contains(filterText, ignoreCase = true) == true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val HEX_FORMAT = "%02x"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue