Android: fixes after testing (saved copy asks on leaving, forms survive turning, names, cleanup, dates), Maia's «thinking…»
- A copy saved into an own database is that database's game: leaving with new changes asks; the source file's paging goes. - The save sheet, data form and leave question survive turning the phone; the form starts from the game each time it opens. - A new database's default name is free («My games 2»); an own file left by a deletion whose Undo was cut short is removed at start. - «Undo» in the menu; «Make it the main line» offers Undo; «Elo» translated; 31.02 is not a date. - «thinking…» with a spinner beside Maia's name instead of the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9e7314836d
commit
ed7d040bad
15 changed files with 76 additions and 19 deletions
|
|
@ -167,6 +167,9 @@ class Library(private val context: Context) {
|
|||
listOf("$stem.pgn", "$stem.online.json", "$stem.online.lock")
|
||||
}.toSet()
|
||||
onlineDir.listFiles()?.filter { it.name !in online }?.forEach { it.delete() }
|
||||
// An own database deleted while its "Undo" was offered, the app closed meanwhile.
|
||||
val own = _entries.value.filter { it.source == Source.Own }.map { it.location }.toSet()
|
||||
ownDir.listFiles()?.filter { it.name !in own }?.forEach { it.delete() }
|
||||
val used = _entries.value.mapNotNull { it.tree ?: it.location.takeIf { _ -> it.source == Source.File || it.source == Source.ChessBase } }.toSet()
|
||||
for (p in context.contentResolver.persistedUriPermissions) {
|
||||
if (p.uri.toString() !in used) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.BoxWithConstraints
|
|||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
|
@ -151,6 +152,8 @@ fun PlayerLine(
|
|||
nameColor: Color = Color.Unspecified,
|
||||
maxLines: Int = 1,
|
||||
abbreviate: Boolean = true,
|
||||
/// What the player is doing now («thinking…» of Maia, android-play.md §31.3).
|
||||
status: String? = null,
|
||||
) {
|
||||
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
|
||||
if (disc != null) {
|
||||
|
|
@ -164,6 +167,10 @@ fun PlayerLine(
|
|||
Text(elo, style = MaterialTheme.typography.bodyMedium.merge(Tabular), color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
}
|
||||
if (status != null) {
|
||||
androidx.compose.material3.CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp)
|
||||
Text(status, Modifier.padding(start = 6.dp), style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
Text(
|
||||
result ?: "",
|
||||
style = style.merge(Tabular),
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
}
|
||||
|
||||
/// "My games", or "My games 2" when that one is taken.
|
||||
private fun freeName(base: String, taken: List<String>): String {
|
||||
fun freeName(base: String, taken: List<String>): String {
|
||||
if (base !in taken) return base
|
||||
var i = 2
|
||||
while ("$base $i" in taken) i++
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ fun pgnDateOf(text: String): String? {
|
|||
if (t.isEmpty()) return ""
|
||||
Regex("""(\d{4})(?:[.\-/](\d{1,2}|\?\?))?(?:[.\-/](\d{1,2}|\?\?))?""").matchEntire(t)?.let { m ->
|
||||
val (y, mo, d) = m.destructured
|
||||
return listOf(y, part(mo, 12) ?: return null, part(d, 31) ?: return null).joinToString(".")
|
||||
return listOf(y, part(mo, 12) ?: return null, part(d, 31) ?: return null).joinToString(".").takeIf(::realDay)
|
||||
}
|
||||
Regex("""(\d{1,2})[.\-/](\d{1,2})[.\-/](\d{4})""").matchEntire(t)?.let { m ->
|
||||
val (d, mo, y) = m.destructured
|
||||
return listOf(y, part(mo, 12) ?: return null, part(d, 31) ?: return null).joinToString(".")
|
||||
return listOf(y, part(mo, 12) ?: return null, part(d, 31) ?: return null).joinToString(".").takeIf(::realDay)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
@ -63,6 +63,13 @@ private fun part(p: String, max: Int): String? = when {
|
|||
else -> null
|
||||
}
|
||||
|
||||
/// A day that the month has (31.02 is not one).
|
||||
private fun realDay(date: String): Boolean {
|
||||
val (y, m, d) = date.split('.').map { it.toIntOrNull() } + listOf(null, null, null)
|
||||
if (y == null || m == null || d == null) return true
|
||||
return runCatching { java.time.LocalDate.of(y, m, d) }.isSuccess
|
||||
}
|
||||
|
||||
private val RESULTS = listOf("1-0", "1/2-1/2", "0-1", "*")
|
||||
|
||||
/// The game's data (android-play.md §30.5): players and ratings, event, place, date,
|
||||
|
|
@ -115,11 +122,11 @@ fun GameDataForm(game: GameData, doneLabel: String, onDone: (List<Tag>, String)
|
|||
val digits = KeyboardOptions(keyboardType = KeyboardType.Number)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
OutlinedTextField(white, { white = it }, Modifier.weight(1f), label = { Text(stringResource(R.string.tag_white)) }, singleLine = true)
|
||||
OutlinedTextField(whiteElo, { v -> whiteElo = v.filter(Char::isDigit).take(4) }, Modifier.width(88.dp), label = { Text("Elo") }, singleLine = true, keyboardOptions = digits)
|
||||
OutlinedTextField(whiteElo, { v -> whiteElo = v.filter(Char::isDigit).take(4) }, Modifier.width(88.dp), label = { Text(stringResource(R.string.elo)) }, singleLine = true, keyboardOptions = digits)
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
OutlinedTextField(black, { black = it }, Modifier.weight(1f), label = { Text(stringResource(R.string.tag_black)) }, singleLine = true)
|
||||
OutlinedTextField(blackElo, { v -> blackElo = v.filter(Char::isDigit).take(4) }, Modifier.width(88.dp), label = { Text("Elo") }, singleLine = true, keyboardOptions = digits)
|
||||
OutlinedTextField(blackElo, { v -> blackElo = v.filter(Char::isDigit).take(4) }, Modifier.width(88.dp), label = { Text(stringResource(R.string.elo)) }, singleLine = true, keyboardOptions = digits)
|
||||
}
|
||||
OutlinedTextField(event, { event = it }, Modifier.fillMaxWidth(), label = { Text(stringResource(R.string.tag_event)) }, singleLine = true)
|
||||
OutlinedTextField(site, { site = it }, Modifier.fillMaxWidth(), label = { Text(stringResource(R.string.tag_site)) }, singleLine = true)
|
||||
|
|
|
|||
|
|
@ -422,6 +422,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
// «Play on from here» asked for at this move.
|
||||
var playFrom by remember { mutableStateOf<Int?>(null) }
|
||||
val deletedText = stringResource(R.string.moves_deleted)
|
||||
val mainText = stringResource(R.string.made_main)
|
||||
val undoText = stringResource(R.string.undo_action)
|
||||
fun undo() {
|
||||
edit?.undo()?.let { apply(it) }
|
||||
|
|
@ -551,11 +552,14 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
var saves by remember { mutableIntStateOf(0) }
|
||||
@Suppress("UNUSED_EXPRESSION") saves
|
||||
val modified = g != null && edit?.isModified() == true
|
||||
var saving by remember { mutableStateOf(false) }
|
||||
// Kept when the phone turns (the activity is made again).
|
||||
var saving by rememberSaveable { mutableStateOf(false) }
|
||||
// The game's data form; `firstSave`: a new game's first save asks for it first.
|
||||
var editingData by remember { mutableStateOf(false) }
|
||||
var firstSave by remember { mutableStateOf(false) }
|
||||
var leaving by remember { mutableStateOf(false) }
|
||||
var editingData by rememberSaveable { mutableStateOf(false) }
|
||||
var firstSave by rememberSaveable { mutableStateOf(false) }
|
||||
// Each opening of the form starts from the game (its fields are kept only while open).
|
||||
var formOpening by rememberSaveable { mutableIntStateOf(0) }
|
||||
var leaving by rememberSaveable { mutableStateOf(false) }
|
||||
var afterSave by remember { mutableStateOf<(() -> Unit)?>(null) }
|
||||
val ownEntries = libraryEntries.filter { it.source == Source.Own }
|
||||
val savedText = stringResource(R.string.saved_to)
|
||||
|
|
@ -589,6 +593,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
newGame && !playGame -> {
|
||||
firstSave = true
|
||||
editingData = true
|
||||
formOpening++
|
||||
}
|
||||
else -> saving = true
|
||||
}
|
||||
|
|
@ -597,7 +602,8 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
// new one); moves in someone else's game are for trying out (owner's decision).
|
||||
// A game against Maia: put aside while it goes on (no question); after its end like
|
||||
// a new game, and gone from hand once left.
|
||||
val asksOnLeave = modified && (ownGame || newGame || (playGame && runOver != null))
|
||||
// A copy saved into an own database is that database's game from then on.
|
||||
val asksOnLeave = modified && (ownGame || newGame || held.savedTo != null || (playGame && runOver != null))
|
||||
val exit: () -> Unit = {
|
||||
if (playGame && held.play.value?.over?.value != null) app.maiaGames.clear()
|
||||
onBack()
|
||||
|
|
@ -916,7 +922,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
val placeLine = if (playGame && run != null) {
|
||||
stringResource(R.string.play_adjourned_sub, stringResource(if (run.meta.userWhite) R.string.play_as_white else R.string.play_as_black), stringResource(R.string.play_untimed))
|
||||
} else joinKnown(
|
||||
if (total > 0) stringResource(R.string.game_of, place + 1, total) else "",
|
||||
if (total > 0 && held.savedTo == null) stringResource(R.string.game_of, place + 1, total) else "",
|
||||
round?.let { stringResource(R.string.tag_round).lowercase() + " " + it } ?: "",
|
||||
)
|
||||
Column(
|
||||
|
|
@ -951,7 +957,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
else -> held.savedTo?.first?.let { app.library.entry(it) }?.let { stringResource(R.string.save_in, displayName(it)) }
|
||||
} ?: stringResource(R.string.save_to_mine)
|
||||
IconButton(onClick = { save() }) { Icon(Icons.Rounded.Save, where) }
|
||||
} else if (!newGame && !playGame) {
|
||||
} else if (!newGame && !playGame && held.savedTo == null) {
|
||||
IconButton(onClick = { place -= 1 }, enabled = place > 0) {
|
||||
Icon(Icons.Rounded.ChevronLeft, stringResource(R.string.previous_game))
|
||||
}
|
||||
|
|
@ -964,7 +970,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
|
||||
// First, and only when there is something to take back (§29.6).
|
||||
if (g != null && edit?.canUndo() == true) {
|
||||
DropdownMenuItem(text = { Text(stringResource(R.string.undo)) }, onClick = {
|
||||
DropdownMenuItem(text = { Text(stringResource(R.string.undo_menu)) }, onClick = {
|
||||
menu = false
|
||||
undo()
|
||||
})
|
||||
|
|
@ -1043,10 +1049,10 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
val thinkingText = stringResource(R.string.play_thinking)
|
||||
val maiaThinks = { white: Boolean -> if (gameOn && runThinking && run?.meta?.userWhite != white) thinkingText else null }
|
||||
val whiteBar: @Composable () -> Unit = {
|
||||
PlayerBar(whiteName ?: whiteLabel, elo(tag("WhiteElo")), true, maiaThinks(true) ?: sideResult(result, true), known = whiteName != null, abbreviate = !study)
|
||||
PlayerBar(whiteName ?: whiteLabel, elo(tag("WhiteElo")), true, sideResult(result, true), known = whiteName != null, abbreviate = !study, status = maiaThinks(true))
|
||||
}
|
||||
val blackBar: @Composable () -> Unit = {
|
||||
PlayerBar(blackName ?: blackLabel, elo(tag("BlackElo")), false, maiaThinks(false) ?: sideResult(result, false), known = blackName != null)
|
||||
PlayerBar(blackName ?: blackLabel, elo(tag("BlackElo")), false, sideResult(result, false), known = blackName != null, status = maiaThinks(false))
|
||||
}
|
||||
val topBar = if (flipped) whiteBar else blackBar
|
||||
val bottomBar = if (flipped) blackBar else whiteBar
|
||||
|
|
@ -1096,6 +1102,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
TextButton(onClick = {
|
||||
info = false
|
||||
editingData = true
|
||||
formOpening++
|
||||
}) { Text(stringResource(R.string.edit)) }
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1103,7 +1110,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
},
|
||||
)
|
||||
}
|
||||
if (editingData && g != null) {
|
||||
if (editingData && g != null) androidx.compose.runtime.key(formOpening) {
|
||||
GameDataForm(
|
||||
g,
|
||||
doneLabel = stringResource(if (firstSave) R.string.next else R.string.done),
|
||||
|
|
@ -1233,7 +1240,12 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
},
|
||||
onMakeMain = {
|
||||
moveSheet = null
|
||||
runCatching { edit?.makeMain(sheetMove.toUInt()) }.getOrNull()?.let { apply(it) }
|
||||
runCatching { edit?.makeMain(sheetMove.toUInt()) }.getOrNull()?.let { e ->
|
||||
apply(e)
|
||||
scope.launch {
|
||||
if (snackbar.showSnackbar(mainText, undoText, duration = SnackbarDuration.Short) == SnackbarResult.ActionPerformed) undo()
|
||||
}
|
||||
}
|
||||
},
|
||||
onDelete = {
|
||||
moveSheet = null
|
||||
|
|
@ -1475,7 +1487,7 @@ private fun pgnDate(date: String): String {
|
|||
/// A player above or below the board (§7.11): the side's disc, the name (full while it
|
||||
/// fits), the rating, the share of the result. A missing name shows the side, greyed.
|
||||
@Composable
|
||||
private fun PlayerBar(name: String, elo: String, white: Boolean, result: String?, known: Boolean, abbreviate: Boolean = true) {
|
||||
private fun PlayerBar(name: String, elo: String, white: Boolean, result: String?, known: Boolean, abbreviate: Boolean = true, status: String? = null) {
|
||||
PlayerLine(
|
||||
name = name,
|
||||
elo = elo,
|
||||
|
|
@ -1486,6 +1498,7 @@ private fun PlayerBar(name: String, elo: String, white: Boolean, result: String?
|
|||
disc = white,
|
||||
nameColor = if (known) androidx.compose.ui.graphics.Color.Unspecified else MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
abbreviate = abbreviate,
|
||||
status = status,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fun SaveSheet(own: List<DbEntry>, last: String?, onSave: (DbEntry) -> Unit, onCr
|
|||
var chosen by remember { mutableStateOf(own.firstOrNull { it.id == last }?.id ?: own.firstOrNull()?.id) }
|
||||
var creating by remember { mutableStateOf(own.isEmpty()) }
|
||||
val defaultName = stringResource(R.string.own_default_name)
|
||||
var name by remember { mutableStateOf(defaultName) }
|
||||
var name by remember { mutableStateOf(freeName(defaultName, own.map { it.name })) }
|
||||
ModalBottomSheet(onDismissRequest = onDismiss) {
|
||||
Column(Modifier.fillMaxWidth().padding(bottom = 24.dp)) {
|
||||
Text(stringResource(R.string.save_to_db), style = MaterialTheme.typography.titleLarge, modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp))
|
||||
|
|
|
|||
|
|
@ -514,4 +514,7 @@
|
|||
<string name="play_from_maia">Von hier gegen Maia weiterspielen…</string>
|
||||
<string name="play_from_label">Nach %1$s</string>
|
||||
<string name="sound">Ton</string>
|
||||
<string name="undo_menu">Rückgängig</string>
|
||||
<string name="made_main">Jetzt die Hauptvariante</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -522,4 +522,7 @@
|
|||
<string name="play_from_maia">Seguir desde aquí contra Maia…</string>
|
||||
<string name="play_from_label">Tras %1$s</string>
|
||||
<string name="sound">Sonido</string>
|
||||
<string name="undo_menu">Deshacer</string>
|
||||
<string name="made_main">Ahora es la línea principal</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -522,4 +522,7 @@
|
|||
<string name="play_from_maia">Continuer d’ici contre Maia…</string>
|
||||
<string name="play_from_label">Après %1$s</string>
|
||||
<string name="sound">Son</string>
|
||||
<string name="undo_menu">Annuler</string>
|
||||
<string name="made_main">Ligne principale désormais</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -522,4 +522,7 @@
|
|||
<string name="play_from_maia">Continua da qui contro Maia…</string>
|
||||
<string name="play_from_label">Dopo %1$s</string>
|
||||
<string name="sound">Suono</string>
|
||||
<string name="undo_menu">Annulla</string>
|
||||
<string name="made_main">Ora è la linea principale</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -515,4 +515,7 @@
|
|||
<string name="play_from_maia">Осы жерден Maia-мен жалғастыру…</string>
|
||||
<string name="play_from_label">%1$s кейін</string>
|
||||
<string name="sound">Дыбыс</string>
|
||||
<string name="undo_menu">Болдырмау</string>
|
||||
<string name="made_main">Енді негізгі нұсқа</string>
|
||||
<string name="elo">Эло</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -523,4 +523,7 @@
|
|||
<string name="play_from_maia">Continuar daqui contra a Maia…</string>
|
||||
<string name="play_from_label">Depois de %1$s</string>
|
||||
<string name="sound">Som</string>
|
||||
<string name="undo_menu">Desfazer</string>
|
||||
<string name="made_main">Agora é a linha principal</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -530,4 +530,7 @@
|
|||
<string name="play_from_maia">Играть отсюда с Maia…</string>
|
||||
<string name="play_from_label">После %1$s</string>
|
||||
<string name="sound">Звук</string>
|
||||
<string name="undo_menu">Отменить</string>
|
||||
<string name="made_main">Теперь основной вариант</string>
|
||||
<string name="elo">Эло</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -513,4 +513,7 @@
|
|||
<string name="play_from_maia">Shu yerdan Maia bilan davom ettirish…</string>
|
||||
<string name="play_from_label">%1$s dan keyin</string>
|
||||
<string name="sound">Ovoz</string>
|
||||
<string name="undo_menu">Bekor qilish</string>
|
||||
<string name="made_main">Endi asosiy variant</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -518,4 +518,7 @@
|
|||
<string name="play_from_maia">Play on from here with Maia…</string>
|
||||
<string name="play_from_label">After %1$s</string>
|
||||
<string name="sound">Sound</string>
|
||||
<string name="undo_menu">Undo</string>
|
||||
<string name="made_main">Now the main line</string>
|
||||
<string name="elo">Elo</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue