Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea509841 authored by Hasib Prince's avatar Hasib Prince
Browse files

Fixed: showing progress in detail page and memory leak

parent 6cd1f0ac
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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()
    }

+19 −5
Original line number Diff line number Diff line
@@ -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<FusedApp, ApplicationListRVAdapter.ViewHolder>(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
    }
}
+2 −4
Original line number Diff line number Diff line
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<in DownloadProgress>) {
        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) }