Add error handling to preparePlayerItems
This commit is contained in:
parent
2a8b937402
commit
d67e3fb39c
7 changed files with 80 additions and 8 deletions
|
@ -98,6 +98,17 @@ class EpisodeBottomSheetFragment : BottomSheetDialogFragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.playerItemsError.observe(viewLifecycleOwner, {
|
||||||
|
when (it) {
|
||||||
|
true -> {
|
||||||
|
binding.playerItemsError.visibility = View.VISIBLE
|
||||||
|
binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
|
||||||
|
binding.progressCircular.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
false -> binding.playerItemsError.visibility = View.GONE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
viewModel.loadEpisode(args.episodeId)
|
viewModel.loadEpisode(args.episodeId)
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
|
|
|
@ -114,6 +114,17 @@ class MediaInfoFragment : Fragment() {
|
||||||
binding.favoriteButton.setImageResource(drawable)
|
binding.favoriteButton.setImageResource(drawable)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.playerItemsError.observe(viewLifecycleOwner, {
|
||||||
|
when (it) {
|
||||||
|
true -> {
|
||||||
|
binding.playerItemsError.visibility = View.VISIBLE
|
||||||
|
binding.playButton.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_play))
|
||||||
|
binding.progressCircular.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
false -> binding.playerItemsError.visibility = View.GONE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
binding.trailerButton.setOnClickListener {
|
binding.trailerButton.setOnClickListener {
|
||||||
val intent = Intent(
|
val intent = Intent(
|
||||||
Intent.ACTION_VIEW,
|
Intent.ACTION_VIEW,
|
||||||
|
|
|
@ -43,6 +43,9 @@ constructor(
|
||||||
|
|
||||||
var playerItems: MutableList<PlayerItem> = mutableListOf()
|
var playerItems: MutableList<PlayerItem> = mutableListOf()
|
||||||
|
|
||||||
|
private val _playerItemsError = MutableLiveData<Boolean>()
|
||||||
|
val playerItemsError: LiveData<Boolean> = _playerItemsError
|
||||||
|
|
||||||
fun loadEpisode(episodeId: UUID) {
|
fun loadEpisode(episodeId: UUID) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
|
@ -59,14 +62,23 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun preparePlayer() {
|
fun preparePlayer() {
|
||||||
|
_playerItemsError.value = false
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
createPlayerItems(_item.value!!)
|
try {
|
||||||
_navigateToPlayer.value = true
|
createPlayerItems(_item.value!!)
|
||||||
|
_navigateToPlayer.value = true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_playerItemsError.value = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun createPlayerItems(startEpisode: BaseItemDto) {
|
private suspend fun createPlayerItems(startEpisode: BaseItemDto) {
|
||||||
val episodes = jellyfinRepository.getEpisodes(startEpisode.seriesId!!, startEpisode.seasonId!!, startIndex = startEpisode.indexNumber?.minus(1))
|
val episodes = jellyfinRepository.getEpisodes(
|
||||||
|
startEpisode.seriesId!!,
|
||||||
|
startEpisode.seasonId!!,
|
||||||
|
startIndex = startEpisode.indexNumber?.minus(1)
|
||||||
|
)
|
||||||
for (episode in episodes) {
|
for (episode in episodes) {
|
||||||
val mediaSources = jellyfinRepository.getMediaSources(episode.id)
|
val mediaSources = jellyfinRepository.getMediaSources(episode.id)
|
||||||
playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
|
playerItems.add(PlayerItem(episode.id, mediaSources[0].id!!))
|
||||||
|
|
|
@ -69,6 +69,9 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
||||||
|
|
||||||
var playerItems: MutableList<PlayerItem> = mutableListOf()
|
var playerItems: MutableList<PlayerItem> = mutableListOf()
|
||||||
|
|
||||||
|
private val _playerItemsError = MutableLiveData<Boolean>()
|
||||||
|
val playerItemsError: LiveData<Boolean> = _playerItemsError
|
||||||
|
|
||||||
fun loadData(itemId: UUID, itemType: String) {
|
fun loadData(itemId: UUID, itemType: String) {
|
||||||
_error.value = false
|
_error.value = false
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
@ -181,9 +184,14 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun preparePlayer() {
|
fun preparePlayer() {
|
||||||
|
_playerItemsError.value = false
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
createPlayerItems(_item.value!!)
|
try {
|
||||||
_navigateToPlayer.value = playerItems.toTypedArray()
|
createPlayerItems(_item.value!!)
|
||||||
|
_navigateToPlayer.value = playerItems.toTypedArray()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_playerItemsError.value = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,22 @@
|
||||||
android:src="@drawable/ic_heart" />
|
android:src="@drawable/ic_heart" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/player_items_error"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/buttons"
|
||||||
|
android:text="@string/error_preparing_player_items"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
|
android:textColor="@color/red"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -172,7 +188,7 @@
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/buttons"
|
app:layout_constraintTop_toBottomOf="@id/player_items_error"
|
||||||
tools:text="After one hundred years of peace, humanity is suddenly reminded of the terror of being at the Titans' mercy." />
|
tools:text="After one hundred years of peace, humanity is suddenly reminded of the terror of being at the Titans' mercy." />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -148,10 +148,10 @@
|
||||||
android:id="@+id/progress_circular"
|
android:id="@+id/progress_circular"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:elevation="8dp"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
|
android:elevation="8dp"
|
||||||
android:indeterminateTint="@color/white"
|
android:indeterminateTint="@color/white"
|
||||||
|
android:padding="8dp"
|
||||||
android:visibility="invisible" />
|
android:visibility="invisible" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
@ -185,6 +185,19 @@
|
||||||
android:src="@drawable/ic_heart" />
|
android:src="@drawable/ic_heart" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/player_items_error"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="24dp"
|
||||||
|
android:layout_marginTop="-12dp"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:text="@string/error_preparing_player_items"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
|
android:textColor="@color/red"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/info"
|
android:id="@+id/info"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -49,4 +49,5 @@
|
||||||
<string name="switch_server">Switch server</string>
|
<string name="switch_server">Switch server</string>
|
||||||
<string name="settings_category_appearance">Appearance</string>
|
<string name="settings_category_appearance">Appearance</string>
|
||||||
<string name="theme">Theme</string>
|
<string name="theme">Theme</string>
|
||||||
|
<string name="error_preparing_player_items">Error preparing player items</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue