From 47855f0cf9fe19eb78a53ef7734ff1d77e6fe65b Mon Sep 17 00:00:00 2001 From: droid Date: Wed, 6 Mar 2024 13:55:32 +0100 Subject: [PATCH 1/2] fix: crash after rotating device in open content --- .../course/presentation/unit/html/HtmlUnitFragment.kt | 2 +- .../presentation/unit/video/EncodedVideoUnitViewModel.kt | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/course/src/main/java/org/openedx/course/presentation/unit/html/HtmlUnitFragment.kt b/course/src/main/java/org/openedx/course/presentation/unit/html/HtmlUnitFragment.kt index 124ceb327..a74b9d5ee 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/html/HtmlUnitFragment.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/html/HtmlUnitFragment.kt @@ -118,7 +118,7 @@ class HtmlUnitFragment : Fragment() { }, onWebPageLoaded = { isLoading = false - viewModel.setWebPageLoaded(requireContext().assets) + if (isAdded) viewModel.setWebPageLoaded(requireContext().assets) } ) } else { diff --git a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt index 1ff0df22e..260c0d48a 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt @@ -80,9 +80,11 @@ class EncodedVideoUnitViewModel( initPlayer() val executor = Executors.newSingleThreadExecutor() - castContext = CastContext.getSharedInstance(context, executor).result - castContext?.let { - castPlayer = CastPlayer(it) + CastContext.getSharedInstance(context, executor).addOnCompleteListener { + it.result?.let { castContext -> + this.castContext = castContext + castPlayer = CastPlayer(castContext) + } } } From 5682db4350978f4aa299a714ec0832e76251930b Mon Sep 17 00:00:00 2001 From: droid Date: Thu, 14 Mar 2024 09:53:31 +0100 Subject: [PATCH 2/2] refactor: removed unused variable --- .../course/presentation/unit/video/EncodedVideoUnitViewModel.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt index 260c0d48a..c49357161 100644 --- a/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/unit/video/EncodedVideoUnitViewModel.kt @@ -50,7 +50,6 @@ class EncodedVideoUnitViewModel( private set var castPlayer: CastPlayer? = null private set - private var castContext: CastContext? = null var isCastActive = false @@ -82,7 +81,6 @@ class EncodedVideoUnitViewModel( val executor = Executors.newSingleThreadExecutor() CastContext.getSharedInstance(context, executor).addOnCompleteListener { it.result?.let { castContext -> - this.castContext = castContext castPlayer = CastPlayer(castContext) } }