Skip to content

Commit 86eca6d

Browse files
committed
Refactor AccentColorOption and remove blocking calls from BasePreferences
Signed-off-by: Saul Henriquez <saul_henriquez@hotmail.com>
1 parent 4ea27ec commit 86eca6d

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

Omega/src/com/neoapps/neolauncher/preferences/BasePreferences.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,12 @@ open class ColorIntPref(
193193
) : PrefDelegate<String>(titleId, summaryId, dataStore, key, defaultValue, onChange) {
194194

195195
fun getColor(): Int {
196-
return runBlocking(Dispatchers.IO) {
197-
AccentColorOption.Companion.fromString(getValue()).accentColor
198-
}
196+
return AccentColorOption.fromString(getValue()).accentColor
199197
}
200198

201199
@Composable
202200
fun getColorFromState(): Int {
203-
return AccentColorOption.Companion.fromString(getState().value).accentColor
201+
return AccentColorOption.fromString(getState().value).accentColor
204202
}
205203
}
206204

Omega/src/com/neoapps/neolauncher/theme/AccentColorOption.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,29 @@ import com.android.launcher3.Utilities
2626
import com.neoapps.neolauncher.NeoApp
2727
import com.neoapps.neolauncher.util.getColorAttr
2828
import com.neoapps.neolauncher.util.getSystemAccent
29+
import com.neoapps.neolauncher.wallpaper.WallpaperColorsCompat
2930
import com.neoapps.neolauncher.wallpaper.WallpaperManagerCompat
3031

3132
sealed 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

Comments
 (0)