mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-12 00:32:26 +01:00
Add Wi-fi check
This commit is contained in:
1 parent
fb0736a3b3
commit
be6ef93dfe
2 files changed
+25
-3
No files matched your search
@@ -9,6 +9,8 @@ import android.provider.Settings
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.content.Context
|
||||
import android.net.wifi.WifiManager
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -57,6 +59,8 @@ internal fun WirelessButton() {
|
||||
val context = LocalContext.current
|
||||
var devices by remember { mutableStateOf<List<BluetoothDevice>?>(null) }
|
||||
var denied by remember { mutableStateOf(false) }
|
||||
var showWifiDialog by remember { mutableStateOf(false) }
|
||||
|
||||
fun granted() = WIRELESS_PERMISSIONS.all {
|
||||
ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
@@ -83,8 +87,13 @@ internal fun WirelessButton() {
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
denied = false
|
||||
if (granted()) devices = WirelessLink.pairedDevices(context) else ask.launch(WIRELESS_PERMISSIONS)
|
||||
val wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
if (!wifiManager.isWifiEnabled) {
|
||||
showWifiDialog = true
|
||||
} else {
|
||||
denied = false
|
||||
if (granted()) devices = WirelessLink.pairedDevices(context) else ask.launch(WIRELESS_PERMISSIONS)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().height(64.dp),
|
||||
) {
|
||||
@@ -154,4 +163,15 @@ internal fun WirelessButton() {
|
||||
confirmButton = { TextButton(onClick = { devices = null }) { Text(stringResource(R.string.cancel)) } },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (showWifiDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showWifiDialog = false },
|
||||
title = { Text(stringResource(R.string.Wifi_off)) },
|
||||
text = { Text(stringResource(R.string.Wifi_not_enabled)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { showWifiDialog = false }) { Text("OK") }
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -393,6 +393,8 @@
|
||||
<string name="wireless_auto_off">Doesn\'t connect on its own</string>
|
||||
<string name="wireless_auto_turn_on">Let it connect on its own</string>
|
||||
<string name="bluetooth_settings">Bluetooth settings</string>
|
||||
<string name="Wifi_not_enabled">Please enable Wi-Fi to connect wirelessly</string>
|
||||
<string name="Wifi_off">Wi-Fi is off</string>
|
||||
|
||||
<!-- Voice models -->
|
||||
<string name="voice_live_title">Voice: live words</string>
|
||||
|
||||
Reference in new issue
Block a user