Fix if media items are in folders
This commit is contained in:
parent
59d687f5a0
commit
45fc40b51e
9 changed files with 39 additions and 11 deletions
|
@ -96,7 +96,8 @@ class HomeFragment : Fragment() {
|
|||
findNavController().navigate(
|
||||
HomeFragmentDirections.actionNavigationHomeToLibraryFragment(
|
||||
view.id,
|
||||
view.name
|
||||
view.name,
|
||||
view.type
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class LibraryFragment : Fragment() {
|
|||
})
|
||||
|
||||
binding.errorLayout.errorRetryButton.setOnClickListener {
|
||||
viewModel.loadItems(args.libraryId)
|
||||
viewModel.loadItems(args.libraryId, args.libraryType)
|
||||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
|
@ -65,7 +65,7 @@ class LibraryFragment : Fragment() {
|
|||
ViewItemListAdapter(ViewItemListAdapter.OnClickListener { item ->
|
||||
navigateToMediaInfoFragment(item)
|
||||
})
|
||||
viewModel.loadItems(args.libraryId)
|
||||
viewModel.loadItems(args.libraryId, args.libraryType)
|
||||
}
|
||||
|
||||
private fun navigateToMediaInfoFragment(item: BaseItemDto) {
|
||||
|
|
|
@ -89,7 +89,8 @@ class MediaFragment : Fragment() {
|
|||
findNavController().navigate(
|
||||
MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
|
||||
library.id,
|
||||
library.name
|
||||
library.name,
|
||||
library.collectionType,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@ import java.util.*
|
|||
data class View(
|
||||
val id: UUID,
|
||||
val name: String?,
|
||||
var items: List<BaseItemDto>? = null
|
||||
var items: List<BaseItemDto>? = null,
|
||||
val type: String?
|
||||
)
|
|
@ -10,7 +10,11 @@ interface JellyfinRepository {
|
|||
|
||||
suspend fun getItem(itemId: UUID): BaseItemDto
|
||||
|
||||
suspend fun getItems(parentId: UUID? = null): List<BaseItemDto>
|
||||
suspend fun getItems(
|
||||
parentId: UUID? = null,
|
||||
includeTypes: List<String>? = null,
|
||||
recursive: Boolean = false
|
||||
): List<BaseItemDto>
|
||||
|
||||
suspend fun getFavoriteItems(): List<BaseItemDto>
|
||||
|
||||
|
|
|
@ -25,12 +25,18 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
return item
|
||||
}
|
||||
|
||||
override suspend fun getItems(parentId: UUID?): List<BaseItemDto> {
|
||||
override suspend fun getItems(
|
||||
parentId: UUID?,
|
||||
includeTypes: List<String>?,
|
||||
recursive: Boolean
|
||||
): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.userId!!,
|
||||
parentId = parentId
|
||||
parentId = parentId,
|
||||
includeItemTypes = includeTypes,
|
||||
recursive = recursive
|
||||
).content.items ?: listOf()
|
||||
}
|
||||
return items
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.jellyfin.sdk.model.api.BaseItemDto
|
|||
fun BaseItemDto.toView(): View {
|
||||
return View(
|
||||
id = id,
|
||||
name = name
|
||||
name = name,
|
||||
type = collectionType
|
||||
)
|
||||
}
|
|
@ -23,12 +23,22 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
private val _error = MutableLiveData<String>()
|
||||
val error: LiveData<String> = _error
|
||||
|
||||
fun loadItems(parentId: UUID) {
|
||||
fun loadItems(parentId: UUID, libraryType: String?) {
|
||||
_error.value = null
|
||||
_finishedLoading.value = false
|
||||
Timber.d("$libraryType")
|
||||
val itemType = when (libraryType) {
|
||||
"movies" -> "Movie"
|
||||
"tvshows" -> "Series"
|
||||
else -> null
|
||||
}
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
_items.value = jellyfinRepository.getItems(parentId)
|
||||
_items.value = jellyfinRepository.getItems(
|
||||
parentId,
|
||||
includeTypes = if (itemType != null) listOf(itemType) else null,
|
||||
recursive = true
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
_error.value = e.message
|
||||
|
|
|
@ -84,6 +84,10 @@
|
|||
app:exitAnim="@anim/nav_default_exit_anim"
|
||||
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
|
||||
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
||||
<argument
|
||||
android:name="libraryType"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/mediaInfoFragment"
|
||||
|
|
Loading…
Reference in a new issue