Ship the real club crests in the APK, and fix the CI licence step
All checks were successful
Build TV app / build (push) Successful in 4m15s
All checks were successful
Build TV app / build (push) Successful in 4m15s
Resolving crests from Wikipedia at runtime never produced a visible badge on the TV and left nothing in the log to debug, so the shield fallback was all anyone ever saw. They are now downloaded once at build time by tools/fetch-crests.py into assets/crests (git-ignored, so no trademarked artwork is committed) and loaded from there — instant, and independent of the network. CI: accepting SDK licences by piping "yes" into sdkmanager died of SIGPIPE (exit 141) under pipefail; the licence hashes are written directly now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,15 +18,22 @@ class Crests(context: Context) {
|
||||
|
||||
private val prefs = context.getSharedPreferences("crests", Context.MODE_PRIVATE)
|
||||
|
||||
/** Cached crest URL for a club, fetching it once per article. */
|
||||
/** Cached crest URL for a club, fetched once and then reused. */
|
||||
suspend fun urlFor(article: String): String? = withContext(Dispatchers.IO) {
|
||||
prefs.getString(article, null)?.let { return@withContext it.ifEmpty { null } }
|
||||
prefs.getString(article, null)?.takeIf { it.isNotEmpty() }?.let {
|
||||
return@withContext it
|
||||
}
|
||||
val resolved = runCatching { fetch(article) }
|
||||
.onFailure { Log.w(TAG, "crest lookup failed: ${it.javaClass.simpleName}") }
|
||||
.onFailure { Log.w(TAG, "crest lookup failed for $article: $it") }
|
||||
.getOrNull()
|
||||
// Remember misses too, so a club without a crest is not looked up
|
||||
// again on every screen.
|
||||
prefs.edit().putString(article, resolved.orEmpty()).apply()
|
||||
if (resolved != null) {
|
||||
Log.i(TAG, "crest for $article: $resolved")
|
||||
prefs.edit().putString(article, resolved).apply()
|
||||
} else {
|
||||
// Deliberately not cached: a single failed lookup (no network
|
||||
// yet at start-up) must not hide the crest forever.
|
||||
Log.w(TAG, "no crest for $article")
|
||||
}
|
||||
resolved
|
||||
}
|
||||
|
||||
@@ -41,6 +48,8 @@ class Crests(context: Context) {
|
||||
val body = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
JSONObject(body).optJSONObject("thumbnail")?.optString("source")
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
// Drop the analytics query the API appends.
|
||||
?.substringBefore("?")
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ object TeamFilters {
|
||||
club("duisburg", "MSV", "MSV Duisburg", listOf("msv duisburg", "duisburg"), 0xFF004E9E, WHITE),
|
||||
club("mannheim", "SVWM", "SV Waldhof Mannheim", listOf("waldhof mannheim", "waldhof"), 0xFF0B4EA2, WHITE),
|
||||
club("wehen", "SVWW", "SV Wehen Wiesbaden", listOf("wehen wiesbaden", "wehen"), 0xFFE1000F, BLACK),
|
||||
club("ulm", "SSV", "SSV Ulm 1846", listOf("ssv ulm"), 0xFFE1000F, WHITE),
|
||||
club("ulm", "SSV", "SSV Ulm 1846", listOf("ssv ulm"), 0xFFE1000F, WHITE, article = "SSV Ulm 1846 Fußball"),
|
||||
club("regensburg", "SSVJ", "SSV Jahn Regensburg", listOf("jahn regensburg", "regensburg"), 0xFFE1000F, WHITE),
|
||||
club("verl", "SCV", "SC Verl", listOf("sc verl"), 0xFF00703C, WHITE),
|
||||
club("viktoria", "VKÖ", "Viktoria Köln", listOf("viktoria köln"), 0xFFE1000F, WHITE),
|
||||
@@ -108,7 +108,7 @@ object TeamFilters {
|
||||
club("ingolstadt", "FCI", "FC Ingolstadt 04", listOf("ingolstadt"), 0xFFE1000F, BLACK),
|
||||
club("wuppertal", "WSV", "Wuppertaler SV", listOf("wuppertaler sv"), 0xFFE1000F, 0xFF0B4EA2),
|
||||
club("stuttgart-ii", "VfB2", "VfB Stuttgart II", listOf("vfb stuttgart ii"), 0xFFE32219, BLACK),
|
||||
club("hoffenheim-ii", "TSG2", "TSG Hoffenheim II", listOf("hoffenheim ii"), 0xFF1C63B7, BLACK),
|
||||
club("hoffenheim-ii", "TSG2", "TSG Hoffenheim II", listOf("hoffenheim ii"), 0xFF1C63B7, BLACK, article = "TSG 1899 Hoffenheim"),
|
||||
)
|
||||
|
||||
/** Clubs switched on for a viewer before they touch the settings. */
|
||||
|
||||
@@ -433,28 +433,21 @@ private fun ChannelRow(
|
||||
}
|
||||
|
||||
/**
|
||||
* The club badge, resolved from Wikipedia and cached on the device. Until
|
||||
* it arrives (or if it never does) a shield in the club colours stands in.
|
||||
* The club badge. The images ship in the APK (fetched at build time by
|
||||
* tools/fetch-crests.py, never committed), so nothing has to load over the
|
||||
* network; the coloured shield stands in if one is ever missing.
|
||||
*/
|
||||
@Composable
|
||||
private fun Crest(team: dev.castarr.tv.data.TeamFilter, state: AppState) {
|
||||
val url by androidx.compose.runtime.produceState<String?>(null, team.key) {
|
||||
value = state.crests.urlFor(team.article)
|
||||
}
|
||||
Box(Modifier.size(20.dp), contentAlignment = Alignment.Center) {
|
||||
val crestUrl = url
|
||||
if (crestUrl != null) {
|
||||
SubcomposeAsyncImage(
|
||||
model = crestUrl,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Fit,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
loading = { ShieldFallback(team) },
|
||||
error = { ShieldFallback(team) },
|
||||
)
|
||||
} else {
|
||||
ShieldFallback(team)
|
||||
}
|
||||
SubcomposeAsyncImage(
|
||||
model = "file:///android_asset/crests/${team.key}.png",
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Fit,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
loading = { ShieldFallback(team) },
|
||||
error = { ShieldFallback(team) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -84,7 +86,14 @@ fun SettingsScreen(state: AppState) {
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 40.dp, vertical = 12.dp)
|
||||
) {
|
||||
Column(Modifier.weight(1.25f), verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
// The cards outgrew one screen once club menus arrived; focus
|
||||
// movement scrolls this column along.
|
||||
Column(
|
||||
Modifier
|
||||
.weight(1.25f)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
SettingsCard("Konto") {
|
||||
if (state.auth.isLoggedIn) {
|
||||
Row(
|
||||
|
||||
Reference in New Issue
Block a user