simplified calls to system services

and fixed some code that assumed BluetoothManager to never be NULL
This commit is contained in:
Ken Van Hoeylandt 2020-09-17 19:49:50 +02:00
parent b98a8ea34b
commit f97bc21719
4 changed files with 22 additions and 15 deletions

View file

@ -33,6 +33,8 @@ import com.geeksville.android.isGooglePlayAvailable
import com.geeksville.concurrent.handledLaunch
import com.geeksville.mesh.MainActivity
import com.geeksville.mesh.R
import com.geeksville.mesh.android.bluetoothManager
import com.geeksville.mesh.android.usbManager
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.BluetoothInterface
import com.geeksville.mesh.service.MeshService
@ -137,11 +139,8 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
debug("BTScanModel cleared")
}
/// Note: may be null on platforms without a bluetooth driver (ie. the emulator)
val bluetoothAdapter =
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter
private val usbManager = context.getSystemService(Context.USB_SERVICE) as UsbManager
val bluetoothAdapter = context.bluetoothManager?.adapter
private val usbManager get() = context.usbManager
var selectedAddress: String? = null
val errorText = object : MutableLiveData<String?>(null) {}