Skip to content

Commit

Permalink
update: fixing bug change theme
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed Mar 16, 2024
1 parent b5426bc commit a0a53c4
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ package com.frogobox.appkeyboard.model
data class KeyboardThemeModel(
val name: String,
val description: String,
val themType: ThemeType,
val background: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
27 changes: 22 additions & 5 deletions app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,11 +44,27 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {

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)
}
}
}
}

Expand Down Expand Up @@ -363,7 +380,7 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {
)
}

private fun getStateToggle(key: String) : Boolean {
private fun getStateToggle(key: String): Boolean {
return pref.loadPrefBoolean(key, true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ThemeActivity : BaseActivity<ActivityThemeBinding>(),
"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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.
override fun onFinish() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.
override fun onHideProgress() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/keyboard_ime.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
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">

<ImageView
android:id="@+id/iv_background_keyboard"
android:layout_width="@dimen/frogo_dimen_0dp"
android:layout_height="@dimen/frogo_dimen_0dp"
android:contentDescription="@string/dummy"
android:scaleType="centerCrop"
android:src="@drawable/ic_wallpaper_dummy"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,43 +144,29 @@ abstract class BaseKeyboardIME<VB : ViewBinding> : InputMethodService(), OnKeybo
currentInputConnection?.commitText(text, 0)
}

override fun initialSetupKeyboard() {
override fun initialSetupKeyboard() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

}

override fun setupTheme() {

}
override fun setupTheme() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

override fun setupBinding() {
initialSetupKeyboard()
setupTheme()
}

override fun invalidateKeyboard() {

setupTheme()
setupFeatureKeyboard()
}

override fun initCurrentInputConnection() {

}

override fun hideMainKeyboard() {

}

override fun showMainKeyboard() {
override fun initCurrentInputConnection() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

}

override fun showOnlyKeyboard() {
override fun hideMainKeyboard() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

}
override fun showMainKeyboard() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

override fun hideOnlyKeyboard() {
override fun showOnlyKeyboard() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

}
override fun hideOnlyKeyboard() {}

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed. Warning

This empty block of code can be removed.

override fun EditText.showKeyboardExt() {
setOnFocusChangeListener { v, hasFocus ->
Expand Down
4 changes: 1 addition & 3 deletions frogo-keyboard/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
<color name="keypad_text">#F9FCFF</color>
<color name="keypad">#80232427</color>
<color name="keypad_mini">#232427</color>
<color name="keypad_stroke">#232427</color>
<color name="keypad_stroke">#80232427</color>

<color name="keypad_action_icon">#181921</color>
<color name="keypad_action_background">#80B1BEFF</color>



</resources>
4 changes: 2 additions & 2 deletions frogo-keyboard/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<color name="keyboard_board">@android:color/transparent</color>

<color name="keypad_text">#001E2C</color>
<color name="keypad">#FFFFFF</color>
<color name="keypad_stroke">#EFEFEF</color>
<color name="keypad">#80FFFFFF</color>
<color name="keypad_stroke">#80EFEFEF</color>
<color name="keypad_pressed">#757575</color>

<color name="keypad_action_icon">#FFFFFF</color>
Expand Down

0 comments on commit a0a53c4

Please sign in to comment.