mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-16 23:12:12 +00:00
fix: implement catalog resolution logic for folders
This commit is contained in:
parent
2771feab57
commit
d031f22012
3 changed files with 50 additions and 14 deletions
|
|
@ -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 }
|
||||
|
||||
|
|
@ -111,9 +111,7 @@ fun CollectionEditorScreen(
|
|||
val genrePickerSource = genrePickerIndex?.let { editingFolder.resolvedSources.getOrNull(it) }
|
||||
val genrePickerCatalogSource = genrePickerSource?.addonCatalogSource()
|
||||
val genrePickerCatalog = genrePickerCatalogSource?.let { source ->
|
||||
state.availableCatalogs.find {
|
||||
it.addonId == source.addonId && it.type == source.type && it.catalogId == source.catalogId
|
||||
}
|
||||
state.availableCatalogs.findAvailableCatalog(source)
|
||||
}
|
||||
|
||||
FolderEditorPage(
|
||||
|
|
@ -757,11 +755,7 @@ private fun FolderEditorPage(
|
|||
} else if (addonSource != null) {
|
||||
FolderCatalogSourceCard(
|
||||
source = addonSource,
|
||||
matchingCatalog = state.availableCatalogs.find {
|
||||
it.addonId == addonSource.addonId &&
|
||||
it.type == addonSource.type &&
|
||||
it.catalogId == addonSource.catalogId
|
||||
},
|
||||
matchingCatalog = state.availableCatalogs.findAvailableCatalog(addonSource),
|
||||
onRemove = { CollectionEditorRepository.removeCatalogSource(index) },
|
||||
onOpenGenrePicker = { CollectionEditorRepository.showGenrePicker(index) },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -150,10 +150,9 @@ object FolderDetailRepository {
|
|||
)
|
||||
} else {
|
||||
val catalogSource = source.addonCatalogSource() ?: return@forEach
|
||||
val addon = addons.find { it.manifest?.id == catalogSource.addonId }
|
||||
val catalog = addon?.manifest?.catalogs?.find {
|
||||
it.id == catalogSource.catalogId && it.type == catalogSource.type
|
||||
}
|
||||
val resolvedCatalog = addons.findCollectionCatalog(catalogSource)
|
||||
val addon = resolvedCatalog?.addon
|
||||
val catalog = resolvedCatalog?.catalog
|
||||
val label = catalog?.name ?: catalogSource.catalogId
|
||||
val typeLabel = localizedMediaTypeLabel(catalogSource.type)
|
||||
val genreSuffix = if (catalogSource.genre != null) " · ${catalogSource.genre}" else ""
|
||||
|
|
@ -188,8 +187,8 @@ object FolderDetailRepository {
|
|||
sources.forEachIndexed { sourceIndex, source ->
|
||||
val tabIndex = if (showAll) sourceIndex + 1 else sourceIndex
|
||||
val catalogSource = source.addonCatalogSource()
|
||||
val addon = catalogSource?.let { value -> addons.find { it.manifest?.id == value.addonId } }
|
||||
if (!source.isTmdb && addon == null) {
|
||||
val resolvedCatalog = catalogSource?.let { addons.findCollectionCatalog(it) }
|
||||
if (!source.isTmdb && resolvedCatalog == null) {
|
||||
updateTab(tabIndex) {
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue