mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: implement repository pattern for NodeDB (#835)
- enforce Unidirectional Data Flow removing nodeDB updates via `MainActivity`/`UIState` - merge `MyNodeInfoDao` into `NodeInfoDao` - move node list re-indexing to database
This commit is contained in:
parent
3f0dfb7690
commit
c8f93db00d
10 changed files with 170 additions and 147 deletions
|
|
@ -320,16 +320,8 @@ 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.asLiveData().observe(viewLifecycleOwner) {
|
||||
nodesAdapter.onNodesChanged(it.perhapsReindexBy(model.myNodeNum))
|
||||
model.nodeDB.nodeDBbyNum.asLiveData().observe(viewLifecycleOwner) {
|
||||
nodesAdapter.onNodesChanged(it.values.toTypedArray())
|
||||
}
|
||||
|
||||
model.localConfig.asLiveData().observe(viewLifecycleOwner) { config ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue