From 956db658e90fb058226b774ce812ffb06d6c39e6 Mon Sep 17 00:00:00 2001 From: andrekir Date: Wed, 24 May 2023 06:43:58 -0300 Subject: [PATCH] refactor: remove RadioInterfaceService from MainActivity --- app/src/main/java/com/geeksville/mesh/MainActivity.kt | 9 ++------- app/src/main/java/com/geeksville/mesh/model/UIState.kt | 5 +++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 37a7dc2b..d9c79159 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -38,7 +38,6 @@ import com.geeksville.mesh.model.ChannelSet import com.geeksville.mesh.model.DeviceVersion import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.repository.radio.BluetoothInterface -import com.geeksville.mesh.repository.radio.RadioInterfaceService import com.geeksville.mesh.repository.radio.SerialInterface import com.geeksville.mesh.service.* import com.geeksville.mesh.ui.* @@ -55,7 +54,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.cancel import java.text.DateFormat import java.util.Date -import javax.inject.Inject /* UI design @@ -118,9 +116,6 @@ class MainActivity : AppCompatActivity(), Logging { private val scanModel: BTScanModel by viewModels() val model: UIViewModel by viewModels() - @Inject - internal lateinit var radioInterfaceService: RadioInterfaceService - private val requestPermissionsLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions -> if (!permissions.entries.all { it.value }) { @@ -664,7 +659,7 @@ class MainActivity : AppCompatActivity(), Logging { } bluetoothViewModel.enabled.observe(this) { enabled -> - if (!enabled && !requestedEnable && scanModel.selectedBluetooth) { + if (!enabled && !requestedEnable && model.selectedBluetooth) { requestedEnable = true if (hasBluetoothPermission()) { val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) @@ -701,7 +696,7 @@ class MainActivity : AppCompatActivity(), Logging { errormsg("Bind of MeshService failed") } - val bonded = radioInterfaceService.getBondedDeviceAddress() != null + val bonded = model.bondedAddress != null if (!bonded && usbDevice == null) // we will handle USB later showSettingsPage() } diff --git a/app/src/main/java/com/geeksville/mesh/model/UIState.kt b/app/src/main/java/com/geeksville/mesh/model/UIState.kt index 6bb24106..93628c73 100644 --- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt +++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt @@ -29,6 +29,7 @@ import com.geeksville.mesh.LocalOnlyProtos.LocalModuleConfig import com.geeksville.mesh.MeshProtos.User import com.geeksville.mesh.database.PacketRepository import com.geeksville.mesh.repository.datastore.RadioConfigRepository +import com.geeksville.mesh.repository.radio.RadioInterfaceService import com.geeksville.mesh.service.MeshService import com.geeksville.mesh.util.GPSFormat import com.geeksville.mesh.util.positionToMeter @@ -86,6 +87,7 @@ fun getInitials(nameIn: String): String { class UIViewModel @Inject constructor( private val app: Application, private val radioConfigRepository: RadioConfigRepository, + private val radioInterfaceService: RadioInterfaceService, private val meshLogRepository: MeshLogRepository, private val packetRepository: PacketRepository, private val quickChatActionRepository: QuickChatActionRepository, @@ -96,6 +98,9 @@ class UIViewModel @Inject constructor( var meshService: IMeshService? = null val nodeDB = NodeDB(this) + val bondedAddress get() = radioInterfaceService.getBondedDeviceAddress() + val selectedBluetooth: Boolean get() = bondedAddress?.getOrNull(0) == 'x' + private val _meshLog = MutableStateFlow>(emptyList()) val meshLog: StateFlow> = _meshLog