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 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, rtcPeerConnection
|
deviceService, bluetoothService
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
@ -121,13 +117,6 @@ 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,14 +12,12 @@ 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
|
||||||
@ -58,12 +56,6 @@ 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()) {
|
||||||
@ -113,12 +105,11 @@ 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, rtcPeerConnection) as T
|
return SettingsViewModel(deviceService, bluetoothService) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user