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

FEATURE :: Theme Keyboard #65

Merged
merged 9 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
android:name=".ui.toggle.ToggleActivity"
android:exported="false" />

<activity
android:name=".ui.theme.ThemeActivity"
android:exported="false" />

<activity android:name=".ui.language.KeyboardLanguageActivity"
android:exported="false" />

Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/com/frogobox/appkeyboard/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import android.content.Context
import android.os.Build
import androidx.emoji2.bundled.BundledEmojiCompatConfig
import androidx.emoji2.text.EmojiCompat
import com.frogobox.appkeyboard.di.koin.databaseModule
import com.frogobox.appkeyboard.di.koin.delegateModule
import com.frogobox.appkeyboard.di.koin.repositoryModule
import com.frogobox.appkeyboard.di.koin.viewModelModule
import com.frogobox.sdk.FrogoKoinApplication
import dagger.hilt.android.HiltAndroidApp
import org.koin.core.KoinApplication
import java.util.Locale

/**
Expand Down Expand Up @@ -43,17 +38,6 @@ class MainApp : FrogoKoinApplication() {

}

override fun setupKoinModule(koinApplication: KoinApplication) {
koinApplication.modules(
listOf(
delegateModule,
repositoryModule,
databaseModule,
viewModelModule,
)
)
}

override fun onCreate() {
super.onCreate()
instance = this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.frogobox.appkeyboard.common.ext

import android.content.Context
import com.frogobox.appkeyboard.util.Constant.PREF_KEYBOARD_TYPE
import com.frogobox.appkeyboard.util.Constant.PREF_ROOT_NAME
import com.frogobox.libkeyboard.R
import com.frogobox.sdk.delegate.preference.PreferenceDelegatesImpl

/**
* Created by Faisal Amir on 24/10/22
* -----------------------------------------
Expand All @@ -14,9 +8,4 @@ import com.frogobox.sdk.delegate.preference.PreferenceDelegatesImpl
* -----------------------------------------
* Copyright (C) Frogobox ID / amirisback
* All rights reserved
*/

fun Context.getKeyboardType(): Int {
val pref = PreferenceDelegatesImpl(this, PREF_ROOT_NAME)
return pref.loadPrefInt(PREF_KEYBOARD_TYPE, R.xml.keys_letters_qwerty)
}
*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.frogobox.appkeyboard.di.hilt
package com.frogobox.appkeyboard.di

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/keyboard/keyboard/app/src/main/java/com/frogobox/appkeyboard/di/DatabaseModule.kt is not ending with a new line.

import android.content.Context
import com.frogobox.appkeyboard.data.local.autotext.AutoTextDao
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.frogobox.appkeyboard.di.hilt
package com.frogobox.appkeyboard.di

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/keyboard/keyboard/app/src/main/java/com/frogobox/appkeyboard/di/NetworkModule.kt is not ending with a new line.

import dagger.Module
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.frogobox.appkeyboard.di.hilt
package com.frogobox.appkeyboard.di

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/keyboard/keyboard/app/src/main/java/com/frogobox/appkeyboard/di/RepositoryModule.kt is not ending with a new line.

import com.frogobox.appkeyboard.di.*
import com.frogobox.appkeyboard.repository.autotext.AutoTextRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.frogobox.appkeyboard.di.hilt
package com.frogobox.appkeyboard.di

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/keyboard/keyboard/app/src/main/java/com/frogobox/appkeyboard/di/ServiceModule.kt is not ending with a new line.

import dagger.Module
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.frogobox.appkeyboard.di.hilt
package com.frogobox.appkeyboard.di

Check warning

Code scanning / detekt

Checks whether files end with a line separator. Warning

The file /home/runner/work/keyboard/keyboard/app/src/main/java/com/frogobox/appkeyboard/di/UtilModule.kt is not ending with a new line.

import android.content.Context
import com.frogobox.appkeyboard.util.Constant.PREF_ROOT_NAME
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

65 changes: 44 additions & 21 deletions app/src/main/java/com/frogobox/appkeyboard/services/KeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.annotation.RequiresApi
import com.frogobox.appkeyboard.common.ext.getKeyboardType
import com.frogobox.appkeyboard.databinding.ItemKeyboardHeaderBinding
import com.frogobox.appkeyboard.databinding.KeyboardImeBinding
import com.frogobox.appkeyboard.model.KeyboardFeature
Expand All @@ -19,25 +18,51 @@ import com.frogobox.libkeyboard.common.core.BaseKeyboardIME
import com.frogobox.recycler.core.FrogoRecyclerNotifyListener
import com.frogobox.recycler.core.IFrogoBindingAdapter
import com.frogobox.recycler.ext.injectorBinding
import com.frogobox.sdk.delegate.preference.PreferenceDelegates
import com.frogobox.sdk.ext.getColorExt
import com.frogobox.sdk.ext.gone
import com.frogobox.sdk.ext.invisible
import com.frogobox.sdk.ext.visible
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject


