From f91927b4addaf61e25b63c1814a54a460160ecb9 Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 14 Mar 2024 15:46:36 +0100 Subject: [PATCH] fix: crash after rotating device in open content (#256) * fix: crash after rotating device in open content * refactor: removed unused variable --- .../course/presentation/unit/html/HtmlUnitFragment.kt | 2 +- .../presentation/unit/video/EncodedVideoUnitViewModel.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 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..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 @@ -80,9 +79,10 @@ 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 -> + castPlayer = CastPlayer(castContext) + } } }