Compare commits
13 Commits
v0.9.2
...
3b6a8d7d0a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b6a8d7d0a | ||
|
|
e491f8e50f | ||
|
|
56b5d3f0b0 | ||
|
|
b0b8f8801d | ||
|
|
9a0fa37e55 | ||
|
|
73f6dbba75 | ||
|
|
f6f6a2499f | ||
|
|
8aa3a4da02 | ||
|
|
b7ee0523d1 | ||
|
|
a3105925bb | ||
|
|
7f1dff5661 | ||
|
|
869060c56f | ||
|
|
7ad7f5172e |
53
.github/workflows/build.yml
vendored
53
.github/workflows/build.yml
vendored
@@ -4,24 +4,53 @@ on:
|
|||||||
push:
|
push:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# No marketplace actions: this Gitea runner resolves bare action names
|
||||||
|
# against the local instance, and even with full URLs it cannot resolve
|
||||||
|
# annotated tags ("unsupported object type"). Everything below is plain
|
||||||
|
# shell, which also keeps the job readable.
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
ANDROID_SDK_ROOT: /opt/android-sdk
|
||||||
|
CMDLINE_TOOLS: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout
|
||||||
|
run: |
|
||||||
|
git init -q .
|
||||||
|
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
|
||||||
|
git fetch -q --depth 1 origin "${GITHUB_SHA}"
|
||||||
|
git checkout -q FETCH_HEAD
|
||||||
|
|
||||||
- uses: actions/setup-java@v4
|
- name: Install JDK
|
||||||
with:
|
run: |
|
||||||
distribution: temurin
|
apt-get update -qq
|
||||||
java-version: "17"
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq openjdk-17-jdk-headless > /dev/null
|
||||||
|
java -version
|
||||||
|
|
||||||
- uses: gradle/actions/setup-gradle@v4
|
- name: Install Android SDK
|
||||||
|
run: |
|
||||||
|
mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools"
|
||||||
|
curl -sSL -o /tmp/tools.zip "$CMDLINE_TOOLS"
|
||||||
|
unzip -q /tmp/tools.zip -d "$ANDROID_SDK_ROOT/cmdline-tools"
|
||||||
|
mv "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools" "$ANDROID_SDK_ROOT/cmdline-tools/latest"
|
||||||
|
# Accept licences by writing the hashes: piping "yes" into
|
||||||
|
# sdkmanager dies of SIGPIPE (exit 141) under pipefail.
|
||||||
|
mkdir -p "$ANDROID_SDK_ROOT/licenses"
|
||||||
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_SDK_ROOT/licenses/android-sdk-license"
|
||||||
|
echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK_ROOT/licenses/android-sdk-preview-license"
|
||||||
|
"$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" \
|
||||||
|
"platforms;android-35" "build-tools;35.0.0" "platform-tools" > /dev/null
|
||||||
|
echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties
|
||||||
|
|
||||||
|
- name: Unit tests
|
||||||
|
run: ./gradlew testDebugUnitTest --no-daemon --stacktrace
|
||||||
|
|
||||||
- name: Build debug APK
|
- name: Build debug APK
|
||||||
run: ./gradlew assembleDebug --stacktrace
|
run: ./gradlew assembleDebug --no-daemon --stacktrace
|
||||||
|
|
||||||
- name: Upload APK
|
- name: Summary
|
||||||
uses: actions/upload-artifact@v4
|
if: always()
|
||||||
with:
|
run: |
|
||||||
name: castarr-debug-apk
|
echo "APK:"; ls -la app/build/outputs/apk/debug/ 2>/dev/null || echo " (kein Build)"
|
||||||
path: app/build/outputs/apk/debug/app-debug.apk
|
echo "Tests:"; ls tests/runs/junit/ 2>/dev/null || echo " (keine Reports)"
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,3 +5,6 @@ local.properties
|
|||||||
*.iml
|
*.iml
|
||||||
.kotlin/
|
.kotlin/
|
||||||
tests/runs/
|
tests/runs/
|
||||||
|
app/src/main/assets/crests/
|
||||||
|
tests/demo/playlist.m3u
|
||||||
|
tests/demo/epg.xml
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "dev.castarr.tv"
|
applicationId = "dev.castarr.tv"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 25
|
versionCode = 37
|
||||||
versionName = "0.9.2"
|
versionName = "0.11.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release signing from environment (see ~/.keys/castarr-release.env on the
|
// Release signing from environment (see ~/.keys/castarr-release.env on the
|
||||||
|
|||||||
@@ -267,7 +267,7 @@
|
|||||||
ws: null, connected: false, authorized: false,
|
ws: null, connected: false, authorized: false,
|
||||||
status: { state: 'idle', channel: '', group: '', live: false, volume: 0.5 },
|
status: { state: 'idle', channel: '', group: '', live: false, volume: 0.5 },
|
||||||
channels: [], playlistUrl: '', extras: { nowNext: [], favorites: [], favoritesSupported: false }, favOnly: false,
|
channels: [], playlistUrl: '', extras: { nowNext: [], favorites: [], favoritesSupported: false }, favOnly: false,
|
||||||
retryDelay: 1000, volumeDragging: false, searchTerm: '',
|
retryDelay: 1000, volumeDragging: false, searchTerm: '', teamKey: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- pairing credentials ---
|
// --- pairing credentials ---
|
||||||
@@ -450,16 +450,31 @@
|
|||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
const favSet = new Set(state.extras.favorites || []);
|
const favSet = new Set(state.extras.favorites || []);
|
||||||
const favOn = state.extras.favoritesSupported && state.favOnly;
|
const favOn = state.extras.favoritesSupported && state.favOnly;
|
||||||
const shown = favOn ? filtered.filter((c) => favSet.has(c.backendId)) : filtered;
|
const teams = state.extras.teams || [];
|
||||||
if (state.extras.favoritesSupported) {
|
const club = teams.find((t) => t.key === state.teamKey);
|
||||||
|
// Club view: the TV's club menu, mirrored onto the phone.
|
||||||
|
const clubHits = club ? new Map(club.entries.map((e) => [e.url, e])) : null;
|
||||||
|
const shown = club
|
||||||
|
? filtered.filter((c) => clubHits.has(c.url))
|
||||||
|
: favOn ? filtered.filter((c) => favSet.has(c.backendId)) : filtered;
|
||||||
|
if (state.extras.favoritesSupported || teams.length) {
|
||||||
const bar = document.createElement('div');
|
const bar = document.createElement('div');
|
||||||
bar.style.cssText = 'display:flex;gap:8px;padding:2px 12px 10px';
|
bar.style.cssText = 'display:flex;gap:8px;padding:2px 12px 10px;overflow-x:auto';
|
||||||
[['Alle', false], ['★ Favoriten', true]].forEach(([label, val]) => {
|
const views = [['Alle', null, false]];
|
||||||
|
if (state.extras.favoritesSupported) views.push(['★ Favoriten', null, true]);
|
||||||
|
teams.forEach((t) => views.push([t.label + ' ' + t.entries.length, t.key, false]));
|
||||||
|
views.forEach(([label, key, fav]) => {
|
||||||
|
const active = key ? state.teamKey === key : (!state.teamKey && state.favOnly === fav);
|
||||||
const chip = document.createElement('button');
|
const chip = document.createElement('button');
|
||||||
chip.textContent = label;
|
chip.textContent = label;
|
||||||
chip.style.cssText = 'padding:7px 14px;border-radius:999px;font-size:12px;background:' +
|
chip.style.cssText = 'flex:none;padding:7px 14px;border-radius:999px;font-size:12px;background:' +
|
||||||
(state.favOnly === val ? 'rgba(95,212,196,.12);color:#5fd4c4' : '#121418;color:#9aa0a8');
|
(active ? 'rgba(95,212,196,.12);color:#5fd4c4' : '#121418;color:#9aa0a8');
|
||||||
chip.addEventListener('click', () => { state.favOnly = val; renderChannels(); });
|
chip.addEventListener('click', () => {
|
||||||
|
state.teamKey = key;
|
||||||
|
state.favOnly = fav;
|
||||||
|
listSignature = '';
|
||||||
|
renderChannels();
|
||||||
|
});
|
||||||
bar.appendChild(chip);
|
bar.appendChild(chip);
|
||||||
});
|
});
|
||||||
list.appendChild(bar);
|
list.appendChild(bar);
|
||||||
@@ -467,8 +482,9 @@
|
|||||||
if (!shown.length) {
|
if (!shown.length) {
|
||||||
const empty = document.createElement('div');
|
const empty = document.createElement('div');
|
||||||
empty.className = 'empty';
|
empty.className = 'empty';
|
||||||
empty.textContent = favOn
|
empty.textContent = club
|
||||||
? 'Keine Favoriten — Stern auf einem Sender antippen.'
|
? ('Heute läuft nichts mehr mit ' + club.name + '.')
|
||||||
|
: favOn ? 'Keine Favoriten — Stern auf einem Sender antippen.'
|
||||||
: 'Keine Sender gefunden.';
|
: 'Keine Sender gefunden.';
|
||||||
list.appendChild(empty);
|
list.appendChild(empty);
|
||||||
return;
|
return;
|
||||||
@@ -493,6 +509,18 @@
|
|||||||
const name = document.createElement('span');
|
const name = document.createElement('span');
|
||||||
name.className = 'name'; name.textContent = c.name;
|
name.className = 'name'; name.textContent = c.name;
|
||||||
meta.appendChild(name);
|
meta.appendChild(name);
|
||||||
|
const hit = clubHits ? clubHits.get(c.url) : null;
|
||||||
|
if (hit) {
|
||||||
|
const line = document.createElement('span');
|
||||||
|
line.className = 'grp';
|
||||||
|
const t = new Date(hit.start);
|
||||||
|
const hh = String(t.getHours()).padStart(2, '0') + ':' + String(t.getMinutes()).padStart(2, '0');
|
||||||
|
const running = Date.now() >= hit.start && Date.now() < hit.stop;
|
||||||
|
line.textContent = (running ? 'läuft · ' : 'ab ' + hh + ' · ') + hit.title +
|
||||||
|
(hit.further > 0 ? ' · +' + hit.further + ' weitere' : '');
|
||||||
|
line.style.color = running ? '#5fd4c4' : '#9aa0a8';
|
||||||
|
meta.appendChild(line);
|
||||||
|
} else {
|
||||||
const info = (state.extras.nowNext || [])[idx];
|
const info = (state.extras.nowNext || [])[idx];
|
||||||
if (info && info.now) {
|
if (info && info.now) {
|
||||||
const now = document.createElement('span');
|
const now = document.createElement('span');
|
||||||
@@ -513,6 +541,7 @@
|
|||||||
grp.className = 'grp'; grp.textContent = c.group;
|
grp.className = 'grp'; grp.textContent = c.group;
|
||||||
meta.appendChild(grp);
|
meta.appendChild(grp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
btn.appendChild(num); btn.appendChild(meta);
|
btn.appendChild(num); btn.appendChild(meta);
|
||||||
if (state.extras.favoritesSupported && c.backendId) {
|
if (state.extras.favoritesSupported && c.backendId) {
|
||||||
const star = document.createElement('span');
|
const star = document.createElement('span');
|
||||||
@@ -539,7 +568,8 @@
|
|||||||
let listSignature = '';
|
let listSignature = '';
|
||||||
function renderChannelsIfChanged() {
|
function renderChannelsIfChanged() {
|
||||||
const sig = [
|
const sig = [
|
||||||
state.channels.length, state.searchTerm, state.favOnly,
|
state.channels.length, state.searchTerm, state.favOnly, state.teamKey,
|
||||||
|
JSON.stringify((state.extras.teams || []).map((t) => [t.key, t.entries.length])),
|
||||||
(state.extras.favorites || []).join(','),
|
(state.extras.favorites || []).join(','),
|
||||||
state.status.channel || '',
|
state.status.channel || '',
|
||||||
].join('|');
|
].join('|');
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import dev.castarr.tv.auth.DeviceAuth
|
import dev.castarr.tv.auth.DeviceAuth
|
||||||
import dev.castarr.tv.data.DispatcharrRepository
|
import dev.castarr.tv.data.DispatcharrRepository
|
||||||
import dev.castarr.tv.data.NowNext
|
import dev.castarr.tv.data.NowNext
|
||||||
|
import dev.castarr.tv.data.isEpgPlaceholder
|
||||||
import dev.castarr.tv.data.SourceRepository
|
import dev.castarr.tv.data.SourceRepository
|
||||||
import dev.castarr.tv.player.PlayerController
|
import dev.castarr.tv.player.PlayerController
|
||||||
import dev.castarr.tv.playlist.Channel
|
import dev.castarr.tv.playlist.Channel
|
||||||
@@ -26,6 +27,7 @@ class AppState(
|
|||||||
val dispatcharr: DispatcharrRepository,
|
val dispatcharr: DispatcharrRepository,
|
||||||
) {
|
) {
|
||||||
private val prefs = context.getSharedPreferences("app", Context.MODE_PRIVATE)
|
private val prefs = context.getSharedPreferences("app", Context.MODE_PRIVATE)
|
||||||
|
val crests = dev.castarr.tv.data.Crests(context)
|
||||||
|
|
||||||
var screen by mutableStateOf(Screen.LIVE)
|
var screen by mutableStateOf(Screen.LIVE)
|
||||||
var playerVisible by mutableStateOf(false)
|
var playerVisible by mutableStateOf(false)
|
||||||
@@ -38,6 +40,37 @@ class AppState(
|
|||||||
var isLive by mutableStateOf(false)
|
var isLive by mutableStateOf(false)
|
||||||
var favoritesOnly by mutableStateOf(false)
|
var favoritesOnly by mutableStateOf(false)
|
||||||
var groupFilter by mutableStateOf<String?>(null)
|
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())
|
var audioTracks by mutableStateOf<List<PlayerController.AudioTrack>>(emptyList())
|
||||||
private set
|
private set
|
||||||
private var lastNowTitle: String? = null
|
private var lastNowTitle: String? = null
|
||||||
@@ -132,6 +165,62 @@ class AppState(
|
|||||||
SourceMode.DISPATCHARR -> dispatcharr.nowNext(channel)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One channel's club broadcasts: the next one plus how many follow. */
|
||||||
|
data class TeamHit(
|
||||||
|
val programme: dev.castarr.tv.data.Programme,
|
||||||
|
val further: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
/** How urgent a club menu is right now — drives the rail highlight. */
|
||||||
|
enum class TeamUrgency { NONE, SOON, LIVE }
|
||||||
|
|
||||||
|
/** The urgent state plus the kick-off it refers to, for the rail label. */
|
||||||
|
data class TeamSignal(val urgency: TeamUrgency, val kickOff: Long)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIVE while a match is running, SOON within half an hour of kick-off —
|
||||||
|
* the window in which someone actually wants to be nudged.
|
||||||
|
*/
|
||||||
|
fun teamSignal(matches: List<Pair<Channel, TeamHit>>): TeamSignal {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
var soonAt = 0L
|
||||||
|
matches.forEach { (_, hit) ->
|
||||||
|
val p = hit.programme
|
||||||
|
if (now in p.start until p.stop) return TeamSignal(TeamUrgency.LIVE, p.start)
|
||||||
|
if (p.start in now..(now + SOON_WINDOW_MS) && (soonAt == 0L || p.start < soonAt)) {
|
||||||
|
soonAt = p.start
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return if (soonAt > 0) TeamSignal(TeamUrgency.SOON, soonAt)
|
||||||
|
else TeamSignal(TeamUrgency.NONE, 0L)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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, TeamHit>> {
|
||||||
|
val filter = dev.castarr.tv.data.TeamFilters.byKey(key) ?: return emptyList()
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
val window = dev.castarr.tv.data.TeamFilters.windowEnd(now) - now
|
||||||
|
return activeChannels()
|
||||||
|
.filter { dev.castarr.tv.data.TeamFilters.scansGroup(it.group) }
|
||||||
|
.mapNotNull { channel ->
|
||||||
|
// A channel can carry several of the club's broadcasts in one
|
||||||
|
// evening; the row names the next and counts the rest.
|
||||||
|
val hits = upcoming(channel, window)
|
||||||
|
.filter { !isEpgPlaceholder(it.title) && filter.matches(it.title) }
|
||||||
|
hits.firstOrNull()?.let { channel to TeamHit(it, hits.size - 1) }
|
||||||
|
}
|
||||||
|
.sortedBy { it.second.programme.start }
|
||||||
|
}
|
||||||
|
|
||||||
fun refreshActive() {
|
fun refreshActive() {
|
||||||
when (sourceMode) {
|
when (sourceMode) {
|
||||||
SourceMode.GENERIC -> source.refresh()
|
SourceMode.GENERIC -> source.refresh()
|
||||||
@@ -144,8 +233,14 @@ class AppState(
|
|||||||
result.fold(
|
result.fold(
|
||||||
onSuccess = { appError = AppError.NONE },
|
onSuccess = { appError = AppError.NONE },
|
||||||
onFailure = { throwable ->
|
onFailure = { throwable ->
|
||||||
// Cached channels keep the app usable; only surface a
|
// An expired login must always surface: cached channels
|
||||||
// fullscreen state when there is nothing to show.
|
// would otherwise sit there without EPG or favourites and
|
||||||
|
// nothing would say why.
|
||||||
|
if (throwable.message == "not logged in") {
|
||||||
|
appError = AppError.RELOGIN
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Otherwise cached channels keep the app usable.
|
||||||
if (activeChannels().isNotEmpty()) return
|
if (activeChannels().isNotEmpty()) return
|
||||||
appError = when {
|
appError = when {
|
||||||
throwable.message == "not logged in" -> AppError.RELOGIN
|
throwable.message == "not logged in" -> AppError.RELOGIN
|
||||||
@@ -159,6 +254,9 @@ class AppState(
|
|||||||
private companion object {
|
private companion object {
|
||||||
/** Grace period before re-opening the channel just closed. */
|
/** Grace period before re-opening the channel just closed. */
|
||||||
const val REENTRY_GRACE_MS = 2_500L
|
const val REENTRY_GRACE_MS = 2_500L
|
||||||
|
|
||||||
|
/** How far ahead a kick-off counts as "about to start". */
|
||||||
|
const val SOON_WINDOW_MS = 30 * 60 * 1000L
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isOnline(): Boolean {
|
fun isOnline(): Boolean {
|
||||||
@@ -168,6 +266,8 @@ class AppState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun startOnboarding() {
|
fun startOnboarding() {
|
||||||
|
prefs.edit().remove("teams").apply()
|
||||||
|
activeTeam = null
|
||||||
auth.logout()
|
auth.logout()
|
||||||
appError = AppError.NONE
|
appError = AppError.NONE
|
||||||
welcomePhase = WelcomePhase.WAIT_PHONE
|
welcomePhase = WelcomePhase.WAIT_PHONE
|
||||||
|
|||||||
@@ -50,7 +50,14 @@ class MainActivity : ComponentActivity(), ControlServer.Listener {
|
|||||||
server.startServer()
|
server.startServer()
|
||||||
state.remoteAvailable = server.running
|
state.remoteAvailable = server.running
|
||||||
setContent { CastarrApp(state) }
|
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() {
|
private fun onPlaybackChanged() {
|
||||||
@@ -140,9 +147,36 @@ class MainActivity : ComponentActivity(), ControlServer.Listener {
|
|||||||
}
|
}
|
||||||
val favorites = org.json.JSONArray()
|
val favorites = org.json.JSONArray()
|
||||||
state.dispatcharr.favorites.value.forEach { favorites.put(it) }
|
state.dispatcharr.favorites.value.forEach { favorites.put(it) }
|
||||||
|
// The club menus exist on the TV; the phone should offer them too.
|
||||||
|
val teams = org.json.JSONArray()
|
||||||
|
dev.castarr.tv.data.TeamFilters.all
|
||||||
|
.filter { it.key in state.enabledTeams }
|
||||||
|
.forEach { club ->
|
||||||
|
val entries = org.json.JSONArray()
|
||||||
|
state.teamMatches(club.key).forEach { (channel, hit) ->
|
||||||
|
entries.put(
|
||||||
|
JSONObject()
|
||||||
|
.put("channel", channel.name)
|
||||||
|
.put("url", channel.url)
|
||||||
|
.put("group", channel.group)
|
||||||
|
.put("title", hit.programme.title)
|
||||||
|
.put("start", hit.programme.start)
|
||||||
|
.put("stop", hit.programme.stop)
|
||||||
|
.put("further", hit.further)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
teams.put(
|
||||||
|
JSONObject()
|
||||||
|
.put("key", club.key)
|
||||||
|
.put("label", club.label)
|
||||||
|
.put("name", club.fullName)
|
||||||
|
.put("entries", entries)
|
||||||
|
)
|
||||||
|
}
|
||||||
return JSONObject()
|
return JSONObject()
|
||||||
.put("nowNext", nowNext)
|
.put("nowNext", nowNext)
|
||||||
.put("favorites", favorites)
|
.put("favorites", favorites)
|
||||||
|
.put("teams", teams)
|
||||||
.put("favoritesSupported", state.sourceMode == AppState.SourceMode.DISPATCHARR)
|
.put("favoritesSupported", state.sourceMode == AppState.SourceMode.DISPATCHARR)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,5 +359,6 @@ class MainActivity : ComponentActivity(), ControlServer.Listener {
|
|||||||
const val TICK_INTERVAL_MS = 2_000L
|
const val TICK_INTERVAL_MS = 2_000L
|
||||||
const val SEEK_STEP_SECONDS = 10L
|
const val SEEK_STEP_SECONDS = 10L
|
||||||
const val DIGIT_COMMIT_MS = 1_800L
|
const val DIGIT_COMMIT_MS = 1_800L
|
||||||
|
const val UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
app/src/main/java/dev/castarr/tv/data/Crests.kt
Normal file
63
app/src/main/java/dev/castarr/tv/data/Crests.kt
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
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, fetched once and then reused. */
|
||||||
|
suspend fun urlFor(article: String): String? = withContext(Dispatchers.IO) {
|
||||||
|
prefs.getString(article, null)?.takeIf { it.isNotEmpty() }?.let {
|
||||||
|
return@withContext it
|
||||||
|
}
|
||||||
|
val resolved = runCatching { fetch(article) }
|
||||||
|
.onFailure { Log.w(TAG, "crest lookup failed for $article: $it") }
|
||||||
|
.getOrNull()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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() }
|
||||||
|
// Drop the analytics query the API appends.
|
||||||
|
?.substringBefore("?")
|
||||||
|
} 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)"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,13 +49,20 @@ class DispatcharrRepository(context: Context, private val auth: DeviceAuth) {
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
val result = runCatching {
|
val result = runCatching {
|
||||||
status.value = "loading_channels"
|
status.value = "loading_channels"
|
||||||
|
Log.i(TAG, "refresh start (loggedIn=${auth.isLoggedIn})")
|
||||||
val token = auth.accessToken() ?: error("not logged in")
|
val token = auth.accessToken() ?: error("not logged in")
|
||||||
val groups = fetchGroups(token)
|
val groups = fetchGroups(token)
|
||||||
val list = fetchChannels(token, groups)
|
val list = fetchChannels(token, groups)
|
||||||
channels.value = list
|
channels.value = list
|
||||||
prefs.edit().putString("channels_cache", Channel.listToJson(list).toString()).apply()
|
prefs.edit().putString("channels_cache", Channel.listToJson(list).toString()).apply()
|
||||||
launch { runCatching { refreshFavorites(token) } }
|
launch {
|
||||||
launch { runCatching { refreshProfiles(token) } }
|
runCatching { refreshFavorites(token) }
|
||||||
|
.onFailure { Log.w(TAG, "favorites failed: ${it.javaClass.simpleName}: ${it.message?.take(120)}") }
|
||||||
|
}
|
||||||
|
launch {
|
||||||
|
runCatching { refreshProfiles(token) }
|
||||||
|
.onFailure { Log.w(TAG, "profiles failed: ${it.javaClass.simpleName}: ${it.message?.take(120)}") }
|
||||||
|
}
|
||||||
launch {
|
launch {
|
||||||
runCatching { refreshEpg(token) }
|
runCatching { refreshEpg(token) }
|
||||||
.onFailure { Log.w(TAG, "epg failed: ${it.javaClass.simpleName}: ${it.message?.take(160)}") }
|
.onFailure { Log.w(TAG, "epg failed: ${it.javaClass.simpleName}: ${it.message?.take(160)}") }
|
||||||
@@ -71,6 +78,12 @@ class DispatcharrRepository(context: Context, private val auth: DeviceAuth) {
|
|||||||
fun nowNext(channel: Channel): NowNext =
|
fun nowNext(channel: Channel): NowNext =
|
||||||
XmltvParser.nowNext(programmesByTvgId[channel.tvgId])
|
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) {
|
fun toggleFavorite(channel: Channel) {
|
||||||
if (channel.backendId == 0) return
|
if (channel.backendId == 0) return
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
|||||||
@@ -82,13 +82,20 @@ class SourceRepository(context: Context) {
|
|||||||
status.value = ""
|
status.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Now/Next for an M3U channel: match tvg-id first, then name. */
|
/** Programmes of this channel between now and now + [windowMs]. */
|
||||||
fun nowNext(channel: Channel): NowNext {
|
fun upcoming(channel: Channel, windowMs: Long): List<Programme> {
|
||||||
val direct = channel.tvgId.takeIf { it.isNotEmpty() }?.let { programmes[it] }
|
val now = System.currentTimeMillis()
|
||||||
val byName = direct ?: nameToEpgId[channel.name.lowercase()]?.let { programmes[it] }
|
return XmltvParser.programmesIn(programmesFor(channel), now, now + windowMs)
|
||||||
return XmltvParser.nowNext(byName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private fun loadCachedChannels() {
|
||||||
runCatching {
|
runCatching {
|
||||||
val cached = prefs.getString("channels_cache", null) ?: return
|
val cached = prefs.getString("channels_cache", null) ?: return
|
||||||
|
|||||||
171
app/src/main/java/dev/castarr/tv/data/TeamFilters.kt
Normal file
171
app/src/main/java/dev/castarr/tv/data/TeamFilters.kt
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
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,
|
||||||
|
/** 1, 2 or 3 — groups the picker by division. */
|
||||||
|
val league: Int,
|
||||||
|
) {
|
||||||
|
fun matches(title: String): Boolean {
|
||||||
|
val haystack = title.lowercase()
|
||||||
|
return needles.any { haystack.contains(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object TeamFilters {
|
||||||
|
|
||||||
|
/** Minimum window scanned ahead of now. */
|
||||||
|
const val MIN_WINDOW_MS = 3 * 60 * 60 * 1000L
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scans until midnight, but never less than [MIN_WINDOW_MS] — asking in
|
||||||
|
* the morning should already answer "does my club play tonight", and
|
||||||
|
* asking late at night must not cut the evening short.
|
||||||
|
*/
|
||||||
|
fun windowEnd(now: Long): Long {
|
||||||
|
val midnight = java.util.Calendar.getInstance().apply {
|
||||||
|
timeInMillis = now
|
||||||
|
add(java.util.Calendar.DAY_OF_YEAR, 1)
|
||||||
|
set(java.util.Calendar.HOUR_OF_DAY, 0)
|
||||||
|
set(java.util.Calendar.MINUTE, 0)
|
||||||
|
set(java.util.Calendar.SECOND, 0)
|
||||||
|
set(java.util.Calendar.MILLISECOND, 0)
|
||||||
|
}.timeInMillis
|
||||||
|
return maxOf(midnight, now + MIN_WINDOW_MS)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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,
|
||||||
|
league: Int = 1,
|
||||||
|
) = TeamFilter(key, label, fullName, needles, Color(primary), Color(secondary), article, league)
|
||||||
|
|
||||||
|
/** 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, league = 1),
|
||||||
|
club("bvb", "BVB", "Borussia Dortmund", listOf("borussia dortmund", "bvb"), 0xFFFDE100, BLACK, league = 1),
|
||||||
|
club("leipzig", "RBL", "RB Leipzig", listOf("rb leipzig"), 0xFFDD0741, WHITE, league = 1),
|
||||||
|
club("leverkusen", "B04", "Bayer 04 Leverkusen", listOf("leverkusen"), 0xFFE32219, BLACK, league = 1),
|
||||||
|
club("frankfurt", "SGE", "Eintracht Frankfurt", listOf("eintracht frankfurt"), 0xFF1A1A1A, 0xFFE1000F, league = 1),
|
||||||
|
club("stuttgart", "1893", "VfB Stuttgart", listOf("vfb stuttgart"), 0xFFE32219, WHITE, league = 1),
|
||||||
|
club("gladbach", "BMG", "Borussia Mönchengladbach", listOf("mönchengladbach", "gladbach"), 0xFF1A1A1A, 0xFF00A94F, league = 1),
|
||||||
|
club("wolfsburg", "WOB", "VfL Wolfsburg", listOf("wolfsburg"), 0xFF65B32E, WHITE, league = 1),
|
||||||
|
club("bremen", "SVW", "SV Werder Bremen", listOf("werder bremen", "werder"), 0xFF1D9053, WHITE, league = 1),
|
||||||
|
club("freiburg", "SCF", "SC Freiburg", listOf("sc freiburg", "freiburg"), 0xFFE2001A, WHITE, league = 1),
|
||||||
|
club("hoffenheim", "TSG", "TSG Hoffenheim", listOf("hoffenheim"), 0xFF1C63B7, WHITE, league = 1),
|
||||||
|
club("mainz", "M05", "1. FSV Mainz 05", listOf("mainz 05", "mainz"), 0xFFE1000F, WHITE, league = 1),
|
||||||
|
club("augsburg", "FCA", "FC Augsburg", listOf("augsburg"), 0xFF00693F, 0xFFE1000F, league = 1),
|
||||||
|
club("union", "FCU", "1. FC Union Berlin", listOf("union berlin"), 0xFFE1000F, 0xFFFDE100, league = 1),
|
||||||
|
club("koeln", "EFC", "1. FC Köln", listOf("1. fc köln", "fc köln"), 0xFFE1000F, WHITE, league = 1),
|
||||||
|
club("hsv", "HSV", "Hamburger SV", listOf("hamburger sv", "hsv"), 0xFF0E5EA6, BLACK, league = 1),
|
||||||
|
club("heidenheim", "FCH1", "1. FC Heidenheim", listOf("heidenheim"), 0xFFE1000F, 0xFF1656A4, league = 1),
|
||||||
|
club("st-pauli", "FCSP", "FC St. Pauli", listOf("st. pauli", "st pauli"), 0xFF6B4423, WHITE, league = 1),
|
||||||
|
// --- 2. Bundesliga ---
|
||||||
|
club("schalke", "S04", "FC Schalke 04", listOf("schalke"), 0xFF004D9D, WHITE, league = 2),
|
||||||
|
club("hertha", "BSC", "Hertha BSC", listOf("hertha"), 0xFF004D9D, WHITE, league = 2),
|
||||||
|
club("duesseldorf", "F95", "Fortuna Düsseldorf", listOf("fortuna düsseldorf"), 0xFFE1000F, WHITE, league = 2),
|
||||||
|
club("nuernberg", "FCN", "1. FC Nürnberg", listOf("nürnberg"), 0xFF8B1A1A, WHITE, league = 2),
|
||||||
|
club("kaiserslautern", "FCK", "1. FC Kaiserslautern", listOf("kaiserslautern"), 0xFFE1000F, WHITE, league = 2),
|
||||||
|
club("karlsruhe", "KSC", "Karlsruher SC", listOf("karlsruher sc", "ksc"), 0xFF0055A5, WHITE, league = 2),
|
||||||
|
club("hannover", "H96", "Hannover 96", listOf("hannover 96"), 0xFF00A94F, WHITE, league = 2),
|
||||||
|
club("paderborn", "SCP", "SC Paderborn 07", listOf("paderborn"), 0xFF004D9D, WHITE, league = 2),
|
||||||
|
club("magdeburg", "FCM", "1. FC Magdeburg", listOf("magdeburg"), 0xFF0B7A3E, WHITE, league = 2),
|
||||||
|
club("elversberg", "SVE", "SV Elversberg", listOf("elversberg"), 0xFF1A1A1A, 0xFFE1000F, league = 2),
|
||||||
|
club("darmstadt", "SV98", "SV Darmstadt 98", listOf("darmstadt"), 0xFF004E9E, WHITE, league = 2),
|
||||||
|
club("braunschweig", "BTSV", "Eintracht Braunschweig", listOf("braunschweig"), 0xFFFDE100, 0xFF004E9E, league = 2),
|
||||||
|
club("bochum", "BOC", "VfL Bochum", listOf("bochum"), 0xFF005CA9, WHITE, league = 2),
|
||||||
|
club("muenster", "SCPM", "Preußen Münster", listOf("preußen münster", "münster"), 0xFF00703C, WHITE, league = 2),
|
||||||
|
club("fuerth", "SGF", "SpVgg Greuther Fürth", listOf("greuther fürth", "fürth"), 0xFF00A94F, WHITE, league = 2),
|
||||||
|
club("holstein", "KSV", "Holstein Kiel", listOf("holstein kiel"), 0xFF004E9E, 0xFFE1000F, league = 2),
|
||||||
|
club("dresden", "SGD", "Dynamo Dresden", listOf("dynamo dresden"), 0xFFFDE100, BLACK, league = 2),
|
||||||
|
club("bielefeld", "DSC", "Arminia Bielefeld", listOf("arminia bielefeld", "bielefeld"), 0xFF00539F, WHITE, league = 2),
|
||||||
|
// --- 3. Liga ---
|
||||||
|
club("hansa", "FCH", "FC Hansa Rostock", listOf("hansa"), 0xFF0B4EA2, WHITE, league = 3),
|
||||||
|
club("saarbruecken", "FCS", "1. FC Saarbrücken", listOf("saarbrücken"), 0xFF0B4EA2, BLACK, league = 3),
|
||||||
|
club("aue", "FCE", "Erzgebirge Aue", listOf("erzgebirge aue"), 0xFF7C0A02, WHITE, league = 3),
|
||||||
|
club("cottbus", "FCEC", "Energie Cottbus", listOf("energie cottbus", "cottbus"), 0xFFE1000F, WHITE, league = 3),
|
||||||
|
club("essen", "RWE", "Rot-Weiss Essen", listOf("rot-weiss essen", "rot weiss essen"), 0xFFE1000F, WHITE, league = 3),
|
||||||
|
club("duisburg", "MSV", "MSV Duisburg", listOf("msv duisburg", "duisburg"), 0xFF004E9E, WHITE, league = 3),
|
||||||
|
club("mannheim", "SVWM", "SV Waldhof Mannheim", listOf("waldhof mannheim", "waldhof"), 0xFF0B4EA2, WHITE, league = 3),
|
||||||
|
club("wehen", "SVWW", "SV Wehen Wiesbaden", listOf("wehen wiesbaden", "wehen"), 0xFFE1000F, BLACK, league = 3),
|
||||||
|
club("ulm", "SSV", "SSV Ulm 1846", listOf("ssv ulm"), 0xFFE1000F, WHITE, article = "SSV Ulm 1846 Fußball", league = 3),
|
||||||
|
club("regensburg", "SSVJ", "SSV Jahn Regensburg", listOf("jahn regensburg", "regensburg"), 0xFFE1000F, WHITE, league = 3),
|
||||||
|
club("verl", "SCV", "SC Verl", listOf("sc verl"), 0xFF00703C, WHITE, league = 3),
|
||||||
|
club("viktoria", "VKÖ", "Viktoria Köln", listOf("viktoria köln"), 0xFFE1000F, WHITE, league = 3),
|
||||||
|
club("havelse", "TSVH", "TSV Havelse", listOf("havelse"), 0xFF004E9E, WHITE, league = 3),
|
||||||
|
club("schweinfurt", "FC05", "1. FC Schweinfurt 05", listOf("schweinfurt"), 0xFF00A94F, WHITE, league = 3),
|
||||||
|
club("osnabrueck", "VfLO", "VfL Osnabrück", listOf("osnabrück"), 0xFF6A2C8F, WHITE, league = 3),
|
||||||
|
club("aachen", "ALE", "Alemannia Aachen", listOf("alemannia aachen", "aachen"), 0xFFFDE100, BLACK, league = 3),
|
||||||
|
club("ingolstadt", "FCI", "FC Ingolstadt 04", listOf("ingolstadt"), 0xFFE1000F, BLACK, league = 3),
|
||||||
|
club("wuppertal", "WSV", "Wuppertaler SV", listOf("wuppertaler sv"), 0xFFE1000F, 0xFF0B4EA2, league = 3),
|
||||||
|
club("stuttgart-ii", "VfB2", "VfB Stuttgart II", listOf("vfb stuttgart ii"), 0xFFE32219, BLACK, league = 3),
|
||||||
|
club("hoffenheim-ii", "TSG2", "TSG Hoffenheim II", listOf("hoffenheim ii"), 0xFF1C63B7, BLACK, article = "TSG 1899 Hoffenheim", league = 3),
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 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 }
|
||||||
|
|
||||||
|
/** Clubs grouped by division, in the order the picker shows them. */
|
||||||
|
fun byLeague(clubs: List<TeamFilter> = all): List<Pair<String, List<TeamFilter>>> =
|
||||||
|
listOf(
|
||||||
|
"1. Bundesliga" to clubs.filter { it.league == 1 },
|
||||||
|
"2. Bundesliga" to clubs.filter { it.league == 2 },
|
||||||
|
"3. Liga" to clubs.filter { it.league == 3 },
|
||||||
|
).filter { it.second.isNotEmpty() }
|
||||||
|
|
||||||
|
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 {
|
fun nowNext(programmes: List<Programme>?, at: Long = System.currentTimeMillis()): NowNext {
|
||||||
if (programmes.isNullOrEmpty()) return NowNext(null, null)
|
if (programmes.isNullOrEmpty()) return NowNext(null, null)
|
||||||
val index = programmes.indexOfFirst { at < it.stop }
|
val index = programmes.indexOfFirst { at < it.stop }
|
||||||
|
|||||||
@@ -64,25 +64,45 @@ class ControlServer(
|
|||||||
// from spending someone else's budget.
|
// from spending someone else's budget.
|
||||||
private val attempts = HashMap<String, ArrayDeque<Long>>()
|
private val attempts = HashMap<String, ArrayDeque<Long>>()
|
||||||
|
|
||||||
|
/** True while this address may still try; does not consume budget. */
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun attemptAllowed(address: String): Boolean {
|
private fun attemptAllowed(address: String): Boolean {
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
val queue = attempts.getOrPut(address) { ArrayDeque() }
|
val queue = attempts[address] ?: return true
|
||||||
while (queue.isNotEmpty() && now - queue.first() > ATTEMPT_WINDOW_MS) {
|
while (queue.isNotEmpty() && now - queue.first() > ATTEMPT_WINDOW_MS) {
|
||||||
queue.removeFirst()
|
queue.removeFirst()
|
||||||
}
|
}
|
||||||
|
return queue.size < ATTEMPT_MAX
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only *failed* authentication costs budget. Counting successes too
|
||||||
|
* threw out honest clients: the phone remote reconnects on every
|
||||||
|
* network hiccup, and five reconnects a minute are normal.
|
||||||
|
*/
|
||||||
|
@Synchronized
|
||||||
|
private fun recordFailure(address: String) {
|
||||||
|
val queue = attempts.getOrPut(address) { ArrayDeque() }
|
||||||
|
queue.addLast(System.currentTimeMillis())
|
||||||
if (attempts.size > MAX_TRACKED_ADDRESSES) {
|
if (attempts.size > MAX_TRACKED_ADDRESSES) {
|
||||||
attempts.entries.removeAll { it.value.isEmpty() }
|
attempts.entries.removeAll { it.value.isEmpty() }
|
||||||
}
|
}
|
||||||
if (queue.size >= ATTEMPT_MAX) return false
|
}
|
||||||
queue.addLast(now)
|
|
||||||
return true
|
@Synchronized
|
||||||
|
private fun clearFailures(address: String) {
|
||||||
|
attempts.remove(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startServer() {
|
fun startServer() {
|
||||||
// A busy port must not take the whole app down — the remote is
|
// A busy port must not take the whole app down — the remote is
|
||||||
// optional, everything else keeps working.
|
// optional, everything else keeps working.
|
||||||
running = runCatching { start(NanoHTTPD.SOCKET_READ_TIMEOUT, true) }
|
// NanoHTTPD's 5 s default also applies to the long-lived WebSocket:
|
||||||
|
// with pings only every 8 s the socket timed out mid-session and the
|
||||||
|
// remote was thrown out after a few seconds. The timeout still has to
|
||||||
|
// exist (idle connections must not pin threads), it just has to be
|
||||||
|
// comfortably longer than the ping interval.
|
||||||
|
running = runCatching { start(SOCKET_TIMEOUT_MS, true) }
|
||||||
.onFailure { Log.w(TAG, "control server unavailable: ${it.javaClass.simpleName}") }
|
.onFailure { Log.w(TAG, "control server unavailable: ${it.javaClass.simpleName}") }
|
||||||
.isSuccess
|
.isSuccess
|
||||||
if (!running) return
|
if (!running) return
|
||||||
@@ -292,8 +312,6 @@ class ControlServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleHello(msg: JSONObject) {
|
private fun handleHello(msg: JSONObject) {
|
||||||
// Every failed attempt counts against this address, whether it
|
|
||||||
// carried a token or a code.
|
|
||||||
if (!attemptAllowed(remoteAddress)) {
|
if (!attemptAllowed(remoteAddress)) {
|
||||||
trySend(JSONObject().put("type", "error").put("error", "rate_limited").toString())
|
trySend(JSONObject().put("type", "error").put("error", "rate_limited").toString())
|
||||||
runCatching { close(WebSocketFrame.CloseCode.PolicyViolation, "rate limited", false) }
|
runCatching { close(WebSocketFrame.CloseCode.PolicyViolation, "rate limited", false) }
|
||||||
@@ -302,10 +320,12 @@ class ControlServer(
|
|||||||
val tokenOk = Pairing.isValidToken(context, msg.optString("token"))
|
val tokenOk = Pairing.isValidToken(context, msg.optString("token"))
|
||||||
val codeOk = !tokenOk && Pairing.isValidCode(context, msg.optString("code"))
|
val codeOk = !tokenOk && Pairing.isValidCode(context, msg.optString("code"))
|
||||||
if (!tokenOk && !codeOk) {
|
if (!tokenOk && !codeOk) {
|
||||||
|
recordFailure(remoteAddress)
|
||||||
trySend(JSONObject().put("type", "error").put("error", "bad_code").toString())
|
trySend(JSONObject().put("type", "error").put("error", "bad_code").toString())
|
||||||
runCatching { close(WebSocketFrame.CloseCode.PolicyViolation, "bad code", false) }
|
runCatching { close(WebSocketFrame.CloseCode.PolicyViolation, "bad code", false) }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
clearFailures(remoteAddress)
|
||||||
authorized = true
|
authorized = true
|
||||||
deviceName = msg.optString("name").ifEmpty { "Handy" }
|
deviceName = msg.optString("name").ifEmpty { "Handy" }
|
||||||
// A code-authenticated client gets its own revocable token, never
|
// A code-authenticated client gets its own revocable token, never
|
||||||
@@ -339,6 +359,7 @@ class ControlServer(
|
|||||||
private companion object {
|
private companion object {
|
||||||
const val TAG = "ControlServer"
|
const val TAG = "ControlServer"
|
||||||
const val PING_INTERVAL_MS = 8_000L
|
const val PING_INTERVAL_MS = 8_000L
|
||||||
|
const val SOCKET_TIMEOUT_MS = 40_000
|
||||||
const val ATTEMPT_WINDOW_MS = 60_000L
|
const val ATTEMPT_WINDOW_MS = 60_000L
|
||||||
const val ATTEMPT_MAX = 5
|
const val ATTEMPT_MAX = 5
|
||||||
const val MAX_TRACKED_ADDRESSES = 64
|
const val MAX_TRACKED_ADDRESSES = 64
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ private fun TopBar(state: AppState) {
|
|||||||
}
|
}
|
||||||
Spacer(Modifier.width(18.dp))
|
Spacer(Modifier.width(18.dp))
|
||||||
}
|
}
|
||||||
|
state.updateAvailable?.let { version ->
|
||||||
|
UpdateChip(version) { state.screen = AppState.Screen.SETTINGS }
|
||||||
|
Spacer(Modifier.width(10.dp))
|
||||||
|
}
|
||||||
GearButton {
|
GearButton {
|
||||||
state.screen = if (state.screen == AppState.Screen.LIVE) AppState.Screen.SETTINGS
|
state.screen = if (state.screen == AppState.Screen.LIVE) AppState.Screen.SETTINGS
|
||||||
else AppState.Screen.LIVE
|
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). */
|
/** Round settings button with a drawn gear (glyphs render as emoji). */
|
||||||
@Composable
|
@Composable
|
||||||
private fun GearButton(onClick: () -> Unit) {
|
private fun GearButton(onClick: () -> Unit) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.castarr.tv.ui
|
package dev.castarr.tv.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -20,6 +21,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
|
|||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.animation.core.animateFloat
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -29,9 +31,17 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.graphics.Path
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import androidx.compose.ui.graphics.drawscope.clipPath
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusProperties
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
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.focus.onFocusChanged
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -71,7 +81,28 @@ fun LiveScreen(state: AppState) {
|
|||||||
val groups = remember(allChannels) {
|
val groups = remember(allChannels) {
|
||||||
allChannels.mapNotNull { it.group.ifEmpty { null } }.distinct().sorted()
|
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) }
|
||||||
|
}
|
||||||
|
// Re-evaluates the highlight every minute; without it "gleich" would
|
||||||
|
// only appear when something else happened to recompose.
|
||||||
|
var urgencyTick by remember { mutableStateOf(0) }
|
||||||
|
LaunchedEffect(teams) {
|
||||||
|
while (true) {
|
||||||
|
kotlinx.coroutines.delay(60_000)
|
||||||
|
urgencyTick++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
val channels = when {
|
||||||
|
activeTeam != null -> activeMatches.map { it.first }
|
||||||
state.favoritesOnly -> allChannels.filter { it.backendId in favorites }
|
state.favoritesOnly -> allChannels.filter { it.backendId in favorites }
|
||||||
state.groupFilter != null -> allChannels.filter { it.group == state.groupFilter }
|
state.groupFilter != null -> allChannels.filter { it.group == state.groupFilter }
|
||||||
else -> allChannels
|
else -> allChannels
|
||||||
@@ -114,11 +145,18 @@ fun LiveScreen(state: AppState) {
|
|||||||
state.restorePending = false
|
state.restorePending = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val intoList = if (channels.isEmpty()) Modifier
|
// A FocusRequester that is not currently attached throws when used, and
|
||||||
else Modifier.focusProperties { right = listFocus }
|
// 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()) {
|
Row(Modifier.fillMaxSize()) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
|
state = railState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(264.dp)
|
.width(264.dp)
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight(),
|
||||||
@@ -128,7 +166,8 @@ fun LiveScreen(state: AppState) {
|
|||||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
) {
|
) {
|
||||||
item {
|
item {
|
||||||
val selected = !state.favoritesOnly && state.groupFilter == null
|
val selected = !state.favoritesOnly && state.groupFilter == null &&
|
||||||
|
state.activeTeam == null
|
||||||
GroupItem(
|
GroupItem(
|
||||||
label = "Alle Sender",
|
label = "Alle Sender",
|
||||||
count = allChannels.size,
|
count = allChannels.size,
|
||||||
@@ -138,6 +177,7 @@ fun LiveScreen(state: AppState) {
|
|||||||
),
|
),
|
||||||
suppressAutoSelect = { state.restorePending },
|
suppressAutoSelect = { state.restorePending },
|
||||||
) {
|
) {
|
||||||
|
state.activeTeam = null
|
||||||
state.favoritesOnly = false
|
state.favoritesOnly = false
|
||||||
state.groupFilter = null
|
state.groupFilter = null
|
||||||
}
|
}
|
||||||
@@ -147,17 +187,40 @@ fun LiveScreen(state: AppState) {
|
|||||||
GroupItem(
|
GroupItem(
|
||||||
label = "★ Favoriten",
|
label = "★ Favoriten",
|
||||||
count = favorites.size,
|
count = favorites.size,
|
||||||
selected = state.favoritesOnly,
|
selected = state.favoritesOnly && state.activeTeam == null,
|
||||||
modifier = intoList.then(
|
modifier = intoList.then(
|
||||||
if (state.favoritesOnly) Modifier.focusRequester(railFocus) else Modifier
|
if (state.favoritesOnly) Modifier.focusRequester(railFocus) else Modifier
|
||||||
),
|
),
|
||||||
suppressAutoSelect = { state.restorePending },
|
suppressAutoSelect = { state.restorePending },
|
||||||
) {
|
) {
|
||||||
|
state.activeTeam = null
|
||||||
state.favoritesOnly = true
|
state.favoritesOnly = true
|
||||||
state.groupFilter = null
|
state.groupFilter = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
items(teams, key = { it.key }) { club ->
|
||||||
|
val clubMatches = matchesByTeam[club.key].orEmpty()
|
||||||
|
val clubSignal = remember(clubMatches, urgencyTick) {
|
||||||
|
state.teamSignal(clubMatches)
|
||||||
|
}
|
||||||
|
GroupItem(
|
||||||
|
label = club.label,
|
||||||
|
count = clubMatches.size,
|
||||||
|
selected = state.activeTeam == club.key,
|
||||||
|
leading = { Crest(club, state, clubSignal.urgency) },
|
||||||
|
signal = clubSignal,
|
||||||
|
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 {
|
item {
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
@@ -171,12 +234,13 @@ fun LiveScreen(state: AppState) {
|
|||||||
GroupItem(
|
GroupItem(
|
||||||
label = group,
|
label = group,
|
||||||
count = remember(allChannels, group) { allChannels.count { it.group == group } },
|
count = remember(allChannels, group) { allChannels.count { it.group == group } },
|
||||||
selected = state.groupFilter == group,
|
selected = state.groupFilter == group && state.activeTeam == null,
|
||||||
modifier = intoList.then(
|
modifier = intoList.then(
|
||||||
if (state.groupFilter == group) Modifier.focusRequester(railFocus) else Modifier
|
if (state.groupFilter == group) Modifier.focusRequester(railFocus) else Modifier
|
||||||
),
|
),
|
||||||
suppressAutoSelect = { state.restorePending },
|
suppressAutoSelect = { state.restorePending },
|
||||||
) {
|
) {
|
||||||
|
state.activeTeam = null
|
||||||
state.favoritesOnly = false
|
state.favoritesOnly = false
|
||||||
state.groupFilter = group
|
state.groupFilter = group
|
||||||
}
|
}
|
||||||
@@ -196,9 +260,13 @@ fun LiveScreen(state: AppState) {
|
|||||||
if (channels.isEmpty()) {
|
if (channels.isEmpty()) {
|
||||||
item {
|
item {
|
||||||
Text(
|
Text(
|
||||||
if (state.favoritesOnly)
|
when {
|
||||||
|
activeTeam != null ->
|
||||||
|
"Heute läuft nichts mehr mit ${activeTeam.fullName}."
|
||||||
|
state.favoritesOnly ->
|
||||||
"Noch keine Favoriten — halte OK auf einem Sender gedrückt."
|
"Noch keine Favoriten — halte OK auf einem Sender gedrückt."
|
||||||
else "Diese Gruppe ist leer.",
|
else -> "Diese Gruppe ist leer."
|
||||||
|
},
|
||||||
color = CastarrColors.faint,
|
color = CastarrColors.faint,
|
||||||
fontFamily = AppFont,
|
fontFamily = AppFont,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
@@ -213,13 +281,18 @@ fun LiveScreen(state: AppState) {
|
|||||||
// matching the remote's number pad in every view.
|
// matching the remote's number pad in every view.
|
||||||
number = allChannels.indexOf(channel) + 1,
|
number = allChannels.indexOf(channel) + 1,
|
||||||
modifier = Modifier
|
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 == 0) Modifier.focusRequester(listFocus) else Modifier)
|
||||||
.then(
|
.then(
|
||||||
if (listIndex == restoreIndex) Modifier.focusRequester(restoreFocus)
|
if (listIndex == restoreIndex) Modifier.focusRequester(restoreFocus)
|
||||||
else Modifier
|
else Modifier
|
||||||
),
|
),
|
||||||
nowNext = state.nowNext(channel),
|
nowNext = state.nowNext(channel),
|
||||||
|
highlight = teamHits[channel.url],
|
||||||
playing = state.currentChannel?.url == channel.url,
|
playing = state.currentChannel?.url == channel.url,
|
||||||
// All rows are favorites in the favorites view — the
|
// All rows are favorites in the favorites view — the
|
||||||
// star only carries meaning elsewhere.
|
// star only carries meaning elsewhere.
|
||||||
@@ -241,6 +314,9 @@ private fun GroupItem(
|
|||||||
count: Int,
|
count: Int,
|
||||||
selected: Boolean,
|
selected: Boolean,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
leading: (@Composable () -> Unit)? = null,
|
||||||
|
/** Replaces the count when a match is on or about to start. */
|
||||||
|
signal: AppState.TeamSignal? = null,
|
||||||
suppressAutoSelect: () -> Boolean = { false },
|
suppressAutoSelect: () -> Boolean = { false },
|
||||||
onSelect: () -> Unit,
|
onSelect: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -264,6 +340,10 @@ private fun GroupItem(
|
|||||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 9.dp),
|
modifier = Modifier.padding(horizontal = 14.dp, vertical = 9.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
|
if (leading != null) {
|
||||||
|
leading()
|
||||||
|
Spacer(Modifier.width(10.dp))
|
||||||
|
}
|
||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
fontFamily = AppFont,
|
fontFamily = AppFont,
|
||||||
@@ -274,10 +354,24 @@ private fun GroupItem(
|
|||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
Spacer(Modifier.width(8.dp))
|
Spacer(Modifier.width(8.dp))
|
||||||
|
// The signal lives in the value column instead of adding a
|
||||||
|
// badge — the count is worth less than "now" or "16:00" is.
|
||||||
|
val urgent = signal?.urgency ?: AppState.TeamUrgency.NONE
|
||||||
Text(
|
Text(
|
||||||
"$count",
|
when (urgent) {
|
||||||
|
AppState.TeamUrgency.LIVE -> "läuft"
|
||||||
|
AppState.TeamUrgency.SOON -> formatClock(signal!!.kickOff)
|
||||||
|
AppState.TeamUrgency.NONE -> "$count"
|
||||||
|
},
|
||||||
|
color = when (urgent) {
|
||||||
|
AppState.TeamUrgency.LIVE -> CastarrColors.live
|
||||||
|
AppState.TeamUrgency.SOON -> CastarrColors.accent
|
||||||
|
AppState.TeamUrgency.NONE -> Color.Unspecified
|
||||||
|
},
|
||||||
fontFamily = AppFont,
|
fontFamily = AppFont,
|
||||||
fontSize = 12.sp,
|
fontSize = 12.sp,
|
||||||
|
fontWeight = if (urgent == AppState.TeamUrgency.NONE) FontWeight.Normal
|
||||||
|
else FontWeight.SemiBold,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,6 +383,7 @@ private fun ChannelRow(
|
|||||||
number: Int,
|
number: Int,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
nowNext: NowNext,
|
nowNext: NowNext,
|
||||||
|
highlight: AppState.TeamHit? = null,
|
||||||
playing: Boolean,
|
playing: Boolean,
|
||||||
favorite: Boolean,
|
favorite: Boolean,
|
||||||
epgStamp: Long,
|
epgStamp: Long,
|
||||||
@@ -349,7 +444,13 @@ private fun ChannelRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(Modifier.width(24.dp))
|
Spacer(Modifier.width(24.dp))
|
||||||
|
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))
|
EpgCell(nowNext, Modifier.weight(1f))
|
||||||
|
}
|
||||||
if (playing) {
|
if (playing) {
|
||||||
Spacer(Modifier.width(12.dp))
|
Spacer(Modifier.width(12.dp))
|
||||||
Box(
|
Box(
|
||||||
@@ -363,6 +464,81 @@ private fun ChannelRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
urgency: AppState.TeamUrgency = AppState.TeamUrgency.NONE,
|
||||||
|
) {
|
||||||
|
Box(Modifier.size(20.dp), contentAlignment = Alignment.Center) {
|
||||||
|
if (urgency != AppState.TeamUrgency.NONE) {
|
||||||
|
// A slow pulse is what actually catches the eye from the sofa;
|
||||||
|
// colour alone does not at that distance.
|
||||||
|
val transition = androidx.compose.animation.core.rememberInfiniteTransition(
|
||||||
|
label = "crest-pulse",
|
||||||
|
)
|
||||||
|
val phase by transition.animateFloat(
|
||||||
|
initialValue = 0f,
|
||||||
|
targetValue = 1f,
|
||||||
|
animationSpec = androidx.compose.animation.core.infiniteRepeatable(
|
||||||
|
androidx.compose.animation.core.tween(2000, easing = androidx.compose.animation.core.LinearEasing),
|
||||||
|
androidx.compose.animation.core.RepeatMode.Restart,
|
||||||
|
),
|
||||||
|
label = "phase",
|
||||||
|
)
|
||||||
|
val ringColor =
|
||||||
|
if (urgency == AppState.TeamUrgency.LIVE) CastarrColors.live
|
||||||
|
else CastarrColors.accent
|
||||||
|
Canvas(Modifier.size(30.dp)) {
|
||||||
|
val grow = phase.coerceAtMost(0.7f) / 0.7f
|
||||||
|
drawCircle(
|
||||||
|
color = ringColor.copy(alpha = (1f - grow) * 0.9f),
|
||||||
|
radius = size.minDimension * (0.33f + grow * 0.17f),
|
||||||
|
style = Stroke(width = 2.dp.toPx()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SubcomposeAsyncImage(
|
||||||
|
model = "file:///android_asset/crests/${team.key}.png",
|
||||||
|
contentDescription = null,
|
||||||
|
contentScale = ContentScale.Fit,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
loading = { ShieldFallback(team) },
|
||||||
|
error = { 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. */
|
/** Bare channel logo (they ship transparent); initials as fallback. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun LogoTile(channel: Channel) {
|
private fun LogoTile(channel: Channel) {
|
||||||
@@ -397,6 +573,42 @@ private fun LogoInitials(initials: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The next club broadcast on this channel, and how many follow it. */
|
||||||
|
@Composable
|
||||||
|
private fun HighlightCell(hit: AppState.TeamHit, modifier: Modifier = Modifier) {
|
||||||
|
val programme = hit.programme
|
||||||
|
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)}" +
|
||||||
|
if (hit.further > 0) " · +${hit.further} weitere" else "",
|
||||||
|
color = CastarrColors.faint,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun formatClock(millis: Long): String =
|
private fun formatClock(millis: Long): String =
|
||||||
SimpleDateFormat("HH:mm", Locale.GERMANY).format(Date(millis))
|
SimpleDateFormat("HH:mm", Locale.GERMANY).format(Date(millis))
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import androidx.compose.foundation.Canvas
|
|||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -14,9 +16,14 @@ import androidx.compose.foundation.layout.Spacer
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -32,6 +39,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Path
|
import androidx.compose.ui.graphics.Path
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -72,6 +80,7 @@ fun SettingsScreen(state: AppState) {
|
|||||||
val profiles by state.dispatcharr.profiles.collectAsState()
|
val profiles by state.dispatcharr.profiles.collectAsState()
|
||||||
var updateStatus by remember { mutableStateOf("") }
|
var updateStatus by remember { mutableStateOf("") }
|
||||||
var picker by remember { mutableStateOf<Picker?>(null) }
|
var picker by remember { mutableStateOf<Picker?>(null) }
|
||||||
|
var clubPicker by remember { mutableStateOf(false) }
|
||||||
// Bumped on reset so the QR code and the four-digit code redraw.
|
// Bumped on reset so the QR code and the four-digit code redraw.
|
||||||
var pairingEpoch by remember { mutableStateOf(0) }
|
var pairingEpoch by remember { mutableStateOf(0) }
|
||||||
|
|
||||||
@@ -80,7 +89,14 @@ fun SettingsScreen(state: AppState) {
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(horizontal = 40.dp, vertical = 12.dp)
|
.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") {
|
SettingsCard("Konto") {
|
||||||
if (state.auth.isLoggedIn) {
|
if (state.auth.isLoggedIn) {
|
||||||
Row(
|
Row(
|
||||||
@@ -163,6 +179,32 @@ fun SettingsScreen(state: AppState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsCard("Vereinsmenüs") {
|
||||||
|
Text(
|
||||||
|
"Eigene Gruppe mit allen Sendern, auf denen der Verein " +
|
||||||
|
"heute noch 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 · Entfernen",
|
||||||
|
leading = { ClubCrest(club, state) },
|
||||||
|
trailing = { RemoveIcon() },
|
||||||
|
) { state.toggleTeam(club.key) }
|
||||||
|
}
|
||||||
|
if (active.size < dev.castarr.tv.data.TeamFilters.MAX_ACTIVE) {
|
||||||
|
SettingRow(
|
||||||
|
"Verein hinzufügen",
|
||||||
|
subtitle = "1. bis 3. Liga",
|
||||||
|
) { clubPicker = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SettingsCard("App") {
|
SettingsCard("App") {
|
||||||
SettingRow(
|
SettingRow(
|
||||||
"Version ${BuildConfig.VERSION_NAME}",
|
"Version ${BuildConfig.VERSION_NAME}",
|
||||||
@@ -203,6 +245,10 @@ fun SettingsScreen(state: AppState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SettingRow(
|
||||||
|
"Senderliste neu laden",
|
||||||
|
subtitle = "Holt Sender, Programm und Favoriten erneut",
|
||||||
|
) { state.refreshActive() }
|
||||||
SettingRow(
|
SettingRow(
|
||||||
"Erweitert",
|
"Erweitert",
|
||||||
subtitle = "M3U/EPG-Adressen von Hand eintragen",
|
subtitle = "M3U/EPG-Adressen von Hand eintragen",
|
||||||
@@ -267,13 +313,168 @@ fun SettingsScreen(state: AppState) {
|
|||||||
picker?.let { current ->
|
picker?.let { current ->
|
||||||
PickerDialog(current) { picker = null }
|
PickerDialog(current) { picker = null }
|
||||||
}
|
}
|
||||||
|
if (clubPicker) {
|
||||||
|
ClubPickerDialog(
|
||||||
|
state = state,
|
||||||
|
onPick = { club -> state.toggleTeam(club.key); clubPicker = false },
|
||||||
|
onClose = { clubPicker = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Club crest from the bundled assets; initials while it loads. */
|
||||||
|
@Composable
|
||||||
|
private fun ClubCrest(team: dev.castarr.tv.data.TeamFilter, state: AppState, size: Int = 26) {
|
||||||
|
Box(Modifier.size(size.dp), contentAlignment = Alignment.Center) {
|
||||||
|
coil.compose.SubcomposeAsyncImage(
|
||||||
|
model = "file:///android_asset/crests/${team.key}.png",
|
||||||
|
contentDescription = null,
|
||||||
|
contentScale = androidx.compose.ui.layout.ContentScale.Fit,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
loading = { CrestInitials(team) },
|
||||||
|
error = { CrestInitials(team) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun CrestInitials(team: dev.castarr.tv.data.TeamFilter) {
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(team.primary),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
team.label.take(3),
|
||||||
|
color = team.secondary,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 8.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Club chooser: crests plus division headers, because a flat list of 56
|
||||||
|
* names is unreadable on a remote.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun ClubPickerDialog(
|
||||||
|
state: AppState,
|
||||||
|
onPick: (dev.castarr.tv.data.TeamFilter) -> Unit,
|
||||||
|
onClose: () -> Unit,
|
||||||
|
) {
|
||||||
|
val firstFocus = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(Unit) { runCatching { firstFocus.requestFocus() } }
|
||||||
|
val sections = remember(state.enabledTeams) {
|
||||||
|
dev.castarr.tv.data.TeamFilters.byLeague(
|
||||||
|
dev.castarr.tv.data.TeamFilters.all.filter { it.key !in state.enabledTeams }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val firstKey = sections.firstOrNull()?.second?.firstOrNull()?.key
|
||||||
|
Dialog(onDismissRequest = onClose, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(CastarrColors.bgDeep.copy(alpha = 0.88f)),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.width(420.dp)
|
||||||
|
.clip(RoundedCornerShape(16.dp))
|
||||||
|
.background(CastarrColors.surface)
|
||||||
|
.padding(horizontal = 10.dp, vertical = 14.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"VEREIN HINZUFÜGEN",
|
||||||
|
color = CastarrColors.faint,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 11.sp,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
letterSpacing = 2.sp,
|
||||||
|
modifier = Modifier.padding(start = 14.dp, bottom = 10.dp),
|
||||||
|
)
|
||||||
|
LazyColumn(Modifier.heightIn(max = 460.dp)) {
|
||||||
|
sections.forEach { (league, clubs) ->
|
||||||
|
item(key = "h-$league") {
|
||||||
|
Text(
|
||||||
|
league,
|
||||||
|
color = CastarrColors.accent,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 11.sp,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
letterSpacing = 1.5.sp,
|
||||||
|
modifier = Modifier.padding(start = 14.dp, top = 12.dp, bottom = 6.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
items(clubs, key = { it.key }) { club ->
|
||||||
|
val focusMod =
|
||||||
|
if (club.key == firstKey) Modifier.focusRequester(firstFocus)
|
||||||
|
else Modifier
|
||||||
|
Surface(
|
||||||
|
onClick = { onPick(club) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.then(focusMod),
|
||||||
|
shape = ClickableSurfaceDefaults.shape(rowShape),
|
||||||
|
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f),
|
||||||
|
colors = ClickableSurfaceDefaults.colors(
|
||||||
|
containerColor = androidx.compose.ui.graphics.Color.Transparent,
|
||||||
|
contentColor = CastarrColors.fg,
|
||||||
|
focusedContainerColor = CastarrColors.surfaceFocused,
|
||||||
|
focusedContentColor = CastarrColors.fg,
|
||||||
|
),
|
||||||
|
border = ClickableSurfaceDefaults.border(
|
||||||
|
focusedBorder = Border(
|
||||||
|
border = BorderStroke(2.dp, CastarrColors.accent),
|
||||||
|
shape = rowShape,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(horizontal = 14.dp, vertical = 9.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
ClubCrest(club, state, size = 24)
|
||||||
|
Spacer(Modifier.width(12.dp))
|
||||||
|
Text(
|
||||||
|
club.fullName,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 14.sp,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
club.label,
|
||||||
|
color = CastarrColors.faint,
|
||||||
|
fontFamily = AppFont,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TV-friendly dropdown replacement: fullscreen scrim, options centered. */
|
/** TV-friendly dropdown replacement: fullscreen scrim, options centered. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
||||||
val selectedFocus = remember { FocusRequester() }
|
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(
|
Dialog(
|
||||||
onDismissRequest = onClose,
|
onDismissRequest = onClose,
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||||
@@ -302,7 +503,11 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
|||||||
letterSpacing = 2.sp,
|
letterSpacing = 2.sp,
|
||||||
modifier = Modifier.padding(start = 14.dp, bottom = 10.dp),
|
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
|
val selected = index == picker.selected
|
||||||
Surface(
|
Surface(
|
||||||
onClick = {
|
onClick = {
|
||||||
@@ -311,7 +516,11 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
|||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.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),
|
shape = ClickableSurfaceDefaults.shape(rowShape),
|
||||||
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f),
|
scale = ClickableSurfaceDefaults.scale(focusedScale = 1f),
|
||||||
colors = ClickableSurfaceDefaults.colors(
|
colors = ClickableSurfaceDefaults.colors(
|
||||||
@@ -355,6 +564,7 @@ private fun PickerDialog(picker: Picker, onClose: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Current value plus a small drawn caret, shown at a row's trailing edge. */
|
/** Current value plus a small drawn caret, shown at a row's trailing edge. */
|
||||||
@@ -385,6 +595,35 @@ private fun ValueWithCaret(value: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Drawn "x": the row only ever removes, so a toggle would mislead. */
|
||||||
|
@Composable
|
||||||
|
private fun RemoveIcon() {
|
||||||
|
val color = CastarrColors.muted
|
||||||
|
Canvas(Modifier.size(14.dp)) {
|
||||||
|
val stroke = 2.dp.toPx()
|
||||||
|
drawLine(color, Offset(0f, 0f), Offset(size.width, size.height), stroke)
|
||||||
|
drawLine(color, Offset(size.width, 0f), Offset(0f, size.height), stroke)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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
|
@Composable
|
||||||
private fun SettingsCard(title: String, content: @Composable () -> Unit) {
|
private fun SettingsCard(title: String, content: @Composable () -> Unit) {
|
||||||
Column(
|
Column(
|
||||||
@@ -415,6 +654,7 @@ private fun SettingRow(
|
|||||||
label: String,
|
label: String,
|
||||||
subtitle: String? = null,
|
subtitle: String? = null,
|
||||||
danger: Boolean = false,
|
danger: Boolean = false,
|
||||||
|
leading: (@Composable () -> Unit)? = null,
|
||||||
trailing: (@Composable () -> Unit)? = null,
|
trailing: (@Composable () -> Unit)? = null,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
@@ -440,6 +680,10 @@ private fun SettingRow(
|
|||||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp),
|
modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
|
if (leading != null) {
|
||||||
|
leading()
|
||||||
|
Spacer(Modifier.width(12.dp))
|
||||||
|
}
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
|
|||||||
107
tests/demo/make-demo-data.py
Executable file
107
tests/demo/make-demo-data.py
Executable file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Neutral demo line-up for screenshots and manual testing.
|
||||||
|
|
||||||
|
Invented channels and programmes only — no real provider data ever ends up
|
||||||
|
in a screenshot. One club match is placed a few minutes ahead so the club
|
||||||
|
menu shows its "kick-off imminent" state.
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
|
p = argparse.ArgumentParser()
|
||||||
|
p.add_argument("--out", default=os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
p.add_argument("--kickoff-in", type=int, default=18,
|
||||||
|
help="minutes until the club match starts")
|
||||||
|
args = p.parse_args()
|
||||||
|
|
||||||
|
now = datetime.datetime.now().astimezone()
|
||||||
|
|
||||||
|
|
||||||
|
def fmt(dt):
|
||||||
|
# Local offset, so the emulator's clock agrees with ours (CEST vs CET).
|
||||||
|
return dt.strftime("%Y%m%d%H%M%S %z")
|
||||||
|
|
||||||
|
|
||||||
|
CHANNELS = [
|
||||||
|
("Unterhaltung", "Blau TV HD", "blau"),
|
||||||
|
("Unterhaltung", "Nordlicht HD", "nordlicht"),
|
||||||
|
("Unterhaltung", "Kanal Sieben", "sieben"),
|
||||||
|
("Filme", "Kinohaus HD", "kinohaus"),
|
||||||
|
("Filme", "Filmwerk Classic", "filmwerk"),
|
||||||
|
("Filme", "Nachtkino HD", "nachtkino"),
|
||||||
|
("Serien", "Serienbox HD", "serienbox"),
|
||||||
|
("Serien", "Staffel Eins", "staffel"),
|
||||||
|
("Sport", "Arena Sport 1 HD", "arena1"),
|
||||||
|
("Sport", "Arena Sport 2 HD", "arena2"),
|
||||||
|
("Sport", "Liga Live UHD", "ligalive"),
|
||||||
|
("Sport", "Stadionkanal HD", "stadion"),
|
||||||
|
("Nachrichten", "Tagesblick HD", "tagesblick"),
|
||||||
|
("Nachrichten", "Weltbericht", "weltbericht"),
|
||||||
|
("Doku & Wissen", "Terra Doku HD", "terra"),
|
||||||
|
("Doku & Wissen", "Wissenswelt", "wissen"),
|
||||||
|
("Kinder", "Krümelkiste", "kruemel"),
|
||||||
|
("Musik", "Tonspur HD", "tonspur"),
|
||||||
|
("Regional", "Hafenkanal HD", "hafen"),
|
||||||
|
("International", "Globus TV", "globus"),
|
||||||
|
]
|
||||||
|
|
||||||
|
PROGRAMMES = {
|
||||||
|
"blau": [("Morgenmagazin", -40, 80), ("Kochduell", 40, 60)],
|
||||||
|
"nordlicht": [("Küstenrevier", -20, 70), ("Nordlicht Talk", 50, 45)],
|
||||||
|
"sieben": [("Quiz um Sieben", -10, 60), ("Sieben Reportage", 50, 45)],
|
||||||
|
"kinohaus": [("Der weite Weg", -55, 125), ("Sturmhöhe", 70, 110)],
|
||||||
|
"filmwerk": [("Schwarzweiß", -30, 95), ("Die Erbschaft", 65, 100)],
|
||||||
|
"nachtkino": [("Mitternachtszug", -15, 105), ("Letzte Runde", 90, 95)],
|
||||||
|
"serienbox": [("Praxis Ostwind (3/12)", -25, 45), ("Praxis Ostwind (4/12)", 20, 45)],
|
||||||
|
"staffel": [("Hafenwache (7/10)", -35, 50), ("Hafenwache (8/10)", 15, 50)],
|
||||||
|
"arena1": [("Handball: Pokalrunde", -45, 105), ("Sport am Abend", 60, 60)],
|
||||||
|
"arena2": [("Radsport: Etappe 4", -50, 130), ("Motorsport kompakt", 80, 55)],
|
||||||
|
"ligalive": [("Sport aktuell", -25, 43), ("__CLUB__", None, 120)],
|
||||||
|
"stadion": [("Stadionmagazin", -20, 60), ("FC St. Pauli: Der Rückblick", 40, 45)],
|
||||||
|
"tagesblick": [("Tagesblick am Mittag", -12, 30), ("Wetter und Verkehr", 18, 15)],
|
||||||
|
"weltbericht": [("Weltbericht Spezial", -35, 75), ("Auslandsjournal", 40, 45)],
|
||||||
|
"terra": [("Wale der Arktis", -40, 90), ("Vulkane Islands", 50, 45)],
|
||||||
|
"wissen": [("Wie Brücken halten", -20, 45), ("Chemie des Alltags", 25, 45)],
|
||||||
|
"kruemel": [("Bärenbande", -15, 25), ("Malstunde", 10, 25)],
|
||||||
|
"tonspur": [("Charts der Woche", -60, 120), ("Akustik-Session", 60, 60)],
|
||||||
|
"hafen": [("Hafenrundfahrt", -30, 60), ("Regional um sechs", 30, 30)],
|
||||||
|
"globus": [("Globus Reportage", -45, 90), ("Fernweh", 45, 60)],
|
||||||
|
}
|
||||||
|
|
||||||
|
CLUB_TITLE = "Pokal: Nordstadt - FC St. Pauli, 1. Runde"
|
||||||
|
|
||||||
|
os.makedirs(args.out, exist_ok=True)
|
||||||
|
m3u = os.path.join(args.out, "playlist.m3u")
|
||||||
|
xml = os.path.join(args.out, "epg.xml")
|
||||||
|
|
||||||
|
with open(m3u, "w", encoding="utf-8") as f:
|
||||||
|
f.write("#EXTM3U\n")
|
||||||
|
for group, name, cid in CHANNELS:
|
||||||
|
f.write(f'#EXTINF:-1 tvg-id="{cid}" group-title="{group}",{name}\n')
|
||||||
|
f.write(f"http://10.0.2.2:8099/stream/{cid}.ts\n")
|
||||||
|
|
||||||
|
|
||||||
|
def escape(text):
|
||||||
|
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||||
|
|
||||||
|
|
||||||
|
with open(xml, "w", encoding="utf-8") as f:
|
||||||
|
f.write('<?xml version="1.0" encoding="UTF-8"?>\n<tv>\n')
|
||||||
|
for _, name, cid in CHANNELS:
|
||||||
|
f.write(f' <channel id="{cid}"><display-name>{escape(name)}</display-name></channel>\n')
|
||||||
|
for cid, items in PROGRAMMES.items():
|
||||||
|
for title, offset, length in items:
|
||||||
|
if title == "__CLUB__":
|
||||||
|
title, offset = CLUB_TITLE, args.kickoff_in
|
||||||
|
start = now + datetime.timedelta(minutes=offset)
|
||||||
|
stop = start + datetime.timedelta(minutes=length)
|
||||||
|
f.write(
|
||||||
|
f' <programme start="{fmt(start)}" stop="{fmt(stop)}" channel="{cid}">'
|
||||||
|
f"<title>{escape(title)}</title></programme>\n"
|
||||||
|
)
|
||||||
|
f.write("</tv>\n")
|
||||||
|
|
||||||
|
print(f"{len(CHANNELS)} Sender, {sum(len(v) for v in PROGRAMMES.values())} Sendungen")
|
||||||
|
print(f"Anstoß in {args.kickoff_in} Min: {CLUB_TITLE}")
|
||||||
|
print(f"-> {m3u}\n-> {xml}")
|
||||||
80
tests/unit/TeamFiltersTest.kt
Normal file
80
tests/unit/TeamFiltersTest.kt
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
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 `window reaches midnight but never falls below three hours`() {
|
||||||
|
val cal = java.util.Calendar.getInstance()
|
||||||
|
// Morning: the window must reach into the evening.
|
||||||
|
cal.set(java.util.Calendar.HOUR_OF_DAY, 9)
|
||||||
|
cal.set(java.util.Calendar.MINUTE, 0)
|
||||||
|
val morning = cal.timeInMillis
|
||||||
|
val eveningKickoff = morning + 12 * 60 * 60 * 1000L
|
||||||
|
assertTrue(TeamFilters.windowEnd(morning) > eveningKickoff)
|
||||||
|
|
||||||
|
// Late at night: still at least three hours ahead.
|
||||||
|
cal.set(java.util.Calendar.HOUR_OF_DAY, 23)
|
||||||
|
cal.set(java.util.Calendar.MINUTE, 30)
|
||||||
|
val lateNight = cal.timeInMillis
|
||||||
|
assertTrue(
|
||||||
|
TeamFilters.windowEnd(lateNight) >= lateNight + TeamFilters.MIN_WINDOW_MS
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@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))
|
||||||
|
}
|
||||||
|
}
|
||||||
58
tools/crest-sources.json
Normal file
58
tools/crest-sources.json
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"aachen": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Alemannia_Aachen_2010.svg/langde-330px-Alemannia_Aachen_2010.svg.png",
|
||||||
|
"aue": "https://thumb.wikimedia.org/wikipedia/de/thumb/1/13/Fc_erzgebirge_aue.svg/langde-330px-Fc_erzgebirge_aue.svg.png",
|
||||||
|
"augsburg": "https://upload.wikimedia.org/wikipedia/de/thumb/b/b5/Logo_FC_Augsburg.svg/langde-330px-Logo_FC_Augsburg.svg.png",
|
||||||
|
"bayern": "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/FC_Bayern_M%C3%BCnchen_logo_%282024%29.svg/langde-330px-FC_Bayern_M%C3%BCnchen_logo_%282024%29.svg.png",
|
||||||
|
"bielefeld": "https://thumb.wikimedia.org/wikipedia/commons/thumb/f/fd/Arminia_Bielefeld_Logo_2021%E2%80%93.svg/langde-330px-Arminia_Bielefeld_Logo_2021%E2%80%93.svg.png",
|
||||||
|
"bochum": "https://thumb.wikimedia.org/wikipedia/commons/thumb/7/72/VfL_Bochum_logo.svg/langde-330px-VfL_Bochum_logo.svg.png",
|
||||||
|
"braunschweig": "https://thumb.wikimedia.org/wikipedia/de/thumb/4/45/Logo_Eintracht_Braunschweig.svg/langde-330px-Logo_Eintracht_Braunschweig.svg.png",
|
||||||
|
"bremen": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/SV-Werder-Bremen-Logo.svg/langde-330px-SV-Werder-Bremen-Logo.svg.png",
|
||||||
|
"bvb": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/Borussia_Dortmund_logo.svg/langde-330px-Borussia_Dortmund_logo.svg.png",
|
||||||
|
"cottbus": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Logo_Energie_Cottbus.svg/langde-330px-Logo_Energie_Cottbus.svg.png",
|
||||||
|
"darmstadt": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/SV_Darmstadt_98_Logo.svg/langde-330px-SV_Darmstadt_98_Logo.svg.png",
|
||||||
|
"dresden": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Logo_SG_Dynamo_Dresden_neu.svg/langde-330px-Logo_SG_Dynamo_Dresden_neu.svg.png",
|
||||||
|
"duesseldorf": "https://thumb.wikimedia.org/wikipedia/commons/thumb/9/94/Fortuna_D%C3%BCsseldorf.svg/langde-330px-Fortuna_D%C3%BCsseldorf.svg.png",
|
||||||
|
"duisburg": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Msv_duisburg_%282017%29.svg/langde-330px-Msv_duisburg_%282017%29.svg.png",
|
||||||
|
"elversberg": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/SV_Elversberg_Logo_2021.svg/langde-330px-SV_Elversberg_Logo_2021.svg.png",
|
||||||
|
"essen": "https://upload.wikimedia.org/wikipedia/de/thumb/8/8a/Logo_Rot-Weiss_Essen.svg/langde-330px-Logo_Rot-Weiss_Essen.svg.png",
|
||||||
|
"frankfurt": "https://upload.wikimedia.org/wikipedia/de/thumb/3/32/Logo_Eintracht_Frankfurt_1998.svg/langde-330px-Logo_Eintracht_Frankfurt_1998.svg.png",
|
||||||
|
"freiburg": "https://upload.wikimedia.org/wikipedia/de/thumb/b/bf/SC_Freiburg_Logo.svg/langde-330px-SC_Freiburg_Logo.svg.png",
|
||||||
|
"fuerth": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/SpVgg_Greuther_F%C3%BCrth_2017.svg/langde-330px-SpVgg_Greuther_F%C3%BCrth_2017.svg.png",
|
||||||
|
"gladbach": "https://thumb.wikimedia.org/wikipedia/commons/thumb/8/81/Borussia_M%C3%B6nchengladbach_logo.svg/langde-330px-Borussia_M%C3%B6nchengladbach_logo.svg.png",
|
||||||
|
"hannover": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Hannover_96_Logo.svg/langde-330px-Hannover_96_Logo.svg.png",
|
||||||
|
"hansa": "https://thumb.wikimedia.org/wikipedia/commons/thumb/8/8f/F.C._Hansa_Rostock_Logo.svg/langde-330px-F.C._Hansa_Rostock_Logo.svg.png",
|
||||||
|
"havelse": "https://thumb.wikimedia.org/wikipedia/commons/thumb/8/89/TSV_Havelse_logo.svg/langde-330px-TSV_Havelse_logo.svg.png",
|
||||||
|
"heidenheim": "https://thumb.wikimedia.org/wikipedia/commons/thumb/9/9d/1._FC_Heidenheim_1846.svg/langde-330px-1._FC_Heidenheim_1846.svg.png",
|
||||||
|
"hertha": "https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Hertha_BSC_Logo_2012.svg/langde-330px-Hertha_BSC_Logo_2012.svg.png",
|
||||||
|
"hoffenheim": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_TSG_Hoffenheim.svg/langde-330px-Logo_TSG_Hoffenheim.svg.png",
|
||||||
|
"hoffenheim-ii": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Logo_TSG_Hoffenheim.svg/langde-330px-Logo_TSG_Hoffenheim.svg.png",
|
||||||
|
"holstein": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Holstein_Kiel_Logo.svg/langde-330px-Holstein_Kiel_Logo.svg.png",
|
||||||
|
"hsv": "https://thumb.wikimedia.org/wikipedia/commons/thumb/f/f7/Hamburger_SV_logo.svg/langde-330px-Hamburger_SV_logo.svg.png",
|
||||||
|
"ingolstadt": "https://thumb.wikimedia.org/wikipedia/de/thumb/5/55/FC-Ingolstadt_logo.svg/langde-330px-FC-Ingolstadt_logo.svg.png",
|
||||||
|
"kaiserslautern": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Logo_1_FC_Kaiserslautern.svg/langde-330px-Logo_1_FC_Kaiserslautern.svg.png",
|
||||||
|
"karlsruhe": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Karlsruher_SC_Logo_2.svg/langde-330px-Karlsruher_SC_Logo_2.svg.png",
|
||||||
|
"koeln": "https://thumb.wikimedia.org/wikipedia/commons/thumb/0/01/1._FC_Koeln_Logo_2014%E2%80%93.svg/langde-330px-1._FC_Koeln_Logo_2014%E2%80%93.svg.png",
|
||||||
|
"leipzig": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/2019-07-12_Fu%C3%9Fball%3B_Freundschaftsspiel_RB_Leipzig_-_FC_Z%C3%BCrich_1DX_0881_by_Stepro_2.png/330px-2019-07-12_Fu%C3%9Fball%3B_Freundschaftsspiel_RB_Leipzig_-_FC_Z%C3%BCrich_1DX_0881_by_Stepro_2.png",
|
||||||
|
"leverkusen": "https://upload.wikimedia.org/wikipedia/de/thumb/f/f7/Bayer_Leverkusen_Logo.svg/langde-330px-Bayer_Leverkusen_Logo.svg.png",
|
||||||
|
"magdeburg": "https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/1._FC_Magdeburg.svg/langde-330px-1._FC_Magdeburg.svg.png",
|
||||||
|
"mainz": "https://thumb.wikimedia.org/wikipedia/commons/thumb/9/9e/Logo_Mainz_05.svg/langde-330px-Logo_Mainz_05.svg.png",
|
||||||
|
"mannheim": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Svwaldhof.svg/langde-330px-Svwaldhof.svg.png",
|
||||||
|
"muenster": "https://thumb.wikimedia.org/wikipedia/de/thumb/7/7e/SC_Preussen_Muenster_Logo_2018.svg/langde-330px-SC_Preussen_Muenster_Logo_2018.svg.png",
|
||||||
|
"nuernberg": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/1._FC_N%C3%BCrnberg_logo.svg/langde-330px-1._FC_N%C3%BCrnberg_logo.svg.png",
|
||||||
|
"osnabrueck": "https://thumb.wikimedia.org/wikipedia/commons/thumb/4/4e/VfL_Osnabrueck_Logo_2021%E2%80%93.svg/langde-330px-VfL_Osnabrueck_Logo_2021%E2%80%93.svg.png",
|
||||||
|
"paderborn": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/SC_Paderborn_07_Logo_new.svg/langde-330px-SC_Paderborn_07_Logo_new.svg.png",
|
||||||
|
"regensburg": "https://thumb.wikimedia.org/wikipedia/commons/thumb/3/3d/Jahn_Regensburg_logo2014.svg/langde-330px-Jahn_Regensburg_logo2014.svg.png",
|
||||||
|
"saarbruecken": "https://thumb.wikimedia.org/wikipedia/de/thumb/f/ff/1._FC_Saarbr%C3%BCcken.svg/langde-330px-1._FC_Saarbr%C3%BCcken.svg.png",
|
||||||
|
"schalke": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/FC_Schalke_04_Logo.svg/langde-330px-FC_Schalke_04_Logo.svg.png",
|
||||||
|
"schweinfurt": "https://thumb.wikimedia.org/wikipedia/de/thumb/7/7c/1._FC_Schweinfurt_05.svg/langde-330px-1._FC_Schweinfurt_05.svg.png",
|
||||||
|
"st-pauli": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Fc_st_pauli_logo.svg/langde-330px-Fc_st_pauli_logo.svg.png",
|
||||||
|
"stuttgart": "https://thumb.wikimedia.org/wikipedia/commons/thumb/e/eb/VfB_Stuttgart_1893_Logo.svg/langde-330px-VfB_Stuttgart_1893_Logo.svg.png",
|
||||||
|
"stuttgart-ii": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/VfB_Stuttgart_1893_Logo.svg/langde-330px-VfB_Stuttgart_1893_Logo.svg.png",
|
||||||
|
"ulm": "https://thumb.wikimedia.org/wikipedia/commons/thumb/6/6c/SSV_Ulm_1846_Fussball.svg/langde-330px-SSV_Ulm_1846_Fussball.svg.png",
|
||||||
|
"union": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/1._FC_Union_Berlin_Logo.svg/langde-330px-1._FC_Union_Berlin_Logo.svg.png",
|
||||||
|
"verl": "https://thumb.wikimedia.org/wikipedia/commons/thumb/c/ce/SC_Verl_Logo.svg/langde-330px-SC_Verl_Logo.svg.png",
|
||||||
|
"viktoria": "https://thumb.wikimedia.org/wikipedia/commons/thumb/d/dc/FC_Viktoria_K%C3%B6ln_1904_Logo.svg/langde-330px-FC_Viktoria_K%C3%B6ln_1904_Logo.svg.png",
|
||||||
|
"wehen": "https://upload.wikimedia.org/wikipedia/de/e/e0/SV_Wehen_Logo.png",
|
||||||
|
"wolfsburg": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/VfL_Wolfsburg_logo_2026.svg/langde-330px-VfL_Wolfsburg_logo_2026.svg.png",
|
||||||
|
"wuppertal": "https://thumb.wikimedia.org/wikipedia/de/thumb/9/9b/WuppertalerSVLogo.svg/langde-330px-WuppertalerSVLogo.svg.png"
|
||||||
|
}
|
||||||
67
tools/fetch-crests.py
Normal file
67
tools/fetch-crests.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Downloads club crests into the APK's assets at build time.
|
||||||
|
|
||||||
|
The badges are trademarks: they are fetched into a generated, git-ignored
|
||||||
|
folder so the repository stays free of them while the app ships with them
|
||||||
|
and needs no network at runtime.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
OUT = sys.argv[1] if len(sys.argv) > 1 else "app/src/main/assets/crests"
|
||||||
|
URLS = "tools/crest-sources.json"
|
||||||
|
SRC = "app/src/main/java/dev/castarr/tv/data/TeamFilters.kt"
|
||||||
|
SUMMARY = "https://de.wikipedia.org/api/rest_v1/page/summary/"
|
||||||
|
UA = {"User-Agent": "Castarr build script (private use)"}
|
||||||
|
|
||||||
|
os.makedirs(OUT, exist_ok=True)
|
||||||
|
# Image URLs are plain text and safe to commit; the artwork itself is not.
|
||||||
|
sources = {}
|
||||||
|
if os.path.exists(URLS):
|
||||||
|
sources = json.load(open(URLS, encoding="utf-8"))
|
||||||
|
kotlin = open(SRC, encoding="utf-8").read()
|
||||||
|
entries = re.findall(r'club\((.*?)\)\s*,\s*(?://.*)?$', kotlin, re.M | re.S)
|
||||||
|
clubs = []
|
||||||
|
for raw in re.findall(r'club\(\s*"([^"]+)",\s*"[^"]*",\s*"([^"]+)"[^\n]*', kotlin):
|
||||||
|
clubs.append(raw)
|
||||||
|
# an explicit article = "..." wins over the club name
|
||||||
|
overrides = dict(re.findall(r'club\(\s*"([^"]+)"[^\n]*article = "([^"]+)"', kotlin))
|
||||||
|
clubs = [(k, overrides.get(k, n)) for k, n in clubs]
|
||||||
|
|
||||||
|
fetched = skipped = failed = 0
|
||||||
|
for key, full_name in clubs:
|
||||||
|
target = os.path.join(OUT, f"{key}.png")
|
||||||
|
if os.path.exists(target) and os.path.getsize(target) > 0:
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
thumb = sources.get(key)
|
||||||
|
if not thumb:
|
||||||
|
url = SUMMARY + urllib.parse.quote(full_name)
|
||||||
|
with urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=20) as r:
|
||||||
|
thumb = json.load(r).get("thumbnail", {}).get("source")
|
||||||
|
if not thumb:
|
||||||
|
raise ValueError("no thumbnail")
|
||||||
|
sources[key] = thumb.split("?")[0]
|
||||||
|
thumb = sources[key]
|
||||||
|
with urllib.request.urlopen(urllib.request.Request(thumb, headers=UA), timeout=20) as r:
|
||||||
|
data = r.read()
|
||||||
|
with open(target, "wb") as f:
|
||||||
|
f.write(data)
|
||||||
|
fetched += 1
|
||||||
|
except Exception as exc: # noqa: BLE001 - best effort, shield is the fallback
|
||||||
|
print(f" {key}: {exc}", file=sys.stderr)
|
||||||
|
failed += 1
|
||||||
|
# Wikipedia rate-limits bursts; this runs rarely and caches.
|
||||||
|
time.sleep(1.2)
|
||||||
|
|
||||||
|
with open(URLS, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(dict(sorted(sources.items())), f, indent=2, ensure_ascii=False)
|
||||||
|
f.write("\n")
|
||||||
|
|
||||||
|
print(f"crests: {fetched} geladen, {skipped} vorhanden, {failed} fehlgeschlagen")
|
||||||
Reference in New Issue
Block a user