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

Commit a52336fa authored by Fahim M. Choudhury's avatar Fahim M. Choudhury Committed by Fahim M. Choudhury
Browse files

refactor(search): resolve install button's action when it's stuck on indefinite progress indicator

For error scenarios where install button's action was set to NoOp, there was no handling for it. Hence, clicking on the button wouldn't perform any action.

This commit fixes the issue by canceling any pending operation when such scenario occurs.
parent ea4b695e
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ data class PrimaryActionUiState(
    val isFilledStyle: Boolean,
    val isDisabledStyle: Boolean = false,
    val showMore: Boolean = false,
    val actionIntent: InstallButtonAction = InstallButtonAction.NoOp,
    val actionIntent: InstallButtonAction = InstallButtonAction.ShowUnsupportedDialog,
    val progressFraction: Float = 0f,
)

+8 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ data class InstallButtonState(
    val showProgressBar: Boolean = false,
    val progressPercentText: String? = null,
    val progressFraction: Float = 0f,
    val actionIntent: InstallButtonAction = InstallButtonAction.NoOp,
    val actionIntent: InstallButtonAction = InstallButtonAction.ShowUnsupportedDialog,
    @StringRes val snackbarMessageId: Int? = null,
    val dialogType: InstallDialogType? = null,
    val statusTag: StatusTag = StatusTag.Unknown,
@@ -58,7 +58,13 @@ enum class InstallButtonStyle {
}

enum class InstallButtonAction {
    Install, CancelDownload, OpenAppOrPwa, UpdateSelfConfirm, ShowPaidDialog, ShowBlockedSnackbar, NoOp,
    Install,
    CancelDownload,
    OpenAppOrPwa,
    UpdateSelfConfirm,
    ShowPaidDialog,
    ShowBlockedSnackbar,
    ShowUnsupportedDialog,
}

enum class InstallDialogType {
+9 −9
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ private fun mapUpdatable(input: InstallButtonStateInput): InstallButtonState {
        enabled = true,
        style = buildStyleFor(status = Status.UPDATABLE, enabled = true),
        actionIntent = when {
            unsupported -> InstallButtonAction.NoOp
            unsupported -> InstallButtonAction.ShowUnsupportedDialog
            input.isSelfUpdate -> InstallButtonAction.UpdateSelfConfirm
            else -> InstallButtonAction.Install
        },
@@ -81,7 +81,7 @@ private fun mapUnavailableUnsupported(): InstallButtonState {
        label = ButtonLabel(resId = R.string.not_available),
        enabled = true,
        style = buildStyleFor(Status.UNAVAILABLE, enabled = true),
        actionIntent = InstallButtonAction.NoOp,
        actionIntent = InstallButtonAction.ShowUnsupportedDialog,
        statusTag = StatusTag.UnavailableUnsupported,
    )
}
@@ -114,7 +114,7 @@ private fun mapUnavailablePaid(input: InstallButtonStateInput): InstallButtonSta
            enabled = false,
            style = buildStyleFor(Status.UNAVAILABLE, enabled = false),
            showProgressBar = true,
            actionIntent = InstallButtonAction.NoOp,
            actionIntent = InstallButtonAction.ShowUnsupportedDialog,
            statusTag = StatusTag.UnavailablePaid,
        )

@@ -169,9 +169,9 @@ private fun mapDownloading(input: InstallButtonStateInput, status: Status): Inst
private fun mapInstalling(status: Status): InstallButtonState {
    return InstallButtonState(
        label = ButtonLabel(resId = R.string.installing),
        enabled = true,
        style = buildStyleFor(status, enabled = true),
        actionIntent = InstallButtonAction.NoOp,
        enabled = false,
        style = buildStyleFor(status, enabled = false),
        actionIntent = InstallButtonAction.ShowUnsupportedDialog,
        statusTag = StatusTag.Installing,
        rawStatus = status,
    )
@@ -208,9 +208,9 @@ private fun mapInstallationIssue(input: InstallButtonStateInput): InstallButtonS
private fun mapUnknown(input: InstallButtonStateInput): InstallButtonState {
    return InstallButtonState(
        label = ButtonLabel(resId = R.string.install),
        enabled = true,
        style = InstallButtonStyle.AccentOutline,
        actionIntent = InstallButtonAction.NoOp,
        enabled = false,
        style = InstallButtonStyle.Disabled,
        actionIntent = InstallButtonAction.ShowUnsupportedDialog,
        statusTag = StatusTag.Unknown,
        rawStatus = input.app.status,
    )
+4 −3
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
                    enabled = true,
                    style = InstallButtonStyle.Disabled,
                    showProgressBar = true,
                    actionIntent = InstallButtonAction.NoOp,
                    actionIntent = InstallButtonAction.CancelDownload,
                )
            } else {
                mapInstallButtonState(
@@ -309,8 +309,9 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
            InstallButtonAction.ShowBlockedSnackbar -> {
                showBlockedSnackbar()
            }

            InstallButtonAction.NoOp -> Unit
            InstallButtonAction.ShowUnsupportedDialog -> {
                mainActivityViewModel.checkUnsupportedApplication(app, requireContext())
            }
        }
    }

+9 −7
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ class InstallButtonStateMapperTest {
    }

    @Test
    fun updatable_unsupported_is_noop() {
    fun updatable_unsupported_shows_unsupported_dialog() {
        val state = mapAppToInstallState(
            input = defaultInput(
                app = baseApp(Status.UPDATABLE),
@@ -113,7 +113,7 @@ class InstallButtonStateMapperTest {
            ),
        )
        assertEquals(R.string.not_available, state.label.resId)
        assertEquals(InstallButtonAction.NoOp, state.actionIntent)
        assertEquals(InstallButtonAction.ShowUnsupportedDialog, state.actionIntent)
        assertEquals(StatusTag.Updatable, state.statusTag)
    }

@@ -170,7 +170,7 @@ class InstallButtonStateMapperTest {
    }

    @Test
    fun unavailable_unsupported_noop() {
    fun unavailable_unsupported_shows_unsupported_dialog() {
        val state = mapAppToInstallState(
            input = defaultInput(
                app = baseApp(Status.UNAVAILABLE, isFree = false, price = PAID_PRICE),
@@ -178,7 +178,7 @@ class InstallButtonStateMapperTest {
            ),
        )
        assertEquals(R.string.not_available, state.label.resId)
        assertEquals(InstallButtonAction.NoOp, state.actionIntent)
        assertEquals(InstallButtonAction.ShowUnsupportedDialog, state.actionIntent)
        assertEquals(StatusTag.UnavailableUnsupported, state.statusTag)
    }

@@ -245,7 +245,7 @@ class InstallButtonStateMapperTest {
            input = defaultInput(app = baseApp(Status.INSTALLING)),
        )
        assertEquals(R.string.installing, state.label.resId)
        assertTrue(state.enabled)
        assertFalse(state.enabled)
        assertEquals(StatusTag.Installing, state.statusTag)
    }

@@ -320,12 +320,14 @@ class InstallButtonStateMapperTest {
    }

    @Test
    fun purchase_needed_status_defaults_to_noop() {
    fun purchase_needed_status_defaults_to_unsupported_dialog_intent() {
        val app = baseApp(Status.PURCHASE_NEEDED)
        val state = mapAppToInstallState(
            input = defaultInput(app = app),
        )
        assertEquals(InstallButtonAction.NoOp, state.actionIntent)
        assertFalse(state.enabled)
        assertEquals(InstallButtonAction.ShowUnsupportedDialog, state.actionIntent)
        assertFalse(state.actionIntent == InstallButtonAction.CancelDownload)
        assertEquals(StatusTag.Unknown, state.statusTag)
    }
}