Merge Wholphin v1.1.0 while preserving Wolfskin features #27
1 changed files with 31 additions and 1 deletions
|
|
@ -89,6 +89,7 @@ import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
import org.jellyfin.sdk.api.client.ApiClient
|
||||||
|
import org.jellyfin.sdk.api.client.extensions.libraryApi
|
||||||
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
import org.jellyfin.sdk.model.api.CollectionType
|
import org.jellyfin.sdk.model.api.CollectionType
|
||||||
|
|
@ -168,15 +169,25 @@ class CollectionFolderViewModel
|
||||||
val id = collectionFilter.libraryDisplayInfoIdOverride ?: itemId
|
val id = collectionFilter.libraryDisplayInfoIdOverride ?: itemId
|
||||||
libraryDisplayInfoDao.getItem(user, id)
|
libraryDisplayInfoDao.getItem(user, id)
|
||||||
}
|
}
|
||||||
|
val ancestorDisplayInfo =
|
||||||
|
if (libraryDisplayInfo?.viewOptions == null && item != null) {
|
||||||
|
getAncestorDisplayInfo(item)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
viewOptions = libraryDisplayInfo?.viewOptions ?: defaultViewOptions,
|
viewOptions =
|
||||||
|
libraryDisplayInfo?.viewOptions
|
||||||
|
?: ancestorDisplayInfo?.viewOptions
|
||||||
|
?: defaultViewOptions,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val sortAndDirection =
|
val sortAndDirection =
|
||||||
if (collectionFilter.useSavedLibraryDisplayInfo) {
|
if (collectionFilter.useSavedLibraryDisplayInfo) {
|
||||||
libraryDisplayInfo?.sortAndDirection
|
libraryDisplayInfo?.sortAndDirection
|
||||||
|
?: ancestorDisplayInfo?.sortAndDirection
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
} ?: initialSortAndDirection ?: SortAndDirection.DEFAULT
|
} ?: initialSortAndDirection ?: SortAndDirection.DEFAULT
|
||||||
|
|
@ -232,6 +243,25 @@ class CollectionFolderViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a sub-folder, returns the saved display info of the closest ancestor that has one
|
||||||
|
*/
|
||||||
|
private suspend fun getAncestorDisplayInfo(item: BaseItem): LibraryDisplayInfo? {
|
||||||
|
if (item.type != BaseItemKind.FOLDER || collectionFilter.libraryDisplayInfoIdOverride != null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val user = serverRepository.currentUser ?: return null
|
||||||
|
return try {
|
||||||
|
api.libraryApi
|
||||||
|
.getAncestors(item.id, user.id)
|
||||||
|
.content
|
||||||
|
.firstNotNullOfOrNull { ancestor -> libraryDisplayInfoDao.getItem(user, ancestor.id) }
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
Timber.w(ex, "Error getting ancestors for %s", item.id)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveLibraryDisplayInfo(
|
private fun saveLibraryDisplayInfo(
|
||||||
newFilter: GetItemsFilter = state.value.filter,
|
newFilter: GetItemsFilter = state.value.filter,
|
||||||
newSort: SortAndDirection = state.value.sortAndDirection,
|
newSort: SortAndDirection = state.value.sortAndDirection,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue