fix: reindex node list when local node isn't first (index 0)

master
andrekir 2023-05-21 06:08:34 -03:00
rodzic 8151aceea4
commit e2f63e015c
1 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -286,8 +286,16 @@ class UsersFragment : ScreenFragment("Users"), Logging {
binding.nodeListView.adapter = nodesAdapter
binding.nodeListView.layoutManager = LinearLayoutManager(requireContext())
// ensure our local node is first (index 0)
fun Map<String, NodeInfo>.perhapsReindexBy(nodeNum: Int?): Array<NodeInfo> =
if (size > 1 && nodeNum != null && values.firstOrNull()?.num != nodeNum) {
values.partition { node -> node.num == nodeNum }.let { it.first + it.second }
} else {
values
}.toTypedArray()
model.nodeDB.nodes.observe(viewLifecycleOwner) {
nodesAdapter.onNodesChanged(it.values.toTypedArray())
nodesAdapter.onNodesChanged(it.perhapsReindexBy(model.myNodeNum))
}
model.packetResponse.asLiveData().observe(viewLifecycleOwner) { meshLog ->