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

DEVELOP :: MULTI LANGUAGE SUPPORT #37

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
76 changes: 76 additions & 0 deletions app/schemas/com.frogobox.keyboard.data.local.db.AppDatabase/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "f76c2f5058229a55fe3cb182b8e11113",
"entities": [
{
"tableName": "auto_text",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `label` TEXT NOT NULL, `date` TEXT NOT NULL, `updatedDate` TEXT NOT NULL, `updatedTime` TEXT NOT NULL, `body` TEXT NOT NULL, `isActive` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "label",
"columnName": "label",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedDate",
"columnName": "updatedDate",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "updatedTime",
"columnName": "updatedTime",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "body",
"columnName": "body",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isActive",
"columnName": "isActive",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f76c2f5058229a55fe3cb182b8e11113')"
]
}
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
android:name=".ui.toggle.ToggleActivity"
android:exported="false" />

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

<activity
android:name=".ui.main.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.frogobox.keyboard.R
import com.frogobox.keyboard.util.Constant.PREF_KEYBOARD_TYPE
import com.frogobox.keyboard.util.Constant.PREF_ROOT_NAME
import com.frogobox.sdk.delegate.preference.PreferenceDelegatesImpl

/**
* Created by Faisal Amir on 24/10/22
Expand Down Expand Up @@ -45,4 +48,9 @@ fun Context.getStrokeColor() = ContextCompat.getColor(this, R.color.keyboard_bg_

fun Drawable.applyColorFilter(color: Int) = mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN)

fun ImageView.applyColorFilter(color: Int) = setColorFilter(color, PorterDuff.Mode.SRC_IN)
fun ImageView.applyColorFilter(color: Int) = setColorFilter(color, PorterDuff.Mode.SRC_IN)

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
Expand Up @@ -23,6 +23,7 @@ import android.widget.EditText
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import com.frogobox.keyboard.R
import com.frogobox.keyboard.common.ext.getKeyboardType
import com.frogobox.keyboard.common.ext.getProperBackgroundColor
import com.frogobox.keyboard.common.ext.getProperTextColor
import com.frogobox.keyboard.databinding.ItemKeyboardHeaderBinding
Expand Down Expand Up @@ -622,7 +623,7 @@ class KeyboardIME : InputMethodService(), OnKeyboardActionListener {
}

private fun getKeyboardLayoutXML(): Int {
return R.xml.keys_letters_qwerty
return baseContext.getKeyboardType()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.frogobox.keyboard.ui.language

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/keyboard/ui/language/KeyboardLanguage.kt is not ending with a new line.

/**
* Created by Faisal Amir on 24/10/22
* -----------------------------------------
* E-mail : faisalamircs@gmail.com
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) Frogobox ID / amirisback
* All rights reserved
*/


