Skip to content

Commit

Permalink
Encourage upgrading Thunderbird for QR code import
Browse files Browse the repository at this point in the history
Co-authored-by: cketti <cketti@thunderbird.net>
  • Loading branch information
kewisch and cketti committed Oct 25, 2024
1 parent 5be4e9a commit c777ad5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
2 changes: 2 additions & 0 deletions feature/onboarding/migration/thunderbird/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ dependencies {
implementation(projects.core.ui.compose.designsystem)
implementation(projects.feature.account.common)

implementation(libs.timber)

testImplementation(projects.core.ui.compose.testing)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package app.k9mail.feature.onboarding.migration.thunderbird

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
Expand All @@ -13,21 +20,33 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextDecoration
import app.k9mail.core.common.provider.BrandNameProvider
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonFilled
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonOutlined
import app.k9mail.core.ui.compose.designsystem.atom.card.CardFilled
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyMedium
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodySmall
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium
import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer
import app.k9mail.core.ui.compose.theme2.MainTheme
import app.k9mail.feature.account.common.ui.AppTitleTopHeader
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import org.koin.compose.koinInject
import timber.log.Timber

@Composable
internal fun TbOnboardingMigrationScreen(
Expand Down Expand Up @@ -104,7 +123,7 @@ private fun AlreadyUsingThunderbirdCard(onQrCodeScan: () -> Unit) {
BulletList(
items = persistentListOf(
stringResource(R.string.onboarding_migration_thunderbird_qr_code_import_instructions_bullet_1),
stringResource(R.string.onboarding_migration_thunderbird_qr_code_import_instructions_bullet_2),
stringResource(R.string.onboarding_migration_thunderbird_qr_code_import_instructions_bullet_2_v2),
),
modifier = Modifier
.padding(bottom = MainTheme.spacings.double),
Expand All @@ -117,6 +136,58 @@ private fun AlreadyUsingThunderbirdCard(onQrCodeScan: () -> Unit) {
.testTag("QrCodeImportButton")
.align(Alignment.CenterHorizontally),
)

ThunderbirdVersionNote(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(top = MainTheme.spacings.half),
)
}
}

@Composable
private fun ThunderbirdVersionNote(
modifier: Modifier = Modifier,
) {
val formatString = if (LocalInspectionMode.current) {
// When called from Android Studio previews, stringResource() replaces format string placeholders. We work
// around that by using a static string.
"Import requires the latest version of Thunderbird Desktop 128. %s"
} else {
stringResource(R.string.onboarding_migration_thunderbird_qr_code_import_instructions_require_latest)
}

val context = LocalContext.current

Box(
modifier = modifier
.clip(MainTheme.shapes.small)
.clickable { context.launchLearnHowToUpdateThunderbird() }
.semantics { role = Role.Button }
.padding(MainTheme.spacings.double),
) {
check("%s" in formatString) { "Placeholder needs to be exactly %s" }

val prefix = formatString.substringBefore("%s")
val suffix = formatString.substringAfter("%s")

val text = buildAnnotatedString {
val linkText = AnnotatedString(
text = stringResource(
R.string.onboarding_migration_thunderbird_qr_code_import_instructions_learn_update,
),
spanStyle = SpanStyle(
color = MainTheme.colors.primary,
textDecoration = TextDecoration.Underline,
),
)

append(prefix)
append(linkText)
append(suffix)
}

TextBodySmall(text)
}
}

Expand Down Expand Up @@ -196,3 +267,20 @@ private fun TextBodyMediumFullLineHeight(text: String) {
),
)
}

private fun Context.launchLearnHowToUpdateThunderbird() {
try {
val url = getString(R.string.onboarding_migration_thunderbird_update_thunderbird_url)
val viewIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))

startActivity(viewIntent)
} catch (e: ActivityNotFoundException) {
Timber.d(e, "Failed to open URL")

Toast.makeText(
this,
getString(R.string.onboarding_migration_thunderbird_link_open_error),
Toast.LENGTH_SHORT,
).show()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="onboarding_migration_thunderbird_update_thunderbird_url" translatable="false">https://support.mozilla.org/kb/updating-thunderbird</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="onboarding_migration_thunderbird_qr_code_import_title">Already using Thunderbird on desktop?</string>
<string name="onboarding_migration_thunderbird_qr_code_import_text">Easily import your account settings by scanning a QR code.</string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_intro">In Thunderbird desktop, go to:</string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_bullet_1">‘Settings’ in the Spaces Toolbar (bottom left)</string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_bullet_2">Select ‘Export to Mobile’ and follow the instructions</string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_bullet_2_v2">Select ‘Export to Mobile’</string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_require_latest">Import requires the latest version of Thunderbird Desktop 128. <xliff:g id="link_text">%s</xliff:g></string>
<string name="onboarding_migration_thunderbird_qr_code_import_instructions_learn_update">Learn how to update Thunderbird.</string>
<string name="onboarding_migration_thunderbird_qr_code_import_button_text">Import settings</string>
<string name="onboarding_migration_thunderbird_new_account_title">New to Thunderbird?</string>
<string name="onboarding_migration_thunderbird_new_account_button_text">Add an email account now</string>
<string name="onboarding_migration_thunderbird_import_title">Moving from another app or device?</string>
<string name="onboarding_migration_thunderbird_import_button_text">Import your account settings now</string>
<string name="onboarding_migration_thunderbird_link_open_error">No app found to open the link.</string>
</resources>

0 comments on commit c777ad5

Please sign in to comment.