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
|
package code.name.monkey.retromusic.helper
|
||||||
|
|
||||||
import android.app.WallpaperColors
|
|
||||||
import android.app.WallpaperManager
|
import android.app.WallpaperManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
@ -12,18 +11,21 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
class WallpaperAccentManager(val context: Context) {
|
class WallpaperAccentManager(val context: Context) {
|
||||||
|
|
||||||
private val onColorsChangedListener by lazy {
|
private val onColorsChangedListener by lazy {
|
||||||
WallpaperManager.OnColorsChangedListener { colors, which ->
|
WallpaperManager.OnColorsChangedListener { _, _ ->
|
||||||
updateColors(colors, which)
|
updateColors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
if (VersionUtils.hasOreoMR1() && PreferenceUtil.wallpaperAccent) {
|
if (VersionUtils.hasOreoMR1()) {
|
||||||
WallpaperManager.getInstance(context).apply {
|
with(WallpaperManager.getInstance(context)) {
|
||||||
addOnColorsChangedListener(onColorsChangedListener, Handler(Looper.getMainLooper()))
|
updateColors()
|
||||||
ThemeStore.editTheme(context).wallpaperColor(
|
if (PreferenceUtil.wallpaperAccent) {
|
||||||
getWallpaperColors(WallpaperManager.FLAG_SYSTEM)?.primaryColor?.toArgb() ?: 0
|
addOnColorsChangedListener(
|
||||||
).commit()
|
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 (VersionUtils.hasOreoMR1()) {
|
||||||
if (which == WallpaperManager.FLAG_SYSTEM && colors != null) {
|
val colors = WallpaperManager.getInstance(context)
|
||||||
ThemeStore.editTheme(context).wallpaperColor(colors.primaryColor.toArgb())
|
.getWallpaperColors(WallpaperManager.FLAG_SYSTEM)
|
||||||
.commit()
|
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
|
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="circle_play_button"
|
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" />
|
android:title="@string/pref_title_circle_button" />
|
||||||
|
|
||||||
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory
|
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue