Compare commits
3 Commits
7a5f3df4c2
...
3d3f8710f2
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d3f8710f2 | |||
| 645f8e2f04 | |||
| 60f146afbc |
@ -32,24 +32,20 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.tvcontroller.R
|
||||
import com.example.tvcontroller.Settings
|
||||
import com.example.tvcontroller.ui.views.SettingsViewModel
|
||||
import com.example.tvcontroller.ui.views.SettingsViewModel.Companion.CONNECT_CONTROLLER_VIEW
|
||||
import com.example.tvcontroller.ui.views.SettingsViewModel.Companion.MAIN_SETTINGS_VIEW
|
||||
import com.example.tvcontroller.services.BluetoothService
|
||||
import com.example.tvcontroller.services.ControllerService
|
||||
import com.example.tvcontroller.services.DeviceService
|
||||
import com.example.tvcontroller.webrtc.RtcPeerConnection
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsView(
|
||||
deviceService: DeviceService,
|
||||
bluetoothService: BluetoothService,
|
||||
rtcPeerConnection: RtcPeerConnection
|
||||
bluetoothService: BluetoothService
|
||||
) {
|
||||
val viewModel = viewModel<SettingsViewModel>(
|
||||
factory = SettingsViewModel.provideFactory(
|
||||
deviceService, bluetoothService, rtcPeerConnection
|
||||
deviceService, bluetoothService
|
||||
)
|
||||
)
|
||||
val navController = rememberNavController()
|
||||
@ -121,13 +117,6 @@ fun SettingsView(
|
||||
stringResource(id = R.string.connect_button_label)
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = { viewModel.connectRtcPeerConnection() },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = "Connect RTC Peer")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,14 +12,12 @@ import com.example.tvcontroller.Settings
|
||||
import com.example.tvcontroller.data.BluetoothDevice
|
||||
import com.example.tvcontroller.services.BluetoothService
|
||||
import com.example.tvcontroller.services.DeviceService
|
||||
import com.example.tvcontroller.webrtc.RtcPeerConnection
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SettingsViewModel(
|
||||
private val deviceService: DeviceService,
|
||||
private val bluetoothService: BluetoothService,
|
||||
private val rtcPeerConnection: RtcPeerConnection
|
||||
private val bluetoothService: BluetoothService
|
||||
) : ViewModel() {
|
||||
var serverAddress by mutableStateOf(deviceService.getServerAddress())
|
||||
private set
|
||||
@ -58,12 +56,6 @@ class SettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun connectRtcPeerConnection() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
rtcPeerConnection.connect()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateConnectionState() {
|
||||
Log.i("SettingsViewModel", "Device token: ${deviceService.getToken()}")
|
||||
connectionState = if (deviceService.getToken().isEmpty()) {
|
||||
@ -113,12 +105,11 @@ class SettingsViewModel(
|
||||
|
||||
fun provideFactory(
|
||||
deviceService: DeviceService,
|
||||
bluetoothService: BluetoothService,
|
||||
rtcPeerConnection: RtcPeerConnection
|
||||
bluetoothService: BluetoothService
|
||||
) = object : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return SettingsViewModel(deviceService, bluetoothService, rtcPeerConnection) as T
|
||||
return SettingsViewModel(deviceService, bluetoothService) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user