From eb82405f67f21823d928248bbda31b7a9e7aa5d4 Mon Sep 17 00:00:00 2001 From: IlyaZar Date: Mon, 6 Jul 2026 14:18:19 +0200 Subject: [PATCH] refactor: move about compose ui - keep about activity focused on lifecycle setup --- .../protect/card_locker/AboutActivityTest.kt | 3 +- .../java/protect/card_locker/AboutActivity.kt | 141 +----------------- .../card_locker/compose/AboutActivity.kt | 130 +++++++++++++++- 3 files changed, 132 insertions(+), 142 deletions(-) diff --git a/app/src/androidTest/java/protect/card_locker/AboutActivityTest.kt b/app/src/androidTest/java/protect/card_locker/AboutActivityTest.kt index 7555fa5a98..15305f3c9d 100644 --- a/app/src/androidTest/java/protect/card_locker/AboutActivityTest.kt +++ b/app/src/androidTest/java/protect/card_locker/AboutActivityTest.kt @@ -15,6 +15,7 @@ import androidx.test.platform.app.InstrumentationRegistry import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import protect.card_locker.compose.AboutScreenContent import protect.card_locker.compose.theme.CatimaTheme @OptIn(ExperimentalTestApi::class) @@ -86,4 +87,4 @@ class AboutActivityTest { onNodeWithTag("card_rate_google").assertIsNotDisplayed() onNodeWithTag("card_report_error").performScrollTo().assertIsDisplayed() } -} \ No newline at end of file +} diff --git a/app/src/main/java/protect/card_locker/AboutActivity.kt b/app/src/main/java/protect/card_locker/AboutActivity.kt index 284d081391..efa891d75d 100644 --- a/app/src/main/java/protect/card_locker/AboutActivity.kt +++ b/app/src/main/java/protect/card_locker/AboutActivity.kt @@ -1,34 +1,13 @@ package protect.card_locker import android.os.Bundle -import androidx.activity.OnBackPressedDispatcher import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Scaffold -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.SpanStyle -import androidx.compose.ui.text.TextLinkStyles -import androidx.compose.ui.text.fromHtml -import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.tooling.preview.Preview -import protect.card_locker.compose.CatimaAboutSection -import protect.card_locker.compose.CatimaTopAppBar +import protect.card_locker.compose.AboutScreenContent import protect.card_locker.compose.theme.CatimaTheme class AboutActivity : CatimaComponentActivity() { private lateinit var content: AboutContent - @OptIn(ExperimentalMaterial3Api::class) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -49,121 +28,3 @@ class AboutActivity : CatimaComponentActivity() { } } } - -@Composable -fun AboutScreenContent( - content: AboutContent, - showDonate: Boolean = true, - showRateOnGooglePlay: Boolean = false, - onBackPressedDispatcher: OnBackPressedDispatcher? = null, -) { - Scaffold( - topBar = { CatimaTopAppBar(content.pageTitle.toString(), onBackPressedDispatcher) } - ) { innerPadding -> - Column( - modifier = Modifier - .padding(innerPadding) - .verticalScroll(rememberScrollState()) - ) { - CatimaAboutSection( - stringResource(R.string.version_history), - content.versionHistory, - modifier = Modifier.testTag("card_version_history"), - onClickUrl = "https://catima.app/changelog/", - onClickDialogText = AnnotatedString.fromHtml( - htmlString = content.historyHtml, - linkStyles = TextLinkStyles( - style = SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary - ) - ) - ) - ) - CatimaAboutSection( - stringResource(R.string.credits), - content.copyrightShort, - modifier = Modifier.testTag("card_credits"), - onClickDialogText = AnnotatedString.fromHtml( - htmlString = content.contributorInfoHtml, - linkStyles = TextLinkStyles( - style = SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary - ) - ) - ) - ) - CatimaAboutSection( - stringResource(R.string.help_translate_this_app), - stringResource(R.string.translate_platform), - modifier = Modifier.testTag("card_translate"), - onClickUrl = "https://hosted.weblate.org/engage/catima/" - ) - CatimaAboutSection( - stringResource(R.string.license), - stringResource(R.string.app_license), - modifier = Modifier.testTag("card_license"), - onClickUrl = "https://github.com/CatimaLoyalty/Android/blob/main/LICENSE", - onClickDialogText = AnnotatedString.fromHtml( - htmlString = content.licenseHtml, - linkStyles = TextLinkStyles( - style = SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary - ) - ) - ) - ) - CatimaAboutSection( - stringResource(R.string.source_repository), - stringResource(R.string.on_github), - modifier = Modifier.testTag("card_source_github"), - onClickUrl = "https://github.com/CatimaLoyalty/Android/" - ) - CatimaAboutSection( - stringResource(R.string.privacy_policy), - stringResource(R.string.and_data_usage), - modifier = Modifier.testTag("card_privacy_policy"), - onClickUrl = "https://catima.app/privacy-policy/", - onClickDialogText = AnnotatedString.fromHtml( - htmlString = content.privacyHtml, - linkStyles = TextLinkStyles( - style = SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary - ) - ) - ) - ) - if (showDonate) { - CatimaAboutSection( - stringResource(R.string.donate), - "", - modifier = Modifier.testTag("card_donate"), - onClickUrl = "https://catima.app/donate" - ) - } - if (showRateOnGooglePlay) { - CatimaAboutSection( - stringResource(R.string.rate_this_app), - stringResource(R.string.on_google_play), - modifier = Modifier.testTag("card_rate_google"), - onClickUrl = "https://play.google.com/store/apps/details?id=me.hackerchick.catima" - ) - } - CatimaAboutSection( - stringResource(R.string.report_error), - stringResource(R.string.on_github), - modifier = Modifier.testTag("card_report_error"), - onClickUrl = "https://github.com/CatimaLoyalty/Android/issues" - ) - } - } -} - -@Preview -@Composable -private fun AboutActivityPreview() { - AboutScreenContent(AboutContent(LocalContext.current)) -} diff --git a/app/src/main/java/protect/card_locker/compose/AboutActivity.kt b/app/src/main/java/protect/card_locker/compose/AboutActivity.kt index 3fcc5760cd..a3e2404057 100644 --- a/app/src/main/java/protect/card_locker/compose/AboutActivity.kt +++ b/app/src/main/java/protect/card_locker/compose/AboutActivity.kt @@ -1,5 +1,6 @@ package protect.card_locker.compose +import androidx.activity.OnBackPressedDispatcher import androidx.activity.compose.LocalActivity import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column @@ -9,6 +10,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.AlertDialog import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable @@ -16,14 +18,134 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.hideFromAccessibility import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextLinkStyles +import androidx.compose.ui.text.fromHtml +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import protect.card_locker.AboutContent import protect.card_locker.OpenWebLinkHandler import protect.card_locker.R +@Composable +fun AboutScreenContent( + content: AboutContent, + showDonate: Boolean = true, + showRateOnGooglePlay: Boolean = false, + onBackPressedDispatcher: OnBackPressedDispatcher? = null, +) { + Scaffold( + topBar = { CatimaTopAppBar(content.pageTitle.toString(), onBackPressedDispatcher) } + ) { innerPadding -> + Column( + modifier = Modifier + .padding(innerPadding) + .verticalScroll(rememberScrollState()) + ) { + CatimaAboutSection( + stringResource(R.string.version_history), + content.versionHistory, + modifier = Modifier.testTag("card_version_history"), + onClickUrl = "https://catima.app/changelog/", + onClickDialogText = AnnotatedString.fromHtml( + htmlString = content.historyHtml, + linkStyles = TextLinkStyles( + style = SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary + ) + ) + ) + ) + CatimaAboutSection( + stringResource(R.string.credits), + content.copyrightShort, + modifier = Modifier.testTag("card_credits"), + onClickDialogText = AnnotatedString.fromHtml( + htmlString = content.contributorInfoHtml, + linkStyles = TextLinkStyles( + style = SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary + ) + ) + ) + ) + CatimaAboutSection( + stringResource(R.string.help_translate_this_app), + stringResource(R.string.translate_platform), + modifier = Modifier.testTag("card_translate"), + onClickUrl = "https://hosted.weblate.org/engage/catima/" + ) + CatimaAboutSection( + stringResource(R.string.license), + stringResource(R.string.app_license), + modifier = Modifier.testTag("card_license"), + onClickUrl = "https://github.com/CatimaLoyalty/Android/blob/main/LICENSE", + onClickDialogText = AnnotatedString.fromHtml( + htmlString = content.licenseHtml, + linkStyles = TextLinkStyles( + style = SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary + ) + ) + ) + ) + CatimaAboutSection( + stringResource(R.string.source_repository), + stringResource(R.string.on_github), + modifier = Modifier.testTag("card_source_github"), + onClickUrl = "https://github.com/CatimaLoyalty/Android/" + ) + CatimaAboutSection( + stringResource(R.string.privacy_policy), + stringResource(R.string.and_data_usage), + modifier = Modifier.testTag("card_privacy_policy"), + onClickUrl = "https://catima.app/privacy-policy/", + onClickDialogText = AnnotatedString.fromHtml( + htmlString = content.privacyHtml, + linkStyles = TextLinkStyles( + style = SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary + ) + ) + ) + ) + if (showDonate) { + CatimaAboutSection( + stringResource(R.string.donate), + "", + modifier = Modifier.testTag("card_donate"), + onClickUrl = "https://catima.app/donate" + ) + } + if (showRateOnGooglePlay) { + CatimaAboutSection( + stringResource(R.string.rate_this_app), + stringResource(R.string.on_google_play), + modifier = Modifier.testTag("card_rate_google"), + onClickUrl = "https://play.google.com/store/apps/details?id=me.hackerchick.catima" + ) + } + CatimaAboutSection( + stringResource(R.string.report_error), + stringResource(R.string.on_github), + modifier = Modifier.testTag("card_report_error"), + onClickUrl = "https://github.com/CatimaLoyalty/Android/issues" + ) + } + } +} + @Composable fun CatimaAboutSection( title: String, @@ -97,4 +219,10 @@ fun CatimaAboutSection( } ) } -} \ No newline at end of file +} + +@Preview +@Composable +private fun AboutActivityPreview() { + AboutScreenContent(AboutContent(LocalContext.current)) +}