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

Commit bfd180a5 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury Committed by Nishith Khanna
Browse files

refactor(ui): set disabled colour as install button's border for queued and awaiting status

parent 25243212
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
@@ -61,6 +62,7 @@ import foundation.e.apps.R
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.ui.compose.state.InstallButtonAction
import foundation.e.apps.ui.compose.theme.AppTheme
import foundation.e.elib.R as eR

@Composable
fun SearchResultListItem(
@@ -199,6 +201,7 @@ private fun PrimaryActionArea(
        val accentColor = MaterialTheme.colorScheme.tertiary
        val labelTextColor = when {
            uiState.isFilledStyle -> Color.White
            uiState.isDisabledStyle -> colorResource(eR.color.e_disabled_color)
            else -> accentColor
        }

@@ -226,6 +229,7 @@ private fun PrimaryActionArea(

        val borderColor = when {
            uiState.isFilledStyle -> Color.Transparent
            uiState.isDisabledStyle -> colorResource(eR.color.e_disabled_color)
            uiState.enabled -> accentColor
            else -> accentColor.copy(alpha = 0.38f)
        }
@@ -247,7 +251,6 @@ private fun PrimaryActionArea(
                    uiState.isFilledStyle -> accentColor.copy(alpha = 0.12f)
                    else -> Color.Transparent
                },
                disabledContentColor = labelTextColor.copy(alpha = 0.38f),
            ),
            border = BorderStroke(1.dp, borderColor),
            contentPadding = PaddingValues.Zero,
@@ -285,6 +288,7 @@ data class PrimaryActionUiState(
    val enabled: Boolean,
    val isInProgress: Boolean,
    val isFilledStyle: Boolean,
    val isDisabledStyle: Boolean = false,
    val showMore: Boolean = false,
    val actionIntent: InstallButtonAction = InstallButtonAction.NoOp,
    val progressFraction: Float = 0f,
+1 −0
Original line number Diff line number Diff line
@@ -576,6 +576,7 @@ private fun Application.toSearchResultUiState(buttonState: InstallButtonState):
            enabled = buttonState.enabled,
            isInProgress = buttonState.isInProgress(),
            isFilledStyle = buttonState.style == InstallButtonStyle.AccentFill,
            isDisabledStyle = buttonState.style == InstallButtonStyle.Disabled,
            showMore = false,
            actionIntent = buttonState.actionIntent,
            progressFraction = buttonState.progressFraction,
+3 −2
Original line number Diff line number Diff line
@@ -169,8 +169,8 @@ private fun mapDownloading(input: InstallButtonStateInput, status: Status): Inst
private fun mapInstalling(status: Status): InstallButtonState {
    return InstallButtonState(
        label = ButtonLabel(resId = R.string.installing),
        enabled = false,
        style = buildStyleFor(status, enabled = false),
        enabled = true,
        style = buildStyleFor(status, enabled = true),
        actionIntent = InstallButtonAction.NoOp,
        statusTag = StatusTag.Installing,
        rawStatus = status,
@@ -223,6 +223,7 @@ private fun buildDefaultBlockedLabel(app: Application): ButtonLabel {

private fun buildStyleFor(status: Status, enabled: Boolean): InstallButtonStyle {
    return when {
        status == Status.QUEUED || status == Status.AWAITING -> InstallButtonStyle.Disabled
        status == Status.INSTALLED || status == Status.UPDATABLE -> {
            if (enabled) InstallButtonStyle.AccentFill else InstallButtonStyle.Disabled
        }
+2 −2
Original line number Diff line number Diff line
@@ -169,8 +169,8 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
            if (isPending && (overrideStatus == null || overrideStatus == Status.UNAVAILABLE)) {
                InstallButtonState(
                    label = ButtonLabel(),
                    enabled = false,
                    style = InstallButtonStyle.AccentOutline,
                    enabled = true,
                    style = InstallButtonStyle.Disabled,
                    showProgressBar = true,
                    actionIntent = InstallButtonAction.NoOp,
                )
+21 −1
Original line number Diff line number Diff line
@@ -205,6 +205,26 @@ class InstallButtonStateMapperTest {
        assertEquals(InstallButtonAction.CancelDownload, state.actionIntent)
    }

    @Test
    fun queued_maps_to_disabled_style() {
        val state = mapAppToInstallState(
            input = defaultInput(app = baseApp(Status.QUEUED)),
        )
        assertEquals(R.string.cancel, state.label.resId)
        assertEquals(InstallButtonStyle.Disabled, state.style)
        assertTrue(state.enabled)
    }

    @Test
    fun awaiting_maps_to_disabled_style() {
        val state = mapAppToInstallState(
            input = defaultInput(app = baseApp(Status.AWAITING)),
        )
        assertEquals(R.string.cancel, state.label.resId)
        assertEquals(InstallButtonStyle.Disabled, state.style)
        assertTrue(state.enabled)
    }

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