mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-04 17:29:07 +00:00
ref: pinned collections to appear at the top in HomeCatalogSettingsRepository
This commit is contained in:
parent
acbd830edb
commit
8e8e65d831
1 changed files with 26 additions and 0 deletions
|
|
@ -114,6 +114,7 @@ object HomeCatalogSettingsRepository {
|
|||
return
|
||||
}
|
||||
normalizePreferences()
|
||||
enforcePinnedCollectionsAtTop()
|
||||
publish()
|
||||
persist()
|
||||
}
|
||||
|
|
@ -122,6 +123,7 @@ object HomeCatalogSettingsRepository {
|
|||
ensureLoaded()
|
||||
collectionDefinitions = buildCollectionDefinitions(collections)
|
||||
normalizePreferences()
|
||||
enforcePinnedCollectionsAtTop()
|
||||
publish()
|
||||
persist()
|
||||
}
|
||||
|
|
@ -382,6 +384,30 @@ object HomeCatalogSettingsRepository {
|
|||
return (catalogKeys + collectionKeys)
|
||||
.sortedBy { key -> preferences[key]?.order ?: Int.MAX_VALUE }
|
||||
}
|
||||
|
||||
private fun enforcePinnedCollectionsAtTop() {
|
||||
val orderedKeys = allOrderedKeys()
|
||||
if (orderedKeys.isEmpty()) return
|
||||
|
||||
val pinnedCollectionKeys = collectionDefinitions
|
||||
.asSequence()
|
||||
.filter { it.isPinnedToTop }
|
||||
.map { it.key }
|
||||
.toSet()
|
||||
if (pinnedCollectionKeys.isEmpty()) return
|
||||
|
||||
val pinnedKeys = orderedKeys.filter { it in pinnedCollectionKeys }
|
||||
if (pinnedKeys.isEmpty()) return
|
||||
|
||||
val nonPinnedKeys = orderedKeys.filterNot { it in pinnedCollectionKeys }
|
||||
val reorderedKeys = pinnedKeys + nonPinnedKeys
|
||||
if (reorderedKeys == orderedKeys) return
|
||||
|
||||
reorderedKeys.forEachIndexed { index, itemKey ->
|
||||
val current = preferences[itemKey] ?: return@forEachIndexed
|
||||
preferences[itemKey] = current.copy(order = index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal data class CollectionCatalogDefinition(
|
||||
|
|
|
|||
Loading…
Reference in a new issue