refactor: use CollectionType
in LibraryFragment
This commit is contained in:
parent
0238aaebc3
commit
c1819406cf
8 changed files with 33 additions and 27 deletions
|
@ -209,9 +209,9 @@ class HomeFragment : Fragment() {
|
||||||
private fun navigateToLibraryFragment(view: dev.jdtech.jellyfin.models.View) {
|
private fun navigateToLibraryFragment(view: dev.jdtech.jellyfin.models.View) {
|
||||||
findNavController().navigate(
|
findNavController().navigate(
|
||||||
HomeFragmentDirections.actionNavigationHomeToLibraryFragment(
|
HomeFragmentDirections.actionNavigationHomeToLibraryFragment(
|
||||||
view.id,
|
libraryId = view.id,
|
||||||
view.name,
|
libraryName = view.name,
|
||||||
view.type
|
libraryType = view.type
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import dev.jdtech.jellyfin.core.R as CoreR
|
||||||
import dev.jdtech.jellyfin.databinding.FragmentLibraryBinding
|
import dev.jdtech.jellyfin.databinding.FragmentLibraryBinding
|
||||||
import dev.jdtech.jellyfin.dialogs.ErrorDialogFragment
|
import dev.jdtech.jellyfin.dialogs.ErrorDialogFragment
|
||||||
import dev.jdtech.jellyfin.dialogs.SortDialogFragment
|
import dev.jdtech.jellyfin.dialogs.SortDialogFragment
|
||||||
import dev.jdtech.jellyfin.models.CollectionType
|
|
||||||
import dev.jdtech.jellyfin.models.FindroidBoxSet
|
import dev.jdtech.jellyfin.models.FindroidBoxSet
|
||||||
import dev.jdtech.jellyfin.models.FindroidItem
|
import dev.jdtech.jellyfin.models.FindroidItem
|
||||||
import dev.jdtech.jellyfin.models.FindroidMovie
|
import dev.jdtech.jellyfin.models.FindroidMovie
|
||||||
|
@ -116,11 +115,7 @@ class LibraryFragment : Fragment() {
|
||||||
binding.itemsRecyclerView.adapter =
|
binding.itemsRecyclerView.adapter =
|
||||||
ViewItemPagingAdapter(
|
ViewItemPagingAdapter(
|
||||||
ViewItemPagingAdapter.OnClickListener { item ->
|
ViewItemPagingAdapter.OnClickListener { item ->
|
||||||
if (args.libraryType == CollectionType.BoxSets.type) {
|
|
||||||
navigateToItem(item)
|
navigateToItem(item)
|
||||||
} else {
|
|
||||||
navigateToItem(item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -149,9 +149,9 @@ class MediaFragment : Fragment() {
|
||||||
private fun navigateToLibraryFragment(library: FindroidCollection) {
|
private fun navigateToLibraryFragment(library: FindroidCollection) {
|
||||||
findNavController().navigate(
|
findNavController().navigate(
|
||||||
MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
|
MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
|
||||||
library.id,
|
libraryId = library.id,
|
||||||
library.name,
|
libraryName = library.name,
|
||||||
library.type.type,
|
libraryType = library.type,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,9 +98,7 @@
|
||||||
app:argType="java.util.UUID" />
|
app:argType="java.util.UUID" />
|
||||||
<argument
|
<argument
|
||||||
android:name="libraryName"
|
android:name="libraryName"
|
||||||
android:defaultValue="Library"
|
app:argType="string" />
|
||||||
app:argType="string"
|
|
||||||
app:nullable="true" />
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_libraryFragment_to_showFragment"
|
android:id="@+id/action_libraryFragment_to_showFragment"
|
||||||
app:destination="@id/showFragment"
|
app:destination="@id/showFragment"
|
||||||
|
@ -124,9 +122,7 @@
|
||||||
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
||||||
<argument
|
<argument
|
||||||
android:name="libraryType"
|
android:name="libraryType"
|
||||||
android:defaultValue="unknown"
|
app:argType="dev.jdtech.jellyfin.models.CollectionType" />
|
||||||
app:argType="string"
|
|
||||||
app:nullable="true" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/showFragment"
|
android:id="@+id/showFragment"
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dev.jdtech.jellyfin.AppPreferences
|
import dev.jdtech.jellyfin.AppPreferences
|
||||||
import dev.jdtech.jellyfin.core.R
|
import dev.jdtech.jellyfin.core.R
|
||||||
|
import dev.jdtech.jellyfin.models.CollectionType
|
||||||
import dev.jdtech.jellyfin.models.SortBy
|
import dev.jdtech.jellyfin.models.SortBy
|
||||||
import dev.jdtech.jellyfin.viewmodels.LibraryViewModel
|
import dev.jdtech.jellyfin.viewmodels.LibraryViewModel
|
||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
|
@ -17,7 +18,7 @@ import org.jellyfin.sdk.model.api.SortOrder
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class SortDialogFragment(
|
class SortDialogFragment(
|
||||||
private val parentId: UUID,
|
private val parentId: UUID,
|
||||||
private val libraryType: String?,
|
private val libraryType: CollectionType,
|
||||||
private val viewModel: LibraryViewModel,
|
private val viewModel: LibraryViewModel,
|
||||||
private val sortType: String
|
private val sortType: String
|
||||||
) : DialogFragment() {
|
) : DialogFragment() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.UUID
|
||||||
|
|
||||||
data class View(
|
data class View(
|
||||||
val id: UUID,
|
val id: UUID,
|
||||||
val name: String?,
|
val name: String,
|
||||||
var items: List<FindroidItem>? = null,
|
var items: List<FindroidItem>? = null,
|
||||||
val type: String?
|
val type: CollectionType
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.os.Bundle
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
|
import dev.jdtech.jellyfin.models.CollectionType
|
||||||
import dev.jdtech.jellyfin.models.View
|
import dev.jdtech.jellyfin.models.View
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||||
|
@ -16,8 +17,8 @@ import org.jellyfin.sdk.model.api.BaseItemDto
|
||||||
fun BaseItemDto.toView(): View {
|
fun BaseItemDto.toView(): View {
|
||||||
return View(
|
return View(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name ?: "",
|
||||||
type = collectionType
|
type = valueOf(collectionType, CollectionType.Movies)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,3 +45,15 @@ fun Activity.restart() {
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : Enum<T>> valueOf(type: String?, default: T): T {
|
||||||
|
if (type == null) {
|
||||||
|
return default
|
||||||
|
}
|
||||||
|
|
||||||
|
return try {
|
||||||
|
java.lang.Enum.valueOf(T::class.java, type)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
default
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
|
||||||
import androidx.paging.PagingData
|
import androidx.paging.PagingData
|
||||||
import androidx.paging.cachedIn
|
import androidx.paging.cachedIn
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import dev.jdtech.jellyfin.models.CollectionType
|
||||||
import dev.jdtech.jellyfin.models.FindroidItem
|
import dev.jdtech.jellyfin.models.FindroidItem
|
||||||
import dev.jdtech.jellyfin.models.SortBy
|
import dev.jdtech.jellyfin.models.SortBy
|
||||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||||
|
@ -37,16 +38,16 @@ constructor(
|
||||||
|
|
||||||
fun loadItems(
|
fun loadItems(
|
||||||
parentId: UUID,
|
parentId: UUID,
|
||||||
libraryType: String?,
|
libraryType: CollectionType,
|
||||||
sortBy: SortBy = SortBy.defaultValue,
|
sortBy: SortBy = SortBy.defaultValue,
|
||||||
sortOrder: SortOrder = SortOrder.ASCENDING
|
sortOrder: SortOrder = SortOrder.ASCENDING
|
||||||
) {
|
) {
|
||||||
itemsloaded = true
|
itemsloaded = true
|
||||||
Timber.d("$libraryType")
|
Timber.d("$libraryType")
|
||||||
val itemType = when (libraryType) {
|
val itemType = when (libraryType) {
|
||||||
"movies" -> listOf(BaseItemKind.MOVIE)
|
CollectionType.Movies -> listOf(BaseItemKind.MOVIE)
|
||||||
"tvshows" -> listOf(BaseItemKind.SERIES)
|
CollectionType.TvShows -> listOf(BaseItemKind.SERIES)
|
||||||
"boxsets" -> listOf(BaseItemKind.BOX_SET)
|
CollectionType.BoxSets -> listOf(BaseItemKind.BOX_SET)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
Loading…
Reference in a new issue