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

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

Merge branch '4127-fix-search-install-button-state-on-error' into 'main'

refactor(search): resolve install button's action on error and app uninstallation events

See merge request !698
parents 07166f78 a52336fa
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,
    )
+9 −3
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
        setComposeContent(composeView)
    }

    override fun onResume() {
        super.onResume()
        searchViewModel.refreshInstallStatuses()
    }

    private fun setupComposeView(view: View): ComposeView {
        return view.findViewById<ComposeView>(R.id.composeView).apply {
            setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
@@ -172,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(
@@ -304,8 +309,9 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
            InstallButtonAction.ShowBlockedSnackbar -> {
                showBlockedSnackbar()
            }

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

+8 −2
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ class SearchViewModelV2 @Inject constructor(
    private val _scrollPositions = MutableStateFlow<Map<SearchTabType, ScrollPosition>>(emptyMap())
    private val statusSnapshot = MutableStateFlow<StatusSnapshot?>(null)
    private val downloadProgress = MutableStateFlow<DownloadProgress?>(null)
    private val installStatusRefreshTick = MutableStateFlow(0L)
    private val _progressPercentByKey = MutableStateFlow<Map<String, Int>>(emptyMap())
    val progressPercentByKey: StateFlow<Map<String, Int>> = _progressPercentByKey.asStateFlow()
    private val _statusByKey = MutableStateFlow<Map<String, Status>>(emptyMap())
@@ -299,12 +300,17 @@ class SearchViewModelV2 @Inject constructor(
        downloadProgress.value = progress
    }

    fun refreshInstallStatuses() {
        installStatusRefreshTick.update { it + 1 }
    }

    private fun Flow<PagingData<Application>>.withStatus(): Flow<PagingData<Application>> =
        combine(
            this,
            statusSnapshot.filterNotNull(),
            downloadProgress
        ) { paging: PagingData<Application>, snapshot: StatusSnapshot, progress: DownloadProgress? ->
            downloadProgress,
            installStatusRefreshTick
        ) { paging, snapshot, progress, _ ->
            paging.map { app -> reconcile(app, snapshot, progress) }
        }

Loading