-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update SettingsViewModel.kt #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
For Below api level 31 i have also fixed it
updated for just commit
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@dturner My CLA certificate is not verifying I have done the same as per the instructions. Please help! |
It looks like this PR contains commits from multiple authors. All authors must sign the CLA. |
Specifically, this commit 9efe95d is from an author that hasn't signed the CLA |
I have made all the commits myself since I read somewhere that I should verify the CLA by committing again. Should I fork again and make a new PR? |
@dturner I have successfully signed the CLA. Can you please tell me if there is anything else I need to do? |
You need to update the unit tests so that they pass |
Okay |
(context.getSystemService(Context.UI_MODE_SERVICE) as? UiModeManager) | ||
?.setApplicationNightMode(uiModeMode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(context.getSystemService(Context.UI_MODE_SERVICE) as? UiModeManager) | |
?.setApplicationNightMode(uiModeMode) | |
context.getSystemService<UiModeManager>()?.setApplicationNightMode(uiModeMode) |
@@ -62,6 +72,21 @@ class SettingsViewModel @Inject constructor( | |||
fun updateDarkThemeConfig(darkThemeConfig: DarkThemeConfig) { | |||
viewModelScope.launch { | |||
userDataRepository.setDarkThemeConfig(darkThemeConfig) | |||
val splashMode = when (darkThemeConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name is quite misleading. Could we change it to nightMode
?
} | ||
AppCompatDelegate.setDefaultNightMode(splashMode) | ||
if (Build.VERSION.SDK_INT >= VERSION_CODES.S) { | ||
val uiModeMode = when (darkThemeConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiModeMode
should be renamed, why not simply uiMode
or nightMode
?
@@ -35,6 +44,7 @@ import kotlin.time.Duration.Companion.seconds | |||
@HiltViewModel | |||
class SettingsViewModel @Inject constructor( | |||
private val userDataRepository: UserDataRepository, | |||
@ApplicationContext private val context: Context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing Context
instances in ViewModel
s is generally a bad practice as it might lead to memory leak (here since we use @ApplicationContext
it does not really leak anything), and facilitate accessing Context
resources that might change through configuration changes that would not be reflected in the ViewModel scope.
Could we instead request a UiModeManager
and @Provide
it in a Hilt module? (or even extract this logic of applying a DarkThemeConfig
altogether in a dedicated class?)
What I have done and why