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,24 +1,21 @@
|
|||
package code.name.monkey.retromusic.helper
|
||||
|
||||
import android.app.WallpaperColors
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.annotation.RequiresApi
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
|
||||
class WallpaperAccentManager(val context: Context) {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O_MR1)
|
||||
private val onColorsChangedListener =
|
||||
private val onColorsChangedListener by lazy {
|
||||
WallpaperManager.OnColorsChangedListener { colors, which ->
|
||||
if (which == WallpaperManager.FLAG_SYSTEM && colors != null) {
|
||||
ThemeStore.editTheme(context).wallpaperColor(colors.primaryColor.toArgb()).commit()
|
||||
}
|
||||
updateColors(colors, which)
|
||||
}
|
||||
}
|
||||
|
||||
fun init() {
|
||||
if (VersionUtils.hasOreoMR1() && PreferenceUtil.wallpaperAccent) {
|
||||
|
@ -37,4 +34,13 @@ class WallpaperAccentManager(val context: Context) {
|
|||
.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