warn repeatedly about missing permissions

1.2-legacy
Kevin Hester 2021-05-10 08:09:42 +08:00
rodzic 0c7dac8cb2
commit b14061e6cc
4 zmienionych plików z 41 dodań i 39 usunięć

Wyświetl plik

@ -1,22 +1,6 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings> </JetCodeStyleSettings>
<codeStyleSettings language="PROTO"> <codeStyleSettings language="PROTO">

Wyświetl plik

@ -291,8 +291,10 @@ class MainActivity : AppCompatActivity(), Logging,
/** /**
* Remind user he's disabled permissions we need * Remind user he's disabled permissions we need
*
* @return true if we did warn
*/ */
private fun warnMissingPermissions() { fun warnMissingPermissions(): Boolean {
// Older versions of android don't know about these permissions - ignore failure to grant // Older versions of android don't know about these permissions - ignore failure to grant
val ignoredPermissions = setOf( val ignoredPermissions = setOf(
Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION,
@ -304,10 +306,12 @@ class MainActivity : AppCompatActivity(), Logging,
!ignoredPermissions.contains(name) !ignoredPermissions.contains(name)
} }
if (deniedPermissions.isNotEmpty()) { return if (deniedPermissions.isNotEmpty()) {
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}") errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
showToast(R.string.permission_missing) showToast(R.string.permission_missing)
} true
} else
false
} }
override fun onRequestPermissionsResult( override fun onRequestPermissionsResult(
@ -1133,7 +1137,8 @@ class MainActivity : AppCompatActivity(), Logging,
val styles = arrayOf( val styles = arrayOf(
getString(R.string.theme_light), getString(R.string.theme_light),
getString(R.string.theme_dark), getString(R.string.theme_dark),
getString(R.string.theme_system)) getString(R.string.theme_system)
)
/// Load preferences and its value /// Load preferences and its value
val prefs = UIViewModel.getPreferences(this) val prefs = UIViewModel.getPreferences(this)

Wyświetl plik

@ -889,8 +889,22 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity()) val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity())
.checkLocationSettings(builder.build()) .checkLocationSettings(builder.build())
fun weNeedAccess() {
context?.let { c ->
warn("Telling user we need need location accesss")
Toast.makeText(
c,
getString(R.string.location_disabled_warning),
Toast.LENGTH_SHORT
).show()
}
}
locationSettingsResponse.addOnSuccessListener { locationSettingsResponse.addOnSuccessListener {
debug("We have location access") if(!it.locationSettingsStates.isBleUsable || !it.locationSettingsStates.isLocationUsable)
weNeedAccess()
else
debug("We have location access")
} }
locationSettingsResponse.addOnFailureListener { _ -> locationSettingsResponse.addOnFailureListener { _ ->
@ -910,13 +924,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
// For now just punt and show a dialog // 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 // The context might be gone (if activity is going away) by the time this handler is called
context?.let { c -> weNeedAccess()
Toast.makeText(
c,
getString(R.string.location_disabled_warning),
Toast.LENGTH_SHORT
).show()
}
//} else //} else
// Exceptions.report(exception) // Exceptions.report(exception)
@ -945,20 +953,25 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (!hasCompanionDeviceApi) if (!hasCompanionDeviceApi)
scanModel.startScan() scanModel.startScan()
requireActivity().registerReceiver(updateProgressReceiver, updateProgressFilter) val activity = requireActivity() as MainActivity
activity.registerReceiver(updateProgressReceiver, updateProgressFilter)
// Keep reminding user BLE is still off // Keep reminding user BLE is still off
val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true
if (!hasUSB) { if (!hasUSB) {
// Warn user if BLE is disabled // First warn about permissions, and then if needed warn abotu settings
if (scanModel.bluetoothAdapter?.isEnabled != true) { if(!activity.warnMissingPermissions()) {
Toast.makeText( // Warn user if BLE is disabled
requireContext(), if (scanModel.bluetoothAdapter?.isEnabled != true) {
R.string.error_bluetooth, Toast.makeText(
Toast.LENGTH_SHORT requireContext(),
).show() R.string.error_bluetooth,
} else { Toast.LENGTH_SHORT
checkLocationEnabled() ).show()
} else {
checkLocationEnabled()
}
} }
} }
} }

@ -1 +1 @@
Subproject commit 0c080d8f65d69986559f187e667d98a28329ce7f Subproject commit 16385ae6b102be20103fc310fd5e5ad5b178ea7a