feat: add server settings form in settings view

This commit is contained in:
Fritz Heiden 2025-03-18 20:19:07 +01:00
parent c712cf800d
commit 035393578f
6 changed files with 115 additions and 23 deletions

View File

@ -49,6 +49,9 @@
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
@ -17,7 +18,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.TVController">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -0,0 +1,9 @@
package com.example.tvcontroller
import android.util.Log
object DeviceService {
fun createIntegration(name: String, code: String) {
Log.i("DeviceService", "Creating integration for $name with code $code")
}
}

View File

@ -14,12 +14,13 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
@ -30,6 +31,7 @@ import com.example.tvcontroller.ui.theme.TVControllerTheme
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.tvcontroller.ui.AppViewModel
@ -50,11 +52,6 @@ class MainActivity : ComponentActivity() {
}
}
}
override fun onDestroy() {
super.onDestroy()
bluetoothService.cleanUp()
}
}
@Composable
@ -151,19 +148,3 @@ fun RemoteScreen(modifier: Modifier = Modifier) {
}
}
}
@Composable
fun SettingsScreen(modifier: Modifier = Modifier, appViewModel: AppViewModel = viewModel()) {
Column(
modifier = modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
if (appViewModel.isBluetoothEnabled()) {
Text(text = "Settings Screen", modifier = modifier)
}else{
Text(text = "Bluetooth is disabled. Please enable it in settings.", modifier = modifier)
}
}
}

View File

@ -0,0 +1,89 @@
package com.example.tvcontroller
import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.tvcontroller.ui.AppViewModel
@Composable
fun SettingsScreen(appViewModel: AppViewModel = viewModel()) {
var serverUrl by remember { mutableStateOf("") }
var deviceName by remember { mutableStateOf(android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL) }
var registrationCode by remember { mutableStateOf("") }
fun connect() {
Log.i("SettingsScreen", "Save settings: $serverUrl, $deviceName, $registrationCode")
}
Column(
modifier = Modifier
.padding(16.dp, 16.dp)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = stringResource(id = R.string.settings_title),
style = MaterialTheme.typography.displaySmall
)
Spacer(modifier = Modifier.padding(8.dp))
Text(
text = stringResource(id = R.string.server_settings_heading),
style = MaterialTheme.typography.headlineSmall
)
Text(
text = stringResource(id = R.string.server_connection_label) + ": " + stringResource(id = R.string.connection_state_disconnected),
style = MaterialTheme.typography.bodyMedium
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = serverUrl,
onValueChange = { serverUrl = it },
label = { Text(stringResource(id = R.string.server_url_label)) }
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = deviceName,
onValueChange = { deviceName = it },
label = { Text(stringResource(id = R.string.device_name_label)) }
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = registrationCode,
onValueChange = { registrationCode = it },
label = { Text(stringResource(id = R.string.registration_code_label)) }
)
OutlinedButton(onClick = { connect() }, modifier = Modifier.fillMaxWidth()) {
Text(
stringResource(id = R.string.connect_button_label)
)
}
Spacer(modifier = Modifier.padding(8.dp))
Text(
text = stringResource(id = R.string.controller_settings_heading),
style = MaterialTheme.typography.headlineSmall
)
if (appViewModel.isBluetoothEnabled()) {
Text(text = "Controller settings: Bluetooth is enabled.", style = MaterialTheme.typography.bodyMedium)
} else {
Text(text = "Bluetooth is disabled. Please enable it in settings.", style = MaterialTheme.typography.bodyMedium)
}
}
}

View File

@ -1,3 +1,13 @@
<resources>
<string name="app_name">TV Controller</string>
<string name="settings_title">Settings</string>
<string name="server_url_label">Server URL</string>
<string name="device_name_label">Device name</string>
<string name="registration_code_label">Registration code</string>
<string name="server_settings_heading">Server settings</string>
<string name="controller_settings_heading">Controller settings</string>
<string name="server_connection_label">Connection state</string>
<string name="connection_state_disconnected">disconnected</string>
<string name="save_button_label">Save</string>
<string name="connect_button_label">Connect</string>
</resources>