Better UI layout on the device screen

This commit is contained in:
2024-01-27 23:14:26 +07:00
parent 18bd21fba1
commit 3b62743481
6 changed files with 67 additions and 58 deletions

View File

@@ -14,7 +14,7 @@ import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import com.helible.pilot.BluetoothDataTransferService
import com.helible.pilot.viewmodels.BluetoothDataTransferService
import com.helible.pilot.KMessage
import com.helible.pilot.dataclasses.BluetoothDeviceDomain
import com.helible.pilot.receivers.BluetoothAdapterStateReceiver
@@ -40,7 +40,7 @@ import java.util.UUID
sealed interface ConnectionResult {
object ConnectionEstablished : ConnectionResult
data class TransferSucceded(val message: KMessage) : ConnectionResult
data class TransferSucceded(val message: String) : ConnectionResult
data class Error(val message: String) : ConnectionResult
}
@@ -219,6 +219,7 @@ class AndroidBluetoothController(private val context: Context) : BluetoothContro
return flow {}
}
return flow {
Log.i("BluetoothController", "Connecting to device...")
currentClientSocket =
bluetoothAdapter.getRemoteDevice(device).createRfcommSocketToServiceRecord(
UUID.fromString(SERVICE_UUID)
@@ -235,7 +236,9 @@ class AndroidBluetoothController(private val context: Context) : BluetoothContro
)
}
} catch (e: IOException) {
closeConnection()
socket.close()
currentClientSocket = null
Log.e("BluetoothController", e.toString())
emit(ConnectionResult.Error("Connection was interrupted"))
}
}
@@ -256,6 +259,7 @@ class AndroidBluetoothController(private val context: Context) : BluetoothContro
override fun closeConnection() {
currentClientSocket?.close()
currentClientSocket = null
Log.i("BluetoothController", "Connection closed")
}
override fun onDestroy() {