@@ -26,19 +26,29 @@ import com.android.launcher3.Utilities
2626import com.neoapps.neolauncher.NeoApp
2727import com.neoapps.neolauncher.util.getColorAttr
2828import com.neoapps.neolauncher.util.getSystemAccent
29+ import com.neoapps.neolauncher.wallpaper.WallpaperColorsCompat
2930import com.neoapps.neolauncher.wallpaper.WallpaperManagerCompat
3031
3132sealed class AccentColorOption {
3233 abstract val isSupported: Boolean
3334 abstract val displayName: Int
3435 abstract val accentColor: Int
3536
37+ protected fun resolveWallpaperColor (selector : WallpaperColorsCompat .() -> Int? ): Int {
38+ val context = NeoApp .instance?.applicationContext ? : return LightPrimary .toArgb()
39+ return WallpaperManagerCompat .INSTANCE .get(context)
40+ .wallpaperColors
41+ ?.selector()
42+ ? : LightPrimary .toArgb()
43+ }
44+
3645 object SystemAccent : AccentColorOption() {
3746 override val isSupported = true
3847 override val displayName = R .string.icon_shape_system_default
3948
4049 override val accentColor: Int
41- get() = NeoApp .instance?.applicationContext!! .getSystemAccent(false )
50+ get() = NeoApp .instance?.applicationContext?.getSystemAccent(false )
51+ ? : LightPrimary .toArgb()
4252
4353 override fun toString () = " system_accent"
4454 }
@@ -47,8 +57,7 @@ sealed class AccentColorOption {
4757 override val isSupported = true
4858 override val displayName = R .string.theme_auto
4959 override val accentColor: Int
50- get() = WallpaperManagerCompat .INSTANCE .get(NeoApp .instance?.applicationContext)
51- .wallpaperColors?.getPrimaryColor() ? : LightPrimary .toArgb()
60+ get() = resolveWallpaperColor { getPrimaryColor() }
5261
5362 override fun toString () = " wallpaper_primary"
5463 }
@@ -57,8 +66,7 @@ sealed class AccentColorOption {
5766 override val isSupported = true
5867 override val displayName = R .string.color_wallpaper_secondary
5968 override val accentColor: Int
60- get() = WallpaperManagerCompat .INSTANCE .get(NeoApp .instance?.applicationContext)
61- .wallpaperColors?.getSecondaryColor() ? : LightPrimary .toArgb()
69+ get() = resolveWallpaperColor { getSecondaryColor() }
6270
6371 override fun toString () = " wallpaper_secondary"
6472 }
@@ -67,8 +75,7 @@ sealed class AccentColorOption {
6775 override val isSupported = true
6876 override val displayName = R .string.color_wallpaper_tertiary
6977 override val accentColor: Int
70- get() = WallpaperManagerCompat .INSTANCE .get(NeoApp .instance?.applicationContext)
71- .wallpaperColors?.getTertiaryColor() ? : LightPrimary .toArgb()
78+ get() = resolveWallpaperColor { getTertiaryColor() }
7279
7380 override fun toString () = " wallpaper_tertiary"
7481 }
@@ -90,7 +97,8 @@ sealed class AccentColorOption {
9097
9198 override val displayName = - 1
9299 override val accentColor: Int
93- get() = NeoApp .instance?.applicationContext!! .getColorAttr(colorAccent)
100+ get() = NeoApp .instance?.applicationContext?.getColorAttr(colorAccent)
101+ ? : LightPrimary .toArgb()
94102
95103 }
96104
0 commit comments