fix: implement catalog resolution logic for folders

This commit is contained in:
tapframe 2026-04-29 23:48:11 +05:30
parent 2771feab57
commit d031f22012
3 changed files with 50 additions and 14 deletions

View file

@ -0,0 +1,43 @@
package com.nuvio.app.features.collection
import com.nuvio.app.features.addons.AddonCatalog
import com.nuvio.app.features.addons.ManagedAddon
internal data class ResolvedCollectionCatalog(
val addon: ManagedAddon,
val catalog: AddonCatalog,
)
internal fun List<ManagedAddon>.findCollectionCatalog(
source: CollectionCatalogSource,
): ResolvedCollectionCatalog? {
val declaredAddon = firstOrNull { it.manifest?.id == source.addonId }
val declaredCatalog = declaredAddon?.manifest?.catalogs?.findSourceCatalog(source)
if (declaredAddon != null && declaredCatalog != null) {
return ResolvedCollectionCatalog(addon = declaredAddon, catalog = declaredCatalog)
}
return firstNotNullOfOrNull { addon ->
val catalog = addon.manifest?.catalogs?.find {
it.id == source.catalogId && it.type == source.type
} ?: return@firstNotNullOfOrNull null
ResolvedCollectionCatalog(addon = addon, catalog = catalog)
}
}
internal fun List<AvailableCatalog>.findAvailableCatalog(
source: CollectionCatalogSource,
): AvailableCatalog? {
val declaredCatalogs = filter { it.addonId == source.addonId }
return declaredCatalogs.findSourceCatalog(source)
?: firstOrNull { it.catalogId == source.catalogId && it.type == source.type }
}
private fun List<AddonCatalog>.findSourceCatalog(source: CollectionCatalogSource): AddonCatalog? =
find { it.id == source.catalogId && it.type == source.type }
?: find { it.id == source.catalogId.substringBefore(",") && it.type == source.type }
private fun List<AvailableCatalog>.findSourceCatalog(source: CollectionCatalogSource): AvailableCatalog? =
find { it.catalogId == source.catalogId && it.type == source.type }
?: find { it.catalogId == source.catalogId.substringBefore(",") && it.type == source.type }

View file

@ -111,9 +111,7 @@ fun CollectionEditorScreen(
val genrePickerSource = genrePickerIndex?.let { editingFolder.resolvedSources.getOrNull(it) } val genrePickerSource = genrePickerIndex?.let { editingFolder.resolvedSources.getOrNull(it) }
val genrePickerCatalogSource = genrePickerSource?.addonCatalogSource() val genrePickerCatalogSource = genrePickerSource?.addonCatalogSource()
val genrePickerCatalog = genrePickerCatalogSource?.let { source -> val genrePickerCatalog = genrePickerCatalogSource?.let { source ->
state.availableCatalogs.find { state.availableCatalogs.findAvailableCatalog(source)
it.addonId == source.addonId && it.type == source.type && it.catalogId == source.catalogId
}
} }
FolderEditorPage( FolderEditorPage(
@ -757,11 +755,7 @@ private fun FolderEditorPage(
} else if (addonSource != null) { } else if (addonSource != null) {
FolderCatalogSourceCard( FolderCatalogSourceCard(
source = addonSource, source = addonSource,
matchingCatalog = state.availableCatalogs.find { matchingCatalog = state.availableCatalogs.findAvailableCatalog(addonSource),
it.addonId == addonSource.addonId &&
it.type == addonSource.type &&
it.catalogId == addonSource.catalogId
},
onRemove = { CollectionEditorRepository.removeCatalogSource(index) }, onRemove = { CollectionEditorRepository.removeCatalogSource(index) },
onOpenGenrePicker = { CollectionEditorRepository.showGenrePicker(index) }, onOpenGenrePicker = { CollectionEditorRepository.showGenrePicker(index) },
) )

View file

@ -150,10 +150,9 @@ object FolderDetailRepository {
) )
} else { } else {
val catalogSource = source.addonCatalogSource() ?: return@forEach val catalogSource = source.addonCatalogSource() ?: return@forEach
val addon = addons.find { it.manifest?.id == catalogSource.addonId } val resolvedCatalog = addons.findCollectionCatalog(catalogSource)
val catalog = addon?.manifest?.catalogs?.find { val addon = resolvedCatalog?.addon
it.id == catalogSource.catalogId && it.type == catalogSource.type val catalog = resolvedCatalog?.catalog
}
val label = catalog?.name ?: catalogSource.catalogId val label = catalog?.name ?: catalogSource.catalogId
val typeLabel = localizedMediaTypeLabel(catalogSource.type) val typeLabel = localizedMediaTypeLabel(catalogSource.type)
val genreSuffix = if (catalogSource.genre != null) " · ${catalogSource.genre}" else "" val genreSuffix = if (catalogSource.genre != null) " · ${catalogSource.genre}" else ""
@ -188,8 +187,8 @@ object FolderDetailRepository {
sources.forEachIndexed { sourceIndex, source -> sources.forEachIndexed { sourceIndex, source ->
val tabIndex = if (showAll) sourceIndex + 1 else sourceIndex val tabIndex = if (showAll) sourceIndex + 1 else sourceIndex
val catalogSource = source.addonCatalogSource() val catalogSource = source.addonCatalogSource()
val addon = catalogSource?.let { value -> addons.find { it.manifest?.id == value.addonId } } val resolvedCatalog = catalogSource?.let { addons.findCollectionCatalog(it) }
if (!source.isTmdb && addon == null) { if (!source.isTmdb && resolvedCatalog == null) {
updateTab(tabIndex) { updateTab(tabIndex) {
it.copy( it.copy(
isLoading = false, isLoading = false,