Fixed crash on API lower than 27 because of WallpaperAccentManager
This commit is contained in:
parent
df21419b8b
commit
93ad0d0a90
1 changed files with 13 additions and 7 deletions
|
@ -1,22 +1,19 @@
|
||||||
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.Build
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
|
||||||
class WallpaperAccentManager(val context: Context) {
|
class WallpaperAccentManager(val context: Context) {
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O_MR1)
|
private val onColorsChangedListener by lazy {
|
||||||
private val onColorsChangedListener =
|
|
||||||
WallpaperManager.OnColorsChangedListener { colors, which ->
|
WallpaperManager.OnColorsChangedListener { colors, which ->
|
||||||
if (which == WallpaperManager.FLAG_SYSTEM && colors != null) {
|
updateColors(colors, which)
|
||||||
ThemeStore.editTheme(context).wallpaperColor(colors.primaryColor.toArgb()).commit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,4 +34,13 @@ class WallpaperAccentManager(val context: Context) {
|
||||||
.removeOnColorsChangedListener(onColorsChangedListener)
|
.removeOnColorsChangedListener(onColorsChangedListener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateColors(colors: WallpaperColors?, which: Int) {
|
||||||
|
if (VersionUtils.hasOreoMR1()) {
|
||||||
|
if (which == WallpaperManager.FLAG_SYSTEM && colors != null) {
|
||||||
|
ThemeStore.editTheme(context).wallpaperColor(colors.primaryColor.toArgb())
|
||||||
|
.commit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue