Android: the app updates itself; one release check for the desktop and the phone
- crates/releases: the latest release on GitHub, its files and SHA-256 sums, shared by the desktop updater and the phone (desktop update.rs keeps its installers). - mobile-api check_release: a newer release with its APKs and sums; a desktop-only release is no update, one without the light APK's sum cannot be checked. - Android (android-ui.md §25): a check at start and on return once a day (switch and «Check now» in About), a card over the databases, a sheet through the install permission, the download (DownloadManager), the SHA-256, the full build keeping its engine network, and PackageInstaller; the state survives restarts, the update's snackbar waits for a screen. Network state permission for both builds (the full one crashed without it). Debug builds may ask a test server (CP_UPDATE_API). - Release notes on GitHub come from this version's CHANGELOG section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
136f5320a8
commit
7f23bca320
35 changed files with 2502 additions and 138 deletions
4
androidApp/app/src/debug/AndroidManifest.xml
Normal file
4
androidApp/app/src/debug/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application android:networkSecurityConfig="@xml/network_security_config" />
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Debug builds only: a test release served over plain HTTP by the emulator's host
|
||||
(build.gradle.kts, CP_UPDATE_API). Release builds keep Android's default: HTTPS only. -->
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="false">10.0.2.2</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This build also downloads the network of Stockfish on request (on Wi-Fi or not). -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
</manifest>
|
||||
|
|
@ -2,6 +2,13 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Games from Lichess and Chess.com, only when asked for (android-ui.md §23). -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- Whether there is a network, before a download (the engine's, an update) and a check
|
||||
for updates: in both builds. -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- The app installs its own updates (android-ui.md §25); the second one lets Android
|
||||
skip its question when the app installed the previous version itself. -->
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />
|
||||
|
||||
<application
|
||||
android:name=".ChessPenguinApp"
|
||||
|
|
@ -46,6 +53,10 @@
|
|||
<data android:mimeType="application/octet-stream" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- The package installer's answer to an update (data/AppUpdates.kt). -->
|
||||
<receiver
|
||||
android:name=".data.InstallResult"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import android.net.Uri
|
||||
import android.provider.OpenableColumns
|
||||
import io.github.vrubelroman.chesspenguin.data.AppUpdates
|
||||
import io.github.vrubelroman.chesspenguin.data.DbEntry
|
||||
import io.github.vrubelroman.chesspenguin.data.EngineFiles
|
||||
import io.github.vrubelroman.chesspenguin.data.Library
|
||||
|
|
@ -31,6 +32,8 @@ class ChessPenguinApp : Application() {
|
|||
val engineFiles by lazy { EngineFiles(this, scope) }
|
||||
/// Games from Lichess and Chess.com being downloaded (android-ui.md §23).
|
||||
val downloads by lazy { OnlineDownloads(library, scope) }
|
||||
/// The app's own updates (android-ui.md §25).
|
||||
val updates by lazy { AppUpdates(this, scope, engineFiles) }
|
||||
|
||||
/// The games shown on the list of each database (after a search), for paging
|
||||
/// games from the game screen: database id → game numbers.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package io.github.vrubelroman.chesspenguin
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import kotlinx.coroutines.launch
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.graphics.Color
|
||||
|
|
@ -35,7 +39,20 @@ class MainActivity : ComponentActivity() {
|
|||
enableEdgeToEdge()
|
||||
// Not again when the activity is made anew (turned): it was taken the first time.
|
||||
if (savedInstanceState == null) receive(intent)
|
||||
val settings = (application as ChessPenguinApp).settings
|
||||
val app = application as ChessPenguinApp
|
||||
val settings = app.settings
|
||||
// Android's question «Update this app?» is put on the screen only while the app is
|
||||
// on it (the installer may answer while the user is elsewhere).
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
app.updates.confirm.collect { confirm ->
|
||||
if (confirm != null) {
|
||||
app.updates.confirmShown()
|
||||
startActivity(confirm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setContent {
|
||||
val prefs by settings.prefs.collectAsState()
|
||||
val dark = when (prefs.theme) {
|
||||
|
|
@ -75,8 +92,21 @@ class MainActivity : ComponentActivity() {
|
|||
(application as ChessPenguinApp).receive(uri)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
val updates = (application as ChessPenguinApp).updates
|
||||
updates.foreground = true
|
||||
updates.checkIfDue()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(application as ChessPenguinApp).updates.onResume()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
(application as ChessPenguinApp).updates.foreground = false
|
||||
// Gone to the background or closed, not turned.
|
||||
if (!isChangingConfigurations) (application as ChessPenguinApp).leftApp()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import uniffi.mobile_api.ApiException
|
|||
import java.io.FileNotFoundException
|
||||
import io.github.vrubelroman.chesspenguin.ui.app
|
||||
import io.github.vrubelroman.chesspenguin.ui.openProblem
|
||||
import io.github.vrubelroman.chesspenguin.ui.UpdateSheet
|
||||
import androidx.navigation3.runtime.NavKey
|
||||
import androidx.navigation3.runtime.entryProvider
|
||||
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
|
||||
|
|
@ -76,6 +77,9 @@ fun MainNavigation() {
|
|||
show(it.entry)
|
||||
}
|
||||
}
|
||||
// The app's update, over any screen (android-ui.md §25.3).
|
||||
val updateSheet by app.updates.sheet.collectAsState()
|
||||
if (updateSheet) UpdateSheet()
|
||||
when (val i = incoming) {
|
||||
Incoming.Opening -> Dialog(onDismissRequest = {}, properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)) {
|
||||
Surface(shape = MaterialTheme.shapes.extraLarge, color = MaterialTheme.colorScheme.surfaceContainerHigh) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,648 @@
|
|||
package io.github.vrubelroman.chesspenguin.data
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.storage.StorageManager
|
||||
import io.github.vrubelroman.chesspenguin.BuildConfig
|
||||
import io.github.vrubelroman.chesspenguin.ChessPenguinApp
|
||||
import io.github.vrubelroman.chesspenguin.R
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import uniffi.mobile_api.ReleaseCheck
|
||||
import uniffi.mobile_api.checkRelease
|
||||
import uniffi.mobile_api.releaseApi
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.security.MessageDigest
|
||||
|
||||
/// A newer release, as it is kept between starts: its light APK is what is installed.
|
||||
@Serializable
|
||||
data class Update(
|
||||
val version: String,
|
||||
val page: String,
|
||||
val apkName: String,
|
||||
val apkUrl: String,
|
||||
val apkSize: Long,
|
||||
val sha256: String,
|
||||
)
|
||||
|
||||
/// A step that takes seconds and cannot be stopped.
|
||||
enum class UpdateStep { CheckingFile, KeepingEngine, Installing }
|
||||
|
||||
/// Why an update did not go on (android-ui.md §25.3 F).
|
||||
enum class UpdateProblem { NoInternet, DownloadFailed, NoSpace, Corrupt, BadRelease, InstallStorage, Conflict, Blocked, InstallFailed }
|
||||
|
||||
/// Where the update of a known newer release is.
|
||||
sealed interface UpdateState {
|
||||
val update: Update
|
||||
|
||||
data class Available(override val update: Update) : UpdateState
|
||||
|
||||
/// Android needs the user's permission to install apps; `denied`: back without it.
|
||||
data class NeedsPermission(override val update: Update, val denied: Boolean) : UpdateState
|
||||
|
||||
data class Downloading(override val update: Update, val done: Long, val waitingNetwork: Boolean) : UpdateState
|
||||
|
||||
data class Busy(override val update: Update, val step: UpdateStep) : UpdateState
|
||||
|
||||
/// Downloaded and checked; `aborted`: the user said no to Android's question.
|
||||
data class Ready(override val update: Update, val aborted: Boolean) : UpdateState
|
||||
|
||||
data class Failed(override val update: Update, val problem: UpdateProblem, val detail: String?) : UpdateState
|
||||
}
|
||||
|
||||
/// The manual check in About.
|
||||
sealed interface CheckState {
|
||||
data object Idle : CheckState
|
||||
data object Checking : CheckState
|
||||
data object Latest : CheckState
|
||||
data object Offline : CheckState
|
||||
data object Failed : CheckState
|
||||
}
|
||||
|
||||
/// Messages for a snackbar over the app.
|
||||
sealed interface UpdateMessage {
|
||||
data object Ready : UpdateMessage
|
||||
data object Cancelled : UpdateMessage
|
||||
data object Latest : UpdateMessage
|
||||
data class Updated(val from: String, val to: String, val page: String) : UpdateMessage
|
||||
}
|
||||
|
||||
/// The app updating itself (android-ui.md §25): asks GitHub for a newer release (the
|
||||
/// core's check, the same as the desktop's), downloads its light APK with the system's
|
||||
/// download service, checks it against the release's SHA-256 and gives it to Android's
|
||||
/// package installer. What is known is kept, so a restart picks it up where it was.
|
||||
class AppUpdates(private val context: Context, private val scope: CoroutineScope, private val engine: EngineFiles) {
|
||||
private val prefs = context.getSharedPreferences("update", Context.MODE_PRIVATE)
|
||||
private val downloads get() = context.getSystemService(DownloadManager::class.java)
|
||||
private val dir get() = context.getExternalFilesDir("updates")
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
private val api = BuildConfig.UPDATE_API.ifEmpty { releaseApi() }
|
||||
|
||||
private val _state = MutableStateFlow<UpdateState?>(null)
|
||||
/// The known newer release and where its update is; null when there is none.
|
||||
val state: StateFlow<UpdateState?> = _state.asStateFlow()
|
||||
|
||||
private val _check = MutableStateFlow<CheckState>(CheckState.Idle)
|
||||
val check: StateFlow<CheckState> = _check.asStateFlow()
|
||||
|
||||
private val _auto = MutableStateFlow(prefs.getBoolean(AUTO, !BuildConfig.DEBUG))
|
||||
/// «Check for updates at start».
|
||||
val auto: StateFlow<Boolean> = _auto.asStateFlow()
|
||||
|
||||
private val _hidden = MutableStateFlow(prefs.getString(HIDDEN, null))
|
||||
/// The version hidden with «Not now» on the card.
|
||||
val hidden: StateFlow<String?> = _hidden.asStateFlow()
|
||||
|
||||
/// The release was found by «Check now»: its card shows even with the check off.
|
||||
private val _asked = MutableStateFlow(false)
|
||||
val asked: StateFlow<Boolean> = _asked.asStateFlow()
|
||||
|
||||
private val _lastCheck = MutableStateFlow(prefs.getLong(LAST_OK, 0L))
|
||||
/// When the last check that got an answer was made (0: never).
|
||||
val lastCheck: StateFlow<Long> = _lastCheck.asStateFlow()
|
||||
|
||||
private val _message = MutableStateFlow<UpdateMessage?>(null)
|
||||
/// One message for a snackbar; the screen that shows it calls [shown].
|
||||
val message: StateFlow<UpdateMessage?> = _message.asStateFlow()
|
||||
|
||||
fun shown(m: UpdateMessage) {
|
||||
_message.compareAndSet(m, null)
|
||||
if (m is UpdateMessage.Updated) prefs.edit().remove(UPDATED_FROM).remove(UPDATED_PAGE).apply()
|
||||
}
|
||||
|
||||
private val _confirm = MutableStateFlow<Intent?>(null)
|
||||
/// Android's question «Update this app?», to be shown when the app is on the screen.
|
||||
val confirm: StateFlow<Intent?> = _confirm.asStateFlow()
|
||||
|
||||
private val _sheet = MutableStateFlow(prefs.getString(AWAITING_PERMISSION, null) != null)
|
||||
/// The update sheet is open: a finished download goes on to install by itself. It
|
||||
/// opens again after a restart while the user was in the permission's settings.
|
||||
val sheet: StateFlow<Boolean> = _sheet.asStateFlow()
|
||||
/// The app is on the screen (MainActivity's onStart … onStop).
|
||||
@Volatile var foreground = false
|
||||
|
||||
/// The user watches the sheet: a finished download goes on to install. Not when the
|
||||
/// app is in the background — Android would close it unseen (§25.1 p. 6).
|
||||
private val watched get() = _sheet.value && foreground
|
||||
|
||||
fun openSheet() {
|
||||
_sheet.value = true
|
||||
}
|
||||
|
||||
fun closeSheet() {
|
||||
_sheet.value = false
|
||||
}
|
||||
|
||||
private var watching: Job? = null
|
||||
private var session: Int? = null
|
||||
private var confirmShown = false
|
||||
|
||||
init {
|
||||
// The first start of a new version: say so, and forget the update.
|
||||
// Kept until a screen shows it: Android may start the new version in the background
|
||||
// first, only to hand it the installer's answer.
|
||||
prefs.getString(INSTALLING_FROM, null)?.let { from ->
|
||||
if (from != BuildConfig.VERSION_NAME) {
|
||||
prefs.edit()
|
||||
.putString(UPDATED_FROM, from)
|
||||
.putString(UPDATED_PAGE, known()?.page ?: "")
|
||||
.remove(LATEST)
|
||||
.remove(READY)
|
||||
.apply()
|
||||
forgetFile()
|
||||
}
|
||||
prefs.edit().remove(INSTALLING_FROM).apply()
|
||||
}
|
||||
prefs.getString(UPDATED_FROM, null)?.let { from ->
|
||||
_message.value = UpdateMessage.Updated(from, BuildConfig.VERSION_NAME, prefs.getString(UPDATED_PAGE, "") ?: "")
|
||||
}
|
||||
val update = known()
|
||||
when {
|
||||
// Installed by hand from the site, or never newer than this app.
|
||||
update == null || !newer(update.version) -> forgetAll()
|
||||
prefs.getLong(DOWNLOAD, -1L) != -1L -> watch(update, prefs.getLong(DOWNLOAD, -1L))
|
||||
update.sha256.isEmpty() -> _state.value = UpdateState.Failed(update, UpdateProblem.BadRelease, null)
|
||||
prefs.getString(READY, null) == update.version && apk(update).exists() -> _state.value = UpdateState.Ready(update, aborted = false)
|
||||
else -> {
|
||||
forgetFile()
|
||||
_state.value = UpdateState.Available(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On start and on return to the app: a check when one is due (§25.6).
|
||||
fun checkIfDue() {
|
||||
if (!_auto.value || busy()) return
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - _lastCheck.value < DAY || now - prefs.getLong(LAST_ATTEMPT, 0L) < HOUR) return
|
||||
scope.launch { runCheck(manual = false) }
|
||||
}
|
||||
|
||||
/// «Check now» (works with the automatic check off).
|
||||
fun checkNow() {
|
||||
if (_check.value == CheckState.Checking) return
|
||||
scope.launch { runCheck(manual = true) }
|
||||
}
|
||||
|
||||
private suspend fun runCheck(manual: Boolean) {
|
||||
if (busy()) {
|
||||
if (manual) _check.value = CheckState.Idle
|
||||
return
|
||||
}
|
||||
_check.value = CheckState.Checking
|
||||
prefs.edit().putLong(LAST_ATTEMPT, System.currentTimeMillis()).apply()
|
||||
if (!online()) {
|
||||
_check.value = if (manual) CheckState.Offline else CheckState.Idle
|
||||
return
|
||||
}
|
||||
val result = withContext(Dispatchers.IO) { checkRelease(api) }
|
||||
when (result) {
|
||||
is ReleaseCheck.Newer -> {
|
||||
val light = result.release.light ?: return
|
||||
val update = Update(result.release.version, result.release.page, light.name, light.url, light.size.toLong(), light.sha256)
|
||||
checked()
|
||||
_check.value = CheckState.Idle
|
||||
if (manual) {
|
||||
_asked.value = true
|
||||
setHidden(null)
|
||||
}
|
||||
found(update)
|
||||
}
|
||||
is ReleaseCheck.Unverifiable -> {
|
||||
checked()
|
||||
_check.value = CheckState.Idle
|
||||
val light = result.release.light ?: return
|
||||
val update = Update(result.release.version, result.release.page, light.name, light.url, light.size.toLong(), "")
|
||||
if (manual) {
|
||||
_asked.value = true
|
||||
setHidden(null)
|
||||
}
|
||||
found(update)
|
||||
if (!busy()) _state.value = UpdateState.Failed(update, UpdateProblem.BadRelease, null)
|
||||
}
|
||||
is ReleaseCheck.UpToDate -> {
|
||||
checked()
|
||||
_check.value = CheckState.Latest
|
||||
if (manual) _message.value = UpdateMessage.Latest
|
||||
if (!busy()) forgetAll()
|
||||
}
|
||||
is ReleaseCheck.Failed -> _check.value = if (manual) CheckState.Failed else CheckState.Idle
|
||||
}
|
||||
}
|
||||
|
||||
private fun checked() {
|
||||
val now = System.currentTimeMillis()
|
||||
_lastCheck.value = now
|
||||
prefs.edit().putLong(LAST_OK, now).apply()
|
||||
}
|
||||
|
||||
/// A newer release found: a downloaded older one is of no use any more.
|
||||
private fun found(update: Update) {
|
||||
val current = _state.value
|
||||
if (current != null && current.update == update) return
|
||||
if (busy()) return
|
||||
forgetFile()
|
||||
prefs.edit().putString(LATEST, json.encodeToString(update)).remove(READY).apply()
|
||||
if (_hidden.value != null && _hidden.value != update.version) setHidden(null)
|
||||
_state.value = UpdateState.Available(update)
|
||||
}
|
||||
|
||||
fun setAuto(on: Boolean) {
|
||||
_auto.value = on
|
||||
if (!on) _asked.value = false
|
||||
prefs.edit().putBoolean(AUTO, on).apply()
|
||||
if (on) checkIfDue()
|
||||
}
|
||||
|
||||
/// «Not now» on the card: hidden until a newer version.
|
||||
fun hide() {
|
||||
_state.value?.let { setHidden(it.update.version) }
|
||||
}
|
||||
|
||||
private fun setHidden(version: String?) {
|
||||
_hidden.value = version
|
||||
prefs.edit().apply { if (version == null) remove(HIDDEN) else putString(HIDDEN, version) }.apply()
|
||||
}
|
||||
|
||||
/// «Update» / «Try again» / «Download again»: from the permission on to the install.
|
||||
fun start() {
|
||||
val update = _state.value?.update ?: return
|
||||
if (update.sha256.isEmpty()) {
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.BadRelease, null)
|
||||
return
|
||||
}
|
||||
if (!context.packageManager.canRequestPackageInstalls()) {
|
||||
_state.value = UpdateState.NeedsPermission(update, denied = false)
|
||||
return
|
||||
}
|
||||
if (prefs.getString(READY, null) == update.version && apk(update).exists()) {
|
||||
install(update)
|
||||
return
|
||||
}
|
||||
download(update)
|
||||
}
|
||||
|
||||
/// The permission's settings page is being opened: back from it, the update goes on
|
||||
/// (also when Android restarted the app meanwhile).
|
||||
fun permissionAsked() {
|
||||
_state.value?.let { prefs.edit().putString(AWAITING_PERMISSION, it.update.version).apply() }
|
||||
}
|
||||
|
||||
/// Back in the app after the permission's settings page.
|
||||
fun onResume() {
|
||||
prefs.getString(AWAITING_PERMISSION, null)?.let { version ->
|
||||
val update = _state.value?.update
|
||||
prefs.edit().remove(AWAITING_PERMISSION).apply()
|
||||
if (update != null && update.version == version) {
|
||||
if (context.packageManager.canRequestPackageInstalls()) {
|
||||
_sheet.value = true
|
||||
start()
|
||||
} else {
|
||||
_state.value = UpdateState.NeedsPermission(update, denied = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Android's question was closed with no answer: the file waits for «Install».
|
||||
if (confirmShown) {
|
||||
confirmShown = false
|
||||
scope.launch {
|
||||
delay(1500)
|
||||
val s = _state.value
|
||||
if (s is UpdateState.Busy && s.step == UpdateStep.Installing && _confirm.value == null) {
|
||||
abandon()
|
||||
_state.value = UpdateState.Ready(s.update, aborted = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The question was put on the screen.
|
||||
fun confirmShown() {
|
||||
_confirm.value = null
|
||||
confirmShown = true
|
||||
}
|
||||
|
||||
private fun download(update: Update) {
|
||||
if (!online()) {
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.NoInternet, null)
|
||||
return
|
||||
}
|
||||
if (freeSpace() < needed(update)) {
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.NoSpace, null)
|
||||
return
|
||||
}
|
||||
forgetFile()
|
||||
// Under another name while it comes: removing the download from the system's list
|
||||
// deletes its file, and the checked file must stay.
|
||||
val target = File(apk(update).path + ".download")
|
||||
val request = DownloadManager.Request(Uri.parse(update.apkUrl))
|
||||
.setTitle(context.getString(R.string.upd_notification))
|
||||
.setDestinationUri(Uri.fromFile(target))
|
||||
// No "complete" notification: tapping it would open the file past the check.
|
||||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
||||
.setAllowedOverMetered(true)
|
||||
.setAllowedOverRoaming(true)
|
||||
val id = try {
|
||||
downloads.enqueue(request)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.DownloadFailed, e.message)
|
||||
return
|
||||
}
|
||||
prefs.edit().putLong(DOWNLOAD, id).putString(DOWNLOAD_VERSION, update.version).apply()
|
||||
_state.value = UpdateState.Downloading(update, 0, waitingNetwork = false)
|
||||
watch(update, id)
|
||||
}
|
||||
|
||||
/// «Cancel» while downloading.
|
||||
fun cancel() {
|
||||
val update = _state.value?.update ?: return
|
||||
watching?.cancel()
|
||||
val id = prefs.getLong(DOWNLOAD, -1L)
|
||||
if (id != -1L) downloads.remove(id)
|
||||
prefs.edit().remove(DOWNLOAD).remove(DOWNLOAD_VERSION).apply()
|
||||
forgetFile()
|
||||
_state.value = UpdateState.Available(update)
|
||||
_message.value = UpdateMessage.Cancelled
|
||||
}
|
||||
|
||||
/// «Not now» in the sheet after an error: the card shows the release again.
|
||||
fun dismissProblem() {
|
||||
val s = _state.value
|
||||
// The same file would fail the same way: the card keeps saying so.
|
||||
if (s is UpdateState.Failed && s.problem in setOf(UpdateProblem.Conflict, UpdateProblem.Blocked, UpdateProblem.BadRelease)) return
|
||||
if (s is UpdateState.Failed || s is UpdateState.NeedsPermission) {
|
||||
prefs.edit().remove(AWAITING_PERMISSION).apply()
|
||||
val ready = prefs.getString(READY, null) == s.update.version && apk(s.update).exists()
|
||||
_state.value = if (ready) UpdateState.Ready(s.update, aborted = false) else UpdateState.Available(s.update)
|
||||
}
|
||||
}
|
||||
|
||||
private fun watch(update: Update, id: Long) {
|
||||
watching?.cancel()
|
||||
_state.value = UpdateState.Downloading(update, 0, waitingNetwork = false)
|
||||
watching = scope.launch(Dispatchers.Main.immediate) {
|
||||
while (isActive) {
|
||||
val row = withContext(Dispatchers.IO) { progress(id) }
|
||||
if (row == null) {
|
||||
// Removed from the system's list of downloads.
|
||||
prefs.edit().remove(DOWNLOAD).remove(DOWNLOAD_VERSION).apply()
|
||||
_state.value = UpdateState.Available(update)
|
||||
return@launch
|
||||
}
|
||||
when (row.status) {
|
||||
DownloadManager.STATUS_SUCCESSFUL -> {
|
||||
val moved = File(apk(update).path + ".download").renameTo(apk(update))
|
||||
downloads.remove(id)
|
||||
prefs.edit().remove(DOWNLOAD).remove(DOWNLOAD_VERSION).apply()
|
||||
if (moved) {
|
||||
verify(update)
|
||||
} else {
|
||||
forgetFile()
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.DownloadFailed, null)
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
DownloadManager.STATUS_FAILED -> {
|
||||
downloads.remove(id)
|
||||
prefs.edit().remove(DOWNLOAD).remove(DOWNLOAD_VERSION).apply()
|
||||
forgetFile()
|
||||
val space = row.reason == DownloadManager.ERROR_INSUFFICIENT_SPACE
|
||||
_state.value = UpdateState.Failed(update, if (space) UpdateProblem.NoSpace else UpdateProblem.DownloadFailed, null)
|
||||
return@launch
|
||||
}
|
||||
else -> {
|
||||
// A server that does not answer is retried quietly; only a missing network is said.
|
||||
val waiting = row.status == DownloadManager.STATUS_PAUSED && row.reason == DownloadManager.PAUSED_WAITING_FOR_NETWORK
|
||||
_state.value = UpdateState.Downloading(update, row.done.coerceAtLeast(0), waiting)
|
||||
}
|
||||
}
|
||||
delay(500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Row(val status: Int, val reason: Int, val done: Long)
|
||||
|
||||
private fun progress(id: Long): Row? =
|
||||
downloads.query(DownloadManager.Query().setFilterById(id))?.use { c ->
|
||||
if (!c.moveToFirst()) return null
|
||||
Row(
|
||||
c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)),
|
||||
c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON)),
|
||||
c.getLong(c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)),
|
||||
)
|
||||
}
|
||||
|
||||
/// The SHA-256 of the file against the release's; then on to the install when the user
|
||||
/// waits for it in the sheet, or «downloaded» when they are elsewhere.
|
||||
private suspend fun verify(update: Update) {
|
||||
_state.value = UpdateState.Busy(update, UpdateStep.CheckingFile)
|
||||
val file = apk(update)
|
||||
val sum = withContext(Dispatchers.IO) { runCatching { sha256(file) }.getOrNull() }
|
||||
if (sum != update.sha256) {
|
||||
forgetFile()
|
||||
_state.value = UpdateState.Failed(update, UpdateProblem.Corrupt, null)
|
||||
return
|
||||
}
|
||||
prefs.edit().putString(READY, update.version).apply()
|
||||
if (watched) {
|
||||
install(update)
|
||||
} else {
|
||||
_state.value = UpdateState.Ready(update, aborted = false)
|
||||
// With the sheet open the user sees it there.
|
||||
if (!_sheet.value) _message.value = UpdateMessage.Ready
|
||||
}
|
||||
}
|
||||
|
||||
/// «Install»: the engine's network kept (full build), then Android's installer.
|
||||
fun install() {
|
||||
val s = _state.value ?: return
|
||||
if (!context.packageManager.canRequestPackageInstalls()) {
|
||||
start()
|
||||
return
|
||||
}
|
||||
install(s.update)
|
||||
}
|
||||
|
||||
private fun install(update: Update) {
|
||||
scope.launch(Dispatchers.Main.immediate) {
|
||||
if (engine.builtIn) {
|
||||
_state.value = UpdateState.Busy(update, UpdateStep.KeepingEngine)
|
||||
engine.keepBuiltIn()
|
||||
}
|
||||
_state.value = UpdateState.Busy(update, UpdateStep.Installing)
|
||||
val committed = withContext(Dispatchers.IO) { runCatching { commit(apk(update)) } }
|
||||
committed.onFailure { e ->
|
||||
abandon()
|
||||
val problem = if (e is IOException && freeSpace() < update.apkSize * 2) UpdateProblem.InstallStorage else UpdateProblem.InstallFailed
|
||||
_state.value = UpdateState.Failed(update, problem, e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the APK into an installer session and commits it; the answer comes to
|
||||
/// [InstallResult].
|
||||
private fun commit(file: File) {
|
||||
val installer = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL).apply {
|
||||
setAppPackageName(context.packageName)
|
||||
setSize(file.length())
|
||||
// Without Android's question when it allows that (the app installed the last
|
||||
// version itself): the conditions are Android's.
|
||||
setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED)
|
||||
if (Build.VERSION.SDK_INT >= 33) setPackageSource(PackageInstaller.PACKAGE_SOURCE_DOWNLOADED_FILE)
|
||||
}
|
||||
val id = installer.createSession(params)
|
||||
session = id
|
||||
installer.openSession(id).use { s ->
|
||||
file.inputStream().use { input ->
|
||||
s.openWrite("base.apk", 0, file.length()).use { out ->
|
||||
input.copyTo(out, 256 * 1024)
|
||||
s.fsync(out)
|
||||
}
|
||||
}
|
||||
prefs.edit().putString(INSTALLING_FROM, BuildConfig.VERSION_NAME).apply()
|
||||
val intent = Intent(context, InstallResult::class.java).setPackage(context.packageName)
|
||||
// Mutable: the installer fills in the result.
|
||||
val pending = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
|
||||
s.commit(pending.intentSender)
|
||||
}
|
||||
}
|
||||
|
||||
private fun abandon() {
|
||||
session?.let { runCatching { context.packageManager.packageInstaller.abandonSession(it) } }
|
||||
session = null
|
||||
prefs.edit().remove(INSTALLING_FROM).apply()
|
||||
}
|
||||
|
||||
/// The installer's answer (from [InstallResult]).
|
||||
internal fun onInstallResult(status: Int, message: String?, confirm: Intent?) {
|
||||
val update = _state.value?.update ?: return
|
||||
when (status) {
|
||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> _confirm.value = confirm
|
||||
// The process ends with the install: nothing more to show.
|
||||
PackageInstaller.STATUS_SUCCESS -> {}
|
||||
else -> {
|
||||
session = null
|
||||
prefs.edit().remove(INSTALLING_FROM).apply()
|
||||
_confirm.value = null
|
||||
_state.value = when (status) {
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> UpdateState.Ready(update, aborted = true)
|
||||
PackageInstaller.STATUS_FAILURE_STORAGE -> UpdateState.Failed(update, UpdateProblem.InstallStorage, message)
|
||||
PackageInstaller.STATUS_FAILURE_CONFLICT -> UpdateState.Failed(update, UpdateProblem.Conflict, message)
|
||||
PackageInstaller.STATUS_FAILURE_BLOCKED -> UpdateState.Failed(update, UpdateProblem.Blocked, message)
|
||||
else -> UpdateState.Failed(update, UpdateProblem.InstallFailed, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Space the update needs: the file twice (download, install), and the engine's
|
||||
/// network when the full build keeps it first.
|
||||
fun needed(update: Update): Long =
|
||||
2 * update.apkSize + if (engine.builtIn && engine.state.value != NetState.Ready) BuildConfig.NET_SIZE else 0
|
||||
|
||||
/// Downloading, checking or installing: a check waits for it to end.
|
||||
private fun busy(): Boolean = _state.value.let { it is UpdateState.Downloading || it is UpdateState.Busy || it is UpdateState.NeedsPermission }
|
||||
|
||||
private fun known(): Update? = prefs.getString(LATEST, null)?.let { runCatching { json.decodeFromString<Update>(it) }.getOrNull() }
|
||||
|
||||
private fun newer(version: String): Boolean = compare(version, BuildConfig.VERSION_NAME) > 0
|
||||
|
||||
private fun apk(update: Update): File = File(dir ?: context.cacheDir, update.apkName)
|
||||
|
||||
private fun forgetFile() {
|
||||
dir?.listFiles()?.forEach { it.delete() }
|
||||
prefs.edit().remove(READY).apply()
|
||||
}
|
||||
|
||||
private fun forgetAll() {
|
||||
forgetFile()
|
||||
prefs.edit().remove(LATEST).remove(DOWNLOAD).remove(DOWNLOAD_VERSION).remove(AWAITING_PERMISSION).apply()
|
||||
_state.value = null
|
||||
_asked.value = false
|
||||
}
|
||||
|
||||
private fun freeSpace(): Long = try {
|
||||
val storage = context.getSystemService(StorageManager::class.java)
|
||||
storage.getAllocatableBytes(storage.getUuidForPath(context.filesDir))
|
||||
} catch (e: IOException) {
|
||||
context.filesDir.usableSpace
|
||||
}
|
||||
|
||||
private fun online(): Boolean {
|
||||
val cm = context.getSystemService(ConnectivityManager::class.java) ?: return true
|
||||
val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false
|
||||
return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val AUTO = "autoCheck"
|
||||
const val LAST_OK = "lastCheckOk"
|
||||
const val LAST_ATTEMPT = "lastAttempt"
|
||||
const val LATEST = "latest"
|
||||
const val HIDDEN = "hiddenVersion"
|
||||
const val DOWNLOAD = "downloadId"
|
||||
const val DOWNLOAD_VERSION = "downloadVersion"
|
||||
const val READY = "readyVersion"
|
||||
const val AWAITING_PERMISSION = "awaitingPermission"
|
||||
const val INSTALLING_FROM = "installingFrom"
|
||||
const val UPDATED_FROM = "updatedFrom"
|
||||
const val UPDATED_PAGE = "updatedPage"
|
||||
const val DAY = 24 * 60 * 60 * 1000L
|
||||
const val HOUR = 60 * 60 * 1000L
|
||||
}
|
||||
}
|
||||
|
||||
/// "0.15.0" against "0.14.2": the numbers major.minor.patch.
|
||||
fun compare(a: String, b: String): Int {
|
||||
fun parts(v: String) = v.trim().removePrefix("v").split('.').map { p -> p.takeWhile(Char::isDigit).toIntOrNull() ?: 0 }
|
||||
val (x, y) = parts(a) to parts(b)
|
||||
for (i in 0 until maxOf(x.size, y.size)) {
|
||||
val c = (x.getOrElse(i) { 0 }).compareTo(y.getOrElse(i) { 0 })
|
||||
if (c != 0) return c
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
private fun sha256(file: File): String {
|
||||
val digest = MessageDigest.getInstance("SHA-256")
|
||||
file.inputStream().use { input ->
|
||||
val buf = ByteArray(256 * 1024)
|
||||
while (true) {
|
||||
val n = input.read(buf)
|
||||
if (n < 0) break
|
||||
digest.update(buf, 0, n)
|
||||
}
|
||||
}
|
||||
return digest.digest().joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
|
||||
/// The package installer's answer to an update.
|
||||
class InstallResult : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)
|
||||
val message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)
|
||||
val confirm = androidx.core.content.IntentCompat.getParcelableExtra(intent, Intent.EXTRA_INTENT, Intent::class.java)
|
||||
(context.applicationContext as ChessPenguinApp).updates.onInstallResult(status, message, confirm)
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,9 @@ class EngineFiles(private val context: Context, private val scope: CoroutineScop
|
|||
private var job: Job? = null
|
||||
|
||||
init {
|
||||
// A network of another version of Stockfish (kept before an update, §25.6) is of
|
||||
// no use to this one.
|
||||
dir.listFiles()?.filter { it.name != net.name && it.name != part.name }?.forEach { it.delete() }
|
||||
when {
|
||||
installed() -> _state.value = NetState.Ready
|
||||
download() != NO_DOWNLOAD -> {
|
||||
|
|
@ -123,6 +126,24 @@ class EngineFiles(private val context: Context, private val scope: CoroutineScop
|
|||
watch(id)
|
||||
}
|
||||
|
||||
/// Keeps the network of the full build in the app's storage, so that it stays after
|
||||
/// the app is updated to the light build (android-ui.md §25.6). False when it could
|
||||
/// not (no space): the light build then offers the download, as always.
|
||||
suspend fun keepBuiltIn(): Boolean = withContext(Dispatchers.IO) {
|
||||
if (!builtIn || installed()) return@withContext true
|
||||
if (freeSpace() < 2 * BuildConfig.NET_SIZE) return@withContext false
|
||||
try {
|
||||
dir.mkdirs()
|
||||
context.assets.open(BuildConfig.NET_NAME).use { install(it) }
|
||||
_state.value = NetState.Ready
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
part.delete()
|
||||
if (!installed()) _state.value = NetState.Missing
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops a download and throws away what came.
|
||||
fun cancel() {
|
||||
job?.cancel()
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ import androidx.compose.material3.Scaffold
|
|||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.painterResource
|
||||
|
|
@ -58,7 +61,10 @@ private val NOTICES = listOf(
|
|||
@Composable
|
||||
fun AboutScreen(onBack: () -> Unit) {
|
||||
val uri = LocalUriHandler.current
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
UpdateMessages(snackbar)
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbar) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.about)) },
|
||||
|
|
@ -74,7 +80,10 @@ fun AboutScreen(onBack: () -> Unit) {
|
|||
Text(stringResource(R.string.app_name), style = MaterialTheme.typography.titleLarge)
|
||||
val build = stringResource(if (BuildConfig.NET_BUILT_IN) R.string.build_full else R.string.build_light)
|
||||
Text("${BuildConfig.VERSION_NAME} ${stringResource(R.string.alpha)} · $build", color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Spacer(Modifier.height(24.dp))
|
||||
// Right under the version (android-ui.md §25.5).
|
||||
AboutUpdates()
|
||||
Spacer(Modifier.height(24.dp))
|
||||
Text(stringResource(R.string.about_text), style = MaterialTheme.typography.bodyLarge)
|
||||
TextButton(onClick = { uri.openUri(SITE) }, contentPadding = androidx.compose.foundation.layout.PaddingValues(0.dp)) {
|
||||
Text(stringResource(R.string.website))
|
||||
|
|
|
|||
|
|
@ -91,6 +91,15 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
val scope = rememberCoroutineScope()
|
||||
val removedText = stringResource(R.string.removed)
|
||||
val removedCopyText = stringResource(R.string.removed_copy)
|
||||
val update = shownUpdate()
|
||||
val hiddenText = stringResource(R.string.upd_hidden_snack)
|
||||
val onUpdateHidden: () -> Unit = {
|
||||
scope.launch {
|
||||
snackbar.currentSnackbarData?.dismiss()
|
||||
snackbar.showSnackbar(hiddenText)
|
||||
}
|
||||
}
|
||||
UpdateMessages(snackbar)
|
||||
val removedOnlineText = stringResource(R.string.online_removed)
|
||||
val resourcesForSnack = LocalResources.current
|
||||
val openText = stringResource(R.string.online_open_short)
|
||||
|
|
@ -128,6 +137,13 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
val add = { choosing = true }
|
||||
var renaming by remember { mutableStateOf<DbEntry?>(null) }
|
||||
val list = rememberLazyListState()
|
||||
// The card comes when GitHub answers, after the list is drawn: a list at its top then
|
||||
// keeps its first database in place and the card lands above the screen. It is
|
||||
// brought into sight; a list scrolled down by the user stays where it is.
|
||||
val cardShown = update != null
|
||||
LaunchedEffect(cardShown) {
|
||||
if (cardShown && list.firstVisibleItemIndex == 1 && list.firstVisibleItemScrollOffset == 0) list.animateScrollToItem(0)
|
||||
}
|
||||
val expanded by remember { derivedStateOf { list.firstVisibleItemIndex == 0 } }
|
||||
val scroll = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
// The samples are small: read them at once, so their rows show the number of games.
|
||||
|
|
@ -162,16 +178,21 @@ fun DatabasesScreen(onOpen: (String) -> Unit, onAdded: (DbEntry) -> Unit, onSett
|
|||
},
|
||||
) { padding ->
|
||||
if (entries.isEmpty()) {
|
||||
Empty(Modifier.padding(padding), onAdd = add, onSamples = {
|
||||
library.addSamples()
|
||||
library.entries.value.firstOrNull()?.let { onOpen(it.id) }
|
||||
})
|
||||
Column(Modifier.padding(padding)) {
|
||||
update?.let { UpdateCard(it, onHidden = onUpdateHidden) }
|
||||
Empty(Modifier.weight(1f), onAdd = add, onSamples = {
|
||||
library.addSamples()
|
||||
library.entries.value.firstOrNull()?.let { onOpen(it.id) }
|
||||
})
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
Modifier.fillMaxSize(),
|
||||
state = list,
|
||||
contentPadding = PaddingValues(top = padding.calculateTopPadding(), bottom = padding.calculateBottomPadding() + 88.dp),
|
||||
) {
|
||||
// A newer version of the app (android-ui.md §25.2): the first item of the list.
|
||||
update?.let { u -> item(key = "update") { UpdateCard(u, onHidden = onUpdateHidden, modifier = Modifier.animateItem()) } }
|
||||
items(entries, key = { it.id }) { e ->
|
||||
DatabaseRow(
|
||||
e,
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o
|
|||
}
|
||||
val pieces = remember { Pieces(context) }
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
UpdateMessages(snackbar)
|
||||
val scope = rememberCoroutineScope()
|
||||
val view = LocalView.current
|
||||
val hint = stringResource(R.string.board_hint)
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ fun GamesScreen(db: String, onBack: () -> Unit, onGame: (place: Int, query: Stri
|
|||
val scroll = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val download = app.downloads.views.collectAsState().value[db]
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
UpdateMessages(snackbar)
|
||||
val resources = LocalResources.current
|
||||
// How a download of this database ended (§23.3); the list reads it again by itself.
|
||||
LaunchedEffect(db) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.takeOrElse
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
|
@ -65,6 +66,8 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
var sheet by remember { mutableStateOf(false) }
|
||||
val lang = uiLanguage()
|
||||
val scroll = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val snackbar = remember { androidx.compose.material3.SnackbarHostState() }
|
||||
UpdateMessages(snackbar)
|
||||
val size = (BuildConfig.NET_SIZE / 1_000_000).toInt()
|
||||
|
||||
val themeNames = listOf(
|
||||
|
|
@ -88,6 +91,7 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scroll.nestedScrollConnection),
|
||||
snackbarHost = { androidx.compose.material3.SnackbarHost(snackbar) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.settings)) },
|
||||
|
|
@ -115,7 +119,7 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
Toggle(stringResource(R.string.vibration), prefs.vibration) { v -> set { it.copy(vibration = v) } }
|
||||
|
||||
Group(stringResource(R.string.group_look))
|
||||
Item(stringResource(R.string.board_and_pieces), boardLabel(prefs.board) + " · " + prefs.pieces.dir, onBoardStyle)
|
||||
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) {
|
||||
choice = Choice(R.string.theme, themeNames.map { it.second }, themeNames.indexOfFirst { it.first == prefs.theme }) { i ->
|
||||
set { it.copy(theme = themeNames[i].first) }
|
||||
|
|
@ -169,7 +173,8 @@ fun SettingsScreen(onBack: () -> Unit, onAbout: () -> Unit, onBoardStyle: () ->
|
|||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Item(stringResource(R.string.about), null, onAbout)
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +249,7 @@ private fun Group(title: String) {
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun Item(title: String, value: String?, onClick: (() -> Unit)?) {
|
||||
private fun Item(title: String, value: String?, valueColor: androidx.compose.ui.graphics.Color = androidx.compose.ui.graphics.Color.Unspecified, onClick: (() -> Unit)?) {
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
|
|
@ -254,7 +259,9 @@ private fun Item(title: String, value: String?, onClick: (() -> Unit)?) {
|
|||
verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center,
|
||||
) {
|
||||
Text(title, style = MaterialTheme.typography.bodyLarge)
|
||||
if (value != null) Text(value, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
if (value != null) {
|
||||
Text(value, style = MaterialTheme.typography.bodyMedium, color = valueColor.takeOrElse { MaterialTheme.colorScheme.onSurfaceVariant })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,580 @@
|
|||
package io.github.vrubelroman.chesspenguin.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.toggleable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.OpenInNew
|
||||
import androidx.compose.material.icons.rounded.SystemUpdateAlt
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.LiveRegionMode
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.heading
|
||||
import androidx.compose.ui.semantics.liveRegion
|
||||
import androidx.compose.ui.semantics.onClick
|
||||
import androidx.compose.ui.semantics.role
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import io.github.vrubelroman.chesspenguin.BuildConfig
|
||||
import io.github.vrubelroman.chesspenguin.R
|
||||
import io.github.vrubelroman.chesspenguin.data.CheckState
|
||||
import io.github.vrubelroman.chesspenguin.data.NetState
|
||||
import io.github.vrubelroman.chesspenguin.data.UpdateMessage
|
||||
import io.github.vrubelroman.chesspenguin.data.UpdateProblem
|
||||
import io.github.vrubelroman.chesspenguin.data.UpdateState
|
||||
import io.github.vrubelroman.chesspenguin.data.UpdateStep
|
||||
import io.github.vrubelroman.chesspenguin.theme.Tabular
|
||||
|
||||
private const val SITE_URL = "https://chess.vrubel.xyz"
|
||||
|
||||
private fun mb(bytes: Long) = ((bytes + 999_999) / 1_000_000).toInt()
|
||||
|
||||
/// The update the card on «Databases» shows, or null: none known, hidden with «Not now»,
|
||||
/// or the check turned off (unless the user asked for it).
|
||||
@Composable
|
||||
fun shownUpdate(): UpdateState? {
|
||||
val updates = app().updates
|
||||
val state by updates.state.collectAsState()
|
||||
val auto by updates.auto.collectAsState()
|
||||
val hidden by updates.hidden.collectAsState()
|
||||
val asked by updates.asked.collectAsState()
|
||||
val s = state ?: return null
|
||||
if (hidden == s.update.version) return null
|
||||
if (!auto && !asked && s is UpdateState.Available) return null
|
||||
return s
|
||||
}
|
||||
|
||||
/// The card over the list of databases (android-ui.md §25.2).
|
||||
@Composable
|
||||
fun UpdateCard(state: UpdateState, onHidden: () -> Unit, modifier: Modifier = Modifier) {
|
||||
val updates = app().updates
|
||||
val uri = LocalUriHandler.current
|
||||
val update = state.update
|
||||
val title = stringResource(R.string.upd_title, update.version)
|
||||
val progressOnly = state is UpdateState.Downloading || state is UpdateState.Busy
|
||||
val downloadingText = when (state) {
|
||||
is UpdateState.Downloading -> if (state.waitingNetwork) {
|
||||
title + ", " + stringResource(R.string.upd_waiting_net_short)
|
||||
} else {
|
||||
stringResource(R.string.upd_card_downloading, update.version, mb(state.done), mb(update.apkSize))
|
||||
}
|
||||
is UpdateState.Busy -> title + ", " + stepText(state.step)
|
||||
else -> null
|
||||
}
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)
|
||||
.then(
|
||||
if (progressOnly) {
|
||||
Modifier
|
||||
.clickable(role = Role.Button) { updates.openSheet() }
|
||||
.clearAndSetSemantics {
|
||||
contentDescription = downloadingText ?: title
|
||||
role = Role.Button
|
||||
onClick { updates.openSheet(); true }
|
||||
}
|
||||
} else {
|
||||
Modifier
|
||||
},
|
||||
),
|
||||
) {
|
||||
Column(Modifier.padding(start = 16.dp, end = 16.dp, top = 12.dp, bottom = if (progressOnly) 16.dp else 8.dp)) {
|
||||
Row(verticalAlignment = Alignment.Top) {
|
||||
Icon(Icons.Rounded.SystemUpdateAlt, null, tint = MaterialTheme.colorScheme.primary, modifier = Modifier.size(24.dp))
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(
|
||||
title,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
fontWeight = FontWeight.Medium,
|
||||
modifier = Modifier.semantics { heading() },
|
||||
)
|
||||
Spacer(Modifier.height(2.dp))
|
||||
when (state) {
|
||||
is UpdateState.Available, is UpdateState.NeedsPermission ->
|
||||
YouHave(update.page) { uri.openUri(update.page) }
|
||||
is UpdateState.Downloading -> {
|
||||
Spacer(Modifier.height(6.dp))
|
||||
LinearProgressIndicator(
|
||||
progress = { state.done.toFloat() / update.apkSize.coerceAtLeast(1) },
|
||||
modifier = Modifier.fillMaxWidth().height(4.dp),
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Text(
|
||||
if (state.waitingNetwork) stringResource(R.string.upd_waiting_net_short) else stringResource(R.string.downloaded_of, mb(state.done), mb(update.apkSize)),
|
||||
style = MaterialTheme.typography.bodyMedium.merge(Tabular),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
is UpdateState.Busy -> {
|
||||
Spacer(Modifier.height(6.dp))
|
||||
LinearProgressIndicator(Modifier.fillMaxWidth().height(4.dp))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Text(stepText(state.step), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
is UpdateState.Ready -> Text(
|
||||
stringResource(R.string.upd_ready_short),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
is UpdateState.Failed -> Text(
|
||||
shortProblem(state.problem),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!progressOnly) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
|
||||
TextButton(onClick = {
|
||||
updates.hide()
|
||||
onHidden()
|
||||
}) { Text(stringResource(R.string.not_now)) }
|
||||
when (state) {
|
||||
is UpdateState.Ready -> FilledTonalButton(onClick = {
|
||||
updates.openSheet()
|
||||
updates.install()
|
||||
}) { Text(stringResource(R.string.upd_install)) }
|
||||
is UpdateState.Failed -> FilledTonalButton(onClick = { updates.openSheet() }) { Text(stringResource(R.string.upd_more)) }
|
||||
else -> FilledTonalButton(onClick = {
|
||||
updates.openSheet()
|
||||
updates.start()
|
||||
}) { Text(stringResource(R.string.upd_update)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// «You have 0.14.0 · What's new ↗».
|
||||
@Composable
|
||||
private fun YouHave(page: String, onWhatsNew: () -> Unit) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
stringResource(R.string.upd_you_have, BuildConfig.VERSION_NAME) + " · ",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
if (page.isNotEmpty()) WhatsNew(Modifier.minimumInteractiveComponentSize(), onWhatsNew)
|
||||
}
|
||||
}
|
||||
|
||||
/// «What's new ↗»: the release's page on GitHub.
|
||||
@Composable
|
||||
private fun WhatsNew(modifier: Modifier, onClick: () -> Unit) {
|
||||
val description = stringResource(R.string.upd_whats_new_cd)
|
||||
Row(
|
||||
modifier
|
||||
.clickable(role = Role.Button, onClick = onClick)
|
||||
.semantics(mergeDescendants = true) { contentDescription = description },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(stringResource(R.string.upd_whats_new), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.primary)
|
||||
Spacer(Modifier.width(2.dp))
|
||||
Icon(Icons.AutoMirrored.Rounded.OpenInNew, null, tint = MaterialTheme.colorScheme.primary, modifier = Modifier.size(18.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun stepText(step: UpdateStep): String = stringResource(
|
||||
when (step) {
|
||||
UpdateStep.CheckingFile -> R.string.upd_checking_file
|
||||
UpdateStep.KeepingEngine -> R.string.upd_keeping_engine
|
||||
UpdateStep.Installing -> R.string.upd_installing
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun shortProblem(p: UpdateProblem): String = stringResource(
|
||||
when (p) {
|
||||
UpdateProblem.NoInternet -> R.string.upd_short_offline
|
||||
UpdateProblem.NoSpace, UpdateProblem.InstallStorage -> R.string.upd_short_space
|
||||
UpdateProblem.Corrupt -> R.string.upd_short_corrupt
|
||||
UpdateProblem.DownloadFailed -> R.string.upd_short_failed
|
||||
UpdateProblem.BadRelease -> R.string.upd_short_release
|
||||
UpdateProblem.Conflict, UpdateProblem.Blocked, UpdateProblem.InstallFailed -> R.string.upd_short_install
|
||||
},
|
||||
)
|
||||
|
||||
/// The «Update» sheet (android-ui.md §25.3), over whatever screen is shown.
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun UpdateSheet() {
|
||||
val app = app()
|
||||
val updates = app.updates
|
||||
val state by updates.state.collectAsState()
|
||||
val net by app.engineFiles.state.collectAsState()
|
||||
val games by app.downloads.views.collectAsState()
|
||||
val context = LocalContext.current
|
||||
val uri = LocalUriHandler.current
|
||||
val s = state
|
||||
if (s == null) {
|
||||
LaunchedEffect(Unit) { updates.closeSheet() }
|
||||
return
|
||||
}
|
||||
val update = s.update
|
||||
// Back from the settings with the permission: TalkBack says the download has begun.
|
||||
val view = androidx.compose.ui.platform.LocalView.current
|
||||
val granted = stringResource(R.string.upd_perm_granted)
|
||||
var waited by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(s is UpdateState.NeedsPermission, s is UpdateState.Downloading) {
|
||||
if (s is UpdateState.NeedsPermission) waited = true
|
||||
if (s is UpdateState.Downloading && waited) {
|
||||
waited = false
|
||||
@Suppress("DEPRECATION")
|
||||
view.announceForAccessibility(granted)
|
||||
}
|
||||
}
|
||||
val close = {
|
||||
updates.closeSheet()
|
||||
updates.dismissProblem()
|
||||
}
|
||||
ModalBottomSheet(onDismissRequest = close, sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)) {
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(start = 24.dp, end = 24.dp, bottom = 24.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.upd_title, update.version), style = MaterialTheme.typography.titleLarge, modifier = Modifier.semantics { heading() })
|
||||
Spacer(Modifier.height(4.dp))
|
||||
YouHave(update.page) { uri.openUri(update.page) }
|
||||
if (uiLanguage() != "en") {
|
||||
Text(stringResource(R.string.upd_notes_english), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
// The engine stays when there is one to keep: in the app's storage, or in a full
|
||||
// build that keeps it before the install.
|
||||
val engine = net == NetState.Ready || BuildConfig.NET_BUILT_IN
|
||||
Text(stringResource(if (engine) R.string.upd_keeps else R.string.upd_keeps_no_engine), style = MaterialTheme.typography.bodyLarge)
|
||||
Text(stringResource(R.string.upd_closes), style = MaterialTheme.typography.bodyLarge)
|
||||
if (games.values.any { it.state.running }) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(stringResource(R.string.upd_online_note), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
val live = Modifier.semantics { liveRegion = LiveRegionMode.Polite }
|
||||
when (s) {
|
||||
is UpdateState.Available -> Buttons(
|
||||
secondary = stringResource(R.string.not_now) to close,
|
||||
primary = stringResource(R.string.upd_update) to { updates.start() },
|
||||
)
|
||||
is UpdateState.NeedsPermission -> {
|
||||
val openSettings = {
|
||||
updates.permissionAsked()
|
||||
context.startActivity(
|
||||
Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:${context.packageName}")),
|
||||
)
|
||||
}
|
||||
if (!s.denied) {
|
||||
Text(stringResource(R.string.upd_perm_title), style = MaterialTheme.typography.titleMedium, modifier = live)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(stringResource(R.string.upd_perm_body), style = MaterialTheme.typography.bodyMedium)
|
||||
} else {
|
||||
Text(stringResource(R.string.upd_perm_denied), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error, modifier = live)
|
||||
Link(stringResource(R.string.upd_on_site)) { uri.openUri(SITE_URL) }
|
||||
}
|
||||
Spacer(Modifier.height(24.dp))
|
||||
Buttons(
|
||||
secondary = stringResource(R.string.cancel) to close,
|
||||
primary = stringResource(R.string.upd_perm_open) to openSettings,
|
||||
)
|
||||
}
|
||||
is UpdateState.Downloading -> {
|
||||
LinearProgressIndicator(
|
||||
progress = { s.done.toFloat() / update.apkSize.coerceAtLeast(1) },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
if (s.waitingNetwork) stringResource(R.string.upd_waiting_net) else stringResource(R.string.downloaded_of, mb(s.done), mb(update.apkSize)),
|
||||
style = MaterialTheme.typography.bodyMedium.merge(Tabular),
|
||||
)
|
||||
Text(stringResource(R.string.upd_leave), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = live)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = {
|
||||
updates.cancel()
|
||||
updates.closeSheet()
|
||||
}) { Text(stringResource(R.string.cancel_download)) }
|
||||
}
|
||||
}
|
||||
is UpdateState.Busy -> {
|
||||
LinearProgressIndicator(Modifier.fillMaxWidth())
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(stepText(s.step), style = MaterialTheme.typography.bodyMedium, modifier = live)
|
||||
}
|
||||
is UpdateState.Ready -> {
|
||||
Text(
|
||||
stringResource(if (s.aborted) R.string.upd_aborted else R.string.upd_ready),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = live,
|
||||
)
|
||||
Spacer(Modifier.height(24.dp))
|
||||
Buttons(
|
||||
secondary = stringResource(R.string.not_now) to { updates.closeSheet() },
|
||||
primary = stringResource(R.string.upd_install) to { updates.install() },
|
||||
)
|
||||
}
|
||||
is UpdateState.Failed -> Problem(s, onRetry = { updates.start() }, onSite = { uri.openUri(SITE_URL) }, onClose = close)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Problem(s: UpdateState.Failed, onRetry: () -> Unit, onSite: () -> Unit, onClose: () -> Unit) {
|
||||
val updates = app().updates
|
||||
val text = when (s.problem) {
|
||||
UpdateProblem.NoInternet -> stringResource(R.string.no_internet)
|
||||
UpdateProblem.DownloadFailed -> stringResource(R.string.upd_err_failed)
|
||||
UpdateProblem.NoSpace -> stringResource(R.string.no_space, mb(updates.needed(s.update)))
|
||||
UpdateProblem.Corrupt -> stringResource(R.string.upd_err_corrupt)
|
||||
UpdateProblem.BadRelease -> stringResource(R.string.upd_err_release)
|
||||
UpdateProblem.InstallStorage -> stringResource(R.string.upd_err_storage, mb(updates.needed(s.update)))
|
||||
UpdateProblem.Conflict -> stringResource(R.string.upd_err_conflict)
|
||||
UpdateProblem.Blocked -> stringResource(R.string.upd_err_blocked)
|
||||
UpdateProblem.InstallFailed -> stringResource(R.string.upd_err_install)
|
||||
}
|
||||
Text(text, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error, modifier = Modifier.semantics { liveRegion = LiveRegionMode.Polite })
|
||||
val install = s.problem in setOf(UpdateProblem.InstallStorage, UpdateProblem.Conflict, UpdateProblem.Blocked, UpdateProblem.InstallFailed)
|
||||
val detail = s.detail
|
||||
if (install && !detail.isNullOrBlank()) {
|
||||
var open by rememberSaveable { mutableStateOf(false) }
|
||||
Link(stringResource(R.string.upd_details)) { open = !open }
|
||||
if (open) {
|
||||
@Suppress("DEPRECATION")
|
||||
val clipboard = androidx.compose.ui.platform.LocalClipboardManager.current
|
||||
Text(detail, fontFamily = FontFamily.Monospace, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
TextButton(onClick = { clipboard.setText(androidx.compose.ui.text.AnnotatedString(detail)) }) { Text(stringResource(R.string.upd_copy)) }
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(24.dp))
|
||||
val notNow = stringResource(R.string.not_now)
|
||||
val ok = stringResource(R.string.ok)
|
||||
val retry = stringResource(R.string.retry)
|
||||
val site = stringResource(R.string.upd_open_site)
|
||||
when (s.problem) {
|
||||
UpdateProblem.NoInternet, UpdateProblem.DownloadFailed, UpdateProblem.InstallStorage -> Buttons(notNow to onClose, retry to onRetry)
|
||||
UpdateProblem.Corrupt -> Buttons(notNow to onClose, stringResource(R.string.download_again) to onRetry)
|
||||
UpdateProblem.NoSpace -> Buttons(null, ok to onClose)
|
||||
UpdateProblem.BadRelease, UpdateProblem.Conflict, UpdateProblem.Blocked -> Buttons(ok to onClose, site to onSite)
|
||||
UpdateProblem.InstallFailed -> Buttons(site to onSite, retry to onRetry)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Buttons(secondary: Pair<String, () -> Unit>?, primary: Pair<String, () -> Unit>) {
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
|
||||
secondary?.let { (label, action) -> TextButton(onClick = action) { Text(label) } }
|
||||
Button(onClick = primary.second) { Text(primary.first) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Link(text: String, onClick: () -> Unit) {
|
||||
Row(
|
||||
Modifier.heightIn(min = 48.dp).clickable(role = Role.Button, onClick = onClick),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(text, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
/// The «Updates» block of About (android-ui.md §25.5).
|
||||
@Composable
|
||||
fun AboutUpdates() {
|
||||
val updates = app().updates
|
||||
val state by updates.state.collectAsState()
|
||||
val check by updates.check.collectAsState()
|
||||
val auto by updates.auto.collectAsState()
|
||||
val last by updates.lastCheck.collectAsState()
|
||||
val uri = LocalUriHandler.current
|
||||
val context = LocalContext.current
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
stringResource(R.string.upd_group),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.semantics { heading() },
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
val s = state
|
||||
if (s == null) {
|
||||
// Said only after a check that got an answer.
|
||||
if (last > 0 || check == CheckState.Latest) Text(stringResource(R.string.upd_latest), style = MaterialTheme.typography.bodyLarge)
|
||||
} else {
|
||||
Text(stringResource(R.string.upd_title, s.update.version), style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Medium)
|
||||
if (s.update.page.isNotEmpty()) WhatsNew(Modifier.heightIn(min = 48.dp)) { uri.openUri(s.update.page) }
|
||||
when (s) {
|
||||
is UpdateState.Downloading -> {
|
||||
LinearProgressIndicator(progress = { s.done.toFloat() / s.update.apkSize.coerceAtLeast(1) }, modifier = Modifier.fillMaxWidth())
|
||||
Text(
|
||||
if (s.waitingNetwork) stringResource(R.string.upd_waiting_net_short) else stringResource(R.string.downloaded_of, mb(s.done), mb(s.update.apkSize)),
|
||||
style = MaterialTheme.typography.bodyMedium.merge(Tabular),
|
||||
)
|
||||
}
|
||||
is UpdateState.Busy -> {
|
||||
LinearProgressIndicator(Modifier.fillMaxWidth())
|
||||
Text(stepText(s.step), style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
is UpdateState.Failed -> Text(shortProblem(s.problem), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error)
|
||||
else -> {}
|
||||
}
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
when (s) {
|
||||
is UpdateState.Ready -> Button(onClick = {
|
||||
updates.openSheet()
|
||||
updates.install()
|
||||
}) { Text(stringResource(R.string.upd_install)) }
|
||||
is UpdateState.Downloading, is UpdateState.Busy -> TextButton(onClick = { updates.openSheet() }) { Text(stringResource(R.string.upd_more)) }
|
||||
is UpdateState.Failed -> TextButton(onClick = { updates.openSheet() }) { Text(stringResource(R.string.upd_more)) }
|
||||
else -> Button(onClick = {
|
||||
updates.openSheet()
|
||||
updates.start()
|
||||
}) { Text(stringResource(R.string.upd_update)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 72.dp)
|
||||
.toggleable(value = auto, role = Role.Switch, onValueChange = { updates.setAuto(it) }),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(stringResource(R.string.upd_auto), style = MaterialTheme.typography.bodyLarge, modifier = Modifier.weight(1f))
|
||||
Switch(checked = auto, onCheckedChange = null)
|
||||
}
|
||||
Text(stringResource(R.string.upd_auto_sub), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
if (check == CheckState.Checking) {
|
||||
Row(Modifier.heightIn(min = 48.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Text(stringResource(R.string.upd_checking), style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
} else {
|
||||
// Not while an update is downloaded or installed: the check waits for it.
|
||||
val busy = s is UpdateState.Downloading || s is UpdateState.Busy || s is UpdateState.NeedsPermission
|
||||
TextButton(onClick = { updates.checkNow() }, enabled = !busy, contentPadding = androidx.compose.foundation.layout.PaddingValues(0.dp)) {
|
||||
Text(stringResource(R.string.upd_check_now))
|
||||
}
|
||||
}
|
||||
when (check) {
|
||||
CheckState.Offline -> Text(stringResource(R.string.upd_check_offline), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error)
|
||||
CheckState.Failed -> Text(stringResource(R.string.upd_check_failed), style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.error)
|
||||
else -> {}
|
||||
}
|
||||
if (last > 0) {
|
||||
// «today, 14:05» inside the sentence: Android writes it from a capital.
|
||||
val whenText = DateUtils.getRelativeDateTimeString(context, last, DateUtils.DAY_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0)
|
||||
.toString().replaceFirstChar { it.lowercaseChar() }
|
||||
Text(stringResource(R.string.upd_checked, whenText), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The second line of «About» in Settings while a newer version is known (§25.5).
|
||||
@Composable
|
||||
fun aboutUpdateLine(): String? {
|
||||
val updates = app().updates
|
||||
val state by updates.state.collectAsState()
|
||||
val auto by updates.auto.collectAsState()
|
||||
val asked by updates.asked.collectAsState()
|
||||
val s = state ?: return null
|
||||
if (!auto && !asked && s is UpdateState.Available) return null
|
||||
return when (s) {
|
||||
is UpdateState.Downloading, is UpdateState.Busy -> stringResource(R.string.s_about_downloading, s.update.version)
|
||||
is UpdateState.Ready -> stringResource(R.string.s_about_ready, s.update.version)
|
||||
else -> stringResource(R.string.s_about_available, s.update.version)
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the update's messages in a screen's snackbar (only one screen is on at a time).
|
||||
@Composable
|
||||
fun UpdateMessages(snackbar: SnackbarHostState) {
|
||||
val updates = app().updates
|
||||
val message by updates.message.collectAsState()
|
||||
val uri = LocalUriHandler.current
|
||||
val ready = stringResource(R.string.upd_ready_snack)
|
||||
val install = stringResource(R.string.upd_install)
|
||||
val cancelled = stringResource(R.string.download_cancelled)
|
||||
val latest = stringResource(R.string.upd_latest)
|
||||
val whatsNew = stringResource(R.string.upd_whats_new)
|
||||
val doneText = (message as? UpdateMessage.Updated)?.let { stringResource(R.string.upd_done_snack, it.from, it.to) }
|
||||
// Marked shown when its snackbar is gone: a screen left meanwhile hands it to the next.
|
||||
LaunchedEffect(message) {
|
||||
val m = message ?: return@LaunchedEffect
|
||||
snackbar.currentSnackbarData?.dismiss()
|
||||
when (m) {
|
||||
UpdateMessage.Ready -> {
|
||||
if (snackbar.showSnackbar(ready, install, duration = SnackbarDuration.Long) == SnackbarResult.ActionPerformed) {
|
||||
updates.openSheet()
|
||||
updates.install()
|
||||
}
|
||||
}
|
||||
UpdateMessage.Cancelled -> snackbar.showSnackbar(cancelled)
|
||||
UpdateMessage.Latest -> snackbar.showSnackbar(latest)
|
||||
is UpdateMessage.Updated -> {
|
||||
val action = if (m.page.isNotEmpty()) whatsNew else null
|
||||
if (snackbar.showSnackbar(doneText ?: "", action, duration = SnackbarDuration.Long) == SnackbarResult.ActionPerformed) uri.openUri(m.page)
|
||||
}
|
||||
}
|
||||
updates.shown(m)
|
||||
}
|
||||
}
|
||||
|
|
@ -328,4 +328,64 @@
|
|||
<item quantity="one">bis zu %1$s Partie</item>
|
||||
<item quantity="other">bis zu %1$s Partien</item>
|
||||
</plurals>
|
||||
<string name="upd_title">Version %1$s ist erschienen</string>
|
||||
<string name="upd_you_have">Sie haben %1$s</string>
|
||||
<string name="upd_whats_new">Neuigkeiten</string>
|
||||
<string name="upd_whats_new_cd">Neuigkeiten, öffnet die Seite auf GitHub</string>
|
||||
<string name="upd_notes_english">Die Änderungsliste steht auf GitHub, auf Englisch.</string>
|
||||
<string name="upd_update">Aktualisieren</string>
|
||||
<string name="upd_install">Installieren</string>
|
||||
<string name="upd_hidden_snack">Das Update finden Sie unter Einstellungen → Über</string>
|
||||
<string name="upd_keeps">Datenbanken, Einstellungen und die Engine bleiben erhalten.</string>
|
||||
<string name="upd_keeps_no_engine">Datenbanken und Einstellungen bleiben erhalten.</string>
|
||||
<string name="upd_closes">ChessPenguin schließt sich während der Installation — öffnen Sie es danach wieder.</string>
|
||||
<string name="upd_online_note">Partien werden gerade heruntergeladen: Die Installation unterbricht den Download, danach können Sie ihn fortsetzen.</string>
|
||||
<string name="upd_perm_title">Eine Berechtigung ist nötig</string>
|
||||
<string name="upd_perm_body">Android installiert Apps außerhalb eines Stores nur mit Ihrer Erlaubnis. Die Einstellungen öffnen sich: Aktivieren Sie den Schalter für ChessPenguin und kehren Sie zurück.</string>
|
||||
<string name="upd_perm_open">Einstellungen öffnen</string>
|
||||
<string name="upd_perm_denied">Die Berechtigung ist deaktiviert — ohne sie installiert Android die neue Version nicht.</string>
|
||||
<string name="upd_perm_granted">Berechtigung erteilt, Download läuft</string>
|
||||
<string name="upd_on_site">Von der Website herunterladen</string>
|
||||
<string name="upd_open_site">Website öffnen</string>
|
||||
<string name="upd_leave">Sie können dieses Fenster schließen: Der Download läuft weiter.</string>
|
||||
<string name="upd_waiting_net">Kein Netz. Der Download läuft von selbst weiter, sobald das Netz zurück ist.</string>
|
||||
<string name="upd_waiting_net_short">Wartet auf Netz</string>
|
||||
<string name="upd_checking_file">Datei wird geprüft…</string>
|
||||
<string name="upd_keeping_engine">Engine wird gesichert…</string>
|
||||
<string name="upd_installing">Wird installiert…</string>
|
||||
<string name="upd_ready">Die neue Version ist heruntergeladen und geprüft.</string>
|
||||
<string name="upd_ready_short">Heruntergeladen und geprüft</string>
|
||||
<string name="upd_ready_snack">Die neue Version ist heruntergeladen</string>
|
||||
<string name="upd_aborted">Installation abgebrochen. Die neue Version ist heruntergeladen — installieren Sie sie, wann es Ihnen passt.</string>
|
||||
<string name="upd_notification">ChessPenguin-Update</string>
|
||||
<string name="upd_done_snack">ChessPenguin wurde aktualisiert: %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">Der Download ist fehlgeschlagen. Versuchen Sie es erneut.</string>
|
||||
<string name="upd_err_corrupt">Die Datei wurde beim Herunterladen beschädigt und deshalb nicht installiert. Versuchen Sie es erneut.</string>
|
||||
<string name="upd_err_release">Mit dieser Version stimmt etwas nicht: Die Android-Datei lässt sich nicht prüfen. Laden Sie die neue Version von der Website herunter.</string>
|
||||
<string name="upd_err_storage">Android hat die neue Version nicht installiert: zu wenig Speicher. Geben Sie %1$d MB frei und versuchen Sie es erneut.</string>
|
||||
<string name="upd_err_conflict">Android hat die neue Version nicht installiert: Dieses ChessPenguin ist mit einem anderen Schlüssel signiert. Die neue Version lässt sich erst nach dem Entfernen dieser installieren, und dabei gehen die Datenbankliste und die heruntergeladenen Datenbanken verloren.</string>
|
||||
<string name="upd_err_blocked">Android oder der Schutz des Telefons hat die Installation gestoppt. Laden Sie die neue Version von der Website herunter.</string>
|
||||
<string name="upd_err_install">Android hat die neue Version nicht installiert. Versuchen Sie es erneut oder laden Sie sie von der Website herunter.</string>
|
||||
<string name="upd_short_offline">Kein Internet</string>
|
||||
<string name="upd_short_space">Zu wenig Speicher</string>
|
||||
<string name="upd_short_corrupt">Die Datei ist beschädigt</string>
|
||||
<string name="upd_short_install">Von Android nicht installiert</string>
|
||||
<string name="upd_short_failed">Download fehlgeschlagen</string>
|
||||
<string name="upd_more">Mehr erfahren</string>
|
||||
<string name="upd_details">Details</string>
|
||||
<string name="upd_copy">Kopieren</string>
|
||||
<string name="upd_group">Updates</string>
|
||||
<string name="upd_auto">Beim Start nach Updates suchen</string>
|
||||
<string name="upd_auto_sub">Einmal am Tag fragt ChessPenguin bei GitHub nach der neuesten Version; über Sie wird nichts gesendet.</string>
|
||||
<string name="upd_check_now">Jetzt prüfen</string>
|
||||
<string name="upd_checking">Wird geprüft…</string>
|
||||
<string name="upd_latest">Sie haben die neueste Version</string>
|
||||
<string name="upd_checked">Zuletzt geprüft: %1$s</string>
|
||||
<string name="upd_check_offline">Kein Internet — Updates lassen sich nicht prüfen</string>
|
||||
<string name="upd_check_failed">Updates ließen sich nicht prüfen: GitHub hat nicht geantwortet. Versuchen Sie es später.</string>
|
||||
<string name="s_about_available">Version %1$s ist erschienen</string>
|
||||
<string name="s_about_downloading">Version %1$s wird heruntergeladen…</string>
|
||||
<string name="s_about_ready">Version %1$s ist heruntergeladen</string>
|
||||
<string name="upd_card_downloading">Update auf %1$s, %2$d von %3$d Megabyte heruntergeladen</string>
|
||||
<string name="upd_short_release">Datei lässt sich nicht prüfen</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -334,4 +334,64 @@
|
|||
<item quantity="many">hasta %1$s partidas</item>
|
||||
<item quantity="other">hasta %1$s partidas</item>
|
||||
</plurals>
|
||||
<string name="upd_title">Ha salido la versión %1$s</string>
|
||||
<string name="upd_you_have">Tienes la %1$s</string>
|
||||
<string name="upd_whats_new">Novedades</string>
|
||||
<string name="upd_whats_new_cd">Novedades, abre la página en GitHub</string>
|
||||
<string name="upd_notes_english">La lista de cambios está en GitHub, en inglés.</string>
|
||||
<string name="upd_update">Actualizar</string>
|
||||
<string name="upd_install">Instalar</string>
|
||||
<string name="upd_hidden_snack">La actualización está en Ajustes, en Acerca de</string>
|
||||
<string name="upd_keeps">Las bases, los ajustes y el motor se conservan.</string>
|
||||
<string name="upd_keeps_no_engine">Las bases y los ajustes se conservan.</string>
|
||||
<string name="upd_closes">ChessPenguin se cierra durante la instalación; luego vuelve a abrirlo.</string>
|
||||
<string name="upd_online_note">Se están descargando partidas: la instalación detendrá la descarga; luego puedes continuarla.</string>
|
||||
<string name="upd_perm_title">Hace falta un permiso</string>
|
||||
<string name="upd_perm_body">Android solo instala aplicaciones de fuera de una tienda con tu permiso. Se abrirán los ajustes: activa el interruptor para ChessPenguin y vuelve.</string>
|
||||
<string name="upd_perm_open">Abrir ajustes</string>
|
||||
<string name="upd_perm_denied">El permiso está desactivado; sin él, Android no instalará la nueva versión.</string>
|
||||
<string name="upd_perm_granted">Permiso concedido, descargando</string>
|
||||
<string name="upd_on_site">Descargar desde la web</string>
|
||||
<string name="upd_open_site">Abrir la web</string>
|
||||
<string name="upd_leave">Puedes cerrar esto: la descarga continúa.</string>
|
||||
<string name="upd_waiting_net">Sin red. La descarga seguirá sola cuando vuelva la red.</string>
|
||||
<string name="upd_waiting_net_short">Esperando red</string>
|
||||
<string name="upd_checking_file">Comprobando el archivo…</string>
|
||||
<string name="upd_keeping_engine">Guardando el motor…</string>
|
||||
<string name="upd_installing">Instalando…</string>
|
||||
<string name="upd_ready">La nueva versión está descargada y comprobada.</string>
|
||||
<string name="upd_ready_short">Descargada y comprobada</string>
|
||||
<string name="upd_ready_snack">La nueva versión está descargada</string>
|
||||
<string name="upd_aborted">Instalación cancelada. La nueva versión está descargada: instálala cuando quieras.</string>
|
||||
<string name="upd_notification">Actualización de ChessPenguin</string>
|
||||
<string name="upd_done_snack">ChessPenguin se ha actualizado: %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">La descarga ha fallado. Inténtalo de nuevo.</string>
|
||||
<string name="upd_err_corrupt">El archivo se dañó al descargarse, así que no se instaló. Inténtalo de nuevo.</string>
|
||||
<string name="upd_err_release">Algo falla en esta versión: no se puede comprobar el archivo de Android. Descarga la nueva versión en la web.</string>
|
||||
<string name="upd_err_storage">Android no ha instalado la nueva versión: no hay espacio. Libera %1$d MB e inténtalo de nuevo.</string>
|
||||
<string name="upd_err_conflict">Android no ha instalado la nueva versión: este ChessPenguin está firmado con otra clave. La nueva versión solo se puede instalar tras desinstalar esta, y al desinstalarla se pierden la lista de bases y las bases descargadas.</string>
|
||||
<string name="upd_err_blocked">Android o la protección del teléfono detuvo la instalación. Descarga la nueva versión en la web.</string>
|
||||
<string name="upd_err_install">Android no ha instalado la nueva versión. Inténtalo de nuevo o descárgala en la web.</string>
|
||||
<string name="upd_short_offline">Sin internet</string>
|
||||
<string name="upd_short_space">No hay espacio suficiente</string>
|
||||
<string name="upd_short_corrupt">El archivo se dañó</string>
|
||||
<string name="upd_short_install">Android no la instaló</string>
|
||||
<string name="upd_short_failed">La descarga ha fallado</string>
|
||||
<string name="upd_more">Ver más</string>
|
||||
<string name="upd_details">Detalles</string>
|
||||
<string name="upd_copy">Copiar</string>
|
||||
<string name="upd_group">Actualizaciones</string>
|
||||
<string name="upd_auto">Buscar actualizaciones al iniciar</string>
|
||||
<string name="upd_auto_sub">Una vez al día ChessPenguin pregunta a GitHub cuál es la última versión; no se envía nada sobre ti.</string>
|
||||
<string name="upd_check_now">Comprobar ahora</string>
|
||||
<string name="upd_checking">Comprobando…</string>
|
||||
<string name="upd_latest">Tienes la última versión</string>
|
||||
<string name="upd_checked">Última comprobación: %1$s</string>
|
||||
<string name="upd_check_offline">Sin internet: no se pueden buscar actualizaciones</string>
|
||||
<string name="upd_check_failed">No se pudieron buscar actualizaciones: GitHub no respondió. Inténtalo más tarde.</string>
|
||||
<string name="s_about_available">Ha salido la versión %1$s</string>
|
||||
<string name="s_about_downloading">Descargando la versión %1$s…</string>
|
||||
<string name="s_about_ready">La versión %1$s está descargada</string>
|
||||
<string name="upd_card_downloading">Actualización a %1$s, %2$d de %3$d megabytes descargados</string>
|
||||
<string name="upd_short_release">No se puede comprobar el archivo</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -334,4 +334,64 @@
|
|||
<item quantity="many">jusqu\'à %1$s parties</item>
|
||||
<item quantity="other">jusqu\'à %1$s parties</item>
|
||||
</plurals>
|
||||
<string name="upd_title">La version %1$s est sortie</string>
|
||||
<string name="upd_you_have">Vous avez %1$s</string>
|
||||
<string name="upd_whats_new">Nouveautés</string>
|
||||
<string name="upd_whats_new_cd">Nouveautés, ouvre la page sur GitHub</string>
|
||||
<string name="upd_notes_english">La liste des changements est sur GitHub, en anglais.</string>
|
||||
<string name="upd_update">Mettre à jour</string>
|
||||
<string name="upd_install">Installer</string>
|
||||
<string name="upd_hidden_snack">La mise à jour est dans Paramètres, rubrique À propos</string>
|
||||
<string name="upd_keeps">Les bases, les paramètres et le moteur sont conservés.</string>
|
||||
<string name="upd_keeps_no_engine">Les bases et les paramètres sont conservés.</string>
|
||||
<string name="upd_closes">ChessPenguin se ferme pendant l’installation — rouvrez-le ensuite.</string>
|
||||
<string name="upd_online_note">Des parties sont en cours de téléchargement : l’installation va l’interrompre, vous pourrez le reprendre ensuite.</string>
|
||||
<string name="upd_perm_title">Une autorisation est nécessaire</string>
|
||||
<string name="upd_perm_body">Android n’installe des applications hors d’une boutique qu’avec votre autorisation. Les paramètres vont s’ouvrir : activez l’interrupteur pour ChessPenguin et revenez.</string>
|
||||
<string name="upd_perm_open">Ouvrir les paramètres</string>
|
||||
<string name="upd_perm_denied">L’autorisation est désactivée — sans elle, Android n’installera pas la nouvelle version.</string>
|
||||
<string name="upd_perm_granted">Autorisation accordée, téléchargement en cours</string>
|
||||
<string name="upd_on_site">Télécharger sur le site</string>
|
||||
<string name="upd_open_site">Ouvrir le site</string>
|
||||
<string name="upd_leave">Vous pouvez fermer : le téléchargement continue.</string>
|
||||
<string name="upd_waiting_net">Pas de réseau. Le téléchargement reprendra tout seul quand le réseau reviendra.</string>
|
||||
<string name="upd_waiting_net_short">En attente du réseau</string>
|
||||
<string name="upd_checking_file">Vérification du fichier…</string>
|
||||
<string name="upd_keeping_engine">Conservation du moteur…</string>
|
||||
<string name="upd_installing">Installation…</string>
|
||||
<string name="upd_ready">La nouvelle version est téléchargée et vérifiée.</string>
|
||||
<string name="upd_ready_short">Téléchargée et vérifiée</string>
|
||||
<string name="upd_ready_snack">La nouvelle version est téléchargée</string>
|
||||
<string name="upd_aborted">Installation annulée. La nouvelle version est téléchargée — installez-la quand vous voulez.</string>
|
||||
<string name="upd_notification">Mise à jour de ChessPenguin</string>
|
||||
<string name="upd_done_snack">ChessPenguin est mis à jour : %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">Le téléchargement a échoué. Réessayez.</string>
|
||||
<string name="upd_err_corrupt">Le fichier a été endommagé pendant le téléchargement ; il n’a pas été installé. Réessayez.</string>
|
||||
<string name="upd_err_release">Cette version pose problème : le fichier Android ne peut pas être vérifié. Téléchargez la nouvelle version sur le site.</string>
|
||||
<string name="upd_err_storage">Android n’a pas installé la nouvelle version : pas assez d’espace. Libérez %1$d Mo et réessayez.</string>
|
||||
<string name="upd_err_conflict">Android n’a pas installé la nouvelle version : ce ChessPenguin est signé avec une autre clé. La nouvelle version ne peut s’installer qu’après la suppression de celle-ci, et la suppression efface la liste des bases et les bases téléchargées.</string>
|
||||
<string name="upd_err_blocked">Android ou la protection du téléphone a arrêté l’installation. Téléchargez la nouvelle version sur le site.</string>
|
||||
<string name="upd_err_install">Android n’a pas installé la nouvelle version. Réessayez ou téléchargez-la sur le site.</string>
|
||||
<string name="upd_short_offline">Pas d’Internet</string>
|
||||
<string name="upd_short_space">Pas assez d’espace</string>
|
||||
<string name="upd_short_corrupt">Le fichier est endommagé</string>
|
||||
<string name="upd_short_install">Android ne l’a pas installée</string>
|
||||
<string name="upd_short_failed">Le téléchargement a échoué</string>
|
||||
<string name="upd_more">En savoir plus</string>
|
||||
<string name="upd_details">Détails</string>
|
||||
<string name="upd_copy">Copier</string>
|
||||
<string name="upd_group">Mises à jour</string>
|
||||
<string name="upd_auto">Rechercher les mises à jour au démarrage</string>
|
||||
<string name="upd_auto_sub">Une fois par jour, ChessPenguin demande à GitHub quelle est la dernière version ; rien sur vous n’est envoyé.</string>
|
||||
<string name="upd_check_now">Vérifier maintenant</string>
|
||||
<string name="upd_checking">Vérification…</string>
|
||||
<string name="upd_latest">Vous avez la dernière version</string>
|
||||
<string name="upd_checked">Dernière vérification : %1$s</string>
|
||||
<string name="upd_check_offline">Pas d’Internet — impossible de vérifier les mises à jour</string>
|
||||
<string name="upd_check_failed">Impossible de vérifier les mises à jour : GitHub n’a pas répondu. Réessayez plus tard.</string>
|
||||
<string name="s_about_available">La version %1$s est sortie</string>
|
||||
<string name="s_about_downloading">Téléchargement de la version %1$s…</string>
|
||||
<string name="s_about_ready">La version %1$s est téléchargée</string>
|
||||
<string name="upd_card_downloading">Mise à jour vers %1$s, %2$d sur %3$d mégaoctets téléchargés</string>
|
||||
<string name="upd_short_release">Fichier impossible à vérifier</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -334,4 +334,64 @@
|
|||
<item quantity="many">fino a %1$s partite</item>
|
||||
<item quantity="other">fino a %1$s partite</item>
|
||||
</plurals>
|
||||
<string name="upd_title">È uscita la versione %1$s</string>
|
||||
<string name="upd_you_have">Hai la %1$s</string>
|
||||
<string name="upd_whats_new">Novità</string>
|
||||
<string name="upd_whats_new_cd">Novità, apre la pagina su GitHub</string>
|
||||
<string name="upd_notes_english">L’elenco delle modifiche è su GitHub, in inglese.</string>
|
||||
<string name="upd_update">Aggiorna</string>
|
||||
<string name="upd_install">Installa</string>
|
||||
<string name="upd_hidden_snack">L’aggiornamento è in Impostazioni, alla voce Informazioni</string>
|
||||
<string name="upd_keeps">Database, impostazioni e motore vengono mantenuti.</string>
|
||||
<string name="upd_keeps_no_engine">Database e impostazioni restano.</string>
|
||||
<string name="upd_closes">ChessPenguin si chiude durante l’installazione: poi riaprilo.</string>
|
||||
<string name="upd_online_note">Si stanno scaricando partite: l’installazione interrompe il download, poi puoi riprenderlo.</string>
|
||||
<string name="upd_perm_title">Serve un’autorizzazione</string>
|
||||
<string name="upd_perm_body">Android installa app non provenienti da uno store solo con il tuo permesso. Si apriranno le impostazioni: attiva l’interruttore per ChessPenguin e torna indietro.</string>
|
||||
<string name="upd_perm_open">Apri impostazioni</string>
|
||||
<string name="upd_perm_denied">L’autorizzazione è disattivata: senza di essa, Android non installerà la nuova versione.</string>
|
||||
<string name="upd_perm_granted">Autorizzazione concessa, download in corso</string>
|
||||
<string name="upd_on_site">Scarica dal sito</string>
|
||||
<string name="upd_open_site">Apri il sito</string>
|
||||
<string name="upd_leave">Puoi chiudere: il download continua.</string>
|
||||
<string name="upd_waiting_net">Nessuna rete. Il download riprenderà da solo quando torna la rete.</string>
|
||||
<string name="upd_waiting_net_short">In attesa di rete</string>
|
||||
<string name="upd_checking_file">Controllo del file…</string>
|
||||
<string name="upd_keeping_engine">Salvataggio del motore…</string>
|
||||
<string name="upd_installing">Installazione…</string>
|
||||
<string name="upd_ready">La nuova versione è scaricata e controllata.</string>
|
||||
<string name="upd_ready_short">Scaricata e controllata</string>
|
||||
<string name="upd_ready_snack">La nuova versione è scaricata</string>
|
||||
<string name="upd_aborted">Installazione annullata. La nuova versione è scaricata: installala quando vuoi.</string>
|
||||
<string name="upd_notification">Aggiornamento di ChessPenguin</string>
|
||||
<string name="upd_done_snack">ChessPenguin è aggiornato: %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">Il download non è riuscito. Riprova.</string>
|
||||
<string name="upd_err_corrupt">Il file si è danneggiato durante lo scaricamento, quindi non è stato installato. Riprova.</string>
|
||||
<string name="upd_err_release">Qualcosa non va in questa versione: il file per Android non si può controllare. Scarica la nuova versione dal sito.</string>
|
||||
<string name="upd_err_storage">Android non ha installato la nuova versione: spazio insufficiente. Libera %1$d MB e riprova.</string>
|
||||
<string name="upd_err_conflict">Android non ha installato la nuova versione: questo ChessPenguin è firmato con un’altra chiave. La nuova versione si può installare solo dopo aver rimosso questa, e rimuovendola si perdono l’elenco dei database e i database scaricati.</string>
|
||||
<string name="upd_err_blocked">Android o la protezione del telefono ha fermato l’installazione. Scarica la nuova versione dal sito.</string>
|
||||
<string name="upd_err_install">Android non ha installato la nuova versione. Riprova o scaricala dal sito.</string>
|
||||
<string name="upd_short_offline">Nessuna connessione</string>
|
||||
<string name="upd_short_space">Spazio insufficiente</string>
|
||||
<string name="upd_short_corrupt">Il file si è danneggiato</string>
|
||||
<string name="upd_short_install">Android non l’ha installata</string>
|
||||
<string name="upd_short_failed">Download non riuscito</string>
|
||||
<string name="upd_more">Scopri di più</string>
|
||||
<string name="upd_details">Dettagli</string>
|
||||
<string name="upd_copy">Copia</string>
|
||||
<string name="upd_group">Aggiornamenti</string>
|
||||
<string name="upd_auto">Cerca aggiornamenti all’avvio</string>
|
||||
<string name="upd_auto_sub">Una volta al giorno ChessPenguin chiede a GitHub qual è l’ultima versione; nulla su di te viene inviato.</string>
|
||||
<string name="upd_check_now">Controlla ora</string>
|
||||
<string name="upd_checking">Controllo in corso…</string>
|
||||
<string name="upd_latest">Hai l’ultima versione</string>
|
||||
<string name="upd_checked">Ultimo controllo: %1$s</string>
|
||||
<string name="upd_check_offline">Nessuna connessione: impossibile cercare aggiornamenti</string>
|
||||
<string name="upd_check_failed">Impossibile cercare aggiornamenti: GitHub non ha risposto. Riprova più tardi.</string>
|
||||
<string name="s_about_available">È uscita la versione %1$s</string>
|
||||
<string name="s_about_downloading">Scaricamento della versione %1$s…</string>
|
||||
<string name="s_about_ready">La versione %1$s è scaricata</string>
|
||||
<string name="upd_card_downloading">Aggiornamento a %1$s, %2$d di %3$d megabyte scaricati</string>
|
||||
<string name="upd_short_release">File non verificabile</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -340,4 +340,64 @@
|
|||
<item quantity="many">до %1$s партий</item>
|
||||
<item quantity="other">до %1$s партии</item>
|
||||
</plurals>
|
||||
<string name="upd_title">Вышла версия %1$s</string>
|
||||
<string name="upd_you_have">У вас %1$s</string>
|
||||
<string name="upd_whats_new">Что нового</string>
|
||||
<string name="upd_whats_new_cd">Что нового, откроется страница на GitHub</string>
|
||||
<string name="upd_notes_english">Список изменений — на GitHub, по-английски.</string>
|
||||
<string name="upd_update">Обновить</string>
|
||||
<string name="upd_install">Установить</string>
|
||||
<string name="upd_hidden_snack">Обновление — в Настройках, в разделе «О программе»</string>
|
||||
<string name="upd_keeps">Базы, настройки и движок останутся.</string>
|
||||
<string name="upd_keeps_no_engine">Базы и настройки останутся.</string>
|
||||
<string name="upd_closes">На время установки ChessPenguin закроется — потом откройте его снова.</string>
|
||||
<string name="upd_online_note">Идёт скачивание партий: установка его остановит, потом его можно продолжить.</string>
|
||||
<string name="upd_perm_title">Нужно одно разрешение</string>
|
||||
<string name="upd_perm_body">Android ставит приложения не из магазина только с вашего разрешения. Откроются настройки: включите переключатель для ChessPenguin и вернитесь назад.</string>
|
||||
<string name="upd_perm_open">Открыть настройки</string>
|
||||
<string name="upd_perm_denied">Разрешение не включено — без него Android не установит новую версию.</string>
|
||||
<string name="upd_perm_granted">Разрешение есть, скачиваю</string>
|
||||
<string name="upd_on_site">Скачать на сайте</string>
|
||||
<string name="upd_open_site">Открыть сайт</string>
|
||||
<string name="upd_leave">Лист можно закрыть: загрузка продолжится.</string>
|
||||
<string name="upd_waiting_net">Нет сети. Загрузка продолжится сама, когда сеть появится.</string>
|
||||
<string name="upd_waiting_net_short">Ждёт сеть</string>
|
||||
<string name="upd_checking_file">Проверяю файл…</string>
|
||||
<string name="upd_keeping_engine">Сохраняю движок…</string>
|
||||
<string name="upd_installing">Устанавливаю…</string>
|
||||
<string name="upd_ready">Новая версия скачана и проверена.</string>
|
||||
<string name="upd_ready_short">Скачана и проверена</string>
|
||||
<string name="upd_ready_snack">Новая версия скачана</string>
|
||||
<string name="upd_aborted">Установка отменена. Новая версия скачана — установите её, когда будет удобно.</string>
|
||||
<string name="upd_notification">Обновление ChessPenguin</string>
|
||||
<string name="upd_done_snack">ChessPenguin обновлён: %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">Загрузка не удалась. Попробуйте ещё раз.</string>
|
||||
<string name="upd_err_corrupt">Файл повредился при скачивании, поэтому не установлен. Попробуйте ещё раз.</string>
|
||||
<string name="upd_err_release">С этим выпуском что-то не так: файл для Android нельзя проверить. Скачайте новую версию на сайте.</string>
|
||||
<string name="upd_err_storage">Android не установил новую версию: не хватает места. Освободите %1$d МБ и попробуйте ещё раз.</string>
|
||||
<string name="upd_err_conflict">Android не установил новую версию: этот ChessPenguin подписан другим ключом. Поставить новую версию можно только после удаления этой, а при удалении пропадут список баз и скачанные базы.</string>
|
||||
<string name="upd_err_blocked">Установку остановил Android или защита телефона. Скачайте новую версию на сайте.</string>
|
||||
<string name="upd_err_install">Android не установил новую версию. Попробуйте ещё раз или скачайте её на сайте.</string>
|
||||
<string name="upd_short_offline">Нет интернета</string>
|
||||
<string name="upd_short_space">Не хватает места</string>
|
||||
<string name="upd_short_corrupt">Файл повредился</string>
|
||||
<string name="upd_short_install">Android не установил</string>
|
||||
<string name="upd_short_failed">Загрузка не удалась</string>
|
||||
<string name="upd_more">Подробнее</string>
|
||||
<string name="upd_details">Подробности</string>
|
||||
<string name="upd_copy">Копировать</string>
|
||||
<string name="upd_group">Обновления</string>
|
||||
<string name="upd_auto">Проверять обновления при запуске</string>
|
||||
<string name="upd_auto_sub">Раз в день ChessPenguin спрашивает у GitHub, какая версия последняя; ничего о вас не отправляется.</string>
|
||||
<string name="upd_check_now">Проверить сейчас</string>
|
||||
<string name="upd_checking">Проверяю…</string>
|
||||
<string name="upd_latest">У вас последняя версия</string>
|
||||
<string name="upd_checked">Проверено %1$s</string>
|
||||
<string name="upd_check_offline">Нет интернета — проверить обновления нельзя</string>
|
||||
<string name="upd_check_failed">Не удалось проверить обновления: GitHub не ответил. Попробуйте позже.</string>
|
||||
<string name="s_about_available">Вышла версия %1$s</string>
|
||||
<string name="s_about_downloading">Скачивается версия %1$s…</string>
|
||||
<string name="s_about_ready">Версия %1$s скачана</string>
|
||||
<string name="upd_card_downloading">Обновление до %1$s, скачано %2$d из %3$d мегабайт</string>
|
||||
<string name="upd_short_release">Файл нельзя проверить</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -331,4 +331,65 @@
|
|||
<item quantity="one">up to %1$s game</item>
|
||||
<item quantity="other">up to %1$s games</item>
|
||||
</plurals>
|
||||
<string name="upd_title">Version %1$s is out</string>
|
||||
<string name="upd_you_have">You have %1$s</string>
|
||||
<string name="upd_whats_new">What’s new</string>
|
||||
<string name="upd_whats_new_cd">What’s new, opens the page on GitHub</string>
|
||||
<string name="upd_update">Update</string>
|
||||
<string name="upd_install">Install</string>
|
||||
<string name="upd_hidden_snack">The update is in Settings, under About</string>
|
||||
<string name="upd_keeps">Databases, settings and the engine stay.</string>
|
||||
<string name="upd_keeps_no_engine">Databases and settings stay.</string>
|
||||
<string name="upd_closes">ChessPenguin closes while it installs — then open it again.</string>
|
||||
<string name="upd_online_note">Games are downloading: installing stops it; you can continue it later.</string>
|
||||
<string name="upd_perm_title">One permission is needed</string>
|
||||
<string name="upd_perm_body">Android installs apps from outside a store only with your permission. Settings will open: turn the switch on for ChessPenguin and come back.</string>
|
||||
<string name="upd_perm_open">Open settings</string>
|
||||
<string name="upd_perm_denied">The permission is off — without it Android won’t install the new version.</string>
|
||||
<string name="upd_perm_granted">Permission granted, downloading</string>
|
||||
<string name="upd_on_site">Download from the website</string>
|
||||
<string name="upd_open_site">Open the website</string>
|
||||
<string name="upd_leave">You can close this: the download goes on.</string>
|
||||
<string name="upd_waiting_net">No network. The download goes on by itself when the network is back.</string>
|
||||
<string name="upd_waiting_net_short">Waiting for network</string>
|
||||
<string name="upd_checking_file">Checking the file…</string>
|
||||
<string name="upd_keeping_engine">Keeping the engine…</string>
|
||||
<string name="upd_installing">Installing…</string>
|
||||
<string name="upd_ready">The new version is downloaded and checked.</string>
|
||||
<string name="upd_ready_short">Downloaded and checked</string>
|
||||
<string name="upd_ready_snack">The new version is downloaded</string>
|
||||
<string name="upd_aborted">Installation cancelled. The new version is downloaded — install it whenever you like.</string>
|
||||
<string name="upd_notification">ChessPenguin update</string>
|
||||
<string name="upd_done_snack">ChessPenguin is updated: %1$s → %2$s</string>
|
||||
<string name="upd_err_failed">The download failed. Try again.</string>
|
||||
<string name="upd_err_corrupt">The file got damaged while downloading, so it was not installed. Try again.</string>
|
||||
<string name="upd_err_release">Something is wrong with this release: the Android file cannot be checked. Download the new version from the website.</string>
|
||||
<string name="upd_err_storage">Android did not install the new version: not enough space. Free %1$d MB and try again.</string>
|
||||
<string name="upd_err_conflict">Android did not install the new version: this ChessPenguin is signed with a different key. The new version can only be installed after removing this one, and removing it loses the list of databases and the downloaded databases.</string>
|
||||
<string name="upd_err_blocked">Android or the phone’s protection stopped the installation. Download the new version from the website.</string>
|
||||
<string name="upd_err_install">Android did not install the new version. Try again or download it from the website.</string>
|
||||
<string name="upd_short_offline">No internet</string>
|
||||
<string name="upd_short_space">Not enough space</string>
|
||||
<string name="upd_short_corrupt">The file got damaged</string>
|
||||
<string name="upd_short_install">Android did not install it</string>
|
||||
<string name="upd_short_failed">The download failed</string>
|
||||
<string name="upd_more">More</string>
|
||||
<string name="upd_details">Details</string>
|
||||
<string name="upd_copy">Copy</string>
|
||||
<string name="upd_group">Updates</string>
|
||||
<string name="upd_auto">Check for updates at start</string>
|
||||
<string name="upd_auto_sub">Once a day ChessPenguin asks GitHub which version is the latest; nothing about you is sent.</string>
|
||||
<string name="upd_check_now">Check now</string>
|
||||
<string name="upd_checking">Checking…</string>
|
||||
<string name="upd_latest">You have the latest version</string>
|
||||
<string name="upd_checked">Checked %1$s</string>
|
||||
<string name="upd_check_offline">No internet — cannot check for updates</string>
|
||||
<string name="upd_check_failed">Could not check for updates: GitHub did not answer. Try later.</string>
|
||||
<string name="s_about_available">Version %1$s is out</string>
|
||||
<string name="s_about_downloading">Downloading version %1$s…</string>
|
||||
<string name="s_about_ready">Version %1$s is downloaded</string>
|
||||
<string name="upd_card_downloading">Update to %1$s, %2$d of %3$d megabytes downloaded</string>
|
||||
<!-- Shown only when the interface is not in English. -->
|
||||
<string name="upd_notes_english">The list of changes is on GitHub, in English.</string>
|
||||
<string name="upd_short_release">The file cannot be checked</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue