mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Merge pull request #351 from meshtastic/snackbar
improve Settings notifications
This commit is contained in:
commit
1a7ca03e7d
3 changed files with 36 additions and 36 deletions
|
|
@ -62,6 +62,7 @@ import com.google.android.gms.common.ConnectionResult
|
|||
import com.google.android.gms.common.GoogleApiAvailability
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
import com.vorlonsoft.android.rate.AppRate
|
||||
|
|
@ -399,7 +400,12 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
return if (message != null) {
|
||||
errormsg("Denied permissions: $message")
|
||||
showToast(message)
|
||||
Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_INDEFINITE)
|
||||
.apply { view.findViewById<TextView>(R.id.snackbar_text).isSingleLine = false }
|
||||
.setAction(R.string.okay) {
|
||||
// dismiss
|
||||
}
|
||||
.show()
|
||||
true
|
||||
} else
|
||||
false
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import android.view.inputmethod.EditorInfo
|
|||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.RadioButton
|
||||
import android.widget.Toast
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
|
@ -50,6 +50,7 @@ import com.google.android.gms.location.LocationRequest
|
|||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.location.LocationSettingsRequest
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -654,18 +655,17 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
binding.provideLocationCheckbox.isEnabled = isGooglePlayAvailable(requireContext())
|
||||
binding.provideLocationCheckbox.setOnCheckedChangeListener { view, isChecked ->
|
||||
model.provideLocation.value = isChecked
|
||||
|
||||
if (view.isChecked) {
|
||||
debug("User changed location tracking to $isChecked")
|
||||
if (view.isPressed) { // We want to ignore changes caused by code (as opposed to the user)
|
||||
val hasLocationPermission = myActivity.hasLocationPermission()
|
||||
val hasBackgroundPermission = myActivity.hasBackgroundPermission()
|
||||
|
||||
// Don't check the box until the system setting changes
|
||||
view.isChecked = hasLocationPermission && hasBackgroundPermission
|
||||
view.isChecked = myActivity.hasLocationPermission() && myActivity.hasBackgroundPermission()
|
||||
|
||||
if (!hasLocationPermission) // Make sure we have location permission (prerequisite)
|
||||
if (!myActivity.hasLocationPermission()) // Make sure we have location permission (prerequisite)
|
||||
myActivity.requestLocationPermission()
|
||||
if (hasLocationPermission && !hasBackgroundPermission)
|
||||
else if (!myActivity.hasBackgroundPermission())
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.background_required)
|
||||
.setMessage(R.string.why_background_required)
|
||||
|
|
@ -678,12 +678,11 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
.show()
|
||||
|
||||
if (view.isChecked) {
|
||||
model.provideLocation.value = isChecked
|
||||
checkLocationEnabled(getString(R.string.location_disabled))
|
||||
model.meshService?.setupProvideLocation()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
model.provideLocation.value = isChecked
|
||||
model.meshService?.stopProvideLocation()
|
||||
}
|
||||
}
|
||||
|
|
@ -844,7 +843,9 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
}
|
||||
|
||||
// If the user has not turned on location access throw up a toast warning
|
||||
private fun checkLocationEnabled() {
|
||||
private fun checkLocationEnabled(
|
||||
warningReason: String = getString(R.string.location_disabled_warning)
|
||||
) {
|
||||
|
||||
val hasGps: Boolean =
|
||||
myActivity.packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)
|
||||
|
|
@ -863,23 +864,20 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity())
|
||||
.checkLocationSettings(builder.build())
|
||||
|
||||
fun weNeedAccess() {
|
||||
fun weNeedAccess(warningReason: String) {
|
||||
warn("Telling user we need need location access")
|
||||
|
||||
var warningReason = getString(R.string.location_disabled)
|
||||
if (!hasCompanionDeviceApi)
|
||||
warningReason = getString(R.string.location_disabled_warning)
|
||||
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
warningReason,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
Snackbar.make(binding.changeRadioButton, warningReason, Snackbar.LENGTH_INDEFINITE)
|
||||
.apply { view.findViewById<TextView>(R.id.snackbar_text).isSingleLine = false }
|
||||
.setAction(R.string.okay) {
|
||||
// dismiss
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
locationSettingsResponse.addOnSuccessListener {
|
||||
if (!it.locationSettingsStates?.isBleUsable!! || !it.locationSettingsStates?.isLocationUsable!!)
|
||||
weNeedAccess()
|
||||
weNeedAccess(warningReason)
|
||||
else
|
||||
debug("We have location access")
|
||||
}
|
||||
|
|
@ -901,7 +899,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
// For now just punt and show a dialog
|
||||
|
||||
// The context might be gone (if activity is going away) by the time this handler is called
|
||||
weNeedAccess()
|
||||
weNeedAccess(warningReason)
|
||||
|
||||
//} else
|
||||
// Exceptions.report(exception)
|
||||
|
|
@ -938,18 +936,14 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
if (!hasUSB) {
|
||||
// Warn user if BLE is disabled
|
||||
if (scanModel.bluetoothAdapter?.isEnabled != true) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.error_bluetooth,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Snackbar.make(binding.changeRadioButton, R.string.error_bluetooth, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(R.string.okay) {
|
||||
// dismiss
|
||||
}
|
||||
.show()
|
||||
} else {
|
||||
if (!hasCompanionDeviceApi) {
|
||||
if (!myActivity.warnMissingPermissions())
|
||||
checkLocationEnabled()
|
||||
} else
|
||||
if (binding.provideLocationCheckbox.isChecked)
|
||||
checkLocationEnabled()
|
||||
if (binding.provideLocationCheckbox.isChecked)
|
||||
checkLocationEnabled(getString(R.string.location_disabled))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
<string name="please_pair">Please pair device in Android Settings.</string>
|
||||
<string name="pairing_completed">Pairing completed, starting service</string>
|
||||
<string name="pairing_failed_try_again">Pairing failed, please select again</string>
|
||||
<string name="location_disabled">Location access is disabled, can not provide position to the mesh.</string>
|
||||
<string name="location_disabled">Location access is turned off, can not provide position to mesh.</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="disconnected">Disconnected</string>
|
||||
<string name="device_sleeping">Device sleeping</string>
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
<string name="modem_config_very_long">Long Range / Slow</string>
|
||||
<string name="modem_config_unrecognized">UNRECOGNIZED</string>
|
||||
<string name="meshtastic_service_notifications">Meshtastic Service Notifications</string>
|
||||
<string name="location_disabled_warning">You must turn on (high accuracy) location services in Android Settings</string>
|
||||
<string name="location_disabled_warning">Location must be turned on (high accuracy) to find new devices via bluetooth. You can turn it off again afterwards.</string>
|
||||
<string name="about">About</string>
|
||||
<string name="a_list_of_nodes_in_the_mesh">A list of nodes in the mesh</string>
|
||||
<string name="text_messages">Text messages</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue