From ef7e4050bb9bb97a7906e95a819094d808741888 Mon Sep 17 00:00:00 2001 From: Naveen Singh Date: Fri, 14 Jun 2024 23:06:53 +0530 Subject: [PATCH] Minor code improvement --- .../fossify/keyboard/views/MyKeyboardView.kt | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt index b4bb73b9..157f0ee7 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt @@ -87,7 +87,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut private var mTextColor = 0 private var mBackgroundColor = 0 + private var mKeyboardBackgroundColor = 0 private var mPrimaryColor = 0 + private var mStrokeColor = 0 private var mKeyColor = 0 private var mKeyColorPressed = 0 @@ -210,7 +212,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut with(context.safeStorageContext) { mTextColor = getProperTextColor() mBackgroundColor = getProperBackgroundColor() + mKeyboardBackgroundColor = getKeyboardBackgroundColor() mPrimaryColor = getProperPrimaryColor() + mStrokeColor = getStrokeColor() } mPreviewPopup = PopupWindow(context) @@ -382,7 +386,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut with(context.safeStorageContext) { mTextColor = getProperTextColor() mBackgroundColor = getProperBackgroundColor() + mKeyboardBackgroundColor = getKeyboardBackgroundColor() mPrimaryColor = getProperPrimaryColor() + mStrokeColor = getStrokeColor() mShowKeyBorders = config.showKeyBorders mUsingSystemTheme = config.isUsingSystemTheme @@ -398,28 +404,25 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut resources.getDrawable(R.drawable.keyboard_key_selector, context.theme) } - val strokeColor = context.getStrokeColor() - val backgroundColor = context.getKeyboardBackgroundColor() - if (!isMainKeyboard) { val previewBackground = background as LayerDrawable - previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(backgroundColor) - previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(strokeColor) + previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mKeyboardBackgroundColor) + previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mStrokeColor) background = previewBackground } else { - background.applyColorFilter(backgroundColor) + background.applyColorFilter(mKeyboardBackgroundColor) } val rippleBg = resources.getDrawable(R.drawable.clipboard_background, context.theme) as RippleDrawable val layerDrawable = rippleBg.findDrawableByLayerId(R.id.clipboard_background_holder) as LayerDrawable - layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(strokeColor) + layerDrawable.findDrawableByLayerId(R.id.clipboard_background_stroke).applyColorFilter(mStrokeColor) layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor) val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor() keyboardViewBinding?.apply { topKeyboardDivider.beGoneIf(wasDarkened) - topKeyboardDivider.background = ColorDrawable(strokeColor) - mToolbarHolder?.background = ColorDrawable(backgroundColor) + topKeyboardDivider.background = ColorDrawable(mStrokeColor) + mToolbarHolder?.background = ColorDrawable(mKeyboardBackgroundColor) clipboardValue.apply { background = rippleBg @@ -436,8 +439,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mToolbarHolder?.beInvisibleIf(context.isDeviceLocked) topClipboardDivider.beGoneIf(wasDarkened) - topClipboardDivider.background = ColorDrawable(strokeColor) - clipboardManagerHolder.background = ColorDrawable(backgroundColor) + topClipboardDivider.background = ColorDrawable(mStrokeColor) + clipboardManagerHolder.background = ColorDrawable(mKeyboardBackgroundColor) clipboardManagerClose.applyColorFilter(mTextColor) clipboardManagerManage.applyColorFilter(mTextColor) @@ -447,7 +450,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut clipboardContentPlaceholder2.setTextColor(mTextColor) } - setupEmojiPalette(toolbarColor = backgroundColor, backgroundColor = mBackgroundColor, textColor = mTextColor) + setupEmojiPalette(toolbarColor = mKeyboardBackgroundColor, backgroundColor = mBackgroundColor, textColor = mTextColor) if (context.config.keyboardLanguage == LANGUAGE_VIETNAMESE_TELEX) { setupLanguageTelex() } else { @@ -902,8 +905,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } val previewBackground = mPreviewText!!.background as LayerDrawable - previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(context.getKeyboardBackgroundColor()) - previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(context.getStrokeColor()) + previewBackground.findDrawableByLayerId(R.id.button_background_shape).applyColorFilter(mKeyboardBackgroundColor) + previewBackground.findDrawableByLayerId(R.id.button_background_stroke).applyColorFilter(mStrokeColor) mPreviewText!!.background = previewBackground mPreviewText!!.setTextColor(mTextColor) @@ -1464,7 +1467,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut emojiPaletteClose.applyColorFilter(textColor) emojiPaletteLabel.setTextColor(textColor) - emojiPaletteBottomBar.background = ColorDrawable(backgroundColor) + emojiPaletteBottomBar.background = ColorDrawable(toolbarColor) emojiPaletteModeChange.apply { setTextColor(textColor) setOnClickListener {