kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: clean up map onNodesChanged
rodzic
c9bff2b942
commit
334ee86362
|
@ -111,7 +111,7 @@ class MapFragment : ScreenFragment("Map Fragment"), Logging {
|
||||||
Configuration.getInstance().userAgentValue =
|
Configuration.getInstance().userAgentValue =
|
||||||
BuildConfig.APPLICATION_ID // Required to get online tiles
|
BuildConfig.APPLICATION_ID // Required to get online tiles
|
||||||
map = viewIn.findViewById(R.id.map)
|
map = viewIn.findViewById(R.id.map)
|
||||||
mPrefs = context!!.getSharedPreferences(prefsName, Context.MODE_PRIVATE)
|
mPrefs = requireContext().getSharedPreferences(prefsName, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
setupMapProperties()
|
setupMapProperties()
|
||||||
map.setTileSource(loadOnlineTileSourceBase())
|
map.setTileSource(loadOnlineTileSourceBase())
|
||||||
|
@ -241,7 +241,7 @@ class MapFragment : ScreenFragment("Map Fragment"), Logging {
|
||||||
resources.getString(R.string.cancel)
|
resources.getString(R.string.cancel)
|
||||||
)
|
)
|
||||||
) { dialog, _ -> dialog.dismiss() }
|
) { dialog, _ -> dialog.dismiss() }
|
||||||
activity!!.runOnUiThread { // show it
|
requireActivity().runOnUiThread { // show it
|
||||||
// create alert dialog
|
// create alert dialog
|
||||||
val alertDialog = alertDialogBuilder.create()
|
val alertDialog = alertDialogBuilder.create()
|
||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
|
@ -537,38 +537,23 @@ class MapFragment : ScreenFragment("Map Fragment"), Logging {
|
||||||
private fun onNodesChanged(nodes: Collection<NodeInfo>) {
|
private fun onNodesChanged(nodes: Collection<NodeInfo>) {
|
||||||
val nodesWithPosition = nodes.filter { it.validPosition != null }
|
val nodesWithPosition = nodes.filter { it.validPosition != null }
|
||||||
val ic = ContextCompat.getDrawable(requireActivity(), R.drawable.ic_baseline_location_on_24)
|
val ic = ContextCompat.getDrawable(requireActivity(), R.drawable.ic_baseline_location_on_24)
|
||||||
|
debug("Showing on map: ${nodesWithPosition.size} nodes")
|
||||||
/**
|
nodePositions = nodesWithPosition.map { node ->
|
||||||
* Using the latest nodedb, generate GeoPoint
|
val (p, u) = Pair(node.position!!, node.user!!)
|
||||||
*/
|
val marker = MarkerWithLabel(map, "${u.longName} ${formatAgo(p.time)}")
|
||||||
// Find all nodes with valid locations
|
marker.title = "${u.longName} ${node.batteryStr}"
|
||||||
fun getCurrentNodes(): List<MarkerWithLabel> {
|
marker.snippet = model.gpsString(p)
|
||||||
debug("Showing on map: ${nodesWithPosition.size} nodes")
|
model.ourNodeInfo.value?.let { our ->
|
||||||
val mrkr = nodesWithPosition.map { node ->
|
our.distanceStr(node)?.let { dist ->
|
||||||
val p = node.position!!
|
marker.subDescription = getString(R.string.map_subDescription)
|
||||||
lateinit var marker: MarkerWithLabel
|
.format(our.bearing(node), dist)
|
||||||
node.user?.let {
|
|
||||||
val label = it.longName + " " + formatAgo(p.time)
|
|
||||||
marker = MarkerWithLabel(map, label)
|
|
||||||
marker.title = "${it.longName} ${node.batteryStr}"
|
|
||||||
marker.snippet = model.gpsString(p)
|
|
||||||
model.ourNodeInfo.value?.let { our ->
|
|
||||||
our.distanceStr(node)?.let { dist ->
|
|
||||||
marker.subDescription = getString(R.string.map_subDescription).format(
|
|
||||||
our.bearing(node),
|
|
||||||
dist
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
|
||||||
marker.position = GeoPoint(p.latitude, p.longitude)
|
|
||||||
marker.icon = ic
|
|
||||||
}
|
}
|
||||||
marker
|
|
||||||
}
|
}
|
||||||
return mrkr
|
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||||
|
marker.position = GeoPoint(p.latitude, p.longitude)
|
||||||
|
marker.icon = ic
|
||||||
|
marker
|
||||||
}
|
}
|
||||||
nodePositions = getCurrentNodes()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue