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

Commit 59ceeca5 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

fix(deeplink): Fix deeplink broken due to auth not completing

parent 63a74ffd
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -153,7 +153,10 @@ class MainActivity : AppCompatActivity() {
        val (bottomNavigationView, navController) = setupBottomNav()

        if (savedInstanceState == null) {
            queueFdroidDeepLink(intent)
            val hasPendingFdroidDeepLink = queueFdroidDeepLink(intent)
            if (!hasPendingFdroidDeepLink) {
                navController.handleDeepLink(intent)
            }
        }

        setupViewModels()
+23 −2
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
    }

    private var isDetailsLoaded = false
    private var hasRequestedInitialAuthRefresh = false
    private lateinit var screenshotsRVAdapter: ApplicationScreenshotsRVAdapter
    private var uiRenderer: ApplicationUiRenderer? = null
    private var installUiBinder: ApplicationInstallUiBinder? = null
@@ -112,7 +113,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        setupToolbar(view)
        setupScreenshotRVAdapter()
        setupViewBinders()
        binding.applicationLayout.visibility = View.INVISIBLE
        showLoadingUI()

        uiRenderer?.collectState()
        observeAuthRefreshSnapshot()
@@ -134,7 +135,12 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        viewLifecycleOwner.lifecycleScope.launch {
            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                sessionViewModel.authRefreshSnapshotFlow.collectLatest { snapshot ->
                    if (snapshot == null || isDetailsLoaded) {
                    if (isDetailsLoaded) {
                        return@collectLatest
                    }

                    if (snapshot == null) {
                        handleMissingAuthRefreshSnapshot()
                        return@collectLatest
                    }

@@ -144,7 +150,22 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) {
        }
    }

    private fun handleMissingAuthRefreshSnapshot() {
        if (isFdroidDeepLink || args.source != Source.PLAY_STORE) {
            loadDataWhenNetworkAvailable(hasPlayStoreSession = false)
            return
        }

        if (hasRequestedInitialAuthRefresh) {
            return
        }

        hasRequestedInitialAuthRefresh = true
        sessionViewModel.refreshSessions(listOf(AuthStore.PLAY_STORE))
    }

    private suspend fun handleAuthRefreshSnapshot(snapshot: AuthRefreshSnapshot) {
        hasRequestedInitialAuthRefresh = false
        if (isFdroidDeepLink || args.source != Source.PLAY_STORE) {
            loadDataWhenNetworkAvailable(hasPlayStoreSession = false)
            return