Feature: Filter node list (#920)

* Filter node list with text field against shortname and longname

* Show filter hint

* Reference "this" node from model instead of list position
This commit is contained in:
Davis 2024-03-31 13:39:35 -06:00 committed by GitHub
parent 5c6aadb5fd
commit 675c6a6b22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 180 additions and 19 deletions

View file

@ -141,6 +141,18 @@ class UIViewModel @Inject constructor(
private val _focusedNode = MutableStateFlow<NodeInfo?>(null)
val focusedNode: StateFlow<NodeInfo?> = _focusedNode
private val _nodeFilterText = MutableStateFlow("")
val nodeFilterText: StateFlow<String> = _nodeFilterText
val filteredNodes = nodeDB.nodeDBbyNum.combine(_nodeFilterText) { nodes, filterText ->
if (filterText.isBlank()) return@combine nodes
nodes.filter { entry ->
entry.value.user?.longName?.contains(filterText, ignoreCase = true) == true ||
entry.value.user?.shortName?.contains(filterText, ignoreCase = true) == true
}
}
// hardware info about our local device (can be null)
val myNodeInfo: StateFlow<MyNodeInfo?> get() = nodeDB.myNodeInfo
val ourNodeInfo: StateFlow<NodeInfo?> get() = nodeDB.ourNodeInfo
@ -615,4 +627,9 @@ class UIViewModel @Inject constructor(
_currentTab.value = 1
_focusedNode.value = node
}
fun setNodeFilterText(text: String) {
_nodeFilterText.value = text
}
}