From 494d8e68351605b2886ea37730c86b1e52ba64aa Mon Sep 17 00:00:00 2001 From: alwaysmesmerizingyou Date: Mon, 5 Oct 2026 20:38:56 -0700 Subject: [PATCH] fixed watch history --- .../app/src/main/java/tv/vyla/app/MainActivity.kt | 12 ++++++++++++ .../main/java/tv/vyla/app/data/LibraryManager.kt | 13 +++++++++++++ .../main/java/tv/vyla/app/ui/components/Sidebar.kt | 3 +++ .../java/tv/vyla/app/ui/screens/LibraryScreen.kt | 5 +++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/tv/vyla/app/MainActivity.kt b/android/app/src/main/java/tv/vyla/app/MainActivity.kt index 4c5d2d1..7a77ac9 100644 --- a/android/app/src/main/java/tv/vyla/app/MainActivity.kt +++ b/android/app/src/main/java/tv/vyla/app/MainActivity.kt @@ -48,6 +48,7 @@ class MainActivity : ComponentActivity() { val watchLaterItems by libraryManager.watchLater.collectAsState() val favoriteItems by libraryManager.favorites.collectAsState() + val historyItems by libraryManager.history.collectAsState() val sidebarFocusRequester = remember { FocusRequester() } val contentFocusRequester = remember { FocusRequester() } @@ -64,6 +65,7 @@ class MainActivity : ComponentActivity() { if (playingItem == null) { Sidebar( currentDestination = currentDestination, + hasHistory = historyItems.isNotEmpty(), hasWatchLater = watchLaterItems.isNotEmpty(), hasFavorites = favoriteItems.isNotEmpty(), onNavigate = { dest -> @@ -98,6 +100,7 @@ class MainActivity : ComponentActivity() { mode = currentDestination, onOpenDetail = { item -> activeDetailItem = item }, onPlay = { item -> + libraryManager.addHistory(item) playingItem = item playingEpisode = null }, @@ -118,6 +121,14 @@ class MainActivity : ComponentActivity() { } ) } + NavDestination.HISTORY -> { + LibraryScreen( + title = "Watch History", + items = historyItems, + onOpenDetail = { item -> activeDetailItem = item }, + emptyMessage = "Nothing watched yet. Press play on a title and it shows up here." + ) + } NavDestination.WATCH_LATER -> { LibraryScreen( title = "Watch Later", @@ -147,6 +158,7 @@ class MainActivity : ComponentActivity() { onToggleWatchLater = { libraryManager.toggle("wl", it) }, onToggleFavorite = { libraryManager.toggle("fav", it) }, onPlay = { itm, ep -> + libraryManager.addHistory(itm) playingItem = itm playingEpisode = ep }, diff --git a/android/app/src/main/java/tv/vyla/app/data/LibraryManager.kt b/android/app/src/main/java/tv/vyla/app/data/LibraryManager.kt index 5b89b1d..8515bd9 100644 --- a/android/app/src/main/java/tv/vyla/app/data/LibraryManager.kt +++ b/android/app/src/main/java/tv/vyla/app/data/LibraryManager.kt @@ -30,10 +30,21 @@ class LibraryManager private constructor(context: Context) { private val _favorites = MutableStateFlow>(emptyList()) val favorites: StateFlow> = _favorites.asStateFlow() + private val _history = MutableStateFlow>(emptyList()) + val history: StateFlow> = _history.asStateFlow() + init { load() } + fun addHistory(item: MediaItem) { + val current = _history.value.toMutableList() + current.removeAll { it.id == item.id && it.mediaType == item.mediaType } + current.add(0, item) + _history.value = current.take(100) + save() + } + private fun load() { val raw = prefs.getString("vyla.lib", null) if (raw.isNullOrEmpty()) return @@ -41,6 +52,7 @@ class LibraryManager private constructor(context: Context) { val root = JSONObject(raw) _watchLater.value = parseList(root.optJSONArray("wl")) _favorites.value = parseList(root.optJSONArray("fav")) + _history.value = parseList(root.optJSONArray("hist")) } catch (e: Exception) { e.printStackTrace() } @@ -51,6 +63,7 @@ class LibraryManager private constructor(context: Context) { val root = JSONObject() root.put("wl", serializeList(_watchLater.value)) root.put("fav", serializeList(_favorites.value)) + root.put("hist", serializeList(_history.value)) prefs.edit().putString("vyla.lib", root.toString()).apply() } catch (e: Exception) { e.printStackTrace() diff --git a/android/app/src/main/java/tv/vyla/app/ui/components/Sidebar.kt b/android/app/src/main/java/tv/vyla/app/ui/components/Sidebar.kt index 8499194..c5e8f3f 100644 --- a/android/app/src/main/java/tv/vyla/app/ui/components/Sidebar.kt +++ b/android/app/src/main/java/tv/vyla/app/ui/components/Sidebar.kt @@ -51,6 +51,7 @@ enum class NavDestination(val key: String, val title: String, val icon: ImageVec MOVIES("movie", "Movies", Icons.Default.Movie), TV_SHOWS("tv", "TV Shows", Icons.Default.Tv), ANIME("anime", "Anime", Icons.Default.AutoAwesome), + HISTORY("history", "History", Icons.Default.History), WATCH_LATER("wl", "Watch Later", Icons.Default.Schedule), FAVORITES("fav", "Favorites", Icons.Default.Favorite) } @@ -59,6 +60,7 @@ enum class NavDestination(val key: String, val title: String, val icon: ImageVec @OptIn(ExperimentalComposeUiApi::class) fun Sidebar( currentDestination: NavDestination, + hasHistory: Boolean, hasWatchLater: Boolean, hasFavorites: Boolean, onNavigate: (NavDestination) -> Unit, @@ -148,6 +150,7 @@ fun Sidebar( ) { NavDestination.values().forEach { destination -> val shouldShow = when (destination) { + NavDestination.HISTORY -> hasHistory || currentDestination == NavDestination.HISTORY NavDestination.WATCH_LATER -> hasWatchLater || currentDestination == NavDestination.WATCH_LATER NavDestination.FAVORITES -> hasFavorites || currentDestination == NavDestination.FAVORITES else -> true diff --git a/android/app/src/main/java/tv/vyla/app/ui/screens/LibraryScreen.kt b/android/app/src/main/java/tv/vyla/app/ui/screens/LibraryScreen.kt index df5f0d0..0819087 100644 --- a/android/app/src/main/java/tv/vyla/app/ui/screens/LibraryScreen.kt +++ b/android/app/src/main/java/tv/vyla/app/ui/screens/LibraryScreen.kt @@ -34,7 +34,8 @@ fun LibraryScreen( title: String, items: List, onOpenDetail: (MediaItem) -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, + emptyMessage: String = "Nothing here yet. Open a title, press the ⋮ button and add it." ) { var ambientUrl by remember(items) { mutableStateOf(items.firstOrNull()?.ambientBackdropUrl) } Box(modifier = modifier.fillMaxSize().background(VylaBackground)) { @@ -86,7 +87,7 @@ fun LibraryScreen( contentAlignment = androidx.compose.ui.Alignment.TopStart ) { Text( - text = "Nothing here yet. Open a title, press the ⋮ button and add it.", + text = emptyMessage, color = VylaTextMuted, fontSize = 17.sp )