Continued work on #369: Inject radio interface implementations (#481)

This required creation of new interfaces in order to break the
static coupling.  This also allowed for the removal of some plumbing
of dependencies of these implementations since they are now directly
injected.
This commit is contained in:
Mike Cumings 2023-10-24 12:09:18 -07:00 committed by GitHub
parent 121376201d
commit a7b0d70c03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 370 additions and 220 deletions

View file

@ -38,7 +38,8 @@ import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.model.primaryChannel
import com.geeksville.mesh.model.toChannelSet
import com.geeksville.mesh.repository.radio.BluetoothInterface
import com.geeksville.mesh.repository.radio.SerialInterface
import com.geeksville.mesh.repository.radio.InterfaceId
import com.geeksville.mesh.repository.radio.RadioInterfaceService
import com.geeksville.mesh.service.*
import com.geeksville.mesh.ui.*
import com.geeksville.mesh.ui.map.MapFragment
@ -121,6 +122,9 @@ class MainActivity : AppCompatActivity(), Logging {
@Inject
internal lateinit var serviceRepository: ServiceRepository
@Inject
internal lateinit var radioInterfaceService: RadioInterfaceService
private val bluetoothPermissionsLauncher =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->
if (result.entries.all { it.value }) {
@ -462,9 +466,9 @@ class MainActivity : AppCompatActivity(), Logging {
try {
usbDevice?.let { usb ->
debug("Switching to USB radio ${usb.deviceName}")
service.setDeviceAddress(SerialInterface.toInterfaceName(usb.deviceName))
usbDevice =
null // Only switch once - thereafter it should be stored in settings
val address = radioInterfaceService.toInterfaceAddress(InterfaceId.SERIAL, usb.deviceName)
service.setDeviceAddress(address)
usbDevice = null // Only switch once - thereafter it should be stored in settings
}
val connectionState =