Skip to content

Commit 067c43c

Browse files
feat: onboarding language screen ui and viewModel (#2850)
1 parent 19cacac commit 067c43c

File tree

28 files changed

+1296
-49
lines changed

28 files changed

+1296
-49
lines changed

core/datastore/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ android {
2323
}
2424

2525
kotlin{
26-
2726
sourceSets{
2827
commonMain.dependencies {
2928
implementation(libs.multiplatform.settings)
@@ -32,6 +31,7 @@ kotlin{
3231
implementation(libs.kotlinx.coroutines.core)
3332
implementation(libs.kotlinx.serialization.core)
3433
implementation(projects.core.common)
34+
implementation(projects.core.model)
3535
}
3636
}
3737
}

core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesDataSource.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.russhwolf.settings.serialization.decodeValue
1717
import com.russhwolf.settings.serialization.decodeValueOrNull
1818
import com.russhwolf.settings.serialization.encodeValue
1919
import kotlinx.coroutines.CoroutineDispatcher
20+
import kotlinx.coroutines.flow.Flow
2021
import kotlinx.coroutines.flow.MutableStateFlow
2122
import kotlinx.coroutines.flow.map
2223
import kotlinx.coroutines.withContext
@@ -25,6 +26,7 @@ import okio.ByteString.Companion.encodeUtf8
2526
import org.mifos.mobile.core.datastore.model.AppSettings
2627
import org.mifos.mobile.core.datastore.model.AppTheme
2728
import org.mifos.mobile.core.datastore.model.UserData
29+
import org.mifos.mobile.core.model.LanguageConfig
2830

2931
private const val USER_DATA = "userData"
3032
private const val APP_SETTINGS = "appSettings"
@@ -70,6 +72,9 @@ class UserPreferencesDataSource(
7072

7173
val officeName = _userInfo.map { it.officeName }
7274

75+
val observeLanguage: Flow<LanguageConfig>
76+
get() = _settingsInfo.map { it.language }
77+
7378
suspend fun updateSettingsInfo(appSettings: AppSettings) {
7479
withContext(dispatcher) {
7580
settings.putSettingsPreference(appSettings)
@@ -167,6 +172,27 @@ class UserPreferencesDataSource(
167172
return _settingsInfo.value.gcmToken
168173
}
169174

175+
suspend fun setLanguage(language: LanguageConfig) =
176+
withContext(dispatcher) {
177+
val newPreference = settings.getSettingsPreference().copy(language = language)
178+
settings.putSettingsPreference(newPreference)
179+
_settingsInfo.value = newPreference
180+
}
181+
182+
suspend fun setShowOnboarding(showOnboarding: Boolean) =
183+
withContext(dispatcher) {
184+
val newPreference = settings.getSettingsPreference().copy(showOnboarding = showOnboarding)
185+
settings.putSettingsPreference(newPreference)
186+
_settingsInfo.value = newPreference
187+
}
188+
189+
suspend fun setFirstTimeState(firstTimeState: Boolean) =
190+
withContext(dispatcher) {
191+
val newPreference = settings.getSettingsPreference().copy(firstTimeState = firstTimeState)
192+
settings.putSettingsPreference(newPreference)
193+
_settingsInfo.value = newPreference
194+
}
195+
170196
companion object {
171197
private const val PROFILE_IMAGE = "preferences_profile_image"
172198
}
@@ -185,6 +211,14 @@ private fun Settings.putUserPreference(user: UserData) {
185211
)
186212
}
187213

214+
private fun Settings.getSettingsPreference(): AppSettings {
215+
return decodeValue(
216+
key = APP_SETTINGS,
217+
serializer = AppSettings.serializer(),
218+
defaultValue = AppSettings.DEFAULT,
219+
)
220+
}
221+
188222
private fun Settings.putSettingsPreference(settings: AppSettings) {
189223
encodeValue(
190224
key = APP_SETTINGS,

core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesRepository.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.mifos.mobile.core.common.DataState
1515
import org.mifos.mobile.core.datastore.model.AppSettings
1616
import org.mifos.mobile.core.datastore.model.AppTheme
1717
import org.mifos.mobile.core.datastore.model.UserData
18+
import org.mifos.mobile.core.model.LanguageConfig
1819

1920
interface UserPreferencesRepository {
2021
val userInfo: Flow<UserData>
@@ -30,8 +31,11 @@ interface UserPreferencesRepository {
3031
val profileImage: String?
3132

3233
val sentTokenToServer: StateFlow<Boolean>
34+
3335
val gcmToken: StateFlow<String?>
3436

37+
val observeLanguage: Flow<LanguageConfig>
38+
3539
suspend fun updateToken(password: String): DataState<Unit>
3640

3741
suspend fun updateTheme(theme: AppTheme): DataState<Unit>
@@ -48,5 +52,11 @@ interface UserPreferencesRepository {
4852

4953
suspend fun saveGcmToken(token: String?): DataState<Unit>
5054

55+
suspend fun setShowOnboarding(showOnboarding: Boolean)
56+
57+
suspend fun setFirstTimeState(firstTimeState: Boolean)
58+
59+
suspend fun setLanguage(language: LanguageConfig)
60+
5161
suspend fun logOut(): Unit
5262
}

core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/UserPreferencesRepositoryImpl.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.mifos.mobile.core.common.DataState
2020
import org.mifos.mobile.core.datastore.model.AppSettings
2121
import org.mifos.mobile.core.datastore.model.AppTheme
2222
import org.mifos.mobile.core.datastore.model.UserData
23+
import org.mifos.mobile.core.model.LanguageConfig
2324

2425
class UserPreferencesRepositoryImpl(
2526
private val preferenceManager: UserPreferencesDataSource,
@@ -65,6 +66,9 @@ class UserPreferencesRepositoryImpl(
6566
get() = preferenceManager.settingsInfo.map { it.gcmToken }
6667
.stateIn(unconfinedScope, SharingStarted.Eagerly, null)
6768

69+
override val observeLanguage: Flow<LanguageConfig>
70+
get() = preferenceManager.observeLanguage
71+
6872
override suspend fun updateToken(password: String): DataState<Unit> {
6973
return try {
7074
val result = preferenceManager.updateToken(password)
@@ -137,6 +141,18 @@ class UserPreferencesRepositoryImpl(
137141
}
138142
}
139143

144+
override suspend fun setFirstTimeState(firstTimeState: Boolean) {
145+
preferenceManager.setFirstTimeState(firstTimeState)
146+
}
147+
148+
override suspend fun setShowOnboarding(showOnboarding: Boolean) {
149+
preferenceManager.setShowOnboarding(showOnboarding)
150+
}
151+
152+
override suspend fun setLanguage(language: LanguageConfig) {
153+
preferenceManager.setLanguage(language)
154+
}
155+
140156
override suspend fun logOut() {
141157
preferenceManager.clearInfo()
142158
}

core/datastore/src/commonMain/kotlin/org/mifos/mobile/core/datastore/model/AppSettings.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,31 @@
1010
package org.mifos.mobile.core.datastore.model
1111

1212
import kotlinx.serialization.Serializable
13+
import org.mifos.mobile.core.model.LanguageConfig
1314

1415
@Serializable
1516
data class AppSettings(
1617
val tenant: String,
1718
val baseUrl: String,
1819
val passcode: String? = null,
1920
val appTheme: AppTheme = AppTheme.SYSTEM,
20-
val language: MifosAppLanguage,
2121
val sentTokenToServer: Boolean = false,
2222
val gcmToken: String? = null,
23+
24+
val language: LanguageConfig,
25+
val showOnboarding: Boolean,
26+
val firstTimeState: Boolean,
2327
) {
2428
companion object {
2529
val DEFAULT = AppSettings(
2630
tenant = "default",
2731
baseUrl = "https://tt.mifos.community/",
2832
appTheme = AppTheme.SYSTEM,
29-
language = MifosAppLanguage.SYSTEM_LANGUAGE,
3033
sentTokenToServer = false,
3134
gcmToken = null,
35+
language = LanguageConfig.DEFAULT,
36+
showOnboarding = true,
37+
firstTimeState = true,
3238
)
3339
}
3440
}

core/designsystem/src/commonMain/kotlin/org/mifos/mobile/core/designsystem/theme/Color.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@ object AppColors {
233233
val borderColorOne = Color(0xFFD6E4F7)
234234

235235
val customBlack = Color(0xFF3A3A3A)
236+
val customWhite = Color(0xFFFFFFFF)
236237
}

core/designsystem/src/commonMain/kotlin/org/mifos/mobile/core/designsystem/theme/DesignToken.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ data class AppSizes(
286286
val avatarSmall: Dp = 32.dp,
287287
val avatarMedium: Dp = 48.dp,
288288
val avatarLarge: Dp = 64.dp,
289-
val buttonHeight: Dp = 48.dp,
289+
val buttonHeight: Dp = 56.dp,
290290
val inputHeight: Dp = 56.dp,
291291
val cardMinHeight: Dp = 120.dp,
292292
val profile: Dp = 72.dp,
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.core.model
11+
12+
enum class LanguageConfig(
13+
val localName: String?,
14+
val languageName: String,
15+
) {
16+
DEFAULT(
17+
localName = null,
18+
languageName = "System (Default)",
19+
),
20+
ENGLISH(
21+
localName = "en",
22+
languageName = "English (English)",
23+
),
24+
TELUGU(
25+
localName = "te",
26+
languageName = "Telugu (తెలుగు)",
27+
),
28+
HINDI(
29+
localName = "hi",
30+
languageName = "Hindi (हिंदी)",
31+
),
32+
ARABIC(
33+
localName = "ar",
34+
languageName = "Arabic (عربى)",
35+
),
36+
URDU(
37+
localName = "ur",
38+
languageName = "Urdu (اُردُو)",
39+
),
40+
BENGALI(
41+
localName = "bn",
42+
languageName = "Bengali (বাঙালি)",
43+
),
44+
SPANISH(
45+
localName = "es",
46+
languageName = "Spanish (Español)",
47+
),
48+
FRENCH(
49+
localName = "fr",
50+
languageName = "French (français)",
51+
),
52+
INDONESIAN(
53+
localName = "id",
54+
languageName = "Indonesian (bahasa Indonesia)",
55+
),
56+
KHMER(
57+
localName = "km",
58+
languageName = "Khmer (ភាសាខ្មែរ)",
59+
),
60+
KANNADA(
61+
localName = "kn",
62+
languageName = "Kannada (ಕನ್ನಡ)",
63+
),
64+
BURMESE(
65+
localName = "my",
66+
languageName = "Burmese (မြန်မာ)",
67+
),
68+
POLISH(
69+
localName = "pl",
70+
languageName = "Polish (Polski)",
71+
),
72+
PORTUGUESE(
73+
localName = "pt",
74+
languageName = "Portuguese (Português)",
75+
),
76+
RUSSIAN(
77+
localName = "ru",
78+
languageName = "Russian (русский)",
79+
),
80+
SWAHILI(
81+
localName = "sw",
82+
languageName = "Swahili (Kiswahili)",
83+
),
84+
FARSI(
85+
localName = "fa",
86+
languageName = "Farsi (فارسی)",
87+
),
88+
;
89+
90+
companion object {
91+
fun fromString(value: String): LanguageConfig {
92+
return entries.find { it.languageName.equals(value, ignoreCase = true) } ?: DEFAULT
93+
}
94+
}
95+
}

core/ui/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ kotlin{
4747
}
4848
}
4949

50+
51+
compose.resources {
52+
publicResClass = true
53+
generateResClass = always
54+
packageOfResClass = "mifos_mobile.core.ui.generated.resources"
55+
}

0 commit comments

Comments
 (0)