Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining and pulling members up to the superclass. #216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 1 addition & 202 deletions app/src/main/java/be/scri/services/EnglishKeyboardIME.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package be.scri.services

import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.text.InputType
import android.util.Log
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.EditorInfo.IME_ACTION_NONE
import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.MyKeyboard
import be.scri.helpers.MyKeyboard.Companion.KEYCODE_ENTER
import be.scri.views.MyKeyboardView

class EnglishKeyboardIME : SimpleKeyboardIME() {
class EnglishKeyboardIME : SimpleKeyboardIME("English") {
override fun getKeyboardLayoutXML(): Int = R.xml.keys_letters_english

override var shiftPermToggleSpeed = 500
Expand All @@ -33,53 +27,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME() {
override var hasTextBeforeCursor = false
override lateinit var binding: KeyboardViewCommandOptionsBinding

enum class ScribeState {
IDLE,
SELECT_COMMAND,
TRANSLATE,
CONJUGATE,
PLURAL,
SELECT_VERB_CONJUNCTION,
SELECT_CASE_DECLENSION,
ALREADY_PLURAL,
INVALID,
DISPLAY_INFORMATION,
}

private var currentState: ScribeState = ScribeState.IDLE
private lateinit var keyboardBinding: KeyboardViewKeyboardBinding
private var isAutoSuggestEnabled: Boolean = false

private fun shouldCommitPeriodAfterSpace(language: String): Boolean {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
return sharedPref.getBoolean("period_on_double_tap_$language", false)
}

override fun onStartInputView(
editorInfo: EditorInfo?,
restarting: Boolean,
) {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
updateEnterKeyColor(isUserDarkMode)
initializeEmojiButtons()
isAutoSuggestEnabled = sharedPref.getBoolean("emoji_suggestions_English", true)
updateButtonVisibility(isAutoSuggestEnabled)
setupIdleView()
super.onStartInputView(editorInfo, restarting)
setupCommandBarTheme(binding)
}

override fun commitPeriodAfterSpace() {
if (shouldCommitPeriodAfterSpace("English")) {
val inputConnection = currentInputConnection ?: return
inputConnection.deleteSurroundingText(1, 0)
inputConnection.commitText(". ", 1)
}
}

override fun onCreateInputView(): View {
binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater)
setupCommandBarTheme(binding)
Expand All @@ -97,89 +44,6 @@ class EnglishKeyboardIME : SimpleKeyboardIME() {
return keyboardHolder
}

private fun setupIdleView() {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
when (isUserDarkMode) {
true -> {
binding.translateBtn.setBackgroundColor(getColor(R.color.transparent))
binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent))
binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent))
binding.translateBtn.setTextColor(Color.WHITE)
binding.conjugateBtn.setTextColor(Color.WHITE)
binding.pluralBtn.setTextColor(Color.WHITE)
binding.separator2.setBackgroundColor(getColor(R.color.special_key_dark))
binding.separator3.setBackgroundColor(getColor(R.color.special_key_dark))
}
else -> {
binding.translateBtn.setBackgroundColor(getColor(R.color.transparent))
binding.conjugateBtn.setBackgroundColor(getColor(R.color.transparent))
binding.pluralBtn.setBackgroundColor(getColor(R.color.transparent))
binding.translateBtn.setTextColor(Color.BLACK)
binding.conjugateBtn.setTextColor(Color.BLACK)
binding.pluralBtn.setTextColor(Color.BLACK)
binding.separator2.setBackgroundColor(getColor(R.color.special_key_light))
binding.separator3.setBackgroundColor(getColor(R.color.special_key_light))
}
}
setupCommandBarTheme(binding)
binding.translateBtn.text = "Suggestion"
binding.conjugateBtn.text = "Suggestion"
binding.pluralBtn.text = "Suggestion"
binding.separator2.visibility = View.VISIBLE
binding.separator3.visibility = View.VISIBLE
binding.scribeKey.setOnClickListener {
updateButtonVisibility(false)
currentState = ScribeState.SELECT_COMMAND
Log.i("MY-TAG", "SELECT COMMAND STATE FROM English IME")
binding.scribeKey.foreground = getDrawable(R.drawable.close)
updateUI()
}
}

