adding a toggle for forcing english

This commit is contained in:
tibbi 2017-11-30 20:32:57 +01:00
parent 6d056683f1
commit 9d5c905207
5 changed files with 66 additions and 0 deletions

View File

@ -9,6 +9,7 @@
tools:node="remove"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_launcher_name"

View File

@ -0,0 +1,11 @@
package com.simplemobiletools.thankyou
import android.app.Application
import com.simplemobiletools.commons.extensions.checkUseEnglish
class App : Application() {
override fun onCreate() {
super.onCreate()
checkUseEnglish()
}
}

View File

@ -6,27 +6,41 @@ import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.commons.extensions.appLaunched
import com.simplemobiletools.commons.extensions.checkWhatsNew
import com.simplemobiletools.commons.extensions.restartActivity
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.thankyou.BuildConfig
import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.extensions.config
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity() {
var storedUseEnglish = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
appLaunched()
checkWhatsNewDialog()
storeStateVariables()
}
override fun onResume() {
super.onResume()
if (storedUseEnglish != config.useEnglish) {
restartActivity()
return
}
updateTextColors(activity_main)
}
override fun onPause() {
super.onPause()
storeStateVariables()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
@ -41,6 +55,12 @@ class MainActivity : SimpleActivity() {
return true
}
private fun storeStateVariables() {
config.apply {
storedUseEnglish = useEnglish
}
}
private fun launchSettings() {
startActivity(Intent(this, SettingsActivity::class.java))
}

View File

@ -4,10 +4,13 @@ import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Bundle
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.useEnglishToggled
import com.simplemobiletools.thankyou.R
import com.simplemobiletools.thankyou.extensions.config
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
class SettingsActivity : SimpleActivity() {
@ -20,6 +23,7 @@ class SettingsActivity : SimpleActivity() {
super.onResume()
setupCustomizeColors()
setupUseEnglish()
setupHideLauncherIcon()
updateTextColors(settings_holder)
}
@ -30,6 +34,16 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
settings_use_english.isChecked = config.useEnglish
settings_use_english_holder.setOnClickListener {
settings_use_english.toggle()
config.useEnglish = settings_use_english.isChecked
useEnglishToggled()
}
}
private fun setupHideLauncherIcon() {
settings_hide_launcher_icon.isChecked = config.hideLauncherIcon
settings_hide_launcher_icon_holder.setOnClickListener {

View File

@ -30,6 +30,26 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_use_english_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_use_english"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/use_english_language"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_hide_launcher_icon_holder"
android:layout_width="match_parent"