diff --git a/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeModel.kt b/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeModel.kt index fbeb203..d6f0f9f 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeModel.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeModel.kt @@ -13,5 +13,6 @@ package com.frogobox.appkeyboard.model data class KeyboardThemeModel( val name: String, val description: String, + val themType: ThemeType, val background: Int, ) \ No newline at end of file diff --git a/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeType.kt b/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeType.kt index 86fc817..c65373c 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeType.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/model/KeyboardThemeType.kt @@ -11,30 +11,35 @@ import com.frogobox.appkeyboard.R * ----------------------------------------- */ +enum class ThemeType { + COLOR, IMAGE +} enum class KeyboardThemeType( private val label: String, private val desc: String, + private val themeType: ThemeType, private val background: Int, ) { - DEFAULT("Default", "Default Color", R.color.color_bg_keyboard_default), - RED("Red", "Red Color", R.color.color_bg_keyboard_red), - GREEN("Green", "Green Color", R.color.color_bg_keyboard_green), - YELLOW("Yellow", "Yellow Color", R.color.color_bg_keyboard_yellow), - BLUE("Blue", "Blue Color", R.color.color_bg_keyboard_blue), - IMAGE_BG_DARK("Image", "Sample Wallpaper", R.drawable.ic_wallpaper_dummy) - ; + DEFAULT("Default", "Default Color", ThemeType.COLOR, R.color.color_bg_keyboard_default), + RED("Red", "Red Color", ThemeType.COLOR, R.color.color_bg_keyboard_red), + GREEN("Green", "Green Color", ThemeType.COLOR, R.color.color_bg_keyboard_green), + YELLOW("Yellow", "Yellow Color", ThemeType.COLOR, R.color.color_bg_keyboard_yellow), + BLUE("Blue", "Blue Color", ThemeType.COLOR, R.color.color_bg_keyboard_blue), + IMAGE_BG_DARK("Image", "Sample Wallpaper", ThemeType.IMAGE, R.drawable.ic_wallpaper_dummy); fun mapToModel(): KeyboardThemeModel { return KeyboardThemeModel( this.label, this.desc, + this.themeType, this.background ) } companion object { - infix fun from(value: String): KeyboardThemeType = entries.firstOrNull { it.name == value } ?: DEFAULT + infix fun from(value: String): KeyboardThemeType = + entries.firstOrNull { it.name == value } ?: DEFAULT } } \ No newline at end of file diff --git a/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt b/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt index 0f46374..4ea64e3 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt @@ -14,6 +14,7 @@ import com.frogobox.appkeyboard.databinding.ItemKeyboardHeaderBinding import com.frogobox.appkeyboard.databinding.KeyboardImeBinding import com.frogobox.appkeyboard.model.KeyboardFeatureModel import com.frogobox.appkeyboard.model.KeyboardFeatureType +import com.frogobox.appkeyboard.model.ThemeType import com.frogobox.appkeyboard.ui.main.MainActivity import com.frogobox.libkeyboard.common.core.BaseKeyboardIME import com.frogobox.recycler.core.FrogoRecyclerNotifyListener @@ -43,11 +44,27 @@ class KeyboardIME : BaseKeyboardIME() { override fun setupTheme() { binding?.apply { - holderKeyboard.setBackgroundColor(getColorExt(android.R.color.transparent)) - ivBackgroundKeyboard.setImageResource(pref.loadPrefInt( + + val background = pref.loadPrefInt( KeyboardUtil.KEYBOARD_COLOR, - getColorExt(R.color.color_bg_keyboard_default) - )) + R.color.color_bg_keyboard_default + ) + + val backgroundType = ThemeType.valueOf( + pref.loadPrefString( + KeyboardUtil.KEYBOARD_COLOR_TYPE, + ThemeType.COLOR.name + ) + ) + + when (backgroundType) { + ThemeType.COLOR -> { + ivBackgroundKeyboard.setBackgroundColor(getColorExt(background)) + } + ThemeType.IMAGE -> { + ivBackgroundKeyboard.setImageResource(background) + } + } } } @@ -363,7 +380,7 @@ class KeyboardIME : BaseKeyboardIME() { ) } - private fun getStateToggle(key: String) : Boolean { + private fun getStateToggle(key: String): Boolean { return pref.loadPrefBoolean(key, true) } diff --git a/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardUtil.kt b/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardUtil.kt index e08b967..bb0e2c1 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardUtil.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/services/KeyboardUtil.kt @@ -21,6 +21,7 @@ class KeyboardUtil @Inject constructor( companion object { const val KEYBOARD_TYPE = "KEYBOARD_TYPE" const val KEYBOARD_COLOR = "KEYBOARD_COLOR" + const val KEYBOARD_COLOR_TYPE = "KEYBOARD_COLOR_TYPE" } private fun getStateToggle(key: String) : Boolean { diff --git a/app/src/main/java/com/frogobox/appkeyboard/ui/language/KeyboardLanguageActivity.kt b/app/src/main/java/com/frogobox/appkeyboard/ui/language/KeyboardLanguageActivity.kt index ca35167..4431c2f 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/ui/language/KeyboardLanguageActivity.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/ui/language/KeyboardLanguageActivity.kt @@ -7,7 +7,6 @@ import androidx.activity.viewModels import com.frogobox.appkeyboard.common.base.BaseActivity import com.frogobox.appkeyboard.databinding.ActivityKeyboardLanguageBinding import com.frogobox.appkeyboard.databinding.ItemLanguageKeyboardBinding -import com.frogobox.appkeyboard.model.KeyboardThemeModel import com.frogobox.recycler.core.FrogoRecyclerNotifyListener import com.frogobox.recycler.core.IFrogoBindingAdapter import com.frogobox.recycler.ext.injectorBinding diff --git a/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeActivity.kt b/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeActivity.kt index ad750e3..71aafd7 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeActivity.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeActivity.kt @@ -122,7 +122,7 @@ class ThemeActivity : BaseActivity(), "Are you sure you want to change keyboard theme?", listenerNo = {}, listenerYes = { - viewModel.setThemeColor(data.background) { + viewModel.setThemeColor(data) { viewModel.getThemeData() showToast("${data.name} Theme Applied") } diff --git a/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeViewModel.kt b/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeViewModel.kt index 40e779d..a859a41 100644 --- a/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeViewModel.kt +++ b/app/src/main/java/com/frogobox/appkeyboard/ui/theme/ThemeViewModel.kt @@ -38,8 +38,9 @@ class ThemeViewModel @Inject constructor( return pref.loadPrefInt(KeyboardUtil.KEYBOARD_COLOR, R.color.color_bg_keyboard_default) } - fun setThemeColor(color: Int, onSuccess: () -> Unit) { - pref.savePrefInt(KeyboardUtil.KEYBOARD_COLOR, color, object : FrogoStateResponse { + fun setThemeColor(data: KeyboardThemeModel, onSuccess: () -> Unit) { + pref.savePrefString(KeyboardUtil.KEYBOARD_COLOR_TYPE, data.themType.name) + pref.savePrefInt(KeyboardUtil.KEYBOARD_COLOR, data.background, object : FrogoStateResponse { override fun onFailed(statusCode: Int, errorMessage: String) {} override fun onFinish() {} override fun onHideProgress() {} diff --git a/app/src/main/res/layout/keyboard_ime.xml b/app/src/main/res/layout/keyboard_ime.xml index 7b4d448..c897c68 100644 --- a/app/src/main/res/layout/keyboard_ime.xml +++ b/app/src/main/res/layout/keyboard_ime.xml @@ -3,8 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/holder_keyboard" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="@color/color_bg_keyboard_default"> + android:layout_height="wrap_content"> : InputMethodService(), OnKeybo currentInputConnection?.commitText(text, 0) } - override fun initialSetupKeyboard() { + override fun initialSetupKeyboard() {} - } - - override fun setupTheme() { - - } + override fun setupTheme() {} override fun setupBinding() { initialSetupKeyboard() @@ -158,29 +154,19 @@ abstract class BaseKeyboardIME : InputMethodService(), OnKeybo } override fun invalidateKeyboard() { - + setupTheme() setupFeatureKeyboard() } - override fun initCurrentInputConnection() { - - } - - override fun hideMainKeyboard() { - - } - - override fun showMainKeyboard() { + override fun initCurrentInputConnection() {} - } - - override fun showOnlyKeyboard() { + override fun hideMainKeyboard() {} - } + override fun showMainKeyboard() {} - override fun hideOnlyKeyboard() { + override fun showOnlyKeyboard() {} - } + override fun hideOnlyKeyboard() {} override fun EditText.showKeyboardExt() { setOnFocusChangeListener { v, hasFocus -> diff --git a/frogo-keyboard/src/main/res/values-night/colors.xml b/frogo-keyboard/src/main/res/values-night/colors.xml index 3c9e496..45d4fcd 100644 --- a/frogo-keyboard/src/main/res/values-night/colors.xml +++ b/frogo-keyboard/src/main/res/values-night/colors.xml @@ -14,11 +14,9 @@ #F9FCFF #80232427 #232427 - #232427 + #80232427 #181921 #80B1BEFF - - \ No newline at end of file diff --git a/frogo-keyboard/src/main/res/values/colors.xml b/frogo-keyboard/src/main/res/values/colors.xml index e8a2301..b7d9199 100644 --- a/frogo-keyboard/src/main/res/values/colors.xml +++ b/frogo-keyboard/src/main/res/values/colors.xml @@ -27,8 +27,8 @@ @android:color/transparent #001E2C - #FFFFFF - #EFEFEF + #80FFFFFF + #80EFEFEF #757575 #FFFFFF