Autodisconnect from device, when the flight screen remove from the backstack
This commit is contained in:
@@ -241,7 +241,7 @@ class AndroidBluetoothController(private val context: Context) : BluetoothContro
|
||||
if(dataTransferService == null) {
|
||||
return null
|
||||
}
|
||||
dataTransferService?.sendMessage("R1399\n\r".toByteArray())
|
||||
dataTransferService?.sendMessage("R1250\n\r".toByteArray())
|
||||
return message
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.helible.pilot
|
||||
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -84,7 +83,7 @@ class BluetoothViewModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
.catch { throwable ->
|
||||
.catch { _ ->
|
||||
bluetoothController.closeConnection()
|
||||
_state.update {
|
||||
it.copy(
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -162,6 +163,11 @@ class MainActivity : ComponentActivity() {
|
||||
bluetoothViewModel.connectToDevice(device)
|
||||
}
|
||||
}
|
||||
BackHandler {
|
||||
bluetoothViewModel.disconnectFromDevice()
|
||||
Log.i("FlightScreen", "Disconnected from device")
|
||||
navController.navigate("scanner")
|
||||
}
|
||||
when {
|
||||
bluetoothState.isConnecting -> {
|
||||
Column(
|
||||
|
||||
Reference in New Issue
Block a user