Add dependency injection to MediaViewModel
This commit is contained in:
parent
2c8ddaad24
commit
7908661b82
4 changed files with 7 additions and 20 deletions
|
@ -30,7 +30,7 @@ class MediaFragment : Fragment() {
|
|||
binding.viewModel = viewModel
|
||||
binding.viewsRecyclerView.adapter =
|
||||
CollectionListAdapter(CollectionListAdapter.OnClickListener { library ->
|
||||
nagivateToLibraryFragment(library)
|
||||
navigateToLibraryFragment(library)
|
||||
})
|
||||
|
||||
viewModel.finishedLoading.observe(viewLifecycleOwner, {
|
||||
|
@ -42,7 +42,7 @@ class MediaFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
private fun nagivateToLibraryFragment(library: BaseItemDto) {
|
||||
private fun navigateToLibraryFragment(library: BaseItemDto) {
|
||||
findNavController().navigate(
|
||||
MediaFragmentDirections.actionNavigationMediaToLibraryFragment(
|
||||
library.id,
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.*
|
|||
interface JellyfinRepository {
|
||||
suspend fun getItem(itemId: UUID): BaseItemDto
|
||||
|
||||
suspend fun getItems(parentId: UUID): List<BaseItemDto>
|
||||
suspend fun getItems(parentId: UUID? = null): List<BaseItemDto>
|
||||
|
||||
suspend fun getSeasons(seriesId: UUID): List<BaseItemDto>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
return item
|
||||
}
|
||||
|
||||
override suspend fun getItems(parentId: UUID): List<BaseItemDto> {
|
||||
override suspend fun getItems(parentId: UUID?): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
package dev.jdtech.jellyfin.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.*
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dev.jdtech.jellyfin.api.JellyfinApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MediaViewModel
|
||||
@Inject
|
||||
constructor(
|
||||
application: Application
|
||||
private val jellyfinRepository: JellyfinRepository
|
||||
) : ViewModel() {
|
||||
private val jellyfinApi = JellyfinApi.getInstance(application, "")
|
||||
|
||||
private val _collections = MutableLiveData<List<BaseItemDto>>()
|
||||
val collections: LiveData<List<BaseItemDto>> = _collections
|
||||
|
@ -27,17 +22,9 @@ constructor(
|
|||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
val items = getItems(jellyfinApi.userId!!)
|
||||
val items = jellyfinRepository.getItems()
|
||||
_collections.value = items
|
||||
_finishedLoading.value = true
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getItems(userId: UUID): List<BaseItemDto>? {
|
||||
var items: List<BaseItemDto>?
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(userId).content.items
|
||||
}
|
||||
return items
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue