map analytics optional

This commit is contained in:
geeksville
2020-04-11 13:20:30 -07:00
parent 838e61a97a
commit 042e8d6ebb
9 changed files with 826 additions and 34 deletions

View File

@@ -23,6 +23,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.geeksville.android.GeeksvilleApplication
import com.geeksville.android.Logging
import com.geeksville.android.ServiceClient
import com.geeksville.mesh.model.Channel
@@ -262,15 +263,18 @@ class MainActivity : AppCompatActivity(), Logging,
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val prefs = UIViewModel.getPreferences(this)
model.ownerName.value = prefs.getString("owner", "")!!
val isInTestLab = (application as GeeksvilleApplication).isInTestLab
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
if (bluetoothAdapter != null) {
if (bluetoothAdapter != null && !isInTestLab) {
bluetoothAdapter!!.takeIf { !it.isEnabled }?.apply {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
@@ -284,8 +288,8 @@ class MainActivity : AppCompatActivity(), Logging,
.show()
}
requestPermission()
if (isInTestLab)
requestPermission() // permissions don't work there
/* not yet working
// Configure sign-in to request the user's ID, email address, and basic

View File

@@ -16,11 +16,11 @@ class MeshUtilApplication : GeeksvilleApplication() {
Logging.showLogs = BuildConfig.DEBUG
// We default to off in the manifest, FIXME turn on only if user approves
// We default to off in the manifest - we turn on here if the user approves
// leave off when running in the debugger
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
val crashlytics = FirebaseCrashlytics.getInstance()
crashlytics.setCrashlyticsCollectionEnabled(true)
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
crashlytics.setCustomKey("debug_build", BuildConfig.DEBUG)
// Attach to our exception wrapper
@@ -29,7 +29,6 @@ class MeshUtilApplication : GeeksvilleApplication() {
}
}
// Mapbox Access token
Mapbox.getInstance(this, getString(R.string.mapbox_access_token))
}
}

View File

@@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.geeksville.android.GeeksvilleApplication
import com.geeksville.android.Logging
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.R
@@ -116,64 +117,80 @@ class MapFragment : ScreenFragment("Map"), Logging {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.map_view, container, false)
): View? {
// We can't allow mapbox if user doesn't want analytics
val id =
if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
// Mapbox Access token
R.layout.map_view
} else {
R.layout.map_not_allowed
}
lateinit var mapView: MapView
return inflater.inflate(id, container, false)
}
var mapView: MapView? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mapView = view.findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
// We might not have a real mapview if running with analytics
if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) {
val v = view.findViewById<MapView>(R.id.mapView)
mapView = v
v.onCreate(savedInstanceState)
mapView.getMapAsync { map ->
v.getMapAsync { map ->
// val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24)
val markerIcon = requireActivity().getDrawable(R.drawable.ic_twotone_person_pin_24)!!
// val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24)
val markerIcon =
requireActivity().getDrawable(R.drawable.ic_twotone_person_pin_24)!!
map.setStyle(Style.OUTDOORS) { style ->
style.addSource(nodePositions)
style.addImage(markerImageId, markerIcon)
style.addLayer(nodeLayer)
style.addLayer(labelLayer)
map.setStyle(Style.OUTDOORS) { style ->
style.addSource(nodePositions)
style.addImage(markerImageId, markerIcon)
style.addLayer(nodeLayer)
style.addLayer(labelLayer)
}
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
onNodesChanged(map, nodes.values)
})
//map.uiSettings.isScrollGesturesEnabled = true
//map.uiSettings.isZoomGesturesEnabled = true
}
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
onNodesChanged(map, nodes.values)
})
//map.uiSettings.isScrollGesturesEnabled = true
//map.uiSettings.isZoomGesturesEnabled = true
}
}
override fun onPause() {
mapView.onPause()
mapView?.onPause()
super.onPause()
}
override fun onStart() {
super.onStart()
mapView.onStart()
mapView?.onStart()
}
override fun onStop() {
mapView.onStop()
mapView?.onStop()
super.onStop()
}
override fun onResume() {
super.onResume()
mapView.onResume()
mapView?.onResume()
}
override fun onDestroy() {
mapView.onDestroy()
mapView?.onDestroy()
super.onDestroy()
}
override fun onSaveInstanceState(outState: Bundle) {
mapView.onSaveInstanceState(outState)
mapView?.onSaveInstanceState(outState)
super.onSaveInstanceState(outState)
}
}

View File

@@ -259,9 +259,13 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
requireActivity().hideKeyboard()
}
// Set analytics checkbox
analyticsOkayCheckbox.isChecked =
(requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed
analyticsOkayCheckbox.setOnCheckedChangeListener { _, isChecked ->
// FIXME, preserve this in settings
analyticsOkayCheckbox.isChecked = true // so users will complain and I'll fix the bug
debug("User changed analytics to $isChecked")
(requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed =
isChecked
}
scanModel.errorText.observe(viewLifecycleOwner, Observer { errMsg ->