diff --git a/app/src/main/java/be/scri/ui/screens/tutorial/TutorialContent.kt b/app/src/main/java/be/scri/ui/screens/tutorial/TutorialContent.kt index f55de975..26b7735b 100644 --- a/app/src/main/java/be/scri/ui/screens/tutorial/TutorialContent.kt +++ b/app/src/main/java/be/scri/ui/screens/tutorial/TutorialContent.kt @@ -8,47 +8,90 @@ package be.scri.ui.screens.tutorial * through a specific Scribe feature. */ object TutorialContent { + private fun getLanguageName(languageCode: String): String = + when (languageCode) { + "en" -> "English" + "es" -> "Spanish" + "fr" -> "French" + "it" -> "Italian" + "pt" -> "Portuguese" + "ru" -> "Russian" + "sv" -> "Swedish" + else -> "German" + } + /** * Chapter 1: Noun Annotation. * Teaches users about gender tags that appear when typing nouns. */ - val nounAnnotationSteps = - listOf( + fun getNounAnnotationSteps(languageCode: String): List { + val language = getLanguageName(languageCode) + val (fatherWord, fatherTag, fatherGender) = + when (languageCode) { + "en" -> Triple("father", "M", "Masculine") + "es" -> Triple("padre", "M", "Masculino") + "fr" -> Triple("père", "M", "Masculin") + "it" -> Triple("padre", "M", "Maschile") + "pt" -> Triple("pai", "M", "Masculino") + "ru" -> Triple("отец", "M", "Мужской") + "sv" -> Triple("far", "C", "Common") + else -> Triple("Vater", "M", "Maskulin") + } + + val (motherWord, motherTag, motherGender) = + when (languageCode) { + "en" -> Triple("mother", "F", "Feminine") + "es" -> Triple("madre", "F", "Femenino") + "fr" -> Triple("mère", "F", "Féminin") + "it" -> Triple("madre", "F", "Femminile") + "pt" -> Triple("mãe", "F", "Feminino") + "ru" -> Triple("мать", "F", "Женский") + "sv" -> Triple("mor", "C", "Common") + else -> Triple("Mutter", "F", "Feminin") + } + + return listOf( TutorialStep( instruction = - "Write the word \"Vater\". Notice the word suggestions " + + "Write the word \"$fatherWord\". Notice the word suggestions " + "that appear on the keyboard's top bar.\n\n" + "Then, press space. You will see the word's gender " + - "tag on the keyboard's top bar \u2013 in this case, \"M\" for Maskulin.", - expectedWord = "Vater", + "tag on the keyboard's top bar \u2013 in this case, \"$fatherTag\" for $fatherGender.", + hint = "If your second language is not $language, change the language in your keyboard.", + expectedWord = fatherWord, ), TutorialStep( instruction = - "Now write the word \"Mutter\" and then press space. " + - "The gender tag will be \"F\", for Feminin.", - expectedWord = "Mutter", + "Now write the word \"$motherWord\" and then press space. " + + "The gender tag will be \"$motherTag\", for $motherGender.", + hint = "If your second language is not $language, change the language in your keyboard.", + expectedWord = motherWord, ), ) + } /** * Chapter 2: Word Translation. * Teaches users how to use the Translate command via the Scribe key. */ - val wordTranslationSteps = - listOf( + fun wordTranslationSteps(languageCode: String): List { + val language = getLanguageName(languageCode) + return listOf( TutorialStep( instruction = "Let's translate! Tap the \u27A1 Scribe key on the top-left " + "corner of your keyboard, and select \u00DCbersetzen.\n\n" + "Then write the word you want to translate, press \u25B6, " + "and the translation will be returned to you.", - hint = "If your second language is not German, change the language in your keyboard.", + hint = "If your second language is not $language, change the language in your keyboard.", requiresValidation = false, ), ) + } - val verbConjugationSteps = - listOf( + fun verbConjugationSteps(languageCode: String): List { + val language = getLanguageName(languageCode) + return listOf( TutorialStep( instruction = "On to the verbs. Tap the \u27A1 Scribe key on the top-left " + @@ -56,13 +99,15 @@ object TutorialContent { "Write the verb you want to conjugate, press \u25B6, and " + "you will see a table with all the verb tenses. Select " + "the one you need and it will be inserted!", - hint = "If your second language is not German, change the language in your keyboard.", + hint = "If your second language is not $language, change the language in your keyboard.", requiresValidation = false, ), ) + } - val nounPluralsSteps = - listOf( + fun nounPluralsSteps(languageCode: String): List { + val language = getLanguageName(languageCode) + return listOf( TutorialStep( instruction = "Finding the plural of a noun with Scribe is easy. Tap " + @@ -70,17 +115,18 @@ object TutorialContent { "keyboard, and select Plural.\n\n" + "Then write the noun you want the plural for, press " + "\u25B6, and the plural will be returned to you.", - hint = "If your second language is not German, change the language in your keyboard.", + hint = "If your second language is not $language, change the language in your keyboard.", requiresValidation = false, ), ) + } /** Returns all chapters as a list of pairs (title, steps). */ - fun getAllChapters(): List>> = + fun getAllChapters(languageCode: String = "de"): List>> = listOf( - "Noun annotation" to nounAnnotationSteps, - "Word translation" to wordTranslationSteps, - "Verb conjugation" to verbConjugationSteps, - "Noun plurals" to nounPluralsSteps, + "Noun annotation" to getNounAnnotationSteps(languageCode), + "Word translation" to wordTranslationSteps(languageCode), + "Verb conjugation" to verbConjugationSteps(languageCode), + "Noun plurals" to nounPluralsSteps(languageCode), ) } diff --git a/app/src/main/java/be/scri/ui/screens/tutorial/TutorialNavigator.kt b/app/src/main/java/be/scri/ui/screens/tutorial/TutorialNavigator.kt index d82d2f0d..71d6cc8c 100644 --- a/app/src/main/java/be/scri/ui/screens/tutorial/TutorialNavigator.kt +++ b/app/src/main/java/be/scri/ui/screens/tutorial/TutorialNavigator.kt @@ -2,14 +2,40 @@ package be.scri.ui.screens.tutorial +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.provider.Settings import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext + +private fun getCurrentScribeLanguage(context: Context): String { + val currentImeId = + Settings.Secure.getString( + context.contentResolver, + Settings.Secure.DEFAULT_INPUT_METHOD, + ) ?: "" + + return when { + currentImeId.contains("EnglishKeyboardIME") -> "en" + currentImeId.contains("SpanishKeyboardIME") -> "es" + currentImeId.contains("FrenchKeyboardIME") -> "fr" + currentImeId.contains("ItalianKeyboardIME") -> "it" + currentImeId.contains("PortugueseKeyboardIME") -> "pt" + currentImeId.contains("RussianKeyboardIME") -> "ru" + currentImeId.contains("SwedishKeyboardIME") -> "sv" + else -> "de" + } +} /** * The main tutorial navigation controller. @@ -28,7 +54,39 @@ fun TutorialNavigator( var currentStepIndex by remember { mutableIntStateOf(0) } var isFullTutorial by remember { mutableStateOf(false) } - val allChapters = TutorialContent.getAllChapters() + val context = LocalContext.current + + var activeLanguageCode by remember { + mutableStateOf(getCurrentScribeLanguage(context)) + } + + DisposableEffect(context) { + val receiver = + object : BroadcastReceiver() { + override fun onReceive( + context: Context, + intent: Intent, + ) { + if (intent.action == Intent.ACTION_INPUT_METHOD_CHANGED) { + activeLanguageCode = getCurrentScribeLanguage(context) + } + } + } + + context.registerReceiver( + receiver, + IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED), + ) + + onDispose { + context.unregisterReceiver(receiver) + } + } + + val allChapters = + remember(activeLanguageCode) { + TutorialContent.getAllChapters(activeLanguageCode) + } BackHandler { if (currentScreen == "home") {