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

Verified Commit ec0571a7 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

fix(updates): restore install button when download progress tracking ends

Treat missing download progress as no active update so the updates list can restore the install button instead of leaving items stuck in a download state.
parent e0df10b6
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ class DownloadProgressTracker @Inject constructor(
        application?.let { app ->
            val appDownload = appManager.getDownloadList()
                .singleOrNull { it.id.contentEquals(app._id) && it.packageName.contentEquals(app.package_name) }
                ?: return 0
                ?: return -1
            return calculateProgress(appDownload, progress)
        }
        return 0
        return -1
    }

    suspend fun calculateProgress(
+15 −9
Original line number Diff line number Diff line
@@ -144,17 +144,9 @@ class ApplicationListRVAdapter(
            updateRating(searchApp)
            updateSourceTag(searchApp)
            setAppIcon(searchApp, shimmerDrawable)
            removeIsPurchasedObserver(holder)

            setInstallButtonDimensions(view)

            if (appInfoFetchViewModel.isAppInBlockedList(searchApp)) {
                setupShowMoreButton()
            } else {
                mainActivityViewModel.verifyUiFilter(searchApp) {
                    setupInstallButton(searchApp, view, holder)
                }
            }
            bindInstallControls(holder, searchApp)
        }
    }

@@ -169,6 +161,20 @@ class ApplicationListRVAdapter(
        }
    }

    fun bindInstallControls(holder: ViewHolder, searchApp: Application = holder.app) {
        holder.app = searchApp
        removeIsPurchasedObserver(holder)
        with(holder.binding) {
            if (appInfoFetchViewModel.isAppInBlockedList(searchApp)) {
                setupShowMoreButton()
            } else {
                mainActivityViewModel.verifyUiFilter(searchApp) {
                    setupInstallButton(searchApp, holder.itemView, holder)
                }
            }
        }
    }

    companion object {
        private const val SHIMMER_DURATION_MS = 500L
        private const val SHIMMER_BASE_ALPHA = 0.7f
+21 −0
Original line number Diff line number Diff line
@@ -440,6 +440,7 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI

                val progress = appProgressViewModel.calculateProgress(fusedApp, downloadProgress)
                if (progress == -1) {
                    restoreInstallButton(adapter, recyclerView, index, fusedApp)
                    return@forEachIndexed
                }

@@ -452,6 +453,26 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI
        }
    }

    private fun restoreInstallButton(
        adapter: ApplicationListRVAdapter,
        recyclerView: RecyclerView,
        index: Int,
        fusedApp: Application
    ) {
        val restoredApp = fusedApp.copy()
        mainActivityViewModel.updateStatusOfFusedApps(
            applicationList = listOf(restoredApp),
            appInstallList = emptyList()
        )
        displayedUpdates.find { it._id == restoredApp._id }?.status = restoredApp.status
        updateButtonAvailability()

        val viewHolder = recyclerView.findViewHolderForAdapterPosition(index)
            as? ApplicationListRVAdapter.ViewHolder
            ?: return
        adapter.bindInstallControls(viewHolder, restoredApp)
    }

    override fun onDestroyView() {
        resetViewState()
        updatesListAdapter = null