diff --git a/app/src/main/java/com/apkupdater/ui/component/Settings.kt b/app/src/main/java/com/apkupdater/ui/component/Settings.kt index 375a1c09..4b010604 100644 --- a/app/src/main/java/com/apkupdater/ui/component/Settings.kt +++ b/app/src/main/java/com/apkupdater/ui/component/Settings.kt @@ -1,6 +1,7 @@ package com.apkupdater.ui.component import androidx.annotation.DrawableRes +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -9,11 +10,13 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExposedDropdownMenuBox import androidx.compose.material3.ExposedDropdownMenuDefaults import androidx.compose.material3.Icon +import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.SegmentedButton import androidx.compose.material3.SegmentedButtonDefaults @@ -34,8 +37,12 @@ import androidx.compose.ui.Alignment.Companion.CenterStart import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Alignment.Companion.Start import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.platform.LocalTextInputService import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.apkupdater.R @@ -138,7 +145,8 @@ fun DropDownSetting( options: List, getValue: () -> Int, setValue: (Int) -> Unit, - @DrawableRes icon: Int + @DrawableRes icon: Int, + width: Int = 100 ) = Box(Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp, bottom = 8.dp).fillMaxWidth()) { var expanded by remember { mutableStateOf(false) } var selectedOptionText by remember { mutableStateOf(options[getValue()]) } @@ -154,16 +162,14 @@ fun DropDownSetting( ExposedDropdownMenuBox( expanded = expanded, onExpandedChange = { expanded = !expanded }, - modifier = Modifier - .align(CenterEnd) - .width(150.dp) + modifier = Modifier.align(CenterEnd).width(width.dp) ) { CompositionLocalProvider(LocalTextInputService provides null) { // Disable Keyboard OutlinedTextField( readOnly = true, value = selectedOptionText, onValueChange = { setValue(options.indexOf(it)) }, - modifier = Modifier.menuAnchor(), + modifier = Modifier.menuAnchor().clickable { expanded = !expanded }, trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) }, colors = ExposedDropdownMenuDefaults.textFieldColors() ) @@ -185,3 +191,51 @@ fun DropDownSetting( } } } + +@Suppress("unused") +@Composable +fun TextFieldSetting( + text: String, + valueRange: IntRange = 0..23, + getValue: () -> Int, + setValue: (Int) -> Unit, + @DrawableRes icon: Int +) = Box(Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp, bottom = 8.dp).fillMaxWidth()) { + + var value by remember { mutableStateOf(getValue().toString()) } + + Row(Modifier.align(CenterStart)) { + Icon( + painterResource(id = icon), + text, + Modifier.align(CenterVertically).padding(end = 16.dp).size(24.dp) + ) + Text(text, Modifier.align(CenterVertically)) + } + OutlinedTextField( + modifier = Modifier + .align(CenterEnd) + .width(100.dp) + .onFocusChanged { if (!it.hasFocus && value == "") value = getValue().toString() }, + value = value, + singleLine = true, + maxLines = 1, + textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.End), + onValueChange = { + var new = it.toIntOrNull() + if (new != null) { + if (new < valueRange.first) { + new = valueRange.first + } else if (new > valueRange.last) { + new = valueRange.last + } + value = new.toString() + setValue(new) + } else { + value = "" + } + }, + keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done), + ) + +} diff --git a/app/src/main/java/com/apkupdater/ui/screen/SettingsScreen.kt b/app/src/main/java/com/apkupdater/ui/screen/SettingsScreen.kt index 39b9086f..b2c2988b 100644 --- a/app/src/main/java/com/apkupdater/ui/screen/SettingsScreen.kt +++ b/app/src/main/java/com/apkupdater/ui/screen/SettingsScreen.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.UriHandler import androidx.compose.ui.res.painterResource @@ -40,6 +41,7 @@ import com.apkupdater.BuildConfig import com.apkupdater.R import com.apkupdater.data.ui.GitHubSource import com.apkupdater.data.ui.SettingsUiState +import com.apkupdater.ui.component.DropDownSetting import com.apkupdater.ui.component.LargeTitle import com.apkupdater.ui.component.LoadingImageApp import com.apkupdater.ui.component.MediumText @@ -49,6 +51,7 @@ import com.apkupdater.ui.component.SliderSetting import com.apkupdater.ui.component.SourceIcon import com.apkupdater.ui.component.SwitchSetting import com.apkupdater.ui.theme.statusBarColor +import com.apkupdater.util.isAndroidTv import com.apkupdater.viewmodel.SettingsViewModel import org.koin.androidx.compose.koinViewModel @@ -256,14 +259,24 @@ fun Settings(viewModel: SettingsViewModel) = LazyColumn { text = stringResource(R.string.settings_alarm), icon = R.drawable.ic_alarm ) - SliderSetting( - getValue = { viewModel.getAlarmHour().toFloat() }, - setValue = { viewModel.setAlarmHour(it.toInt()) }, - text = stringResource(R.string.settings_hour), - valueRange = 0f..23f, - steps = 23, - R.drawable.ic_hour - ) + if (LocalContext.current.isAndroidTv()) { + DropDownSetting( + text = stringResource(R.string.settings_hour), + options = (0..23).map { it.toString() }, + getValue = { viewModel.getAlarmHour() }, + setValue = { viewModel.setAlarmHour(it) }, + icon = R.drawable.ic_hour + ) + } else { + SliderSetting( + getValue = { viewModel.getAlarmHour().toFloat() }, + setValue = { viewModel.setAlarmHour(it.toInt()) }, + text = stringResource(R.string.settings_hour), + valueRange = 0f..23f, + steps = 23, + R.drawable.ic_hour + ) + } SegmentedButtonSetting( stringResource(R.string.frequency), listOf( diff --git a/app/src/main/res/drawable/ic_alpha.xml b/app/src/main/res/drawable/ic_alpha.xml index 425326fe..84c2476e 100644 --- a/app/src/main/res/drawable/ic_alpha.xml +++ b/app/src/main/res/drawable/ic_alpha.xml @@ -1,4 +1,10 @@ - - + + diff --git a/app/src/main/res/drawable/ic_beta.xml b/app/src/main/res/drawable/ic_beta.xml index b8194d94..379646b7 100644 --- a/app/src/main/res/drawable/ic_beta.xml +++ b/app/src/main/res/drawable/ic_beta.xml @@ -1,4 +1,10 @@ - - + +