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