@@ -21,6 +21,10 @@ import com.nuvio.app.core.ui.NuvioScreen
2121import com.nuvio.app.core.ui.NuvioNetworkOfflineCard
2222import com.nuvio.app.core.ui.nuvioSafeBottomPadding
2323import com.nuvio.app.features.addons.AddonRepository
24+ import com.nuvio.app.features.cloud.CloudLibraryContentType
25+ import com.nuvio.app.features.cloud.CloudLibraryRepository
26+ import com.nuvio.app.features.cloud.CloudLibraryUiState
27+ import com.nuvio.app.features.cloud.findPlaybackTargetForProgress
2428import com.nuvio.app.features.details.MetaDetailsRepository
2529import com.nuvio.app.features.details.nextReleasedEpisodeAfter
2630import com.nuvio.app.features.home.components.HomeCatalogRowSection
@@ -109,6 +113,7 @@ fun HomeScreen(
109113 val continueWatchingPreferences by ContinueWatchingPreferencesRepository .uiState.collectAsStateWithLifecycle()
110114 val watchedUiState by WatchedRepository .uiState.collectAsStateWithLifecycle()
111115 val watchProgressUiState by WatchProgressRepository .uiState.collectAsStateWithLifecycle()
116+ val cloudLibraryUiState by CloudLibraryRepository .uiState.collectAsStateWithLifecycle()
112117 val networkStatusUiState by NetworkStatusRepository .uiState.collectAsStateWithLifecycle()
113118 val traktSettingsUiState by remember {
114119 TraktSettingsRepository .ensureLoaded()
@@ -218,6 +223,12 @@ fun HomeScreen(
218223 effectiveWatchProgressEntries.continueWatchingEntries()
219224 }
220225
226+ LaunchedEffect (visibleContinueWatchingEntries) {
227+ if (visibleContinueWatchingEntries.any(WatchProgressEntry ::isCloudLibraryProgressEntry)) {
228+ CloudLibraryRepository .ensureLoaded()
229+ }
230+ }
231+
221232 val latestCompletedAtBySeries = remember(allNextUpSeedEntries) {
222233 allNextUpSeedEntries
223234 .groupBy { entry -> entry.parentMetaId }
@@ -348,6 +359,7 @@ fun HomeScreen(
348359 effectivNextUpItems,
349360 nextUpSuppressedSeriesIds,
350361 continueWatchingPreferences.sortMode,
362+ cloudLibraryUiState,
351363 ) {
352364 buildHomeContinueWatchingItems(
353365 visibleEntries = visibleContinueWatchingEntries,
@@ -356,6 +368,7 @@ fun HomeScreen(
356368 nextUpSuppressedSeriesIds = nextUpSuppressedSeriesIds,
357369 sortMode = continueWatchingPreferences.sortMode,
358370 todayIsoDate = CurrentDateProvider .todayIsoDate(),
371+ cloudLibraryUiState = cloudLibraryUiState,
359372 )
360373 }
361374 val availableManifests = remember(addonsUiState.addons) {
@@ -911,6 +924,7 @@ internal fun buildHomeContinueWatchingItems(
911924 nextUpSuppressedSeriesIds : Set <String >? = null,
912925 sortMode : ContinueWatchingSortMode = ContinueWatchingSortMode .DEFAULT ,
913926 todayIsoDate : String = "",
927+ cloudLibraryUiState : CloudLibraryUiState ? = null,
914928): List <ContinueWatchingItem > {
915929 val suppressedSeriesIds = nextUpSuppressedSeriesIds
916930 ? : visibleEntries
@@ -926,7 +940,9 @@ internal fun buildHomeContinueWatchingItems(
926940 val liveItem = entry.toContinueWatchingItem()
927941 HomeContinueWatchingCandidate (
928942 lastUpdatedEpochMs = entry.lastUpdatedEpochMs,
929- item = liveItem.withFallbackMetadata(cachedInProgressByVideoId[entry.videoId]),
943+ item = liveItem
944+ .withFallbackMetadata(cachedInProgressByVideoId[entry.videoId])
945+ .withCloudLibraryMetadata(cloudLibraryUiState),
930946 isProgressEntry = true ,
931947 )
932948 },
@@ -1166,9 +1182,16 @@ private fun ContinueWatchingItem.withFallbackMetadata(
11661182 fallback : ContinueWatchingItem ? ,
11671183): ContinueWatchingItem {
11681184 if (fallback == null ) return this
1185+ val fallbackTitle = fallback.title
1186+ .takeIf { it.isNotBlank() }
1187+ ?.takeUnless { fallback.hasPlaceholderCloudTitle() }
11691188
11701189 return copy(
1171- title = title.ifBlank { fallback.title },
1190+ title = when {
1191+ title.isBlank() -> fallback.title
1192+ hasPlaceholderCloudTitle() && fallbackTitle != null -> fallbackTitle
1193+ else -> title
1194+ },
11721195 subtitle = subtitle.ifBlank { fallback.subtitle },
11731196 imageUrl = imageUrl ? : fallback.imageUrl,
11741197 logo = logo ? : fallback.logo,
@@ -1180,3 +1203,35 @@ private fun ContinueWatchingItem.withFallbackMetadata(
11801203 released = released ? : fallback.released,
11811204 )
11821205}
1206+
1207+ private fun ContinueWatchingItem.withCloudLibraryMetadata (
1208+ cloudLibraryUiState : CloudLibraryUiState ? ,
1209+ ): ContinueWatchingItem {
1210+ if (! isCloudLibraryContinueWatchingItem() || cloudLibraryUiState == null ) return this
1211+ val target = cloudLibraryUiState.findPlaybackTargetForProgress(
1212+ contentId = parentMetaId,
1213+ videoId = videoId,
1214+ ) ? : return this
1215+ val fileName = target.file.name.trim().takeIf { it.isNotBlank() }
1216+ ? : target.item.name.trim().takeIf { it.isNotBlank() }
1217+ ? : return this
1218+ return copy(
1219+ title = fileName,
1220+ pauseDescription = pauseDescription
1221+ ? : target.item.name.takeIf { itemName -> itemName.isNotBlank() && itemName != fileName },
1222+ )
1223+ }
1224+
1225+ private fun ContinueWatchingItem.hasPlaceholderCloudTitle (): Boolean {
1226+ if (! isCloudLibraryContinueWatchingItem()) return false
1227+ val normalizedTitle = title.trim()
1228+ return normalizedTitle.equals(parentMetaId, ignoreCase = true ) ||
1229+ normalizedTitle.equals(videoId, ignoreCase = true )
1230+ }
1231+
1232+ private fun ContinueWatchingItem.isCloudLibraryContinueWatchingItem (): Boolean =
1233+ parentMetaType.equals(CloudLibraryContentType , ignoreCase = true )
1234+
1235+ private fun WatchProgressEntry.isCloudLibraryProgressEntry (): Boolean =
1236+ contentType.equals(CloudLibraryContentType , ignoreCase = true ) ||
1237+ parentMetaType.equals(CloudLibraryContentType , ignoreCase = true )
0 commit comments