private fun setupSelectCommandView() {
binding.translateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded))
binding.conjugateBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded))
binding.pluralBtn.setBackgroundDrawable(getDrawable(R.drawable.button_background_rounded))
binding.translateBtn.text = "Translate"
binding.conjugateBtn.text = "Conjugate"
binding.pluralBtn.text = "Plural"
binding.separator2.visibility = View.GONE
binding.separator3.visibility = View.GONE
super.setupCommandBarTheme(binding)
binding.scribeKey.setOnClickListener {
currentState = ScribeState.IDLE
Log.i("MY-TAG", "IDLE STATE")
binding.scribeKey.foreground = getDrawable(R.drawable.ic_scribe_icon_vector)
updateUI()
}
binding.translateBtn.setOnClickListener {
currentState = ScribeState.TRANSLATE
Log.i("MY-TAG", "TRANSLATE STATE")
updateUI()
}
binding.conjugateBtn.setOnClickListener {
Log.i("MY-TAG", "CONJUGATE STATE")
currentState = ScribeState.CONJUGATE
updateUI()
}
binding.pluralBtn.setOnClickListener {
Log.i("MY-TAG", "PLURAL STATE")
currentState = ScribeState.PLURAL
updateUI()
}
}

private fun updateEnterKeyColor(isDarkMode: Boolean? = null) {
when (currentState) {
ScribeState.IDLE -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode)
ScribeState.SELECT_COMMAND -> keyboardView?.setEnterKeyColor(null, isDarkMode = isDarkMode)
else -> keyboardView?.setEnterKeyColor(getColor(R.color.dark_scribe_blue))
}
}

override fun onKey(code: Int) {
val inputConnection = currentInputConnection
if (keyboard == null || inputConnection == null) {
Expand Down Expand Up @@ -230,75 +94,10 @@ class EnglishKeyboardIME : SimpleKeyboardIME() {
}
}

private fun switchToToolBar() {
this.keyboardBinding = initializeKeyboardBinding()
val keyboardHolder = keyboardBinding.root
super.setupToolBarTheme(keyboardBinding)
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
when (isUserDarkMode) {
true -> {
keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_dark))
}
false -> {
keyboardBinding.topKeyboardDivider.setBackgroundColor(getColor(R.color.special_key_light))
}
}
keyboardView = keyboardBinding.keyboardView
keyboardView!!.setKeyboard(keyboard!!)
keyboardView!!.mOnKeyboardActionListener = this
keyboardBinding.scribeKey.setOnClickListener {
currentState = ScribeState.IDLE
switchToCommandToolBar()
updateUI()
}
setInputView(keyboardHolder)
}

private fun switchToCommandToolBar() {
val binding = KeyboardViewCommandOptionsBinding.inflate(layoutInflater)
this.binding = binding
val keyboardHolder = binding.root
setupCommandBarTheme(binding)
keyboardView = binding.keyboardView
keyboardView!!.setKeyboard(keyboard!!)
keyboardView!!.mOnKeyboardActionListener = this
keyboardBinding.scribeKey.setOnClickListener {
currentState = ScribeState.IDLE
setupSelectCommandView()
updateUI()
}
setInputView(keyboardHolder)
}

override fun onCreate() {
super.onCreate()
keyboard = MyKeyboard(this, getKeyboardLayoutXML(), enterKeyType)
onCreateInputView()
setupCommandBarTheme(binding)
}

private fun updateUI() {
val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val isSystemDarkMode = currentNightMode == Configuration.UI_MODE_NIGHT_YES
val isUserDarkMode = sharedPref.getBoolean("dark_mode", isSystemDarkMode)
when (currentState) {
ScribeState.IDLE -> {
setupIdleView()
initializeEmojiButtons()
updateButtonVisibility(isAutoSuggestEnabled)
}
ScribeState.SELECT_COMMAND -> setupSelectCommandView()
else -> switchToToolBar()
}
updateEnterKeyColor(isUserDarkMode)
}

private fun initializeKeyboardBinding(): KeyboardViewKeyboardBinding {
val keyboardBinding = KeyboardViewKeyboardBinding.inflate(layoutInflater)
return keyboardBinding
}
}
Loading