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

Verified Commit a42ea6a3 authored by Saalim Quadri's avatar Saalim Quadri
Browse files

fix: Instant redirect for Play Store deep links in PWA/OSS mode



* Also rename observeAppNotFoundAutoRedirect to observeAutoRedirect

Signed-off-by: default avatarSaalim Quadri <danascape@gmail.com>
parent dc021c88
Loading
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ class MainActivity : AppCompatActivity() {
                }

                launch {
                    observeAppNotFoundAutoRedirect()
                    observeAutoRedirect()
                }
            }
        }
@@ -598,11 +598,21 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeAppNotFoundAutoRedirect() {
        EventBus.events.filterIsInstance<AppEvent.AppNotFoundAutoRedirect>()
            .collectLatest {
    private suspend fun observeAutoRedirect() {
        EventBus.events.filterIsInstance<AppEvent.AutoRedirectHome>()
            .collectLatest { event ->
                event.message?.let { messageResId ->
                    showSnackbarMessage(getString(messageResId))
                }

                try {
                    findNavController(R.id.fragment).navigateUp()
                    val navController = findNavController(R.id.fragment)

                    if (event.message != null && navController.currentDestination?.id == R.id.applicationFragment) {
                        navController.navigate(R.id.action_applicationFragment_to_homeFragment)
                    } else {
                        navController.navigateUp()
                    }
                } catch (e: IllegalArgumentException) {
                    Timber.w(e, "Failed to navigate up from app not found")

+4 −2
Original line number Diff line number Diff line
@@ -90,7 +90,9 @@ class ApplicationViewModel @Inject constructor(
         * GPlayAuth, it will only have CleanApkAuth.
         */
        if (gPlayObj == null && params.source == Source.PLAY_STORE) {
            _errorMessageLiveData.postValue(R.string.gplay_data_for_oss)
            viewModelScope.launch {
                EventBus.invokeEvent(AppEvent.AutoRedirectHome(R.string.gplay_data_for_oss))
            }
            return
        }

@@ -240,7 +242,7 @@ class ApplicationViewModel @Inject constructor(
    private fun scheduleAutoRedirect() {
        viewModelScope.launch {
            delay(REDIRECT_DELAY_MS)
            EventBus.invokeEvent(AppEvent.AppNotFoundAutoRedirect())
            EventBus.invokeEvent(AppEvent.AutoRedirectHome())
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -41,5 +41,5 @@ sealed class AppEvent(val data: Any) {
        val onClose: CompletableDeferred<Unit>? = null
    ) : AppEvent(type)
    class SuccessfulLogin(user: User): AppEvent(user)
    class AppNotFoundAutoRedirect : AppEvent(Unit)
    class AutoRedirectHome(val message: Int? = null) : AppEvent(message ?: Unit)
}