From 8d3846394c9667a1fc3241b0c3563045b94bbcd0 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Wed, 18 Sep 2024 12:17:48 +0600 Subject: [PATCH] fix: lifecycleScope of the coroutine --- .../e/apps/ui/application/ApplicationFragment.kt | 6 +++--- .../apps/ui/applicationlist/ApplicationListFragment.kt | 2 +- .../java/foundation/e/apps/ui/home/HomeFragment.kt | 2 +- .../java/foundation/e/apps/ui/search/SearchFragment.kt | 2 +- .../foundation/e/apps/ui/updates/UpdatesFragment.kt | 10 +++++++--- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt index 210a4aa11..2540de6f3 100644 --- a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt @@ -503,7 +503,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) { } private fun collectShareVisibilityState() { - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.RESUMED) { applicationViewModel.shareButtonVisibilityState.collectLatest { state -> when (state) { @@ -516,7 +516,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) { } private fun collectAppContentRatingState() { - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.RESUMED) { applicationViewModel.appContentRatingState .collectLatest(::updateContentRatingUi) @@ -759,7 +759,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) { downloadPB.visibility = View.VISIBLE appSize.visibility = View.GONE applicationViewModel.downloadProgress.observe(viewLifecycleOwner) { - lifecycleScope.launch(Dispatchers.Main) { + viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) { updateProgress(it) } } diff --git a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt index 01ecf4c07..909c6a896 100644 --- a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt @@ -307,7 +307,7 @@ class ApplicationListFragment : downloadProgress: DownloadProgress ) { val adapter = recyclerView.adapter as ApplicationListRVAdapter - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { adapter.currentList.forEach { fusedApp -> if (fusedApp.status == Status.DOWNLOADING) { val progress = diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt index e086de665..91ac8ad0e 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt @@ -227,7 +227,7 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall downloadProgress: DownloadProgress, childRV: RecyclerView ) { - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { updateDownloadProgressOfAppList(adapter, downloadProgress, childRV) } } diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt index e3db9336c..f81383409 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt @@ -384,7 +384,7 @@ class SearchFragment : private fun updateProgressOfInstallingApps(downloadProgress: DownloadProgress) { val adapter = recyclerView?.adapter as ApplicationListRVAdapter - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { adapter.currentList.forEach { fusedApp -> if (fusedApp.status == Status.DOWNLOADING) { val progress = diff --git a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt index f22b69256..9ba5a6fee 100644 --- a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt @@ -23,8 +23,10 @@ import android.view.View import androidx.appcompat.app.AlertDialog import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager @@ -173,8 +175,10 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI WorkManager.getInstance(requireContext()) .getWorkInfosForUniqueWorkLiveData(INSTALL_WORK_NAME) .observe(viewLifecycleOwner) { workInfoList -> - lifecycleScope.launchWhenResumed { - binding.button.isEnabled = shouldUpdateButtonEnable(workInfoList) + viewLifecycleOwner.lifecycleScope.launch { + repeatOnLifecycle(Lifecycle.State.RESUMED) { + binding.button.isEnabled = shouldUpdateButtonEnable(workInfoList) + } } } } @@ -353,7 +357,7 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI downloadProgress: DownloadProgress ) { val adapter = recyclerView.adapter as ApplicationListRVAdapter - lifecycleScope.launch { + viewLifecycleOwner.lifecycleScope.launch { adapter.currentList.forEach { fusedApp -> if (fusedApp.status == Status.DOWNLOADING) { val progress = -- GitLab