kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
clean up companion device pairing
rodzic
b95dcbb26e
commit
45ce83db99
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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,14 +864,17 @@ 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")
|
|
||||||
Toast.makeText(
|
var warningReason = getString(R.string.location_disabled)
|
||||||
c,
|
if (!hasCompanionDeviceApi)
|
||||||
getString(R.string.location_disabled_warning),
|
warningReason = getString(R.string.location_disabled_warning)
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
Toast.makeText(
|
||||||
}
|
requireContext(),
|
||||||
|
warningReason,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
locationSettingsResponse.addOnSuccessListener {
|
locationSettingsResponse.addOnSuccessListener {
|
||||||
|
@ -947,10 +945,11 @@ 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()
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue