Improve home loading
This commit is contained in:
parent
78117aee3e
commit
2ff9239e8c
5 changed files with 48 additions and 36 deletions
|
@ -12,7 +12,9 @@ import dev.jdtech.jellyfin.models.HomeSection
|
|||
import dev.jdtech.jellyfin.models.View
|
||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||
import dev.jdtech.jellyfin.utils.toView
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
|
@ -50,43 +52,56 @@ constructor(
|
|||
_finishedLoading.value = false
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
|
||||
|
||||
jellyfinRepository.postCapabilities()
|
||||
val views: MutableList<View> = mutableListOf()
|
||||
val userViews = jellyfinRepository.getUserViews()
|
||||
for (view in userViews) {
|
||||
Timber.d("Collection type: ${view.collectionType}")
|
||||
if (view.collectionType == "homevideos" ||
|
||||
view.collectionType == "music" ||
|
||||
view.collectionType == "playlists" ||
|
||||
view.collectionType == "books" ||
|
||||
view.collectionType == "livetv"
|
||||
) continue
|
||||
val latestItems = jellyfinRepository.getLatestMedia(view.id)
|
||||
if (latestItems.isEmpty()) continue
|
||||
val v = view.toView()
|
||||
v.items = latestItems
|
||||
views.add(v)
|
||||
}
|
||||
|
||||
val items = mutableListOf<HomeItem>()
|
||||
|
||||
val resumeItems = jellyfinRepository.getResumeItems()
|
||||
val resumeSection =
|
||||
HomeSection(UUID.randomUUID(), continueWatchingString, resumeItems)
|
||||
withContext(Dispatchers.Default) {
|
||||
|
||||
if (!resumeItems.isNullOrEmpty()) {
|
||||
items.add(HomeItem.Section(resumeSection))
|
||||
val resumeItems = jellyfinRepository.getResumeItems()
|
||||
val resumeSection =
|
||||
HomeSection(UUID.randomUUID(), continueWatchingString, resumeItems)
|
||||
|
||||
if (!resumeItems.isNullOrEmpty()) {
|
||||
items.add(HomeItem.Section(resumeSection))
|
||||
}
|
||||
|
||||
val nextUpItems = jellyfinRepository.getNextUp()
|
||||
val nextUpSection = HomeSection(UUID.randomUUID(), nextUpString, nextUpItems)
|
||||
|
||||
if (!nextUpItems.isNullOrEmpty()) {
|
||||
items.add(HomeItem.Section(nextUpSection))
|
||||
}
|
||||
}
|
||||
|
||||
val nextUpItems = jellyfinRepository.getNextUp()
|
||||
val nextUpSection = HomeSection(UUID.randomUUID(), nextUpString, nextUpItems)
|
||||
_views.value = items
|
||||
|
||||
if (!nextUpItems.isNullOrEmpty()) {
|
||||
items.add(HomeItem.Section(nextUpSection))
|
||||
val views: MutableList<View> = mutableListOf()
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
val userViews = jellyfinRepository.getUserViews()
|
||||
|
||||
for (view in userViews) {
|
||||
Timber.d("Collection type: ${view.collectionType}")
|
||||
if (view.collectionType == "homevideos" ||
|
||||
view.collectionType == "music" ||
|
||||
view.collectionType == "playlists" ||
|
||||
view.collectionType == "books" ||
|
||||
view.collectionType == "livetv"
|
||||
) continue
|
||||
val latestItems = jellyfinRepository.getLatestMedia(view.id)
|
||||
if (latestItems.isEmpty()) continue
|
||||
val v = view.toView()
|
||||
v.items = latestItems
|
||||
views.add(v)
|
||||
}
|
||||
}
|
||||
|
||||
_views.value = items + views.map { HomeItem.ViewItem(it) }
|
||||
|
||||
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
_error.value = e.toString()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment_activity_main"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/nav_view"
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/main_toolbar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/windowBackground"
|
||||
app:layout_constraintBottom_toTopOf="@id/nav_host_fragment_activity_main"
|
||||
|
@ -47,6 +47,5 @@
|
|||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
|
|
|
@ -16,18 +16,18 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".fragments.HomeFragment">
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/loading_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:trackCornerRadius="10dp" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<include android:id="@+id/error_layout" layout="@layout/error_panel" />
|
||||
<include
|
||||
android:id="@+id/error_layout"
|
||||
layout="@layout/error_panel" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/views_recycler_view"
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:layoutAnimation="@anim/overview_media_animation"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
app:homeEpisodes="@{section.items}"
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:clipToPadding="false"
|
||||
android:layoutAnimation="@anim/overview_media_animation"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="12dp"
|
||||
app:items="@{view.items}"
|
||||
|
|
Loading…
Reference in a new issue