[#18] Add a swap score button.
Some checks are pending
continuous-integration/drone/push Build is pending

closes #18
This commit is contained in:
2023-01-27 12:36:49 +01:00
parent 4346af3d2b
commit f52bfa64ce
3 changed files with 34 additions and 4 deletions

View File

@@ -63,7 +63,8 @@ fun Landscape(viewModel: ICounterViewModel) {
{ viewModel.deleteClicked() },
{ viewModel.negateClicked() },
{ viewModel.submitClicked() },
{ viewModel.keyboardHidden = true })
{ viewModel.keyboardHidden = true },
{ viewModel.swapInputScores() })
}
}
}
@@ -102,7 +103,8 @@ fun Portrait(viewModel: ICounterViewModel) {
{ viewModel.deleteClicked() },
{ viewModel.negateClicked() },
{ viewModel.submitClicked() },
{ viewModel.keyboardHidden = true })
{ viewModel.keyboardHidden = true },
{ viewModel.swapInputScores() })
}
}
}
@@ -174,4 +176,7 @@ internal class PreviewViewModel : ICounterViewModel {
override fun updateFocusStateB(state: Boolean) {
}
override fun swapInputScores() {
}
}

View File

@@ -43,6 +43,7 @@ interface ICounterViewModel {
fun updateNameB(value: String)
fun updateFocusStateA(state: Boolean)
fun updateFocusStateB(state: Boolean)
fun swapInputScores()
}
@HiltViewModel
@@ -235,4 +236,10 @@ class CounterViewModel @Inject constructor(
override fun updateFocusStateB(state: Boolean) {
isBFocused = state
}
override fun swapInputScores() {
val swap = currentScoreA
currentScoreA = currentScoreB
currentScoreB = swap
}
}

View File

@@ -6,6 +6,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Backspace
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.KeyboardHide
import androidx.compose.material.icons.outlined.SwapHoriz
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
@@ -36,12 +37,14 @@ fun KeyboardView(
deleteClicked: () -> Unit,
negateClicked: () -> Unit,
submitClicked: () -> Unit,
hideKeyboardClicked: () -> Unit
hideKeyboardClicked: () -> Unit,
onSwapClicked: () -> Unit
) {
val keyboardController = LocalSoftwareKeyboardController.current
Column {
Row {
Row(Modifier.height(IntrinsicSize.Max)) {
Column(Modifier.weight(1f)) {
CenteredTextField(
scoreA,
@@ -55,6 +58,19 @@ fun KeyboardView(
)
}
Surface(
Modifier
.wrapContentWidth()
.fillMaxHeight(),
tonalElevation = 3.dp,
shape = MaterialTheme.shapes.extraSmall
) {
Column {
IconButton(onClick = onSwapClicked) {
Icon(Icons.Outlined.SwapHoriz, null)
}
}
}
Column(Modifier.weight(1f)) {
CenteredTextField(
@@ -69,6 +85,7 @@ fun KeyboardView(
}
}
Row {
Column(Modifier.weight(1f)) {
KeyboardTextButton("1") {
@@ -246,6 +263,7 @@ fun KeyboardViewPreview() {
{},
{},
{},
{},
{})
}
}