From 4e82b6b7069183415ff4327a79df43ef998dc120 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 20 Nov 2017 17:08:18 +0100 Subject: [PATCH] adding a toggle for using english --- .../draw/activities/MainActivity.kt | 13 ++++++++++++ .../draw/activities/SettingsActivity.kt | 14 +++++++++++++ app/src/main/res/layout/activity_settings.xml | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt index d2358af..4e53794 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt @@ -44,6 +44,8 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { private var isEraserOn = false private var isImageCaptureIntent = false + private var storedUseEnglish = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -64,10 +66,16 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { checkIntents() checkWhatsNewDialog() + storeStateVariables() } override fun onResume() { super.onResume() + if (storedUseEnglish != config.useEnglish) { + restartActivity() + return + } + val isStrokeWidthBarEnabled = config.showBrushSize stroke_width_bar.beVisibleIf(isStrokeWidthBarEnabled) my_canvas.setIsStrokeWidthBarEnabled(isStrokeWidthBarEnabled) @@ -78,6 +86,7 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { super.onPause() config.brushColor = color config.brushSize = strokeWidth + storeStateVariables() } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -106,6 +115,10 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener { return true } + private fun storeStateVariables() { + storedUseEnglish = config.useEnglish + } + private fun launchSettings() { startActivity(Intent(applicationContext, SettingsActivity::class.java)) } diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/draw/activities/SettingsActivity.kt index 9d107e9..5c89d4b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/activities/SettingsActivity.kt @@ -1,10 +1,13 @@ package com.simplemobiletools.draw.activities import android.os.Bundle +import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.extensions.useEnglishToggled import com.simplemobiletools.draw.R import com.simplemobiletools.draw.extensions.config import kotlinx.android.synthetic.main.activity_settings.* +import java.util.* class SettingsActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -16,6 +19,7 @@ class SettingsActivity : SimpleActivity() { super.onResume() setupCustomizeColors() + setupUseEnglish() setupBrushSize() updateTextColors(settings_holder) } @@ -26,6 +30,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 setupBrushSize() { settings_show_brush_size.isChecked = config.showBrushSize settings_show_brush_size_holder.setOnClickListener { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 4b4e6de..92181fd 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -30,6 +30,26 @@ + + + + + +