From e2f63e015c51f13a09622549f61c511a2b0b2111 Mon Sep 17 00:00:00 2001 From: andrekir Date: Sun, 21 May 2023 06:08:34 -0300 Subject: [PATCH] fix: reindex node list when local node isn't first (index 0) --- .../main/java/com/geeksville/mesh/ui/UsersFragment.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt index e382609d..fefe1995 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt @@ -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.perhapsReindexBy(nodeNum: Int?): Array = + 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 ->