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) {
|
||||
findNavController().navigate(
|
||||
HomeFragmentDirections.actionNavigationHomeToLibraryFragment(
|
||||
view.id,
|
||||
view.name,
|
||||
view.type
|
||||
libraryId = view.id,
|
||||
libraryName = view.name,
|
||||
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.dialogs.ErrorDialogFragment
|
||||
import dev.jdtech.jellyfin.dialogs.SortDialogFragment
|
||||
import dev.jdtech.jellyfin.models.CollectionType
|
||||
import dev.jdtech.jellyfin.models.FindroidBoxSet
|
||||
import dev.jdtech.jellyfin.models.FindroidItem
|
||||
import dev.jdtech.jellyfin.models.FindroidMovie
|
||||
|
@ -116,11 +115,7 @@ class LibraryFragment : Fragment() {
|
|||
binding.itemsRecyclerView.adapter =
|
||||
ViewItemPagingAdapter(
|
||||
ViewItemPagingAdapter.OnClickListener { item ->
|
||||
if (args.libraryType == CollectionType.BoxSets.type) {
|
||||
navigateToItem(item)
|
||||
} else {
|
||||
navigateToItem(item)
|
||||
}
|
||||
navigateToItem(item)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -149,9 +149,9 @@ class MediaFragment : Fragment() {
|
|||
private fun navigateToLibraryFragment(library: FindroidCollection) {
|
||||
findNavController().navigate(
|
||||
MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
|
||||
library.id,
|
||||
library.name,
|
||||
library.type.type,
|
||||
libraryId = library.id,
|
||||
libraryName = library.name,
|
||||
libraryType = library.type,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -98,9 +98,7 @@
|
|||
app:argType="java.util.UUID" />
|
||||
<argument
|
||||
android:name="libraryName"
|
||||
android:defaultValue="Library"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
app:argType="string" />
|
||||
<action
|
||||
android:id="@+id/action_libraryFragment_to_showFragment"
|
||||
app:destination="@id/showFragment"
|
||||
|
@ -124,9 +122,7 @@
|
|||
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
||||
<argument
|
||||
android:name="libraryType"
|
||||
android:defaultValue="unknown"
|
||||
app:argType="string"
|
||||
app:nullable="true" />
|
||||
app:argType="dev.jdtech.jellyfin.models.CollectionType" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/showFragment"
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import dev.jdtech.jellyfin.AppPreferences
|
||||
import dev.jdtech.jellyfin.core.R
|
||||
import dev.jdtech.jellyfin.models.CollectionType
|
||||
import dev.jdtech.jellyfin.models.SortBy
|
||||
import dev.jdtech.jellyfin.viewmodels.LibraryViewModel
|
||||
import java.lang.IllegalStateException
|
||||
|
@ -17,7 +18,7 @@ import org.jellyfin.sdk.model.api.SortOrder
|
|||
@AndroidEntryPoint
|
||||
class SortDialogFragment(
|
||||
private val parentId: UUID,
|
||||
private val libraryType: String?,
|
||||
private val libraryType: CollectionType,
|
||||
private val viewModel: LibraryViewModel,
|
||||
private val sortType: String
|
||||
) : DialogFragment() {
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.UUID
|
|||
|
||||
data class View(
|
||||
val id: UUID,
|
||||
val name: String?,
|
||||
val name: String,
|
||||
var items: List<FindroidItem>? = null,
|
||||
val type: String?
|
||||
val type: CollectionType
|
||||
)
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.os.Bundle
|
|||
import android.util.TypedValue
|
||||
import androidx.annotation.AttrRes
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import dev.jdtech.jellyfin.models.CollectionType
|
||||
import dev.jdtech.jellyfin.models.View
|
||||
import java.io.Serializable
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
|
@ -16,8 +17,8 @@ import org.jellyfin.sdk.model.api.BaseItemDto
|
|||
fun BaseItemDto.toView(): View {
|
||||
return View(
|
||||
id = id,
|
||||
name = name,
|
||||
type = collectionType
|
||||
name = name ?: "",
|
||||
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
|
||||
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.cachedIn
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dev.jdtech.jellyfin.models.CollectionType
|
||||
import dev.jdtech.jellyfin.models.FindroidItem
|
||||
import dev.jdtech.jellyfin.models.SortBy
|
||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||
|
@ -37,16 +38,16 @@ constructor(
|
|||
|
||||
fun loadItems(
|
||||
parentId: UUID,
|
||||
libraryType: String?,
|
||||
libraryType: CollectionType,
|
||||
sortBy: SortBy = SortBy.defaultValue,
|
||||
sortOrder: SortOrder = SortOrder.ASCENDING
|
||||
) {
|
||||
itemsloaded = true
|
||||
Timber.d("$libraryType")
|
||||
val itemType = when (libraryType) {
|
||||
"movies" -> listOf(BaseItemKind.MOVIE)
|
||||
"tvshows" -> listOf(BaseItemKind.SERIES)
|
||||
"boxsets" -> listOf(BaseItemKind.BOX_SET)
|
||||
CollectionType.Movies -> listOf(BaseItemKind.MOVIE)
|
||||
CollectionType.TvShows -> listOf(BaseItemKind.SERIES)
|
||||
CollectionType.BoxSets -> listOf(BaseItemKind.BOX_SET)
|
||||
else -> null
|
||||
}
|
||||
viewModelScope.launch {
|
||||
|
|
Loading…
Reference in a new issue