Skip to content

Commit e79efe2

Browse files
WIP
1 parent 775b55f commit e79efe2

File tree

10 files changed

+311
-586
lines changed

10 files changed

+311
-586
lines changed

app/build.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
33
plugins {
44
id("com.android.application")
55
id("org.jetbrains.kotlin.android")
6+
id("org.jetbrains.kotlin.plugin.compose") version "2.1.21"
67
}
78

89
kotlin {
@@ -46,6 +47,7 @@ android {
4647

4748
buildFeatures {
4849
buildConfig = true
50+
compose = true
4951
viewBinding = true
5052
}
5153

@@ -109,6 +111,7 @@ android {
109111

110112
dependencies {
111113
// AndroidX
114+
implementation("androidx.activity:activity-compose:1.10.1")
112115
implementation("androidx.appcompat:appcompat:1.7.0")
113116
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
114117
implementation("androidx.core:core-ktx:1.16.0")
@@ -119,6 +122,14 @@ dependencies {
119122
implementation("com.google.android.material:material:1.12.0")
120123
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
121124

125+
// Compose
126+
val composeBom = platform("androidx.compose:compose-bom:2025.05.01")
127+
implementation(composeBom)
128+
testImplementation(composeBom)
129+
androidTestImplementation(composeBom)
130+
implementation("androidx.compose.foundation:foundation")
131+
implementation("androidx.compose.material3:material3")
132+
122133
// Third-party
123134
implementation("com.journeyapps:zxing-android-embedded:4.3.0@aar")
124135
implementation("com.github.yalantis:ucrop:2.2.10")
Lines changed: 117 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,131 @@
11
package protect.card_locker
22

33
import android.os.Bundle
4-
import android.text.Spanned
5-
import android.view.MenuItem
6-
import android.view.View
7-
import android.widget.ScrollView
8-
import android.widget.TextView
9-
10-
import androidx.annotation.StringRes
11-
import androidx.core.view.isVisible
12-
13-
import com.google.android.material.dialog.MaterialAlertDialogBuilder
14-
15-
import protect.card_locker.databinding.AboutActivityBinding
16-
17-
class AboutActivity : CatimaAppCompatActivity() {
18-
private companion object {
19-
private const val TAG = "Catima"
20-
}
21-
22-
private lateinit var binding: AboutActivityBinding
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.rememberScrollState
9+
import androidx.compose.foundation.verticalScroll
10+
import androidx.compose.material3.ExperimentalMaterial3Api
11+
import androidx.compose.material3.MaterialTheme
12+
13+
import androidx.compose.material3.Scaffold
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.res.stringResource
16+
import androidx.compose.ui.text.AnnotatedString
17+
import androidx.compose.ui.text.SpanStyle
18+
import androidx.compose.ui.text.TextLinkStyles
19+
import androidx.compose.ui.text.fromHtml
20+
import androidx.compose.ui.text.style.TextDecoration
21+
22+
import protect.card_locker.compose.CatimaAboutSection
23+
import protect.card_locker.compose.CatimaTopAppBar
24+
import protect.card_locker.compose.theme.CatimaTheme
25+
26+
27+
class AboutActivity : ComponentActivity() {
2328
private lateinit var content: AboutContent
2429

30+
@OptIn(ExperimentalMaterial3Api::class)
2531
override fun onCreate(savedInstanceState: Bundle?) {
2632
super.onCreate(savedInstanceState)
27-
binding = AboutActivityBinding.inflate(layoutInflater)
2833
content = AboutContent(this)
2934
title = content.pageTitle
30-
setContentView(binding.root)
31-
setSupportActionBar(binding.toolbar)
32-
enableToolbarBackButton()
33-
34-
binding.apply {
35-
creditsSub.text = content.copyrightShort
36-
versionHistorySub.text = content.versionHistory
37-
38-
versionHistory.tag = "https://catima.app/changelog/"
39-
translate.tag = "https://hosted.weblate.org/engage/catima/"
40-
license.tag = "https://github.com/CatimaLoyalty/Android/blob/main/LICENSE"
41-
repo.tag = "https://github.com/CatimaLoyalty/Android/"
42-
privacy.tag = "https://catima.app/privacy-policy/"
43-
reportError.tag = "https://github.com/CatimaLoyalty/Android/issues"
44-
rate.tag = "https://play.google.com/store/apps/details?id=me.hackerchick.catima"
45-
donate.tag = "https://catima.app/donate"
46-
47-
// Hide Google Play rate button if not on Google Play
48-
rate.isVisible = BuildConfig.showRateOnGooglePlay
49-
// Hide donate button on Google Play (Google Play doesn't allow donation links)
50-
donate.isVisible = BuildConfig.showDonate
51-
}
52-
53-
bindClickListeners()
54-
}
55-
56-
override fun onOptionsItemSelected(item: MenuItem): Boolean {
57-
return when (item.itemId) {
58-
android.R.id.home -> {
59-
finish()
60-
true
61-
}
62-
63-
else -> super.onOptionsItemSelected(item)
64-
}
65-
}
66-
67-
override fun onDestroy() {
68-
super.onDestroy()
69-
content.destroy()
70-
clearClickListeners()
71-
}
72-
73-
private fun bindClickListeners() {
74-
binding.apply {
75-
versionHistory.setOnClickListener { showHistory(it) }
76-
translate.setOnClickListener { openExternalBrowser(it) }
77-
license.setOnClickListener { showLicense(it) }
78-
repo.setOnClickListener { openExternalBrowser(it) }
79-
privacy.setOnClickListener { showPrivacy(it) }
80-
reportError.setOnClickListener { openExternalBrowser(it) }
81-
rate.setOnClickListener { openExternalBrowser(it) }
82-
donate.setOnClickListener { openExternalBrowser(it) }
83-
credits.setOnClickListener { showCredits() }
84-
}
85-
}
86-
87-
private fun clearClickListeners() {
88-
binding.apply {
89-
versionHistory.setOnClickListener(null)
90-
translate.setOnClickListener(null)
91-
license.setOnClickListener(null)
92-
repo.setOnClickListener(null)
93-
privacy.setOnClickListener(null)
94-
reportError.setOnClickListener(null)
95-
rate.setOnClickListener(null)
96-
donate.setOnClickListener(null)
97-
credits.setOnClickListener(null)
98-
}
99-
}
100-
101-
private fun showCredits() {
102-
showHTML(R.string.credits, content.contributorInfo, null)
103-
}
10435

105-
private fun showHistory(view: View) {
106-
showHTML(R.string.version_history, content.historyInfo, view)
107-
}
108-
109-
private fun showLicense(view: View) {
110-
showHTML(R.string.license, content.licenseInfo, view)
111-
}
112-
113-
private fun showPrivacy(view: View) {
114-
showHTML(R.string.privacy_policy, content.privacyInfo, view)
115-
}
116-
117-
private fun showHTML(@StringRes title: Int, text: Spanned, view: View?) {
118-
val dialogContentPadding = resources.getDimensionPixelSize(R.dimen.alert_dialog_content_padding)
119-
val textView = TextView(this).apply {
120-
setText(text)
121-
Utils.makeTextViewLinksClickable(this, text)
122-
}
123-
124-
val scrollView = ScrollView(this).apply {
125-
addView(textView)
126-
setPadding(dialogContentPadding, dialogContentPadding / 2, dialogContentPadding, 0)
127-
}
128-
129-
MaterialAlertDialogBuilder(this).apply {
130-
setTitle(title)
131-
setView(scrollView)
132-
setPositiveButton(R.string.ok, null)
133-
134-
// Add View online button if an URL is linked to this view
135-
view?.tag?.let {
136-
setNeutralButton(R.string.view_online) { _, _ -> openExternalBrowser(view) }
36+
setContent {
37+
CatimaTheme {
38+
Scaffold(
39+
topBar = { CatimaTopAppBar(title.toString(), onBackPressedDispatcher) }
40+
) { innerPadding ->
41+
Column(modifier = Modifier.padding(innerPadding).verticalScroll(rememberScrollState())) {
42+
CatimaAboutSection(
43+
stringResource(R.string.version_history),
44+
content.versionHistory,
45+
onClickUrl = "https://catima.app/changelog/",
46+
onClickDialogText = AnnotatedString.fromHtml(
47+
htmlString = content.historyHtml,
48+
linkStyles = TextLinkStyles(
49+
style = SpanStyle(
50+
textDecoration = TextDecoration.Underline,
51+
color = MaterialTheme.colorScheme.primary
52+
)
53+
)
54+
)
55+
)
56+
CatimaAboutSection(
57+
stringResource(R.string.credits),
58+
content.copyrightShort,
59+
onClickDialogText = AnnotatedString.fromHtml(
60+
htmlString = content.contributorInfoHtml,
61+
linkStyles = TextLinkStyles(
62+
style = SpanStyle(
63+
textDecoration = TextDecoration.Underline,
64+
color = MaterialTheme.colorScheme.primary
65+
)
66+
)
67+
)
68+
)
69+
CatimaAboutSection(
70+
stringResource(R.string.help_translate_this_app),
71+
stringResource(R.string.translate_platform),
72+
onClickUrl = "https://hosted.weblate.org/engage/catima/"
73+
)
74+
CatimaAboutSection(
75+
stringResource(R.string.license),
76+
stringResource(R.string.app_license),
77+
onClickUrl = "https://github.com/CatimaLoyalty/Android/blob/main/LICENSE",
78+
onClickDialogText = AnnotatedString.fromHtml(
79+
htmlString = content.licenseHtml,
80+
linkStyles = TextLinkStyles(
81+
style = SpanStyle(
82+
textDecoration = TextDecoration.Underline,
83+
color = MaterialTheme.colorScheme.primary
84+
)
85+
)
86+
)
87+
)
88+
CatimaAboutSection(
89+
stringResource(R.string.source_repository),
90+
stringResource(R.string.on_github),
91+
onClickUrl = "https://github.com/CatimaLoyalty/Android/"
92+
)
93+
CatimaAboutSection(
94+
stringResource(R.string.privacy_policy),
95+
stringResource(R.string.and_data_usage),
96+
onClickUrl = "https://catima.app/privacy-policy/",
97+
onClickDialogText = AnnotatedString.fromHtml(
98+
htmlString = content.privacyHtml,
99+
linkStyles = TextLinkStyles(
100+
style = SpanStyle(
101+
textDecoration = TextDecoration.Underline,
102+
color = MaterialTheme.colorScheme.primary
103+
)
104+
)
105+
)
106+
)
107+
if (BuildConfig.showDonate) {
108+
CatimaAboutSection(
109+
stringResource(R.string.donate),
110+
"",
111+
onClickUrl = "https://catima.app/donate"
112+
)
113+
}
114+
if (BuildConfig.showRateOnGooglePlay) {
115+
CatimaAboutSection(
116+
stringResource(R.string.rate_this_app),
117+
stringResource(R.string.on_google_play),
118+
onClickUrl = "https://play.google.com/store/apps/details?id=me.hackerchick.catima"
119+
)
120+
}
121+
CatimaAboutSection(
122+
stringResource(R.string.report_error),
123+
stringResource(R.string.on_github),
124+
onClickUrl = "https://github.com/CatimaLoyalty/Android/issues"
125+
)
126+
}
127+
}
137128
}
138-
139-
show()
140-
}
141-
}
142-
143-
private fun openExternalBrowser(view: View) {
144-
val tag = view.tag
145-
if (tag is String && tag.startsWith("https://")) {
146-
OpenWebLinkHandler().openBrowser(this, tag)
147129
}
148130
}
149131
}

0 commit comments

Comments
 (0)