sforkowany z mirror/meshtastic-android
refactor: remove RadioInterfaceService from MainActivity
rodzic
d01e8e8e74
commit
956db658e9
|
@ -38,7 +38,6 @@ import com.geeksville.mesh.model.ChannelSet
|
||||||
import com.geeksville.mesh.model.DeviceVersion
|
import com.geeksville.mesh.model.DeviceVersion
|
||||||
import com.geeksville.mesh.model.UIViewModel
|
import com.geeksville.mesh.model.UIViewModel
|
||||||
import com.geeksville.mesh.repository.radio.BluetoothInterface
|
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.repository.radio.SerialInterface
|
||||||
import com.geeksville.mesh.service.*
|
import com.geeksville.mesh.service.*
|
||||||
import com.geeksville.mesh.ui.*
|
import com.geeksville.mesh.ui.*
|
||||||
|
@ -55,7 +54,6 @@ import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
UI design
|
UI design
|
||||||
|
@ -118,9 +116,6 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
private val scanModel: BTScanModel by viewModels()
|
private val scanModel: BTScanModel by viewModels()
|
||||||
val model: UIViewModel by viewModels()
|
val model: UIViewModel by viewModels()
|
||||||
|
|
||||||
@Inject
|
|
||||||
internal lateinit var radioInterfaceService: RadioInterfaceService
|
|
||||||
|
|
||||||
private val requestPermissionsLauncher =
|
private val requestPermissionsLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
||||||
if (!permissions.entries.all { it.value }) {
|
if (!permissions.entries.all { it.value }) {
|
||||||
|
@ -664,7 +659,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
bluetoothViewModel.enabled.observe(this) { enabled ->
|
bluetoothViewModel.enabled.observe(this) { enabled ->
|
||||||
if (!enabled && !requestedEnable && scanModel.selectedBluetooth) {
|
if (!enabled && !requestedEnable && model.selectedBluetooth) {
|
||||||
requestedEnable = true
|
requestedEnable = true
|
||||||
if (hasBluetoothPermission()) {
|
if (hasBluetoothPermission()) {
|
||||||
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
||||||
|
@ -701,7 +696,7 @@ class MainActivity : AppCompatActivity(), Logging {
|
||||||
errormsg("Bind of MeshService failed")
|
errormsg("Bind of MeshService failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
val bonded = radioInterfaceService.getBondedDeviceAddress() != null
|
val bonded = model.bondedAddress != null
|
||||||
if (!bonded && usbDevice == null) // we will handle USB later
|
if (!bonded && usbDevice == null) // we will handle USB later
|
||||||
showSettingsPage()
|
showSettingsPage()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.geeksville.mesh.LocalOnlyProtos.LocalModuleConfig
|
||||||
import com.geeksville.mesh.MeshProtos.User
|
import com.geeksville.mesh.MeshProtos.User
|
||||||
import com.geeksville.mesh.database.PacketRepository
|
import com.geeksville.mesh.database.PacketRepository
|
||||||
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
||||||
|
import com.geeksville.mesh.repository.radio.RadioInterfaceService
|
||||||
import com.geeksville.mesh.service.MeshService
|
import com.geeksville.mesh.service.MeshService
|
||||||
import com.geeksville.mesh.util.GPSFormat
|
import com.geeksville.mesh.util.GPSFormat
|
||||||
import com.geeksville.mesh.util.positionToMeter
|
import com.geeksville.mesh.util.positionToMeter
|
||||||
|
@ -86,6 +87,7 @@ fun getInitials(nameIn: String): String {
|
||||||
class UIViewModel @Inject constructor(
|
class UIViewModel @Inject constructor(
|
||||||
private val app: Application,
|
private val app: Application,
|
||||||
private val radioConfigRepository: RadioConfigRepository,
|
private val radioConfigRepository: RadioConfigRepository,
|
||||||
|
private val radioInterfaceService: RadioInterfaceService,
|
||||||
private val meshLogRepository: MeshLogRepository,
|
private val meshLogRepository: MeshLogRepository,
|
||||||
private val packetRepository: PacketRepository,
|
private val packetRepository: PacketRepository,
|
||||||
private val quickChatActionRepository: QuickChatActionRepository,
|
private val quickChatActionRepository: QuickChatActionRepository,
|
||||||
|
@ -96,6 +98,9 @@ class UIViewModel @Inject constructor(
|
||||||
var meshService: IMeshService? = null
|
var meshService: IMeshService? = null
|
||||||
val nodeDB = NodeDB(this)
|
val nodeDB = NodeDB(this)
|
||||||
|
|
||||||
|
val bondedAddress get() = radioInterfaceService.getBondedDeviceAddress()
|
||||||
|
val selectedBluetooth: Boolean get() = bondedAddress?.getOrNull(0) == 'x'
|
||||||
|
|
||||||
private val _meshLog = MutableStateFlow<List<MeshLog>>(emptyList())
|
private val _meshLog = MutableStateFlow<List<MeshLog>>(emptyList())
|
||||||
val meshLog: StateFlow<List<MeshLog>> = _meshLog
|
val meshLog: StateFlow<List<MeshLog>> = _meshLog
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue