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

Added Language-Specific Placeholders and Prompts for Scribe Keyboard #285

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 12 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ dependencies {
androidTestImplementation("androidx.test:runner:1.6.2")
androidTestImplementation("io.mockk:mockk-android:1.13.5")


// Other libraries
api("joda-time:joda-time:2.10.13")
api("com.github.tibbi:RecyclerView-FastScroller:e7d3e150c4")
Expand All @@ -250,17 +249,20 @@ tasks.register<Copy>("moveFromi18n") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
destinationDir = file("src/main/res")

val locales = file("src/main/assets/i18n/Scribe-i18n/values").listFiles()
?.filter { it.isDirectory }
?.map { it.name }
?: emptyList()
val locales =
file("src/main/assets/i18n/Scribe-i18n/values")
.listFiles()
?.filter { it.isDirectory }
?.map { it.name }
?: emptyList()
locales.forEach { locale ->
val fromDir = file("src/main/assets/i18n/Scribe-i18n/values/$locale/")
val targetDir = if (locale == "en-US") {
"values"
} else {
"values-$locale"
}
val targetDir =
if (locale == "en-US") {
"values"
} else {
"values-$locale"
}

if (fromDir.exists()) {
println("Copying from $fromDir to $targetDir")
Expand Down
114 changes: 114 additions & 0 deletions app/src/main/java/be/scri/helpers/HintUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
package be.scri.helpers

import android.content.Context
import be.scri.helpers.english.ENInterfaceVariables
import be.scri.helpers.french.FRInterfaceVariables
import be.scri.helpers.german.DEInterfaceVariables
import be.scri.helpers.italian.ITInterfaceVariables
import be.scri.helpers.portuguese.PTInterfaceVariables
import be.scri.helpers.russian.RUInterfaceVariables
import be.scri.helpers.spanish.ESInterfaceVariables
import be.scri.helpers.swedish.SVInterfaceVariables
import be.scri.services.SimpleKeyboardIME

object HintUtils {
fun resetHints(context: Context) {
Expand All @@ -31,4 +40,109 @@ object HintUtils {
apply()
}
}

fun getCommandBarHint(
currentState: SimpleKeyboardIME.ScribeState,
language: String,
): String {
val hintMessageForState = getHintForState(currentState)
return hintMessageForState[language] ?: "" // return the placeholder or empty string if not found
}

private fun getHintForState(currentState: SimpleKeyboardIME.ScribeState): Map<String, String> =
when (currentState) {
SimpleKeyboardIME.ScribeState.TRANSLATE -> getTranslateHints()
SimpleKeyboardIME.ScribeState.CONJUGATE -> getConjugateHints()
SimpleKeyboardIME.ScribeState.PLURAL -> getPluralHints()
else -> emptyMap()
}

private fun getTranslateHints(): Map<String, String> =
mapOf(
"English" to ENInterfaceVariables.TRANSLATE_PLACEHOLDER,
"French" to FRInterfaceVariables.TRANSLATE_PLACEHOLDER,
"German" to DEInterfaceVariables.TRANSLATE_PLACEHOLDER,
"Italian" to ITInterfaceVariables.TRANSLATE_PLACEHOLDER,
"Portuguese" to PTInterfaceVariables.TRANSLATE_PLACEHOLDER,
"Russian" to RUInterfaceVariables.TRANSLATE_PLACEHOLDER,
"Spanish" to ESInterfaceVariables.TRANSLATE_PLACEHOLDER,
"Swedish" to SVInterfaceVariables.TRANSLATE_PLACEHOLDER,
)

private fun getConjugateHints(): Map<String, String> =
mapOf(
"English" to ENInterfaceVariables.CONJUGATE_PLACEHOLDER,
"French" to FRInterfaceVariables.CONJUGATE_PLACEHOLDER,
"German" to DEInterfaceVariables.CONJUGATE_PLACEHOLDER,
"Italian" to ITInterfaceVariables.CONJUGATE_PLACEHOLDER,
"Portuguese" to PTInterfaceVariables.CONJUGATE_PLACEHOLDER,
"Russian" to RUInterfaceVariables.CONJUGATE_PLACEHOLDER,
"Spanish" to ESInterfaceVariables.CONJUGATE_PLACEHOLDER,
"Swedish" to SVInterfaceVariables.CONJUGATE_PLACEHOLDER,
)

private fun getPluralHints(): Map<String, String> =
mapOf(
"English" to ENInterfaceVariables.PLURAL_PLACEHOLDER,
"French" to FRInterfaceVariables.PLURAL_PLACEHOLDER,
"German" to DEInterfaceVariables.PLURAL_PLACEHOLDER,
"Italian" to ITInterfaceVariables.PLURAL_PLACEHOLDER,
"Portuguese" to PTInterfaceVariables.PLURAL_PLACEHOLDER,
"Russian" to RUInterfaceVariables.PLURAL_PLACEHOLDER,
"Spanish" to ESInterfaceVariables.PLURAL_PLACEHOLDER,
"Swedish" to SVInterfaceVariables.PLURAL_PLACEHOLDER,
)

fun getPromptText(
currentState: SimpleKeyboardIME.ScribeState,
language: String,
): String =
when (currentState) {
SimpleKeyboardIME.ScribeState.TRANSLATE -> getTranslationPrompt(language)
SimpleKeyboardIME.ScribeState.CONJUGATE -> getConjugationPrompt(language)
SimpleKeyboardIME.ScribeState.PLURAL -> getPluralPrompt(language)
else -> ""
}

private fun getTranslationPrompt(language: String): String {
val languageShorthand =
mapOf(
"English" to "en",
"French" to "fr",
"German" to "de",
"Italian" to "it",
"Portuguese" to "pt",
"Russian" to "ru",
"Spanish" to "es",
"Swedish" to "sv",
)
val shorthand = languageShorthand[language] ?: "en" // default fallback to "en"
return "en -> $shorthand"
}

private fun getConjugationPrompt(language: String): String =
when (language) {
"English" -> ENInterfaceVariables.CONJUGATE_PROMPT
"French" -> FRInterfaceVariables.CONJUGATE_PROMPT
"German" -> DEInterfaceVariables.CONJUGATE_PROMPT
"Italian" -> ITInterfaceVariables.CONJUGATE_PROMPT
"Portuguese" -> PTInterfaceVariables.CONJUGATE_PROMPT
"Russian" -> RUInterfaceVariables.CONJUGATE_PROMPT
"Spanish" -> ESInterfaceVariables.CONJUGATE_PROMPT
"Swedish" -> SVInterfaceVariables.CONJUGATE_PROMPT
else -> "Conjugate :"
}

private fun getPluralPrompt(language: String): String =
when (language) {
"English" -> ENInterfaceVariables.PLURAL_PROMPT
"French" -> FRInterfaceVariables.PLURAL_PROMPT
"German" -> DEInterfaceVariables.PLURAL_PROMPT
"Italian" -> ITInterfaceVariables.PLURAL_PROMPT
"Portuguese" -> PTInterfaceVariables.PLURAL_PROMPT
"Russian" -> RUInterfaceVariables.PLURAL_PROMPT
"Spanish" -> ESInterfaceVariables.PLURAL_PROMPT
"Swedish" -> SVInterfaceVariables.PLURAL_PROMPT
else -> "Plural :"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package be.scri.helpers.portugese
package be.scri.helpers.portuguese

object PTInterfaceVariables {
// MARK: Currency Symbols
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/be/scri/services/SimpleKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import be.scri.R
import be.scri.databinding.KeyboardViewCommandOptionsBinding
import be.scri.databinding.KeyboardViewKeyboardBinding
import be.scri.helpers.DatabaseHelper
import be.scri.helpers.HintUtils
import be.scri.helpers.MyKeyboard
import be.scri.helpers.SHIFT_OFF
import be.scri.helpers.SHIFT_ON_ONE_CHAR
Expand Down Expand Up @@ -113,7 +114,21 @@ abstract class SimpleKeyboardIME(
DISPLAY_INFORMATION,
}

private fun updateCommandBarHintandPrompt() {
val commandBarButton = keyboardBinding.commandBar
val hintMessage = HintUtils.getCommandBarHint(currentState, language)
val promptText = HintUtils.getPromptText(currentState, language)
val promptTextView = keyboardBinding.promptText
promptTextView?.setText(promptText)
commandBarButton.hint = hintMessage
Log.d(
"KeyboardUpdate",
"CommandBar Hint Updated: [State: $currentState, Language: $language, Hint: $hintMessage]",
)
}

private fun updateKeyboardMode(isCommandMode: Boolean = false) {
updateCommandBarHintandPrompt()
enterKeyType =
if (isCommandMode) {
MyKeyboard.MyCustomActions.IME_ACTION_COMMAND
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/cmd_bar_prompt_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/light_key_press_color">
<item android:id="@+id/button_background_holder">
<layer-list>
<item android:id="@+id/button_background_shape">
<shape android:shape="rectangle">
<solid android:color="#FFFFFFFF" />
</shape>
</item>
</layer-list>
</item>
</ripple>
53 changes: 47 additions & 6 deletions app/src/main/res/layout/keyboard_view_keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,74 @@
<Button
android:id="@+id/scribe_key"
android:layout_width="0dp"
android:layout_height="@dimen/toolbar_icon_height"
android:layout_height="36dp"
android:layout_marginStart="@dimen/small_margin"
android:background="@drawable/scribe_key_background_left_rounded"
android:contentDescription="@string/scribe_key"
android:foreground="@drawable/close"
android:foregroundGravity="center"
android:foregroundTint="@color/light_key_text_color"
app:layout_constraintBottom_toBottomOf="@+id/command_field"
app:layout_constraintEnd_toStartOf="@+id/command_bar"
app:layout_constraintEnd_toStartOf="@+id/prompt_text"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_weight="20"
app:layout_constraintStart_toStartOf="@+id/command_field"
app:layout_constraintTop_toTopOf="@+id/command_field" />

<TextView
android:id="@+id/prompt_text"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:background="@drawable/cmd_bar_prompt_background"
android:textFontWeight="500"
android:textColor="@android:color/black"
android:textSize="16sp"
android:gravity="center"
android:minWidth="48dp"
android:maxWidth="120dp"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
android:singleLine="true"
android:ellipsize="end"
app:layout_constraintBottom_toBottomOf="@+id/command_field"
app:layout_constraintEnd_toStartOf="@+id/command_bar"
app:layout_constraintStart_toEndOf="@+id/scribe_key"
app:layout_constraintTop_toTopOf="@+id/command_field" />

<View
android:id="@+id/prompt_text_border"
android:layout_width="1.5dp"
android:layout_height="0dp"
android:background="@android:color/black"
app:layout_constraintTop_toTopOf="@+id/prompt_text"
app:layout_constraintBottom_toBottomOf="@+id/prompt_text"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintEnd_toEndOf="@+id/prompt_text"
app:layout_constraintHorizontal_bias="1.0" />


<Button
android:id="@+id/command_bar"
android:layout_width="0dp"
android:layout_height="@dimen/toolbar_icon_height"
android:layout_height="36dp"
android:textFontWeight="500"
android:layout_marginEnd="@dimen/tiny_margin"
android:background="@drawable/cmd_bar_background_right_rounded"
android:contentDescription="@string/command_bar"
android:elevation="0dp"
android:stateListAnimator="@null"
android:textSize="16sp"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
android:textAlignment="textStart"
app:layout_constraintBottom_toBottomOf="@+id/command_field"
app:layout_constraintEnd_toEndOf="@+id/command_field"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_weight="84"
app:layout_constraintStart_toEndOf="@+id/scribe_key"
app:layout_constraintHorizontal_weight="50"
app:layout_constraintStart_toEndOf="@+id/prompt_text"
app:layout_constraintTop_toTopOf="@+id/command_field" />

<ImageView
Expand Down
Loading