From 84b58e514341aa3093fbd0ad92887ef7638be97e Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 12 Aug 2022 22:57:06 +0200 Subject: [PATCH] show a language picker on Android 13+ --- app/build.gradle | 2 +- .../calculator/activities/MainActivity.kt | 1 - .../calculator/activities/SettingsActivity.kt | 23 ++++++++++++----- app/src/main/res/layout/activity_settings.xml | 25 +++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8ca35588..a187e575 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:9938692154' + implementation 'com.github.SimpleMobileTools:Simple-Commons:84c7bdf0f5' implementation 'me.grantland:autofittextview:0.2.1' implementation 'net.objecthunter:exp4j:0.4.8' diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt index a808731b..2c4460c8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.calculator.activities import android.content.Context import android.content.Intent import android.os.Bundle -import android.view.Menu import android.view.View import android.view.WindowManager import com.simplemobiletools.calculator.BuildConfig diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt index fbb37899..213d5e4a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/SettingsActivity.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.IS_CUSTOMIZING_COLORS import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.helpers.isTiramisuPlus import kotlinx.android.synthetic.main.activity_settings.* import java.util.* import kotlin.system.exitProcess @@ -28,6 +29,7 @@ class SettingsActivity : SimpleActivity() { setupPurchaseThankYou() setupCustomizeColors() setupUseEnglish() + setupLanguage() setupVibrate() setupPreventPhoneFromSleeping() setupUseCommaAsDecimalMark() @@ -49,6 +51,7 @@ class SettingsActivity : SimpleActivity() { // make sure the corners at ripple fit the stroke rounded corners if (settings_purchase_thank_you_holder.isGone()) { settings_use_english_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme) + settings_language_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme) } settings_purchase_thank_you_holder.setOnClickListener { @@ -64,13 +67,8 @@ class SettingsActivity : SimpleActivity() { } private fun setupUseEnglish() { - settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en") + settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) settings_use_english.isChecked = config.useEnglish - - if (settings_use_english_holder.isGone() && settings_purchase_thank_you_holder.isGone()) { - settings_vibrate_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme) - } - settings_use_english_holder.setOnClickListener { settings_use_english.toggle() config.useEnglish = settings_use_english.isChecked @@ -78,6 +76,19 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupLanguage() { + settings_language.text = Locale.getDefault().displayLanguage + settings_language_holder.beVisibleIf(isTiramisuPlus()) + + if (settings_use_english_holder.isGone() && settings_language_holder.isGone() && settings_purchase_thank_you_holder.isGone()) { + settings_vibrate_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme) + } + + settings_language_holder.setOnClickListener { + launchChangeAppLanguageIntent() + } + } + private fun setupVibrate() { settings_vibrate.isChecked = config.vibrateOnButtonPress settings_vibrate_holder.setOnClickListener { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index aadfccdd..76ae88d6 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,6 +1,7 @@ @@ -130,6 +131,30 @@ + + + + + + + +