Skip to content

Commit

Permalink
Add more amoled switch
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Mar 20, 2024
1 parent 866edc1 commit 05a0463
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 22 deletions.
11 changes: 8 additions & 3 deletions app/src/main/java/dev/brahmkshatriya/echo/EchoApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -41,22 +49,36 @@ 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)
summary = getString(R.string.amoled_summary)
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)
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/item_media_track.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/item_playlist_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
android:backgroundTint="?attr/colorSecondaryContainer"
android:alpha="0.25"
app:cardBackgroundColor="?attr/colorTertiary"
android:clickable="false"
app:strokeWidth="0dp" />

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/preference.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="?materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@android:color/transparent">
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/preference_switch.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="?materialCardViewFilledStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@android:color/transparent">
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_monochrome"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions app/src/main/res/values/attributes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="navBackground" format="reference|color" />
<attr name="echoBackground" format="reference|color" />
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@
<string name="restart_app">Restart the app to apply changes</string>
<string name="dynamic_player">Dynamic Player Color</string>
<string name="dynamic_player_summary">Apply color to the player based on the Track Artwork</string>
<string name="more_amoled">More Amoled</string>
<string name="more_amoled_summary">Make the navigation bar black too</string>

</resources>
4 changes: 3 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<item name="android:layout_marginStart">24dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">28sp</item>
<item name="android:background">?attr/colorSurface</item>
</style>

<style name="TopAppBar">
Expand All @@ -34,4 +33,7 @@
<style name="CollapsingBar" parent="Widget.Material3.CollapsingToolbar.Large">
<item name="layout_scrollFlags">scroll|exitUntilCollapsed|snap</item>
</style>
<style name="EchoCardView" parent="Widget.Material3.CardView.Filled">
<item name="cardBackgroundColor">@android:color/transparent</item>
</style>
</resources>
11 changes: 9 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/ic_mono_anim</item>
<item name="android:windowSplashScreenAnimationDuration" tools:targetApi="s">1200</item>
<item name="android:dialogTheme">@style/AppTheme.Dialog</item>
<item name="android:colorBackground">?attr/colorSurface</item>
<item name="materialCardViewStyle">@style/EchoCardView</item>
<item name="android:colorBackground">?attr/echoBackground</item>
<item name="navBackground">?attr/colorSurfaceContainerLowest</item>
<item name="echoBackground">?attr/colorSurface</item>
</style>

<style name="Default.Theme.Echo" parent="Base.Theme.Echo"/>
<style name="Amoled.Theme.Echo" parent="Base.Theme.Echo">
<item name="colorSurface">@color/amoled_bg</item>
<item name="cardBackgroundColor">@color/amoled_bg</item>
<item name="echoBackground">@color/amoled_bg</item>
</style>
<style name="MoreAmoled.Theme.Echo" parent="Amoled.Theme.Echo">
<item name="navBackground">@color/amoled_bg</item>
</style>
</resources>

0 comments on commit 05a0463

Please sign in to comment.