mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-05 21:48:31 +01:00
Compare commits
1 Commits
fix/androi
...
renovate/s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
197dfb803d |
6
bun.lock
6
bun.lock
@@ -93,7 +93,7 @@
|
|||||||
"react-native-volume-manager": "^2.0.8",
|
"react-native-volume-manager": "^2.0.8",
|
||||||
"react-native-web": "^0.21.0",
|
"react-native-web": "^0.21.0",
|
||||||
"react-native-worklets": "0.8.3",
|
"react-native-worklets": "0.8.3",
|
||||||
"sonner-native": "0.21.2",
|
"sonner-native": "0.26.0",
|
||||||
"tailwindcss": "3.3.2",
|
"tailwindcss": "3.3.2",
|
||||||
"use-debounce": "^10.0.4",
|
"use-debounce": "^10.0.4",
|
||||||
"zod": "4.4.3",
|
"zod": "4.4.3",
|
||||||
@@ -1599,7 +1599,7 @@
|
|||||||
|
|
||||||
"react-native-text-ticker": ["react-native-text-ticker@1.15.0", "", {}, "sha512-d/uK+PIOhsYMy1r8h825iq/nADiHsabz3WMbRJSnkpQYn+K9aykUAXRRhu8ZbTAzk4CgnUWajJEFxS5ZDygsdg=="],
|
"react-native-text-ticker": ["react-native-text-ticker@1.15.0", "", {}, "sha512-d/uK+PIOhsYMy1r8h825iq/nADiHsabz3WMbRJSnkpQYn+K9aykUAXRRhu8ZbTAzk4CgnUWajJEFxS5ZDygsdg=="],
|
||||||
|
|
||||||
"react-native-track-player": ["react-native-track-player@github:lovegaoshi/react-native-track-player#33a3ecd", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-windows": "*", "shaka-player": "^4.7.9" }, "optionalPeers": ["react-native-windows", "shaka-player"] }, "lovegaoshi-react-native-track-player-33a3ecd"],
|
"react-native-track-player": ["react-native-track-player@github:lovegaoshi/react-native-track-player#33a3ecd", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-windows": "*", "shaka-player": "^4.7.9" }, "optionalPeers": ["react-native-windows", "shaka-player"] }, "lovegaoshi-react-native-track-player-33a3ecd", "sha512-vfkld2jUj7EPkAjIc/Vbx4Q4MtOOLmYtCYCE2dWJsyLnPqgj1f0xVzBxbeVP7dfT+eSh4KIXfdxESXaHgrXIlw=="],
|
||||||
|
|
||||||
"react-native-udp": ["react-native-udp@4.1.7", "", { "dependencies": { "buffer": "^5.6.0", "events": "^3.1.0" } }, "sha512-NUE3zewu61NCdSsLlj+l0ad6qojcVEZPT4hVG/x6DU9U4iCzwtfZSASh9vm7teAcVzLkdD+cO3411LHshAi/wA=="],
|
"react-native-udp": ["react-native-udp@4.1.7", "", { "dependencies": { "buffer": "^5.6.0", "events": "^3.1.0" } }, "sha512-NUE3zewu61NCdSsLlj+l0ad6qojcVEZPT4hVG/x6DU9U4iCzwtfZSASh9vm7teAcVzLkdD+cO3411LHshAi/wA=="],
|
||||||
|
|
||||||
@@ -1723,7 +1723,7 @@
|
|||||||
|
|
||||||
"slugify": ["slugify@1.6.9", "", {}, "sha512-vZ7rfeehZui7wQs438JXBckYLkIIdfHOXsaVEUMyS5fHo1483l1bMdo0EDSWYclY0yZKFOipDy4KHuKs6ssvdg=="],
|
"slugify": ["slugify@1.6.9", "", {}, "sha512-vZ7rfeehZui7wQs438JXBckYLkIIdfHOXsaVEUMyS5fHo1483l1bMdo0EDSWYclY0yZKFOipDy4KHuKs6ssvdg=="],
|
||||||
|
|
||||||
"sonner-native": ["sonner-native@0.21.2", "", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-gesture-handler": ">=2.16.1", "react-native-reanimated": ">=3.10.1", "react-native-safe-area-context": ">=4.10.5", "react-native-screens": ">=3.31.1", "react-native-svg": ">=15.6.0" } }, "sha512-LnGPmfgzrNIwcc+FvcLJqx8aH1dEHePRzvNR8aIR4kl9spySRkXK160GmQIazjfm6mSMlPqZwRa5eycvrzg/eQ=="],
|
"sonner-native": ["sonner-native@0.26.0", "", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-gesture-handler": "^2.28.0", "react-native-reanimated": "^4.1.1", "react-native-safe-area-context": "^5.6.0", "react-native-screens": "^4.16.0", "react-native-svg": "^15.12.1", "react-native-worklets": "^0.6.1 || ^0.7.0 || ^0.8.0" } }, "sha512-73QJZVTTvWn+0winDmr6VpAGdWj2qJcznSmJabXZ8fRS1Yr07t0b7nRS5ExrsBUx+ZvHP0oqVBbp5Rqbc+9o4g=="],
|
||||||
|
|
||||||
"source-map": ["source-map@0.5.7", "", {}, "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ=="],
|
"source-map": ["source-map@0.5.7", "", {}, "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ=="],
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
|||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Platform, ScrollView, TextInput, View } from "react-native";
|
import { ScrollView, View } from "react-native";
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
import { Text } from "@/components/common/Text";
|
import { Text } from "@/components/common/Text";
|
||||||
import { TVDiscover } from "@/components/jellyseerr/discover/TVDiscover";
|
import { TVDiscover } from "@/components/jellyseerr/discover/TVDiscover";
|
||||||
@@ -231,48 +231,26 @@ export const TVSearchPage: React.FC<TVSearchPageProps> = ({
|
|||||||
paddingTop: insets.top + TOP_PADDING,
|
paddingTop: insets.top + TOP_PADDING,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Search bar: native tvOS SwiftUI `.searchable` on Apple TV, standard
|
{/* Native tvOS search field (SwiftUI `.searchable`, our `tv-search`
|
||||||
TextInput fallback on Android TV (the native module is Apple-only). */}
|
module). It renders the native search bar + grid keyboard and
|
||||||
{Platform.OS === "ios" ? (
|
forwards typed text into the existing query pipeline via setSearch;
|
||||||
|
our own results grid renders below. */}
|
||||||
|
{/* No horizontal margin here: the native tvOS search bar centers itself
|
||||||
|
and renders a trailing "Hold to Dictate in <Language>" hint. Extra
|
||||||
|
margins squeeze the bar's width and clip that trailing hint, so let
|
||||||
|
the native view span the full width and own its own insets. */}
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
marginBottom: 24,
|
marginBottom: 24,
|
||||||
height: SEARCH_AREA_HEIGHT,
|
height: SEARCH_AREA_HEIGHT,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* No horizontal margin here: the native tvOS search bar centers
|
|
||||||
itself and renders a trailing "Hold to Dictate" hint. */}
|
|
||||||
<TvSearchView
|
<TvSearchView
|
||||||
style={{ width: "100%", height: "100%" }}
|
style={{ width: "100%", height: "100%" }}
|
||||||
placeholder={t("search.search")}
|
placeholder={t("search.search")}
|
||||||
onChangeText={(e) => setSearch(e.nativeEvent.text)}
|
onChangeText={(e) => setSearch(e.nativeEvent.text)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
) : (
|
|
||||||
<View
|
|
||||||
style={{
|
|
||||||
marginHorizontal: HORIZONTAL_PADDING,
|
|
||||||
marginBottom: 24,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextInput
|
|
||||||
style={{
|
|
||||||
height: 56,
|
|
||||||
width: "100%",
|
|
||||||
backgroundColor: "#262626",
|
|
||||||
borderRadius: 12,
|
|
||||||
paddingHorizontal: 20,
|
|
||||||
fontSize: 28,
|
|
||||||
color: "#fff",
|
|
||||||
}}
|
|
||||||
placeholder={t("search.search")}
|
|
||||||
placeholderTextColor='rgba(255,255,255,0.4)'
|
|
||||||
onChangeText={setSearch}
|
|
||||||
defaultValue=''
|
|
||||||
autoFocus={false}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
|
|
||||||
<application>
|
<application>
|
||||||
<receiver android:name=".TvRecommendationsReceiver" android:exported="true">
|
<receiver
|
||||||
|
android:name=".TvRecommendationsReceiver"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.media.tv.action.INITIALIZE_PROGRAMS" />
|
<action android:name="android.media.tv.action.INITIALIZE_PROGRAMS" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.media.tv.action.PREVIEW_PROGRAM_BROWSABLE_DISABLED" />
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -61,61 +61,31 @@ internal object TvRecommendationsPublisher {
|
|||||||
|
|
||||||
fun clear(context: Context): Boolean {
|
fun clear(context: Context): Boolean {
|
||||||
val prefs = preferences(context)
|
val prefs = preferences(context)
|
||||||
|
val channelId = prefs.getLong(KEY_CHANNEL_ID, -1L)
|
||||||
|
val programIds = prefs.getString(KEY_PROGRAM_IDS, null)?.let(::JSONObject)
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|
||||||
// KEY_PROGRAM_IDS is now { channelId: "{ providerId: programId }" }
|
if (programIds != null) {
|
||||||
val allProgramIds = prefs.getString(KEY_PROGRAM_IDS, null)?.let(::JSONObject)
|
|
||||||
if (allProgramIds != null) {
|
|
||||||
var deletedPrograms = 0
|
var deletedPrograms = 0
|
||||||
val channelKeys = allProgramIds.keys()
|
|
||||||
while (channelKeys.hasNext()) {
|
|
||||||
val channelIdStr = channelKeys.next()
|
|
||||||
val programIdsJson = allProgramIds.optString(channelIdStr)
|
|
||||||
if (programIdsJson.isBlank()) continue
|
|
||||||
|
|
||||||
try {
|
|
||||||
val programIds = JSONObject(programIdsJson)
|
|
||||||
val keys = programIds.keys()
|
val keys = programIds.keys()
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
val providerId = keys.next()
|
val key = keys.next()
|
||||||
val programId = programIds.optLong(providerId, -1L)
|
val programId = programIds.optLong(key, -1L)
|
||||||
if (programId > 0L) {
|
if (programId > 0L) {
|
||||||
deletePreviewProgram(contentResolver, programId)
|
contentResolver.delete(
|
||||||
|
TvContractCompat.buildPreviewProgramUri(programId),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
)
|
||||||
deletedPrograms += 1
|
deletedPrograms += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.w(TAG, "clear(): failed to parse programIds for channel $channelIdStr", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify the channel
|
|
||||||
val channelId = channelIdStr.toLongOrNull() ?: -1L
|
|
||||||
if (channelId > 0L) {
|
|
||||||
try {
|
|
||||||
contentResolver.notifyChange(TvContractCompat.buildChannelUri(channelId), null)
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "clear(): lost provider permission, cannot notify channel $channelId", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove per-channel pref
|
|
||||||
prefs.edit().remove("programIds_$channelIdStr").apply()
|
|
||||||
}
|
|
||||||
Log.d(TAG, "clear(): deleted $deletedPrograms preview program(s)")
|
Log.d(TAG, "clear(): deleted $deletedPrograms preview program(s)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also handle legacy format (flat { providerId: programId }) for migration
|
if (channelId > 0L) {
|
||||||
val legacyProgramIds = prefs.getString("legacy_" + KEY_PROGRAM_IDS, null)?.let(::JSONObject)
|
contentResolver.notifyChange(TvContractCompat.buildChannelUri(channelId), null)
|
||||||
if (legacyProgramIds != null) {
|
Log.d(TAG, "clear(): notified channel $channelId")
|
||||||
val keys = legacyProgramIds.keys()
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
val key = keys.next()
|
|
||||||
val programId = legacyProgramIds.optLong(key, -1L)
|
|
||||||
if (programId > 0L) {
|
|
||||||
deletePreviewProgram(contentResolver, programId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefs.edit().remove("legacy_" + KEY_PROGRAM_IDS).apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
@@ -126,93 +96,27 @@ internal object TvRecommendationsPublisher {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a single preview program from the TvProvider.
|
|
||||||
* Called by clear(), synchronize() (stale programs), and TvRecommendationsReceiver (user removed).
|
|
||||||
*/
|
|
||||||
fun deletePreviewProgram(context: Context, programId: Long) {
|
|
||||||
try {
|
|
||||||
context.contentResolver.delete(
|
|
||||||
TvContractCompat.buildPreviewProgramUri(programId),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
Log.d(TAG, "deletePreviewProgram(): deleted programId=$programId")
|
|
||||||
|
|
||||||
// Also remove from stored programIds prefs
|
|
||||||
removeProgramFromPrefs(context, programId)
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "deletePreviewProgram(): lost provider permission for programId=$programId", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deletePreviewProgram(contentResolver: android.content.ContentResolver, programId: Long) {
|
|
||||||
try {
|
|
||||||
contentResolver.delete(
|
|
||||||
TvContractCompat.buildPreviewProgramUri(programId),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "deletePreviewProgram(): lost provider permission for programId=$programId", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeProgramFromPrefs(context: Context, programId: Long) {
|
|
||||||
val prefs = preferences(context)
|
|
||||||
val programIdsJson = prefs.getString(KEY_PROGRAM_IDS, null) ?: return
|
|
||||||
try {
|
|
||||||
val programIds = JSONObject(programIdsJson)
|
|
||||||
val keys = programIds.keys()
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
val key = keys.next()
|
|
||||||
if (programIds.optLong(key, -1L) == programId) {
|
|
||||||
programIds.remove(key)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefs.edit().putString(KEY_PROGRAM_IDS, programIds.toString()).apply()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.w(TAG, "removeProgramFromPrefs(): failed to update prefs for programId=$programId", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun synchronize(context: Context, payload: JSONObject): Boolean {
|
private fun synchronize(context: Context, payload: JSONObject): Boolean {
|
||||||
val sections = payload.optJSONArray("sections") ?: JSONArray()
|
val sections = payload.optJSONArray("sections") ?: JSONArray()
|
||||||
if (sections.length() == 0) {
|
val firstSection = if (sections.length() > 0) sections.optJSONObject(0) else null
|
||||||
Log.w(TAG, "synchronize(): no sections in payload")
|
val sectionTitle = firstSection?.optString("title")?.takeIf { it.isNotBlank() } ?: DEFAULT_CHANNEL_NAME
|
||||||
return false
|
val items = firstSection?.optJSONArray("items") ?: JSONArray()
|
||||||
}
|
|
||||||
|
|
||||||
val prefs = preferences(context)
|
|
||||||
val allNextProgramIds = JSONObject()
|
|
||||||
var totalActive = 0
|
|
||||||
var totalDeleted = 0
|
|
||||||
|
|
||||||
for (sectionIndex in 0 until sections.length()) {
|
|
||||||
val section = sections.optJSONObject(sectionIndex) ?: continue
|
|
||||||
val sectionTitle = section.optString("title")?.takeIf { it.isNotBlank() } ?: DEFAULT_CHANNEL_NAME
|
|
||||||
val items = section.optJSONArray("items") ?: JSONArray()
|
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
TAG,
|
TAG,
|
||||||
"synchronize(): section \"$sectionTitle\" ($sectionIndex/${sections.length()}) with ${items.length()} item(s)"
|
"synchronize(): using section \"$sectionTitle\" with ${items.length()} item(s)"
|
||||||
)
|
)
|
||||||
|
|
||||||
val channelId = getOrCreateChannel(context, sectionTitle)
|
val channelId = getOrCreateChannel(context, sectionTitle)
|
||||||
if (channelId <= 0L) {
|
if (channelId <= 0L) {
|
||||||
Log.w(TAG, "synchronize(): failed to get or create channel for \"$sectionTitle\"")
|
Log.w(TAG, "synchronize(): failed to get or create preview channel")
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per Android docs: check channel.isBrowsable() and request if needed.
|
Log.d(TAG, "synchronize(): publishing into channelId=$channelId")
|
||||||
if (!isChannelBrowsable(context, channelId)) {
|
|
||||||
Log.d(TAG, "synchronize(): channel $channelId not browsable, requesting browsable")
|
|
||||||
TvContractCompat.requestChannelBrowsable(context, channelId)
|
|
||||||
}
|
|
||||||
|
|
||||||
val prefKey = "programIds_$channelId"
|
val previousProgramIds = preferences(context)
|
||||||
val previousProgramIds = prefs.getString(prefKey, null)
|
.getString(KEY_PROGRAM_IDS, null)
|
||||||
?.let(::JSONObject)
|
?.let(::JSONObject)
|
||||||
?: JSONObject()
|
?: JSONObject()
|
||||||
val nextProgramIds = JSONObject()
|
val nextProgramIds = JSONObject()
|
||||||
@@ -246,98 +150,44 @@ internal object TvRecommendationsPublisher {
|
|||||||
|
|
||||||
val programId = previousProgramIds.optLong(providerId, -1L)
|
val programId = previousProgramIds.optLong(providerId, -1L)
|
||||||
if (programId > 0L) {
|
if (programId > 0L) {
|
||||||
deletePreviewProgram(context, programId)
|
context.contentResolver.delete(
|
||||||
|
TvContractCompat.buildPreviewProgramUri(programId),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
)
|
||||||
deletedPrograms += 1
|
deletedPrograms += 1
|
||||||
Log.d(TAG, "synchronize(): deleted stale programId=$programId for item=$providerId")
|
Log.d(TAG, "synchronize(): deleted stale programId=$programId for item=$providerId")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allNextProgramIds.put(channelId.toString(), nextProgramIds.toString())
|
preferences(context)
|
||||||
prefs.edit().putString(prefKey, nextProgramIds.toString()).apply()
|
.edit()
|
||||||
totalActive += activeProviderIds.size
|
.putLong(KEY_CHANNEL_ID, channelId)
|
||||||
totalDeleted += deletedPrograms
|
.putString(KEY_PROGRAM_IDS, nextProgramIds.toString())
|
||||||
|
.apply()
|
||||||
|
|
||||||
logProviderState(context, channelId)
|
logProviderState(context, channelId)
|
||||||
}
|
|
||||||
|
|
||||||
// Store all channel program IDs for clear() to use
|
|
||||||
prefs.edit().putString(KEY_PROGRAM_IDS, allNextProgramIds.toString()).apply()
|
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
TAG,
|
TAG,
|
||||||
"synchronize(): completed across ${sections.length()} section(s), $totalActive active program(s), deleted $totalDeleted stale program(s)"
|
"synchronize(): completed with ${activeProviderIds.size} active program(s), deleted $deletedPrograms stale program(s)"
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Query provider to check if a channel is browsable.
|
|
||||||
* Per Android docs: "check channel.isBrowsable() before updating programs."
|
|
||||||
*/
|
|
||||||
private fun isChannelBrowsable(context: Context, channelId: Long): Boolean {
|
|
||||||
return try {
|
|
||||||
context.contentResolver.query(
|
|
||||||
TvContractCompat.buildChannelUri(channelId),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)?.use { cursor ->
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
val browsableIndex = cursor.getColumnIndex(TvContractCompat.Channels.COLUMN_BROWSABLE)
|
|
||||||
if (browsableIndex >= 0) cursor.getInt(browsableIndex) == 1 else true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} ?: false
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "isChannelBrowsable(): lost provider permission for channelId=$channelId", e)
|
|
||||||
true // Assume browsable if we can't check, to avoid blocking updates
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query provider to verify a channel actually exists.
|
|
||||||
* Prevents the channel-delete-recreate bug: if update() returns 0 rows
|
|
||||||
* we must first check whether the channel was deleted by the system
|
|
||||||
* or if the update simply failed for another reason.
|
|
||||||
*/
|
|
||||||
private fun channelExistsInProvider(context: Context, channelId: Long): Boolean {
|
|
||||||
return try {
|
|
||||||
context.contentResolver.query(
|
|
||||||
TvContractCompat.buildChannelUri(channelId),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)?.use { cursor ->
|
|
||||||
cursor.moveToFirst()
|
|
||||||
} ?: false
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "channelExistsInProvider(): lost provider permission for channelId=$channelId", e)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getOrCreateChannel(context: Context, displayName: String): Long {
|
private fun getOrCreateChannel(context: Context, displayName: String): Long {
|
||||||
val prefs = preferences(context)
|
val prefs = preferences(context)
|
||||||
val existingChannelId = prefs.getLong(KEY_CHANNEL_ID, -1L)
|
val existingChannelId = prefs.getLong(KEY_CHANNEL_ID, -1L)
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|
||||||
if (existingChannelId > 0L) {
|
if (existingChannelId > 0L) {
|
||||||
// Query provider first to verify channel actually exists (prevents recreate bug)
|
|
||||||
val exists = channelExistsInProvider(context, existingChannelId)
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
// Channel exists — update it in place, never recreate
|
|
||||||
val updated = Channel.Builder()
|
val updated = Channel.Builder()
|
||||||
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
|
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
|
||||||
.setDisplayName(displayName)
|
.setDisplayName(displayName)
|
||||||
.setAppLinkIntentUri(buildIntentUri(context, "streamyfin://"))
|
.setAppLinkIntentUri(buildIntentUri(context, "streamyfin://"))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
try {
|
|
||||||
val updatedRows = contentResolver.update(
|
val updatedRows = contentResolver.update(
|
||||||
TvContractCompat.buildChannelUri(existingChannelId),
|
TvContractCompat.buildChannelUri(existingChannelId),
|
||||||
updated.toContentValues(),
|
updated.toContentValues(),
|
||||||
@@ -352,36 +202,20 @@ internal object TvRecommendationsPublisher {
|
|||||||
return existingChannelId
|
return existingChannelId
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update returned 0 rows but channel exists — log and return existing ID, don't recreate
|
Log.w(TAG, "getOrCreateChannel(): stored channelId=$existingChannelId was stale, recreating")
|
||||||
Log.e(TAG, "getOrCreateChannel(): update returned 0 for existing channelId=$existingChannelId but channel exists — not recreating")
|
|
||||||
return existingChannelId
|
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "getOrCreateChannel(): lost provider permission updating channelId=$existingChannelId", e)
|
|
||||||
return existingChannelId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Channel truly doesn't exist in provider — recreate
|
|
||||||
Log.w(TAG, "getOrCreateChannel(): channelId=$existingChannelId not in provider, recreating")
|
|
||||||
prefs.edit().remove(KEY_CHANNEL_ID).apply()
|
prefs.edit().remove(KEY_CHANNEL_ID).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new channel
|
|
||||||
val channel = Channel.Builder()
|
val channel = Channel.Builder()
|
||||||
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
|
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
|
||||||
.setDisplayName(displayName)
|
.setDisplayName(displayName)
|
||||||
.setAppLinkIntentUri(buildIntentUri(context, "streamyfin://"))
|
.setAppLinkIntentUri(buildIntentUri(context, "streamyfin://"))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val channelUri = try {
|
val channelUri = contentResolver.insert(
|
||||||
contentResolver.insert(
|
|
||||||
TvContractCompat.Channels.CONTENT_URI,
|
TvContractCompat.Channels.CONTENT_URI,
|
||||||
channel.toContentValues()
|
channel.toContentValues()
|
||||||
)
|
) ?: return -1L
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.e(TAG, "getOrCreateChannel(): lost provider permission, cannot create channel", e)
|
|
||||||
null
|
|
||||||
} ?: return -1L
|
|
||||||
|
|
||||||
val channelId = ContentUris.parseId(channelUri)
|
val channelId = ContentUris.parseId(channelUri)
|
||||||
TvContractCompat.requestChannelBrowsable(context, channelId)
|
TvContractCompat.requestChannelBrowsable(context, channelId)
|
||||||
@@ -415,19 +249,17 @@ internal object TvRecommendationsPublisher {
|
|||||||
builder.setDescription(it)
|
builder.setDescription(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per Android docs: use unique URIs for all images to avoid stale cache
|
|
||||||
imageUrl.takeIf { it.isNotBlank() }?.let {
|
imageUrl.takeIf { it.isNotBlank() }?.let {
|
||||||
val uniqueImageUrl = appendCacheBuster(it)
|
val imageUri = Uri.parse(it)
|
||||||
val imageUri = Uri.parse(uniqueImageUrl)
|
|
||||||
builder.setPosterArtUri(imageUri)
|
builder.setPosterArtUri(imageUri)
|
||||||
builder.setThumbnailUri(imageUri)
|
builder.setThumbnailUri(imageUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val contentValues = builder.build().toContentValues()
|
val contentValues = builder.build().toContentValues()
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|
||||||
if (previousProgramId > 0L) {
|
if (previousProgramId > 0L) {
|
||||||
try {
|
|
||||||
val updatedRows = contentResolver.update(
|
val updatedRows = contentResolver.update(
|
||||||
TvContractCompat.buildPreviewProgramUri(previousProgramId),
|
TvContractCompat.buildPreviewProgramUri(previousProgramId),
|
||||||
contentValues,
|
contentValues,
|
||||||
@@ -441,36 +273,18 @@ internal object TvRecommendationsPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.w(TAG, "upsertPreviewProgram(): existing programId=$previousProgramId was stale, inserting new row")
|
Log.w(TAG, "upsertPreviewProgram(): existing programId=$previousProgramId was stale, inserting new row")
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "upsertPreviewProgram(): lost provider permission for programId=$previousProgramId", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val insertedUri = try {
|
val insertedUri = contentResolver.insert(
|
||||||
contentResolver.insert(
|
|
||||||
TvContractCompat.PreviewPrograms.CONTENT_URI,
|
TvContractCompat.PreviewPrograms.CONTENT_URI,
|
||||||
contentValues
|
contentValues
|
||||||
)
|
) ?: return -1L
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "upsertPreviewProgram(): lost provider permission, cannot insert program", e)
|
|
||||||
null
|
|
||||||
} ?: return -1L
|
|
||||||
|
|
||||||
val programId = ContentUris.parseId(insertedUri)
|
val programId = ContentUris.parseId(insertedUri)
|
||||||
Log.d(TAG, "upsertPreviewProgram(): inserted new programId=$programId")
|
Log.d(TAG, "upsertPreviewProgram(): inserted new programId=$programId")
|
||||||
return programId
|
return programId
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a cache-busting parameter to ensure unique URIs when images change.
|
|
||||||
* Per Android docs: "Use unique Uris for all images... the old image will
|
|
||||||
* continue to appear if you don't change the Uri."
|
|
||||||
*/
|
|
||||||
private fun appendCacheBuster(imageUrl: String): String {
|
|
||||||
val separator = if (imageUrl.contains("?")) "&" else "?"
|
|
||||||
return "$imageUrl${separator}_t=${System.currentTimeMillis()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildIntentUri(context: Context, deepLink: String): Uri {
|
private fun buildIntentUri(context: Context, deepLink: String): Uri {
|
||||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
data = Uri.parse(deepLink)
|
data = Uri.parse(deepLink)
|
||||||
@@ -492,7 +306,6 @@ internal object TvRecommendationsPublisher {
|
|||||||
|
|
||||||
private fun storeChannelLogo(context: Context, channelId: Long) {
|
private fun storeChannelLogo(context: Context, channelId: Long) {
|
||||||
val bitmap = applicationIconBitmap(context) ?: return
|
val bitmap = applicationIconBitmap(context) ?: return
|
||||||
try {
|
|
||||||
val outputStream = context.contentResolver.openOutputStream(
|
val outputStream = context.contentResolver.openOutputStream(
|
||||||
TvContractCompat.buildChannelLogoUri(channelId)
|
TvContractCompat.buildChannelLogoUri(channelId)
|
||||||
) ?: return
|
) ?: return
|
||||||
@@ -501,9 +314,6 @@ internal object TvRecommendationsPublisher {
|
|||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
|
||||||
stream.flush()
|
stream.flush()
|
||||||
}
|
}
|
||||||
} catch (e: SecurityException) {
|
|
||||||
Log.w(TAG, "storeChannelLogo(): lost provider permission for channelId=$channelId", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applicationIconBitmap(context: Context): Bitmap? {
|
private fun applicationIconBitmap(context: Context): Bitmap? {
|
||||||
@@ -531,14 +341,9 @@ internal object TvRecommendationsPublisher {
|
|||||||
return bitmap
|
return bitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChannelId(context: Context): Long {
|
|
||||||
return preferences(context).getLong(KEY_CHANNEL_ID, -1L)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun preferences(context: Context): SharedPreferences {
|
private fun preferences(context: Context): SharedPreferences {
|
||||||
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logProviderState(context: Context, channelId: Long) {
|
private fun logProviderState(context: Context, channelId: Long) {
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|
||||||
@@ -567,8 +372,8 @@ internal object TvRecommendationsPublisher {
|
|||||||
Log.w(TAG, "logProviderState(): channelId=$channelId exists=false")
|
Log.w(TAG, "logProviderState(): channelId=$channelId exists=false")
|
||||||
}
|
}
|
||||||
} ?: Log.w(TAG, "logProviderState(): channel query returned null for channelId=$channelId")
|
} ?: Log.w(TAG, "logProviderState(): channel query returned null for channelId=$channelId")
|
||||||
} catch (error: SecurityException) {
|
} catch (error: Exception) {
|
||||||
Log.w(TAG, "logProviderState(): lost provider permission for channelId=$channelId", error)
|
Log.w(TAG, "logProviderState(): failed to query channelId=$channelId", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
import { requireNativeView } from "expo";
|
import { requireNativeView } from "expo";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import type { View } from "react-native";
|
import type { View } from "react-native";
|
||||||
import { Platform } from "react-native";
|
|
||||||
|
|
||||||
import type { TvSearchViewProps } from "./TvSearchView.types";
|
import type { TvSearchViewProps } from "./TvSearchView.types";
|
||||||
|
|
||||||
// The native TvSearchModule is Apple-only (tvOS SwiftUI `.searchable`).
|
|
||||||
// On Android the component is never rendered, but we must avoid calling
|
|
||||||
// `requireNativeView` at module-scope because it would crash on import.
|
|
||||||
const NativeView: React.ComponentType<
|
const NativeView: React.ComponentType<
|
||||||
TvSearchViewProps & React.RefAttributes<View>
|
TvSearchViewProps & React.RefAttributes<View>
|
||||||
> =
|
> = requireNativeView("TvSearchModule");
|
||||||
Platform.OS === "ios"
|
|
||||||
? requireNativeView("TvSearchModule")
|
|
||||||
: ((() => null) as any);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards its ref to the underlying native view so it can be used as a
|
* Forwards its ref to the underlying native view so it can be used as a
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
"react-native-volume-manager": "^2.0.8",
|
"react-native-volume-manager": "^2.0.8",
|
||||||
"react-native-web": "^0.21.0",
|
"react-native-web": "^0.21.0",
|
||||||
"react-native-worklets": "0.8.3",
|
"react-native-worklets": "0.8.3",
|
||||||
"sonner-native": "0.21.2",
|
"sonner-native": "0.26.0",
|
||||||
"tailwindcss": "3.3.2",
|
"tailwindcss": "3.3.2",
|
||||||
"use-debounce": "^10.0.4",
|
"use-debounce": "^10.0.4",
|
||||||
"zod": "4.4.3"
|
"zod": "4.4.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user