Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Aug 30, 2024
1 parent 9ecad63 commit 27a4945
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import javax.inject.Singleton

@Module
Expand All @@ -32,4 +34,10 @@ object ApplicationModule {
@Provides
@Singleton
fun providesSwissTransferInjection() = SwissTransferInjection()

@Provides
@Singleton
fun providesGlobalCoroutineScope(@DefaultDispatcher defaultDispatcher: CoroutineDispatcher): CoroutineScope {
return CoroutineScope(defaultDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.infomaniak.multiplatform_swisstransfer.SwissTransferInjection
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltAndroidApp
class MainApplication : Application(), DefaultLifecycleObserver {
class MainApplication : Application() {

@Inject
lateinit var swissTransferInjection: SwissTransferInjection

override fun onStart(owner: LifecycleOwner) {
owner.lifecycleScope.launch { swissTransferInjection.loadDefaultAccount() }
@Inject
lateinit var globalCoroutineScope: CoroutineScope

override fun onCreate() {
super.onCreate()
globalCoroutineScope.launch { swissTransferInjection.loadDefaultAccount() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
fun SettingsScreen(
onItemClick: (SettingsOptionScreens) -> Unit,
getSelectedSetting: () -> SettingsOptionScreens?,
appSettings: AppSettings? = null
appSettings: AppSettings
) {
val selectedSetting = getSelectedSetting()

Expand All @@ -77,7 +77,7 @@ fun SettingsScreen(
titleRes = R.string.settingsOptionTheme,
isSelected = { selectedSetting == THEME },
icon = AppIcons.PaintbrushPalette,
description = appSettings?.theme?.getString(),
description = appSettings.theme.getString(),
CHEVRON
) {
onItemClick(THEME)
Expand All @@ -99,7 +99,7 @@ fun SettingsScreen(
titleRes = R.string.settingsOptionValidityPeriod,
isSelected = { selectedSetting == VALIDITY_PERIOD },
icon = AppIcons.FileBadgeArrowDown,
description = appSettings?.validityPeriod?.getString(),
description = appSettings.validityPeriod.getString(),
endIcon = CHEVRON,
) {
onItemClick(VALIDITY_PERIOD)
Expand All @@ -108,7 +108,7 @@ fun SettingsScreen(
titleRes = R.string.settingsOptionDownloadLimit,
isSelected = { selectedSetting == DOWNLOAD_LIMIT },
icon = AppIcons.Clock,
description = appSettings?.downloadLimit?.getString(),
description = appSettings.downloadLimit.getString(),
endIcon = CHEVRON,
) {
onItemClick(DOWNLOAD_LIMIT)
Expand All @@ -117,7 +117,7 @@ fun SettingsScreen(
titleRes = R.string.settingsOptionEmailLanguage,
isSelected = { selectedSetting == EMAIL_LANGUAGE },
icon = AppIcons.SpeechBubble,
description = appSettings?.emailLanguage?.getString(),
description = appSettings.emailLanguage.getString(),
endIcon = CHEVRON,
) {
onItemClick(EMAIL_LANGUAGE)
Expand Down Expand Up @@ -182,12 +182,19 @@ enum class SettingsOptionScreens {
DISCOVER_INFOMANIAK, SHARE_IDEAS, GIVE_FEEDBACK,
}

private class DummyAppSettings(
override var theme: Theme = Theme.SYSTEM,
override var downloadLimit: DownloadLimit = DownloadLimit.TWOHUNDREDFIFTY,
override var emailLanguage: EmailLanguage = EmailLanguage.FRENCH,
override var validityPeriod: ValidityPeriod = ValidityPeriod.THIRTY,
) : AppSettings

@PreviewMobile
@Composable
private fun SettingsScreenPreview() {
SwissTransferTheme {
Surface(color = MaterialTheme.colorScheme.background) {
SettingsScreen(onItemClick = {}, getSelectedSetting = { null })
SettingsScreen(onItemClick = {}, getSelectedSetting = { null }, DummyAppSettings())
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lifecycleRuntimeKtx = "2.8.4"
material3Beta = "1.3.0-rc01"
navigation = "2.8.0-rc01"
serialization = "1.7.1"
swisstransfer = "0.1.0"
swisstransfer = "0.1.1"

[libraries]
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
Expand Down

0 comments on commit 27a4945

Please sign in to comment.