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