|
1 | 1 | package protect.card_locker |
2 | 2 |
|
| 3 | +import android.app.Activity |
| 4 | +import android.content.Context |
3 | 5 | import android.os.Bundle |
4 | 6 | import android.text.Spanned |
5 | | -import android.view.MenuItem |
6 | | -import android.view.View |
7 | 7 | import android.widget.ScrollView |
8 | 8 | import android.widget.TextView |
9 | | - |
10 | | -import androidx.annotation.StringRes |
11 | | -import androidx.core.view.isVisible |
| 9 | +import androidx.activity.ComponentActivity |
| 10 | +import androidx.activity.compose.setContent |
| 11 | +import androidx.compose.foundation.layout.Column |
| 12 | +import androidx.compose.foundation.layout.padding |
| 13 | +import androidx.compose.foundation.rememberScrollState |
| 14 | +import androidx.compose.foundation.verticalScroll |
| 15 | +import androidx.compose.material3.ExperimentalMaterial3Api |
| 16 | + |
| 17 | +import androidx.compose.material3.Scaffold |
| 18 | +import androidx.compose.ui.Modifier |
| 19 | +import androidx.compose.ui.res.stringResource |
12 | 20 |
|
13 | 21 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 22 | +import protect.card_locker.compose.CatimaAboutSection |
| 23 | +import protect.card_locker.compose.CatimaTopAppBar |
| 24 | +import protect.card_locker.compose.theme.CatimaTheme |
14 | 25 |
|
15 | | -import protect.card_locker.databinding.AboutActivityBinding |
16 | 26 |
|
17 | | -class AboutActivity : CatimaAppCompatActivity() { |
18 | | - private companion object { |
| 27 | +class AboutActivity : ComponentActivity() { |
| 28 | + internal companion object { |
19 | 29 | private const val TAG = "Catima" |
20 | | - } |
21 | | - |
22 | | - private lateinit var binding: AboutActivityBinding |
23 | | - private lateinit var content: AboutContent |
24 | | - |
25 | | - override fun onCreate(savedInstanceState: Bundle?) { |
26 | | - super.onCreate(savedInstanceState) |
27 | | - binding = AboutActivityBinding.inflate(layoutInflater) |
28 | | - content = AboutContent(this) |
29 | | - 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 |
| 30 | + fun showHTML(context: Context, title: String, text: Spanned, activity: Activity, url: String?) { |
| 31 | + val dialogContentPadding = context.resources.getDimensionPixelSize(R.dimen.alert_dialog_content_padding) |
| 32 | + val textView = TextView(context).apply { |
| 33 | + setText(text) |
| 34 | + Utils.makeTextViewLinksClickable(this, text) |
61 | 35 | } |
62 | 36 |
|
63 | | - else -> super.onOptionsItemSelected(item) |
64 | | - } |
65 | | - } |
| 37 | + val scrollView = ScrollView(context).apply { |
| 38 | + addView(textView) |
| 39 | + setPadding(dialogContentPadding, dialogContentPadding / 2, dialogContentPadding, 0) |
| 40 | + } |
66 | 41 |
|
67 | | - override fun onDestroy() { |
68 | | - super.onDestroy() |
69 | | - content.destroy() |
70 | | - clearClickListeners() |
71 | | - } |
| 42 | + MaterialAlertDialogBuilder(context).apply { |
| 43 | + setTitle(title) |
| 44 | + setView(scrollView) |
| 45 | + setPositiveButton(R.string.ok, null) |
72 | 46 |
|
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 | | - } |
| 47 | + // Add View online button if an URL is given |
| 48 | + url?.let { |
| 49 | + setNeutralButton(R.string.view_online) { _, _ -> OpenWebLinkHandler().openBrowser(activity, url) } |
| 50 | + } |
86 | 51 |
|
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) |
| 52 | + show() |
| 53 | + } |
98 | 54 | } |
99 | 55 | } |
100 | 56 |
|
101 | | - private fun showCredits() { |
102 | | - showHTML(R.string.credits, content.contributorInfo, null) |
103 | | - } |
104 | | - |
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 | | - } |
| 57 | + private lateinit var content: AboutContent |
128 | 58 |
|
129 | | - MaterialAlertDialogBuilder(this).apply { |
130 | | - setTitle(title) |
131 | | - setView(scrollView) |
132 | | - setPositiveButton(R.string.ok, null) |
| 59 | + @OptIn(ExperimentalMaterial3Api::class) |
| 60 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 61 | + super.onCreate(savedInstanceState) |
| 62 | + content = AboutContent(this) |
| 63 | + title = content.pageTitle |
133 | 64 |
|
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) } |
| 65 | + setContent { |
| 66 | + CatimaTheme { |
| 67 | + Scaffold( |
| 68 | + topBar = { CatimaTopAppBar(title.toString(), onBackPressedDispatcher) } |
| 69 | + ) { innerPadding -> |
| 70 | + Column(modifier = Modifier.padding(innerPadding).verticalScroll(rememberScrollState())) { |
| 71 | + CatimaAboutSection( |
| 72 | + stringResource(R.string.version_history), |
| 73 | + content.versionHistory, |
| 74 | + onClickUrl = "https://catima.app/changelog/", |
| 75 | + onClickDialogText = content.historyInfo |
| 76 | + ) |
| 77 | + CatimaAboutSection( |
| 78 | + stringResource(R.string.credits), |
| 79 | + content.copyrightShort, |
| 80 | + onClickDialogText = content.contributorInfo |
| 81 | + ) |
| 82 | + CatimaAboutSection( |
| 83 | + stringResource(R.string.help_translate_this_app), |
| 84 | + stringResource(R.string.translate_platform), |
| 85 | + onClickUrl = "https://hosted.weblate.org/engage/catima/" |
| 86 | + ) |
| 87 | + CatimaAboutSection( |
| 88 | + stringResource(R.string.license), |
| 89 | + stringResource(R.string.app_license), |
| 90 | + onClickUrl = "https://github.com/CatimaLoyalty/Android/blob/main/LICENSE", |
| 91 | + onClickDialogText = content.licenseInfo |
| 92 | + ) |
| 93 | + CatimaAboutSection( |
| 94 | + stringResource(R.string.source_repository), |
| 95 | + stringResource(R.string.on_github), |
| 96 | + onClickUrl = "https://github.com/CatimaLoyalty/Android/" |
| 97 | + ) |
| 98 | + CatimaAboutSection( |
| 99 | + stringResource(R.string.privacy_policy), |
| 100 | + stringResource(R.string.and_data_usage), |
| 101 | + onClickUrl = "https://catima.app/privacy-policy/", |
| 102 | + onClickDialogText = content.privacyInfo |
| 103 | + ) |
| 104 | + CatimaAboutSection( |
| 105 | + stringResource(R.string.donate), |
| 106 | + "", |
| 107 | + onClickUrl = "https://catima.app/donate" |
| 108 | + ) |
| 109 | + CatimaAboutSection( |
| 110 | + stringResource(R.string.rate_this_app), |
| 111 | + stringResource(R.string.on_google_play), |
| 112 | + onClickUrl = "https://play.google.com/store/apps/details?id=me.hackerchick.catima" |
| 113 | + ) |
| 114 | + CatimaAboutSection( |
| 115 | + stringResource(R.string.report_error), |
| 116 | + stringResource(R.string.on_github), |
| 117 | + onClickUrl = "https://github.com/CatimaLoyalty/Android/issues" |
| 118 | + ) |
| 119 | + } |
| 120 | + } |
137 | 121 | } |
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) |
147 | 122 | } |
148 | 123 | } |
149 | 124 | } |
0 commit comments