Skip to content

Commit 7562207

Browse files
committed
- reactive tutorial changes
1 parent 9d4f50f commit 7562207

2 files changed

Lines changed: 125 additions & 26 deletions

File tree

app/src/main/java/be/scri/ui/screens/tutorial/TutorialContent.kt

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,122 @@ package be.scri.ui.screens.tutorial
88
* through a specific Scribe feature.
99
*/
1010
object TutorialContent {
11+
12+
private fun getLanguageName(languageCode: String): String {
13+
return when (languageCode) {
14+
"en" -> "English"
15+
"es" -> "Spanish"
16+
"fr" -> "French"
17+
"it" -> "Italian"
18+
"pt" -> "Portuguese"
19+
"ru" -> "Russian"
20+
"sv" -> "Swedish"
21+
else -> "German"
22+
}
23+
}
24+
1125
/**
1226
* Chapter 1: Noun Annotation.
1327
* Teaches users about gender tags that appear when typing nouns.
1428
*/
15-
val nounAnnotationSteps =
16-
listOf(
29+
fun getNounAnnotationSteps(languageCode: String): List<TutorialStep> {
30+
val language = getLanguageName(languageCode)
31+
val (fatherWord, fatherTag, fatherGender) = when (languageCode) {
32+
"en" -> Triple("father", "M", "Masculine")
33+
"es" -> Triple("padre", "M", "Masculino")
34+
"fr" -> Triple("père", "M", "Masculin")
35+
"it" -> Triple("padre", "M", "Maschile")
36+
"pt" -> Triple("pai", "M", "Masculino")
37+
"ru" -> Triple("отец", "M", "Мужской")
38+
"sv" -> Triple("far", "C", "Common")
39+
else -> Triple("Vater", "M", "Maskulin")
40+
}
41+
42+
val (motherWord, motherTag, motherGender) = when (languageCode) {
43+
"en" -> Triple("mother", "F", "Feminine")
44+
"es" -> Triple("madre", "F", "Femenino")
45+
"fr" -> Triple("mère", "F", "Féminin")
46+
"it" -> Triple("madre", "F", "Femminile")
47+
"pt" -> Triple("mãe", "F", "Feminino")
48+
"ru" -> Triple("мать", "F", "Женский")
49+
"sv" -> Triple("mor", "C", "Common")
50+
else -> Triple("Mutter", "F", "Feminin")
51+
}
52+
53+
return listOf(
1754
TutorialStep(
1855
instruction =
19-
"Write the word \"Vater\". Notice the word suggestions " +
56+
"Write the word \"$fatherWord\". Notice the word suggestions " +
2057
"that appear on the keyboard's top bar.\n\n" +
2158
"Then, press space. You will see the word's gender " +
22-
"tag on the keyboard's top bar \u2013 in this case, \"M\" for Maskulin.",
23-
expectedWord = "Vater",
59+
"tag on the keyboard's top bar \u2013 in this case, \"$fatherTag\" for $fatherGender.",
60+
hint = "If your second language is not $language, change the language in your keyboard.",
61+
expectedWord = fatherWord,
2462
),
2563
TutorialStep(
2664
instruction =
27-
"Now write the word \"Mutter\" and then press space. " +
28-
"The gender tag will be \"F\", for Feminin.",
29-
expectedWord = "Mutter",
65+
"Now write the word \"$motherWord\" and then press space. " +
66+
"The gender tag will be \"$motherTag\", for $motherGender.",
67+
hint = "If your second language is not $language, change the language in your keyboard.",
68+
expectedWord = motherWord,
3069
),
3170
)
71+
}
3272

3373
/**
3474
* Chapter 2: Word Translation.
3575
* Teaches users how to use the Translate command via the Scribe key.
3676
*/
37-
val wordTranslationSteps =
38-
listOf(
77+
fun wordTranslationSteps(languageCode: String): List<TutorialStep>{
78+
val language = getLanguageName(languageCode)
79+
return listOf(
3980
TutorialStep(
4081
instruction =
4182
"Let's translate! Tap the \u27A1 Scribe key on the top-left " +
4283
"corner of your keyboard, and select \u00DCbersetzen.\n\n" +
4384
"Then write the word you want to translate, press \u25B6, " +
4485
"and the translation will be returned to you.",
45-
hint = "If your second language is not German, change the language in your keyboard.",
86+
hint = "If your second language is not $language, change the language in your keyboard.",
4687
requiresValidation = false,
4788
),
48-
)
89+
)}
4990

50-
val verbConjugationSteps =
51-
listOf(
91+
fun verbConjugationSteps(languageCode: String) : List<TutorialStep>{
92+
val language = getLanguageName(languageCode)
93+
return listOf(
5294
TutorialStep(
5395
instruction =
5496
"On to the verbs. Tap the \u27A1 Scribe key on the top-left " +
5597
"corner of your keyboard, and select Konjugieren.\n\n" +
5698
"Write the verb you want to conjugate, press \u25B6, and " +
5799
"you will see a table with all the verb tenses. Select " +
58100
"the one you need and it will be inserted!",
59-
hint = "If your second language is not German, change the language in your keyboard.",
101+
hint = "If your second language is not $language, change the language in your keyboard.",
60102
requiresValidation = false,
61103
),
62-
)
104+
)}
63105

64-
val nounPluralsSteps =
65-
listOf(
106+
fun nounPluralsSteps (languageCode: String) : List<TutorialStep> {
107+
val language = getLanguageName(languageCode)
108+
return listOf(
66109
TutorialStep(
67110
instruction =
68111
"Finding the plural of a noun with Scribe is easy. Tap " +
69112
"the \u27A1 Scribe key on the top-left corner of your " +
70113
"keyboard, and select Plural.\n\n" +
71114
"Then write the noun you want the plural for, press " +
72115
"\u25B6, and the plural will be returned to you.",
73-
hint = "If your second language is not German, change the language in your keyboard.",
116+
hint = "If your second language is not $language, change the language in your keyboard.",
74117
requiresValidation = false,
75118
),
76-
)
119+
)}
77120

78121
/** Returns all chapters as a list of pairs (title, steps). */
79-
fun getAllChapters(): List<Pair<String, List<TutorialStep>>> =
122+
fun getAllChapters(languageCode: String = "de"): List<Pair<String, List<TutorialStep>>> =
80123
listOf(
81-
"Noun annotation" to nounAnnotationSteps,
82-
"Word translation" to wordTranslationSteps,
83-
"Verb conjugation" to verbConjugationSteps,
84-
"Noun plurals" to nounPluralsSteps,
124+
"Noun annotation" to getNounAnnotationSteps(languageCode),
125+
"Word translation" to wordTranslationSteps(languageCode),
126+
"Verb conjugation" to verbConjugationSteps(languageCode),
127+
"Noun plurals" to nounPluralsSteps(languageCode),
85128
)
86129
}

app/src/main/java/be/scri/ui/screens/tutorial/TutorialNavigator.kt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
package be.scri.ui.screens.tutorial
44

5+
import android.content.BroadcastReceiver
6+
import android.content.Context
7+
import android.content.Intent
8+
import android.content.IntentFilter
59
import androidx.activity.compose.BackHandler
610
import androidx.compose.runtime.Composable
711
import androidx.compose.runtime.getValue
@@ -10,6 +14,30 @@ import androidx.compose.runtime.mutableStateOf
1014
import androidx.compose.runtime.remember
1115
import androidx.compose.runtime.setValue
1216
import androidx.compose.ui.Modifier
17+
import android.provider.Settings
18+
import androidx.compose.runtime.DisposableEffect
19+
import androidx.compose.ui.platform.LocalContext
20+
21+
22+
23+
24+
private fun getCurrentScribeLanguage(context: Context): String {
25+
val currentImeId = Settings.Secure.getString(
26+
context.contentResolver,
27+
Settings.Secure.DEFAULT_INPUT_METHOD
28+
) ?: ""
29+
30+
return when {
31+
currentImeId.contains("EnglishKeyboardIME") -> "en"
32+
currentImeId.contains("SpanishKeyboardIME") -> "es"
33+
currentImeId.contains("FrenchKeyboardIME") -> "fr"
34+
currentImeId.contains("ItalianKeyboardIME") -> "it"
35+
currentImeId.contains("PortugueseKeyboardIME") -> "pt"
36+
currentImeId.contains("RussianKeyboardIME") -> "ru"
37+
currentImeId.contains("SwedishKeyboardIME") -> "sv"
38+
else -> "de"
39+
}
40+
}
1341

1442
/**
1543
* The main tutorial navigation controller.
@@ -28,7 +56,35 @@ fun TutorialNavigator(
2856
var currentStepIndex by remember { mutableIntStateOf(0) }
2957
var isFullTutorial by remember { mutableStateOf(false) }
3058

31-
val allChapters = TutorialContent.getAllChapters()
59+
val context = LocalContext.current
60+
61+
var activeLanguageCode by remember {
62+
mutableStateOf(getCurrentScribeLanguage(context))
63+
}
64+
65+
DisposableEffect(context) {
66+
val receiver = object : BroadcastReceiver() {
67+
override fun onReceive(context: Context, intent: Intent) {
68+
if (intent.action == Intent.ACTION_INPUT_METHOD_CHANGED) {
69+
activeLanguageCode = getCurrentScribeLanguage(context)
70+
}
71+
}
72+
}
73+
74+
context.registerReceiver(
75+
receiver,
76+
IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED)
77+
)
78+
79+
onDispose {
80+
context.unregisterReceiver(receiver)
81+
}
82+
}
83+
84+
85+
val allChapters = remember(activeLanguageCode) {
86+
TutorialContent.getAllChapters(activeLanguageCode)
87+
}
3288

3389
BackHandler {
3490
if (currentScreen == "home") {

0 commit comments

Comments
 (0)