Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3105925bb | ||
|
|
7f1dff5661 | ||
|
|
869060c56f | ||
|
|
7ad7f5172e | ||
|
|
753ab3a3ab | ||
|
|
f157323626 |
20
.github/workflows/build.yml
vendored
20
.github/workflows/build.yml
vendored
@@ -8,20 +8,32 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
# Full URLs: this Gitea resolves bare action names against itself,
|
||||
# where these actions do not exist.
|
||||
- uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-java@v4
|
||||
- uses: https://github.com/actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: "17"
|
||||
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- uses: https://github.com/gradle/actions/setup-gradle@v4
|
||||
|
||||
- name: Unit tests
|
||||
run: ./gradlew testDebugUnitTest --stacktrace
|
||||
|
||||
- name: Build debug APK
|
||||
run: ./gradlew assembleDebug --stacktrace
|
||||
|
||||
- name: Upload APK
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: https://github.com/actions/upload-artifact@v4
|
||||
with:
|
||||
name: castarr-debug-apk
|
||||
path: app/build/outputs/apk/debug/app-debug.apk
|
||||
|
||||
- name: Upload test report
|
||||
if: always()
|
||||
uses: https://github.com/actions/upload-artifact@v4
|
||||
with:
|
||||
name: castarr-test-report
|
||||
path: tests/runs/
|
||||
|
||||
@@ -38,7 +38,7 @@ TV-Fernbedienung oder steuert alles bequem vom Handy aus.
|
||||
1. Auf dem Google TV die App **Downloader** installieren (oder einen anderen
|
||||
Weg nutzen, eine APK-Datei zu öffnen).
|
||||
2. Diese Adresse eingeben:
|
||||
`git.beckm4nn.net/benjamin/castarr/raw/branch/apk/castarr.apk`
|
||||
`git.beckm4nn.net/be-nj/castarr/raw/branch/apk/castarr.apk`
|
||||
3. Installation bestätigen („Unbekannte Quellen" für Downloader erlauben,
|
||||
wenn der Fernseher fragt).
|
||||
4. Castarr starten und den drei Schritten auf dem Bildschirm folgen:
|
||||
|
||||
@@ -12,8 +12,8 @@ android {
|
||||
applicationId = "dev.castarr.tv"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 23
|
||||
versionName = "0.9.0"
|
||||
versionCode = 29
|
||||
versionName = "0.10.3"
|
||||
}
|
||||
|
||||
// Release signing from environment (see ~/.keys/castarr-release.env on the
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.compose.runtime.setValue
|
||||
import dev.castarr.tv.auth.DeviceAuth
|
||||
import dev.castarr.tv.data.DispatcharrRepository
|
||||
import dev.castarr.tv.data.NowNext
|
||||
import dev.castarr.tv.data.isEpgPlaceholder
|
||||
import dev.castarr.tv.data.SourceRepository
|
||||
import dev.castarr.tv.player.PlayerController
|
||||
import dev.castarr.tv.playlist.Channel
|
||||
@@ -26,6 +27,7 @@ class AppState(
|
||||
val dispatcharr: DispatcharrRepository,
|
||||
) {
|
||||
private val prefs = context.getSharedPreferences("app", Context.MODE_PRIVATE)
|
||||
val crests = dev.castarr.tv.data.Crests(context)
|
||||
|
||||
var screen by mutableStateOf(Screen.LIVE)
|
||||
var playerVisible by mutableStateOf(false)
|
||||
@@ -38,6 +40,37 @@ class AppState(
|
||||
var isLive by mutableStateOf(false)
|
||||
var favoritesOnly by mutableStateOf(false)
|
||||
var groupFilter by mutableStateOf<String?>(null)
|
||||
|
||||
/** Club shortcut currently open in the rail, if any. */
|
||||
var activeTeam by mutableStateOf<String?>(null)
|
||||
|
||||
/**
|
||||
* Club menus switched on for this TV. Seeded from the signed-in viewer's
|
||||
* own club; every club can be toggled on in the settings, so a household
|
||||
* can watch for more than one.
|
||||
*/
|
||||
var enabledTeams by mutableStateOf(loadEnabledTeams())
|
||||
private set
|
||||
|
||||
private fun loadEnabledTeams(): Set<String> {
|
||||
val stored = prefs.getStringSet("teams", null)
|
||||
if (stored != null) return stored.toSet()
|
||||
return dev.castarr.tv.data.TeamFilters.defaultKeysFor(auth.username).toSet()
|
||||
}
|
||||
|
||||
/** Returns false when the cap of [TeamFilters.MAX_ACTIVE] is reached. */
|
||||
fun toggleTeam(key: String): Boolean {
|
||||
if (key !in enabledTeams &&
|
||||
enabledTeams.size >= dev.castarr.tv.data.TeamFilters.MAX_ACTIVE
|
||||
) {
|
||||
return false
|
||||
}
|
||||
enabledTeams =
|
||||
if (key in enabledTeams) enabledTeams - key else enabledTeams + key
|
||||
prefs.edit().putStringSet("teams", enabledTeams).apply()
|
||||
if (activeTeam == key && key !in enabledTeams) activeTeam = null
|
||||
return true
|
||||
}
|
||||
var audioTracks by mutableStateOf<List<PlayerController.AudioTrack>>(emptyList())
|
||||
private set
|
||||
private var lastNowTitle: String? = null
|
||||
@@ -51,6 +84,13 @@ class AppState(
|
||||
/** Channel to restore focus to when the list comes back (#13). */
|
||||
var lastWatched by mutableStateOf<Channel?>(null)
|
||||
|
||||
/**
|
||||
* True while the list is being restored after playback. The group rail
|
||||
* opens whatever gets focused, so without this the focus landing there
|
||||
* would silently switch the view back to "Alle Sender".
|
||||
*/
|
||||
var restorePending by mutableStateOf(false)
|
||||
|
||||
private val reentryHandler = android.os.Handler(android.os.Looper.getMainLooper())
|
||||
private var lastStoppedUrl: String = ""
|
||||
private var lastStoppedAt: Long = 0L
|
||||
@@ -125,6 +165,29 @@ class AppState(
|
||||
SourceMode.DISPATCHARR -> dispatcharr.nowNext(channel)
|
||||
}
|
||||
|
||||
private fun upcoming(channel: Channel, windowMs: Long) = when (sourceMode) {
|
||||
SourceMode.GENERIC -> source.upcoming(channel, windowMs)
|
||||
SourceMode.DISPATCHARR -> dispatcharr.upcoming(channel, windowMs)
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels showing the viewer's club within the scanned window, paired
|
||||
* with the programme that matched — earliest kick-off first, so whatever
|
||||
* is running right now sits on top.
|
||||
*/
|
||||
fun teamMatches(key: String): List<Pair<Channel, dev.castarr.tv.data.Programme>> {
|
||||
val filter = dev.castarr.tv.data.TeamFilters.byKey(key) ?: return emptyList()
|
||||
val window = dev.castarr.tv.data.TeamFilters.WINDOW_MS
|
||||
return activeChannels()
|
||||
.filter { dev.castarr.tv.data.TeamFilters.scansGroup(it.group) }
|
||||
.mapNotNull { channel ->
|
||||
upcoming(channel, window)
|
||||
.firstOrNull { !isEpgPlaceholder(it.title) && filter.matches(it.title) }
|
||||
?.let { channel to it }
|
||||
}
|
||||
.sortedBy { it.second.start }
|
||||
}
|
||||
|
||||
fun refreshActive() {
|
||||
when (sourceMode) {
|
||||
SourceMode.GENERIC -> source.refresh()
|
||||
@@ -161,6 +224,8 @@ class AppState(
|
||||
}
|
||||
|
||||
fun startOnboarding() {
|
||||
prefs.edit().remove("teams").apply()
|
||||
activeTeam = null
|
||||
auth.logout()
|
||||
appError = AppError.NONE
|
||||
welcomePhase = WelcomePhase.WAIT_PHONE
|
||||
@@ -190,6 +255,7 @@ class AppState(
|
||||
}
|
||||
|
||||
fun stopPlayback() {
|
||||
restorePending = lastWatched != null
|
||||
reentryHandler.removeCallbacksAndMessages(null)
|
||||
lastStoppedUrl = currentChannel?.url.orEmpty()
|
||||
lastStoppedAt = System.currentTimeMillis()
|
||||
|
||||
@@ -50,7 +50,14 @@ class MainActivity : ComponentActivity(), ControlServer.Listener {
|
||||
server.startServer()
|
||||
state.remoteAvailable = server.running
|
||||
setContent { CastarrApp(state) }
|
||||
lifecycleScope.launch { UpdateChecker.check(state) }
|
||||
lifecycleScope.launch {
|
||||
// At start-up and then occasionally: a TV often keeps the same
|
||||
// app process alive for days.
|
||||
while (true) {
|
||||
UpdateChecker.check(state)
|
||||
delay(UPDATE_CHECK_INTERVAL_MS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onPlaybackChanged() {
|
||||
@@ -325,5 +332,6 @@ class MainActivity : ComponentActivity(), ControlServer.Listener {
|
||||
const val TICK_INTERVAL_MS = 2_000L
|
||||
const val SEEK_STEP_SECONDS = 10L
|
||||
const val DIGIT_COMMIT_MS = 1_800L
|
||||
const val UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000L
|
||||
}
|
||||
}
|
||||
|
||||
54
app/src/main/java/dev/castarr/tv/data/Crests.kt
Normal file
54
app/src/main/java/dev/castarr/tv/data/Crests.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
package dev.castarr.tv.data
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
|
||||
/**
|
||||
* Resolves club crests at runtime from Wikipedia's page summary. The badges
|
||||
* are trademarks, so they are fetched and cached on the device rather than
|
||||
* shipped with the app — nothing copyrighted lives in the repository.
|
||||
*/
|
||||
class Crests(context: Context) {
|
||||
|
||||
private val prefs = context.getSharedPreferences("crests", Context.MODE_PRIVATE)
|
||||
|
||||
/** Cached crest URL for a club, fetching it once per article. */
|
||||
suspend fun urlFor(article: String): String? = withContext(Dispatchers.IO) {
|
||||
prefs.getString(article, null)?.let { return@withContext it.ifEmpty { null } }
|
||||
val resolved = runCatching { fetch(article) }
|
||||
.onFailure { Log.w(TAG, "crest lookup failed: ${it.javaClass.simpleName}") }
|
||||
.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()
|
||||
resolved
|
||||
}
|
||||
|
||||
private fun fetch(article: String): String? {
|
||||
val encoded = URLEncoder.encode(article, "UTF-8").replace("+", "%20")
|
||||
val connection = URL("$SUMMARY$encoded").openConnection() as HttpURLConnection
|
||||
return try {
|
||||
connection.connectTimeout = 10_000
|
||||
connection.readTimeout = 10_000
|
||||
connection.setRequestProperty("User-Agent", USER_AGENT)
|
||||
connection.setRequestProperty("Accept", "application/json")
|
||||
val body = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
JSONObject(body).optJSONObject("thumbnail")?.optString("source")
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TAG = "Crests"
|
||||
const val SUMMARY = "https://de.wikipedia.org/api/rest_v1/page/summary/"
|
||||
const val USER_AGENT = "Castarr TV (private use)"
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,12 @@ class DispatcharrRepository(context: Context, private val auth: DeviceAuth) {
|
||||
fun nowNext(channel: Channel): NowNext =
|
||||
XmltvParser.nowNext(programmesByTvgId[channel.tvgId])
|
||||
|
||||
/** Programmes of this channel between now and now + [windowMs]. */
|
||||
fun upcoming(channel: Channel, windowMs: Long): List<Programme> {
|
||||
val now = System.currentTimeMillis()
|
||||
return XmltvParser.programmesIn(programmesByTvgId[channel.tvgId], now, now + windowMs)
|
||||
}
|
||||
|
||||
fun toggleFavorite(channel: Channel) {
|
||||
if (channel.backendId == 0) return
|
||||
scope.launch {
|
||||
|
||||
@@ -82,13 +82,20 @@ class SourceRepository(context: Context) {
|
||||
status.value = ""
|
||||
}
|
||||
|
||||
/** Now/Next for an M3U channel: match tvg-id first, then name. */
|
||||
fun nowNext(channel: Channel): NowNext {
|
||||
val direct = channel.tvgId.takeIf { it.isNotEmpty() }?.let { programmes[it] }
|
||||
val byName = direct ?: nameToEpgId[channel.name.lowercase()]?.let { programmes[it] }
|
||||
return XmltvParser.nowNext(byName)
|
||||
/** Programmes of this channel between now and now + [windowMs]. */
|
||||
fun upcoming(channel: Channel, windowMs: Long): List<Programme> {
|
||||
val now = System.currentTimeMillis()
|
||||
return XmltvParser.programmesIn(programmesFor(channel), now, now + windowMs)
|
||||
}
|
||||
|
||||
private fun programmesFor(channel: Channel): List<Programme>? {
|
||||
val direct = channel.tvgId.takeIf { it.isNotEmpty() }?.let { programmes[it] }
|
||||
return direct ?: nameToEpgId[channel.name.lowercase()]?.let { programmes[it] }
|
||||
}
|
||||
|
||||
/** Now/Next for an M3U channel: match tvg-id first, then name. */
|
||||
fun nowNext(channel: Channel): NowNext = XmltvParser.nowNext(programmesFor(channel))
|
||||
|
||||
private fun loadCachedChannels() {
|
||||
runCatching {
|
||||
val cached = prefs.getString("channels_cache", null) ?: return
|
||||
|
||||
143
app/src/main/java/dev/castarr/tv/data/TeamFilters.kt
Normal file
143
app/src/main/java/dev/castarr/tv/data/TeamFilters.kt
Normal file
@@ -0,0 +1,143 @@
|
||||
package dev.castarr.tv.data
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
/**
|
||||
* Per-club shortcut to "where does my club play tonight": a rail entry that
|
||||
* lists every channel whose EPG mentions the club within the next few hours.
|
||||
* Crests are fetched from Wikipedia at runtime and cached on the device;
|
||||
* the club colours are the fallback while that is pending or unavailable.
|
||||
*/
|
||||
data class TeamFilter(
|
||||
val key: String,
|
||||
/** Short caption next to the crest in the rail. */
|
||||
val label: String,
|
||||
/** Full club name, shown in the settings and in messages. */
|
||||
val fullName: String,
|
||||
/** Lowercase needles matched against programme titles. */
|
||||
val needles: List<String>,
|
||||
val primary: Color,
|
||||
val secondary: Color,
|
||||
/** German Wikipedia article the crest is resolved from. */
|
||||
val article: String,
|
||||
) {
|
||||
fun matches(title: String): Boolean {
|
||||
val haystack = title.lowercase()
|
||||
return needles.any { haystack.contains(it) }
|
||||
}
|
||||
}
|
||||
|
||||
object TeamFilters {
|
||||
|
||||
/** Window scanned ahead of now. */
|
||||
const val WINDOW_MS = 3 * 60 * 60 * 1000L
|
||||
|
||||
/** At most this many club groups sit in the rail at once. */
|
||||
const val MAX_ACTIVE = 3
|
||||
|
||||
private const val WHITE = 0xFFF2F3F5
|
||||
private const val BLACK = 0xFF15171B
|
||||
|
||||
private fun club(
|
||||
key: String,
|
||||
label: String,
|
||||
fullName: String,
|
||||
needles: List<String>,
|
||||
primary: Long,
|
||||
secondary: Long,
|
||||
article: String = fullName,
|
||||
) = TeamFilter(key, label, fullName, needles, Color(primary), Color(secondary), article)
|
||||
|
||||
/** Clubs of the top three German divisions. */
|
||||
val all: List<TeamFilter> = listOf(
|
||||
// --- Bundesliga ---
|
||||
club("bayern", "FCB", "FC Bayern München", listOf("bayern münchen", "fc bayern"), 0xFFDC052D, WHITE),
|
||||
club("bvb", "BVB", "Borussia Dortmund", listOf("borussia dortmund", "bvb"), 0xFFFDE100, BLACK),
|
||||
club("leipzig", "RBL", "RB Leipzig", listOf("rb leipzig"), 0xFFDD0741, WHITE),
|
||||
club("leverkusen", "B04", "Bayer 04 Leverkusen", listOf("leverkusen"), 0xFFE32219, BLACK),
|
||||
club("frankfurt", "SGE", "Eintracht Frankfurt", listOf("eintracht frankfurt"), 0xFF1A1A1A, 0xFFE1000F),
|
||||
club("stuttgart", "1893", "VfB Stuttgart", listOf("vfb stuttgart"), 0xFFE32219, WHITE),
|
||||
club("gladbach", "BMG", "Borussia Mönchengladbach", listOf("mönchengladbach", "gladbach"), 0xFF1A1A1A, 0xFF00A94F),
|
||||
club("wolfsburg", "WOB", "VfL Wolfsburg", listOf("wolfsburg"), 0xFF65B32E, WHITE),
|
||||
club("bremen", "SVW", "SV Werder Bremen", listOf("werder bremen", "werder"), 0xFF1D9053, WHITE),
|
||||
club("freiburg", "SCF", "SC Freiburg", listOf("sc freiburg", "freiburg"), 0xFFE2001A, WHITE),
|
||||
club("hoffenheim", "TSG", "TSG Hoffenheim", listOf("hoffenheim"), 0xFF1C63B7, WHITE),
|
||||
club("mainz", "M05", "1. FSV Mainz 05", listOf("mainz 05", "mainz"), 0xFFE1000F, WHITE),
|
||||
club("augsburg", "FCA", "FC Augsburg", listOf("augsburg"), 0xFF00693F, 0xFFE1000F),
|
||||
club("union", "FCU", "1. FC Union Berlin", listOf("union berlin"), 0xFFE1000F, 0xFFFDE100),
|
||||
club("koeln", "EFC", "1. FC Köln", listOf("1. fc köln", "fc köln"), 0xFFE1000F, WHITE),
|
||||
club("hsv", "HSV", "Hamburger SV", listOf("hamburger sv", "hsv"), 0xFF0E5EA6, BLACK),
|
||||
club("heidenheim", "FCH1", "1. FC Heidenheim", listOf("heidenheim"), 0xFFE1000F, 0xFF1656A4),
|
||||
club("st-pauli", "FCSP", "FC St. Pauli", listOf("st. pauli", "st pauli"), 0xFF6B4423, WHITE),
|
||||
// --- 2. Bundesliga ---
|
||||
club("schalke", "S04", "FC Schalke 04", listOf("schalke"), 0xFF004D9D, WHITE),
|
||||
club("hertha", "BSC", "Hertha BSC", listOf("hertha"), 0xFF004D9D, WHITE),
|
||||
club("duesseldorf", "F95", "Fortuna Düsseldorf", listOf("fortuna düsseldorf"), 0xFFE1000F, WHITE),
|
||||
club("nuernberg", "FCN", "1. FC Nürnberg", listOf("nürnberg"), 0xFF8B1A1A, WHITE),
|
||||
club("kaiserslautern", "FCK", "1. FC Kaiserslautern", listOf("kaiserslautern"), 0xFFE1000F, WHITE),
|
||||
club("karlsruhe", "KSC", "Karlsruher SC", listOf("karlsruher sc", "ksc"), 0xFF0055A5, WHITE),
|
||||
club("hannover", "H96", "Hannover 96", listOf("hannover 96"), 0xFF00A94F, WHITE),
|
||||
club("paderborn", "SCP", "SC Paderborn 07", listOf("paderborn"), 0xFF004D9D, WHITE),
|
||||
club("magdeburg", "FCM", "1. FC Magdeburg", listOf("magdeburg"), 0xFF0B7A3E, WHITE),
|
||||
club("elversberg", "SVE", "SV Elversberg", listOf("elversberg"), 0xFF1A1A1A, 0xFFE1000F),
|
||||
club("darmstadt", "SV98", "SV Darmstadt 98", listOf("darmstadt"), 0xFF004E9E, WHITE),
|
||||
club("braunschweig", "BTSV", "Eintracht Braunschweig", listOf("braunschweig"), 0xFFFDE100, 0xFF004E9E),
|
||||
club("bochum", "BOC", "VfL Bochum", listOf("bochum"), 0xFF005CA9, WHITE),
|
||||
club("muenster", "SCPM", "Preußen Münster", listOf("preußen münster", "münster"), 0xFF00703C, WHITE),
|
||||
club("fuerth", "SGF", "SpVgg Greuther Fürth", listOf("greuther fürth", "fürth"), 0xFF00A94F, WHITE),
|
||||
club("holstein", "KSV", "Holstein Kiel", listOf("holstein kiel"), 0xFF004E9E, 0xFFE1000F),
|
||||
club("dresden", "SGD", "Dynamo Dresden", listOf("dynamo dresden"), 0xFFFDE100, BLACK),
|
||||
club("bielefeld", "DSC", "Arminia Bielefeld", listOf("arminia bielefeld", "bielefeld"), 0xFF00539F, WHITE),
|
||||
// --- 3. Liga ---
|
||||
club("hansa", "FCH", "FC Hansa Rostock", listOf("hansa"), 0xFF0B4EA2, WHITE),
|
||||
club("saarbruecken", "FCS", "1. FC Saarbrücken", listOf("saarbrücken"), 0xFF0B4EA2, BLACK),
|
||||
club("aue", "FCE", "Erzgebirge Aue", listOf("erzgebirge aue"), 0xFF7C0A02, WHITE),
|
||||
club("cottbus", "FCEC", "Energie Cottbus", listOf("energie cottbus", "cottbus"), 0xFFE1000F, WHITE),
|
||||
club("essen", "RWE", "Rot-Weiss Essen", listOf("rot-weiss essen", "rot weiss essen"), 0xFFE1000F, WHITE),
|
||||
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("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),
|
||||
club("havelse", "TSVH", "TSV Havelse", listOf("havelse"), 0xFF004E9E, WHITE),
|
||||
club("schweinfurt", "FC05", "1. FC Schweinfurt 05", listOf("schweinfurt"), 0xFF00A94F, WHITE),
|
||||
club("osnabrueck", "VfLO", "VfL Osnabrück", listOf("osnabrück"), 0xFF6A2C8F, WHITE),
|
||||
club("aachen", "ALE", "Alemannia Aachen", listOf("alemannia aachen", "aachen"), 0xFFFDE100, BLACK),
|
||||
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),
|
||||
)
|
||||
|
||||
/** Clubs switched on for a viewer before they touch the settings. */
|
||||
private val defaultForUser = mapOf(
|
||||
"benjamin" to listOf("hansa"),
|
||||
"tobiasb" to listOf("stuttgart"),
|
||||
)
|
||||
|
||||
/**
|
||||
* Only sport and free-to-air groups are scanned. Searching all 500
|
||||
* channels would mostly turn up shopping and radio, and the club is
|
||||
* never on those anyway.
|
||||
*/
|
||||
private val groupIncludes = listOf(
|
||||
"sport", "dazn", "sky", "magenta", "prime", "free tv", "hd+",
|
||||
"dyn", "del", "bundesliga", "fussball", "fußball", "at / ch", "at/ch",
|
||||
)
|
||||
|
||||
/** Explicitly out of scope even though they match an include. */
|
||||
private val groupExcludes = listOf("nfl")
|
||||
|
||||
fun scansGroup(group: String): Boolean {
|
||||
val g = group.lowercase()
|
||||
if (groupExcludes.any { g.contains(it) }) return false
|
||||
return groupIncludes.any { g.contains(it) }
|
||||
}
|
||||
|
||||
fun byKey(key: String): TeamFilter? = all.firstOrNull { it.key == key }
|
||||
|
||||
fun defaultKeysFor(username: String): List<String> =
|
||||
defaultForUser[username.trim().lowercase()].orEmpty()
|
||||
}
|
||||
@@ -105,6 +105,14 @@ object XmltvParser {
|
||||
}
|
||||
}
|
||||
|
||||
/** Programmes overlapping [from]..[to], in broadcast order. */
|
||||
fun programmesIn(
|
||||
programmes: List<Programme>?,
|
||||
from: Long,
|
||||
to: Long,
|
||||
): List<Programme> =
|
||||
programmes.orEmpty().filter { it.stop > from && it.start < to }
|
||||
|
||||
fun nowNext(programmes: List<Programme>?, at: Long = System.currentTimeMillis()): NowNext {
|
||||
if (programmes.isNullOrEmpty()) return NowNext(null, null)
|
||||
val index = programmes.indexOfFirst { at < it.stop }
|
||||
|
||||
@@ -132,6 +132,10 @@ private fun TopBar(state: AppState) {
|
||||
}
|
||||
Spacer(Modifier.width(18.dp))
|
||||
}
|
||||
state.updateAvailable?.let { version ->
|
||||
UpdateChip(version) { state.screen = AppState.Screen.SETTINGS }
|
||||
Spacer(Modifier.width(10.dp))
|
||||
}
|
||||
GearButton {
|
||||
state.screen = if (state.screen == AppState.Screen.LIVE) AppState.Screen.SETTINGS
|
||||
else AppState.Screen.LIVE
|
||||
@@ -139,6 +143,33 @@ private fun TopBar(state: AppState) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shown in the top bar as soon as the start-up check finds a newer
|
||||
* release — otherwise an update would only be noticed by someone who
|
||||
* happens to open the settings.
|
||||
*/
|
||||
@Composable
|
||||
private fun UpdateChip(version: String, onClick: () -> Unit) {
|
||||
Surface(
|
||||
onClick = onClick,
|
||||
shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(999.dp)),
|
||||
colors = ClickableSurfaceDefaults.colors(
|
||||
containerColor = CastarrColors.accentDim,
|
||||
contentColor = CastarrColors.accent,
|
||||
focusedContainerColor = CastarrColors.accent,
|
||||
focusedContentColor = CastarrColors.onAccent,
|
||||
),
|
||||
) {
|
||||
Text(
|
||||
"Update $version",
|
||||
fontFamily = AppFont,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Round settings button with a drawn gear (glyphs render as emoji). */
|
||||
@Composable
|
||||
private fun GearButton(onClick: () -> Unit) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.castarr.tv.ui
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -29,9 +30,16 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.drawscope.clipPath
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -71,7 +79,19 @@ fun LiveScreen(state: AppState) {
|
||||
val groups = remember(allChannels) {
|
||||
allChannels.mapNotNull { it.group.ifEmpty { null } }.distinct().sorted()
|
||||
}
|
||||
val teams = remember(state.enabledTeams) {
|
||||
dev.castarr.tv.data.TeamFilters.all.filter { it.key in state.enabledTeams }
|
||||
}
|
||||
// Recomputed when the EPG or the channel list changes — scanning the
|
||||
// sport groups' programmes is cheap, but not per frame.
|
||||
val matchesByTeam = remember(teams, allChannels, epgStamp) {
|
||||
teams.associate { it.key to state.teamMatches(it.key) }
|
||||
}
|
||||
val activeTeam = teams.firstOrNull { it.key == state.activeTeam }
|
||||
val activeMatches = activeTeam?.let { matchesByTeam[it.key] }.orEmpty()
|
||||
val teamHits = remember(activeMatches) { activeMatches.associate { it.first.url to it.second } }
|
||||
val channels = when {
|
||||
activeTeam != null -> activeMatches.map { it.first }
|
||||
state.favoritesOnly -> allChannels.filter { it.backendId in favorites }
|
||||
state.groupFilter != null -> allChannels.filter { it.group == state.groupFilter }
|
||||
else -> allChannels
|
||||
@@ -106,18 +126,26 @@ fun LiveScreen(state: AppState) {
|
||||
// A fresh group starts at the top; a return from playback does not.
|
||||
if (restoreIndex == null) listState.scrollToItem(0)
|
||||
}
|
||||
LaunchedEffect(restoreIndex, channels.size) {
|
||||
if (restoreIndex != null && !restored) {
|
||||
LaunchedEffect(restoreIndex, channels.size, state.restorePending) {
|
||||
if (restoreIndex != null && (state.restorePending || !restored)) {
|
||||
listState.scrollToItem(restoreIndex)
|
||||
runCatching { restoreFocus.requestFocus() }
|
||||
restored = true
|
||||
state.restorePending = false
|
||||
}
|
||||
}
|
||||
val intoList = if (channels.isEmpty()) Modifier
|
||||
else Modifier.focusProperties { right = listFocus }
|
||||
// A FocusRequester that is not currently attached throws when used, and
|
||||
// in a LazyColumn the selected row may well be scrolled out of
|
||||
// composition — so jumps are attempted, not declared.
|
||||
val intoList = if (channels.isEmpty()) Modifier else Modifier.onPreviewKeyEvent { event ->
|
||||
event.type == KeyEventType.KeyDown && event.key == Key.DirectionRight &&
|
||||
runCatching { listFocus.requestFocus() }.isSuccess
|
||||
}
|
||||
|
||||
val railState = rememberLazyListState()
|
||||
Row(Modifier.fillMaxSize()) {
|
||||
LazyColumn(
|
||||
state = railState,
|
||||
modifier = Modifier
|
||||
.width(264.dp)
|
||||
.fillMaxHeight(),
|
||||
@@ -127,7 +155,8 @@ fun LiveScreen(state: AppState) {
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
item {
|
||||
val selected = !state.favoritesOnly && state.groupFilter == null
|
||||
val selected = !state.favoritesOnly && state.groupFilter == null &&
|
||||
state.activeTeam == null
|
||||
GroupItem(
|
||||
label = "Alle Sender",
|
||||
count = allChannels.size,
|
||||
@@ -135,7 +164,9 @@ fun LiveScreen(state: AppState) {
|
||||
modifier = intoList.then(
|
||||
if (selected) Modifier.focusRequester(railFocus) else Modifier
|
||||
),
|
||||
suppressAutoSelect = { state.restorePending },
|
||||
) {
|
||||
state.activeTeam = null
|
||||
state.favoritesOnly = false
|
||||
state.groupFilter = null
|
||||
}
|
||||
@@ -145,16 +176,35 @@ fun LiveScreen(state: AppState) {
|
||||
GroupItem(
|
||||
label = "★ Favoriten",
|
||||
count = favorites.size,
|
||||
selected = state.favoritesOnly,
|
||||
selected = state.favoritesOnly && state.activeTeam == null,
|
||||
modifier = intoList.then(
|
||||
if (state.favoritesOnly) Modifier.focusRequester(railFocus) else Modifier
|
||||
),
|
||||
suppressAutoSelect = { state.restorePending },
|
||||
) {
|
||||
state.activeTeam = null
|
||||
state.favoritesOnly = true
|
||||
state.groupFilter = null
|
||||
}
|
||||
}
|
||||
}
|
||||
items(teams, key = { it.key }) { club ->
|
||||
GroupItem(
|
||||
label = club.label,
|
||||
count = matchesByTeam[club.key]?.size ?: 0,
|
||||
selected = state.activeTeam == club.key,
|
||||
leading = { Crest(club, state) },
|
||||
modifier = intoList.then(
|
||||
if (state.activeTeam == club.key) Modifier.focusRequester(railFocus)
|
||||
else Modifier
|
||||
),
|
||||
suppressAutoSelect = { state.restorePending },
|
||||
) {
|
||||
state.activeTeam = club.key
|
||||
state.favoritesOnly = false
|
||||
state.groupFilter = null
|
||||
}
|
||||
}
|
||||
item {
|
||||
Box(
|
||||
Modifier
|
||||
@@ -168,11 +218,13 @@ fun LiveScreen(state: AppState) {
|
||||
GroupItem(
|
||||
label = group,
|
||||
count = remember(allChannels, group) { allChannels.count { it.group == group } },
|
||||
selected = state.groupFilter == group,
|
||||
selected = state.groupFilter == group && state.activeTeam == null,
|
||||
modifier = intoList.then(
|
||||
if (state.groupFilter == group) Modifier.focusRequester(railFocus) else Modifier
|
||||
),
|
||||
suppressAutoSelect = { state.restorePending },
|
||||
) {
|
||||
state.activeTeam = null
|
||||
state.favoritesOnly = false
|
||||
state.groupFilter = group
|
||||
}
|
||||
@@ -192,9 +244,13 @@ fun LiveScreen(state: AppState) {
|
||||
if (channels.isEmpty()) {
|
||||
item {
|
||||
Text(
|
||||
if (state.favoritesOnly)
|
||||
"Noch keine Favoriten — halte OK auf einem Sender gedrückt."
|
||||
else "Diese Gruppe ist leer.",
|
||||
when {
|
||||
activeTeam != null ->
|
||||
"In den nächsten 3 Stunden läuft nichts mit ${activeTeam.fullName}."
|
||||
state.favoritesOnly ->
|
||||
"Noch keine Favoriten — halte OK auf einem Sender gedrückt."
|
||||
else -> "Diese Gruppe ist leer."
|
||||
},
|
||||
color = CastarrColors.faint,
|
||||
fontFamily = AppFont,
|
||||
fontSize = 14.sp,
|
||||
@@ -209,13 +265,18 @@ fun LiveScreen(state: AppState) {
|
||||
// matching the remote's number pad in every view.
|
||||
number = allChannels.indexOf(channel) + 1,
|
||||
modifier = Modifier
|
||||
.focusProperties { left = railFocus }
|
||||
.onPreviewKeyEvent { event ->
|
||||
event.type == KeyEventType.KeyDown &&
|
||||
event.key == Key.DirectionLeft &&
|
||||
runCatching { railFocus.requestFocus() }.isSuccess
|
||||
}
|
||||
.then(if (listIndex == 0) Modifier.focusRequester(listFocus) else Modifier)
|
||||
.then(
|
||||
if (listIndex == restoreIndex) Modifier.focusRequester(restoreFocus)
|
||||
else Modifier
|
||||
),
|
||||
nowNext = state.nowNext(channel),
|
||||
highlight = teamHits[channel.url],
|
||||
playing = state.currentChannel?.url == channel.url,
|
||||
// All rows are favorites in the favorites view — the
|
||||
// star only carries meaning elsewhere.
|
||||
@@ -237,6 +298,8 @@ private fun GroupItem(
|
||||
count: Int,
|
||||
selected: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
suppressAutoSelect: () -> Boolean = { false },
|
||||
onSelect: () -> Unit,
|
||||
) {
|
||||
Surface(
|
||||
@@ -245,7 +308,7 @@ private fun GroupItem(
|
||||
onClick = onSelect,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.onFocusChanged { if (it.isFocused) onSelect() },
|
||||
.onFocusChanged { if (it.isFocused && !suppressAutoSelect()) onSelect() },
|
||||
shape = ClickableSurfaceDefaults.shape(RoundedCornerShape(10.dp)),
|
||||
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f),
|
||||
colors = ClickableSurfaceDefaults.colors(
|
||||
@@ -259,6 +322,10 @@ private fun GroupItem(
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 9.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (leading != null) {
|
||||
leading()
|
||||
Spacer(Modifier.width(10.dp))
|
||||
}
|
||||
Text(
|
||||
label,
|
||||
fontFamily = AppFont,
|
||||
@@ -284,6 +351,7 @@ private fun ChannelRow(
|
||||
number: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
nowNext: NowNext,
|
||||
highlight: dev.castarr.tv.data.Programme? = null,
|
||||
playing: Boolean,
|
||||
favorite: Boolean,
|
||||
epgStamp: Long,
|
||||
@@ -344,7 +412,13 @@ private fun ChannelRow(
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.width(24.dp))
|
||||
EpgCell(nowNext, Modifier.weight(1f))
|
||||
if (highlight != null) {
|
||||
// In the club view the matching broadcast is the point, not
|
||||
// whatever happens to be running.
|
||||
HighlightCell(highlight, Modifier.weight(1f))
|
||||
} else {
|
||||
EpgCell(nowNext, Modifier.weight(1f))
|
||||
}
|
||||
if (playing) {
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Box(
|
||||
@@ -358,6 +432,57 @@ 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.
|
||||
*/
|
||||
@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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ShieldFallback(team: dev.castarr.tv.data.TeamFilter) {
|
||||
Canvas(Modifier.size(18.dp)) {
|
||||
val w = size.width
|
||||
val h = size.height
|
||||
val shield = Path().apply {
|
||||
moveTo(w * 0.5f, 0f)
|
||||
lineTo(w, h * 0.18f)
|
||||
lineTo(w, h * 0.55f)
|
||||
cubicTo(w, h * 0.82f, w * 0.75f, h * 0.95f, w * 0.5f, h)
|
||||
cubicTo(w * 0.25f, h * 0.95f, 0f, h * 0.82f, 0f, h * 0.55f)
|
||||
lineTo(0f, h * 0.18f)
|
||||
close()
|
||||
}
|
||||
drawPath(shield, team.primary)
|
||||
clipPath(shield) {
|
||||
drawRect(
|
||||
team.secondary,
|
||||
topLeft = Offset(0f, h * 0.42f),
|
||||
size = androidx.compose.ui.geometry.Size(w, h * 0.16f),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Bare channel logo (they ship transparent); initials as fallback. */
|
||||
@Composable
|
||||
private fun LogoTile(channel: Channel) {
|
||||
@@ -392,6 +517,40 @@ private fun LogoInitials(initials: String) {
|
||||
}
|
||||
}
|
||||
|
||||
/** The programme that matched the club filter, with its start time. */
|
||||
@Composable
|
||||
private fun HighlightCell(programme: dev.castarr.tv.data.Programme, modifier: Modifier = Modifier) {
|
||||
val running = System.currentTimeMillis() in programme.start until programme.stop
|
||||
Column(modifier) {
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
Text(
|
||||
programme.title,
|
||||
color = CastarrColors.fg,
|
||||
fontFamily = AppFont,
|
||||
fontSize = 14.sp,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false),
|
||||
)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Text(
|
||||
if (running) "läuft" else "ab ${formatClock(programme.start)}",
|
||||
color = if (running) CastarrColors.accent else CastarrColors.muted,
|
||||
fontFamily = AppFont,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = if (running) FontWeight.SemiBold else FontWeight.Normal,
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Text(
|
||||
"${formatClock(programme.start)}–${formatClock(programme.stop)}",
|
||||
color = CastarrColors.faint,
|
||||
fontFamily = AppFont,
|
||||
fontSize = 12.sp,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatClock(millis: Long): String =
|
||||
SimpleDateFormat("HH:mm", Locale.GERMANY).format(Date(millis))
|
||||
|
||||
|
||||
@@ -14,9 +14,13 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -163,6 +167,41 @@ fun SettingsScreen(state: AppState) {
|
||||
}
|
||||
}
|
||||
|
||||
SettingsCard("Vereinsmenüs") {
|
||||
Text(
|
||||
"Eigene Gruppe mit allen Sendern, auf denen der Verein in den " +
|
||||
"nächsten 3 Stunden läuft. Bis zu " +
|
||||
"${dev.castarr.tv.data.TeamFilters.MAX_ACTIVE} Vereine.",
|
||||
color = CastarrColors.faint, fontFamily = AppFont, fontSize = 11.sp,
|
||||
modifier = Modifier.padding(start = 14.dp, end = 14.dp, bottom = 6.dp),
|
||||
)
|
||||
val active = dev.castarr.tv.data.TeamFilters.all
|
||||
.filter { it.key in state.enabledTeams }
|
||||
active.forEach { club ->
|
||||
SettingRow(
|
||||
club.fullName,
|
||||
subtitle = "Erscheint als ${club.label} in der Senderliste",
|
||||
trailing = { TogglePill(on = true) },
|
||||
) { state.toggleTeam(club.key) }
|
||||
}
|
||||
if (active.size < dev.castarr.tv.data.TeamFilters.MAX_ACTIVE) {
|
||||
SettingRow(
|
||||
"Verein hinzufügen",
|
||||
subtitle = "1. bis 3. Liga",
|
||||
) {
|
||||
val choices = dev.castarr.tv.data.TeamFilters.all
|
||||
.filter { it.key !in state.enabledTeams }
|
||||
picker = Picker(
|
||||
"Verein hinzufügen",
|
||||
choices.map { it.fullName },
|
||||
-1,
|
||||
) { index ->
|
||||
choices.getOrNull(index)?.let { state.toggleTeam(it.key) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SettingsCard("App") {
|
||||
SettingRow(
|
||||
"Version ${BuildConfig.VERSION_NAME}",
|
||||
@@ -273,7 +312,13 @@ fun SettingsScreen(state: AppState) {
|
||||
@Composable
|
||||
private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
||||
val selectedFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { selectedFocus.requestFocus() }
|
||||
// A requester bound to no composed row throws; with no preselection
|
||||
// (adding something new) there is deliberately no such row.
|
||||
LaunchedEffect(Unit) { runCatching { selectedFocus.requestFocus() } }
|
||||
val listState = rememberLazyListState()
|
||||
LaunchedEffect(picker.selected) {
|
||||
if (picker.selected > 0) listState.scrollToItem(picker.selected)
|
||||
}
|
||||
Dialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
@@ -302,7 +347,11 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
||||
letterSpacing = 2.sp,
|
||||
modifier = Modifier.padding(start = 14.dp, bottom = 10.dp),
|
||||
)
|
||||
picker.options.forEachIndexed { index, option ->
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier.heightIn(max = 420.dp),
|
||||
) {
|
||||
itemsIndexed(picker.options) { index, option ->
|
||||
val selected = index == picker.selected
|
||||
Surface(
|
||||
onClick = {
|
||||
@@ -311,7 +360,11 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(if (selected) Modifier.focusRequester(selectedFocus) else Modifier),
|
||||
.then(
|
||||
if (selected || (picker.selected < 0 && index == 0))
|
||||
Modifier.focusRequester(selectedFocus)
|
||||
else Modifier
|
||||
),
|
||||
shape = ClickableSurfaceDefaults.shape(rowShape),
|
||||
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f),
|
||||
colors = ClickableSurfaceDefaults.colors(
|
||||
@@ -352,6 +405,7 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -385,6 +439,24 @@ private fun ValueWithCaret(value: String) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TogglePill(on: Boolean) {
|
||||
Box(
|
||||
Modifier
|
||||
.clip(RoundedCornerShape(999.dp))
|
||||
.background(if (on) CastarrColors.accent else CastarrColors.bg)
|
||||
.padding(horizontal = 12.dp, vertical = 5.dp)
|
||||
) {
|
||||
Text(
|
||||
if (on) "An" else "Aus",
|
||||
color = if (on) CastarrColors.onAccent else CastarrColors.muted,
|
||||
fontFamily = AppFont,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = if (on) FontWeight.SemiBold else FontWeight.Normal,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettingsCard(title: String, content: @Composable () -> Unit) {
|
||||
Column(
|
||||
|
||||
@@ -18,12 +18,12 @@ object UpdateChecker {
|
||||
|
||||
private const val TAG = "UpdateChecker"
|
||||
private const val LATEST =
|
||||
"https://git.beckm4nn.net/api/v1/repos/benjamin/castarr/releases/latest"
|
||||
"https://git.beckm4nn.net/api/v1/repos/be-nj/castarr/releases/latest"
|
||||
|
||||
// Release assets need an API token to upload, so the APK is served from
|
||||
// an orphan branch instead — anonymously fetchable on a public repo.
|
||||
private const val APK_FALLBACK =
|
||||
"https://git.beckm4nn.net/benjamin/castarr/raw/branch/apk/castarr.apk"
|
||||
"https://git.beckm4nn.net/be-nj/castarr/raw/branch/apk/castarr.apk"
|
||||
|
||||
private var apkUrl: String = ""
|
||||
|
||||
@@ -103,7 +103,7 @@ object UpdateChecker {
|
||||
return try {
|
||||
connection.connectTimeout = 10_000
|
||||
connection.readTimeout = 15_000
|
||||
connection.setRequestProperty("Accept", "application/vnd.github+json")
|
||||
connection.setRequestProperty("Accept", "application/json")
|
||||
connection.inputStream.bufferedReader().use { it.readText() }
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
|
||||
61
tests/unit/TeamFiltersTest.kt
Normal file
61
tests/unit/TeamFiltersTest.kt
Normal file
@@ -0,0 +1,61 @@
|
||||
package dev.castarr.tv.data
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class TeamFiltersTest {
|
||||
|
||||
private val hansa = TeamFilters.byKey("hansa")!!
|
||||
private val vfb = TeamFilters.byKey("stuttgart")!!
|
||||
|
||||
@Test
|
||||
fun `matches the club regardless of case and surrounding text`() {
|
||||
assertTrue(hansa.matches("3. Liga: FC Hansa Rostock - Dynamo Dresden"))
|
||||
assertTrue(hansa.matches("HANSA ROSTOCK KOMPAKT"))
|
||||
assertTrue(vfb.matches("Bundesliga: VfB Stuttgart - Bayern München"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `does not match unrelated programmes`() {
|
||||
assertFalse(hansa.matches("Tagesschau"))
|
||||
assertFalse(vfb.matches("Hansa Rostock - Saarbrücken"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `scans sport and free-to-air groups`() {
|
||||
listOf("DAZN Event", "Sky Sport", "Magenta Sport", "Amazon Prime", "Free TV / HD+", "DYN Sport")
|
||||
.forEach { assertTrue(it, TeamFilters.scansGroup(it)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `skips NFL and unrelated groups`() {
|
||||
assertFalse(TeamFilters.scansGroup("DAZN Event NFL"))
|
||||
assertFalse(TeamFilters.scansGroup("Kids"))
|
||||
assertFalse(TeamFilters.scansGroup("Musik"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `assigns each viewer their own club by default`() {
|
||||
assertEquals(listOf("hansa"), TeamFilters.defaultKeysFor("benjamin"))
|
||||
assertEquals(listOf("stuttgart"), TeamFilters.defaultKeysFor("TobiasB"))
|
||||
assertTrue(TeamFilters.defaultKeysFor("someone-else").isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `club keys are unique and every club has needles`() {
|
||||
val keys = TeamFilters.all.map { it.key }
|
||||
assertEquals(keys.size, keys.toSet().size)
|
||||
assertTrue(TeamFilters.all.all { it.needles.isNotEmpty() })
|
||||
assertTrue(TeamFilters.all.all { c -> c.needles.all { it == it.lowercase() } })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `covers all three divisions`() {
|
||||
assertTrue(TeamFilters.all.size > 50)
|
||||
listOf("bayern", "schalke", "hansa").forEach {
|
||||
assertTrue(it, TeamFilters.byKey(it) != null)
|
||||
}
|
||||
}
|
||||
}
|
||||
34
tests/unit/XmltvWindowTest.kt
Normal file
34
tests/unit/XmltvWindowTest.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package dev.castarr.tv.data
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class XmltvWindowTest {
|
||||
|
||||
private fun p(startMin: Long, endMin: Long, title: String) =
|
||||
Programme(startMin * 60_000, endMin * 60_000, title)
|
||||
|
||||
private val schedule = listOf(
|
||||
p(0, 60, "Läuft gerade"),
|
||||
p(60, 120, "Gleich danach"),
|
||||
p(150, 210, "In zweieinhalb Stunden"),
|
||||
p(300, 360, "Deutlich später"),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `returns programmes overlapping the window`() {
|
||||
val titles = XmltvParser.programmesIn(schedule, 30 * 60_000, 180 * 60_000).map { it.title }
|
||||
assertEquals(listOf("Läuft gerade", "Gleich danach", "In zweieinhalb Stunden"), titles)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `excludes programmes outside the window`() {
|
||||
val titles = XmltvParser.programmesIn(schedule, 0, 60 * 60_000).map { it.title }
|
||||
assertEquals(listOf("Läuft gerade"), titles)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `handles a missing schedule`() {
|
||||
assertEquals(emptyList<Programme>(), XmltvParser.programmesIn(null, 0, 1_000))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user