Fix app crash on ErrorDialogFragment.kt configuration change
This commit is contained in:
parent
d3b4fe6ea3
commit
0bd1bb30c8
13 changed files with 46 additions and 25 deletions
|
@ -6,12 +6,13 @@ import android.os.Bundle
|
|||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dev.jdtech.jellyfin.R
|
||||
import dev.jdtech.jellyfin.utils.serializable
|
||||
import java.io.Serializable
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class ErrorDialogFragment(
|
||||
private val error: Exception
|
||||
) : DialogFragment() {
|
||||
class ErrorDialogFragment: DialogFragment() {
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val error = requireArguments().serializable<Exception>("error")!!
|
||||
return activity?.let {
|
||||
val builder = MaterialAlertDialogBuilder(it, R.style.ErrorDialogStyle)
|
||||
builder
|
||||
|
@ -32,4 +33,16 @@ class ErrorDialogFragment(
|
|||
builder.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "error_dialog"
|
||||
|
||||
fun newInstance(error: Exception): ErrorDialogFragment {
|
||||
val errorDialogFragment = ErrorDialogFragment()
|
||||
val args = Bundle()
|
||||
args.putSerializable("error", error as Serializable)
|
||||
errorDialogFragment.arguments = args
|
||||
return errorDialogFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class DownloadFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
@ -92,7 +92,7 @@ class DownloadFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: DownloadViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.downloadsRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -70,7 +70,7 @@ class DownloadSeriesFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
viewModel.loadEpisodes(args.seriesMetadata)
|
||||
|
@ -84,7 +84,7 @@ class DownloadSeriesFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: DownloadSeriesViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.episodesRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ class EpisodeBottomSheetFragment : BottomSheetDialogFragment() {
|
|||
)
|
||||
binding.progressCircular.visibility = View.INVISIBLE
|
||||
binding.playerItemsErrorDetails.setOnClickListener {
|
||||
ErrorDialogFragment(error.error).show(parentFragmentManager, "errordialog")
|
||||
ErrorDialogFragment.newInstance(error.error).show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class FavoriteFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
@ -89,7 +89,7 @@ class FavoriteFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: FavoriteViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.favoritesRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -108,7 +108,7 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: HomeViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
binding.viewsRecyclerView.isVisible = false
|
||||
|
|
|
@ -114,7 +114,7 @@ class LibraryFragment : Fragment() {
|
|||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(
|
||||
parentFragmentManager,
|
||||
"errordialog"
|
||||
ErrorDialogFragment.TAG
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ class LibraryFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: LibraryViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.itemsRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -71,7 +71,7 @@ class MediaFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
@ -139,7 +139,7 @@ class MediaFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: MediaViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.viewsRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -150,7 +150,7 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
binding.checkButton.setOnClickListener {
|
||||
|
@ -297,7 +297,7 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: MediaInfoViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.mediaInfoScrollview.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
@ -326,7 +326,7 @@ class MediaInfoFragment : Fragment() {
|
|||
)
|
||||
binding.progressCircular.visibility = View.INVISIBLE
|
||||
binding.playerItemsErrorDetails.setOnClickListener {
|
||||
ErrorDialogFragment(error.error).show(parentFragmentManager, "errordialog")
|
||||
ErrorDialogFragment.newInstance(error.error).show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ internal class PersonDetailFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ internal class PersonDetailFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: PersonDetailViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.fragmentContent.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -73,7 +73,7 @@ class SearchResultFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
@ -97,7 +97,7 @@ class SearchResultFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: SearchResultViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.searchResultsRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -67,7 +67,7 @@ class SeasonFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.errorLayout.errorDetailsButton.setOnClickListener {
|
||||
errorDialog.show(parentFragmentManager, "errordialog")
|
||||
errorDialog.show(parentFragmentManager, ErrorDialogFragment.TAG)
|
||||
}
|
||||
|
||||
binding.episodesRecyclerView.adapter =
|
||||
|
@ -95,7 +95,7 @@ class SeasonFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun bindUiStateError(uiState: SeasonViewModel.UiState.Error) {
|
||||
errorDialog = ErrorDialogFragment(uiState.error)
|
||||
errorDialog = ErrorDialogFragment.newInstance(uiState.error)
|
||||
binding.loadingIndicator.isVisible = false
|
||||
binding.episodesRecyclerView.isVisible = false
|
||||
binding.errorLayout.errorPanel.isVisible = true
|
||||
|
|
|
@ -2,6 +2,8 @@ package dev.jdtech.jellyfin.utils
|
|||
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.widget.ImageButton
|
||||
import androidx.annotation.AttrRes
|
||||
|
@ -12,6 +14,7 @@ import dev.jdtech.jellyfin.AppNavigationDirections
|
|||
import dev.jdtech.jellyfin.models.View
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import timber.log.Timber
|
||||
import java.io.Serializable
|
||||
|
||||
fun BaseItemDto.toView(): View {
|
||||
return View(
|
||||
|
@ -51,3 +54,8 @@ fun ImageButton.setTintColorAttribute(@AttrRes attributeId: Int, theme: Resource
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
inline fun <reified T : Serializable> Bundle.serializable(key: String): T? = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializable(key, T::class.java)
|
||||
else -> @Suppress("DEPRECATION") getSerializable(key) as? T
|
||||
}
|
Loading…
Reference in a new issue