Skip to content
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
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
implementation("com.charleskorn.kaml:kaml:0.57.0")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7")

}

tasks.register<Copy>("moveFromi18n") {
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import be.scri.helpers.AppFlavor
import be.scri.helpers.FlavorProvider
import be.scri.helpers.PreferencesHelper
import be.scri.navigation.Screen
import be.scri.ui.common.appcomponents.HintDialog
Expand Down Expand Up @@ -216,6 +218,18 @@ fun ScribeApp(
)
},
)
HintDialog(
pagerState = pagerState,
currentPageIndex = page,
sharedPrefsKey = "hint_shown_conjugate",
hintMessageResId = R.string.i18n_app_conjugate_app_hint_tooltip,
isHintChanged = isHintChanged[page] == true,
onDismiss = { onDismiss(it) },
modifier =
Modifier
.fillMaxWidth()
.padding(8.dp),
)
}
HandleBackPress(pagerState, coroutineScope)
}
Expand All @@ -241,7 +255,12 @@ fun ScribeApp(
pagerState = pagerState,
currentPageIndex = page,
sharedPrefsKey = "hint_shown_settings",
hintMessageResId = R.string.i18n_app_settings_app_hint_tooltip,
hintMessageResId =
if (FlavorProvider.get() == AppFlavor.CONJUGATE) {
R.string.i18n_app_settings_conjugate_app_hint_tooltip
} else {
R.string.i18n_app_settings_keyboard_app_hint_tooltip
},
isHintChanged = isHintChanged[page] == true,
onDismiss = { onDismiss(it) },
modifier = Modifier.padding(8.dp),
Expand Down
46 changes: 29 additions & 17 deletions app/src/main/java/be/scri/helpers/data/ConjugateDataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ConjugateDataManager(
*
* @return The conjugated word as a [String], or an empty string if not found.
*/
private fun getTheValueForTheConjugateWord(
fun getTheValueForTheConjugateWord(
word: String,
form: String?,
language: String,
Expand All @@ -96,17 +96,35 @@ class ConjugateDataManager(
return ""
}

val columnName = if (language == "SV") "verb" else "infinitive"
if (!db.columnExists("verbs", columnName)) {
return ""
}
val columnName = db.getInfinitiveColumnName() ?: return ""

getVerbCursor(db, word, language)?.use { cursor ->
getVerbCursor(db, word, columnName)?.use { cursor ->
getConjugatedValueFromCursor(cursor, form, language)
}
} ?: ""
}

private fun getColumnIndexWithFallback(
cursor: Cursor,
columnName: String,
): Int {
var idx = cursor.getColumnIndex(columnName)
if (idx != -1) return idx

val fallbacks =
listOf(
"combined" + columnName.replaceFirstChar { it.uppercase() },
columnName.replace("presentParticiple", "combinedPresentParticiple"),
columnName.replace("pastParticiple", "combinedPastParticiple"),
)
for (fallback in fallbacks) {
idx = cursor.getColumnIndex(fallback)
if (idx != -1) return idx
}

throw IllegalArgumentException("column '$columnName' does not exist. Available columns: " + cursor.columnNames.joinToString(", "))
}

/**
* Extracts a conjugated value from a database cursor for a given form.
* It handles both simple column lookups and complex forms that require parsing.
Expand All @@ -125,7 +143,7 @@ class ConjugateDataManager(
parseComplexForm(cursor, form, language)
} else {
try {
cursor.getString(cursor.getColumnIndexOrThrow(form))
cursor.getString(getColumnIndexWithFallback(cursor, form))
} catch (e: IllegalArgumentException) {
Log.e("ConjugateDataManager", "Simple form column not found: '$form'", e)
""
Expand Down Expand Up @@ -154,7 +172,7 @@ class ConjugateDataManager(
val dbColumnName = form.replace(bracketRegex, "").trim()

return try {
val verbPart = cursor.getString(cursor.getColumnIndexOrThrow(dbColumnName))
val verbPart = cursor.getString(getColumnIndexWithFallback(cursor, dbColumnName))

// Try to handle it as a dynamic lookup (German style: [form auxiliary_column]).
try {
Expand Down Expand Up @@ -219,26 +237,20 @@ class ConjugateDataManager(

/**
* Creates and returns a database cursor pointing to the requested verb's data row.
* Note: Handles a special case for Swedish ("SV") where the key column is 'verb' instead of 'infinitive'.
*
* @param db The SQLite database instance to query.
* @param word The verb to search for.
* @param language The language code, used for special query conditions.
* @param columnName The name of the infinitive/verb column.
*
* @return A [Cursor] positioned at the verb's row, or null if the verb is not found.
* The caller is responsible for closing the cursor.
*/
private fun getVerbCursor(
db: SQLiteDatabase,
word: String,
language: String,
columnName: String,
): Cursor? {
val query =
if (language == "SV") {
"SELECT * FROM verbs WHERE verb = ?"
} else {
"SELECT * FROM verbs WHERE infinitive = ?"
}
val query = "SELECT * FROM verbs WHERE $columnName = ?"
val cursor = db.rawQuery(query, arrayOf(word))
return if (cursor.moveToFirst()) {
cursor
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/be/scri/helpers/data/SQLiteExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ fun SQLiteDatabase.columnExists(
}
false
}

fun SQLiteDatabase.getInfinitiveColumnName(): String? {
val candidates = listOf("infinitive", "verb", "activeInfinitive", "simplePresent")
for (candidate in candidates) {
if (columnExists("verbs", candidate)) {
return candidate
}
}
return null
}
Loading
Loading