Address Gemini code review feedback

- Use first() instead of collect() in MainActivity to avoid redundant
  calls when theme changes at runtime (since SettingsViewModel already
  handles that)
- Extract DarkThemeConfig to night mode mapping into extension functions
  to avoid code duplication and improve maintainability

Based on feedback from gemini-code-assist review
pull/2058/head
shaominngqing 4 weeks ago
parent 302648afde
commit 02fa916bb4

@ -0,0 +1,30 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.util
import androidx.appcompat.app.AppCompatDelegate
import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
/**
* Converts [DarkThemeConfig] to the corresponding [AppCompatDelegate] night mode constant.
* This is used to set the application-level night mode for the splash screen and system UI.
*/
fun DarkThemeConfig.toNightMode(): Int = when (this) {
DarkThemeConfig.FOLLOW_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
DarkThemeConfig.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
DarkThemeConfig.DARK -> AppCompatDelegate.MODE_NIGHT_YES
}

@ -0,0 +1,30 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.feature.settings.impl
import androidx.appcompat.app.AppCompatDelegate
import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
/**
* Converts [DarkThemeConfig] to the corresponding [AppCompatDelegate] night mode constant.
* This is used to set the application-level night mode for the splash screen and system UI.
*/
internal fun DarkThemeConfig.toNightMode(): Int = when (this) {
DarkThemeConfig.FOLLOW_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
DarkThemeConfig.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
DarkThemeConfig.DARK -> AppCompatDelegate.MODE_NIGHT_YES
}
Loading…
Cancel
Save