Skip to content

Commit fa6e906

Browse files
authored
Merge branch 'main' into fix/plural-word-not-recognised
2 parents 6fd5674 + 684beda commit fa6e906

File tree

5 files changed

+85
-32
lines changed

5 files changed

+85
-32
lines changed

app/src/main/assets/data-contracts/sv.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,29 @@
1212
},
1313
"conjugations": {
1414
"1": {
15-
"title": "Aktiv (Active Voice)",
15+
"title": "Aktiv",
1616
"conjugationTypes": {
1717
"1": {
18-
"title": "Active Forms",
18+
"title": "Aktiv",
1919
"conjugationForms": {
2020
"infinitiv": "activeInfinitive",
21-
"imperativ": "imperative",
2221
"presens": "activePresent",
23-
"preteritum (dåtid)": "activePreterite",
24-
"supinum (liggande)": "activeSupine"
22+
"preteritum": "activePreterite",
23+
"supinum": "activeSupine"
2524
}
2625
}
2726
}
2827
},
2928
"2": {
30-
"title": "Passiv (Passive Voice)",
29+
"title": "Passiv",
3130
"conjugationTypes": {
3231
"1": {
33-
"title": "Passive Forms",
32+
"title": "Passiv",
3433
"conjugationForms": {
3534
"infinitiv": "passiveInfinitive",
3635
"presens": "passivePresent",
37-
"preteritum (dåtid)": "passivePreterite",
38-
"supinum (liggande)": "passiveSupine"
36+
"preteritum": "passivePreterite",
37+
"supinum": "passiveSupine"
3938
}
4039
}
4140
}

app/src/main/java/be/scri/helpers/KeyHandler.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,9 @@ class KeyHandler(
320320
val sharedPreferences = context.getSharedPreferences("keyboard_preferences", Context.MODE_PRIVATE)
321321
val editor = sharedPreferences.edit()
322322
var currentValue = sharedPreferences.getInt("conjugate_index", 0)
323-
324-
if (code == KeyboardBase.DISPLAY_LEFT) {
323+
if (code == KeyboardBase.DISPLAY_RIGHT) {
325324
currentValue--
326-
} else if (code == KeyboardBase.DISPLAY_RIGHT) {
325+
} else if (code == KeyboardBase.DISPLAY_LEFT) {
327326
currentValue++
328327
}
329328

app/src/main/java/be/scri/helpers/data/ConjugateDataManager.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ConjugateDataManager(
8383
if (form.isNullOrEmpty()) return ""
8484
return fileManager.getLanguageDatabase(language)?.use { db ->
8585
getVerbCursor(db, word, language)?.use { cursor ->
86-
getConjugatedValueFromCursor(cursor, form)
86+
getConjugatedValueFromCursor(cursor, form, language)
8787
}
8888
} ?: ""
8989
}
@@ -99,9 +99,10 @@ class ConjugateDataManager(
9999
private fun getConjugatedValueFromCursor(
100100
cursor: Cursor,
101101
form: String,
102+
language: String,
102103
): String =
103104
if (form.contains("[")) {
104-
parseComplexForm(cursor, form)
105+
parseComplexForm(cursor, form, language)
105106
} else {
106107
try {
107108
cursor.getString(cursor.getColumnIndexOrThrow(form))
@@ -123,17 +124,39 @@ class ConjugateDataManager(
123124
private fun parseComplexForm(
124125
cursor: Cursor,
125126
form: String,
127+
language: String,
126128
): String {
127129
val bracketRegex = Regex("""\[(.*?)]""")
128130
val match = bracketRegex.find(form) ?: return ""
129131

130132
val auxiliaryWords = match.groupValues[1]
131133
val dbColumnName = form.replace(bracketRegex, "").trim()
134+
132135
return try {
133136
val verbPart = cursor.getString(cursor.getColumnIndexOrThrow(dbColumnName))
134-
"$auxiliaryWords $verbPart".trim()
137+
val words = auxiliaryWords.split(Regex("\\s+"))
138+
val verbType = cursor.getString(cursor.getColumnIndexOrThrow(words.last()))
139+
val db = fileManager.getLanguageDatabase(language = language)
140+
141+
val wordPart1 = words.firstOrNull()
142+
var auxResult = ""
143+
wordPart1?.let {
144+
val auxCursor =
145+
db?.rawQuery(
146+
"SELECT $wordPart1 FROM verbs WHERE wdLexemeId = ?",
147+
arrayOf(verbType),
148+
)
149+
if (auxCursor?.moveToFirst() == true) {
150+
auxResult = auxCursor.getString(0)
151+
}
152+
auxCursor?.close()
153+
}
154+
155+
val result = "$auxResult $verbPart".trim()
156+
Log.d("DEBUG", "Returning: $result")
157+
result
135158
} catch (e: IllegalArgumentException) {
136-
Log.e("ConjugateDataManager", "Complex form column '$dbColumnName' not found", e)
159+
Log.e("ConjugateDataManager", "Column '$dbColumnName' not found", e)
137160
""
138161
}
139162
}

app/src/main/java/be/scri/services/GeneralKeyboardIME.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.text.InputType.TYPE_CLASS_NUMBER
1616
import android.text.InputType.TYPE_CLASS_PHONE
1717
import android.text.InputType.TYPE_MASK_CLASS
1818
import android.text.TextUtils
19+
import android.util.Log
1920
import android.view.KeyEvent
2021
import android.view.View
2122
import android.view.inputmethod.EditorInfo
@@ -389,8 +390,8 @@ abstract class GeneralKeyboardIME(
389390
?.toSet()
390391
nounKeywords = dbManagers.genderManager.findGenderOfWord(languageAlias, dataContract)
391392
caseAnnotation = dbManagers.prepositionManager.getCaseAnnotations(languageAlias)
392-
conjugateOutput = dbManagers.conjugateDataManager.getTheConjugateLabels(languageAlias, dataContract, "describe")
393-
conjugateLabels = dbManagers.conjugateDataManager.extractConjugateHeadings(dataContract, "describe")
393+
conjugateOutput = dbManagers.conjugateDataManager.getTheConjugateLabels(languageAlias, dataContract, "coacha")
394+
conjugateLabels = dbManagers.conjugateDataManager.extractConjugateHeadings(dataContract, "coacha")
394395
keyboard = KeyboardBase(this, keyboardXml, enterKeyType)
395396
keyboardView?.setKeyboard(keyboard!!)
396397

@@ -874,6 +875,7 @@ abstract class GeneralKeyboardIME(
874875
return
875876
}
876877

878+
Log.i("HELLO", "The output from the languageOutput is $languageOutput")
877879
if (language != "English") {
878880
setUpNonEnglishConjugateKeys(languageOutput, conjugateLabels.toList(), title)
879881
} else {
@@ -897,17 +899,30 @@ abstract class GeneralKeyboardIME(
897899
title: String,
898900
) {
899901
val keyCodes =
900-
listOf(
901-
KeyboardBase.CODE_FPS,
902-
KeyboardBase.CODE_FPP,
903-
KeyboardBase.CODE_SPS,
904-
KeyboardBase.CODE_SPP,
905-
KeyboardBase.CODE_TPS,
906-
KeyboardBase.CODE_TPP,
907-
)
902+
when (language) {
903+
"Swedish" -> {
904+
listOf(
905+
KeyboardBase.CODE_TR,
906+
KeyboardBase.CODE_TL,
907+
KeyboardBase.CODE_BR,
908+
KeyboardBase.CODE_BL,
909+
)
910+
}
911+
912+
else -> {
913+
listOf(
914+
KeyboardBase.CODE_FPS,
915+
KeyboardBase.CODE_FPP,
916+
KeyboardBase.CODE_SPS,
917+
KeyboardBase.CODE_SPP,
918+
KeyboardBase.CODE_TPS,
919+
KeyboardBase.CODE_TPP,
920+
)
921+
}
922+
}
908923

909924
keyCodes.forEachIndexed { index, code ->
910-
val value = languageOutput[title]?.elementAtOrNull(index) ?: return@forEachIndexed
925+
val value = languageOutput[title]?.elementAtOrNull(index) ?: ""
911926
keyboardView?.setKeyLabel(value, conjugateLabel.getOrNull(index) ?: "", code)
912927
}
913928
}
@@ -1740,13 +1755,13 @@ abstract class GeneralKeyboardIME(
17401755
dbManagers.conjugateDataManager.getTheConjugateLabels(
17411756
languageAlias,
17421757
dataContract,
1743-
rawInput,
1758+
rawInput.lowercase(),
17441759
)
17451760

17461761
conjugateLabels =
17471762
dbManagers.conjugateDataManager.extractConjugateHeadings(
17481763
dataContract,
1749-
rawInput,
1764+
rawInput.lowercase(),
17501765
)
17511766

17521767
currentState =

app/src/main/java/be/scri/views/KeyboardView.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ class KeyboardView
314314
private const val DISPLAY_RIGHT = 2001
315315
private const val EXTRA_PADDING = 5000
316316
private const val KEY_HEIGHT = 100
317-
private const val I_1 = 0
318-
private const val LEFT_RIGHT_CONJUGATE_KEY_EXTRA_HEIGHT = 370
317+
private var leftShiftForLabel = 0
318+
private const val LEFT_RIGHT_CONJUGATE_KEY_EXTRA_HEIGHT = 340
319319
}
320320

321321
private var popupBindingInternal: KeyboardPopupKeyboardBinding? = null
@@ -873,6 +873,7 @@ class KeyboardView
873873
val keyCount = keys.size
874874
for (i in 0 until keyCount) {
875875
val key = keys[i]
876+
leftShiftForLabel = 0
876877

877878
// If a key has no width, it's effectively invisible. Don't draw it or its shadow.
878879
if (key.width == 0) {
@@ -947,70 +948,86 @@ class KeyboardView
947948
when (code) {
948949
KeyboardBase.CODE_FPS -> {
949950
label = mKeyLabelFPS
951+
leftShiftForLabel = 30
950952
key.topSmallNumber = topSmallLabelFPS
951953
}
952954

953955
KeyboardBase.CODE_FPP -> {
954956
label = mKeyLabelFPP
957+
leftShiftForLabel = 30
955958
key.topSmallNumber = topSmallLabelFPP
956959
}
957960

958961
KeyboardBase.CODE_SPS -> {
959962
label = mKeyLabelSPS
963+
leftShiftForLabel = 30
960964
key.topSmallNumber = topSmallLabelSPS
961965
}
962966

963967
KeyboardBase.CODE_SPP -> {
964968
label = mKeyLabelSPP
969+
leftShiftForLabel = 30
965970
key.topSmallNumber = topSmallLabelSPP
966971
}
967972

968973
KeyboardBase.CODE_TPS -> {
969974
label = mKeyLabelTPS
975+
leftShiftForLabel = 30
970976
key.topSmallNumber = topSmallLabelTPS
971977
}
972978

973979
KeyboardBase.CODE_TPP -> {
974980
label = mKeyLabelTPP
981+
leftShiftForLabel = 30
975982
key.topSmallNumber = topSmallLabelTPP
976983
}
977984

978985
KeyboardBase.CODE_TL -> {
979986
label = mKeyLabelTL
987+
leftShiftForLabel = 30
980988
key.topSmallNumber = topSmallLabelTL
981989
}
982990

983991
KeyboardBase.CODE_TR -> {
984992
label = mKeyLabelTR
993+
leftShiftForLabel = 30
985994
key.topSmallNumber = topSmallLabelTR
986995
}
987996

988997
KeyboardBase.CODE_BL -> {
989998
label = mKeyLabelBL
999+
leftShiftForLabel = 30
9901000
key.topSmallNumber = topSmallLabelBL
9911001
}
9921002

9931003
KeyboardBase.CODE_BR -> {
9941004
label = mKeyLabelBR
1005+
leftShiftForLabel = 30
9951006
key.topSmallNumber = topSmallLabelBR
9961007
}
9971008
KeyboardBase.CODE_2X1_TOP -> {
9981009
label = mKeyLabel2X1TOP
1010+
leftShiftForLabel = 30
9991011
}
10001012
KeyboardBase.CODE_2X1_BOTTOM -> {
10011013
label = mKeyLabel2X1BOTTOM
1014+
leftShiftForLabel = 30
10021015
}
10031016
KeyboardBase.CODE_1X3_CENTER -> {
10041017
label = mKeyLabel1X3LEFT
1018+
leftShiftForLabel = 30
10051019
}
10061020
KeyboardBase.CODE_1X3_LEFT -> {
10071021
label = mKeyLabel1X3TOP
1022+
leftShiftForLabel = 30
10081023
}
10091024
KeyboardBase.CODE_1X3_RIGHT -> {
10101025
label = mKeyLabel1X3BOTTOM
1026+
leftShiftForLabel = 30
10111027
}
10121028
KeyboardBase.CODE_CURRENCY -> {
10131029
label = mCurrencySymbol
1030+
leftShiftForLabel = 30
10141031
}
10151032
}
10161033

@@ -1044,7 +1061,7 @@ class KeyboardView
10441061
if (key.topSmallNumber.isNotEmpty()) {
10451062
canvas.drawText(
10461063
key.topSmallNumber,
1047-
key.width - mTopSmallNumberMarginWidth - I_1,
1064+
key.width - mTopSmallNumberMarginWidth - leftShiftForLabel,
10481065
mTopSmallNumberMarginHeight,
10491066
smallLetterPaint,
10501067
)

0 commit comments

Comments
 (0)