Loading app/src/main/java/foundation/e/apps/AppProgressViewModel.kt +16 −4 Original line number Diff line number Diff line Loading @@ -19,15 +19,19 @@ class AppProgressViewModel @Inject constructor( suspend fun calculateProgress( fusedApp: FusedApp?, progress: DownloadProgress ): Pair<Long, Long> { ): Int { fusedApp?.let { app -> val appDownload = fusedManagerRepository.getDownloadList() .singleOrNull { it.id.contentEquals(app._id) && it.packageName.contentEquals(app.package_name) } ?: return Pair(1, 0) ?: return 0 if (!appDownload.id.contentEquals(app._id) || !appDownload.packageName.contentEquals(app.package_name)) { return@let } if (!isProgressValidForApp(fusedApp, progress)) { return -1 } val downloadingMap = progress.totalSizeBytes.filter { item -> appDownload.downloadIdMap.keys.contains(item.key) } Loading @@ -36,8 +40,16 @@ class AppProgressViewModel @Inject constructor( appDownload.downloadIdMap.keys.contains(item.key) }.values.sum() return Pair(totalSizeBytes, downloadedSoFar) return ((downloadedSoFar / totalSizeBytes.toDouble()) * 100).toInt() } return Pair(1, 0) return 0 } private suspend fun isProgressValidForApp( fusedApp: FusedApp, downloadProgress: DownloadProgress ): Boolean { val download = fusedManagerRepository.getFusedDownload(downloadProgress.downloadId) return download.id == fusedApp._id } } app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +6 −5 Original line number Diff line number Diff line Loading @@ -242,21 +242,22 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li private fun updateProgressOfDownloadingItems( recyclerView: RecyclerView, it: DownloadProgress downloadProgress: DownloadProgress ) { 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 progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress) if (progress == -1) { return@forEach } val viewHolder = recyclerView.findViewHolderForAdapterPosition( adapter.currentList.indexOf(fusedApp) ) viewHolder?.let { (viewHolder as ApplicationListRVAdapter.ViewHolder).binding.installButton.text = "$downloadProgress%" "$progress%" } } } Loading app/src/main/java/foundation/e/apps/home/HomeFragment.kt +4 −3 Original line number Diff line number Diff line Loading @@ -238,14 +238,15 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface if (fusedApp.status == Status.DOWNLOADING) { val progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress) val downloadProgress = ((progress.second / progress.first.toDouble()) * 100).toInt() if (progress == -1) { return@forEach } val childViewHolder = childRV.findViewHolderForAdapterPosition( adapter.currentList.indexOf(fusedApp) ) childViewHolder?.let { (childViewHolder as HomeChildRVAdapter.ViewHolder).binding.installButton.text = "$downloadProgress%" "$progress%" } } } Loading app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgress.kt +2 −1 Original line number Diff line number Diff line Loading @@ -3,5 +3,6 @@ package foundation.e.apps.manager.download.data data class DownloadProgress( var totalSizeBytes: MutableMap<Long, Long> = mutableMapOf(), var bytesDownloadedSoFar: MutableMap<Long, Long> = mutableMapOf(), var status: MutableMap<Long, Boolean> = mutableMapOf() var status: MutableMap<Long, Boolean> = mutableMapOf(), var downloadId: Long = -1 ) app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt +2 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ class DownloadProgressLD @Inject constructor( val bytesDownloadedSoFar = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) downloadProgress.downloadId = id if (!downloadProgress.totalSizeBytes.containsKey(id) || downloadProgress.totalSizeBytes[id] != totalSizeBytes ) { Loading Loading
app/src/main/java/foundation/e/apps/AppProgressViewModel.kt +16 −4 Original line number Diff line number Diff line Loading @@ -19,15 +19,19 @@ class AppProgressViewModel @Inject constructor( suspend fun calculateProgress( fusedApp: FusedApp?, progress: DownloadProgress ): Pair<Long, Long> { ): Int { fusedApp?.let { app -> val appDownload = fusedManagerRepository.getDownloadList() .singleOrNull { it.id.contentEquals(app._id) && it.packageName.contentEquals(app.package_name) } ?: return Pair(1, 0) ?: return 0 if (!appDownload.id.contentEquals(app._id) || !appDownload.packageName.contentEquals(app.package_name)) { return@let } if (!isProgressValidForApp(fusedApp, progress)) { return -1 } val downloadingMap = progress.totalSizeBytes.filter { item -> appDownload.downloadIdMap.keys.contains(item.key) } Loading @@ -36,8 +40,16 @@ class AppProgressViewModel @Inject constructor( appDownload.downloadIdMap.keys.contains(item.key) }.values.sum() return Pair(totalSizeBytes, downloadedSoFar) return ((downloadedSoFar / totalSizeBytes.toDouble()) * 100).toInt() } return Pair(1, 0) return 0 } private suspend fun isProgressValidForApp( fusedApp: FusedApp, downloadProgress: DownloadProgress ): Boolean { val download = fusedManagerRepository.getFusedDownload(downloadProgress.downloadId) return download.id == fusedApp._id } }
app/src/main/java/foundation/e/apps/applicationlist/ApplicationListFragment.kt +6 −5 Original line number Diff line number Diff line Loading @@ -242,21 +242,22 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li private fun updateProgressOfDownloadingItems( recyclerView: RecyclerView, it: DownloadProgress downloadProgress: DownloadProgress ) { 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 progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress) if (progress == -1) { return@forEach } val viewHolder = recyclerView.findViewHolderForAdapterPosition( adapter.currentList.indexOf(fusedApp) ) viewHolder?.let { (viewHolder as ApplicationListRVAdapter.ViewHolder).binding.installButton.text = "$downloadProgress%" "$progress%" } } } Loading
app/src/main/java/foundation/e/apps/home/HomeFragment.kt +4 −3 Original line number Diff line number Diff line Loading @@ -238,14 +238,15 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), FusedAPIInterface if (fusedApp.status == Status.DOWNLOADING) { val progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress) val downloadProgress = ((progress.second / progress.first.toDouble()) * 100).toInt() if (progress == -1) { return@forEach } val childViewHolder = childRV.findViewHolderForAdapterPosition( adapter.currentList.indexOf(fusedApp) ) childViewHolder?.let { (childViewHolder as HomeChildRVAdapter.ViewHolder).binding.installButton.text = "$downloadProgress%" "$progress%" } } } Loading
app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgress.kt +2 −1 Original line number Diff line number Diff line Loading @@ -3,5 +3,6 @@ package foundation.e.apps.manager.download.data data class DownloadProgress( var totalSizeBytes: MutableMap<Long, Long> = mutableMapOf(), var bytesDownloadedSoFar: MutableMap<Long, Long> = mutableMapOf(), var status: MutableMap<Long, Boolean> = mutableMapOf() var status: MutableMap<Long, Boolean> = mutableMapOf(), var downloadId: Long = -1 )
app/src/main/java/foundation/e/apps/manager/download/data/DownloadProgressLD.kt +2 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ class DownloadProgressLD @Inject constructor( val bytesDownloadedSoFar = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) downloadProgress.downloadId = id if (!downloadProgress.totalSizeBytes.containsKey(id) || downloadProgress.totalSizeBytes[id] != totalSizeBytes ) { Loading