0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-19 19:52:14 +02:00

Add feature launcher module to add host activity for composable views

This commit is contained in:
Wolf-Martell Montwé 2023-06-29 11:26:07 +02:00
parent d5c3cf3bf8
commit 4cd261dcc7
No known key found for this signature in database
GPG Key ID: 6D45B21512ACBF72
7 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,25 @@
plugins {
id(ThunderbirdPlugins.Library.androidCompose)
}
android {
namespace = "app.k9mail.feature.launcher"
resourcePrefix = "launcher_"
buildTypes {
debug {
manifestPlaceholders["appAuthRedirectScheme"] = "FIXME: override this in your app project"
}
release {
manifestPlaceholders["appAuthRedirectScheme"] = "FIXME: override this in your app project"
}
}
}
dependencies {
implementation(projects.core.ui.compose.designsystem)
implementation(projects.feature.onboarding)
implementation(projects.feature.account.setup)
testImplementation(projects.core.ui.compose.testing)
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:supportsRtl="true">
<activity
android:name=".FeatureLauncherActivity"
android:windowSoftInputMode="adjustResize"
/>
</application>
</manifest>

View File

@ -0,0 +1,49 @@
package app.k9mail.feature.launcher
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
import app.k9mail.feature.account.setup.navigation.NAVIGATION_ROUTE_ACCOUNT_SETUP
import app.k9mail.feature.launcher.ui.FeatureLauncherApp
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
class FeatureLauncherActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
val destination = intent.getStringExtra(EXTRA_DESTINATION)
setContent {
FeatureLauncherApp(startDestination = destination)
}
}
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)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
context.startActivity(intent)
}
@JvmStatic
fun launchSetupAccount(context: Activity) {
val intent = Intent(context, FeatureLauncherActivity::class.java).apply {
putExtra(EXTRA_DESTINATION, DESTINATION_SETUP_ACCOUNT)
}
context.startActivity(intent)
}
}
}

View File

@ -0,0 +1,10 @@
package app.k9mail.feature.launcher.di
import app.k9mail.feature.account.setup.featureAccountSetupModule
import org.koin.dsl.module
val featureLauncherModule = module {
includes(
featureAccountSetupModule,
)
}

View File

@ -0,0 +1,43 @@
package app.k9mail.feature.launcher.navigation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountSetupFinishedLauncher
import app.k9mail.feature.account.setup.navigation.accountSetupRoute
import app.k9mail.feature.account.setup.navigation.navigateToAccountSetup
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
import app.k9mail.feature.onboarding.navigation.onboardingRoute
import kotlinx.coroutines.launch
import org.koin.compose.koinInject
@Composable
fun FeatureLauncherNavHost(
navController: NavHostController,
startDestination: String?,
modifier: Modifier = Modifier,
accountSetupFinishedLauncher: AccountSetupFinishedLauncher = koinInject<AccountSetupFinishedLauncher>(),
) {
val coroutineScope = rememberCoroutineScope()
NavHost(
navController = navController,
startDestination = startDestination ?: NAVIGATION_ROUTE_ONBOARDING,
modifier = modifier,
) {
onboardingRoute(
onStart = { navController.navigateToAccountSetup() },
onImport = { /* TODO */ },
)
accountSetupRoute(
onBack = navController::popBackStack,
onFinish = {
coroutineScope.launch {
accountSetupFinishedLauncher.launch(it)
}
},
)
}
}

View File

@ -0,0 +1,32 @@
package app.k9mail.feature.launcher.ui
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import app.k9mail.core.ui.compose.designsystem.atom.Background
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.feature.launcher.navigation.FeatureLauncherNavHost
@Composable
fun FeatureLauncherApp(
startDestination: String?,
modifier: Modifier = Modifier,
) {
val navController = rememberNavController()
K9Theme {
Background(
modifier = Modifier
.fillMaxSize()
.safeDrawingPadding()
.then(modifier),
) {
FeatureLauncherNavHost(
navController = navController,
startDestination = startDestination,
)
}
}
}

View File

@ -39,6 +39,7 @@ include(
)
include(
":feature:launcher",
":feature:account:setup",
":feature:account:oauth",
":feature:onboarding",