Play series from MediaInfoFragment
This commit is contained in:
parent
10e89a2df5
commit
a8e9a40023
3 changed files with 77 additions and 16 deletions
|
@ -6,6 +6,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
|
@ -83,11 +84,16 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
})
|
||||
|
||||
viewModel.navigateToPlayer.observe(viewLifecycleOwner, { mediaSource ->
|
||||
navigateToPlayerActivity(
|
||||
arrayOf(PlayerItem(args.itemId, mediaSource.id!!)),
|
||||
viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000)
|
||||
)
|
||||
viewModel.navigateToPlayer.observe(viewLifecycleOwner, { playerItems ->
|
||||
if (playerItems != null) {
|
||||
navigateToPlayerActivity(
|
||||
playerItems,
|
||||
viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000)
|
||||
)
|
||||
viewModel.doneNavigatingToPlayer()
|
||||
binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
|
||||
binding.progressCircular.visibility = View.INVISIBLE
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.played.observe(viewLifecycleOwner, {
|
||||
|
@ -127,6 +133,8 @@ class MediaInfoFragment : Fragment() {
|
|||
binding.peopleRecyclerView.adapter = PersonListAdapter()
|
||||
|
||||
binding.playButton.setOnClickListener {
|
||||
binding.playButton.setImageResource(android.R.color.transparent)
|
||||
binding.progressCircular.visibility = View.VISIBLE
|
||||
if (args.itemType == "Movie") {
|
||||
if (!viewModel.mediaSources.value.isNullOrEmpty()) {
|
||||
if (viewModel.mediaSources.value!!.size > 1) {
|
||||
|
@ -139,8 +147,12 @@ class MediaInfoFragment : Fragment() {
|
|||
arrayOf(PlayerItem(args.itemId, viewModel.mediaSources.value!![0].id!!)),
|
||||
viewModel.item.value!!.userData!!.playbackPositionTicks.div(10000),
|
||||
)
|
||||
binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
|
||||
binding.progressCircular.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
} else if (args.itemType == "Series") {
|
||||
viewModel.preparePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dev.jdtech.jellyfin.models.PlayerItem
|
||||
import dev.jdtech.jellyfin.repository.JellyfinRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -54,8 +55,8 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
private val _mediaSources = MutableLiveData<List<MediaSourceInfo>>()
|
||||
val mediaSources: LiveData<List<MediaSourceInfo>> = _mediaSources
|
||||
|
||||
private val _navigateToPlayer = MutableLiveData<MediaSourceInfo>()
|
||||
val navigateToPlayer: LiveData<MediaSourceInfo> = _navigateToPlayer
|
||||
private val _navigateToPlayer = MutableLiveData<Array<PlayerItem>>()
|
||||
val navigateToPlayer: LiveData<Array<PlayerItem>> = _navigateToPlayer
|
||||
|
||||
private val _played = MutableLiveData<Boolean>()
|
||||
val played: LiveData<Boolean> = _played
|
||||
|
@ -66,6 +67,8 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
private val _error = MutableLiveData<Boolean>()
|
||||
val error: LiveData<Boolean> = _error
|
||||
|
||||
var playerItems: MutableList<PlayerItem> = mutableListOf()
|
||||
|
||||
fun loadData(itemId: UUID, itemType: String) {
|
||||
_error.value = false
|
||||
viewModelScope.launch {
|
||||
|
@ -177,7 +180,38 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
fun preparePlayer() {
|
||||
viewModelScope.launch {
|
||||
createPlayerItems(_item.value!!)
|
||||
_navigateToPlayer.value = playerItems.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun createPlayerItems(series: BaseItemDto) {
|
||||
if (nextUp.value != null) {
|
||||
val startEpisode = nextUp.value!!
|
||||
val episodes = jellyfinRepository.getEpisodes(startEpisode.seriesId!!, startEpisode.seasonId!!, startIndex = startEpisode.indexNumber?.minus(1))
|
||||
for (episode in episodes) {
|
||||
val mediaSources = jellyfinRepository.getMediaSources(episode.id)
|
||||
playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
|
||||
}
|
||||
} else {
|
||||
for (season in seasons.value!!) {
|
||||
if (season.indexNumber == 0) continue
|
||||
val episodes = jellyfinRepository.getEpisodes(series.id, season.id)
|
||||
for (episode in episodes) {
|
||||
val mediaSources = jellyfinRepository.getMediaSources(episode.id)
|
||||
playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateToPlayer(mediaSource: MediaSourceInfo) {
|
||||
_navigateToPlayer.value = mediaSource
|
||||
_navigateToPlayer.value = arrayOf(PlayerItem(item.value!!.id, mediaSource.id!!))
|
||||
}
|
||||
|
||||
fun doneNavigatingToPlayer() {
|
||||
_navigateToPlayer.value = null
|
||||
}
|
||||
}
|
|
@ -129,16 +129,31 @@
|
|||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginBottom="24dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/play_button"
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:background="@drawable/button_setup_background"
|
||||
android:contentDescription="@string/play_button_description"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:src="@drawable/ic_play" />
|
||||
android:layout_marginEnd="12dp">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/play_button"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/button_setup_background"
|
||||
android:contentDescription="@string/play_button_description"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:src="@drawable/ic_play" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_circular"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:elevation="8dp"
|
||||
android:padding="8dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:indeterminateTint="@color/white"
|
||||
android:visibility="invisible" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/trailer_button"
|
||||
|
|
Loading…
Reference in a new issue