kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
rodzic
1d0bc12798
commit
23c748ddc2
|
@ -18,6 +18,8 @@ import com.geeksville.android.Logging
|
||||||
import com.geeksville.mesh.NodeInfo
|
import com.geeksville.mesh.NodeInfo
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.databinding.ActivityOfflineBinding
|
import com.geeksville.mesh.databinding.ActivityOfflineBinding
|
||||||
|
import com.geeksville.mesh.databinding.MapNotAllowedBinding
|
||||||
|
import com.geeksville.mesh.databinding.MapViewBinding
|
||||||
import com.geeksville.mesh.model.UIViewModel
|
import com.geeksville.mesh.model.UIViewModel
|
||||||
import com.geeksville.util.formatAgo
|
import com.geeksville.util.formatAgo
|
||||||
import com.mapbox.bindgen.Value
|
import com.mapbox.bindgen.Value
|
||||||
|
@ -28,6 +30,7 @@ import com.mapbox.geojson.Geometry
|
||||||
import com.mapbox.geojson.Point
|
import com.mapbox.geojson.Point
|
||||||
import com.mapbox.maps.*
|
import com.mapbox.maps.*
|
||||||
import com.mapbox.maps.dsl.cameraOptions
|
import com.mapbox.maps.dsl.cameraOptions
|
||||||
|
import com.mapbox.maps.extension.style.expressions.dsl.generated.id
|
||||||
import com.mapbox.maps.extension.style.expressions.generated.Expression
|
import com.mapbox.maps.extension.style.expressions.generated.Expression
|
||||||
import com.mapbox.maps.extension.style.layers.addLayer
|
import com.mapbox.maps.extension.style.layers.addLayer
|
||||||
import com.mapbox.maps.extension.style.layers.generated.SymbolLayer
|
import com.mapbox.maps.extension.style.layers.generated.SymbolLayer
|
||||||
|
@ -69,7 +72,9 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var handler: Handler
|
private lateinit var handler: Handler
|
||||||
private lateinit var binding: ActivityOfflineBinding
|
private lateinit var binding: MapViewBinding
|
||||||
|
private lateinit var mapNotAllowedBinding: MapNotAllowedBinding
|
||||||
|
private lateinit var viewAnnotationManager: ViewAnnotationManager
|
||||||
|
|
||||||
private lateinit var point: Geometry
|
private lateinit var point: Geometry
|
||||||
|
|
||||||
|
@ -88,7 +93,6 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
private val userTouchLayerId = "user-touch-layer"
|
private val userTouchLayerId = "user-touch-layer"
|
||||||
private var nodePositions = GeoJsonSource(GeoJsonSource.Builder(nodeSourceId))
|
private var nodePositions = GeoJsonSource(GeoJsonSource.Builder(nodeSourceId))
|
||||||
|
|
||||||
private lateinit var viewAnnotationManager: ViewAnnotationManager
|
|
||||||
|
|
||||||
private val userTouchPosition = GeoJsonSource(GeoJsonSource.Builder(userTouchPositionId))
|
private val userTouchPosition = GeoJsonSource(GeoJsonSource.Builder(userTouchPositionId))
|
||||||
|
|
||||||
|
@ -179,42 +183,21 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
// We can't allow mapbox if user doesn't want analytics
|
// We can't allow mapbox if user doesn't want analytics
|
||||||
val id =
|
return if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
|
||||||
if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
|
// Mapbox Access token
|
||||||
// Mapbox Access token
|
binding = MapViewBinding.inflate(inflater, container, false)
|
||||||
R.layout.map_view
|
binding.root
|
||||||
} else {
|
} else {
|
||||||
R.layout.map_not_allowed
|
mapNotAllowedBinding = MapNotAllowedBinding.inflate(inflater, container, false)
|
||||||
}
|
mapNotAllowedBinding.root
|
||||||
|
}
|
||||||
return inflater.inflate(id, container, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapView: MapView? = null
|
var mapView: MapView? = null
|
||||||
|
|
||||||
|
|
||||||
private fun prepareRemoveOfflineRegionButton() {
|
|
||||||
downloadButton("REMOVE DOWNLOADED REGIONS") {
|
|
||||||
removeOfflineRegions()
|
|
||||||
showDownloadedRegions()
|
|
||||||
binding.container.removeAllViews()
|
|
||||||
|
|
||||||
// Re-enable the Mapbox network stack, so that the new offline region download can succeed.
|
|
||||||
OfflineSwitch.getInstance().isMapboxStackConnected = true
|
|
||||||
debug("Mapbox network stack enabled.")
|
|
||||||
|
|
||||||
prepareDownloadButton()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun prepareDownloadButton() {
|
|
||||||
downloadButton("DOWNLOAD") {
|
|
||||||
downloadOfflineRegion()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun showDownloadedRegions() {
|
private fun showDownloadedRegions() {
|
||||||
// Get a list of tile regions that are currently available.
|
// Get a list of tile regions that are currently available.
|
||||||
|
@ -266,12 +249,6 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun downloadButton(text: String, listener: View.OnClickListener) {
|
|
||||||
binding.button.text = text
|
|
||||||
binding.button.setOnClickListener(listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapbox native code can crash painfully if you ever call a mapbox view function while the view is not actively being show
|
* Mapbox native code can crash painfully if you ever call a mapbox view function while the view is not actively being show
|
||||||
*/
|
*/
|
||||||
|
@ -281,6 +258,9 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
override fun onViewCreated(viewIn: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(viewIn: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(viewIn, savedInstanceState)
|
super.onViewCreated(viewIn, savedInstanceState)
|
||||||
|
|
||||||
|
binding.fabStyleToggle.setOnClickListener {
|
||||||
|
downloadOfflineRegion()
|
||||||
|
}
|
||||||
// We might not have a real mapview if running with analytics
|
// We might not have a real mapview if running with analytics
|
||||||
if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
|
if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
|
||||||
val vIn = viewIn.findViewById<MapView>(R.id.mapView)
|
val vIn = viewIn.findViewById<MapView>(R.id.mapView)
|
||||||
|
@ -426,11 +406,11 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||||
// Tile pack download finishes successfully
|
// Tile pack download finishes successfully
|
||||||
expected.value?.let { region ->
|
expected.value?.let { region ->
|
||||||
// logSuccessMessage("TileRegion downloaded: $region")
|
// logSuccessMessage("TileRegion downloaded: $region")
|
||||||
if (binding.stylePackDownloadProgress.progress == binding.stylePackDownloadProgress.max) {
|
// if (binding.stylePackDownloadProgress.progress == binding.stylePackDownloadProgress.max) {
|
||||||
// prepareViewMapButton()
|
// prepareViewMapButton()
|
||||||
} else {
|
// } else {
|
||||||
// logInfoMessage("Waiting for style pack download to be finished.")
|
// logInfoMessage("Waiting for style pack download to be finished.")
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expected.error?.let {
|
expected.error?.let {
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.mapbox.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.mapbox.maps.MapView xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:id="@+id/mapView"
|
android:id="@+id/mapView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
mapbox:mapbox_cameraZoom="0" />
|
mapbox:mapbox_cameraZoom="0" />
|
||||||
|
|
||||||
<!-- <com.google.android.material.floatingactionbutton.FloatingActionButton-->
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
<!-- android:id="@+id/fab_style_toggle"-->
|
android:id="@+id/fab_style_toggle"
|
||||||
<!-- android:layout_width="wrap_content"-->
|
android:layout_width="wrap_content"
|
||||||
<!-- android:layout_height="wrap_content"-->
|
android:layout_height="wrap_content"
|
||||||
<!-- android:layout_margin="16dp"-->
|
android:layout_margin="16dp"
|
||||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
<!-- tools:backgroundTint="@color/colorPrimary" />-->
|
tools:backgroundTint="@color/colorPrimary"
|
||||||
|
android:contentDescription="DownloadButton" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Ładowanie…
Reference in New Issue