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

Commit abce7d0f authored by cketti's avatar cketti
Browse files

Use deep links with FeatureLauncherActivity

parent c9045274
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -4,9 +4,11 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import app.k9mail.feature.account.setup.ui.AccountSetupScreen

const val NAVIGATION_ROUTE_ACCOUNT_SETUP = "/account/setup"
const val DEEPLINK_ACCOUNT_SETUP = "app://$NAVIGATION_ROUTE_ACCOUNT_SETUP"

fun NavController.navigateToAccountSetup(navOptions: NavOptions? = null) {
    navigate(NAVIGATION_ROUTE_ACCOUNT_SETUP, navOptions)
@@ -16,7 +18,12 @@ fun NavGraphBuilder.accountSetupRoute(
    onBack: () -> Unit,
    onFinish: (String) -> Unit,
) {
    composable(route = NAVIGATION_ROUTE_ACCOUNT_SETUP) {
    composable(
        route = NAVIGATION_ROUTE_ACCOUNT_SETUP,
        deepLinks = listOf(
            navDeepLink { uriPattern = DEEPLINK_ACCOUNT_SETUP },
        ),
    ) {
        AccountSetupScreen(
            onBack = onBack,
            onFinish = onFinish,
+6 −11
Original line number Diff line number Diff line
@@ -4,11 +4,12 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.core.net.toUri
import androidx.core.view.WindowCompat
import app.k9mail.core.ui.compose.common.activity.setActivityContent
import app.k9mail.feature.account.setup.navigation.NAVIGATION_ROUTE_ACCOUNT_SETUP
import app.k9mail.feature.account.setup.navigation.DEEPLINK_ACCOUNT_SETUP
import app.k9mail.feature.launcher.ui.FeatureLauncherApp
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
import app.k9mail.feature.onboarding.navigation.DEEPLINK_ONBOARDING

class FeatureLauncherActivity : ComponentActivity() {

@@ -17,22 +18,16 @@ class FeatureLauncherActivity : ComponentActivity() {

        WindowCompat.setDecorFitsSystemWindows(window, false)

        val destination = intent.getStringExtra(EXTRA_DESTINATION)

        setActivityContent {
            FeatureLauncherApp(startDestination = destination)
            FeatureLauncherApp()
        }
    }

    companion object {
        private const val EXTRA_DESTINATION = "destination"
        private const val DESTINATION_ONBOARDING = NAVIGATION_ROUTE_ONBOARDING
        private const val DESTINATION_SETUP_ACCOUNT = NAVIGATION_ROUTE_ACCOUNT_SETUP

        @JvmStatic
        fun launchOnboarding(context: Activity) {
            val intent = Intent(context, FeatureLauncherActivity::class.java).apply {
                putExtra(EXTRA_DESTINATION, DESTINATION_ONBOARDING)
                data = DEEPLINK_ONBOARDING.toUri()
                flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            }
            context.startActivity(intent)
@@ -41,7 +36,7 @@ class FeatureLauncherActivity : ComponentActivity() {
        @JvmStatic
        fun launchSetupAccount(context: Activity) {
            val intent = Intent(context, FeatureLauncherActivity::class.java).apply {
                putExtra(EXTRA_DESTINATION, DESTINATION_SETUP_ACCOUNT)
                data = DEEPLINK_ACCOUNT_SETUP.toUri()
            }
            context.startActivity(intent)
        }
+1 −2
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ import org.koin.compose.koinInject
@Composable
fun FeatureLauncherNavHost(
    navController: NavHostController,
    startDestination: String?,
    onBack: () -> Unit,
    modifier: Modifier = Modifier,
    importSettingsLauncher: ImportSettingsLauncher = koinInject(),
@@ -23,7 +22,7 @@ fun FeatureLauncherNavHost(
) {
    NavHost(
        navController = navController,
        startDestination = startDestination ?: NAVIGATION_ROUTE_ONBOARDING,
        startDestination = NAVIGATION_ROUTE_ONBOARDING,
        modifier = modifier,
    ) {
        onboardingRoute(
+0 −2
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import app.k9mail.feature.launcher.navigation.FeatureLauncherNavHost

@Composable
fun FeatureLauncherApp(
    startDestination: String?,
    modifier: Modifier = Modifier,
) {
    val navController = rememberNavController()
@@ -28,7 +27,6 @@ fun FeatureLauncherApp(

            FeatureLauncherNavHost(
                navController = navController,
                startDestination = startDestination,
                onBack = { activity.finish() },
            )
        }
+8 −1
Original line number Diff line number Diff line
@@ -4,9 +4,11 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import app.k9mail.feature.onboarding.ui.OnboardingScreen

const val NAVIGATION_ROUTE_ONBOARDING = "/onboarding"
const val DEEPLINK_ONBOARDING = "app://$NAVIGATION_ROUTE_ONBOARDING"

fun NavController.navigateToOnboarding(
    navOptions: NavOptions? = null,
@@ -18,7 +20,12 @@ fun NavGraphBuilder.onboardingRoute(
    onStart: () -> Unit,
    onImport: () -> Unit,
) {
    composable(route = NAVIGATION_ROUTE_ONBOARDING) {
    composable(
        route = NAVIGATION_ROUTE_ONBOARDING,
        deepLinks = listOf(
            navDeepLink { uriPattern = DEEPLINK_ONBOARDING },
        ),
    ) {
        OnboardingScreen(
            onStartClick = onStart,
            onImportClick = onImport,