RS: catch BT not on while scanning

This commit is contained in:
Milos Kozak 2020-11-18 11:26:45 +01:00
parent 351d4ea4df
commit a04b674a48

View file

@ -15,9 +15,9 @@ import android.widget.BaseAdapter
import android.widget.TextView import android.widget.TextView
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.R
import info.nightscout.androidaps.danars.events.EventDanaRSDeviceChange
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck import info.nightscout.androidaps.plugins.pump.common.ble.BlePreCheck
import info.nightscout.androidaps.danars.events.EventDanaRSDeviceChange
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import kotlinx.android.synthetic.main.danars_blescanner_activity.* import kotlinx.android.synthetic.main.danars_blescanner_activity.*
import java.util.* import java.util.*
@ -63,13 +63,17 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
stopScan() stopScan()
} }
private fun startScan() { private fun startScan() =
if (bluetoothLeScanner != null) bluetoothLeScanner!!.startScan(mBleScanCallback) try {
} bluetoothLeScanner?.startScan(mBleScanCallback)
} catch (e: IllegalStateException) {
} // ignore BT not on
private fun stopScan() { private fun stopScan() =
if (bluetoothLeScanner != null) bluetoothLeScanner!!.stopScan(mBleScanCallback) try {
} bluetoothLeScanner?.stopScan(mBleScanCallback)
} catch (e: IllegalStateException) {
} // ignore BT not on
private fun addBleDevice(device: BluetoothDevice?) { private fun addBleDevice(device: BluetoothDevice?) {
if (device == null || device.name == null || device.name == "") { if (device == null || device.name == null || device.name == "") {
@ -90,6 +94,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
} }
internal inner class ListAdapter : BaseAdapter() { internal inner class ListAdapter : BaseAdapter() {
override fun getCount(): Int = devices.size override fun getCount(): Int = devices.size
override fun getItem(i: Int): BluetoothDeviceItem = devices[i] override fun getItem(i: Int): BluetoothDeviceItem = devices[i]
override fun getItemId(i: Int): Long = 0 override fun getItemId(i: Int): Long = 0
@ -111,6 +116,7 @@ class BLEScanActivity : NoSplashAppCompatActivity() {
} }
private inner class ViewHolder internal constructor(v: View) : View.OnClickListener { private inner class ViewHolder internal constructor(v: View) : View.OnClickListener {
private lateinit var item: BluetoothDeviceItem private lateinit var item: BluetoothDeviceItem
private val name: TextView = v.findViewById(R.id.ble_name) private val name: TextView = v.findViewById(R.id.ble_name)
private val address: TextView = v.findViewById(R.id.ble_address) private val address: TextView = v.findViewById(R.id.ble_address)