Fixed wallpaper accent not updating when wallpaper is changed
This commit is contained in:
parent
a104e42e0c
commit
5f8ba985a3
2 changed files with 20 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
|||
package code.name.monkey.retromusic.helper
|
||||
|
||||
import android.app.WallpaperColors
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
|
@ -12,18 +11,21 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
|||
class WallpaperAccentManager(val context: Context) {
|
||||
|
||||
private val onColorsChangedListener by lazy {
|
||||
WallpaperManager.OnColorsChangedListener { colors, which ->
|
||||
updateColors(colors, which)
|
||||
WallpaperManager.OnColorsChangedListener { _, _ ->
|
||||
updateColors()
|
||||
}
|
||||
}
|
||||
|
||||
fun init() {
|
||||
if (VersionUtils.hasOreoMR1() && PreferenceUtil.wallpaperAccent) {
|
||||
WallpaperManager.getInstance(context).apply {
|
||||
addOnColorsChangedListener(onColorsChangedListener, Handler(Looper.getMainLooper()))
|
||||
ThemeStore.editTheme(context).wallpaperColor(
|
||||
getWallpaperColors(WallpaperManager.FLAG_SYSTEM)?.primaryColor?.toArgb() ?: 0
|
||||
).commit()
|
||||
if (VersionUtils.hasOreoMR1()) {
|
||||
with(WallpaperManager.getInstance(context)) {
|
||||
updateColors()
|
||||
if (PreferenceUtil.wallpaperAccent) {
|
||||
addOnColorsChangedListener(
|
||||
onColorsChangedListener,
|
||||
Handler(Looper.getMainLooper())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +37,15 @@ class WallpaperAccentManager(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateColors(colors: WallpaperColors?, which: Int) {
|
||||
private fun updateColors() {
|
||||
if (VersionUtils.hasOreoMR1()) {
|
||||
if (which == WallpaperManager.FLAG_SYSTEM && colors != null) {
|
||||
ThemeStore.editTheme(context).wallpaperColor(colors.primaryColor.toArgb())
|
||||
.commit()
|
||||
val colors = WallpaperManager.getInstance(context)
|
||||
.getWallpaperColors(WallpaperManager.FLAG_SYSTEM)
|
||||
if (colors != null) {
|
||||
val primaryColor = colors.primaryColor.toArgb()
|
||||
if (primaryColor != ThemeStore.wallpaperColor(context)) {
|
||||
ThemeStore.editTheme(context).wallpaperColor(primaryColor).commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="circle_play_button"
|
||||
android:layout="@layout/list_item_view_switch"
|
||||
android:layout="@layout/list_item_view_switch_no_title"
|
||||
android:title="@string/pref_title_circle_button" />
|
||||
|
||||
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue