mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor: Display scanning indicator during Bluetooth scan (#2321)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
58546a9d3d
commit
859387b331
4 changed files with 25 additions and 7 deletions
|
|
@ -23,7 +23,6 @@ import android.bluetooth.BluetoothDevice
|
|||
import android.content.Context
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.RemoteException
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
|
@ -306,8 +305,8 @@ class BTScanModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private val _spinner = MutableLiveData(false)
|
||||
val spinner: LiveData<Boolean> get() = _spinner
|
||||
private val _spinner = MutableStateFlow(false)
|
||||
val spinner: StateFlow<Boolean> get() = _spinner.asStateFlow()
|
||||
}
|
||||
|
||||
const val NO_DEVICE_SELECTED = "n"
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ fun ConnectionsScreen(
|
|||
val scanStatusText by scanModel.errorText.observeAsState("")
|
||||
val connectionState by uiViewModel.connectionState.collectAsState(MeshService.ConnectionState.DISCONNECTED)
|
||||
val devices by scanModel.devices.observeAsState(emptyMap())
|
||||
val scanning by scanModel.spinner.observeAsState(false)
|
||||
val scanning by scanModel.spinner.collectAsStateWithLifecycle(false)
|
||||
val receivingLocationUpdates by uiViewModel.receivingLocationUpdates.collectAsState(false)
|
||||
val context = LocalContext.current
|
||||
val app = (context.applicationContext as GeeksvilleApplication)
|
||||
|
|
|
|||
|
|
@ -28,16 +28,19 @@ import androidx.compose.material.icons.Icons
|
|||
import androidx.compose.material.icons.filled.Bluetooth
|
||||
import androidx.compose.material.icons.filled.BluetoothDisabled
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.getBluetoothPermissions
|
||||
import com.geeksville.mesh.model.BTScanModel
|
||||
|
|
@ -52,6 +55,7 @@ fun BLEDevices(
|
|||
scanModel: BTScanModel
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val isScanning by scanModel.spinner.collectAsStateWithLifecycle(false)
|
||||
Row {
|
||||
Text(
|
||||
text = stringResource(R.string.bluetooth),
|
||||
|
|
@ -69,6 +73,22 @@ fun BLEDevices(
|
|||
scanModel.onSelected(device)
|
||||
}
|
||||
}
|
||||
} else if (isScanning) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp),
|
||||
horizontalAlignment = CenterHorizontally
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(96.dp)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.scanning),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
|
|
@ -89,6 +109,7 @@ fun BLEDevices(
|
|||
}
|
||||
}
|
||||
Button(
|
||||
enabled = !isScanning,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
val bluetoothPermissions = context.getBluetoothPermissions()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue