Refactored language constants to a single enum
This commit is contained in:
parent
763ea43c61
commit
964690707b
|
@ -149,40 +149,9 @@ fun Context.setupKeyboardDialogStuff(
|
|||
}
|
||||
|
||||
fun Context.getKeyboardLanguages(): ArrayList<RadioItem> {
|
||||
return arrayListOf(
|
||||
RadioItem(LANGUAGE_BENGALI, getKeyboardLanguageText(LANGUAGE_BENGALI)),
|
||||
RadioItem(LANGUAGE_BULGARIAN, getKeyboardLanguageText(LANGUAGE_BULGARIAN)),
|
||||
RadioItem(LANGUAGE_ENGLISH_QWERTY, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTY)),
|
||||
RadioItem(LANGUAGE_ENGLISH_QWERTZ, getKeyboardLanguageText(LANGUAGE_ENGLISH_QWERTZ)),
|
||||
RadioItem(LANGUAGE_ENGLISH_DVORAK, getKeyboardLanguageText(LANGUAGE_ENGLISH_DVORAK)),
|
||||
RadioItem(LANGUAGE_FRENCH, getKeyboardLanguageText(LANGUAGE_FRENCH)),
|
||||
RadioItem(LANGUAGE_GERMAN, getKeyboardLanguageText(LANGUAGE_GERMAN)),
|
||||
RadioItem(LANGUAGE_GREEK, getKeyboardLanguageText(LANGUAGE_GREEK)),
|
||||
RadioItem(LANGUAGE_LITHUANIAN, getKeyboardLanguageText(LANGUAGE_LITHUANIAN)),
|
||||
RadioItem(LANGUAGE_ROMANIAN, getKeyboardLanguageText(LANGUAGE_ROMANIAN)),
|
||||
RadioItem(LANGUAGE_RUSSIAN, getKeyboardLanguageText(LANGUAGE_RUSSIAN)),
|
||||
RadioItem(LANGUAGE_SLOVENIAN, getKeyboardLanguageText(LANGUAGE_SLOVENIAN)),
|
||||
RadioItem(LANGUAGE_SPANISH, getKeyboardLanguageText(LANGUAGE_SPANISH)),
|
||||
RadioItem(LANGUAGE_TURKISH_Q, getKeyboardLanguageText(LANGUAGE_TURKISH_Q)),
|
||||
)
|
||||
val languages = Language.values().map { RadioItem(it.ordinal, it.getName(this)) }
|
||||
return ArrayList(languages)
|
||||
}
|
||||
|
||||
fun Context.getKeyboardLanguageText(language: Int): String {
|
||||
return when (language) {
|
||||
LANGUAGE_BENGALI -> getString(R.string.translation_bengali)
|
||||
LANGUAGE_BULGARIAN -> getString(R.string.translation_bulgarian)
|
||||
LANGUAGE_ENGLISH_DVORAK -> "${getString(R.string.translation_english)} (DVORAK)"
|
||||
LANGUAGE_ENGLISH_QWERTZ -> "${getString(R.string.translation_english)} (QWERTZ)"
|
||||
LANGUAGE_FRENCH -> getString(R.string.translation_french)
|
||||
LANGUAGE_GERMAN -> getString(R.string.translation_german)
|
||||
LANGUAGE_GREEK -> getString(R.string.translation_greek)
|
||||
LANGUAGE_LITHUANIAN -> getString(R.string.translation_lithuanian)
|
||||
LANGUAGE_ROMANIAN -> getString(R.string.translation_romanian)
|
||||
LANGUAGE_RUSSIAN -> getString(R.string.translation_russian)
|
||||
LANGUAGE_SLOVENIAN -> getString(R.string.translation_slovenian)
|
||||
LANGUAGE_SPANISH -> getString(R.string.translation_spanish)
|
||||
LANGUAGE_TURKISH_Q -> "${getString(R.string.translation_turkish)} (Q)"
|
||||
else -> "${getString(R.string.translation_english)} (QWERTY)"
|
||||
}
|
||||
}
|
||||
fun Context.getKeyboardLanguageText(language: Int) = Language.getKeyboardName(this, language)
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
private fun getDefaultLanguage(): Int {
|
||||
val conf = context.resources.configuration
|
||||
return if (conf.locale.toString().toLowerCase(Locale.getDefault()).startsWith("ru_")) {
|
||||
LANGUAGE_RUSSIAN
|
||||
Language.RUSSIAN.ordinal
|
||||
} else {
|
||||
LANGUAGE_ENGLISH_QWERTY
|
||||
Language.ENGLISH_QWERTY.ordinal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package com.simplemobiletools.keyboard.helpers
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.StringRes
|
||||
import com.simplemobiletools.keyboard.R
|
||||
|
||||
const val SHIFT_OFF = 0
|
||||
const val SHIFT_ON_ONE_CHAR = 1
|
||||
const val SHIFT_ON_PERMANENT = 2
|
||||
|
@ -21,20 +25,72 @@ const val SHOW_NUMBERS_ROW = "show_numbers_row"
|
|||
const val ITEM_SECTION_LABEL = 0
|
||||
const val ITEM_CLIP = 1
|
||||
|
||||
const val LANGUAGE_ENGLISH_QWERTY = 0
|
||||
const val LANGUAGE_RUSSIAN = 1
|
||||
const val LANGUAGE_FRENCH = 2
|
||||
const val LANGUAGE_ENGLISH_QWERTZ = 3
|
||||
const val LANGUAGE_SPANISH = 4
|
||||
const val LANGUAGE_GERMAN = 5
|
||||
const val LANGUAGE_ENGLISH_DVORAK = 6
|
||||
const val LANGUAGE_ROMANIAN = 7
|
||||
const val LANGUAGE_SLOVENIAN = 8
|
||||
const val LANGUAGE_BULGARIAN = 9
|
||||
const val LANGUAGE_TURKISH_Q = 10
|
||||
const val LANGUAGE_LITHUANIAN = 11
|
||||
const val LANGUAGE_BENGALI = 12
|
||||
const val LANGUAGE_GREEK = 13
|
||||
enum class Language(@StringRes private val stringRes: Int, private val layout: Int) {
|
||||
ENGLISH_QWERTY(
|
||||
R.string.translation_english, R.xml.keys_letters_english_qwerty
|
||||
),
|
||||
RUSSIAN(
|
||||
R.string.translation_russian, R.xml.keys_letters_russian
|
||||
),
|
||||
FRENCH(
|
||||
R.string.translation_french, R.xml.keys_letters_french
|
||||
),
|
||||
ENGLISH_QWERTZ(
|
||||
R.string.translation_english, R.xml.keys_letters_english_qwertz
|
||||
),
|
||||
SPANISH(
|
||||
R.string.translation_spanish, R.string.translation_spanish
|
||||
),
|
||||
GERMAN(
|
||||
R.string.translation_german, R.xml.keys_letters_german
|
||||
),
|
||||
ENGLISH_DVORAK(
|
||||
R.string.translation_english, R.xml.keys_letters_english_dvorak
|
||||
),
|
||||
ROMANIAN(
|
||||
R.string.translation_romanian, R.xml.keys_letters_romanian
|
||||
),
|
||||
SLOVENIAN(
|
||||
R.string.translation_slovenian, R.xml.keys_letters_slovenian
|
||||
),
|
||||
BULGARIAN(
|
||||
R.string.translation_bulgarian, R.xml.keys_letters_bulgarian
|
||||
),
|
||||
TURKISH_Q(
|
||||
R.string.translation_turkish, R.xml.keys_letters_turkish_q
|
||||
),
|
||||
LITHUANIAN(
|
||||
R.string.translation_lithuanian, R.xml.keys_letters_lithuanian
|
||||
),
|
||||
BENGALI(
|
||||
R.string.translation_bengali, R.xml.keys_letters_bengali
|
||||
),
|
||||
GREEK(
|
||||
R.string.translation_greek, R.xml.keys_letters_greek
|
||||
);
|
||||
|
||||
fun getName(context: Context): String {
|
||||
with(context) {
|
||||
return when (val language = this@Language) {
|
||||
ENGLISH_DVORAK -> "${getString(language.stringRes)} (DVORAK)"
|
||||
ENGLISH_QWERTY -> "${getString(language.stringRes)} (QWERTY)"
|
||||
ENGLISH_QWERTZ -> "${getString(language.stringRes)} (QWERTZ)"
|
||||
else -> getString(language.stringRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getKeyboardLayout(keyboardLanguage: Int): Int {
|
||||
return Language.values().getOrElse(keyboardLanguage) { ENGLISH_QWERTY }.layout
|
||||
}
|
||||
|
||||
fun getKeyboardName(context: Context, language: Int): String {
|
||||
return Language.values().getOrElse(language) { ENGLISH_QWERTY }.getName(context)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// keyboard height multiplier options
|
||||
const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1
|
||||
|
|
|
@ -270,24 +270,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
|||
}
|
||||
}
|
||||
|
||||
private fun getKeyboardLayoutXML(): Int {
|
||||
return when (baseContext.config.keyboardLanguage) {
|
||||
LANGUAGE_BENGALI -> R.xml.keys_letters_bengali
|
||||
LANGUAGE_BULGARIAN -> R.xml.keys_letters_bulgarian
|
||||
LANGUAGE_ENGLISH_DVORAK -> R.xml.keys_letters_english_dvorak
|
||||
LANGUAGE_ENGLISH_QWERTZ -> R.xml.keys_letters_english_qwertz
|
||||
LANGUAGE_FRENCH -> R.xml.keys_letters_french
|
||||
LANGUAGE_GERMAN -> R.xml.keys_letters_german
|
||||
LANGUAGE_GREEK -> R.xml.keys_letters_greek
|
||||
LANGUAGE_LITHUANIAN -> R.xml.keys_letters_lithuanian
|
||||
LANGUAGE_ROMANIAN -> R.xml.keys_letters_romanian
|
||||
LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian
|
||||
LANGUAGE_SLOVENIAN -> R.xml.keys_letters_slovenian
|
||||
LANGUAGE_SPANISH -> R.xml.keys_letters_spanish_qwerty
|
||||
LANGUAGE_TURKISH_Q -> R.xml.keys_letters_turkish_q
|
||||
else -> R.xml.keys_letters_english_qwerty
|
||||
}
|
||||
}
|
||||
private fun getKeyboardLayoutXML() = Language.getKeyboardLayout(baseContext.config.keyboardLanguage)
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
keyboardView?.setupKeyboard()
|
||||
|
|
Loading…
Reference in New Issue