Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class OfflineStoreEstimateTest {
val folder = TemporaryFolder()

private class VersionStore : AssetVersionStore {
override fun load(): String? = null
override fun save(version: String) = Unit
override fun load(language: String): String? = null
override fun save(language: String, version: String) = Unit
}

private fun bundle() = OfflineBundle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class OfflineStoreVersionTest {
val folder = TemporaryFolder()

private class VersionStore : AssetVersionStore {
override fun load(): String? = null
override fun save(version: String) = Unit
override fun load(language: String): String? = null
override fun save(language: String, version: String) = Unit
}

private fun bundle() = OfflineBundle(
Expand Down
4 changes: 2 additions & 2 deletions androidApp/src/test/java/com/glosso/app/ServerSwitchTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class ServerSwitchTest {
ProductConfigRepository.api = { api }
api.manifest()
ProductConfigRepository.refresh()
assertEquals("a-v1", ApiCache.load())
assertEquals("a-v1", ApiCache.load("en"))
assertTrue(ProductConfigRepository.config.value.flag("server_a"))
assertEquals("learner@example.com", GoogleAccountStore.email.value)

Expand All @@ -167,7 +167,7 @@ class ServerSwitchTest {
assertNull("an account linked on A is not linked on B", GoogleAccountStore.email.value)
assertFalse(ProductConfigRepository.config.value.flag("server_a"))
assertTrue(ProductConfigRepository.config.value.flag("server_b"))
assertEquals("b-v1", ApiCache.load())
assertEquals("b-v1", ApiCache.load("en"))
assertEquals("b-v1", api.contentVersion)
assertTrue(requests.isNotEmpty())
assertTrue("every request goes to B: $requests", requests.all { it.startsWith("https://b.test/") })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class GlossoApiCacheTest {

private class VersionStore(initial: String? = null) : AssetVersionStore {
var value: String? = initial
override fun load(): String? = value
override fun save(version: String) {
override fun load(language: String): String? = value
override fun save(language: String, version: String) {
value = version
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class GlossoApiResumeTest {
val folder = TemporaryFolder()

private class VersionStore : AssetVersionStore {
override fun load(): String? = null
override fun save(version: String) = Unit
override fun load(language: String): String? = null
override fun save(language: String, version: String) = Unit
}

private fun api(engine: MockEngine) = GlossoApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ class AndroidStorageCompatibilityTest {

prefs("glosso_http_cache").edit().putString("asset_version", "v42").commit()
ApiCache.init(app)
assertEquals("v42", ApiCache.load())
ApiCache.save("v43")
assertEquals("v43", prefs("glosso_http_cache").getString("asset_version", null))
// The single pre-course key passes to the first course asked for: the one in use.
assertEquals("v42", ApiCache.load("ru"))
assertNull(prefs("glosso_http_cache").getString("asset_version", null))
assertNull(ApiCache.load("en"))
ApiCache.save("ru", "v43")
assertEquals("v43", prefs("glosso_http_cache").getString("asset_version_ru", null))

UiLanguage.init(app)
assertEquals("en", UiLanguage.current.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ internal fun SoundDial(
drawArc(color, -90f, 360f * fill.value, false, topLeft, arc, style = Stroke(w, cap = StrokeCap.Round))
}
Text(
text = phoneme,
text = GlossoType.ipa(phoneme),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
Expand Down
4 changes: 2 additions & 2 deletions shared/src/commonMain/kotlin/com/glosso/app/LessonsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ private fun VocabularyWord(word: WordModel, onPlay: () -> Unit) {
if (showPhonetics && ipa.isNotBlank()) {
Spacer(Modifier.height(Space.x2))
Text(
text = ipa,
text = GlossoType.ipa(ipa),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ internal fun DialogueTurn(
if (showPhonetics && ipa.isNotBlank()) {
Spacer(Modifier.height(Space.x4))
Text(
text = ipa,
text = GlossoType.ipa(ipa),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.material.icons.outlined.GraphicEq
import androidx.compose.material.icons.outlined.Quiz
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down Expand Up @@ -207,9 +208,12 @@ fun OnboardingScreen(onFinish: () -> Unit) {
GlossoWordmark(Modifier.weight(1f))
// The header skip leaves the whole onboarding. On the seed page
// the footer already offers the same exit with a clearer label, so
// the header one is hidden there to avoid two identical exits.
// the header one is hidden there to avoid two identical exits. Its
// touch-target height stays, so the logo does not jump between pages.
if (page < LAST_PAGE) {
QuietTextButton(stringResource(Res.string.onboarding_skip), onClick = { finish(true) })
} else {
Spacer(Modifier.minimumInteractiveComponentSize())
}
}

Expand Down
10 changes: 5 additions & 5 deletions shared/src/commonMain/kotlin/com/glosso/app/PracticeUi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ internal fun DrillCard(
if (showPhonetics && ipa.isNotBlank()) {
Spacer(Modifier.height(Space.x12))
Text(
text = ipa,
text = GlossoType.ipa(ipa),
style = GlossoType.MonoIPA,
color = GlossoColors.accentText,
)
Expand Down Expand Up @@ -546,7 +546,7 @@ private fun SoundTile(sound: PhoneticLoop.SoundScore, modifier: Modifier = Modif
Column(Modifier.padding(horizontal = Space.x12, vertical = Space.x12)) {
Row(verticalAlignment = Alignment.Bottom) {
Text(
text = "/${shownSound(sound.phoneme)}/",
text = GlossoType.ipa("/${shownSound(sound.phoneme)}/"),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
Expand Down Expand Up @@ -978,7 +978,7 @@ internal fun ExampleWords(words: List<String>, modifier: Modifier = Modifier) {
)
} else {
Text(
text = word,
text = GlossoType.ipa(word),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.padding(vertical = Space.x8),
Expand Down Expand Up @@ -1023,7 +1023,7 @@ private fun ExampleWordChip(word: String, playing: Boolean, onClick: () -> Unit)
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = word,
text = GlossoType.ipa(word),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onPrimaryContainer,
)
Expand Down Expand Up @@ -1196,7 +1196,7 @@ private fun FocusTrend(focus: FocusPractice) {
)
Spacer(Modifier.height(Space.x2))
Text(
text = trend,
text = GlossoType.ipa(trend),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand Down
8 changes: 4 additions & 4 deletions shared/src/commonMain/kotlin/com/glosso/app/YouScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private fun PronunciationPanel(
Spacer(Modifier.height(Space.x16))
moved.forEach { (phoneme, from, to) ->
Text(
text = stringResource(Res.string.you_sound_delta, shownSound(phoneme), from, to),
text = GlossoType.ipa(stringResource(Res.string.you_sound_delta, shownSound(phoneme), from, to)),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand All @@ -309,7 +309,7 @@ private fun SoundBarRow(stat: PhonemeStatModel, todayDelta: Int?) {
val color = accuracyColor(stat.accuracy)
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = "/${shownSound(stat.phoneme)}/",
text = GlossoType.ipa("/${shownSound(stat.phoneme)}/"),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.widthIn(min = 52.dp),
Expand Down Expand Up @@ -465,7 +465,7 @@ private fun PracticeRow(item: PracticeItem) {
when (item.kind) {
PracticeKind.SOUND -> Text(
text = if (showPhonetics) {
shownSound(item.phoneme.orEmpty())
GlossoType.ipa(shownSound(item.phoneme.orEmpty()))
} else {
stringResource(Res.string.you_plan_sound)
},
Expand Down Expand Up @@ -819,7 +819,7 @@ private fun FocusNote(stat: PhonemeStatModel) {
) {
if (showPhonetics) {
Text(
shownSound(stat.phoneme),
GlossoType.ipa(shownSound(stat.phoneme)),
style = GlossoType.MonoIPA,
color = MaterialTheme.colorScheme.onPrimaryContainer,
)
Expand Down
25 changes: 19 additions & 6 deletions shared/src/commonMain/kotlin/com/glosso/app/api/ApiCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.concurrent.Volatile

/**
* Process-wide HTTP cache: a size-bounded, LRU disk store under the cache dir and
* the persisted content version. Initialised from the application context.
* the persisted content version of each course. Initialised from the application context.
*/
object ApiCache : AssetVersionStore {
private const val FILE = "glosso_http_cache"
Expand All @@ -30,15 +30,28 @@ object ApiCache : AssetVersionStore {
/** The shared disk cache, or null before [init] (tests inject their own). */
fun storageOrNull(): LruCacheStorage? = storage

override fun load(): String? = prefs?.getString(KEY)?.takeIf { it.isNotBlank() }
override fun load(language: String): String? {
val prefs = prefs ?: return null
// Before versions were per course, one key held the version of the course
// in use. The first course asked for after the update is that course
// (the client is built for it), so it inherits the key and an offline
// start still reaches what is cached.
prefs.getString(KEY)?.let { legacy ->
prefs.edit(commit = true) {
remove(KEY)
if (!prefs.contains("${KEY}_$language")) putString("${KEY}_$language", legacy)
}
}
return prefs.getString("${KEY}_$language")?.takeIf { it.isNotBlank() }
}

override fun save(version: String) {
prefs?.edit { putString(KEY, version) }
override fun save(language: String, version: String) {
prefs?.edit { putString("${KEY}_$language", version) }
}

/** Drops the content version and every cached response (a server switch). */
/** Drops every course's content version and every cached response (a server switch). */
suspend fun forget() {
prefs?.edit(commit = true) { remove(KEY) }
prefs?.edit(commit = true) { clear() }
storage?.clear()
}
}
11 changes: 6 additions & 5 deletions shared/src/commonMain/kotlin/com/glosso/app/api/ApiStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package com.glosso.app.api
/**
* Remembers the content version across restarts. The version is part of every
* content URL (`?v=`), so persisting it is what lets a cold, offline start reach
* the entries already on disk.
* the entries already on disk. Each course has its own catalogue, so the version
* is kept per target language.
*/
interface AssetVersionStore {
fun load(): String?
fun save(version: String)
fun load(language: String): String?
fun save(language: String, version: String)

/** No persistence; used when a caller injects its own cache. */
object None : AssetVersionStore {
override fun load(): String? = null
override fun save(version: String) = Unit
override fun load(language: String): String? = null
override fun save(language: String, version: String) = Unit
}
}
Loading