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

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

fix(updates): ensure off-screen updates have correct button state/UI

Keep the updates list and adapter state in sync when progress tracking loses a download so recycled rows stop showing stale install controls.
parent 5ac17dd5
Loading
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI

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

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

    private fun restoreInstallButton(
        adapter: ApplicationListRVAdapter,
        recyclerView: RecyclerView,
        index: Int,
        fusedApp: Application
    ) {
    private fun restoreInstallButton(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)
        val updatedApps = displayedUpdates.map { displayedApp ->
            if (displayedApp._id == restoredApp._id) {
                displayedApp.copy(status = restoredApp.status)
            } else {
                displayedApp
            }
        }

        displayedUpdates = updatedApps
        updatesListAdapter?.setData(updatedApps)
        updateButtonAvailability()
    }

    override fun onDestroyView() {