From ffe6236c2de71db746ee937b46db1293d32b52d8 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Thu, 11 Jan 2024 15:26:07 +0100 Subject: [PATCH] Support HTML in credits screen --- .../protect/card_locker/AboutActivity.java | 26 ++++++++++++------- .../protect/card_locker/AboutContent.java | 18 ++++++------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/protect/card_locker/AboutActivity.java b/app/src/main/java/protect/card_locker/AboutActivity.java index 2eeb11467..58178a424 100644 --- a/app/src/main/java/protect/card_locker/AboutActivity.java +++ b/app/src/main/java/protect/card_locker/AboutActivity.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.ScrollView; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.annotation.StringRes; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -98,11 +99,7 @@ public class AboutActivity extends CatimaAppCompatActivity { } private void showCredits() { - new MaterialAlertDialogBuilder(this) - .setTitle(R.string.credits) - .setMessage(content.getContributorInfo()) - .setPositiveButton(R.string.ok, null) - .show(); + showHTML(R.string.credits, content.getContributorInfo(), null); } private void showHistory(View view) { @@ -117,7 +114,7 @@ public class AboutActivity extends CatimaAppCompatActivity { showHTML(R.string.privacy_policy, content.getPrivacyInfo(), view); } - private void showHTML(@StringRes int title, final Spanned text, View view) { + private void showHTML(@StringRes int title, final Spanned text, @Nullable View view) { int dialogContentPadding = getResources().getDimensionPixelSize(R.dimen.alert_dialog_content_padding); TextView textView = new TextView(this); textView.setText(text); @@ -125,12 +122,21 @@ public class AboutActivity extends CatimaAppCompatActivity { ScrollView scrollView = new ScrollView(this); scrollView.addView(textView); scrollView.setPadding(dialogContentPadding, dialogContentPadding / 2, dialogContentPadding, 0); - new MaterialAlertDialogBuilder(this) + + // Create dialog + MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(this); + materialAlertDialogBuilder .setTitle(title) .setView(scrollView) - .setPositiveButton(R.string.ok, null) - .setNeutralButton(R.string.view_online, (dialog, which) -> openExternalBrowser(view)) - .show(); + .setPositiveButton(R.string.ok, null); + + // Add View online button if an URL is linked to this view + if (view != null && view.getTag() != null) { + materialAlertDialogBuilder.setNeutralButton(R.string.view_online, (dialog, which) -> openExternalBrowser(view)); + } + + // Show dialog + materialAlertDialogBuilder.show(); } private void openExternalBrowser(View view) { diff --git a/app/src/main/java/protect/card_locker/AboutContent.java b/app/src/main/java/protect/card_locker/AboutContent.java index 005ec7d3b..e4e8d87fc 100644 --- a/app/src/main/java/protect/card_locker/AboutContent.java +++ b/app/src/main/java/protect/card_locker/AboutContent.java @@ -129,19 +129,19 @@ public class AboutContent { return result.toString(); } - public String getContributorInfo() { + public Spanned getContributorInfo() { StringBuilder contributorInfo = new StringBuilder(); contributorInfo.append(getCopyright()); - contributorInfo.append("\n\n"); + contributorInfo.append("

"); contributorInfo.append(context.getString(R.string.app_copyright_old)); - contributorInfo.append("\n\n"); - contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_contributors), getContributors()), HtmlCompat.FROM_HTML_MODE_COMPACT)); - contributorInfo.append("\n\n"); - contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_libraries), getThirdPartyLibraries()), HtmlCompat.FROM_HTML_MODE_COMPACT)); - contributorInfo.append("\n\n"); - contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_resources), getUsedThirdPartyAssets()), HtmlCompat.FROM_HTML_MODE_COMPACT)); + contributorInfo.append("

"); + contributorInfo.append(String.format(context.getString(R.string.app_contributors), getContributors())); + contributorInfo.append("

"); + contributorInfo.append(String.format(context.getString(R.string.app_libraries), getThirdPartyLibraries())); + contributorInfo.append("

"); + contributorInfo.append(String.format(context.getString(R.string.app_resources), getUsedThirdPartyAssets())); - return contributorInfo.toString(); + return HtmlCompat.fromHtml(contributorInfo.toString(), HtmlCompat.FROM_HTML_MODE_COMPACT); } public Spanned getHistoryInfo() {