Removed languages refactoring (Language.kt enum)

This commit is contained in:
merkost 2023-05-29 17:18:35 +10:00
parent 326772789b
commit 88c4bb5ebb
5 changed files with 83 additions and 94 deletions

View File

@ -4,11 +4,7 @@ import android.content.ClipboardManager
import android.content.Context
import android.graphics.Color
import android.os.IBinder
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import android.view.*
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.content.res.ResourcesCompat
@ -149,9 +145,47 @@ fun Context.setupKeyboardDialogStuff(
}
fun Context.getKeyboardLanguages(): ArrayList<RadioItem> {
val languages = Language.sorted(this).map { RadioItem(it.ordinal, it.getName(this)) }
return ArrayList(languages)
return arrayListOf(
RadioItem(LANGUAGE_BENGALI, getKeyboardLanguageText(LANGUAGE_BENGALI)),
RadioItem(LANGUAGE_BULGARIAN, getKeyboardLanguageText(LANGUAGE_BULGARIAN)),
RadioItem(LANGUAGE_DANISH, getKeyboardLanguageText(LANGUAGE_DANISH)),
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_NORWEGIAN, getKeyboardLanguageText(LANGUAGE_NORWEGIAN)),
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_SWEDISH, getKeyboardLanguageText(LANGUAGE_SWEDISH)),
RadioItem(LANGUAGE_TURKISH_Q, getKeyboardLanguageText(LANGUAGE_TURKISH_Q)),
)
}
fun Context.getKeyboardLanguageText(language: Int): String {
return when (language) {
LANGUAGE_BENGALI -> getString(R.string.translation_bengali)
LANGUAGE_BULGARIAN -> getString(R.string.translation_bulgarian)
LANGUAGE_DANISH -> getString(R.string.translation_danish)
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_NORWEGIAN -> getString(R.string.translation_norwegian)
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_SWEDISH -> getString(R.string.translation_swedish)
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)

View File

@ -48,9 +48,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.ordinal
LANGUAGE_RUSSIAN
} else {
Language.ENGLISH_QWERTY.ordinal
LANGUAGE_ENGLISH_QWERTY
}
}
}

View File

@ -75,6 +75,24 @@ 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
const val LANGUAGE_NORWEGIAN = 14
const val LANGUAGE_SWEDISH = 15
const val LANGUAGE_DANISH = 16
// keyboard height multiplier options
const val KEYBOARD_HEIGHT_MULTIPLIER_SMALL = 1
const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2

View File

@ -1,83 +0,0 @@
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) {
BENGALI(
R.string.translation_bengali, R.xml.keys_letters_bengali
),
BULGARIAN(
R.string.translation_bulgarian, R.xml.keys_letters_bulgarian
),
DANISH(
R.string.translation_danish, R.xml.keys_letters_danish
),
ENGLISH_DVORAK(
R.string.translation_english, R.xml.keys_letters_english_dvorak
),
ENGLISH_QWERTY(
R.string.translation_english, R.xml.keys_letters_english_qwerty
),
ENGLISH_QWERTZ(
R.string.translation_english, R.xml.keys_letters_english_qwertz
),
FRENCH(
R.string.translation_french, R.xml.keys_letters_french
),
GERMAN(
R.string.translation_german, R.xml.keys_letters_german
),
GREEK(
R.string.translation_greek, R.xml.keys_letters_greek
),
LITHUANIAN(
R.string.translation_lithuanian, R.xml.keys_letters_lithuanian
),
NORWEGIAN(
R.string.translation_norwegian, R.xml.keys_letters_norwegian
),
ROMANIAN(
R.string.translation_romanian, R.xml.keys_letters_romanian
),
RUSSIAN(
R.string.translation_russian, R.xml.keys_letters_russian
),
SLOVENIAN(
R.string.translation_slovenian, R.xml.keys_letters_slovenian
),
SPANISH(
R.string.translation_spanish, R.string.translation_spanish
),
SWEDISH(
R.string.translation_swedish, R.xml.keys_letters_swedish
),
TURKISH_Q(
R.string.translation_turkish, R.xml.keys_letters_turkish_q
);
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 sorted(context: Context) = Language.values().sortedBy { context.getString(it.stringRes) }
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)
}
}
}

View File

@ -294,7 +294,27 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
}
}
private fun getKeyboardLayoutXML() = Language.getKeyboardLayout(baseContext.config.keyboardLanguage)
private fun getKeyboardLayoutXML(): Int {
return when (baseContext.config.keyboardLanguage) {
LANGUAGE_BENGALI -> R.xml.keys_letters_bengali
LANGUAGE_BULGARIAN -> R.xml.keys_letters_bulgarian
LANGUAGE_DANISH -> R.xml.keys_letters_danish
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_NORWEGIAN -> R.xml.keys_letters_norwegian
LANGUAGE_ROMANIAN -> R.xml.keys_letters_romanian
LANGUAGE_RUSSIAN -> R.xml.keys_letters_russian
LANGUAGE_SLOVENIAN -> R.xml.keys_letters_slovenian
LANGUAGE_SWEDISH -> R.xml.keys_letters_swedish
LANGUAGE_SPANISH -> R.xml.keys_letters_spanish_qwerty
LANGUAGE_TURKISH_Q -> R.xml.keys_letters_turkish_q
else -> R.xml.keys_letters_english_qwerty
}
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
keyboardView?.setupKeyboard()