kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: replace Activity with Context parameter
rodzic
7c9e15f35e
commit
113ccfcc26
|
@ -1,7 +1,6 @@
|
||||||
package com.geeksville.mesh.model
|
package com.geeksville.mesh.model
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.le.*
|
import android.bluetooth.le.*
|
||||||
|
@ -228,7 +227,7 @@ class BTScanModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private var networkDiscovery: Job? = null
|
private var networkDiscovery: Job? = null
|
||||||
fun startScan(activity: Activity?) {
|
fun startScan(context: Context?) {
|
||||||
_spinner.value = true
|
_spinner.value = true
|
||||||
|
|
||||||
// Start Network Service Discovery (find TCP devices)
|
// Start Network Service Discovery (find TCP devices)
|
||||||
|
@ -236,7 +235,7 @@ class BTScanModel @Inject constructor(
|
||||||
.onEach { addDevice(TCPDeviceListEntry(it)) }
|
.onEach { addDevice(TCPDeviceListEntry(it)) }
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
|
|
||||||
if (activity != null) startCompanionScan(activity) else startClassicScan()
|
if (context != null) startCompanionScan(context) else startClassicScan()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
|
@ -315,9 +314,9 @@ class BTScanModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun startCompanionScan(activity: Activity) {
|
private fun startCompanionScan(context: Context) {
|
||||||
debug("starting companion scan")
|
debug("starting companion scan")
|
||||||
activity.companionDeviceManager?.associate(
|
context.companionDeviceManager?.associate(
|
||||||
associationRequest(),
|
associationRequest(),
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
object : CompanionDeviceManager.Callback() {
|
object : CompanionDeviceManager.Callback() {
|
||||||
|
|
Ładowanie…
Reference in New Issue