refactor: remove RadioInterfaceService from MainActivity

master
andrekir 2023-05-24 06:43:58 -03:00
rodzic d01e8e8e74
commit 956db658e9
2 zmienionych plików z 7 dodań i 7 usunięć

Wyświetl plik

@ -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()
}

Wyświetl plik

@ -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<List<MeshLog>>(emptyList())
val meshLog: StateFlow<List<MeshLog>> = _meshLog