Skip to content

Commit

Permalink
Implemented things by branch name, also:
Browse files Browse the repository at this point in the history
1) Created setContentDescription modifier that allows to set contentDescription on any used Modifier - as accessibility feature, suppossing that it may help to understand the UI architecture more
  • Loading branch information
b0r1ngx committed Feb 28, 2024
1 parent 35da3a3 commit ecd16ac
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.arkivanov.minesweeper

import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics

fun Modifier.setContentDescription(description: String, role: Role): Modifier =
this.then(
Modifier.semantics {
this.contentDescription = description
this.role = role
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ internal inline fun <T> T.runUnless(condition: Boolean, block: T.() -> T): T =
} else {
block()
}

internal fun CharSequence.countValuebleChars(): Int = count { it in "0123456789-" }
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.arkivanov.decompose.value.MutableValue
import com.arkivanov.decompose.value.Value
import com.arkivanov.minesweeper.countValuebleChars
import com.arkivanov.minesweeper.setContentDescription

private val cellSize = 16.dp
private const val defaultCountersSize = 3

@Composable
internal fun GameContent(component: GameComponent, modifier: Modifier = Modifier) {
Expand All @@ -72,11 +75,9 @@ internal fun GameContent(component: GameComponent, modifier: Modifier = Modifier
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceAround
) {
Text(
text = "$remainingBombs",
style = MaterialTheme.typography.body2,
RemainingBombs(
remainingBombs = remainingBombs,
modifier = Modifier.weight(1f),
textAlign = TextAlign.Center
)

RestartButton(
Expand All @@ -86,6 +87,10 @@ internal fun GameContent(component: GameComponent, modifier: Modifier = Modifier
onClick = component::onRestartClicked,
)

Stopwatch(

)

Text(
text = "000", // TODO: Place for stopwatch
style = MaterialTheme.typography.body2,
Expand Down Expand Up @@ -126,6 +131,43 @@ internal fun GameContent(component: GameComponent, modifier: Modifier = Modifier
}
}

@Composable
fun RemainingBombs(
remainingBombs: Int,
modifier: Modifier = Modifier,
) {
val bombsStringified = remainingBombs.toString()
val digits = bombsStringified.countValuebleChars()
// TODO: Idea - When user isWin, make all ---, 000?
Row(
modifier = modifier.setContentDescription(
description = "Counter of remaining bombs",
role = Role.Image
),
horizontalArrangement = Arrangement.Center
) {
val zeroesToDrawOnTheRightSide = defaultCountersSize - digits
if (zeroesToDrawOnTheRightSide > 0) {
for (i in 0 until zeroesToDrawOnTheRightSide) {
Image(
painter = LocalGameIcons.icons.digits.getValue('0'),
contentDescription = "0",
contentScale = ContentScale.Crop,
modifier = Modifier.height(26.dp),
)
}
}
for (char in bombsStringified) {
Image(
painter = LocalGameIcons.icons.digits.getValue(char),
contentDescription = char.toString(),
contentScale = ContentScale.Crop,
modifier = Modifier.height(26.dp),
)
}
}
}

@Composable
private fun CellContent(cell: Cell, modifier: Modifier = Modifier) {
Image(
Expand Down Expand Up @@ -173,6 +215,11 @@ private fun RestartButton(
)
}

@Composable
fun Stopwatch() {
// TODO: Implement stopwatch feature
}

@Composable
private fun ControlsInfo(modifier: Modifier = Modifier) {
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ internal val CellStatus.isFlagged: Boolean
internal fun Cell.open(): Cell =
copy(status = CellStatus.Open)

// TODO: Can we somehow increase work of this thing? not each time count run for all grid
internal val GameState.remainingMines: Int
get() = (maxMines - grid.values.count { it.status.isFlagged })

0 comments on commit ecd16ac

Please sign in to comment.