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 14aef8e7242945c603d82b71feb484fc63b0627d..7cbe70d995132f34d124497d9a01e590bebaa3d8 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -259,8 +259,6 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { if (appInfoFetchViewModel.isAppInBlockedList(it)) { binding.snackbarLayout.visibility = View.VISIBLE } - - observeDownloadStatus(view) fetchAppTracker(it) } @@ -323,6 +321,11 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { } } + override fun onResume() { + super.onResume() + observeDownloadStatus(binding.root) + } + private fun handleInstallingIssue( installButton: MaterialButton, fusedApp: FusedApp, 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 e0b206aa5e3605f427b93123abd4c4139adc1e77..7041ea3728165cc9092e862a966522f13e41d58e 100644 --- a/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt @@ -143,10 +143,6 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu layoutManager = LinearLayoutManager(view?.context) } - appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { - updateProgressOfDownloadingItems(recyclerView, it) - } - viewModel.appListLiveData.observe(viewLifecycleOwner) { listAdapter?.setData(it) if (!isDownloadObserverAdded) { @@ -184,6 +180,10 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu } } } + + appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { + updateProgressOfDownloadingItems(recyclerView, it) + } } private fun updateProgressOfDownloadingItems( diff --git a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt index 0516c34693eaae23507cfd3362cb9ef2ab43b310..7f0e34340d3a73053654bc47546ca726c84bce49 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -51,6 +51,7 @@ import javax.inject.Inject @AndroidEntryPoint class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { + private lateinit var homeParentRVAdapter: HomeParentRVAdapter private var _binding: FragmentHomeBinding? = null private val binding get() = _binding!! @@ -83,7 +84,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { } } - val homeParentRVAdapter = HomeParentRVAdapter( + homeParentRVAdapter = HomeParentRVAdapter( this, pkgManagerModule, pwaManagerModule, @@ -123,10 +124,6 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { }, it.second) } } - - appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { - updateProgressOfDownloadingAppItemViews(homeParentRVAdapter, it) - } } /* @@ -190,6 +187,9 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { override fun onResume() { super.onResume() binding.shimmerLayout.startShimmer() + appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { + updateProgressOfDownloadingAppItemViews(homeParentRVAdapter, it) + } } override fun onPause() { 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 f461c1b56b98ddddebf69f037523e60b45b4ac9d..b606f3b9b0280624308c098a33b7be0342650c43 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 @@ -31,12 +31,11 @@ class DownloadProgressLD @Inject constructor( override fun observe(owner: LifecycleOwner, observer: Observer) { job = Job() super.observe(owner, observer) - } - override fun onActive() { - super.onActive() + val hasActiveObservers = hasActiveObservers() + launch { - while (isActive) { + while (hasActiveObservers) { val downloads = fusedManagerRepository.getDownloadList() val downloadingList = downloads.map { it.downloadIdMap }.filter { it.values.contains(false) } @@ -80,7 +79,6 @@ class DownloadProgressLD @Inject constructor( } if (downloadingIds.isEmpty()) { - clearDownload() cancel() } cursor.moveToNext() diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 7cf486ab4591862ac24369b1fc72ee4a70a1440e..91e0ba2ada8c2734451203b9fcebf5e82c01fdc5 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -49,6 +49,7 @@ 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.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User @@ -151,26 +152,6 @@ class SearchFragment : layoutManager = LinearLayoutManager(view.context) } - appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { - val adapter = recyclerView?.adapter as ApplicationListRVAdapter - lifecycleScope.launch { - adapter.currentList.forEach { fusedApp -> - if (fusedApp.status == Status.DOWNLOADING) { - val progress = appProgressViewModel.calculateProgress(fusedApp, it) - val downloadProgress = - ((progress.second / progress.first.toDouble()) * 100).toInt() - val viewHolder = recyclerView?.findViewHolderForAdapterPosition( - adapter.currentList.indexOf(fusedApp) - ) - viewHolder?.let { - (viewHolder as ApplicationListRVAdapter.ViewHolder).binding.installButton.text = - "$downloadProgress%" - } - } - } - } - } - mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val searchList = searchViewModel.searchResult.value?.toMutableList() @@ -199,9 +180,33 @@ class SearchFragment : } } + private fun updateProgressOfInstallingApps(downloadProgress: DownloadProgress) { + val adapter = recyclerView?.adapter as ApplicationListRVAdapter + lifecycleScope.launch { + adapter.currentList.forEach { fusedApp -> + if (fusedApp.status == Status.DOWNLOADING) { + val progress = + appProgressViewModel.calculateProgress(fusedApp, downloadProgress) + val downloadProgress = + ((progress.second / progress.first.toDouble()) * 100).toInt() + val viewHolder = recyclerView?.findViewHolderForAdapterPosition( + adapter.currentList.indexOf(fusedApp) + ) + viewHolder?.let { + (viewHolder as ApplicationListRVAdapter.ViewHolder).binding.installButton.text = + "$downloadProgress%" + } + } + } + } + } + override fun onResume() { super.onResume() binding.shimmerLayout.startShimmer() + appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { + updateProgressOfInstallingApps(it) + } } override fun onPause() { diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index eb03b02d953800a39b6b5422844900a9c5f1240c..65a116ba1d1e71f099be7cdb082d480135386fa8 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -121,10 +121,6 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { layoutManager = LinearLayoutManager(view.context) } - appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { - updateProgressOfDownloadingItems(recyclerView, it) - } - updatesViewModel.updatesList.observe(viewLifecycleOwner) { listAdapter?.setData(it) if (!isDownloadObserverAdded) { @@ -143,6 +139,12 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { } } + override fun onResume() { + super.onResume() + appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) { + updateProgressOfDownloadingItems(binding.recyclerView, it) + } + } private fun observeDownloadList() { mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val appList = updatesViewModel.updatesList.value?.toMutableList()