Android: the lists dressed up (docs/design/android-lists.md)
The owner approved the designer's «А» for the games list and «Б» for the databases screen: - Games: a thin line between games, a disc of each side, the winner's «1» on a tile (and the name a little heavier), «½» on quieter tiles, the ECO on its own tag that never gives way; the game last opened marked and in sight; search matches marked, the ECO tag too. Search finds by the ECO. - Databases: badges by kind in Catppuccin colours (Mocha dark, Latte light: PGN blue, ChessBase peach, archives mauve, online teal, own green, ♞ for the player's); the number of games stands out; groups as cards (16/4 dp corners, 2 dp apart); the game put aside with its position on a small board (no coordinates) and «Continue»; two equal, quiet buttons. - Settings as cards with icons; the add sheet's icons in tiles of the kind. - Fixed on the way (the tester): a list read anew after a quick new search could show another game's names in a row; clearing a search goes back to the top; tiles, tags and buttons grow with a large font. Reviewed by the designer and the tester on the emulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
95572c530b
commit
f120c49fd4
22 changed files with 813 additions and 131 deletions
|
|
@ -58,6 +58,9 @@ class ChessPenguinApp : Application() {
|
|||
/// The games shown on the list of each database (after a search), for paging
|
||||
/// games from the game screen: database id → game numbers.
|
||||
val shown = HashMap<String, List<UInt>>()
|
||||
/// The game last opened from a database's list: the search it was found with and its
|
||||
/// place there (android-lists.md §3.6; the list marks it and shows it again).
|
||||
val lastOpened = HashMap<String, Pair<String, Int>>()
|
||||
|
||||
/// Changes each time the app goes to the background, and in every new process: the
|
||||
/// engine button of a game holds only for the visit it was pressed in (§8.3).
|
||||
|
|
|
|||
|
|
@ -77,3 +77,29 @@ fun nagColor(nag: Int, dark: Boolean): Color? = if (dark) {
|
|||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
/// The kinds of databases, each in its own colour on its badge (android-lists.md §5.1).
|
||||
enum class DbKind { Pgn, ChessBase, Archive, Online, Own }
|
||||
|
||||
/// A badge's background and what is written on it.
|
||||
data class KindColor(val container: Color, val content: Color)
|
||||
|
||||
/// The colour of a kind of database, from Catppuccin (the owner's choice): Mocha in the
|
||||
/// dark theme, Latte in the light one, on a tint of the same hue (contrast at least 5:1).
|
||||
fun kindColor(kind: DbKind, dark: Boolean): KindColor = if (dark) {
|
||||
when (kind) {
|
||||
DbKind.Pgn -> KindColor(Color(0xFF384660), Color(0xFF89B4FA)) // blue
|
||||
DbKind.ChessBase -> KindColor(Color(0xFF55443B), Color(0xFFFAB387)) // peach
|
||||
DbKind.Archive -> KindColor(Color(0xFF4A3F5E), Color(0xFFCBA6F7)) // mauve
|
||||
DbKind.Online -> KindColor(Color(0xFF3A5250), Color(0xFF94E2D5)) // teal
|
||||
DbKind.Own -> KindColor(Color(0xFF3F523F), Color(0xFFA6E3A1)) // green
|
||||
}
|
||||
} else {
|
||||
when (kind) {
|
||||
DbKind.Pgn -> KindColor(Color(0xFFDFEAFE), Color(0xFF1957D0))
|
||||
DbKind.ChessBase -> KindColor(Color(0xFFFFE9DD), Color(0xFFA54107))
|
||||
DbKind.Archive -> KindColor(Color(0xFFEEE3FD), Color(0xFF7A33D7))
|
||||
DbKind.Online -> KindColor(Color(0xFFDFF0F1), Color(0xFF116D73))
|
||||
DbKind.Own -> KindColor(Color(0xFFE4F2E1), Color(0xFF2D701E))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.foundation.background
|
||||
import io.github.vrubelroman.chesspenguin.theme.DbKind
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
|
|
@ -53,6 +56,16 @@ import io.github.vrubelroman.chesspenguin.data.FolderScan
|
|||
import io.github.vrubelroman.chesspenguin.data.Found
|
||||
import io.github.vrubelroman.chesspenguin.data.Source
|
||||
|
||||
/// The icon of a way to add, in a round tile coloured as the database it brings
|
||||
/// (android-lists.md §6).
|
||||
@Composable
|
||||
private fun KindIcon(kind: DbKind, icon: androidx.compose.ui.graphics.vector.ImageVector) {
|
||||
val c = io.github.vrubelroman.chesspenguin.theme.kindColor(kind, io.github.vrubelroman.chesspenguin.theme.LocalChessColors.current.dark)
|
||||
Box(Modifier.size(40.dp).clip(androidx.compose.foundation.shape.CircleShape).background(c.container), contentAlignment = Alignment.Center) {
|
||||
Icon(icon, null, tint = c.content, modifier = Modifier.size(22.dp))
|
||||
}
|
||||
}
|
||||
|
||||
/// "Add a database": games in the clipboard, a file, every database in a folder, or a
|
||||
/// player's games from Lichess and Chess.com.
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
|
|
@ -71,7 +84,7 @@ fun AddSheet(onFile: () -> Unit, onFolder: () -> Unit, onPaste: (() -> Unit)?, o
|
|||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.add_paste)) },
|
||||
supportingContent = { Text(stringResource(R.string.add_paste_hint)) },
|
||||
leadingContent = { Icon(Icons.Outlined.ContentPaste, null) },
|
||||
leadingContent = { KindIcon(DbKind.Pgn, Icons.Outlined.ContentPaste) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(role = Role.Button, onClick = onPaste).padding(horizontal = 8.dp),
|
||||
)
|
||||
|
|
@ -79,21 +92,21 @@ fun AddSheet(onFile: () -> Unit, onFolder: () -> Unit, onPaste: (() -> Unit)?, o
|
|||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.online_title)) },
|
||||
supportingContent = { Text(stringResource(R.string.add_online_hint)) },
|
||||
leadingContent = { Icon(Icons.Outlined.CloudDownload, null) },
|
||||
leadingContent = { KindIcon(DbKind.Online, Icons.Outlined.CloudDownload) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(role = Role.Button, onClick = onOnline).padding(horizontal = 8.dp),
|
||||
)
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.add_file)) },
|
||||
supportingContent = { Text(stringResource(R.string.add_file_hint)) },
|
||||
leadingContent = { Icon(Icons.Outlined.Description, null) },
|
||||
leadingContent = { KindIcon(DbKind.Pgn, Icons.Outlined.Description) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(role = Role.Button, onClick = onFile).padding(horizontal = 8.dp),
|
||||
)
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.add_folder)) },
|
||||
supportingContent = { Text(stringResource(R.string.add_folder_hint)) },
|
||||
leadingContent = { Icon(Icons.Outlined.Folder, null) },
|
||||
leadingContent = { KindIcon(DbKind.Pgn, Icons.Outlined.Folder) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(role = Role.Button, onClick = onFolder).padding(horizontal = 8.dp),
|
||||
)
|
||||
|
|
@ -197,7 +210,7 @@ private fun FoundRow(f: Found, checked: Boolean, onChange: (Boolean) -> Unit) {
|
|||
) {
|
||||
Checkbox(checked = checked || f.added, onCheckedChange = null, enabled = enabled)
|
||||
Spacer(Modifier.size(12.dp))
|
||||
FormatBadge(label, error = f.incomplete)
|
||||
FormatBadge(label, error = f.incomplete, kind = when (label) { "CB" -> DbKind.ChessBase; "7Z", "ZIP" -> DbKind.Archive; else -> DbKind.Pgn })
|
||||
Column(Modifier.weight(1f).padding(start = 16.dp)) {
|
||||
Text(f.name, style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
val where = if (f.path.isEmpty()) note else "${f.path} · $note"
|
||||
|
|
|
|||
|
|
@ -190,6 +190,8 @@ fun Board(
|
|||
input: BoardInput? = null,
|
||||
/// Two squares lit red: a wrong move of the trainer, shown for a moment (§32.2).
|
||||
alert: Pair<String, String>? = null,
|
||||
/// The files and ranks along the edges (none on a small board that only shows).
|
||||
coordinates: Boolean = true,
|
||||
) {
|
||||
val colors = LocalChessColors.current
|
||||
val context = LocalContext.current
|
||||
|
|
@ -372,7 +374,7 @@ fun Board(
|
|||
}
|
||||
// Over the pieces, so that b, c, f, g stay readable (as on Lichess).
|
||||
// Coordinates: files along the bottom edge, ranks along the left edge.
|
||||
for (k in 0 until 8) {
|
||||
for (k in 0 until (if (coordinates) 8 else 0)) {
|
||||
val fileIndex = if (flipped) 7 - k else k
|
||||
val rankIndex = if (flipped) k else 7 - k
|
||||
val bottomLight = (7 + k) % 2 == 0
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
|
|
@ -33,6 +35,12 @@ import androidx.compose.ui.text.withStyle
|
|||
import io.github.vrubelroman.chesspenguin.ChessPenguinApp
|
||||
import io.github.vrubelroman.chesspenguin.R
|
||||
import io.github.vrubelroman.chesspenguin.theme.Tabular
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import io.github.vrubelroman.chesspenguin.theme.kindColor
|
||||
import io.github.vrubelroman.chesspenguin.theme.LocalChessColors
|
||||
import io.github.vrubelroman.chesspenguin.theme.DbKind
|
||||
import io.github.vrubelroman.chesspenguin.data.Notation
|
||||
import io.github.vrubelroman.chesspenguin.data.DbEntry
|
||||
import io.github.vrubelroman.chesspenguin.data.Source
|
||||
|
|
@ -73,21 +81,57 @@ fun formatName(e: DbEntry): String = when (e.fileName.substringAfterLast('.', ""
|
|||
else -> "PGN"
|
||||
}
|
||||
|
||||
/// What kind of database an entry is (its badge's colour, android-lists.md §5.1).
|
||||
fun kindOf(e: DbEntry): DbKind {
|
||||
return when {
|
||||
e.source == Source.Own -> DbKind.Own
|
||||
e.source == Source.Online -> DbKind.Online
|
||||
else -> when (badge(e)) {
|
||||
"CB" -> DbKind.ChessBase
|
||||
"7Z", "ZIP" -> DbKind.Archive
|
||||
else -> DbKind.Pgn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A database's badge: 40 dp, the colour of its kind, a word or an icon on it.
|
||||
@Composable
|
||||
fun FormatBadge(text: String, error: Boolean = false) {
|
||||
fun KindBadge(
|
||||
kind: DbKind,
|
||||
error: Boolean = false,
|
||||
content: @Composable (Color) -> Unit,
|
||||
) {
|
||||
val c = kindColor(kind, LocalChessColors.current.dark)
|
||||
Box(
|
||||
Modifier
|
||||
.size(40.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(if (error) MaterialTheme.colorScheme.errorContainer else MaterialTheme.colorScheme.primaryContainer),
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(if (error) MaterialTheme.colorScheme.errorContainer else c.container),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
text,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = if (error) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
)
|
||||
}
|
||||
) { content(if (error) MaterialTheme.colorScheme.error else c.content) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FormatBadge(text: String, error: Boolean = false, kind: DbKind = DbKind.Pgn) {
|
||||
KindBadge(kind, error) { color -> Text(text, style = MaterialTheme.typography.labelSmall, color = color) }
|
||||
}
|
||||
|
||||
/// The shape of a card in a group of `count` (android-lists.md §5.3): 16 dp outside,
|
||||
/// 4 dp where it meets its neighbours.
|
||||
fun groupShape(index: Int, count: Int): RoundedCornerShape {
|
||||
val top = if (index == 0) 16.dp else 4.dp
|
||||
val bottom = if (index == count - 1) 16.dp else 4.dp
|
||||
return RoundedCornerShape(topStart = top, topEnd = top, bottomStart = bottom, bottomEnd = bottom)
|
||||
}
|
||||
|
||||
/// A row of a group drawn as its card: 12 dp from the screen's edges, 2 dp between cards.
|
||||
@Composable
|
||||
fun Modifier.groupCard(index: Int, count: Int): Modifier {
|
||||
val shape = groupShape(index, count)
|
||||
return this
|
||||
.padding(start = 12.dp, end = 12.dp, bottom = 2.dp)
|
||||
.clip(shape)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerLow, shape)
|
||||
}
|
||||
|
||||
/// "Carlsen, Magnus" → "Carlsen M."; other names stay as in the file (§6.2).
|
||||
|
|
@ -111,11 +155,57 @@ fun PlayerName(
|
|||
color: Color = Color.Unspecified,
|
||||
maxLines: Int = 1,
|
||||
abbreviate: Boolean = true,
|
||||
/// Words searched for: shown marked where they are in the name as shown.
|
||||
highlight: String? = null,
|
||||
) {
|
||||
val measurer = rememberTextMeasurer()
|
||||
BoxWithConstraints(modifier) {
|
||||
val text = if (abbreviate && measurer.measure(name, style, softWrap = false).size.width > constraints.maxWidth) shortName(name) else name
|
||||
Text(text, style = style, color = color, maxLines = maxLines, overflow = TextOverflow.Ellipsis)
|
||||
Text(highlighted(text, highlight), style = style, color = color, maxLines = maxLines, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
/// `text` with the first place of each searched word marked (android-lists.md §3.7);
|
||||
/// case does not matter.
|
||||
@Composable
|
||||
fun highlighted(text: String, query: String?): AnnotatedString {
|
||||
val words = query?.split(' ')?.filter { it.isNotBlank() }.orEmpty()
|
||||
if (words.isEmpty()) return AnnotatedString(text)
|
||||
val mark = SpanStyle(
|
||||
background = MaterialTheme.colorScheme.primaryContainer,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
)
|
||||
return buildAnnotatedString {
|
||||
append(text)
|
||||
for (w in words) {
|
||||
val at = text.indexOf(w, ignoreCase = true)
|
||||
if (at >= 0) addStyle(mark, at, at + w.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A player's share of the result in the list of games (android-lists.md §3.3): the
|
||||
/// winner's «1» on a tile, «½» on a quieter one, a loss as a plain «0».
|
||||
@Composable
|
||||
fun ResultTile(result: String?) {
|
||||
// At least 24×20 dp; it grows with the font.
|
||||
Box(Modifier.widthIn(min = 24.dp).heightIn(min = 20.dp), contentAlignment = Alignment.Center) {
|
||||
when (result) {
|
||||
"1" -> Box(
|
||||
Modifier.widthIn(min = 24.dp).heightIn(min = 20.dp).clip(RoundedCornerShape(6.dp)).background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text("1", style = MaterialTheme.typography.labelLarge.merge(Tabular), fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
}
|
||||
"½" -> Box(
|
||||
Modifier.widthIn(min = 24.dp).heightIn(min = 20.dp).clip(RoundedCornerShape(6.dp)).background(MaterialTheme.colorScheme.surfaceContainerHigh),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text("½", style = MaterialTheme.typography.labelLarge.merge(Tabular), color = MaterialTheme.colorScheme.onSurface)
|
||||
}
|
||||
null -> {}
|
||||
else -> Text(result, style = MaterialTheme.typography.labelLarge.merge(Tabular), color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,11 +222,14 @@ fun elo(value: String): String = value.trim().takeIf { v -> v.toIntOrNull()?.let
|
|||
|
||||
/// The colour of a side: a small disc (white with a rim, or black).
|
||||
@Composable
|
||||
fun SideDisc(white: Boolean) {
|
||||
fun SideDisc(white: Boolean, size: androidx.compose.ui.unit.Dp = 12.dp) {
|
||||
// Black darker than any background, white whiter; the ring in the text's muted colour
|
||||
// keeps either from reading as an empty circle (android-lists.md §3.2).
|
||||
val dark = LocalChessColors.current.dark
|
||||
Box(
|
||||
Modifier.size(12.dp).clip(CircleShape)
|
||||
.background(if (white) Color(0xFFF5F5F0) else Color(0xFF26282B))
|
||||
.border(1.dp, MaterialTheme.colorScheme.outline, CircleShape),
|
||||
Modifier.size(size).clip(CircleShape)
|
||||
.background(if (white) Color.White else if (dark) Color(0xFF0E0F10) else Color(0xFF1C1D1F))
|
||||
.border(1.dp, MaterialTheme.colorScheme.onSurfaceVariant, CircleShape),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,15 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import io.github.vrubelroman.chesspenguin.theme.DbKind
|
||||
import androidx.compose.material.icons.rounded.CloudDownload
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import android.content.ClipboardManager
|
||||
import android.text.format.DateUtils
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
|
|
@ -175,6 +185,8 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
val own = entries.filter { it.source == Source.Own }
|
||||
val theApp = app()
|
||||
val adjourned by theApp.maiaGames.current.collectAsState()
|
||||
// Back on the list of databases, a list of games was left: its mark goes (android-lists.md §3.6).
|
||||
LaunchedEffect(Unit) { theApp.lastOpened.clear() }
|
||||
val playRemovedText = stringResource(R.string.play_removed)
|
||||
val keptText = stringResource(R.string.player_kept_unfinished)
|
||||
var playing by remember { mutableStateOf(false) }
|
||||
|
|
@ -264,18 +276,33 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
// A game against Maia put aside (§31.7): go on with it, or let it go.
|
||||
adjourned?.takeIf { !it.over }?.let { m ->
|
||||
item(key = "adjourned") {
|
||||
// The game's position on a small board, the side and the move, and
|
||||
// «Continue» as the screen's main action while it waits (android-lists.md §5.4).
|
||||
val shownAt = remember(m) { adjournedPosition(theApp.maiaGames.pgn()) }
|
||||
val sideText = stringResource(if (m.userWhite) R.string.play_as_white else R.string.play_as_black)
|
||||
val sub = shownAt?.second?.let { sideText + " · " + stringResource(R.string.play_move_n, it) } ?: sideText
|
||||
val title = stringResource(R.string.play_adjourned_title, m.strength.toString())
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 4.dp)
|
||||
.background(MaterialTheme.colorScheme.secondaryContainer, RoundedCornerShape(12.dp))
|
||||
.padding(start = 16.dp, end = 4.dp, top = 4.dp, bottom = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(MaterialTheme.colorScheme.primaryContainer)
|
||||
.clickable(onClick = onPlay)
|
||||
.semantics(mergeDescendants = true) {}
|
||||
.padding(start = 12.dp, top = 12.dp, bottom = 12.dp, end = 4.dp),
|
||||
verticalAlignment = Alignment.Top,
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.play_adjourned, m.strength.toString(), stringResource(if (m.userWhite) R.string.play_as_white else R.string.play_as_black)),
|
||||
Modifier.weight(1f),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
TextButton(onClick = onPlay) { Text(stringResource(R.string.play_continue)) }
|
||||
shownAt?.let { (fen, _) ->
|
||||
Box(Modifier.clip(RoundedCornerShape(6.dp))) { MiniBoard(fen, flipped = !m.userWhite, size = 72.dp) }
|
||||
Spacer(Modifier.width(12.dp))
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Medium, color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(sub, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Button(onClick = onPlay, modifier = Modifier.heightIn(min = 32.dp), contentPadding = PaddingValues(horizontal = 16.dp, vertical = 4.dp)) {
|
||||
Text(stringResource(R.string.play_continue))
|
||||
}
|
||||
}
|
||||
IconButton(onClick = {
|
||||
// Played on both sides: kept in the player's database,
|
||||
// unfinished (no «Undo»: it is there to be deleted).
|
||||
|
|
@ -302,14 +329,20 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
}
|
||||
}
|
||||
item(key = "actions") {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
FilledTonalButton(onClick = { if (adjourned?.over == false) askingAdjourned = true else playing = true }, modifier = Modifier.height(48.dp)) {
|
||||
Icon(Icons.Rounded.SmartToy, null)
|
||||
// Two equal buttons over the whole width (android-lists.md §5.5).
|
||||
// Neutral, as the cards' edges: the blue stays for the game put aside and the FAB.
|
||||
val quiet = ButtonDefaults.filledTonalButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp), horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
FilledTonalButton(onClick = { if (adjourned?.over == false) askingAdjourned = true else playing = true }, modifier = Modifier.weight(1f).heightIn(min = 56.dp), shape = RoundedCornerShape(16.dp), colors = quiet) {
|
||||
Icon(Icons.Rounded.SmartToy, null, tint = MaterialTheme.colorScheme.primary)
|
||||
Spacer(Modifier.size(8.dp))
|
||||
Text(stringResource(R.string.play_with_maia))
|
||||
}
|
||||
FilledTonalButton(onClick = onNewGame, modifier = Modifier.height(48.dp)) {
|
||||
Icon(Icons.Rounded.Add, null)
|
||||
FilledTonalButton(onClick = onNewGame, modifier = Modifier.weight(1f).heightIn(min = 56.dp), shape = RoundedCornerShape(16.dp), colors = quiet) {
|
||||
Icon(Icons.Rounded.Add, null, tint = MaterialTheme.colorScheme.primary)
|
||||
Spacer(Modifier.size(8.dp))
|
||||
Text(stringResource(R.string.new_game))
|
||||
}
|
||||
|
|
@ -331,7 +364,8 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
)
|
||||
}
|
||||
}
|
||||
items(own, key = { it.id }) { e ->
|
||||
items(own.size, key = { own[it].id }) { k ->
|
||||
val e = own[k]
|
||||
OwnRow(
|
||||
e,
|
||||
player = theApp.playerGames.isPlayers(e.id),
|
||||
|
|
@ -360,7 +394,7 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
deleting = e
|
||||
}
|
||||
},
|
||||
modifier = Modifier.animateItem(),
|
||||
modifier = Modifier.animateItem().groupCard(k, own.size),
|
||||
)
|
||||
}
|
||||
item(key = "files-head") {
|
||||
|
|
@ -371,7 +405,8 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
items(files, key = { it.id }) { e ->
|
||||
items(files.size, key = { files[it].id }) { k ->
|
||||
val e = files[k]
|
||||
DatabaseRow(
|
||||
e,
|
||||
download = views[e.id],
|
||||
|
|
@ -404,7 +439,7 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.animateItem(),
|
||||
modifier = Modifier.animateItem().groupCard(k, files.size),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -549,24 +584,21 @@ private fun OwnRow(e: DbEntry, player: Boolean, onOpen: () -> Unit, onRename: ()
|
|||
.fillMaxWidth()
|
||||
.height(72.dp)
|
||||
.combinedClickable(onClick = onOpen, onLongClick = { menu = true })
|
||||
.padding(start = 16.dp, end = 4.dp),
|
||||
.padding(start = 12.dp, end = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(
|
||||
Modifier.size(40.dp).clip(RoundedCornerShape(8.dp)).background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
KindBadge(DbKind.Own) { color ->
|
||||
// A player's database (games against Maia written by themselves): a knight.
|
||||
if (player) {
|
||||
Text("♞", style = MaterialTheme.typography.titleLarge, color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text("♞", style = MaterialTheme.typography.titleLarge, color = color)
|
||||
} else {
|
||||
Icon(Icons.Rounded.EditNote, null, tint = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Icon(Icons.Rounded.EditNote, null, tint = color)
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f).padding(start = 16.dp)) {
|
||||
Column(Modifier.weight(1f).padding(start = 12.dp)) {
|
||||
Text(displayName(e), style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(
|
||||
pluralStringResource(R.plurals.games_count, n, groupDigits(n)) + " · " + stringResource(if (player) R.string.player_db_row else R.string.own_on_phone),
|
||||
countFirst(pluralStringResource(R.plurals.games_count, n, groupDigits(n)), stringResource(if (player) R.string.player_db_row else R.string.own_on_phone)),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
|
|
@ -641,6 +673,7 @@ private fun DatabaseRow(
|
|||
val subtitle = e.games?.let {
|
||||
stringResource(R.string.games_with_format, pluralStringResource(R.plurals.games_count, it, groupDigits(it)), e.format ?: format)
|
||||
} ?: stringResource(R.string.not_opened, formatName(e))
|
||||
val gamesText = e.games?.let { pluralStringResource(R.plurals.games_count, it, groupDigits(it)) }
|
||||
val shownSubtitle = when {
|
||||
// A copy kept in the app says so: removing it deletes it.
|
||||
e.source == Source.Copy -> subtitle + " · " + stringResource(R.string.db_copy)
|
||||
|
|
@ -664,14 +697,20 @@ private fun DatabaseRow(
|
|||
.fillMaxWidth()
|
||||
.height(72.dp)
|
||||
.combinedClickable(onClick = onOpen, onLongClick = { menu = true })
|
||||
.padding(start = 16.dp, end = 4.dp),
|
||||
.padding(start = 12.dp, end = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
FormatBadge(format)
|
||||
Column(Modifier.weight(1f).padding(start = 16.dp)) {
|
||||
// A downloaded database is told by where it comes from, not by its format.
|
||||
val kind = kindOf(e)
|
||||
KindBadge(kind) { color ->
|
||||
if (kind == DbKind.Online) Icon(Icons.Rounded.CloudDownload, null, tint = color, modifier = Modifier.size(22.dp))
|
||||
else Text(format, style = MaterialTheme.typography.labelSmall, color = color)
|
||||
}
|
||||
Column(Modifier.weight(1f).padding(start = 12.dp)) {
|
||||
Text(displayName(e), style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(
|
||||
shownSubtitle,
|
||||
// The number of games stands out (a big database from a small one).
|
||||
if (failure == null && gamesText != null && shownSubtitle.startsWith(gamesText)) countFirst(gamesText, shownSubtitle.removePrefix(gamesText).removePrefix(" · ")) else androidx.compose.ui.text.AnnotatedString(shownSubtitle),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (failure != null) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
|
|
@ -728,6 +767,31 @@ private fun RenameDialog(name: String, own: Boolean = false, onDismiss: () -> Un
|
|||
)
|
||||
}
|
||||
|
||||
/// «**267 games** · PGN»: the number of games heavier and in the text's colour.
|
||||
@Composable
|
||||
private fun countFirst(count: String, rest: String): androidx.compose.ui.text.AnnotatedString {
|
||||
val strong = SpanStyle(fontWeight = FontWeight.Medium, color = MaterialTheme.colorScheme.onSurface)
|
||||
return buildAnnotatedString {
|
||||
withStyle(strong) { append(count) }
|
||||
if (rest.isNotEmpty()) append(" · $rest")
|
||||
}
|
||||
}
|
||||
|
||||
/// The position on the board of a game put aside, and the number of its last move.
|
||||
private fun adjournedPosition(pgn: String?): Pair<String, Int>? {
|
||||
pgn ?: return null
|
||||
val s = runCatching { uniffi.mobile_api.GameSession.fromPgn(pgn) }.getOrNull() ?: return null
|
||||
return try {
|
||||
val d = s.data()
|
||||
val end = lineEnd(d)
|
||||
val node = d.nodes[end]
|
||||
// The move to be made: after White's, the same number; after Black's, the next.
|
||||
node.fen to (if (end == 0) 1 else node.moveNumber.toInt() + if (node.white) 0 else 1)
|
||||
} finally {
|
||||
s.close()
|
||||
}
|
||||
}
|
||||
|
||||
/// The name of pasted games: one game by its players, games of one event by it, others by
|
||||
/// when they were pasted (`dated`), so that two pastes differ.
|
||||
private fun pastedName(db: Database, dated: String): String {
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ fun GameScreen(
|
|||
val dbEntry = libraryEntries.firstOrNull { it.id == db }
|
||||
var games by remember { mutableStateOf(app.shown[db]) }
|
||||
var place by rememberSaveable { mutableIntStateOf(startPlace) }
|
||||
// The list marks the game it comes back to (the one paged to with ‹ ›, too).
|
||||
LaunchedEffect(place) { if (db != NEW_GAME && db != PLAY_GAME) app.lastOpened[db] = query to place }
|
||||
// The game as changed on the board (android-play.md §29), kept while the phone turns:
|
||||
// a game of someone else's file is changed for analysis and never written there.
|
||||
val held: GameEdit = viewModel()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import kotlinx.coroutines.flow.first
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -99,8 +107,18 @@ fun GamesScreen(db: String, onBack: () -> Unit, onGame: (place: Int, query: Stri
|
|||
val found = withContext(Dispatchers.Default) { app.library.listed(db, d, query) }
|
||||
rows.clear()
|
||||
shown = found
|
||||
// New results start at the top.
|
||||
list.scrollToItem(0)
|
||||
// Once the new list is laid out (else the list keeps its place by a row's key).
|
||||
snapshotFlow { list.layoutInfo.totalItemsCount }.first { it == found.size }
|
||||
// Back from a game: it in sight; new results start at the top.
|
||||
val last = app.lastOpened[db]?.takeIf { it.first == query }?.second?.takeIf { it < found.size }
|
||||
val first = list.firstVisibleItemIndex
|
||||
val seen = list.layoutInfo.visibleItemsInfo.size.takeIf { it > 0 } ?: 6
|
||||
when {
|
||||
last == null -> list.scrollToItem(0)
|
||||
// Already on the screen (the list kept its place): it stays where it is.
|
||||
last in first until first + seen - 1 -> {}
|
||||
else -> list.scrollToItem((last - 3).coerceAtLeast(0))
|
||||
}
|
||||
app.shown[db] = found
|
||||
}
|
||||
val scroll = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
|
|
@ -219,6 +237,7 @@ fun GamesScreen(db: String, onBack: () -> Unit, onGame: (place: Int, query: Stri
|
|||
else -> {
|
||||
// Wide enough for the database's largest number.
|
||||
val numberWidth = numberWidth(database?.len()?.toInt() ?: games.size)
|
||||
val last = app.lastOpened[db]?.takeIf { it.first == query }?.second
|
||||
LazyColumn(Modifier.fillMaxSize(), state = list) {
|
||||
items(games.size, key = { games[it].toLong() }) { place ->
|
||||
val chunk = place / CHUNK
|
||||
|
|
@ -227,10 +246,19 @@ fun GamesScreen(db: String, onBack: () -> Unit, onGame: (place: Int, query: Stri
|
|||
if (rows[chunk] == null) {
|
||||
val d = database ?: return@LaunchedEffect
|
||||
val part = games.subList(chunk * CHUNK, minOf(games.size, (chunk + 1) * CHUNK))
|
||||
rows[chunk] = withContext(Dispatchers.Default) { d.rowsOf(part) }
|
||||
val read = withContext(Dispatchers.Default) { d.rowsOf(part) }
|
||||
// Rows of a list replaced meanwhile (a new search) are not this one's.
|
||||
if (shown === games) rows[chunk] = read
|
||||
}
|
||||
}
|
||||
GameRowView(games[place].toInt() + 1, numberWidth, loaded?.getOrNull(place % CHUNK)) { onGame(place, query) }
|
||||
GameRowView(
|
||||
games[place].toInt() + 1,
|
||||
numberWidth,
|
||||
loaded?.getOrNull(place % CHUNK),
|
||||
lastOpened = place == last,
|
||||
divider = place < games.size - 1,
|
||||
query = query,
|
||||
) { onGame(place, query) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -277,67 +305,158 @@ private fun numberWidth(count: Int): androidx.compose.ui.unit.Dp {
|
|||
}
|
||||
}
|
||||
|
||||
/// One game (§6.2): its number, White and Black each on a line of their own (with the
|
||||
/// rating and the share of the result), then event · year · ECO. The row is read as one
|
||||
/// sentence by TalkBack.
|
||||
/// One game (§6.2, android-lists.md §3): its number, White and Black each on a line of
|
||||
/// their own (a disc of the side, the rating, the share of the result), then event · year
|
||||
/// and the ECO on a tag. A thin line under it; the game last opened is marked. The row
|
||||
/// is read as one sentence by TalkBack.
|
||||
@Composable
|
||||
private fun GameRowView(number: Int, numberWidth: androidx.compose.ui.unit.Dp, row: GameRow?, onClick: () -> Unit) {
|
||||
private fun GameRowView(
|
||||
number: Int,
|
||||
numberWidth: androidx.compose.ui.unit.Dp,
|
||||
row: GameRow?,
|
||||
lastOpened: Boolean,
|
||||
divider: Boolean,
|
||||
query: String,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
// 6 + 24 + 24 + 20 + 6 = 80 dp at the normal font size; the lines grow with a larger font.
|
||||
val nameLine = lineHeight(MaterialTheme.typography.bodyLarge, 24.dp)
|
||||
val detailsLine = lineHeight(MaterialTheme.typography.bodyMedium, 20.dp)
|
||||
val said = row?.let { rowDescription(number, it) } ?: ""
|
||||
Row(
|
||||
val lastText = stringResource(R.string.last_opened)
|
||||
val said = row?.let { rowDescription(number, it) + if (lastOpened) ". $lastText" else "" } ?: ""
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.height(12.dp + nameLine * 2 + detailsLine)
|
||||
.background(if (lastOpened) colors.surfaceContainer else Color.Transparent)
|
||||
.clickable(enabled = row != null, onClick = onClick)
|
||||
.clearAndSetSemantics { if (row != null) contentDescription = said }
|
||||
.padding(horizontal = 16.dp, vertical = 6.dp),
|
||||
verticalAlignment = Alignment.Top,
|
||||
.clearAndSetSemantics { if (row != null) contentDescription = said },
|
||||
) {
|
||||
// Level with White's line.
|
||||
Box(Modifier.width(numberWidth).height(nameLine), contentAlignment = Alignment.CenterEnd) {
|
||||
Text(
|
||||
groupDigits(number),
|
||||
style = MaterialTheme.typography.bodySmall.merge(Tabular),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
Row(Modifier.fillMaxSize().padding(horizontal = 16.dp, vertical = 6.dp), verticalAlignment = Alignment.Top) {
|
||||
// Level with White's line.
|
||||
Box(Modifier.width(numberWidth).height(nameLine), contentAlignment = Alignment.CenterEnd) {
|
||||
Text(
|
||||
groupDigits(number),
|
||||
style = MaterialTheme.typography.bodySmall.merge(Tabular),
|
||||
color = colors.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(12.dp))
|
||||
GameRowText(row, nameLine, detailsLine, query, Modifier.weight(1f))
|
||||
}
|
||||
if (lastOpened) {
|
||||
Box(
|
||||
Modifier.align(Alignment.CenterStart).width(3.dp).fillMaxHeight()
|
||||
.background(colors.primary, RoundedCornerShape(topEnd = 2.dp, bottomEnd = 2.dp)),
|
||||
)
|
||||
}
|
||||
// From the discs to 16 dp before the edge; the number stays in the margin.
|
||||
if (divider) {
|
||||
Box(
|
||||
Modifier.align(Alignment.BottomStart).padding(start = 16.dp + numberWidth + 12.dp, end = 16.dp)
|
||||
.fillMaxWidth().height(1.dp).background(colors.outlineVariant),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(12.dp))
|
||||
GameRowText(row, nameLine, detailsLine, Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameRowText(row: GameRow?, nameLine: androidx.compose.ui.unit.Dp, detailsLine: androidx.compose.ui.unit.Dp, modifier: Modifier) {
|
||||
private fun GameRowText(row: GameRow?, nameLine: androidx.compose.ui.unit.Dp, detailsLine: androidx.compose.ui.unit.Dp, query: String, modifier: Modifier) {
|
||||
Column(modifier) {
|
||||
if (row == null) return@Column
|
||||
val style = MaterialTheme.typography.bodyLarge
|
||||
val muted = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
val white = row.white.trim().takeIf { it.isNotEmpty() && it != "?" }
|
||||
val black = row.black.trim().takeIf { it.isNotEmpty() && it != "?" }
|
||||
if (white != null && black == null) {
|
||||
val study = white != null && black == null
|
||||
if (study) {
|
||||
// A study or a book position: a title for White and no Black — two lines of it.
|
||||
// From the top, level with the number, not centred in the two lines.
|
||||
// From the top, level with the number, not centred in the two lines; no discs:
|
||||
// these are not players.
|
||||
Box(Modifier.height(nameLine * 2)) {
|
||||
PlayerLine(white, elo(row.whiteElo), null, style, maxLines = 2, abbreviate = false)
|
||||
PlayerName(white, style, maxLines = 2, abbreviate = false, highlight = query)
|
||||
}
|
||||
} else {
|
||||
PlayerLine(white ?: "?", elo(row.whiteElo), sideResult(row.result, true), style, Modifier.height(nameLine), nameColor = if (white == null) muted else androidx.compose.ui.graphics.Color.Unspecified)
|
||||
PlayerLine(black ?: "?", elo(row.blackElo), sideResult(row.result, false), style, Modifier.height(nameLine), nameColor = if (black == null) muted else androidx.compose.ui.graphics.Color.Unspecified)
|
||||
ListPlayer(white, elo(row.whiteElo), sideResult(row.result, true), true, style, nameLine, query)
|
||||
ListPlayer(black, elo(row.blackElo), sideResult(row.result, false), false, style, nameLine, query)
|
||||
}
|
||||
val details = joinKnown(row.event, year(row.date), row.eco)
|
||||
if (details.isNotEmpty()) {
|
||||
Text(
|
||||
details,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = muted,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.height(detailsLine),
|
||||
val details = joinKnown(row.event, year(row.date))
|
||||
val eco = row.eco.trim().takeIf { it.isNotEmpty() && it != "?" }
|
||||
if (details.isNotEmpty() || eco != null) {
|
||||
// Under the names (past the discs); the ECO tag never gives way, the event does.
|
||||
Row(Modifier.height(detailsLine).padding(start = if (study) 0.dp else 16.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
highlighted(details, query),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = muted,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
if (eco != null) {
|
||||
Spacer(Modifier.width(8.dp))
|
||||
EcoTag(eco, marked = query.split(' ').any { it.isNotBlank() && eco.startsWith(it.trim(), ignoreCase = true) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One player in the list: the disc of the side, the name (the winner's a little
|
||||
/// heavier), the rating, the share of the result on its tile.
|
||||
@Composable
|
||||
private fun ListPlayer(
|
||||
name: String?,
|
||||
rating: String,
|
||||
result: String?,
|
||||
white: Boolean,
|
||||
style: androidx.compose.ui.text.TextStyle,
|
||||
height: androidx.compose.ui.unit.Dp,
|
||||
query: String,
|
||||
) {
|
||||
val won = result == "1"
|
||||
Row(Modifier.height(height), verticalAlignment = Alignment.CenterVertically) {
|
||||
SideDisc(white, 8.dp)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {
|
||||
PlayerName(
|
||||
name ?: "?",
|
||||
if (won) style.copy(fontWeight = androidx.compose.ui.text.font.FontWeight.Medium) else style,
|
||||
Modifier.weight(1f, fill = false),
|
||||
if (name == null) MaterialTheme.colorScheme.onSurfaceVariant else Color.Unspecified,
|
||||
highlight = query,
|
||||
)
|
||||
if (rating.isNotEmpty()) {
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(rating, style = MaterialTheme.typography.bodyMedium.merge(Tabular), color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
ResultTile(result)
|
||||
}
|
||||
}
|
||||
|
||||
/// The opening's code on a small outlined tag at the right of the details line; filled
|
||||
/// like the other matches when it is what was searched for.
|
||||
@Composable
|
||||
private fun EcoTag(eco: String, marked: Boolean) {
|
||||
val shape = RoundedCornerShape(4.dp)
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(
|
||||
Modifier.heightIn(min = 16.dp).widthIn(min = 32.dp)
|
||||
.background(if (marked) colors.primaryContainer else Color.Transparent, shape)
|
||||
.border(1.dp, if (marked) colors.primaryContainer else colors.outline, shape)
|
||||
.padding(horizontal = 4.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
eco,
|
||||
style = MaterialTheme.typography.labelSmall.merge(Tabular),
|
||||
color = if (marked) colors.onPrimaryContainer else colors.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -252,6 +252,7 @@ fun MiniBoard(fen: String, flipped: Boolean, size: androidx.compose.ui.unit.Dp)
|
|||
description = "",
|
||||
animated = false,
|
||||
modifier = Modifier.width(size),
|
||||
coordinates = false,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,26 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import androidx.compose.material.icons.rounded.Info
|
||||
import androidx.compose.material.icons.rounded.SdCard
|
||||
import androidx.compose.material.icons.rounded.DeveloperBoard
|
||||
import androidx.compose.material.icons.rounded.Timer
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.Memory
|
||||
import androidx.compose.material.icons.rounded.Translate
|
||||
import androidx.compose.material.icons.rounded.Palette
|
||||
import androidx.compose.material.icons.rounded.GridOn
|
||||
import androidx.compose.material.icons.rounded.Save
|
||||
import androidx.compose.material.icons.rounded.Vibration
|
||||
import androidx.compose.material.icons.automirrored.rounded.FormatListBulleted
|
||||
import androidx.compose.material.icons.automirrored.rounded.Notes
|
||||
import androidx.compose.material.icons.automirrored.rounded.VolumeUp
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowRightAlt
|
||||
import androidx.compose.material.icons.rounded.Animation
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.background
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -104,8 +125,9 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
) { padding ->
|
||||
Column(Modifier.fillMaxSize().padding(padding).verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) {
|
||||
Group(stringResource(R.string.group_game))
|
||||
Cards {
|
||||
val notationNow = notationNames.firstOrNull { it.first == prefs.notation } ?: notationNames.first()
|
||||
Item(stringResource(R.string.notation), notationNow.second) {
|
||||
Item(stringResource(R.string.notation), notationNow.second, icon = Icons.AutoMirrored.Rounded.Notes) {
|
||||
choice = Choice(
|
||||
R.string.notation,
|
||||
notationNames.map { it.second },
|
||||
|
|
@ -114,15 +136,17 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
) { i -> set { it.copy(notation = notationNames[i].first) } }
|
||||
}
|
||||
|
||||
Toggle(stringResource(R.string.animation), prefs.animation) { v -> set { it.copy(animation = v) } }
|
||||
Toggle(stringResource(R.string.best_arrow), prefs.bestArrow) { v -> set { it.copy(bestArrow = v) } }
|
||||
Toggle(stringResource(R.string.sound), prefs.sound) { v -> set { it.copy(sound = v) } }
|
||||
Toggle(stringResource(R.string.vibration), prefs.vibration) { v -> set { it.copy(vibration = v) } }
|
||||
Toggle(stringResource(R.string.record_games), prefs.recordGames) { v -> set { it.copy(recordGames = v) } }
|
||||
Toggle(stringResource(R.string.animation), prefs.animation, Icons.Rounded.Animation) { v -> set { it.copy(animation = v) } }
|
||||
Toggle(stringResource(R.string.best_arrow), prefs.bestArrow, Icons.AutoMirrored.Rounded.ArrowRightAlt) { v -> set { it.copy(bestArrow = v) } }
|
||||
Toggle(stringResource(R.string.sound), prefs.sound, Icons.AutoMirrored.Rounded.VolumeUp) { v -> set { it.copy(sound = v) } }
|
||||
Toggle(stringResource(R.string.vibration), prefs.vibration, Icons.Rounded.Vibration) { v -> set { it.copy(vibration = v) } }
|
||||
Toggle(stringResource(R.string.record_games), prefs.recordGames, Icons.Rounded.Save) { v -> set { it.copy(recordGames = v) } }
|
||||
}
|
||||
|
||||
Group(stringResource(R.string.group_look))
|
||||
Item(stringResource(R.string.board_and_pieces), boardLabel(prefs.board) + " · " + prefs.pieces.dir, onClick = onBoardStyle)
|
||||
Item(stringResource(R.string.theme), themeNames.first { it.first == prefs.theme }.second) {
|
||||
Cards {
|
||||
Item(stringResource(R.string.board_and_pieces), boardLabel(prefs.board) + " · " + prefs.pieces.dir, icon = Icons.Rounded.GridOn, onClick = onBoardStyle)
|
||||
Item(stringResource(R.string.theme), themeNames.first { it.first == prefs.theme }.second, icon = Icons.Rounded.Palette) {
|
||||
choice = Choice(R.string.theme, themeNames.map { it.second }, themeNames.indexOfFirst { it.first == prefs.theme }) { i ->
|
||||
set { it.copy(theme = themeNames[i].first) }
|
||||
}
|
||||
|
|
@ -132,42 +156,45 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
if (it.isEmpty()) stringResource(R.string.theme_system) else Locale.forLanguageTag(it).let { l -> l.getDisplayLanguage(l).replaceFirstChar(Char::uppercase) }
|
||||
}
|
||||
val language = remember { Language.get(context) }
|
||||
Item(stringResource(R.string.language), languageNames[LANGUAGES.indexOf(language).coerceAtLeast(0)]) {
|
||||
Item(stringResource(R.string.language), languageNames[LANGUAGES.indexOf(language).coerceAtLeast(0)], icon = Icons.Rounded.Translate) {
|
||||
choice = Choice(R.string.language, languageNames, LANGUAGES.indexOf(language).coerceAtLeast(0)) { i ->
|
||||
if (Language.set(context, LANGUAGES[i])) (context as? Activity)?.recreate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Group(stringResource(R.string.group_engine))
|
||||
Cards {
|
||||
when {
|
||||
files.builtIn -> Status(stringResource(R.string.engine_built_in))
|
||||
files.builtIn -> Status(stringResource(R.string.engine_built_in), Icons.Rounded.Memory)
|
||||
net == NetState.Ready -> {
|
||||
Status(stringResource(R.string.engine_downloaded))
|
||||
Item(stringResource(R.string.engine_delete, size), null) { deleting = true }
|
||||
Status(stringResource(R.string.engine_downloaded), Icons.Rounded.Memory)
|
||||
Item(stringResource(R.string.engine_delete, size), null, icon = Icons.Rounded.Delete) { deleting = true }
|
||||
}
|
||||
net is NetState.Loading -> {
|
||||
val l = net as NetState.Loading
|
||||
Item(stringResource(R.string.engine_downloading, (l.done / 1_000_000).toInt(), (l.total / 1_000_000).toInt()), null) { sheet = true }
|
||||
Item(stringResource(R.string.engine_downloading, (l.done / 1_000_000).toInt(), (l.total / 1_000_000).toInt()), null, icon = Icons.Rounded.Memory) { sheet = true }
|
||||
}
|
||||
// The same sheet as in a game: the size, mobile data, cancel (§9).
|
||||
else -> Item(stringResource(R.string.engine_missing, size), null) { sheet = true }
|
||||
else -> Item(stringResource(R.string.engine_missing, size), null, icon = Icons.Rounded.Memory) { sheet = true }
|
||||
}
|
||||
Item(stringResource(R.string.lines), "${prefs.engineLines}") {
|
||||
Item(stringResource(R.string.lines), "${prefs.engineLines}", icon = Icons.AutoMirrored.Rounded.FormatListBulleted) {
|
||||
choice = Choice(R.string.lines, listOf("1", "2", "3"), prefs.engineLines - 1) { i -> set { it.copy(engineLines = i + 1) } }
|
||||
}
|
||||
Item(stringResource(R.string.time_per_position), secondsNames.firstOrNull { it.first == prefs.engineSeconds }?.second ?: "") {
|
||||
Item(stringResource(R.string.time_per_position), secondsNames.firstOrNull { it.first == prefs.engineSeconds }?.second ?: "", icon = Icons.Rounded.Timer) {
|
||||
choice = Choice(R.string.time_per_position, secondsNames.map { it.second }, secondsNames.indexOfFirst { it.first == prefs.engineSeconds }) { i ->
|
||||
set { it.copy(engineSeconds = secondsNames[i].first) }
|
||||
}
|
||||
}
|
||||
Item(stringResource(R.string.threads), "${prefs.engineThreads}") {
|
||||
Item(stringResource(R.string.threads), "${prefs.engineThreads}", icon = Icons.Rounded.DeveloperBoard) {
|
||||
choice = Choice(R.string.threads, (1..cores).map { "$it" }, prefs.engineThreads - 1) { i -> set { it.copy(engineThreads = i + 1) } }
|
||||
}
|
||||
val hashes = listOf(16, 32, 64, 128, 256)
|
||||
val hashNames = hashes.map { stringResource(R.string.megabytes, it) }
|
||||
Item(stringResource(R.string.memory), stringResource(R.string.megabytes, prefs.engineHashMb)) {
|
||||
Item(stringResource(R.string.memory), stringResource(R.string.megabytes, prefs.engineHashMb), icon = Icons.Rounded.SdCard) {
|
||||
choice = Choice(R.string.memory, hashNames, hashes.indexOf(prefs.engineHashMb)) { i -> set { it.copy(engineHashMb = hashes[i]) } }
|
||||
}
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.engine_battery),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
|
|
@ -176,7 +203,9 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
// A newer version of the app, even with its card hidden (android-ui.md §25.5).
|
||||
Item(stringResource(R.string.about), aboutUpdateLine(), valueColor = MaterialTheme.colorScheme.primary, onClick = onAbout)
|
||||
Cards {
|
||||
Item(stringResource(R.string.about), aboutUpdateLine(), valueColor = MaterialTheme.colorScheme.primary, icon = Icons.Rounded.Info, onClick = onAbout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,44 +279,75 @@ private fun Group(title: String) {
|
|||
)
|
||||
}
|
||||
|
||||
/// A group's items as cards (android-lists.md §6): 16 dp corners outside, 4 dp between
|
||||
/// them, 2 dp of the background between cards.
|
||||
@Composable
|
||||
private fun Item(title: String, value: String?, valueColor: androidx.compose.ui.graphics.Color = androidx.compose.ui.graphics.Color.Unspecified, onClick: (() -> Unit)?) {
|
||||
private fun Cards(content: @Composable androidx.compose.foundation.layout.ColumnScope.() -> Unit) {
|
||||
Column(
|
||||
Modifier.padding(horizontal = 12.dp).clip(RoundedCornerShape(16.dp)),
|
||||
verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(2.dp),
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
/// One card of a group.
|
||||
@Composable
|
||||
private fun Modifier.card(): Modifier = fillMaxWidth().clip(RoundedCornerShape(4.dp)).background(MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
|
||||
/// An item's icon: 24 dp, then 16 dp to its text.
|
||||
@Composable
|
||||
private fun ItemIcon(icon: androidx.compose.ui.graphics.vector.ImageVector?) {
|
||||
if (icon == null) return
|
||||
Icon(icon, null, tint = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.size(24.dp))
|
||||
Spacer(Modifier.width(16.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Item(
|
||||
title: String,
|
||||
value: String?,
|
||||
valueColor: androidx.compose.ui.graphics.Color = androidx.compose.ui.graphics.Color.Unspecified,
|
||||
icon: androidx.compose.ui.graphics.vector.ImageVector? = null,
|
||||
onClick: (() -> Unit)?,
|
||||
) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.card()
|
||||
.heightIn(min = 56.dp)
|
||||
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier)
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge)
|
||||
if (value != null) {
|
||||
Text(value, style = MaterialTheme.typography.bodyMedium, color = valueColor.takeOrElse { MaterialTheme.colorScheme.onSurfaceVariant })
|
||||
ItemIcon(icon)
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge)
|
||||
if (value != null) {
|
||||
Text(value, style = MaterialTheme.typography.bodyMedium, color = valueColor.takeOrElse { MaterialTheme.colorScheme.onSurfaceVariant })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A line that tells, not a button.
|
||||
@Composable
|
||||
private fun Status(text: String) {
|
||||
Text(
|
||||
text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
private fun Status(text: String, icon: androidx.compose.ui.graphics.vector.ImageVector? = null) {
|
||||
Row(Modifier.card().heightIn(min = 56.dp).padding(horizontal = 16.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
ItemIcon(icon)
|
||||
Text(text, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Toggle(title: String, value: Boolean, onChange: (Boolean) -> Unit) {
|
||||
private fun Toggle(title: String, value: Boolean, icon: androidx.compose.ui.graphics.vector.ImageVector? = null, onChange: (Boolean) -> Unit) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.card()
|
||||
.heightIn(min = 56.dp)
|
||||
.selectable(selected = value, role = Role.Switch) { onChange(!value) }
|
||||
.padding(horizontal = 16.dp),
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
ItemIcon(icon)
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f))
|
||||
Switch(checked = value, onCheckedChange = null)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -545,4 +545,7 @@
|
|||
<string name="player_written_new">✓ Neue Datenbank „%1$s“, Nr. %2$s ›</string>
|
||||
<string name="player_write_failed">Konnte nicht in „%1$s“ schreiben: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Eine neue Partie ersetzt sie.</string>
|
||||
<string name="last_opened">Zuletzt geöffnet</string>
|
||||
<string name="play_adjourned_title">Partie gegen Maia %1$s</string>
|
||||
<string name="play_move_n">Zug %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -553,4 +553,7 @@
|
|||
<string name="player_written_new">✓ Base nueva «%1$s», n.º %2$s ›</string>
|
||||
<string name="player_write_failed">No se pudo escribir en «%1$s»: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Una partida nueva la sustituye.</string>
|
||||
<string name="last_opened">Abierta por última vez</string>
|
||||
<string name="play_adjourned_title">Partida contra Maia %1$s</string>
|
||||
<string name="play_move_n">jugada %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -553,4 +553,7 @@
|
|||
<string name="player_written_new">✓ Nouvelle base « %1$s », n° %2$s ›</string>
|
||||
<string name="player_write_failed">Impossible d’écrire dans « %1$s » : %2$s</string>
|
||||
<string name="play_adjourned_replaced">Une nouvelle partie la remplace.</string>
|
||||
<string name="last_opened">Ouverte en dernier</string>
|
||||
<string name="play_adjourned_title">Partie contre Maia %1$s</string>
|
||||
<string name="play_move_n">coup %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -553,4 +553,7 @@
|
|||
<string name="player_written_new">✓ Nuovo database «%1$s», n. %2$s ›</string>
|
||||
<string name="player_write_failed">Impossibile scrivere in «%1$s»: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Una nuova partita la sostituisce.</string>
|
||||
<string name="last_opened">Aperta per ultima</string>
|
||||
<string name="play_adjourned_title">Partita contro Maia %1$s</string>
|
||||
<string name="play_move_n">mossa %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -546,4 +546,7 @@
|
|||
<string name="player_written_new">✓ Жаңа база «%1$s», № %2$s ›</string>
|
||||
<string name="player_write_failed">«%1$s» базасына жазу мүмкін болмады: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Жаңа ойын оның орнын басады.</string>
|
||||
<string name="last_opened">Соңғы ашылған</string>
|
||||
<string name="play_adjourned_title">Maia %1$s-мен ойын</string>
|
||||
<string name="play_move_n">%1$d-жүріс</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -554,4 +554,7 @@
|
|||
<string name="player_written_new">✓ Nova base «%1$s», n.º %2$s ›</string>
|
||||
<string name="player_write_failed">Não foi possível gravar em «%1$s»: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Uma nova partida a substitui.</string>
|
||||
<string name="last_opened">Aberta por último</string>
|
||||
<string name="play_adjourned_title">Partida contra a Maia %1$s</string>
|
||||
<string name="play_move_n">lance %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -561,4 +561,7 @@
|
|||
<string name="player_written_new">✓ Создана база «%1$s», № %2$s ›</string>
|
||||
<string name="player_write_failed">Не удалось записать в «%1$s»: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Новая партия заменит её.</string>
|
||||
<string name="last_opened">Открыта последней</string>
|
||||
<string name="play_adjourned_title">Партия с Maia %1$s</string>
|
||||
<string name="play_move_n">%1$d-й ход</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -544,4 +544,7 @@
|
|||
<string name="player_written_new">✓ Yangi baza «%1$s», № %2$s ›</string>
|
||||
<string name="player_write_failed">«%1$s» ga yozib bo‘lmadi: %2$s</string>
|
||||
<string name="play_adjourned_replaced">Yangi o‘yin uning o‘rnini oladi.</string>
|
||||
<string name="last_opened">Oxirgi ochilgan</string>
|
||||
<string name="play_adjourned_title">Maia %1$s bilan o‘yin</string>
|
||||
<string name="play_move_n">%1$d-yurish</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -549,4 +549,7 @@
|
|||
<string name="player_written_new">✓ New database “%1$s”, No. %2$s ›</string>
|
||||
<string name="player_write_failed">Could not write to “%1$s”: %2$s</string>
|
||||
<string name="play_adjourned_replaced">A new game replaces it.</string>
|
||||
<string name="last_opened">Last opened</string>
|
||||
<string name="play_adjourned_title">Game against Maia %1$s</string>
|
||||
<string name="play_move_n">move %1$d</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue