fix(language): fix review code from @tibbi

Signed-off-by: Hung <>
This commit is contained in:
Henry 2023-06-27 11:43:23 +07:00 committed by Hung
parent 177be0205f
commit 0ead92bab0
4 changed files with 8 additions and 11 deletions

View file

@ -14,7 +14,6 @@ import com.simplemobiletools.keyboard.extensions.getKeyboardLanguages
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_LARGE import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_LARGE
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_SMALL import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_SMALL
import com.simplemobiletools.keyboard.helpers.LANGUAGE_VIETNAMESE_TELEX
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
import java.util.* import java.util.*
import kotlin.system.exitProcess import kotlin.system.exitProcess

View file

@ -5,7 +5,7 @@ import org.json.JSONObject
import java.io.InputStream import java.io.InputStream
private var cachedEmojiData: MutableList<String>? = null private var cachedEmojiData: MutableList<String>? = null
val cachedVNTelexData: HashMap<String,String> = HashMap() val cachedVNTelexData: HashMap<String, String> = HashMap()
/** /**
* Reads the emoji list at the given [path] and returns an parsed [MutableList]. If the * Reads the emoji list at the given [path] and returns an parsed [MutableList]. If the
@ -64,18 +64,18 @@ fun parseRawEmojiSpecsFile(context: Context, path: String): MutableList<String>
} }
fun parseRawJsonSpecsFile(context: Context, path: String): HashMap<String,String> { fun parseRawJsonSpecsFile(context: Context, path: String): HashMap<String, String> {
if (cachedVNTelexData.isNotEmpty()) { if (cachedVNTelexData.isNotEmpty()) {
return cachedVNTelexData return cachedVNTelexData
} }
try { try {
val inputStream: InputStream = context.assets.open(path) val inputStream: InputStream = context.assets.open(path)
val jsonString = inputStream.bufferedReader().use{it.readText()} val jsonString = inputStream.bufferedReader().use { it.readText() }
val jsonData = JSONObject(jsonString) val jsonData = JSONObject(jsonString)
val rulesObj = jsonData.getJSONObject("rules") val rulesObj = jsonData.getJSONObject("rules")
val ruleKeys = rulesObj.keys() val ruleKeys = rulesObj.keys()
while (ruleKeys.hasNext()){ while (ruleKeys.hasNext()) {
val key = ruleKeys.next() val key = ruleKeys.next()
val value = rulesObj.getString(key) val value = rulesObj.getString(key)
cachedVNTelexData[key] = value cachedVNTelexData[key] = value

View file

@ -188,7 +188,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
val word = fullText.subSequence(lastIndexEmpty, fullText.length).trim().toString() val word = fullText.subSequence(lastIndexEmpty, fullText.length).trim().toString()
val wordChars = word.toCharArray() val wordChars = word.toCharArray()
val predictWord = StringBuilder() val predictWord = StringBuilder()
for (char in wordChars.size -1 downTo 0) { for (char in wordChars.size - 1 downTo 0) {
predictWord.append(wordChars[char]) predictWord.append(wordChars[char])
val shouldChangeText = predictWord.reverse().toString() val shouldChangeText = predictWord.reverse().toString()
if (cachedVNTelexData.containsKey(shouldChangeText)) { if (cachedVNTelexData.containsKey(shouldChangeText)) {
@ -208,8 +208,6 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
} }
} }
} }
} }
} }
} }

View file

@ -418,9 +418,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor) setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor)
if(context.config.keyboardLanguage == LANGUAGE_VIETNAMESE_TELEX){ if (context.config.keyboardLanguage == LANGUAGE_VIETNAMESE_TELEX) {
setupLanguageTelex() setupLanguageTelex()
}else{ } else {
cachedVNTelexData.clear() cachedVNTelexData.clear()
} }
setupStoredClips() setupStoredClips()