Fix crash on Android 8.0

This commit is contained in:
MM20 2022-10-25 21:25:52 +02:00
parent 5163189789
commit 98d12d309f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -13,6 +13,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -39,12 +40,12 @@ data class WallpaperColors(
}
}
@RequiresApi(Build.VERSION_CODES.O_MR1)
@Composable
fun wallpaperColorsAsState(): State<WallpaperColors> {
val scope = rememberCoroutineScope()
val context = LocalContext.current
val state = remember { mutableStateOf(WallpaperColors()) }
if (isAtLeastApiLevel(27)) {
DisposableEffect(null) {
val wallpaperManager = WallpaperManager.getInstance(context)
val callback = callback@{ colors: android.app.WallpaperColors?, which: Int ->
@ -70,5 +71,6 @@ fun wallpaperColorsAsState(): State<WallpaperColors> {
wallpaperManager.removeOnColorsChangedListener(callback)
}
}
}
return state
}