Loading app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +11 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type Loading @@ -55,6 +56,7 @@ class MainActivityViewModel @Inject constructor( private val dataStoreModule: DataStoreModule, private val fusedAPIRepository: FusedAPIRepository, private val fusedManagerRepository: FusedManagerRepository, private val pkgManagerModule: PkgManagerModule ) : ViewModel() { val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData() Loading Loading @@ -278,4 +280,13 @@ class MainActivityViewModel @Inject constructor( val internetConnection = liveData { emitSource(ReactiveNetwork().observeInternetConnectivity().asLiveData(Dispatchers.Default)) } fun updateStatusOfFusedApps(fusedAppList: List<FusedApp>, fusedDownloadList: List<FusedDownload>) { fusedAppList.forEach { val downloadingItem = fusedDownloadList.find { fusedDownload -> fusedDownload.origin == it.origin && (fusedDownload.packageName == it.package_name || fusedDownload.id == it._id) } it.status = downloadingItem?.status ?: pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code) } } } app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +9 −9 Original line number Diff line number Diff line Loading @@ -84,15 +84,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu private fun observeDownloadList() { mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val categoryList = viewModel.appListLiveData.value?.toMutableList() if (!categoryList.isNullOrEmpty()) { list.forEach { categoryList.find { app -> app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } viewModel.appListLiveData.value = categoryList val appList = viewModel.appListLiveData.value?.toMutableList() appList?.let { mainActivityViewModel.updateStatusOfFusedApps(it, list) } viewModel.appListLiveData.value = appList } } Loading Loading @@ -120,7 +116,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu ) { fusedApp -> ApplicationDialogFragment( title = getString(R.string.dialog_title_paid_app, fusedApp.name), message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), message = getString( R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price ), positiveButtonText = getString(R.string.dialog_confirm), positiveButtonAction = { getApplication(fusedApp) Loading app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt +2 −17 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.api.fused.data.FusedHome import foundation.e.apps.databinding.HomeParentListItemBinding import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.User Loading @@ -43,6 +42,7 @@ class HomeParentRVAdapter( ) : ListAdapter<FusedHome, HomeParentRVAdapter.ViewHolder>(FusedHomeDiffUtil()) { private val viewPool = RecyclerView.RecycledViewPool() private var isDownloadObserverAdded = false inner class ViewHolder(val binding: HomeParentListItemBinding) : RecyclerView.ViewHolder(binding.root) Loading Loading @@ -79,26 +79,11 @@ class HomeParentRVAdapter( homeChildRVAdapter: RecyclerView.Adapter<*>? ) { mainActivityViewModel.downloadList.observe(lifecycleOwner) { updateInstallingAppStatus(it, fusedHome) mainActivityViewModel.updateStatusOfFusedApps(fusedHome.list, it) (homeChildRVAdapter as HomeChildRVAdapter).setData(fusedHome.list) } } private fun updateInstallingAppStatus( downloadList: List<FusedDownload>, fusedHome: FusedHome ) { downloadList.forEach { fusedDownload -> findInstallingApp(fusedHome, fusedDownload)?.status = fusedDownload.status } } private fun findInstallingApp(fusedHome: FusedHome, fusedDownload: FusedDownload): FusedApp? { return fusedHome.list.find { app -> app.origin == fusedDownload.origin && (app.package_name == fusedDownload.packageName || app._id == fusedDownload.id) } } fun setData(newList: List<FusedHome>) { submitList(newList.map { it.copy() }) } Loading app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +8 −6 Original line number Diff line number Diff line Loading @@ -119,7 +119,10 @@ class InstallAppWorker @AssistedInject constructor( ) { databaseRepository.getDownloadFlowById(it.id).takeWhile { isDownloading } .collect { fusedDownload -> fusedDownload?.let { if (fusedDownload == null) { isDownloading = false return@collect } Log.d( TAG, "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}" Loading @@ -127,7 +130,6 @@ class InstallAppWorker @AssistedInject constructor( handleFusedDownloadStatus(fusedDownload) } } } private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { when (fusedDownload.status) { Loading app/src/main/java/foundation/e/apps/search/SearchFragment.kt +4 −8 Original line number Diff line number Diff line Loading @@ -164,15 +164,11 @@ class SearchFragment : } mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val searchResult = searchViewModel.searchResult.value?.toMutableList() if (!searchResult.isNullOrEmpty()) { list.forEach { searchResult.find { app -> app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } searchViewModel.searchResult.value = searchResult val searchList = searchViewModel.searchResult.value?.toMutableList() searchList?.let { mainActivityViewModel.updateStatusOfFusedApps(searchList, list) } searchViewModel.searchResult.value = searchList } searchViewModel.searchResult.observe(viewLifecycleOwner) { Loading Loading
app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +11 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type Loading @@ -55,6 +56,7 @@ class MainActivityViewModel @Inject constructor( private val dataStoreModule: DataStoreModule, private val fusedAPIRepository: FusedAPIRepository, private val fusedManagerRepository: FusedManagerRepository, private val pkgManagerModule: PkgManagerModule ) : ViewModel() { val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData() Loading Loading @@ -278,4 +280,13 @@ class MainActivityViewModel @Inject constructor( val internetConnection = liveData { emitSource(ReactiveNetwork().observeInternetConnectivity().asLiveData(Dispatchers.Default)) } fun updateStatusOfFusedApps(fusedAppList: List<FusedApp>, fusedDownloadList: List<FusedDownload>) { fusedAppList.forEach { val downloadingItem = fusedDownloadList.find { fusedDownload -> fusedDownload.origin == it.origin && (fusedDownload.packageName == it.package_name || fusedDownload.id == it._id) } it.status = downloadingItem?.status ?: pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code) } } }
app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +9 −9 Original line number Diff line number Diff line Loading @@ -84,15 +84,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu private fun observeDownloadList() { mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val categoryList = viewModel.appListLiveData.value?.toMutableList() if (!categoryList.isNullOrEmpty()) { list.forEach { categoryList.find { app -> app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } viewModel.appListLiveData.value = categoryList val appList = viewModel.appListLiveData.value?.toMutableList() appList?.let { mainActivityViewModel.updateStatusOfFusedApps(it, list) } viewModel.appListLiveData.value = appList } } Loading Loading @@ -120,7 +116,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu ) { fusedApp -> ApplicationDialogFragment( title = getString(R.string.dialog_title_paid_app, fusedApp.name), message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price), message = getString( R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price ), positiveButtonText = getString(R.string.dialog_confirm), positiveButtonAction = { getApplication(fusedApp) Loading
app/src/main/java/foundation/e/apps/home/model/HomeParentRVAdapter.kt +2 −17 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import foundation.e.apps.api.fused.FusedAPIInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.api.fused.data.FusedHome import foundation.e.apps.databinding.HomeParentListItemBinding import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.User Loading @@ -43,6 +42,7 @@ class HomeParentRVAdapter( ) : ListAdapter<FusedHome, HomeParentRVAdapter.ViewHolder>(FusedHomeDiffUtil()) { private val viewPool = RecyclerView.RecycledViewPool() private var isDownloadObserverAdded = false inner class ViewHolder(val binding: HomeParentListItemBinding) : RecyclerView.ViewHolder(binding.root) Loading Loading @@ -79,26 +79,11 @@ class HomeParentRVAdapter( homeChildRVAdapter: RecyclerView.Adapter<*>? ) { mainActivityViewModel.downloadList.observe(lifecycleOwner) { updateInstallingAppStatus(it, fusedHome) mainActivityViewModel.updateStatusOfFusedApps(fusedHome.list, it) (homeChildRVAdapter as HomeChildRVAdapter).setData(fusedHome.list) } } private fun updateInstallingAppStatus( downloadList: List<FusedDownload>, fusedHome: FusedHome ) { downloadList.forEach { fusedDownload -> findInstallingApp(fusedHome, fusedDownload)?.status = fusedDownload.status } } private fun findInstallingApp(fusedHome: FusedHome, fusedDownload: FusedDownload): FusedApp? { return fusedHome.list.find { app -> app.origin == fusedDownload.origin && (app.package_name == fusedDownload.packageName || app._id == fusedDownload.id) } } fun setData(newList: List<FusedHome>) { submitList(newList.map { it.copy() }) } Loading
app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +8 −6 Original line number Diff line number Diff line Loading @@ -119,7 +119,10 @@ class InstallAppWorker @AssistedInject constructor( ) { databaseRepository.getDownloadFlowById(it.id).takeWhile { isDownloading } .collect { fusedDownload -> fusedDownload?.let { if (fusedDownload == null) { isDownloading = false return@collect } Log.d( TAG, "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}" Loading @@ -127,7 +130,6 @@ class InstallAppWorker @AssistedInject constructor( handleFusedDownloadStatus(fusedDownload) } } } private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { when (fusedDownload.status) { Loading
app/src/main/java/foundation/e/apps/search/SearchFragment.kt +4 −8 Original line number Diff line number Diff line Loading @@ -164,15 +164,11 @@ class SearchFragment : } mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> val searchResult = searchViewModel.searchResult.value?.toMutableList() if (!searchResult.isNullOrEmpty()) { list.forEach { searchResult.find { app -> app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id) }?.status = it.status } searchViewModel.searchResult.value = searchResult val searchList = searchViewModel.searchResult.value?.toMutableList() searchList?.let { mainActivityViewModel.updateStatusOfFusedApps(searchList, list) } searchViewModel.searchResult.value = searchList } searchViewModel.searchResult.observe(viewLifecycleOwner) { Loading