data class KeyboardLanguage(
val name: String,
val xml: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.frogobox.keyboard.ui.language

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/keyboard/ui/language/KeyboardLanguageActivity.kt is not ending with a new line.
Fixed Show fixed Hide fixed

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.activity.viewModels
import com.frogobox.keyboard.common.base.BaseActivity
import com.frogobox.keyboard.databinding.ActivityKeyboardLanguageBinding
import com.frogobox.keyboard.databinding.ItemLanguageKeyboardBinding
import com.frogobox.recycler.core.FrogoRecyclerNotifyListener
import com.frogobox.recycler.core.IFrogoBindingAdapter
import com.frogobox.recycler.ext.injectorBinding
import com.frogobox.sdk.ext.showToast
import dagger.hilt.android.AndroidEntryPoint

/**
* Created by Faisal Amir on 24/10/22
* -----------------------------------------
* E-mail : faisalamircs@gmail.com
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) Frogobox ID / amirisback
* All rights reserved
*/

@AndroidEntryPoint
class KeyboardLanguageActivity : BaseActivity<ActivityKeyboardLanguageBinding>(),
IFrogoBindingAdapter<KeyboardLanguage, ItemLanguageKeyboardBinding> {

private val viewModel: KeyboardLanguageViewModel by viewModels()

override fun setupViewBinding(): ActivityKeyboardLanguageBinding {
return ActivityKeyboardLanguageBinding.inflate(layoutInflater)
}

override fun setupViewModel() {
super.setupViewModel()
viewModel.apply {
keyboardLanguage.observe(this@KeyboardLanguageActivity) {
setupRV(it)
}
}
}

override fun onCreateExt(savedInstanceState: Bundle?) {
super.onCreateExt(savedInstanceState)
if (savedInstanceState == null) {
viewModel.getKeyboardLanguage(this)
}
}

override fun initView() {
super.initView()
setupDetailActivity("Keyboard Language")
binding.apply {

}
}

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

override fun onItemClicked(
binding: ItemLanguageKeyboardBinding,
data: KeyboardLanguage,
position: Int,
notifyListener: FrogoRecyclerNotifyListener<KeyboardLanguage>
) {
viewModel.setKeyboard(data.xml) {
showToast("${data.name} Selected")
}
}

override fun onItemLongClicked(
binding: ItemLanguageKeyboardBinding,
data: KeyboardLanguage,
position: Int,
notifyListener: FrogoRecyclerNotifyListener<KeyboardLanguage>
) {}

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 setupInitComponent(
binding: ItemLanguageKeyboardBinding,
data: KeyboardLanguage,
position: Int,
notifyListener: FrogoRecyclerNotifyListener<KeyboardLanguage>
) {
binding.apply {
tvItemKeyboardMain.text = data.name
}
}

private fun setupRV(data: List<KeyboardLanguage>) {
binding.rvKeyboardLanguage
.injectorBinding<KeyboardLanguage, ItemLanguageKeyboardBinding>()
.addData(data)
.addCallback(this)
.createLayoutLinearVertical(false)
.build()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.frogobox.keyboard.ui.language

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/keyboard/ui/language/KeyboardLanguageViewModel.kt is not ending with a new line.
Fixed Show fixed Hide fixed

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.frogobox.coresdk.response.FrogoStateResponse
import com.frogobox.keyboard.R
import com.frogobox.keyboard.common.base.BaseViewModel
import com.frogobox.keyboard.util.Constant
import com.frogobox.sdk.delegate.preference.PreferenceDelegates
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
* Created by Faisal Amir on 24/10/22
* -----------------------------------------
* E-mail : faisalamircs@gmail.com
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) Frogobox ID / amirisback
* All rights reserved
*/


@HiltViewModel
class KeyboardLanguageViewModel @Inject constructor(
private val pref : PreferenceDelegates
) : BaseViewModel() {

private var _keyboardLanguage = MutableLiveData<List<KeyboardLanguage>>()
var keyboardLanguage: LiveData<List<KeyboardLanguage>> = _keyboardLanguage

private var _showloading = MutableLiveData<Boolean>()
var showloading: LiveData<Boolean> = _showloading

fun getKeyboardLanguage(context: Context) {
val list = mutableListOf<KeyboardLanguage>()
list.add(KeyboardLanguage("${context.getString(R.string.translation_english)} (QWERTY)", R.xml.keys_letters_qwerty))

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
list.add(KeyboardLanguage("${context.getString(R.string.translation_english)} (QWERTZ)", R.xml.keys_letters_english_qwertz))

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
list.add(KeyboardLanguage("${context.getString(R.string.translation_english)} (DVORAK)", R.xml.keys_letters_english_dvorak))

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.

list.add(KeyboardLanguage(context.getString(R.string.translation_bengali), R.xml.keys_letters_bengali))
list.add(KeyboardLanguage(context.getString(R.string.translation_bulgarian), R.xml.keys_letters_bulgarian))

list.add(KeyboardLanguage(context.getString(R.string.translation_french), R.xml.keys_letters_french))
list.add(KeyboardLanguage(context.getString(R.string.translation_german), R.xml.keys_letters_german))
list.add(KeyboardLanguage(context.getString(R.string.translation_greek), R.xml.keys_letters_greek))
list.add(KeyboardLanguage(context.getString(R.string.translation_lithuanian), R.xml.keys_letters_lithuanian))
list.add(KeyboardLanguage(context.getString(R.string.translation_romanian), R.xml.keys_letters_romanian))
list.add(KeyboardLanguage(context.getString(R.string.translation_slovenian), R.xml.keys_letters_slovenian))
list.add(KeyboardLanguage(context.getString(R.string.translation_spanish), R.xml.keys_letters_spanish_qwerty))
list.add(KeyboardLanguage("${context.getString(R.string.translation_turkish)} (Q)", R.xml.keys_letters_turkish_q))

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style. Warning

Line detected that is longer than the defined maximum line length in the code style.
_keyboardLanguage.postValue(list)
}

fun setKeyboard(xml: Int, onSuccess: () -> Unit) {
pref.savePrefInt(Constant.PREF_KEYBOARD_TYPE, xml, 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() {
_showloading.postValue(false)
}
override fun onShowProgress() {
_showloading.postValue(true)
}
override fun onSuccess() {
onSuccess()
}
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.frogobox.keyboard.common.ext.isDarkThemeOn
import com.frogobox.keyboard.databinding.ActivityMainBinding
import com.frogobox.keyboard.ui.autotext.AutoTextActivity
import com.frogobox.keyboard.ui.detail.DetailActivity
import com.frogobox.keyboard.ui.language.KeyboardLanguageActivity
import com.frogobox.keyboard.ui.toggle.ToggleActivity
import com.frogobox.sdk.ext.showLogDebug
import com.frogobox.sdk.ext.startActivityExt
Expand Down Expand Up @@ -98,6 +99,10 @@ class MainActivity : BaseMainActivity<ActivityMainBinding>() {
startActivityExt<ToggleActivity>()
}

btnMultiLanguage.setOnClickListener {
startActivityExt<KeyboardLanguageActivity>()
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/frogobox/keyboard/util/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ object Constant {

const val PREF_ROOT_NAME = "PREF_ROOT_NAME"

const val PREF_KEYBOARD_TYPE = "PREF_KEYBOARD_TYPE"

object Extra {
const val EXTRA_DATA = "EXTRA_DATA"
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_keyboard_language.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rv_keyboard_language"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/frogo_dimen_16dp"
tools:itemCount="20"
tools:listitem="@layout/item_language_keyboard">

</androidx.recyclerview.widget.RecyclerView>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
android:layout_height="wrap_content"
android:text="Toggle Function" />

<Button
android:id="@+id/btn_multi_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Setup Keyboard Language" />

</LinearLayout>

<Button
Expand Down
Loading
Loading