diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0ff9cf5..58f3d60 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,7 +6,7 @@ plugins { android { namespace = "com.example.tvcontroller" - compileSdk = 34 + compileSdk = 35 defaultConfig { applicationId = "com.example.tvcontroller" @@ -59,6 +59,7 @@ dependencies { implementation(libs.androidx.camera.view) implementation(libs.androidx.camera.mlkit.vision) implementation(libs.androidx.camera.extensions) + implementation(libs.material3) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/app/src/main/java/com/example/tvcontroller/ui/views/SettingsView.kt b/app/src/main/java/com/example/tvcontroller/ui/views/SettingsView.kt index b9ab6be..6d9e589 100644 --- a/app/src/main/java/com/example/tvcontroller/ui/views/SettingsView.kt +++ b/app/src/main/java/com/example/tvcontroller/ui/views/SettingsView.kt @@ -1,24 +1,27 @@ package com.example.tvcontroller.ui.views import android.annotation.SuppressLint -import android.bluetooth.BluetoothDevice -import android.util.Log +import androidx.compose.foundation.clickable 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.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.ListItem import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -30,6 +33,7 @@ import com.example.tvcontroller.services.ControllerService import com.example.tvcontroller.services.DeviceService import kotlinx.coroutines.flow.toList +@OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsView( deviceService: DeviceService, @@ -111,31 +115,53 @@ fun SettingsView( viewModel.startBluetoothScan() val pairedDevices = viewModel.pairedDevices.collectAsState() val scannedDevices = viewModel.scannedDevices.collectAsState() - Column( - modifier = Modifier - .padding(16.dp, 16.dp) - .verticalScroll(rememberScrollState()), - verticalArrangement = Arrangement.spacedBy(8.dp) - ) { - Text( - text = stringResource(id = R.string.connect_controller_title), - style = MaterialTheme.typography.displaySmall + Column { + TopAppBar( + title = { Text(text = stringResource(id = R.string.connect_controller_title)) }, + navigationIcon = { + IconButton(onClick = {}) { + Icon( + painterResource(id = R.drawable.baseline_arrow_back_24), + contentDescription = "Back" + ) + } + }, ) - Spacer(modifier = Modifier.padding(8.dp)) - Text( - text = stringResource(id = R.string.paired_devices_label), - style = MaterialTheme.typography.headlineSmall - ) - pairedDevices.value.forEach { device -> - Text(text = device.getName()) - } - Spacer(modifier = Modifier.padding(8.dp)) - Text( - text = stringResource(id = R.string.scanned_devices_label), - style = MaterialTheme.typography.headlineSmall - ) - scannedDevices.value.forEach { device -> - Text(text = device.getName()) + Column( + modifier = Modifier.verticalScroll(rememberScrollState()), + ) { + Text( + text = stringResource(id = R.string.paired_devices_label), + style = MaterialTheme.typography.headlineSmall, + modifier = Modifier.padding(start = 16.dp) + ) + pairedDevices.value.forEach { device -> + ListItem( + headlineContent = { Text(device.getName()) }, + supportingContent = { + if (device.getName() != device.getAddress()) Text( + device.getAddress() + ) + }, + ) + } + Spacer(modifier = Modifier.padding(8.dp)) + Text( + text = stringResource(id = R.string.scanned_devices_label), + style = MaterialTheme.typography.headlineSmall, + modifier = Modifier.padding(start = 16.dp) + ) + scannedDevices.value.forEach { device -> + if (device != null) ListItem( + headlineContent = { Text(device.getName()) }, + supportingContent = { + if (device.getName() != device.getAddress()) Text( + device.getAddress() + ) + }, + modifier = Modifier.clickable(onClick = {}) + ) + } } } } diff --git a/app/src/main/res/drawable/baseline_arrow_back_24.xml b/app/src/main/res/drawable/baseline_arrow_back_24.xml new file mode 100644 index 0000000..075e95d --- /dev/null +++ b/app/src/main/res/drawable/baseline_arrow_back_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 460bb85..349d121 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ ktor = "3.1.0" lifecycleRuntimeKtx = "2.6.1" activityCompose = "1.8.0" composeBom = "2024.04.01" +material3 = "1.4.0-alpha10" navigationCompose = "2.8.4" [libraries] @@ -37,6 +38,7 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit androidx-material3 = { group = "androidx.compose.material3", name = "material3" } ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } +material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" }