diff --git a/app/src/main/java/com/rathanak/khmerroman/keyboard/R2KhmerService.kt b/app/src/main/java/com/rathanak/khmerroman/keyboard/R2KhmerService.kt index e7ace69..bc590ae 100644 --- a/app/src/main/java/com/rathanak/khmerroman/keyboard/R2KhmerService.kt +++ b/app/src/main/java/com/rathanak/khmerroman/keyboard/R2KhmerService.kt @@ -11,6 +11,7 @@ import android.os.Build import android.os.VibrationEffect import android.os.Vibrator import android.text.InputType +import android.util.Log import android.util.SparseArray import android.view.KeyEvent import android.view.View @@ -75,6 +76,7 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener { private var previousTwo = "" private var isStartSen = true private var isKeyDown: Boolean = false + private var isSpellCheckSelected: Boolean = false var currentInputPassword: Boolean = false var bannerIdsData: MutableList = mutableListOf() var currentBannerIndex = 0 @@ -497,20 +499,10 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener { fun setCurrentText(typoWord: String, selectText: String, startPos: Int, endPos: Int) { //TODO: send to typoWord -> selectText - mockInput() + isSpellCheckSelected = true currentInputConnection.beginBatchEdit() currentInputConnection.setComposingRegion(startPos, endPos); - currentInputConnection.setComposingText(selectText, selectText.length) - currentInputConnection.finishComposingText() - currentInputConnection.endBatchEdit() - } - - fun mockInput () { -// val newText = "អត្ថបទសម្រាប់កាពិនិត្យអក្ខរាវិរុទ្ធ" - val newText = "អត្ថបទ\nសម្រាប់កាពិនិត្យអក្ខរាវិរុទ្ធ" - currentInputConnection.beginBatchEdit() - currentInputConnection.setComposingRegion(0,getCurrentText().length); - currentInputConnection.commitText(newText, newText.length) + currentInputConnection.setComposingText(selectText, startPos) currentInputConnection.finishComposingText() currentInputConnection.endBatchEdit() } @@ -552,6 +544,11 @@ class R2KhmerService : InputMethodService(), KeyboardActionListener { candidatesStart, candidatesEnd ) + if(isSpellCheckSelected) { + isSpellCheckSelected = false + return + } + smartbarManager.performSpellChecking() if (candidateChoosed && firstCommitCandidate) { diff --git a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SmartbarManager.kt b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SmartbarManager.kt index 6e5ac9b..84dca4f 100644 --- a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SmartbarManager.kt +++ b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SmartbarManager.kt @@ -3,7 +3,6 @@ package com.rathanak.khmerroman.keyboard.smartbar import android.content.Intent import android.graphics.Color import android.net.Uri -import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.Button @@ -23,9 +22,9 @@ import io.realm.Realm import kotlinx.android.synthetic.main.smartbar.view.* import kotlinx.coroutines.* -enum class SPELLCHECKER { NORMAL, TYPING, VALIDATION, SPELLING_ERROR, NETWORK_ERROR, REACH_LIMIT_ERROR, INVALID_ERROR, OPEN_TOGGLE } +enum class SPELLCHECKER { NORMAL, TYPING, VALIDATION, SPELLING_ERROR, NETWORK_ERROR, REACH_LIMIT_ERROR, TOKEN_INVALID_ERROR } -class SmartbarManager(private val r_2_khmer: R2KhmerService) { +class SmartbarManager(private val r2Khmer: R2KhmerService) { private var smartbarView: LinearLayout? = null private var isComposingEnabled: Boolean = false private var isDarkMood: Boolean = false @@ -35,10 +34,10 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { private var result: List = emptyList() private var viewState: SPELLCHECKER = SPELLCHECKER.NORMAL private var isAppToggleChecked: Boolean = false - private val spellSuggestionManager: SpellSuggestionManager = SpellSuggestionManager(this, r_2_khmer) + private val spellSuggestionManager: SpellSuggestionManager = SpellSuggestionManager(this, r2Khmer) fun createSmartbarView(): LinearLayout { - val smartbarView = View.inflate(r_2_khmer.context, R.layout.smartbar, null) as LinearLayout + val smartbarView = View.inflate(r2Khmer.context, R.layout.smartbar, null) as LinearLayout this.smartbarView = smartbarView this.smartbarView!!.btnOpenApp.setOnClickListener { launchApp() @@ -48,22 +47,14 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { if (isChecked) { toggleBarLayOut(true) this.smartbarView!!.settingsList.visibility = View.GONE - if (isComposingEnabled) { - r_2_khmer.customInputMethodView?.visibility = View.VISIBLE; - spellSuggestionManager.spellSuggestionView?.visibility = View.GONE - } } else { checkButtonOptionsVisibility() toggleBarLayOut(false) this.smartbarView!!.settingsList.visibility = View.VISIBLE - - if (isComposingEnabled) { - r_2_khmer.customInputMethodView?.visibility = View.GONE; - spellSuggestionManager.spellSuggestionView?.visibility = View.VISIBLE - } } isAppToggleChecked = isChecked updateLogoBtnImage() + updateSpellSuggestionView() } this.smartbarView!!.btnDownloadData.setOnClickListener { it.visibility = View.GONE @@ -76,10 +67,10 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { } this.smartbarView!!.bannerImage.setOnClickListener { - if(r_2_khmer.bannerTargetUrl != "") { - val intent = Intent(Intent.ACTION_VIEW, Uri.parse(r_2_khmer.bannerTargetUrl)) + if(r2Khmer.bannerTargetUrl != "") { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(r2Khmer.bannerTargetUrl)) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - r_2_khmer.context.startActivity(intent) + r2Khmer.context.startActivity(intent) } } @@ -109,7 +100,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { } if (R2KhmerService.downloadDataStatus == KeyboardPreferences.STATUS_NONE) { - Glide.with(r_2_khmer.context) + Glide.with(r2Khmer.context) .load(R.drawable.banner_download_data) .into(this.smartbarView!!.btnDownloadData) @@ -120,7 +111,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { return } else if (R2KhmerService.downloadDataStatus == KeyboardPreferences.STATUS_DOWNLOAD_FAIL) { - Glide.with(r_2_khmer.context) + Glide.with(r2Khmer.context) .load(R.drawable.banner_download_data_fail) .into(this.smartbarView!!.btnDownloadData) @@ -154,7 +145,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { this.smartbarView!!.candidatesContainer.visibility = View.GONE this.smartbarView!!.numbersList!!.visibility = View.GONE if (show) { - if (r_2_khmer.currentInputPassword) { + if (r2Khmer.currentInputPassword) { this.smartbarView!!.numbersList!!.visibility = View.VISIBLE } else if (suggestionCount > 0) { this.smartbarView!!.candidatesContainer.visibility = View.VISIBLE @@ -171,12 +162,12 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { } if(bannerID != "") { - Glide.with(r_2_khmer.context) + Glide.with(r2Khmer.context) .load(bannerID) .error(R.drawable.banner_default_animate) .into(this.smartbarView!!.bannerImage) } else { - Glide.with(r_2_khmer.context) + Glide.with(r2Khmer.context) .load(R.drawable.banner_default_animate) .error(R.drawable.banner_default_animate) .into(this.smartbarView!!.bannerImage) @@ -231,7 +222,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { this.smartbarView!!.candidatesList.removeAllViews() val layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) if (result.isNotEmpty()) for(word in result) { - val btnSuggestion = Button(r_2_khmer.context) + val btnSuggestion = Button(r2Khmer.context) btnSuggestion.layoutParams =layoutParams btnSuggestion.text = word.toString() btnSuggestion.setTextColor(Styles.keyStyle.labelColor) @@ -248,12 +239,6 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { fun setTyping(typing: Boolean) { isTyping = typing - viewState = if(isTyping) { - SPELLCHECKER.TYPING - } else { - SPELLCHECKER.NORMAL - } - updateLogoBtnImage() } fun destroy() { @@ -261,7 +246,9 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { } fun performSpellChecking() { - spellSuggestionManager.performSpellChecking(r_2_khmer.getCurrentText()) + if(isSpellSuggestionEnable()) { + spellSuggestionManager.performSpellChecking(r2Khmer.getCurrentText()) + } } fun setCurrentViewState(state: SPELLCHECKER) { @@ -291,7 +278,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { this.smartbarView!!.btnToggleENCorrection.visibility = View.VISIBLE } - if (r_2_khmer.currentInputPassword) { + if (r2Khmer.currentInputPassword) { this.smartbarView!!.btnOpenApp.visibility = View.GONE } else { this.smartbarView!!.btnOpenApp.visibility = View.VISIBLE @@ -321,54 +308,82 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { this.smartbarView!!.btnToggleENCorrection.isChecked = isENChecked!! this.smartbarView!!.btnToggleAutoCorrection.setOnCheckedChangeListener { buttonView, isChecked -> + KhmerLangApp.preferences?.putBoolean(KeyboardPreferences.KEY_AUTO_TYPING_CORRECTION_MODE, isChecked) if (isChecked) { buttonView.setBackgroundResource(R.drawable.btn_auto) - // TODO: checkInput sentence spell check + performSpellChecking() } else { buttonView.setBackgroundResource(R.drawable.btn_auto_off) - // TODO: change to keyboard layout } - KhmerLangApp.preferences?.putBoolean(KeyboardPreferences.KEY_AUTO_TYPING_CORRECTION_MODE, isChecked) + updateSpellSuggestionView() } + val autoTypeSpellCheck = KhmerLangApp.preferences?.getBoolean(KeyboardPreferences.KEY_AUTO_TYPING_CORRECTION_MODE, false) + this.smartbarView!!.btnToggleAutoCorrection.isChecked = autoTypeSpellCheck!! } private fun updateLogoBtnImage() { - if (isAppToggleChecked) { + if(this.smartbarView == null) { + return + } + + if(this.smartbarView!!.btnAppLogo == null) { + return + } + + if (!isAppToggleChecked) { this.smartbarView!!.btnAppLogo.setBackgroundResource(R.drawable.ic_btn_khmerlang_off_v2) return } - var currentIcon = R.drawable.ic_btn_khmerlang - when(viewState) { + if (!isSpellSuggestionEnable()) { + this.smartbarView!!.btnAppLogo.setBackgroundResource(R.drawable.ic_btn_khmerlang) + return + } + + var currentIcon = when(viewState) { SPELLCHECKER.TYPING -> { - currentIcon = R.drawable.btn_base_typing + R.drawable.btn_base_validation } SPELLCHECKER.VALIDATION -> { - currentIcon = R.drawable.btn_base_validation + R.drawable.btn_base_validation } SPELLCHECKER.NETWORK_ERROR -> { - currentIcon = R.drawable.btn_base_network_error + R.drawable.btn_base_network_error } SPELLCHECKER.REACH_LIMIT_ERROR -> { - currentIcon = R.drawable.btn_base_react_limit + R.drawable.btn_base_react_limit } - SPELLCHECKER.INVALID_ERROR -> { - currentIcon = R.drawable.btn_base_invalid_token + SPELLCHECKER.TOKEN_INVALID_ERROR -> { + R.drawable.btn_base_invalid_token } SPELLCHECKER.SPELLING_ERROR -> { - currentIcon = R.drawable.btn_khmerlang_mobile_danger - } - SPELLCHECKER.OPEN_TOGGLE -> { - currentIcon = R.drawable.ic_btn_khmerlang_off_v2 + R.drawable.btn_khmerlang_mobile_danger } else -> { - currentIcon = R.drawable.ic_btn_khmerlang + R.drawable.ic_btn_khmerlang } } this.smartbarView!!.btnAppLogo.setBackgroundResource(currentIcon) } + private fun updateSpellSuggestionView() { + r2Khmer.customInputMethodView?.visibility = View.VISIBLE; + spellSuggestionManager.spellSuggestionView?.visibility = View.GONE + + if (!isAppToggleChecked && isSpellSuggestionEnable()) { + if (isComposingEnabled) { + r2Khmer.customInputMethodView?.visibility = View.GONE; + spellSuggestionManager.spellSuggestionView?.visibility = View.VISIBLE + } + } + } + + private fun isSpellSuggestionEnable(): Boolean { + val autoTypeSpellCheck = KhmerLangApp.preferences?.getBoolean(KeyboardPreferences.KEY_AUTO_TYPING_CORRECTION_MODE, false) + return autoTypeSpellCheck == true && isComposingEnabled + } + // load spell suggestion data private suspend fun getSuggestion(prevOne: String, prevTwo: String, composingText: String, isStartSen: Boolean) { coroutineScope { @@ -419,16 +434,16 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { val text = view.text.toString() if (text.isNotEmpty()) { // r_2_khmer.commitCandidate(text + " ") - r_2_khmer.commitCandidate(text, isCorrection) + r2Khmer.commitCandidate(text, isCorrection) } } private fun launchApp() { - val pm = r_2_khmer.context.packageManager - val intent:Intent? = pm.getLaunchIntentForPackage(r_2_khmer.context.packageName) + val pm = r2Khmer.context.packageManager + val intent:Intent? = pm.getLaunchIntentForPackage(r2Khmer.context.packageName) intent?.addCategory(Intent.CATEGORY_LAUNCHER) if(intent!=null){ - r_2_khmer.context.startActivity(intent) + r2Khmer.context.startActivity(intent) } } @@ -454,7 +469,7 @@ class SmartbarManager(private val r_2_khmer: R2KhmerService) { R.id.btnNum9 -> KeyData(57, "9") else -> KeyData(0) } - r_2_khmer.sendKeyPress(keyData) + r2Khmer.sendKeyPress(keyData) } private fun listenJobDone() { diff --git a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionAdapter.kt b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionAdapter.kt index 8d51616..12dca7b 100644 --- a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionAdapter.kt +++ b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionAdapter.kt @@ -19,7 +19,7 @@ import com.rathanak.khmerroman.R import com.rathanak.khmerroman.keyboard.R2KhmerService import com.rathanak.khmerroman.request.SpellCheckResultDTO -class SpellSuggestionAdapter(private val r_2_khmer: R2KhmerService, private val context: Context, var suggestionsList: java.util.ArrayList) : BaseAdapter() { +class SpellSuggestionAdapter(private val smartSpell: SpellSuggestionManager, private val context: Context, var suggestionsList: java.util.ArrayList) : BaseAdapter() { override fun getCount(): Int { return suggestionsList.size } @@ -42,6 +42,7 @@ class SpellSuggestionAdapter(private val r_2_khmer: R2KhmerService, private val val btnSpellItemClose = convertView.findViewById(R.id.btnSpellItemClose) as ImageButton btnSpellItemClose.setOnClickListener { suggestionsList.removeAt(position); // remove the item from the data list + handleAfterRemoveItem() notifyDataSetChanged(); } @@ -60,8 +61,13 @@ class SpellSuggestionAdapter(private val r_2_khmer: R2KhmerService, private val val word = it btnWord.text = word btnWord.setOnClickListener { - r_2_khmer.setCurrentText(typoWord, word, startIndex, endIndex + 1) - suggestionsList.removeAt(position); + smartSpell.setCurrentText(typoWord, word, startIndex, endIndex + 1) + suggestionsList.removeAt(position) + if(typoWord.length != word.length) { + updateNextListStartEndPos(position, word.length - typoWord.length) + } + + handleAfterRemoveItem() notifyDataSetChanged(); } @@ -70,4 +76,17 @@ class SpellSuggestionAdapter(private val r_2_khmer: R2KhmerService, private val return convertView } + + private fun handleAfterRemoveItem() { + if(suggestionsList.isNullOrEmpty()) { + smartSpell.onCallEmptyResult() + } + } + + private fun updateNextListStartEndPos(position: Int, updateLength: Int) { + for (index in position until suggestionsList.size) { + suggestionsList[index].startIndex += updateLength + suggestionsList[index].endIndex += updateLength + } + } } diff --git a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionManager.kt b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionManager.kt index a7b9909..5985cbc 100644 --- a/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionManager.kt +++ b/app/src/main/java/com/rathanak/khmerroman/keyboard/smartbar/SpellSuggestionManager.kt @@ -1,6 +1,5 @@ package com.rathanak.khmerroman.keyboard.smartbar -import android.util.Log import android.view.View import android.widget.LinearLayout import androidx.core.graphics.drawable.DrawableCompat @@ -15,7 +14,6 @@ import kotlinx.android.synthetic.main.smartbar.view.btnOpenApp import kotlinx.android.synthetic.main.smartbar.view.smartbar import kotlinx.android.synthetic.main.spell_suggestion.view.spellSuggestionList import kotlinx.android.synthetic.main.spell_suggestion.view.noDataText -import kotlinx.android.synthetic.main.spell_suggestion.view.noInternetConnection import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -25,26 +23,21 @@ import retrofit2.Call import retrofit2.Callback import retrofit2.Response -class SpellSuggestionManager(private val smartBar: SmartbarManager, private val r_2_khmer: R2KhmerService) { +class SpellSuggestionManager(private val smartBar: SmartbarManager, private val r2Khmer: R2KhmerService) { private var spellCheckJob: Job? = null - var currentSentence: String = "" + private var currentSentence: String = "" var spellSuggestionView: LinearLayout? = null private var isDarkMood: Boolean = false var spellSuggestionAdapter: SpellSuggestionAdapter? = null - var spellSuggestionItems: ArrayList = ArrayList() + private var spellSuggestionItems: ArrayList = ArrayList() fun createSpellSuggestionView(): LinearLayout { - var spellSuggestionView = View.inflate(r_2_khmer.context, R.layout.spell_suggestion, null) as LinearLayout + var spellSuggestionView = View.inflate(r2Khmer.context, R.layout.spell_suggestion, null) as LinearLayout this.spellSuggestionView = spellSuggestionView - val listView = spellSuggestionView.spellSuggestionList - spellSuggestionAdapter = SpellSuggestionAdapter(r_2_khmer, r_2_khmer.context, spellSuggestionItems) - listView.adapter = spellSuggestionAdapter - val emptyView = spellSuggestionView.noDataText - var noInternet = spellSuggestionView.noInternetConnection - if(true) { - listView.emptyView = emptyView - } else { - listView.emptyView = noInternet - } + val listSuggestionView = spellSuggestionView.spellSuggestionList + spellSuggestionAdapter = SpellSuggestionAdapter(this, r2Khmer.context, spellSuggestionItems) + listSuggestionView.adapter = spellSuggestionAdapter + listSuggestionView.emptyView = spellSuggestionView.noDataText + return spellSuggestionView } @@ -70,19 +63,54 @@ class SpellSuggestionManager(private val smartBar: SmartbarManager, private val } fun performSpellChecking(sentence: String) { - if(currentSentence.equals(sentence)) { + if(currentSentence == sentence) { return } - smartBar.setCurrentViewState(SPELLCHECKER.VALIDATION) - currentSentence = sentence spellCheckJob?.cancel() + + spellSuggestionAdapter?.suggestionsList?.clear() + spellSuggestionAdapter?.notifyDataSetChanged() + + if (sentence.isEmpty()) { + smartBar.setCurrentViewState(SPELLCHECKER.NORMAL) + spellSuggestionAdapter?.suggestionsList?.clear() + spellSuggestionAdapter?.notifyDataSetChanged() + manageEmptyList(R.string.spell_suggestion_no_typo, R.color.colorPrimary) + return + } else if (sentence.length <= 2) { + smartBar.setCurrentViewState(SPELLCHECKER.NORMAL) + spellSuggestionAdapter?.suggestionsList?.clear() + spellSuggestionAdapter?.notifyDataSetChanged() + manageEmptyList(R.string.spell_suggestion_text_too_short, R.color.colorPrimary) + return + } + + currentSentence = sentence + manageEmptyList(R.string.spell_suggestion_loading, R.color.colorPrimary) + smartBar.setCurrentViewState(SPELLCHECKER.VALIDATION) spellCheckJob = GlobalScope.launch(Dispatchers.Main) { delay(500) spellChecking(currentSentence) } } + fun setCurrentText(typoWord: String, selectText: String, startPos: Int, endPos: Int) { + r2Khmer.setCurrentText(typoWord, selectText, startPos, endPos) + currentSentence = r2Khmer.getCurrentText() + } + + fun onCallEmptyResult() { + manageEmptyList(R.string.spell_suggestion_no_typo, R.color.colorPrimary) + smartBar.setCurrentViewState(SPELLCHECKER.NORMAL) + } + + private fun manageEmptyList(emptyMessageID: Int, colorId: Int) { + spellSuggestionView?.noDataText?.setText(emptyMessageID) + spellSuggestionView?.noDataText?.setTextColor(r2Khmer.getColorInt(colorId)) + } + + private fun spellChecking(searchText: String) { val requestBody = SpellCheckRequestDTO(searchText) val call = ApiClient.apiService.spellCheckIng(requestBody) @@ -92,25 +120,39 @@ class SpellSuggestionManager(private val smartBar: SmartbarManager, private val // Handle the retrieved spell check data val responseBody = response.body() if (responseBody != null) { - spellSuggestionAdapter?.suggestionsList = responseBody.results - spellSuggestionAdapter?.notifyDataSetChanged() - if (responseBody.results.size > 0) { + if (!responseBody.results.isNullOrEmpty()) { smartBar.setCurrentViewState(SPELLCHECKER.SPELLING_ERROR) + spellSuggestionAdapter?.suggestionsList = responseBody.results + spellSuggestionAdapter?.notifyDataSetChanged() } else { smartBar.setCurrentViewState(SPELLCHECKER.NORMAL) } + + manageEmptyList(R.string.spell_suggestion_no_typo, R.color.colorPrimary) } } else { // Handle error - smartBar.setCurrentViewState(SPELLCHECKER.REACH_LIMIT_ERROR) + val errorCode = response.code() + if(errorCode == 400) { + smartBar.setCurrentViewState(SPELLCHECKER.NORMAL) + manageEmptyList(R.string.spell_suggestion_no_internet, R.color.danger) + }else if(errorCode == 429) { + smartBar.setCurrentViewState(SPELLCHECKER.REACH_LIMIT_ERROR) + manageEmptyList(R.string.spell_suggestion_react_limit, R.color.danger) + }else if(errorCode == 401) { + smartBar.setCurrentViewState(SPELLCHECKER.TOKEN_INVALID_ERROR) + manageEmptyList(R.string.spell_suggestion_token_invalid, R.color.danger) + }else { + smartBar.setCurrentViewState(SPELLCHECKER.NETWORK_ERROR) + manageEmptyList(R.string.spell_suggestion_no_internet, R.color.danger) + } } } override fun onFailure(call: Call, t: Throwable) { // Handle failure smartBar.setCurrentViewState(SPELLCHECKER.NETWORK_ERROR) -// smartBar.setCurrentViewState(SPELLCHECKER.INVALID_ERROR) -// smartBar.setCurrentViewState(SPELLCHECKER.REACH_LIMIT_ERROR) + manageEmptyList(R.string.spell_suggestion_no_internet, R.color.danger) } }) } diff --git a/app/src/main/java/com/rathanak/khmerroman/request/SpellCheckResultDTO.kt b/app/src/main/java/com/rathanak/khmerroman/request/SpellCheckResultDTO.kt index 47e613b..bd1fc60 100644 --- a/app/src/main/java/com/rathanak/khmerroman/request/SpellCheckResultDTO.kt +++ b/app/src/main/java/com/rathanak/khmerroman/request/SpellCheckResultDTO.kt @@ -1,10 +1,17 @@ package com.rathanak.khmerroman.request +import com.google.gson.annotations.SerializedName + data class SpellCheckResultDTO( - val startIndex: Int, - val endIndex: Int, + @SerializedName("start_index") + var startIndex: Int, + @SerializedName("end_index") + var endIndex: Int, + @SerializedName("word") val word: String, + @SerializedName("suggestions") val suggestions: Array, + @SerializedName("scores") val scores: Array ) { override fun equals(other: Any?): Boolean { diff --git a/app/src/main/res/layout/spell_suggestion.xml b/app/src/main/res/layout/spell_suggestion.xml index 75e28fe..e5f33d8 100644 --- a/app/src/main/res/layout/spell_suggestion.xml +++ b/app/src/main/res/layout/spell_suggestion.xml @@ -13,7 +13,7 @@ android:layout_height="@dimen/spell_suggestion_height"> - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c5d381..2729c9b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,10 +71,12 @@ - រកមិនឃើញកំហុសទេ !! - មិនអាចភ្ជាប់ទៅម៉ាស៊ីនមេ! - អត្ថបទខ្លីពេក!\nសូមបញ្ចូលយ៉ាងហោចណាស់ ៥ តួអក្សរដើម្បីពិនិត្យមើលបញ្ហា។]]> + រកមិនឃើញកំហុសទេ!!! + មិនអាចភ្ជាប់ទៅម៉ាស៊ីនមេ!!! + អត្ថបទខ្លីពេក!!! សំណើច្រើនដល់ដែនកំណត់!!! + TOKEN មិន​ត្រឹមត្រូវ!!! + កំពុងពិនិត្យ... 5 6 7