Skip to content

Commit

Permalink
show a language picker on Android 13+
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed Aug 12, 2022
1 parent b00ee85 commit 84b58e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,7 @@ class SettingsActivity : SimpleActivity() {
setupPurchaseThankYou()
setupCustomizeColors()
setupUseEnglish()
setupLanguage()
setupVibrate()
setupPreventPhoneFromSleeping()
setupUseCommaAsDecimalMark()
Expand All @@ -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 {
Expand All @@ -64,20 +67,28 @@ 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
exitProcess(0)
}
}

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 {
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down Expand Up @@ -130,6 +131,30 @@

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_language_holder"
style="@style/SettingsHolderTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_background">

<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_language_label"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/language" />

<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_language"
style="@style/SettingsTextValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/settings_language_label"
tools:text="English" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/settings_vibrate_holder"
style="@style/SettingsHolderCheckboxStyle"
Expand Down

0 comments on commit 84b58e5

Please sign in to comment.