Add hide show keyboard function. Fix keyboard too big on small screens. Improve colors.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -67,10 +67,20 @@ class MainActivity : BaseActivity() {
|
|||||||
fun MyScaffoldLayout(
|
fun MyScaffoldLayout(
|
||||||
drawerState: DrawerState,
|
drawerState: DrawerState,
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
navController: NavHostController
|
navController: NavHostController,
|
||||||
|
showFab: Boolean,
|
||||||
|
fabAction: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
floatingActionButton = {
|
||||||
|
if (showFab) {
|
||||||
|
FloatingActionButton(
|
||||||
|
onClick = { fabAction() }) {
|
||||||
|
Icon(Icons.Outlined.Keyboard, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
topBar = {
|
topBar = {
|
||||||
TopBar(
|
TopBar(
|
||||||
mainViewModel.topBarTitle,
|
mainViewModel.topBarTitle,
|
||||||
@@ -238,9 +248,15 @@ class MainActivity : BaseActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
content = { MyScaffoldLayout(drawerState, scope, navController) }
|
) {
|
||||||
)
|
MyScaffoldLayout(
|
||||||
|
drawerState,
|
||||||
|
scope,
|
||||||
|
navController,
|
||||||
|
counterViewModel.keyboardHidden
|
||||||
|
) { counterViewModel.keyboardHidden = false }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Screen(val route: String, val icon: ImageVector, @StringRes val resourceId: Int)
|
private class Screen(val route: String, val icon: ImageVector, @StringRes val resourceId: Int)
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ fun Landscape(viewModel: ICounterViewModel) {
|
|||||||
{ viewModel.digitClicked(it) },
|
{ viewModel.digitClicked(it) },
|
||||||
{ viewModel.addSub100Clicked(it) },
|
{ viewModel.addSub100Clicked(it) },
|
||||||
{ viewModel.deleteClicked() },
|
{ viewModel.deleteClicked() },
|
||||||
{ viewModel.negateClicked() }
|
{ viewModel.negateClicked() },
|
||||||
) { viewModel.submitClicked() }
|
{ viewModel.submitClicked() },
|
||||||
|
{ viewModel.keyboardHidden = true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -89,6 +89,7 @@ fun Portrait(viewModel: ICounterViewModel) {
|
|||||||
Modifier.weight(1f)
|
Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!viewModel.keyboardHidden) {
|
||||||
KeyboardView(
|
KeyboardView(
|
||||||
viewModel.currentScoreA,
|
viewModel.currentScoreA,
|
||||||
viewModel.currentScoreB,
|
viewModel.currentScoreB,
|
||||||
@@ -99,8 +100,10 @@ fun Portrait(viewModel: ICounterViewModel) {
|
|||||||
{ viewModel.digitClicked(it) },
|
{ viewModel.digitClicked(it) },
|
||||||
{ viewModel.addSub100Clicked(it) },
|
{ viewModel.addSub100Clicked(it) },
|
||||||
{ viewModel.deleteClicked() },
|
{ viewModel.deleteClicked() },
|
||||||
{ viewModel.negateClicked() }
|
{ viewModel.negateClicked() },
|
||||||
) { viewModel.submitClicked() }
|
{ viewModel.submitClicked() },
|
||||||
|
{ viewModel.keyboardHidden = true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +132,7 @@ internal class PreviewViewModel : ICounterViewModel {
|
|||||||
override var requestFocusA: FocusRequester = FocusRequester()
|
override var requestFocusA: FocusRequester = FocusRequester()
|
||||||
override var activeValue: String = currentScoreA
|
override var activeValue: String = currentScoreA
|
||||||
override var inactiveValue: String = currentScoreB
|
override var inactiveValue: String = currentScoreB
|
||||||
|
override var keyboardHidden: Boolean = false
|
||||||
|
|
||||||
override fun giveFocusToAIfNone() {
|
override fun giveFocusToAIfNone() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ interface ICounterViewModel {
|
|||||||
var requestFocusA: FocusRequester
|
var requestFocusA: FocusRequester
|
||||||
var activeValue: String
|
var activeValue: String
|
||||||
var inactiveValue: String
|
var inactiveValue: String
|
||||||
|
var keyboardHidden: Boolean
|
||||||
|
|
||||||
fun giveFocusToAIfNone()
|
fun giveFocusToAIfNone()
|
||||||
fun updateOtherScore()
|
fun updateOtherScore()
|
||||||
@@ -75,6 +76,8 @@ class CounterViewModel @Inject constructor(
|
|||||||
|
|
||||||
override var requestFocusA by mutableStateOf(FocusRequester())
|
override var requestFocusA by mutableStateOf(FocusRequester())
|
||||||
|
|
||||||
|
override var keyboardHidden by mutableStateOf(false)
|
||||||
|
|
||||||
override var activeValue: String
|
override var activeValue: String
|
||||||
get() {
|
get() {
|
||||||
return if (isBFocused) {
|
return if (isBFocused) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.*
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Backspace
|
import androidx.compose.material.icons.outlined.Backspace
|
||||||
import androidx.compose.material.icons.outlined.Check
|
import androidx.compose.material.icons.outlined.Check
|
||||||
|
import androidx.compose.material.icons.outlined.KeyboardHide
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
@@ -13,6 +14,7 @@ import androidx.compose.ui.focus.FocusRequester
|
|||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
@@ -33,7 +35,8 @@ fun KeyboardView(
|
|||||||
addSub100Clicked: (Int) -> Unit,
|
addSub100Clicked: (Int) -> Unit,
|
||||||
deleteClicked: () -> Unit,
|
deleteClicked: () -> Unit,
|
||||||
negateClicked: () -> Unit,
|
negateClicked: () -> Unit,
|
||||||
submitClicked: () -> Unit
|
submitClicked: () -> Unit,
|
||||||
|
hideKeyboardClicked: () -> Unit
|
||||||
) {
|
) {
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
|
||||||
@@ -136,8 +139,8 @@ fun KeyboardView(
|
|||||||
|
|
||||||
Row {
|
Row {
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
KeyboardTextButton("+/-") {
|
KeyboardIconButton(Icons.Outlined.KeyboardHide) {
|
||||||
negateClicked()
|
hideKeyboardClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
@@ -145,7 +148,13 @@ fun KeyboardView(
|
|||||||
digitClicked("0")
|
digitClicked("0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(Modifier.weight(2f)) {
|
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
KeyboardTextButton("+/-") {
|
||||||
|
negateClicked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
KeyboardIconButton(Icons.Outlined.Check, enableSubmit) {
|
KeyboardIconButton(Icons.Outlined.Check, enableSubmit) {
|
||||||
submitClicked()
|
submitClicked()
|
||||||
}
|
}
|
||||||
@@ -156,13 +165,25 @@ fun KeyboardView(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun KeyboardTextButton(text: String, onClicked: () -> Unit) {
|
fun KeyboardTextButton(text: String, onClicked: () -> Unit) {
|
||||||
|
|
||||||
|
val configuration = LocalConfiguration.current
|
||||||
|
|
||||||
|
val screenWidth = configuration.screenWidthDp.dp
|
||||||
|
|
||||||
|
val style = if(screenWidth < 350.dp)
|
||||||
|
{
|
||||||
|
MaterialTheme.typography.labelSmall
|
||||||
|
}else {
|
||||||
|
MaterialTheme.typography.labelLarge
|
||||||
|
}
|
||||||
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(50.dp)
|
.height(50.dp)
|
||||||
.padding(2.dp),
|
.padding(2.dp),
|
||||||
onClick = { onClicked() },
|
onClick = { onClicked() },
|
||||||
) { Text(text) }
|
) { Text(text, style = style) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -225,6 +246,7 @@ fun KeyboardViewPreview() {
|
|||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
|
{},
|
||||||
{})
|
{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -18,13 +19,18 @@ fun TeamNamesView(
|
|||||||
updateA: (String) -> Unit,
|
updateA: (String) -> Unit,
|
||||||
updateB: (String) -> Unit
|
updateB: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val color = TextFieldDefaults.textFieldColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
TextField(
|
TextField(
|
||||||
value = nameA,
|
value = nameA,
|
||||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||||
onValueChange = { updateA(it) },
|
onValueChange = { updateA(it) },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
|
colors = color
|
||||||
)
|
)
|
||||||
|
|
||||||
TextField(
|
TextField(
|
||||||
@@ -32,7 +38,8 @@ fun TeamNamesView(
|
|||||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||||
onValueChange = { updateB(it) },
|
onValueChange = { updateB(it) },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
|
colors = color
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import android.content.res.Configuration
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.ElevatedCard
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
@@ -19,7 +16,7 @@ import me.zobrist.tichucounter.ui.AppTheme
|
|||||||
@Composable
|
@Composable
|
||||||
fun TeamScoresView(scoreA: Int, scoreB: Int) {
|
fun TeamScoresView(scoreA: Int, scoreB: Int) {
|
||||||
|
|
||||||
ElevatedCard {
|
ElevatedCard(elevation = CardDefaults.elevatedCardElevation(3.dp)) {
|
||||||
Row {
|
Row {
|
||||||
Text(
|
Text(
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
|
|||||||
Reference in New Issue
Block a user