@AndroidEntryPoint
class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {

@Inject
lateinit var pref: PreferenceDelegates

@Inject
lateinit var keyboardUtil: KeyboardUtil

override fun setupViewBinding(): KeyboardImeBinding {
return KeyboardImeBinding.inflate(LayoutInflater.from(this), null, false)
}

override fun setupTheme() {
binding?.apply {
holderKeyboard.setBackgroundColor(
pref.loadPrefInt(
KeyboardUtil.PREF_KEYBOARD_BACKGROUND_COLOR,
getColorExt(com.frogobox.libkeyboard.R.color.keyboard_board)
)
)
ivBackgroundKeyboard.setImageResource(android.R.color.transparent)
}
}

override fun initialSetupKeyboard() {
binding?.keyboardMain?.setKeyboard(keyboard!!)
}

override fun setupBinding() {
initialSetupKeyboard()
binding?.keyboardMain?.mOnKeyboardActionListener = this
binding?.keyboardEmoji?.mOnKeyboardActionListener = this
super.setupBinding()
binding?.apply {
keyboardMain.mOnKeyboardActionListener = this@KeyboardIME
keyboardEmoji.mOnKeyboardActionListener = this@KeyboardIME
}

}

override fun invalidateKeyboard() {
Expand Down Expand Up @@ -67,7 +92,7 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {
override fun showMainKeyboard() {
binding?.apply {
keyboardMain.visible()
if (KeyboardUtil().menuKeyboard().isEmpty()) {
if (keyboardUtil.menuKeyboard().isEmpty()) {
keyboardHeader.gone()
} else {
keyboardHeader.visible()
Expand Down Expand Up @@ -144,29 +169,26 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {

override fun setupFeatureKeyboard() {
val maxMenu = 4
val gridSize = if (KeyboardUtil().menuKeyboard().size <= maxMenu) {
KeyboardUtil().menuKeyboard().size
} else if (KeyboardUtil().menuKeyboard().size.mod(maxMenu) == 0) {
val gridSize = if (keyboardUtil.menuKeyboard().size <= maxMenu) {
keyboardUtil.menuKeyboard().size
} else if (keyboardUtil.menuKeyboard().size.mod(maxMenu) == 0) {
maxMenu
} else {
maxMenu + 1
}

binding?.apply {
if (KeyboardUtil().menuKeyboard().isEmpty()) {
if (keyboardUtil.menuKeyboard().isEmpty()) {
keyboardHeader.gone()
} else {
keyboardHeader.visible()
keyboardHeader.injectorBinding<KeyboardFeature, ItemKeyboardHeaderBinding>()
.addData(KeyboardUtil().menuKeyboard())
.addCallback(object :
.addData(keyboardUtil.menuKeyboard()).addCallback(object :
IFrogoBindingAdapter<KeyboardFeature, ItemKeyboardHeaderBinding> {

override fun setViewBinding(parent: ViewGroup): ItemKeyboardHeaderBinding {
return ItemKeyboardHeaderBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
LayoutInflater.from(parent.context), parent, false
)
}

Expand Down Expand Up @@ -262,9 +284,10 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {
}

KeyboardFeatureType.SETTING -> {
binding.root.context.startActivity(
Intent(binding.root.context, MainActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
binding.root.context.startActivity(Intent(
binding.root.context, MainActivity::class.java
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
})
}

Expand All @@ -281,9 +304,7 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {
}


})
.createLayoutGrid(gridSize)
.build()
}).createLayoutGrid(gridSize).build()
}
}
}
Expand Down Expand Up @@ -338,7 +359,9 @@ class KeyboardIME : BaseKeyboardIME<KeyboardImeBinding>() {
}

override fun getKeyboardLayoutXML(): Int {
return baseContext.getKeyboardType()
return pref.loadPrefInt(
KeyboardUtil.PREF_KEYBOARD_TYPE, com.frogobox.libkeyboard.R.xml.keys_letters_qwerty
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ package com.frogobox.appkeyboard.services
import com.frogobox.appkeyboard.R
import com.frogobox.appkeyboard.model.KeyboardFeature
import com.frogobox.appkeyboard.model.KeyboardFeatureType
import com.frogobox.sdk.delegate.preference.PreferenceDelegatesImpl
import org.koin.java.KoinJavaComponent.inject
import com.frogobox.sdk.delegate.preference.PreferenceDelegates
import javax.inject.Inject
import javax.inject.Singleton

/**
* Created by Faisal Amir on 11/03/23
* https://github.com/amirisback
*/

class KeyboardUtil {
@Singleton
class KeyboardUtil @Inject constructor(
private val pref: PreferenceDelegates
) {

private val pref: PreferenceDelegatesImpl by inject(PreferenceDelegatesImpl::class.java)
companion object {
const val PREF_KEYBOARD_TYPE = "PREF_KEYBOARD_TYPE"
const val PREF_KEYBOARD_BACKGROUND_COLOR = "PREF_KEYBOARD_BACKGROUND_COLOR"
}

fun menuToggle(): List<KeyboardFeature> {
return listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.frogobox.appkeyboard.common.base.BaseViewModel
import com.frogobox.appkeyboard.services.KeyboardUtil
import com.frogobox.appkeyboard.util.Constant
import com.frogobox.coresdk.response.FrogoStateResponse
import com.frogobox.sdk.delegate.preference.PreferenceDelegates
Expand Down Expand Up @@ -124,7 +125,7 @@ class KeyboardLanguageViewModel @Inject constructor(
}

fun setKeyboard(xml: Int, onSuccess: () -> Unit) {
pref.savePrefInt(Constant.PREF_KEYBOARD_TYPE, xml, object : FrogoStateResponse {
pref.savePrefInt(KeyboardUtil.PREF_KEYBOARD_TYPE, xml, object : FrogoStateResponse {
override fun onFailed(statusCode: Int, errorMessage: String) {}
override fun onFinish() {}
override fun onHideProgress() {
Expand All @@ -143,7 +144,7 @@ class KeyboardLanguageViewModel @Inject constructor(

fun checkKeyboardType(xml: Int): Boolean {
return pref.loadPrefInt(
Constant.PREF_KEYBOARD_TYPE,
KeyboardUtil.PREF_KEYBOARD_TYPE,
com.frogobox.libkeyboard.R.xml.keys_letters_qwerty
) == xml
}
Expand Down
Loading
Loading