dark mode-v10
This commit is contained in:
parent
57bc9b9895
commit
36233da198
3 changed files with 16 additions and 7 deletions
|
|
@ -5,18 +5,20 @@ import androidx.activity.ComponentActivity
|
|||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import com.example.login_v3.auth.HealthCheckScreen
|
||||
import com.example.login_v3.home.setting.setting_detail_page.viewmodel.Theme_ViewModel
|
||||
import com.example.login_v3.ui.theme.AppTheme
|
||||
import com.example.login_v3.ui.theme.Login_V3Theme
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
//color mode viewmodel
|
||||
private val themeViewModel by viewModels<Theme_ViewModel>()
|
||||
private val themeViewModel: Theme_ViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -24,7 +26,9 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
installSplashScreen()
|
||||
setContent {
|
||||
Login_V3Theme(appTheme = themeViewModel.currentTheme) {
|
||||
val currentAppTheme by themeViewModel.currentTheme.collectAsState()
|
||||
|
||||
Login_V3Theme(appTheme = currentAppTheme) {
|
||||
Technologia()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import androidx.compose.material3.MaterialTheme
|
|||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
|
@ -22,7 +24,7 @@ fun setting_theme_page(
|
|||
viewModel: Theme_ViewModel
|
||||
){
|
||||
// 直接讀取,不需要 .value
|
||||
val selectedTheme = viewModel.currentTheme
|
||||
val selectedTheme by viewModel.currentTheme.collectAsState()
|
||||
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
Text(
|
||||
|
|
|
|||
|
|
@ -5,12 +5,15 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.example.login_v3.ui.theme.AppTheme
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class Theme_ViewModel : ViewModel() {
|
||||
var currentTheme by mutableStateOf(AppTheme.SYSTEM)
|
||||
private set
|
||||
private val _currentTheme = MutableStateFlow(AppTheme.DARK)
|
||||
val currentTheme: StateFlow<AppTheme> = _currentTheme.asStateFlow()
|
||||
|
||||
fun updateTheme(newTheme: AppTheme) {
|
||||
currentTheme = newTheme
|
||||
_currentTheme.value = newTheme
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue