Simplify theme color application logic

This commit is contained in:
MM20 2021-12-13 17:34:13 +01:00
parent cb72b9180f
commit 9ebac9684b
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
13 changed files with 35 additions and 79 deletions

View File

@ -37,7 +37,7 @@
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/LauncherTheme.DefaultColors"
android:theme="@style/LauncherTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
@ -51,7 +51,7 @@
android:parentActivityName=".ui.legacy.activity.LauncherActivity"
android:screenOrientation="portrait"
android:taskAffinity="de.mm20.launcher2.settings"
android:theme="@style/SettingsTheme.DefaultColors">
android:theme="@style/SettingsTheme">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />

View File

@ -3,26 +3,22 @@ package de.mm20.launcher2.activity
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import de.mm20.launcher2.R
import de.mm20.launcher2.fragment.PreferencesCalendarFragment
import de.mm20.launcher2.fragment.PreferencesMainFragment
import de.mm20.launcher2.fragment.PreferencesServicesFragment
import de.mm20.launcher2.fragment.PreferencesWeatherFragment
import de.mm20.launcher2.preferences.ColorSchemes
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.ui.legacy.activity.LauncherActivity
import de.mm20.launcher2.ui.legacy.helper.ThemeHelper
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
when(LauncherPreferences.instance.colorScheme) {
ColorSchemes.BLACK -> setTheme(R.style.SettingsTheme_BlackWhiteColors)
else -> setTheme(R.style.SettingsTheme_DefaultColors)
}
ThemeHelper.applyTheme(theme)
if (savedInstanceState == null) {
val fragment = getStartFragment()
setupActionBar()

View File

@ -1,5 +1,5 @@
<resources>
<style name="DefaultColors" parent="BaseTheme">
<style name="DefaultColors">
<item name="colorPrimary">@android:color/system_accent1_200</item>
<item name="colorOnPrimary">@android:color/system_accent1_800</item>
<item name="colorPrimaryContainer">@android:color/system_accent1_700</item>

View File

@ -1,5 +1,5 @@
<resources>
<style name="DefaultColors" parent="BaseTheme">
<style name="DefaultColors">
<item name="colorPrimary">#72D1FF</item>
<item name="colorOnPrimary">#003549</item>
<item name="colorPrimaryContainer">#004D68</item>
@ -29,7 +29,7 @@
<item name="elevationOverlayEnabled">true</item>
</style>
<style name="BlackWhiteColors" parent="BaseTheme">
<style name="BlackWhiteColors">
<item name="colorPrimary">@android:color/white</item>
<item name="colorOnPrimary">@android:color/black</item>
<item name="colorPrimaryContainer">@android:color/black</item>

View File

@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SettingsTheme.DefaultColors" parent="DefaultColors">
<item name="android:statusBarColor">?colorSurface</item>
<item name="android:windowLightStatusBar">false</item>
</style>
<style name="SettingsTheme.BlackWhiteColors" parent="BlackWhiteColors">
<style name="SettingsTheme" parent="BaseTheme">
<item name="android:statusBarColor">?colorSurface</item>
<item name="android:windowLightStatusBar">false</item>
</style>

View File

@ -1,5 +1,5 @@
<resources>
<style name="DefaultColors" parent="BaseTheme">
<style name="DefaultColors">
<item name="colorPrimary">@android:color/system_accent1_600</item>
<item name="colorOnPrimary">@android:color/system_accent1_0</item>
<item name="colorPrimaryContainer">@android:color/system_accent1_100</item>

View File

@ -1,5 +1,5 @@
<resources>
<style name="DefaultColors" parent="BaseTheme">
<style name="DefaultColors">
<item name="colorPrimary">#006689</item>
<item name="colorOnPrimary">@android:color/white</item>
<item name="colorPrimaryContainer">#BFE8FF</item>
@ -29,7 +29,7 @@
<item name="elevationOverlayEnabled">false</item>
</style>
<style name="BlackWhiteColors" parent="BaseTheme">
<style name="BlackWhiteColors">
<item name="colorPrimary">@android:color/black</item>
<item name="colorOnPrimary">@android:color/white</item>
<item name="colorPrimaryContainer">@android:color/white</item>

View File

@ -21,31 +21,6 @@
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>
<!-- Main theme. -->
<style name="LauncherTheme" parent="BaseLauncherTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:colorPrimaryDark">#0000</item>
<item name="android:statusBarColor">#00000000</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:enforceStatusBarContrast">false</item>
<item name="android:enforceNavigationBarContrast">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SettingsTheme" parent="BaseLauncherTheme.Settings">
<item name="android:colorAccent">@color/blue</item>
<item name="colorAccent">@color/blue</item>
<item name="colorPrimary">@color/settings_color_primary</item>
<item name="colorPrimaryDark">@color/settings_color_primary_dark</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowShowWallpaper">true</item>
</style>
<style name="AlertDialogTheme" parent="ThemeOverlay.Material3.Dialog.Alert">
<item name="buttonBarButtonStyle">@style/AlertDialogButtonStyle</item>
<item name="dialogCornerRadius">8dp</item>
@ -96,10 +71,6 @@
<item name="android:textColor">@color/chip_textcolor</item>
</style>
<style name="BaseLauncherTheme.Settings">
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="LauncherTheme.IconStyle">
<item name="android:alpha">0.87</item>
<item name="android:tint">@color/icon_color</item>

View File

@ -19,32 +19,12 @@
</style>
<style name="SettingsTheme.DefaultColors" parent="DefaultColors">
<style name="SettingsTheme" parent="BaseTheme">
<item name="android:statusBarColor">?colorSurface</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="SettingsTheme.BlackWhiteColors" parent="BlackWhiteColors">
<item name="android:statusBarColor">?colorSurface</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="LauncherTheme.DefaultColors" parent="DefaultColors">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:colorPrimaryDark">#0000</item>
<item name="android:statusBarColor">#00000000</item>
<item name="android:navigationBarColor">#00000000</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:enforceStatusBarContrast">false</item>
<item name="android:enforceNavigationBarContrast">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="LauncherTheme.BlackWhiteColors" parent="BlackWhiteColors">
<style name="LauncherTheme" parent="BaseTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:colorPrimaryDark">#0000</item>

View File

@ -48,6 +48,7 @@ public class CrashReporterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getTheme().applyStyle(R.style.DefaultColors, true);
setContentView(R.layout.crash_reporter_activity);
Toolbar toolbar = findViewById(R.id.toolbar);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CrashReporter.Theme" parent="SettingsTheme.DefaultColors">
<style name="CrashReporter.Theme" parent="SettingsTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

View File

@ -50,7 +50,6 @@ import de.mm20.launcher2.ktx.dp
import de.mm20.launcher2.ktx.isBrightColor
import de.mm20.launcher2.legacy.helper.ActivityStarter
import de.mm20.launcher2.permissions.PermissionsManager
import de.mm20.launcher2.preferences.ColorSchemes
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.search.SearchViewModel
import de.mm20.launcher2.transition.ChangingLayoutTransition
@ -59,6 +58,7 @@ import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.databinding.ActivityLauncherBinding
import de.mm20.launcher2.ui.legacy.component.EditFavoritesView
import de.mm20.launcher2.ui.legacy.component.WidgetView
import de.mm20.launcher2.ui.legacy.helper.ThemeHelper
import de.mm20.launcher2.ui.legacy.search.SearchGridView
import de.mm20.launcher2.ui.legacy.widget.LauncherWidget
import de.mm20.launcher2.weather.WeatherViewModel
@ -191,11 +191,8 @@ class LauncherActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val iconRepository: IconRepository by inject()
iconRepository.recreate()
ThemeHelper.applyTheme(theme)
when(LauncherPreferences.instance.colorScheme) {
ColorSchemes.BLACK -> setTheme(R.style.LauncherTheme_BlackWhiteColors)
else -> setTheme(R.style.LauncherTheme_DefaultColors)
}
if (LauncherPreferences.instance.firstRunVersion < 1) {
ActivityCompat.requestPermissions(
this, arrayOf(

View File

@ -0,0 +1,16 @@
package de.mm20.launcher2.ui.legacy.helper
import android.content.res.Resources
import de.mm20.launcher2.preferences.ColorSchemes
import de.mm20.launcher2.preferences.LauncherPreferences
import de.mm20.launcher2.ui.R
object ThemeHelper {
fun applyTheme(theme: Resources.Theme) {
val colorScheme = when(LauncherPreferences.instance.colorScheme) {
ColorSchemes.BLACK -> R.style.BlackWhiteColors
else -> R.style.DefaultColors
}
theme.applyStyle(colorScheme, true)
}
}