Add launch import settings

This commit is contained in:
Wolf-Martell Montwé 2023-06-29 17:46:40 +02:00
parent 0c1921539f
commit 1aa69635f5
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
8 changed files with 118 additions and 3 deletions

View file

@ -10,4 +10,10 @@ val featureModule = module {
context = androidContext(),
)
}
factory<FeatureLauncherExternalContract.ImportSettingsLauncher> {
ImportSettingsLauncher(
context = androidContext(),
)
}
}

View file

@ -0,0 +1,18 @@
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)
}
}

View file

@ -5,7 +5,13 @@
<application
android:theme="@style/Theme.K9.Light"
android:supportsRtl="true" />
android:supportsRtl="true">
<activity
android:name="com.fsck.k9.activity.FragmentLauncherActivity"
/>
</application>
<queries>
<intent>

View file

@ -0,0 +1,55 @@
package com.fsck.k9.activity
import android.content.Intent
import android.os.Bundle
import com.fsck.k9.ui.R
import com.fsck.k9.ui.base.K9Activity
import com.fsck.k9.ui.settings.import.SettingsImportFragment
import com.fsck.k9.ui.settings.import.SettingsImportResultViewModel
import com.fsck.k9.ui.settings.import.SettingsImportSuccess
import org.koin.androidx.viewmodel.ext.android.viewModel
class FragmentLauncherActivity : K9Activity() {
private val settingsImportResultViewModel: SettingsImportResultViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
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(R.string.settings_import_title)
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_launcher_container, SettingsImportFragment())
.commit()
settingsImportResultViewModel.settingsImportResult.observe(this) {
if (it == SettingsImportSuccess) {
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"
}
}

View file

@ -153,11 +153,16 @@ class SettingsImportFragment : Fragment() {
}
}
@Suppress("SwallowedException")
private fun closeImportScreen(action: Action.Close) {
if (action.importSuccess) {
resultViewModel.setSettingsImportResult()
}
findNavController().popBackStack()
try {
findNavController().popBackStack()
} catch (e: IllegalStateException) {
// Fragment does not have NavController
}
}
private fun pickDocument() {

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.fsck.k9.activity.FragmentLauncherActivity">
<include layout="@layout/toolbar" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_launcher_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>

View file

@ -5,4 +5,8 @@ interface FeatureLauncherExternalContract {
fun interface AccountSetupFinishedLauncher {
fun launch(accountUuid: String)
}
fun interface ImportSettingsLauncher {
fun launch()
}
}

View file

@ -7,6 +7,7 @@ import androidx.navigation.compose.NavHost
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.launcher.FeatureLauncherExternalContract.ImportSettingsLauncher
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
import app.k9mail.feature.onboarding.navigation.onboardingRoute
import org.koin.compose.koinInject
@ -16,6 +17,7 @@ fun FeatureLauncherNavHost(
navController: NavHostController,
startDestination: String?,
modifier: Modifier = Modifier,
importSettingsLauncher: ImportSettingsLauncher = koinInject(),
accountSetupFinishedLauncher: AccountSetupFinishedLauncher = koinInject(),
) {
NavHost(
@ -25,7 +27,7 @@ fun FeatureLauncherNavHost(
) {
onboardingRoute(
onStart = { navController.navigateToAccountSetup() },
onImport = { /* TODO */ },
onImport = { importSettingsLauncher.launch() },
)
accountSetupRoute(
onBack = navController::popBackStack,