From 0e591e85d62759b6344da3364229df092d1c61fd Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 6 Nov 2021 09:56:32 +0100 Subject: [PATCH] updating the About page --- .../commons/activities/AboutActivity.kt | 160 ++++++----- .../activities/ContributorsActivity.kt | 12 +- .../commons/extensions/String.kt | 25 +- .../main/res/drawable/ic_article_vector.xml | 12 + .../src/main/res/drawable/ic_email_vector.xml | 6 +- .../src/main/res/drawable/ic_face_vector.xml | 9 + .../src/main/res/drawable/ic_heart_vector.xml | 9 + .../res/drawable/ic_question_mark_vector.xml | 9 + .../src/main/res/layout/activity_about.xml | 265 +++++++++++++----- .../main/res/layout/activity_contributors.xml | 11 +- 10 files changed, 353 insertions(+), 165 deletions(-) create mode 100644 commons/src/main/res/drawable/ic_article_vector.xml create mode 100644 commons/src/main/res/drawable/ic_face_vector.xml create mode 100644 commons/src/main/res/drawable/ic_heart_vector.xml create mode 100644 commons/src/main/res/drawable/ic_question_mark_vector.xml diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt index d00179091..f500e2a93 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt @@ -1,15 +1,14 @@ package com.simplemobiletools.commons.activities +import android.content.ActivityNotFoundException import android.content.Intent +import android.content.Intent.* import android.os.Build import android.os.Bundle -import android.text.Html -import android.text.method.LinkMovementMethod import android.view.Menu -import android.view.View +import androidx.core.net.toUri import com.simplemobiletools.commons.R import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog -import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.RateStarsDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* @@ -30,13 +29,24 @@ class AboutActivity : BaseSimpleActivity() { setContentView(R.layout.activity_about) appName = intent.getStringExtra(APP_NAME) ?: "" linkColor = getAdjustedPrimaryColor() + + arrayOf( + about_faq_icon, + about_rate_us_icon, + about_invite_icon, + about_contributors_icon, + about_more_apps_icon, + about_email_icon, + about_licenses_icon + ).forEach { + it.applyColorFilter(baseConfig.textColor) + } } override fun onResume() { super.onResume() updateTextColors(about_holder) - setupWebsite() setupEmail() setupFAQ() setupMoreApps() @@ -54,122 +64,109 @@ class AboutActivity : BaseSimpleActivity() { return super.onCreateOptionsMenu(menu) } - private fun setupWebsite() { - val websiteText = String.format(getString(R.string.two_string_placeholder), getString(R.string.website_label), getString(R.string.my_website)) - about_website.text = websiteText - } - private fun setupEmail() { - val label = getString(R.string.email_label) - val email = getString(R.string.my_email) - - val appVersion = String.format(getString(R.string.app_version, intent.getStringExtra(APP_VERSION_NAME))) - val deviceOS = String.format(getString(R.string.device_os), Build.VERSION.RELEASE) - val newline = "%0D%0A" - val separator = "------------------------------" - val body = "$appVersion$newline$deviceOS$newline$separator$newline$newline" - val href = "$label
$email" - about_email.text = Html.fromHtml(href) - - if (intent.getBooleanExtra(SHOW_FAQ_BEFORE_MAIL, false) && !baseConfig.wasBeforeAskingShown) { - about_email.setOnClickListener { + about_email_holder.setOnClickListener { + val msg = "${getString(R.string.before_asking_question_read_faq)}\n\n${getString(R.string.make_sure_latest)}" + if (intent.getBooleanExtra(SHOW_FAQ_BEFORE_MAIL, false) && !baseConfig.wasBeforeAskingShown) { baseConfig.wasBeforeAskingShown = true - about_email.movementMethod = LinkMovementMethod.getInstance() - about_email.setOnClickListener(null) - val msg = "${getString(R.string.before_asking_question_read_faq)}\n\n${getString(R.string.make_sure_latest)}" - ConfirmationDialog(this, msg, 0, R.string.read_faq, R.string.skip) { - about_faq_label.performClick() + ConfirmationAdvancedDialog(this, msg, 0, R.string.read_faq, R.string.skip) { success -> + if (success) { + about_faq_holder.performClick() + } else { + about_email_holder.performClick() + } + } + } else { + val appVersion = String.format(getString(R.string.app_version, intent.getStringExtra(APP_VERSION_NAME))) + val deviceOS = String.format(getString(R.string.device_os), Build.VERSION.RELEASE) + val newline = "\n" + val separator = "------------------------------" + val body = "$appVersion$newline$deviceOS$newline$separator$newline$newline" + + val address = getString(R.string.my_email) + val selectorIntent = Intent(ACTION_SENDTO) + .setData("mailto:$address".toUri()) + val emailIntent = Intent(ACTION_SEND).apply { + putExtra(EXTRA_EMAIL, arrayOf(address)) + putExtra(EXTRA_SUBJECT, appName) + putExtra(EXTRA_TEXT, body) + selector = selectorIntent + } + + try { + startActivity(emailIntent) + } catch (e: ActivityNotFoundException) { + toast(R.string.no_app_found) + } catch (e: Exception) { + showErrorToast(e) } } - } else { - about_email.movementMethod = LinkMovementMethod.getInstance() } } private fun setupFAQ() { val faqItems = intent.getSerializableExtra(APP_FAQ) as ArrayList - about_faq_label.beVisibleIf(faqItems.isNotEmpty()) - about_faq_label.setOnClickListener { - openFAQ(faqItems) - } - - about_faq.beVisibleIf(faqItems.isNotEmpty()) - about_faq.setOnClickListener { - openFAQ(faqItems) - } - - about_faq.setTextColor(linkColor) - about_faq.underlineText() - } - - private fun openFAQ(faqItems: ArrayList) { - Intent(applicationContext, FAQActivity::class.java).apply { - putExtra(APP_ICON_IDS, getAppIconIDs()) - putExtra(APP_LAUNCHER_NAME, getAppLauncherName()) - putExtra(APP_FAQ, faqItems) - startActivity(this) + about_faq_holder.beVisibleIf(faqItems.isNotEmpty()) + about_faq_holder.setOnClickListener { + Intent(applicationContext, FAQActivity::class.java).apply { + putExtra(APP_ICON_IDS, getAppIconIDs()) + putExtra(APP_LAUNCHER_NAME, getAppLauncherName()) + putExtra(APP_FAQ, faqItems) + startActivity(this) + } } } private fun setupMoreApps() { - about_more_apps.setOnClickListener { + about_more_apps_holder.setOnClickListener { launchViewIntent("https://play.google.com/store/apps/dev?id=9070296388022589266") } - about_more_apps.setTextColor(linkColor) } private fun setupInvite() { - about_invite.setOnClickListener { + about_invite_holder.setOnClickListener { val text = String.format(getString(R.string.share_text), appName, getStoreUrl()) Intent().apply { - action = Intent.ACTION_SEND - putExtra(Intent.EXTRA_SUBJECT, appName) - putExtra(Intent.EXTRA_TEXT, text) + action = ACTION_SEND + putExtra(EXTRA_SUBJECT, appName) + putExtra(EXTRA_TEXT, text) type = "text/plain" - startActivity(Intent.createChooser(this, getString(R.string.invite_via))) + startActivity(createChooser(this, getString(R.string.invite_via))) } } - about_invite.setTextColor(linkColor) } private fun setupContributors() { - about_contributors.setTextColor(linkColor) - about_contributors.underlineText() - about_contributors.setOnClickListener { + about_contributors_holder.setOnClickListener { val intent = Intent(applicationContext, ContributorsActivity::class.java) startActivity(intent) } } private fun setupRateUs() { - if (baseConfig.appRunCount < 5) { - about_rate_us.visibility = View.GONE - } else { - about_rate_us.setOnClickListener { - if (baseConfig.wasBeforeRateShown) { - if (baseConfig.wasAppRated) { - redirectToRateUs() - } else { - RateStarsDialog(this) - } + about_rate_us_holder.setOnClickListener { + if (baseConfig.wasBeforeRateShown) { + if (baseConfig.wasAppRated) { + redirectToRateUs() } else { - baseConfig.wasBeforeRateShown = true - val msg = "${getString(R.string.before_rate_read_faq)}\n\n${getString(R.string.make_sure_latest)}" - ConfirmationAdvancedDialog(this, msg, 0, R.string.read_faq, R.string.skip) { - if (it) { - about_faq_label.performClick() - } else { - about_rate_us.performClick() - } + RateStarsDialog(this) + } + } else { + baseConfig.wasBeforeRateShown = true + val msg = "${getString(R.string.before_rate_read_faq)}\n\n${getString(R.string.make_sure_latest)}" + ConfirmationAdvancedDialog(this, msg, 0, R.string.read_faq, R.string.skip) { success -> + if (success) { + about_faq_holder.performClick() + } else { + about_rate_us_holder.performClick() } } } } - about_rate_us.setTextColor(linkColor) } private fun setupLicense() { - about_license.setOnClickListener { + about_licenses_holder.setOnClickListener { Intent(applicationContext, LicenseActivity::class.java).apply { putExtra(APP_ICON_IDS, getAppIconIDs()) putExtra(APP_LAUNCHER_NAME, getAppLauncherName()) @@ -177,7 +174,6 @@ class AboutActivity : BaseSimpleActivity() { startActivity(this) } } - about_license.setTextColor(linkColor) } private fun setupFacebook() { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ContributorsActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ContributorsActivity.kt index c278a6ec9..b3e43d56b 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ContributorsActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ContributorsActivity.kt @@ -1,10 +1,12 @@ package com.simplemobiletools.commons.activities import android.os.Bundle +import android.text.Html +import android.text.method.LinkMovementMethod import android.view.Menu import com.simplemobiletools.commons.R import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor -import com.simplemobiletools.commons.extensions.underlineText +import com.simplemobiletools.commons.extensions.removeUnderlines import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.APP_ICON_IDS import com.simplemobiletools.commons.helpers.APP_LAUNCHER_NAME @@ -21,12 +23,12 @@ class ContributorsActivity : BaseSimpleActivity() { setContentView(R.layout.activity_contributors) updateTextColors(contributors_holder) - contributors_development_label.setTextColor(getAdjustedPrimaryColor()) - contributors_development_label.underlineText() - contributors_translation_label.setTextColor(getAdjustedPrimaryColor()) - contributors_translation_label.underlineText() + + contributors_label.text = Html.fromHtml(getString(R.string.contributors_label)) + contributors_label.removeUnderlines() + contributors_label.movementMethod = LinkMovementMethod.getInstance() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt index d71bb7e61..330b1d5a3 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt @@ -9,8 +9,10 @@ import android.provider.MediaStore import android.telephony.PhoneNumberUtils import android.text.Spannable import android.text.SpannableString +import android.text.TextPaint import android.text.TextUtils import android.text.style.ForegroundColorSpan +import android.text.style.URLSpan import android.widget.TextView import com.bumptech.glide.signature.ObjectKey import com.simplemobiletools.commons.helpers.* @@ -46,7 +48,8 @@ fun String.isAValidFilename(): Boolean { return true } -fun String.getOTGPublicPath(context: Context) = "${context.baseConfig.OTGTreeUri}/document/${context.baseConfig.OTGPartition}%3A${substring(context.baseConfig.OTGPath.length).replace("/", "%2F")}" +fun String.getOTGPublicPath(context: Context) = + "${context.baseConfig.OTGTreeUri}/document/${context.baseConfig.OTGPartition}%3A${substring(context.baseConfig.OTGPath.length).replace("/", "%2F")}" fun String.isMediaFile() = isImageFast() || isVideoFast() || isGif() || isRawFast() || isSvg() || isPortrait() @@ -270,6 +273,26 @@ fun String.getDateTimeFromDateString(showYearsSince: Boolean, viewToUpdate: Text return date } +fun TextView.removeUnderlines() { + val spannable = SpannableString(text) + val spans = spannable.getSpans(0, spannable.length, URLSpan::class.java) + for (span in spans) { + val start = spannable.getSpanStart(span) + val end = spannable.getSpanEnd(span) + spannable.removeSpan(span) + val newSpan = URLSpanNoUnderline(span.url) + spannable.setSpan(newSpan, start, end, 0) + } + text = spannable +} + +private class URLSpanNoUnderline(url: String?) : URLSpan(url) { + override fun updateDrawState(textPaint: TextPaint) { + super.updateDrawState(textPaint) + textPaint.isUnderlineText = false + } +} + fun String.getMimeType(): String { val typesMap = HashMap().apply { put("323", "text/h323") diff --git a/commons/src/main/res/drawable/ic_article_vector.xml b/commons/src/main/res/drawable/ic_article_vector.xml new file mode 100644 index 000000000..91604efa9 --- /dev/null +++ b/commons/src/main/res/drawable/ic_article_vector.xml @@ -0,0 +1,12 @@ + + + + diff --git a/commons/src/main/res/drawable/ic_email_vector.xml b/commons/src/main/res/drawable/ic_email_vector.xml index 199210923..2b606f8f4 100644 --- a/commons/src/main/res/drawable/ic_email_vector.xml +++ b/commons/src/main/res/drawable/ic_email_vector.xml @@ -3,7 +3,7 @@ android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> - + diff --git a/commons/src/main/res/drawable/ic_face_vector.xml b/commons/src/main/res/drawable/ic_face_vector.xml new file mode 100644 index 000000000..fc9762668 --- /dev/null +++ b/commons/src/main/res/drawable/ic_face_vector.xml @@ -0,0 +1,9 @@ + + + diff --git a/commons/src/main/res/drawable/ic_heart_vector.xml b/commons/src/main/res/drawable/ic_heart_vector.xml new file mode 100644 index 000000000..54c45ad2b --- /dev/null +++ b/commons/src/main/res/drawable/ic_heart_vector.xml @@ -0,0 +1,9 @@ + + + diff --git a/commons/src/main/res/drawable/ic_question_mark_vector.xml b/commons/src/main/res/drawable/ic_question_mark_vector.xml new file mode 100644 index 000000000..03c1c8f13 --- /dev/null +++ b/commons/src/main/res/drawable/ic_question_mark_vector.xml @@ -0,0 +1,9 @@ + + + diff --git a/commons/src/main/res/layout/activity_about.xml b/commons/src/main/res/layout/activity_about.xml index 992a73e14..131d8917a 100644 --- a/commons/src/main/res/layout/activity_about.xml +++ b/commons/src/main/res/layout/activity_about.xml @@ -8,107 +8,233 @@ + android:layout_height="wrap_content"> - + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_faq_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_rate_us_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_invite_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_contributors_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_more_apps_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + + + + + + + android:layout_below="@+id/about_email_holder" + android:background="?attr/selectableItemBackground" + android:padding="@dimen/medium_margin"> - + - + + + + android:layout_below="@+id/about_licenses_holder" + android:layout_margin="@dimen/activity_margin" + android:text="@string/follow_us" + android:textSize="@dimen/bigger_text_size" /> diff --git a/commons/src/main/res/layout/activity_contributors.xml b/commons/src/main/res/layout/activity_contributors.xml index 5e2a3bc5e..76882bcee 100644 --- a/commons/src/main/res/layout/activity_contributors.xml +++ b/commons/src/main/res/layout/activity_contributors.xml @@ -17,7 +17,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/development" - android:textColor="@color/color_primary" /> + android:textColor="@color/color_primary" + android:textFontWeight="600" /> + android:textColor="@color/color_primary" + android:textFontWeight="600" /> - + android:textColorLink="@color/color_primary" />