Skip to content

Commit fcde610

Browse files
authored
πŸ”€ :: (#914) μ‹œμŠ€ν…œ ν…Œλ§ˆ μ‚¬μš©μž 선택 제곡
2 parents da9c60e + c900535 commit fcde610

23 files changed

Lines changed: 316 additions & 2 deletions

File tree

β€Žapp/build.gradle.ktsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ dependencies {
9292
implementation(project(ProjectPaths.Core.DEVICE))
9393
implementation(project(ProjectPaths.Core.WIDGET))
9494
implementation(project(ProjectPaths.Core.ONBOARDING))
95+
implementation(project(ProjectPaths.Core.THEME))
9596

9697
implementation(project(ProjectPaths.DATA))
9798
implementation(project(ProjectPaths.DATABASE))

β€Žapp/src/main/kotlin/team/aliens/dms/android/app/MainActivity.ktβ€Ž

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import androidx.activity.ComponentActivity
66
import androidx.activity.compose.setContent
77
import androidx.activity.result.contract.ActivityResultContracts
88
import androidx.activity.viewModels
9+
import androidx.compose.foundation.isSystemInDarkTheme
10+
import androidx.compose.runtime.getValue
911
import androidx.core.view.WindowCompat
12+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1013
import androidx.lifecycle.lifecycleScope
1114
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
1215
import com.google.android.play.core.appupdate.AppUpdateOptions
@@ -19,6 +22,7 @@ import team.aliens.dms.android.app.ui.DmsApp
1922
import team.aliens.dms.android.core.designsystem.DmsTheme
2023
import team.aliens.dms.android.core.jwt.di.IsJwtAvailable
2124
import team.aliens.dms.android.core.notification.DeviceTokenManager
25+
import team.aliens.dms.android.core.theme.ThemeMode
2226
import javax.inject.Inject
2327

2428
@AndroidEntryPoint
@@ -52,7 +56,14 @@ class MainActivity : ComponentActivity() {
5256

5357
checkAppUpdate()
5458
setContent {
55-
DmsTheme {
59+
val themeMode by mainViewModel.themeMode.collectAsStateWithLifecycle()
60+
val systemIsDark = isSystemInDarkTheme()
61+
val isDark = when (themeMode) {
62+
ThemeMode.SYSTEM -> systemIsDark
63+
ThemeMode.LIGHT -> false
64+
ThemeMode.DARK -> true
65+
}
66+
DmsTheme(isDarkTheme = isDark) {
5667
DmsApp()
5768
}
5869
}

β€Žapp/src/main/kotlin/team/aliens/dms/android/app/MainActivityViewModel.ktβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
66
import kotlinx.coroutines.flow.MutableStateFlow
77
import kotlinx.coroutines.flow.StateFlow
88
import kotlinx.coroutines.flow.asStateFlow
9+
import kotlinx.coroutines.flow.first
910
import kotlinx.coroutines.launch
1011
import team.aliens.dms.android.core.jwt.JwtProvider
12+
import team.aliens.dms.android.core.theme.ThemeMode
13+
import team.aliens.dms.android.core.theme.datastore.ThemeDataStoreDataSource
1114
import team.aliens.dms.android.onboarding.datastore.OnboardingDataStoreDataSource
1215
import team.aliens.dms.android.shared.exception.util.runCatchingCancellable
1316
import javax.inject.Inject
@@ -16,6 +19,7 @@ import javax.inject.Inject
1619
class MainActivityViewModel @Inject constructor(
1720
private val jwtProvider: JwtProvider,
1821
private val onboardingDataSource: OnboardingDataStoreDataSource,
22+
private val themeDataStoreDataSource: ThemeDataStoreDataSource,
1923
) : ViewModel() {
2024
val autoSignInAvailable: StateFlow<Boolean> = jwtProvider.isCachedRefreshTokenAvailable
2125

@@ -28,12 +32,21 @@ class MainActivityViewModel @Inject constructor(
2832
private val _isStartupResolved = MutableStateFlow(false)
2933
val isStartupResolved: StateFlow<Boolean> = _isStartupResolved.asStateFlow()
3034

35+
private val _themeMode = MutableStateFlow(ThemeMode.SYSTEM)
36+
val themeMode: StateFlow<ThemeMode> = _themeMode.asStateFlow()
37+
3138
init {
3239
viewModelScope.launch {
3340
runCatchingCancellable { jwtProvider.resolveSession() }
3441
_isOnboardingCompleted.value = onboardingDataSource.getOnboardingCompleted()
42+
_themeMode.value = themeDataStoreDataSource.getThemeModeFlow().first()
3543
_isStartupResolved.value = true
3644
}
45+
viewModelScope.launch {
46+
themeDataStoreDataSource.getThemeModeFlow().collect { mode ->
47+
_themeMode.value = mode
48+
}
49+
}
3750
}
3851

3952
fun resolveSession() {

β€ŽbuildSrc/src/main/kotlin/ProjectPaths.ktβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object ProjectPaths {
2020
const val DEVICE = ":core:device"
2121
const val WIDGET = ":core:widget"
2222
const val ONBOARDING = ":core:onboarding"
23+
const val THEME = ":core:theme"
2324
}
2425

2526
object Shared {

β€Žcore/datastore/src/main/java/team/aliens/dms/android/core/datastore/DataStore.ktβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ internal val Context.featuresStore: PreferencesDataStore by preferencesDataStore
1010
internal val Context.deviceStore: PreferencesDataStore by preferencesDataStore("device-datastore")
1111

1212
internal val Context.onboardingStore: PreferencesDataStore by preferencesDataStore("onboarding-datastore")
13+
14+
internal val Context.themeStore: PreferencesDataStore by preferencesDataStore("theme-datastore")

β€Žcore/datastore/src/main/java/team/aliens/dms/android/core/datastore/Qualifier.ktβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ annotation class JwtDataStore
1717
@Qualifier
1818
@Retention(AnnotationRetention.BINARY)
1919
annotation class OnboardingDataStore
20+
21+
@Qualifier
22+
@Retention(AnnotationRetention.BINARY)
23+
annotation class ThemeDataStore

β€Žcore/datastore/src/main/java/team/aliens/dms/android/core/datastore/di/DataStoreModule.ktβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import team.aliens.dms.android.core.datastore.FeaturesDataStore
1111
import team.aliens.dms.android.core.datastore.JwtDataStore
1212
import team.aliens.dms.android.core.datastore.OnboardingDataStore
1313
import team.aliens.dms.android.core.datastore.PreferencesDataStore
14+
import team.aliens.dms.android.core.datastore.ThemeDataStore
1415
import team.aliens.dms.android.core.datastore.deviceStore
1516
import team.aliens.dms.android.core.datastore.featuresStore
1617
import team.aliens.dms.android.core.datastore.jwtStore
1718
import team.aliens.dms.android.core.datastore.onboardingStore
19+
import team.aliens.dms.android.core.datastore.themeStore
1820
import javax.inject.Singleton
1921

2022
@Module
@@ -48,4 +50,11 @@ internal object DataStoreModule {
4850
fun provideOnboardingDataStore(
4951
@ApplicationContext context: Context,
5052
): PreferencesDataStore = context.onboardingStore
53+
54+
@Provides
55+
@Singleton
56+
@ThemeDataStore
57+
fun provideThemeDataStore(
58+
@ApplicationContext context: Context,
59+
): PreferencesDataStore = context.themeStore
5160
}

β€Žcore/theme/.gitignoreβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

β€Žcore/theme/build.gradle.ktsβ€Ž

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
plugins {
2+
alias(libs.plugins.android.library)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.hilt)
5+
alias(libs.plugins.ksp)
6+
}
7+
8+
android {
9+
namespace = "team.aliens.dms.android.core.theme"
10+
compileSdk = libs.versions.compileSdk.get().toInt()
11+
12+
defaultConfig {
13+
minSdk = libs.versions.minSdk.get().toInt()
14+
15+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles("consumer-rules.pro")
17+
}
18+
19+
buildTypes {
20+
release {
21+
isMinifyEnabled = false
22+
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro",
26+
)
27+
}
28+
}
29+
30+
compileOptions {
31+
sourceCompatibility = Versions.java
32+
targetCompatibility = Versions.java
33+
}
34+
35+
kotlinOptions {
36+
jvmTarget = Versions.java.toString()
37+
}
38+
}
39+
40+
dependencies {
41+
implementation(project(ProjectPaths.Core.DATASTORE))
42+
43+
implementation(libs.androidx.core)
44+
implementation(libs.androidx.datastore.preferences)
45+
46+
implementation(libs.hilt)
47+
ksp(libs.hilt.compiler)
48+
49+
testImplementation(libs.junit)
50+
androidTestImplementation(libs.androidx.junit)
51+
androidTestImplementation(libs.androidx.espresso)
52+
}

β€Žcore/theme/consumer-rules.proβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)