mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-11 00:12:24 +01:00
wireless: a car you said no to can be let to connect on its own again, from the car list
This commit is contained in:
1 parent
327d6fd40a
commit
e9d4203d58
19 files changed
+63
No files matched your search
@@ -116,6 +116,21 @@ internal fun WirelessButton() {
|
||||
}
|
||||
.padding(vertical = 14.dp),
|
||||
)
|
||||
// A car the driver once said no to never asks again, so offer the way back here.
|
||||
if (app.seb3thehacker.gearslip.wireless.WirelessAuto.declinedEarlier(context, device)) {
|
||||
Text(
|
||||
stringResource(R.string.wireless_auto_off),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
TextButton(
|
||||
onClick = {
|
||||
devices = null
|
||||
app.seb3thehacker.gearslip.wireless.WirelessAuto.askAgain(context, device)
|
||||
},
|
||||
modifier = Modifier.padding(bottom = 4.dp),
|
||||
) { Text(stringResource(R.string.wireless_auto_turn_on)) }
|
||||
}
|
||||
}
|
||||
// The car has to be paired before it shows up here, and pairing happens in Android's settings.
|
||||
if (list.isNotEmpty()) {
|
||||
|
||||
@@ -72,6 +72,20 @@ object WirelessAuto {
|
||||
}, Handler(Looper.getMainLooper()))
|
||||
}
|
||||
|
||||
/** True when the driver said no to this car connecting by itself, and it still can't. */
|
||||
fun declinedEarlier(context: Context, device: BluetoothDevice): Boolean {
|
||||
val manager = context.getSystemService(CompanionDeviceManager::class.java) ?: return false
|
||||
return !isCompanion(manager, device.address) &&
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getBoolean(device.address, false)
|
||||
}
|
||||
|
||||
/** Forgets the earlier no and shows Android's dialog for [device] again. */
|
||||
fun askAgain(context: Context, device: BluetoothDevice) {
|
||||
log.i("auto-connect: asking again about ${WirelessLink.name(device)}")
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().remove(device.address).apply()
|
||||
connectedByHand(context, device)
|
||||
}
|
||||
|
||||
/** The driver allowed it in Android's dialog. */
|
||||
fun approved(context: Context, address: String) {
|
||||
log.i("auto-connect: allowed")
|
||||
|
||||
Reference in new issue
Block a user