From 05a04632c8df661eaf6bd02803511741d50be36c Mon Sep 17 00:00:00 2001 From: brahmkshatriya <69040506+brahmkshatriya@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:41:41 +0530 Subject: [PATCH] Add more amoled switch --- .../brahmkshatriya/echo/EchoApplication.kt | 11 +++++-- .../echo/ui/settings/LookFragment.kt | 33 ++++++++++++++++--- .../main/res/layout-land/activity_main.xml | 2 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/item_media_track.xml | 2 -- .../main/res/layout/item_playlist_item.xml | 3 +- app/src/main/res/layout/preference.xml | 4 +-- app/src/main/res/layout/preference_switch.xml | 4 +-- .../mipmap-anydpi-v26/ic_launcher_round.xml | 1 + app/src/main/res/values/attributes.xml | 5 +++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/styles.xml | 4 ++- app/src/main/res/values/themes.xml | 11 +++++-- 13 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/values/attributes.xml diff --git a/app/src/main/java/dev/brahmkshatriya/echo/EchoApplication.kt b/app/src/main/java/dev/brahmkshatriya/echo/EchoApplication.kt index 499232f5..2cbe47f2 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/EchoApplication.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/EchoApplication.kt @@ -36,16 +36,21 @@ class EchoApplication : Application(), ImageLoaderFactory { } companion object { - fun applyUiChanges(application: Application, preferences: SharedPreferences) { + fun applyUiChanges(app: Application, preferences: SharedPreferences) { val theme = when (preferences.getBoolean(LookFragment.AMOLED_KEY, false)) { - true -> R.style.Amoled_Theme_Echo + true -> { + when (preferences.getBoolean(LookFragment.MORE_AMOLED_KEY, false)) { + true -> R.style.MoreAmoled_Theme_Echo + false -> R.style.Amoled_Theme_Echo + } + } false -> R.style.Default_Theme_Echo } val options = DynamicColorsOptions.Builder() .setThemeOverlay(theme) .build() - DynamicColors.applyToActivitiesIfAvailable(application, options) + DynamicColors.applyToActivitiesIfAvailable(app, options) when (preferences.getString(LookFragment.THEME_KEY, "system")) { "light" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/LookFragment.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/LookFragment.kt index 4d6d4915..7c338c1b 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/LookFragment.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/LookFragment.kt @@ -8,18 +8,26 @@ import androidx.preference.Preference import androidx.preference.PreferenceCategory import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreferenceCompat +import dev.brahmkshatriya.echo.EchoApplication.Companion.applyUiChanges import dev.brahmkshatriya.echo.R class LookFragment : PreferenceFragmentCompat() { + + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { val context = preferenceManager.context preferenceManager.sharedPreferencesName = context.packageName preferenceManager.sharedPreferencesMode = Context.MODE_PRIVATE val preferences = preferenceManager.sharedPreferences ?: return - val uiListener = Preference.OnPreferenceChangeListener { _, _ -> - Toast.makeText(context, getString(R.string.restart_app), Toast.LENGTH_SHORT).show() + + fun uiListener(block: (Any) -> Unit = {}) = Preference.OnPreferenceChangeListener { _, new -> + applyUiChanges(requireActivity().application, preferences) + Toast.makeText(context, getString(R.string.restart_app), Toast.LENGTH_SHORT).show() + block(new) true } + val screen = preferenceManager.createPreferenceScreen(context) preferenceScreen = screen @@ -41,10 +49,21 @@ class LookFragment : PreferenceFragmentCompat() { entries = arrayOf("Light", "Dark", "System default") entryValues = arrayOf("light", "dark", "system") value = preferences.getString(THEME_KEY, "system") - onPreferenceChangeListener = uiListener + onPreferenceChangeListener = uiListener() addPreference(this) } + val moreAmoled = SwitchPreferenceCompat(context).apply { + key = MORE_AMOLED_KEY + title = getString(R.string.more_amoled) + summary = getString(R.string.more_amoled_summary) + layoutResource = R.layout.preference_switch + isIconSpaceReserved = false + setDefaultValue(false) + onPreferenceChangeListener = uiListener() + isEnabled = preferences.getBoolean(AMOLED_KEY, false) + } + SwitchPreferenceCompat(context).apply { key = AMOLED_KEY title = getString(R.string.amoled) @@ -52,11 +71,14 @@ class LookFragment : PreferenceFragmentCompat() { layoutResource = R.layout.preference_switch isIconSpaceReserved = false setDefaultValue(false) - onPreferenceChangeListener = uiListener + onPreferenceChangeListener = uiListener { + moreAmoled.isEnabled = it as Boolean + } addPreference(this) - } + addPreference(moreAmoled) + SwitchPreferenceCompat(context).apply { key = DYNAMIC_PLAYER title = getString(R.string.dynamic_player) @@ -74,6 +96,7 @@ class LookFragment : PreferenceFragmentCompat() { companion object { const val THEME_KEY = "theme" const val AMOLED_KEY = "amoled" + const val MORE_AMOLED_KEY = "more_amoled" const val DYNAMIC_PLAYER = "dynamic_player" } } \ No newline at end of file diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 1fefd207..ffb33884 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -35,7 +35,7 @@ android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" - android:background="?attr/colorSurfaceContainerLowest" + app:backgroundTint="?attr/navBackground" app:itemActiveIndicatorStyle="@style/BottomNavbarActiveIndicator" app:itemIconTint="@color/bottom_item_icon" app:labelVisibilityMode="labeled" diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6d727574..24e0c591 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -28,7 +28,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="?attr/colorSurfaceContainerLowest" + app:backgroundTint="?attr/navBackground" app:itemActiveIndicatorStyle="@style/BottomNavbarActiveIndicator" app:itemIconTint="@color/bottom_item_icon" app:labelVisibilityMode="labeled" diff --git a/app/src/main/res/layout/item_media_track.xml b/app/src/main/res/layout/item_media_track.xml index b9364edf..af8497fb 100644 --- a/app/src/main/res/layout/item_media_track.xml +++ b/app/src/main/res/layout/item_media_track.xml @@ -3,10 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" - app:strokeWidth="0dp" android:layout_height="wrap_content"> - diff --git a/app/src/main/res/layout/preference.xml b/app/src/main/res/layout/preference.xml index 2a9d25b3..2dd2f375 100644 --- a/app/src/main/res/layout/preference.xml +++ b/app/src/main/res/layout/preference.xml @@ -1,10 +1,8 @@ + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + \ No newline at end of file diff --git a/app/src/main/res/values/attributes.xml b/app/src/main/res/values/attributes.xml new file mode 100644 index 00000000..1ab8eb37 --- /dev/null +++ b/app/src/main/res/values/attributes.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9a1c2260..4d034cb7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,5 +68,7 @@ Restart the app to apply changes Dynamic Player Color Apply color to the player based on the Track Artwork + More Amoled + Make the navigation bar black too \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0e98a75f..588332ac 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,7 +20,6 @@ 24dp center_vertical 28sp - ?attr/colorSurface + \ 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 0f083f5a..c83ca612 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -5,11 +5,18 @@ @drawable/ic_mono_anim 1200 @style/AppTheme.Dialog - ?attr/colorSurface + @style/EchoCardView + ?attr/echoBackground + ?attr/colorSurfaceContainerLowest + ?attr/colorSurface + \ No newline at end of file