clean up companion device pairing

pull/341/head
andrekir 2022-01-09 00:25:40 -03:00
rodzic b95dcbb26e
commit 45ce83db99
2 zmienionych plików z 21 dodań i 25 usunięć

Wyświetl plik

@ -289,9 +289,6 @@ class MainActivity : AppCompatActivity(), Logging,
return getMissingPermissions(perms) return getMissingPermissions(perms)
} }
/** Ask the user to grant camera permission */
fun requestBTScanPermission() = requestPermission(getCameraPermissions(), false)
/** Ask the user to grant camera permission */ /** Ask the user to grant camera permission */
fun requestCameraPermission() = requestPermission(getCameraPermissions(), false) fun requestCameraPermission() = requestPermission(getCameraPermissions(), false)

Wyświetl plik

@ -236,7 +236,6 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
* returns true if we could start scanning, false otherwise * returns true if we could start scanning, false otherwise
*/ */
fun setupScan(): Boolean { fun setupScan(): Boolean {
debug("BTScan component active")
selectedAddress = RadioInterfaceService.getDeviceAddress(context) selectedAddress = RadioInterfaceService.getDeviceAddress(context)
return if (bluetoothAdapter == null || MockInterface.addressValid(context, "")) { return if (bluetoothAdapter == null || MockInterface.addressValid(context, "")) {
@ -678,12 +677,12 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
} }
.show() .show()
if (view.isChecked) if (view.isChecked) {
model.provideLocation.value = isChecked model.provideLocation.value = isChecked
model.meshService?.setupProvideLocation() model.meshService?.setupProvideLocation()
} }
} }
else { } else {
model.provideLocation.value = isChecked model.provideLocation.value = isChecked
model.meshService?.stopProvideLocation() model.meshService?.stopProvideLocation()
} }
@ -725,10 +724,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
device.address == scanModel.selectedNotNull && device.bonded // Only show checkbox if device is still paired device.address == scanModel.selectedNotNull && device.bonded // Only show checkbox if device is still paired
binding.deviceRadioGroup.addView(b) binding.deviceRadioGroup.addView(b)
// Once we have at least one device, don't show the "looking for" animation - it makes users think
// something is busted
binding.scanProgressBar.visibility = View.INVISIBLE
b.setOnClickListener { b.setOnClickListener {
if (!device.bonded) // If user just clicked on us, try to bond if (!device.bonded) // If user just clicked on us, try to bond
binding.scanStatusText.setText(R.string.starting_pairing) binding.scanStatusText.setText(R.string.starting_pairing)
@ -794,7 +789,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (curRadio != null && !MockInterface.addressValid(requireContext(), "")) { if (curRadio != null && !MockInterface.addressValid(requireContext(), "")) {
binding.warningNotPaired.visibility = View.GONE binding.warningNotPaired.visibility = View.GONE
binding.scanStatusText.text = getString(R.string.current_pair).format(curRadio) // binding.scanStatusText.text = getString(R.string.current_pair).format(curRadio)
} else { } else {
binding.warningNotPaired.visibility = View.VISIBLE binding.warningNotPaired.visibility = View.VISIBLE
binding.scanStatusText.text = getString(R.string.not_paired_yet) binding.scanStatusText.text = getString(R.string.not_paired_yet)
@ -851,11 +846,11 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
// If the user has not turned on location access throw up a toast warning // If the user has not turned on location access throw up a toast warning
private fun checkLocationEnabled() { private fun checkLocationEnabled() {
fun hasGps(): Boolean = val hasGps: Boolean =
myActivity.packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) myActivity.packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)
// FIXME If they don't have google play for now we don't check for location enabled // FIXME If they don't have google play for now we don't check for location enabled
if (hasGps() && isGooglePlayAvailable(requireContext())) { if (hasGps && isGooglePlayAvailable(requireContext())) {
// We do this painful process because LocationManager.isEnabled is only SDK28 or latet // We do this painful process because LocationManager.isEnabled is only SDK28 or latet
val builder = LocationSettingsRequest.Builder() val builder = LocationSettingsRequest.Builder()
builder.setNeedBle(true) builder.setNeedBle(true)
@ -869,15 +864,18 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
.checkLocationSettings(builder.build()) .checkLocationSettings(builder.build())
fun weNeedAccess() { fun weNeedAccess() {
context?.let { c -> warn("Telling user we need need location access")
warn("Telling user we need need location accesss")
var warningReason = getString(R.string.location_disabled)
if (!hasCompanionDeviceApi)
warningReason = getString(R.string.location_disabled_warning)
Toast.makeText( Toast.makeText(
c, requireContext(),
getString(R.string.location_disabled_warning), warningReason,
Toast.LENGTH_SHORT Toast.LENGTH_LONG
).show() ).show()
} }
}
locationSettingsResponse.addOnSuccessListener { locationSettingsResponse.addOnSuccessListener {
if (!it.locationSettingsStates.isBleUsable || !it.locationSettingsStates.isLocationUsable) if (!it.locationSettingsStates.isBleUsable || !it.locationSettingsStates.isLocationUsable)
@ -947,11 +945,12 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
).show() ).show()
} else { } else {
if (!hasCompanionDeviceApi) { if (!hasCompanionDeviceApi) {
if (!myActivity.warnMissingPermissions()) { if (!myActivity.warnMissingPermissions())
checkLocationEnabled()
} else
if (binding.provideLocationCheckbox.isChecked)
checkLocationEnabled() checkLocationEnabled()
} }
} }
} }
} }
}
}