Extracted languages enum to the Language.kt file

This commit is contained in:
merkost 2023-05-22 13:15:56 +10:00
parent 964690707b
commit ec7dd289e9
2 changed files with 72 additions and 67 deletions

View File

@ -25,73 +25,6 @@ const val SHOW_NUMBERS_ROW = "show_numbers_row"
const val ITEM_SECTION_LABEL = 0
const val ITEM_CLIP = 1
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
const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2

View File

@ -0,0 +1,72 @@
package com.simplemobiletools.keyboard.helpers
import android.content.Context
import androidx.annotation.StringRes
import com.simplemobiletools.keyboard.R
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)
}
}
}