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

Commit daa2c219 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

refactor(ui): make purchase and fallback state explicit

parent 6736ff72
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ private fun GoogleOAuthScreenTestContent(
        GoogleOAuthScreen(
            isSubmitting = isSubmitting,
            errorMessage = errorMessage,
            retryVersion = 0,
            onDismissError = { recorder.dismissErrorClicks += 1 },
            onNavigateUp = { recorder.navigateUpClicks += 1 },
            onGoogleLoginSubmit = { email, token ->
+13 −1
Original line number Diff line number Diff line
@@ -35,6 +35,13 @@ class GetAppDetailsUseCase @Inject constructor(
    private val playStoreRepository: PlayStoreRepository,
    private val getEnabledSearchSourcesUseCase: GetEnabledSearchSourcesUseCase,
) {
    companion object {
        private val SOURCE_PRIORITY = listOf(
            Source.OPEN_SOURCE,
            Source.PWA,
            Source.PLAY_STORE,
        )
    }

    suspend operator fun invoke(packageName: String, source: Source? = null): Application {
        if (blockedAppRepository.isBlockedApp(packageName)) {
@@ -85,7 +92,7 @@ class GetAppDetailsUseCase @Inject constructor(
        availableStores: List<Source>
    ): Application {
        var application: Application? = null
        for (store in availableStores.sorted()) {
        for (store in prioritizeAvailableStores(availableStores)) {
            try {
                application = getAppDetailsUnchecked(packageName, store)
                break
@@ -99,6 +106,11 @@ class GetAppDetailsUseCase @Inject constructor(
        )
    }

    private fun prioritizeAvailableStores(availableStores: List<Source>): List<Source> {
        val availableStoreSet = availableStores.toSet()
        return SOURCE_PRIORITY.filter(availableStoreSet::contains)
    }

    private suspend fun getAppDetailsUnchecked(packageName: String, source: Source) =
        when (source) {
            Source.OPEN_SOURCE -> {
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import foundation.e.apps.ui.compose.theme.AppTheme
fun GoogleOAuthScreen(
    isSubmitting: Boolean,
    errorMessage: String?,
    retryVersion: Int,
    onDismissError: () -> Unit,
    onNavigateUp: () -> Unit,
    onGoogleLoginSubmit: (String, String) -> Unit,
@@ -50,6 +51,7 @@ fun GoogleOAuthScreen(
    webContent: @Composable (Modifier) -> Unit = { webModifier ->
        GoogleOAuthWebView(
            isSubmitting = isSubmitting,
            retryVersion = retryVersion,
            onGoogleLoginSubmit = onGoogleLoginSubmit,
            modifier = webModifier,
        )
@@ -147,6 +149,7 @@ private fun GoogleOAuthPreview(
        GoogleOAuthScreen(
            isSubmitting = isSubmitting,
            errorMessage = errorMessage,
            retryVersion = 0,
            onDismissError = {},
            onNavigateUp = {},
            onGoogleLoginSubmit = { _, _ -> },
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
@@ -36,6 +38,7 @@ import foundation.e.apps.ui.compose.theme.AppTheme
class GoogleSignInFragment : Fragment() {

    private val viewModel: LoginViewModel by activityViewModels()
    private var retryVersion by mutableIntStateOf(0)

    override fun onCreateView(
        inflater: LayoutInflater,
@@ -51,7 +54,9 @@ class GoogleSignInFragment : Fragment() {
                    GoogleOAuthScreen(
                        isSubmitting = uiState.isSubmitting,
                        errorMessage = uiState.errorMessage,
                        retryVersion = retryVersion,
                        onDismissError = {
                            retryVersion += 1
                            viewModel.dismissError()
                        },
                        onNavigateUp = {
+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -38,6 +39,7 @@ import foundation.e.apps.feature.auth.login.GoogleOAuthCredentialsExtractor
@Composable
fun GoogleOAuthWebView(
    isSubmitting: Boolean,
    retryVersion: Int,
    onGoogleLoginSubmit: (String, String) -> Unit,
    modifier: Modifier = Modifier,
) {
@@ -73,6 +75,14 @@ fun GoogleOAuthWebView(
        },
    )

    LaunchedEffect(retryVersion) {
        if (retryVersion == 0) {
            return@LaunchedEffect
        }
        lastSubmissionKey = null
        webView?.reload()
    }

    DisposableEffect(Unit) {
        onDispose {
            webView?.apply {
Loading