diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index 261c627c30b16c8cd654faf15c76372a9ebd4bd7..6e884d4712f85bd9a1e6cdc1d10c631d1c51a968 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -679,10 +679,16 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) { override fun onDestroyView() { super.onDestroyView() + _binding?.recyclerView?.adapter = null _binding = null applicationIcon = null } + override fun onPause() { + super.onPause() + mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner) + } + private fun shareApp(name: String, shareUrl: String): Intent { val shareIntent = Intent().apply { action = Intent.ACTION_SEND diff --git a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt index 8f7a324118876c48224d322bc4eb09eaf8968f3d..cb02d69392562f8befce4e5a21c42eb7ce1ade77 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -109,6 +109,7 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li override fun onDestroyView() { super.onDestroyView() + _binding?.recyclerView?.adapter = null _binding = null } @@ -297,6 +298,7 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li override fun onPause() { binding.shimmerLayout.stopShimmer() + mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner) super.onPause() } diff --git a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt index c6ed486a5bef397dba079989c203b00dad2b40db..d310cbdb405ca80ac120298d15168c696e1ebe87 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/model/ApplicationListRVAdapter.kt @@ -66,8 +66,8 @@ class ApplicationListRVAdapter( private val pkgManagerModule: PkgManagerModule, private val pwaManagerModule: PWAManagerModule, private val user: User, - private val lifecycleOwner: LifecycleOwner, - private val paidAppHandler: ((FusedApp) -> Unit)? = null + private var lifecycleOwner: LifecycleOwner?, + private var paidAppHandler: ((FusedApp) -> Unit)? = null ) : ListAdapter(ApplicationDiffUtil()) { private val TAG = ApplicationListRVAdapter::class.java.simpleName @@ -200,7 +200,9 @@ class ApplicationListRVAdapter( } private fun removeIsPurchasedObserver(holder: ViewHolder) { - holder.isPurchasedLiveData.removeObservers(lifecycleOwner) + lifecycleOwner?.let { + holder.isPurchasedLiveData.removeObservers(it) + } } private fun ApplicationListItemBinding.setupInstallButton( @@ -301,7 +303,10 @@ class ApplicationListRVAdapter( searchApp: FusedApp, view: View ) { - privacyInfoViewModel.getAppPrivacyInfoLiveData(searchApp).observe(lifecycleOwner) { + if (lifecycleOwner == null) { + return + } + privacyInfoViewModel.getAppPrivacyInfoLiveData(searchApp).observe(lifecycleOwner!!) { showPrivacyScore() val calculatedScore = privacyInfoViewModel.calculatePrivacyScore(searchApp) if (it.isSuccess() && calculatedScore != -1) { @@ -402,7 +407,10 @@ class ApplicationListRVAdapter( materialButton.text = "" applicationListItemBinding.progressBarInstall.visibility = View.VISIBLE holder.isPurchasedLiveData = appInfoFetchViewModel.isAppPurchased(searchApp) - holder.isPurchasedLiveData.observe(lifecycleOwner) { + if (lifecycleOwner == null) { + return + } + holder.isPurchasedLiveData.observe(lifecycleOwner!!) { materialButton.isEnabled = true applicationListItemBinding.progressBarInstall.visibility = View.GONE materialButton.text = @@ -471,4 +479,10 @@ class ApplicationListRVAdapter( private fun cancelDownload(searchApp: FusedApp) { fusedAPIInterface.cancelDownload(searchApp) } + + override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { + super.onDetachedFromRecyclerView(recyclerView) + lifecycleOwner = null + paidAppHandler = null + } } diff --git a/app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt b/app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt index bba55569252026569f6e5f498978a6394a80a09c..f196fe356cb0dcfbcf14643418dd622a3a542793 100644 --- a/app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt +++ b/app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt @@ -1,6 +1,7 @@ package foundation.e.apps.manager.download.data import android.app.DownloadManager +import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -30,11 +31,8 @@ class DownloadProgressLD @Inject constructor( override fun observe(owner: LifecycleOwner, observer: Observer) { job = Job() super.observe(owner, observer) - - val hasActiveObservers = hasActiveObservers() - launch { - while (hasActiveObservers) { + while (hasActiveObservers() || owner.lifecycle.currentState == Lifecycle.State.RESUMED) { val downloads = fusedManagerRepository.getDownloadList() val downloadingList = downloads.map { it.downloadIdMap }.filter { it.values.contains(false) }