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

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

fixed: memory leak in app list page

parent 2a450d9b
Loading
Loading
Loading
Loading
Loading
+3 −20
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentApplicationListBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -52,7 +51,8 @@ import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_list),
class ApplicationListFragment :
    TimeoutFragment(R.layout.fragment_application_list),
    FusedAPIInterface {

    private val args: ApplicationListFragmentArgs by navArgs()
@@ -162,7 +162,7 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
                onTimeout()
            } else {
                val currentList = listAdapter?.currentList
                if (it.data != null && !currentList.isNullOrEmpty() && !compareOldFusedAppsListWithNewFusedAppsList(
                if (it.data != null && !currentList.isNullOrEmpty() && !viewModel.hasAnyChangeBetweenOldFusedAppsListAndNewFusedAppsList(
                        it.data!!,
                        currentList
                    )
@@ -266,23 +266,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
        }
    }

    /**
     * @return returns true if there is changes in data, otherwise false
     */
    fun compareOldFusedAppsListWithNewFusedAppsList(
        newFusedApps: List<FusedApp>,
        oldFusedApps: List<FusedApp>
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()
        newFusedApps.forEach {
            val indexOfNewFusedApp = newFusedApps.indexOf(it)
            if (!fusedAppDiffUtil.areContentsTheSame(it, oldFusedApps[indexOfNewFusedApp])) {
                return true
            }
        }
        return false
    }

    private fun showLoadingUI() {
        binding.shimmerLayout.startShimmer()
        binding.shimmerLayout.visibility = View.VISIBLE
+23 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.api.ResultSupreme
import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.utils.enums.Origin
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -76,7 +77,7 @@ class ApplicationListViewModel @Inject constructor(
    private var hasNextStreamCluster = false

    fun getList(category: String, browseUrl: String, authData: AuthData, source: String) {
        if (appListLiveData.value?.data?.isNotEmpty() == true || isLoading) {
        if (isLoading) {
            return
        }
        viewModelScope.launch(Dispatchers.IO) {
@@ -97,6 +98,27 @@ class ApplicationListViewModel @Inject constructor(
        }
    }

    /**
     * @return returns true if there is changes in data, otherwise false
     */
    fun hasAnyChangeBetweenOldFusedAppsListAndNewFusedAppsList(
        newFusedApps: List<FusedApp>,
        oldFusedApps: List<FusedApp>
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()
        if (newFusedApps.size != oldFusedApps.size) {
            return true
        }

        newFusedApps.forEach {
            val indexOfNewFusedApp = newFusedApps.indexOf(it)
            if (!fusedAppDiffUtil.areContentsTheSame(it, oldFusedApps[indexOfNewFusedApp])) {
                return true
            }
        }
        return false
    }

    /**
     * Add a placeholder app at the end if more data can be loaded.
     * "Placeholder" app shows a simple progress bar in the RecyclerView, indicating that
+1 −3
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.api.fused.data.FusedHome
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.databinding.FragmentHomeBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.home.model.HomeChildRVAdapter
import foundation.e.apps.home.model.HomeParentRVAdapter
import foundation.e.apps.manager.download.data.DownloadProgress
@@ -51,7 +50,6 @@ import foundation.e.apps.utils.modules.CommonUtilsModule.safeNavigate
import foundation.e.apps.utils.modules.PWAManagerModule
import foundation.e.apps.utils.parentFragment.TimeoutFragment
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
@@ -165,7 +163,7 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface
        homeViewModel.homeScreenData.observe(viewLifecycleOwner) {
            stopLoadingUI()
            if (it.second == ResultStatus.OK) {
                if (homeParentRVAdapter?.currentList?.isNotEmpty() == true && !homeViewModel.compareNewHomeDataWithOldHomeData(
                if (homeParentRVAdapter?.currentList?.isNotEmpty() == true && !homeViewModel.hasAnyChangeBetweenNewHomeDataAndOldHomeData(
                        it.first,
                        homeParentRVAdapter?.currentList as List<FusedHome>
                    )
+8 −1
Original line number Diff line number Diff line
@@ -60,10 +60,17 @@ class HomeViewModel @Inject constructor(
        } ?: true
    }

    fun compareNewHomeDataWithOldHomeData(
    /**
     * @return true, if any change is found, otherwise false
     */
    fun hasAnyChangeBetweenNewHomeDataAndOldHomeData(
        newHomeData: List<FusedHome>,
        oldHomeData: List<FusedHome>
    ): Boolean {
        if (newHomeData.size != oldHomeData.size) {
            return true
        }

        oldHomeData.forEach {
            val fusedHome = newHomeData[oldHomeData.indexOf(it)]
            if (!it.title.contentEquals(fusedHome.title) || !areOldAndNewFusedAppListSame(it, fusedHome)) {
+4 −25
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentSearchBinding
import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -167,7 +166,7 @@ class SearchFragment :
                noAppsFoundLayout?.visibility = View.VISIBLE
            } else {
                val currentList = listAdapter?.currentList
                if (it.data?.first != null && !currentList.isNullOrEmpty() && !compareOldFusedAppsListWithNewFusedAppsList(
                if (it.data?.first != null && !currentList.isNullOrEmpty() && !searchViewModel.hasAnyChangeBetweenOldFusedAppsListAndNewFusedAppsList(
                        it.data?.first!!,
                        currentList
                    )
@@ -212,27 +211,6 @@ class SearchFragment :
        }
    }

    /**
     * @return returns true if there is changes in data, otherwise false
     */
    fun compareOldFusedAppsListWithNewFusedAppsList(
        newFusedApps: List<FusedApp>,
        oldFusedApps: List<FusedApp>
    ): Boolean {
        val fusedAppDiffUtil = HomeChildFusedAppDiffUtil()
        if (newFusedApps.size != oldFusedApps.size) {
            return true
        }
        
        newFusedApps.forEach {
            val indexOfNewFusedApp = newFusedApps.indexOf(it)
            if (!fusedAppDiffUtil.areContentsTheSame(it, oldFusedApps[indexOfNewFusedApp])) {
                return true
            }
        }
        return false
    }

    private fun observeDownloadList(applicationListRVAdapter: ApplicationListRVAdapter) {
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchList =
@@ -267,7 +245,7 @@ class SearchFragment :

    override fun refreshData(authData: AuthData) {
        showLoadingUI()
        searchViewModel.getSearchResults(searchText, authData, this)
        searchViewModel.getSearchResults(searchText, authData, viewLifecycleOwner)
    }

    private fun showLoadingUI() {
@@ -366,6 +344,7 @@ class SearchFragment :
        _binding = null
        searchView = null
        shimmerLayout = null
        recyclerView?.adapter = null
        recyclerView = null
        searchHintLayout = null
        noAppsFoundLayout = null
Loading