diff --git a/app/common/src/main/java/com/fsck/k9/feature/AccountSetupFinishedLauncher.kt b/app/common/src/main/java/com/fsck/k9/feature/AccountSetupFinishedLauncher.kt index 862da1c41..1f717f517 100644 --- a/app/common/src/main/java/com/fsck/k9/feature/AccountSetupFinishedLauncher.kt +++ b/app/common/src/main/java/com/fsck/k9/feature/AccountSetupFinishedLauncher.kt @@ -7,7 +7,11 @@ import com.fsck.k9.activity.MessageList class AccountSetupFinishedLauncher( private val context: Context, ) : FeatureLauncherExternalContract.AccountSetupFinishedLauncher { - override fun launch(accountUuid: String) { - MessageList.launch(context, accountUuid) + override fun launch(accountUuid: String?) { + if (accountUuid != null) { + MessageList.launch(context, accountUuid) + } else { + MessageList.launch(context) + } } } diff --git a/app/common/src/main/java/com/fsck/k9/feature/FeatureModule.kt b/app/common/src/main/java/com/fsck/k9/feature/FeatureModule.kt index c0aa8a943..d9e2e7c22 100644 --- a/app/common/src/main/java/com/fsck/k9/feature/FeatureModule.kt +++ b/app/common/src/main/java/com/fsck/k9/feature/FeatureModule.kt @@ -10,10 +10,4 @@ val featureModule = module { context = androidContext(), ) } - - factory { - ImportSettingsLauncher( - context = androidContext(), - ) - } } diff --git a/app/common/src/main/java/com/fsck/k9/feature/ImportSettingsLauncher.kt b/app/common/src/main/java/com/fsck/k9/feature/ImportSettingsLauncher.kt deleted file mode 100644 index 45a5a778c..000000000 --- a/app/common/src/main/java/com/fsck/k9/feature/ImportSettingsLauncher.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.fsck.k9.feature - -import android.content.Context -import android.content.Intent -import app.k9mail.feature.launcher.FeatureLauncherExternalContract -import com.fsck.k9.activity.FragmentLauncherActivity - -class ImportSettingsLauncher( - private val context: Context, -) : FeatureLauncherExternalContract.ImportSettingsLauncher { - override fun launch() { - val intent = Intent(context, FragmentLauncherActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - putExtra(FragmentLauncherActivity.EXTRA_FRAGMENT, FragmentLauncherActivity.FRAGMENT_IMPORT_SETTINGS) - } - context.startActivity(intent) - } -} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/FragmentLauncherActivity.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/FragmentLauncherActivity.kt index 6ab29546b..11b8e4532 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/FragmentLauncherActivity.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/FragmentLauncherActivity.kt @@ -1,12 +1,10 @@ package com.fsck.k9.activity -import android.content.Intent import android.os.Bundle -import app.k9mail.feature.settings.import.ui.SettingsImportFragment import com.fsck.k9.ui.R import com.fsck.k9.ui.base.K9Activity -import app.k9mail.feature.settings.importing.R as SettingsImportR +// Currently not used class FragmentLauncherActivity : K9Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -14,40 +12,11 @@ class FragmentLauncherActivity : K9Activity() { setLayout(R.layout.activity_fragment_launcher) when (val fragment = intent.getStringExtra(EXTRA_FRAGMENT)) { - FRAGMENT_IMPORT_SETTINGS -> setupSettingsFragment() else -> throw IllegalArgumentException("Unknown destination: $fragment") } } - private fun setupSettingsFragment() { - setTitle(SettingsImportR.string.settings_import_title) - supportFragmentManager.beginTransaction() - .replace(R.id.fragment_launcher_container, SettingsImportFragment()) - .commit() - - supportFragmentManager.setFragmentResultListener( - SettingsImportFragment.FRAGMENT_RESULT_KEY, - this, - ) { _, result: Bundle -> - if (result.getBoolean(SettingsImportFragment.FRAGMENT_RESULT_ACCOUNT_IMPORTED, false)) { - launchMessageList() - } - finish() - } - } - - private fun launchMessageList() { - val intent = Intent(this, MessageList::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - } - - startActivity(intent) - } - companion object { const val EXTRA_FRAGMENT = "fragment" - const val FRAGMENT_IMPORT_SETTINGS = "import_settings" } } diff --git a/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/FeatureLauncherExternalContract.kt b/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/FeatureLauncherExternalContract.kt index 57fdbefb2..0bbd76012 100644 --- a/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/FeatureLauncherExternalContract.kt +++ b/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/FeatureLauncherExternalContract.kt @@ -3,10 +3,6 @@ package app.k9mail.feature.launcher interface FeatureLauncherExternalContract { fun interface AccountSetupFinishedLauncher { - fun launch(accountUuid: String) - } - - fun interface ImportSettingsLauncher { - fun launch() + fun launch(accountUuid: String?) } } diff --git a/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/navigation/FeatureLauncherNavHost.kt b/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/navigation/FeatureLauncherNavHost.kt index 1e4d2637d..e500e4481 100644 --- a/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/navigation/FeatureLauncherNavHost.kt +++ b/feature/launcher/src/main/kotlin/app/k9mail/feature/launcher/navigation/FeatureLauncherNavHost.kt @@ -8,7 +8,6 @@ import app.k9mail.core.ui.compose.common.activity.LocalActivity import app.k9mail.feature.account.edit.navigation.accountEditRoute import app.k9mail.feature.account.setup.navigation.accountSetupRoute import app.k9mail.feature.launcher.FeatureLauncherExternalContract.AccountSetupFinishedLauncher -import app.k9mail.feature.launcher.FeatureLauncherExternalContract.ImportSettingsLauncher import app.k9mail.feature.onboarding.main.navigation.NAVIGATION_ROUTE_ONBOARDING import app.k9mail.feature.onboarding.main.navigation.onboardingRoute import org.koin.compose.koinInject @@ -18,7 +17,6 @@ fun FeatureLauncherNavHost( navController: NavHostController, onBack: () -> Unit, modifier: Modifier = Modifier, - importSettingsLauncher: ImportSettingsLauncher = koinInject(), accountSetupFinishedLauncher: AccountSetupFinishedLauncher = koinInject(), ) { val activity = LocalActivity.current @@ -29,8 +27,8 @@ fun FeatureLauncherNavHost( modifier = modifier, ) { onboardingRoute( - onImport = { importSettingsLauncher.launch() }, - ) { accountUuid -> accountSetupFinishedLauncher.launch(accountUuid) } + onFinish = { accountUuid -> accountSetupFinishedLauncher.launch(accountUuid) }, + ) accountSetupRoute( onBack = onBack, onFinish = { accountSetupFinishedLauncher.launch(it) }, diff --git a/feature/onboarding/main/build.gradle.kts b/feature/onboarding/main/build.gradle.kts index 9b8070137..89eb13aa1 100644 --- a/feature/onboarding/main/build.gradle.kts +++ b/feature/onboarding/main/build.gradle.kts @@ -20,5 +20,6 @@ dependencies { implementation(projects.core.ui.compose.designsystem) implementation(projects.feature.onboarding.welcome) implementation(projects.feature.account.setup) + implementation(projects.feature.settings.import) implementation(projects.feature.onboarding.permissions) } diff --git a/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavHost.kt b/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavHost.kt index 080881014..9db5932cf 100644 --- a/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavHost.kt +++ b/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavHost.kt @@ -6,7 +6,6 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.navigation.NavController -import androidx.navigation.NavOptionsBuilder import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController @@ -14,24 +13,33 @@ import app.k9mail.feature.account.setup.navigation.AccountSetupNavHost import app.k9mail.feature.onboarding.permissions.domain.PermissionsDomainContract.UseCase.HasRuntimePermissions import app.k9mail.feature.onboarding.permissions.ui.PermissionsScreen import app.k9mail.feature.onboarding.welcome.ui.WelcomeScreen +import app.k9mail.feature.settings.import.ui.SettingsImportScreen import org.koin.compose.koinInject private const val NESTED_NAVIGATION_ROUTE_WELCOME = "welcome" private const val NESTED_NAVIGATION_ROUTE_ACCOUNT_SETUP = "account_setup" +private const val NESTED_NAVIGATION_ROUTE_SETTINGS_IMPORT = "settings_import" private const val NESTED_NAVIGATION_ROUTE_PERMISSIONS = "permissions" private fun NavController.navigateToAccountSetup() { navigate(NESTED_NAVIGATION_ROUTE_ACCOUNT_SETUP) } -private fun NavController.navigateToPermissions(builder: NavOptionsBuilder.() -> Unit) { - navigate(NESTED_NAVIGATION_ROUTE_PERMISSIONS, builder) +private fun NavController.navigateToSettingsImport() { + navigate(NESTED_NAVIGATION_ROUTE_SETTINGS_IMPORT) +} + +private fun NavController.navigateToPermissions() { + navigate(NESTED_NAVIGATION_ROUTE_PERMISSIONS) { + popUpTo(NESTED_NAVIGATION_ROUTE_WELCOME) { + inclusive = true + } + } } @Composable fun OnboardingNavHost( - onImport: () -> Unit, - onFinish: (String) -> Unit, + onFinish: (String?) -> Unit, hasRuntimePermissions: HasRuntimePermissions = koinInject(), ) { val navController = rememberNavController() @@ -44,7 +52,7 @@ fun OnboardingNavHost( composable(route = NESTED_NAVIGATION_ROUTE_WELCOME) { WelcomeScreen( onStartClick = { navController.navigateToAccountSetup() }, - onImportClick = onImport, + onImportClick = { navController.navigateToSettingsImport() }, ) } @@ -54,11 +62,7 @@ fun OnboardingNavHost( onFinish = { createdAccountUuid: String -> accountUuid = createdAccountUuid if (hasRuntimePermissions()) { - navController.navigateToPermissions { - popUpTo(NESTED_NAVIGATION_ROUTE_WELCOME) { - inclusive = true - } - } + navController.navigateToPermissions() } else { onFinish(createdAccountUuid) } @@ -66,9 +70,22 @@ fun OnboardingNavHost( ) } + composable(route = NESTED_NAVIGATION_ROUTE_SETTINGS_IMPORT) { + SettingsImportScreen( + onImportSuccess = { + if (hasRuntimePermissions()) { + navController.navigateToPermissions() + } else { + onFinish(null) + } + }, + onBack = { navController.popBackStack() }, + ) + } + composable(route = NESTED_NAVIGATION_ROUTE_PERMISSIONS) { PermissionsScreen( - onNext = { onFinish(requireNotNull(accountUuid)) }, + onNext = { onFinish(accountUuid) }, ) } } diff --git a/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavigation.kt b/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavigation.kt index b87edd2f4..46b5fa9ca 100644 --- a/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavigation.kt +++ b/feature/onboarding/main/src/main/kotlin/app/k9mail/feature/onboarding/main/navigation/OnboardingNavigation.kt @@ -1,25 +1,15 @@ package app.k9mail.feature.onboarding.main.navigation -import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavOptions import app.k9mail.core.ui.compose.common.navigation.deepLinkComposable const val NAVIGATION_ROUTE_ONBOARDING = "onboarding" -fun NavController.navigateToOnboarding( - navOptions: NavOptions? = null, -) { - navigate(NAVIGATION_ROUTE_ONBOARDING, navOptions) -} - fun NavGraphBuilder.onboardingRoute( - onImport: () -> Unit, - onFinish: (String) -> Unit, + onFinish: (String?) -> Unit, ) { deepLinkComposable(route = NAVIGATION_ROUTE_ONBOARDING) { OnboardingNavHost( - onImport = onImport, onFinish = onFinish, ) } diff --git a/feature/settings/import/build.gradle.kts b/feature/settings/import/build.gradle.kts index a662c730a..b9267dd4e 100644 --- a/feature/settings/import/build.gradle.kts +++ b/feature/settings/import/build.gradle.kts @@ -21,6 +21,7 @@ android { dependencies { implementation(projects.app.core) implementation(projects.app.ui.base) + implementation(projects.core.ui.compose.designsystem) implementation(projects.feature.account.oauth) implementation(libs.appauth) diff --git a/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportScreen.kt b/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportScreen.kt new file mode 100644 index 000000000..123e0901d --- /dev/null +++ b/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportScreen.kt @@ -0,0 +1,69 @@ +package app.k9mail.feature.settings.import.ui + +import android.os.Bundle +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.res.stringResource +import androidx.fragment.app.FragmentActivity +import app.k9mail.core.ui.compose.common.activity.LocalActivity +import app.k9mail.core.ui.compose.common.fragment.FragmentView +import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonIcon +import app.k9mail.core.ui.compose.designsystem.organism.TopAppBar +import app.k9mail.core.ui.compose.designsystem.template.Scaffold +import app.k9mail.core.ui.compose.theme.Icons +import app.k9mail.feature.settings.importing.R + +@Composable +fun SettingsImportScreen( + onImportSuccess: () -> Unit, + onBack: () -> Unit, + modifier: Modifier = Modifier, +) { + Scaffold( + topBar = { + TopAppBar( + title = stringResource(R.string.settings_import_title), + navigationIcon = { + ButtonIcon( + onClick = onBack, + imageVector = Icons.Outlined.arrowBack, + ) + }, + ) + }, + modifier = modifier, + ) { innerPadding -> + SettingsImportContent(onImportSuccess, onBack, innerPadding) + } +} + +@Composable +private fun SettingsImportContent( + onImportSuccess: () -> Unit, + onBack: () -> Unit, + paddingValues: PaddingValues, +) { + val activity = LocalActivity.current as FragmentActivity + + activity.supportFragmentManager.setFragmentResultListener( + SettingsImportFragment.FRAGMENT_RESULT_KEY, + LocalLifecycleOwner.current, + ) { _, result: Bundle -> + if (result.getBoolean(SettingsImportFragment.FRAGMENT_RESULT_ACCOUNT_IMPORTED, false)) { + onImportSuccess() + } else { + onBack() + } + } + + FragmentView( + fragmentFactory = { SettingsImportFragment() }, + modifier = Modifier + .fillMaxSize() + .padding(paddingValues), + ) +}