From 68bdd0d929b8bf7bf3de241f0913683006a55f5e Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Fri, 11 Jun 2021 09:08:04 -0600 Subject: [PATCH] style: add basic black theme Finally add black theme support to Auxio. This is abit of a janky implementation since I had to add an extra set of accents, but it shouldn't be as big of a problem after the styles refactoring. Support for black android components is not implemented yet, but will be eventually. --- .../java/org/oxycblt/auxio/MainActivity.kt | 23 +++- .../auxio/settings/SettingsListFragment.kt | 11 ++ .../oxycblt/auxio/settings/SettingsManager.kt | 5 + .../main/java/org/oxycblt/auxio/ui/Accent.kt | 89 ++++++++++++---- .../org/oxycblt/auxio/ui/InterfaceUtils.kt | 9 ++ app/src/main/res/layout/fragment_playback.xml | 1 + app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/styles_core.xml | 5 + app/src/main/res/values/themes.xml | 2 +- app/src/main/res/values/themes_black.xml | 100 ++++++++++++++++++ app/src/main/res/xml/prefs_main.xml | 8 ++ 12 files changed, 232 insertions(+), 25 deletions(-) create mode 100644 app/src/main/res/values/themes_black.xml diff --git a/app/src/main/java/org/oxycblt/auxio/MainActivity.kt b/app/src/main/java/org/oxycblt/auxio/MainActivity.kt index bde3581de..673b0db11 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainActivity.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainActivity.kt @@ -15,6 +15,7 @@ import org.oxycblt.auxio.playback.system.PlaybackService import org.oxycblt.auxio.settings.SettingsManager import org.oxycblt.auxio.ui.Accent import org.oxycblt.auxio.ui.isEdgeOn +import org.oxycblt.auxio.ui.isNight /** * The single [AppCompatActivity] for Auxio. @@ -25,11 +26,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val settingsManager = SettingsManager.getInstance() - val newAccent = Accent.set(settingsManager.accent) - - AppCompatDelegate.setDefaultNightMode(settingsManager.theme) - setTheme(newAccent.theme) + setupTheme() val binding = DataBindingUtil.setContentView( this, R.layout.activity_main @@ -52,6 +49,22 @@ class MainActivity : AppCompatActivity() { onNewIntent(intent) } + private fun setupTheme() { + // Update the current accent and theme + val settingsManager = SettingsManager.getInstance() + AppCompatDelegate.setDefaultNightMode(settingsManager.theme) + + val newAccent = Accent.set(settingsManager.accent) + + // The black theme has a completely separate set of styles since style attributes cannot + // be modified at runtime. + if (isNight() && settingsManager.useBlackTheme) { + setTheme(newAccent.blackTheme) + } else { + setTheme(newAccent.theme) + } + } + override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsListFragment.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsListFragment.kt index 520923a76..eb6f15e51 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsListFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsListFragment.kt @@ -18,6 +18,7 @@ import org.oxycblt.auxio.settings.blacklist.BlacklistDialog import org.oxycblt.auxio.settings.ui.IntListPrefDialog import org.oxycblt.auxio.settings.ui.IntListPreference import org.oxycblt.auxio.ui.Accent +import org.oxycblt.auxio.ui.isNight import org.oxycblt.auxio.ui.showToast /** @@ -82,6 +83,16 @@ class SettingsListFragment : PreferenceFragmentCompat() { } } + SettingsManager.KEY_BLACK_THEME -> { + onPreferenceClickListener = Preference.OnPreferenceClickListener { + if (requireContext().isNight()) { + requireActivity().recreate() + } + + true + } + } + SettingsManager.KEY_ACCENT -> { onPreferenceClickListener = Preference.OnPreferenceClickListener { AccentDialog().show(childFragmentManager, AccentDialog.TAG) diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt index d04c4e9a8..8cbd65b4a 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt @@ -32,6 +32,10 @@ class SettingsManager private constructor(context: Context) : val theme: Int get() = handleThemeCompat(sharedPrefs) + /** Whether the dark theme should be black or not */ + val useBlackTheme: Boolean + get() = sharedPrefs.getBoolean(KEY_BLACK_THEME, false) + /** The current accent. */ var accent: Accent get() = handleAccentCompat(sharedPrefs) @@ -195,6 +199,7 @@ class SettingsManager private constructor(context: Context) : companion object { const val KEY_THEME = "KEY_THEME2" + const val KEY_BLACK_THEME = "KEY_BLACK_THEME" const val KEY_ACCENT = "KEY_ACCENT2" const val KEY_LIB_DISPLAY_MODE = "KEY_LIB_MODE" diff --git a/app/src/main/java/org/oxycblt/auxio/ui/Accent.kt b/app/src/main/java/org/oxycblt/auxio/ui/Accent.kt index 0c5564e5c..a339a4e15 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/Accent.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/Accent.kt @@ -15,34 +15,85 @@ import org.oxycblt.auxio.R * TODO: Add custom accents */ val ACCENTS = arrayOf( - Accent(R.color.red, R.style.Theme_Red, R.string.color_label_red), - Accent(R.color.pink, R.style.Theme_Pink, R.string.color_label_pink), - Accent(R.color.purple, R.style.Theme_Purple, R.string.color_label_purple), - Accent(R.color.deep_purple, R.style.Theme_DeepPurple, R.string.color_label_deep_purple), - Accent(R.color.indigo, R.style.Theme_Indigo, R.string.color_label_indigo), - Accent(R.color.blue, R.style.Theme_Blue, R.string.color_label_blue), - Accent(R.color.light_blue, R.style.Theme_LightBlue, R.string.color_label_light_blue), - Accent(R.color.cyan, R.style.Theme_Cyan, R.string.color_label_cyan), - Accent(R.color.teal, R.style.Theme_Teal, R.string.color_label_teal), - Accent(R.color.green, R.style.Theme_Green, R.string.color_label_green), - Accent(R.color.light_green, R.style.Theme_LightGreen, R.string.color_label_light_green), - Accent(R.color.lime, R.style.Theme_Lime, R.string.color_label_lime), - Accent(R.color.yellow, R.style.Theme_Yellow, R.string.color_label_yellow), - Accent(R.color.orange, R.style.Theme_Orange, R.string.color_label_orange), - Accent(R.color.deep_orange, R.style.Theme_DeepOrange, R.string.color_label_deep_orange), - Accent(R.color.brown, R.style.Theme_Brown, R.string.color_label_brown), - Accent(R.color.grey, R.style.Theme_Gray, R.string.color_label_grey), - Accent(R.color.blue_grey, R.style.Theme_BlueGrey, R.string.color_label_blue_grey), + Accent(R.color.red, R.style.Theme_Red, R.style.Theme_Red_Black, R.string.color_label_red), + Accent(R.color.pink, R.style.Theme_Pink, R.style.Theme_Pink_Black, R.string.color_label_pink), + Accent( + R.color.purple, + R.style.Theme_Purple, + R.style.Theme_Purple_Black, + R.string.color_label_purple + ), + Accent( + R.color.deep_purple, + R.style.Theme_DeepPurple, + R.style.Theme_DeepPurple_Black, + R.string.color_label_deep_purple + ), + Accent( + R.color.indigo, + R.style.Theme_Indigo, + R.style.Theme_Indigo_Black, + R.string.color_label_indigo + ), + Accent(R.color.blue, R.style.Theme_Blue, R.style.Theme_Blue_Black, R.string.color_label_blue), + Accent( + R.color.light_blue, + R.style.Theme_LightBlue, + R.style.Theme_LightBlue_Black, + R.string.color_label_light_blue + ), + Accent(R.color.cyan, R.style.Theme_Cyan, R.style.Theme_Cyan_Black, R.string.color_label_cyan), + Accent(R.color.teal, R.style.Theme_Teal, R.style.Theme_Teal_Black, R.string.color_label_teal), + Accent(R.color.green, R.style.Theme_Green, R.style.Theme_Green_Black, R.string.color_label_green), + Accent( + R.color.light_green, + R.style.Theme_LightGreen, + R.style.Theme_LightGreen_Black, + R.string.color_label_light_green + ), + Accent(R.color.lime, R.style.Theme_Lime, R.style.Theme_Lime_Black, R.string.color_label_lime), + Accent( + R.color.yellow, + R.style.Theme_Yellow, + R.style.Theme_Yellow_Black, + R.string.color_label_yellow + ), + Accent( + R.color.orange, + R.style.Theme_Orange, + R.style.Theme_Orange_Black, + R.string.color_label_orange + ), + Accent( + R.color.deep_orange, + R.style.Theme_DeepOrange, + R.style.Theme_DeepOrange_Black, + R.string.color_label_deep_orange + ), + Accent(R.color.brown, R.style.Theme_Brown, R.style.Theme_Brown_Black, R.string.color_label_brown), + Accent(R.color.grey, R.style.Theme_Grey, R.style.Theme_Grey_Black, R.string.color_label_grey), + Accent( + R.color.blue_grey, + R.style.Theme_BlueGrey, + R.style.Theme_BlueGrey_Black, + R.string.color_label_blue_grey + ), ) /** * The data object for an accent. * @property color The color resource for this accent * @property theme The theme resource for this accent + * @property blackTheme The black theme resource for this accent * @property name The name of this accent * @author OxygenCobalt */ -data class Accent(@ColorRes val color: Int, @StyleRes val theme: Int, @StringRes val name: Int) { +data class Accent( + @ColorRes val color: Int, + @StyleRes val theme: Int, + @StyleRes val blackTheme: Int, + @StringRes val name: Int +) { /** * Get a [ColorStateList] of the accent */ diff --git a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt index a10c50c18..d97f9f69b 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt @@ -78,6 +78,15 @@ fun Context.getSystemServiceSafe(serviceClass: KClass): T { } } +/** + * Returns whether the current UI is in night mode or not. This will work if the theme is + * automatic as well. + */ +fun Context.isNight(): Boolean { + return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == + Configuration.UI_MODE_NIGHT_YES +} + /** * Resolve a color. * @param context [Context] required diff --git a/app/src/main/res/layout/fragment_playback.xml b/app/src/main/res/layout/fragment_playback.xml index 979fd9e96..0336cfcba 100644 --- a/app/src/main/res/layout/fragment_playback.xml +++ b/app/src/main/res/layout/fragment_playback.xml @@ -79,6 +79,7 @@ android:layout_marginStart="@dimen/spacing_mid_large" android:layout_marginEnd="@dimen/spacing_mid_large" android:layout_marginBottom="@dimen/spacing_medium" + android:text="@{song.album.name}" android:onClick="@{() -> detailModel.navToItem(playbackModel.song.album)}" app:layout_constraintBottom_toTopOf="@+id/playback_seek_bar" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 70423b2a9..6f952fb20 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,6 +7,8 @@ #202020 #01fafafa + #000000 + #343434 + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index b9b8e7426..45ce9dd5f 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -83,7 +83,7 @@ @color/brown - diff --git a/app/src/main/res/values/themes_black.xml b/app/src/main/res/values/themes_black.xml new file mode 100644 index 000000000..838835b09 --- /dev/null +++ b/app/src/main/res/values/themes_black.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/prefs_main.xml b/app/src/main/res/xml/prefs_main.xml index 9be4bb84e..a37e73412 100644 --- a/app/src/main/res/xml/prefs_main.xml +++ b/app/src/main/res/xml/prefs_main.xml @@ -20,6 +20,14 @@ app:summary="@string/color_label_blue" app:title="@string/setting_accent" /> + +