Move AccountSetupFinishedLauncher to feature launcher

This commit is contained in:
Wolf-Martell Montwé 2023-06-29 13:00:42 +02:00
parent 9bf80c2266
commit 6cfd9481aa
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
10 changed files with 33 additions and 46 deletions

View file

@ -5,7 +5,6 @@ import app.k9mail.feature.account.setup.AccountSetupExternalContract
import app.k9mail.feature.account.setup.featureAccountSetupModule
import app.k9mail.feature.preview.account.AccountCreator
import app.k9mail.feature.preview.account.AccountOwnerNameProvider
import app.k9mail.feature.preview.account.AccountSetupFinishedLauncher
import app.k9mail.feature.preview.auth.AndroidKeyStoreDirectoryProvider
import app.k9mail.feature.preview.auth.AppOAuthConfigurationFactory
import app.k9mail.feature.preview.auth.DefaultTrustedSocketFactory
@ -13,18 +12,12 @@ import com.fsck.k9.mail.ssl.KeyStoreDirectoryProvider
import com.fsck.k9.mail.ssl.LocalKeyStore
import com.fsck.k9.mail.ssl.TrustManagerFactory
import com.fsck.k9.mail.ssl.TrustedSocketFactory
import org.koin.android.ext.koin.androidContext
import org.koin.core.module.Module
import org.koin.dsl.module
val accountModule: Module = module {
factory<AccountSetupExternalContract.AccountOwnerNameProvider> { AccountOwnerNameProvider() }
factory<AccountSetupExternalContract.AccountCreator> { AccountCreator() }
factory<AccountSetupExternalContract.AccountSetupFinishedLauncher> {
AccountSetupFinishedLauncher(
context = androidContext(),
)
}
}
val featureModule: Module = module {

View file

@ -1,13 +0,0 @@
package app.k9mail.feature.preview.account
import android.content.Context
import android.widget.Toast
import app.k9mail.feature.account.setup.AccountSetupExternalContract
class AccountSetupFinishedLauncher(
private val context: Context,
) : AccountSetupExternalContract.AccountSetupFinishedLauncher {
override suspend fun launch(accountUuid: String) {
Toast.makeText(context, "AccountSetupFinishedLauncher.launch($accountUuid)", Toast.LENGTH_SHORT).show()
}
}

View file

@ -17,6 +17,9 @@ dependencies {
implementation(projects.backend.pop3)
debugImplementation(projects.backend.demo)
implementation(projects.feature.launcher)
// TODO remove account setup dependency
implementation(projects.feature.account.setup)
implementation(libs.androidx.appcompat)

View file

@ -8,6 +8,7 @@ import com.fsck.k9.backends.backendsModule
import com.fsck.k9.controller.ControllerExtension
import com.fsck.k9.crypto.EncryptionExtractor
import com.fsck.k9.crypto.openpgp.OpenPgpEncryptionExtractor
import com.fsck.k9.feature.featureModule
import com.fsck.k9.notification.notificationModule
import com.fsck.k9.preferences.K9StoragePersister
import com.fsck.k9.preferences.StoragePersister
@ -44,4 +45,5 @@ val appModules = listOf(
backendsModule,
storageModule,
newAccountModule,
featureModule,
)

View file

@ -2,7 +2,6 @@ package com.fsck.k9.account
import app.k9mail.feature.account.setup.AccountSetupExternalContract
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
val newAccountModule = module {
@ -20,10 +19,4 @@ val newAccountModule = module {
context = androidApplication(),
)
}
factory<AccountSetupExternalContract.AccountSetupFinishedLauncher> {
AccountSetupFinishedLauncher(
context = androidContext(),
)
}
}

View file

@ -1,14 +1,14 @@
package com.fsck.k9.account
package com.fsck.k9.feature
import android.content.Context
import android.content.Intent
import app.k9mail.feature.account.setup.AccountSetupExternalContract
import app.k9mail.feature.launcher.FeatureLauncherExternalContract
import com.fsck.k9.activity.MessageList
class AccountSetupFinishedLauncher(
private val context: Context,
) : AccountSetupExternalContract.AccountSetupFinishedLauncher {
override suspend fun launch(accountUuid: String) {
) : FeatureLauncherExternalContract.AccountSetupFinishedLauncher {
override fun launch(accountUuid: String) {
val intent = Intent(context, MessageList::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)

View file

@ -0,0 +1,13 @@
package com.fsck.k9.feature
import app.k9mail.feature.launcher.FeatureLauncherExternalContract
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
val featureModule = module {
factory<FeatureLauncherExternalContract.AccountSetupFinishedLauncher> {
AccountSetupFinishedLauncher(
context = androidContext(),
)
}
}

View file

@ -16,8 +16,4 @@ interface AccountSetupExternalContract {
fun interface AccountOwnerNameProvider {
suspend fun getOwnerName(): String?
}
fun interface AccountSetupFinishedLauncher {
suspend fun launch(accountUuid: String)
}
}

View file

@ -0,0 +1,8 @@
package app.k9mail.feature.launcher
interface FeatureLauncherExternalContract {
fun interface AccountSetupFinishedLauncher {
fun launch(accountUuid: String)
}
}

View file

@ -1,16 +1,14 @@
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.launcher.FeatureLauncherExternalContract.AccountSetupFinishedLauncher
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
@ -18,10 +16,8 @@ fun FeatureLauncherNavHost(
navController: NavHostController,
startDestination: String?,
modifier: Modifier = Modifier,
accountSetupFinishedLauncher: AccountSetupFinishedLauncher = koinInject<AccountSetupFinishedLauncher>(),
accountSetupFinishedLauncher: AccountSetupFinishedLauncher = koinInject(),
) {
val coroutineScope = rememberCoroutineScope()
NavHost(
navController = navController,
startDestination = startDestination ?: NAVIGATION_ROUTE_ONBOARDING,
@ -33,11 +29,7 @@ fun FeatureLauncherNavHost(
)
accountSetupRoute(
onBack = navController::popBackStack,
onFinish = {
coroutineScope.launch {
accountSetupFinishedLauncher.launch(it)
}
},
onFinish = { accountSetupFinishedLauncher.launch(it) },
)
}
}