Skip to content

Commit

Permalink
[Theme] support to use Monet colors automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
chr56 committed Apr 3, 2023
1 parent 6443e23 commit a38665d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/lib/phonograph/activity/ThemeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import mt.util.color.darkenColor
import mt.util.color.primaryTextColor
import mt.util.color.secondaryTextColor
import player.phonograph.R
import player.phonograph.util.PhonographColorUtil.applyMonet
import player.phonograph.util.PhonographColorUtil.nightMode
import player.phonograph.util.preferences.StyleConfig
import androidx.appcompat.app.AppCompatDelegate
import android.animation.ValueAnimator
import android.content.res.Configuration
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -178,4 +180,13 @@ abstract class ThemeActivity : MultiLanguageActivity() {
colorChangeAnimator?.cancel()
colorChangeAnimator = null
}

//
// Material You Dynamic COlor
//
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
// Theme
applyMonet(this)
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/player/phonograph/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import player.phonograph.notification.ErrorNotification
import player.phonograph.notification.ErrorNotification.KEY_STACK_TRACE
import player.phonograph.service.queue.QueueManager
import player.phonograph.ui.activities.CrashActivity
import player.phonograph.util.PhonographColorUtil.applyMonet
import android.app.Application
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -57,6 +58,8 @@ class App : Application(), ImageLoaderFactory {
super.onConfigurationChanged(
ContextLocaleDelegate.onConfigurationChanged(this, newConfig)
)
// Theme
applyMonet(this)
}

override fun onCreate() {
Expand Down Expand Up @@ -91,6 +94,8 @@ class App : Application(), ImageLoaderFactory {
.commit()
}

applyMonet(this)

// Set up dynamic shortcuts
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
DynamicShortcutManager(this).initDynamicShortcuts()
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/player/phonograph/util/PhonographColorUtil.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package player.phonograph.util

import mt.pref.ThemeColor
import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
Expand All @@ -12,7 +13,9 @@ import mt.util.color.isColorLight
import mt.util.color.lightenColor
import player.phonograph.App
import player.phonograph.R
import player.phonograph.settings.Setting
import player.phonograph.util.preferences.StyleConfig
import android.os.Build
import java.util.*


Expand Down Expand Up @@ -51,6 +54,18 @@ object PhonographColorUtil {
theme
)

/**
* adjust color settings from Dynamic Color of Material You if available
*/
fun applyMonet(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && Setting.instance.enableMonet) {
ThemeColor.editTheme(context)
.primaryColor(context.getColor(android.R.color.system_accent1_300))
.accentColor(context.getColor(android.R.color.system_accent1_600))
.commit()
}
}

@JvmStatic
@ColorInt
fun shiftBackgroundColorForLightText(@ColorInt backgroundColor: Int): Int {
Expand Down

0 comments on commit a38665d

Please sign in to comment.