ViewModels with lifecycle integration, new Device class, code reformat

This commit is contained in:
2023-12-30 22:49:47 +07:00
parent 7436599ad3
commit d7f3bf386d
29 changed files with 743 additions and 490 deletions
@@ -0,0 +1,44 @@
package com.helible.pilot.receivers
import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.location.LocationManager
import android.os.Build
class BluetoothAdapterStateReceiver(
private val onBluetoothEnabledChanged: (isBluetoothEnabled: Boolean) -> Unit,
private val onDiscoveryRunningChanged: (isDiscoveryRunning: Boolean) -> Unit,
private val onLocationEnabledChanged: () -> Unit,
) : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
when (intent?.action) {
BluetoothAdapter.ACTION_STATE_CHANGED -> {
when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)) {
BluetoothAdapter.STATE_ON -> {
onBluetoothEnabledChanged(true)
}
BluetoothAdapter.STATE_OFF -> {
onBluetoothEnabledChanged(false)
}
}
}
LocationManager.PROVIDERS_CHANGED_ACTION -> {
onLocationEnabledChanged()
}
BluetoothAdapter.ACTION_DISCOVERY_FINISHED -> {
onDiscoveryRunningChanged(false)
}
BluetoothAdapter.ACTION_DISCOVERY_STARTED -> {
onDiscoveryRunningChanged(true)
}
}
}
}