Wrap icon and badge parameters of ShapedLauncherIcon in lambda

This commit is contained in:
MM20 2022-09-02 19:10:55 +02:00
parent 9134085088
commit 6e411e9555
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
9 changed files with 54 additions and 39 deletions

View File

@ -54,27 +54,29 @@ import kotlin.math.roundToInt
fun ShapedLauncherIcon(
modifier: Modifier = Modifier,
size: Dp,
icon: LauncherIcon? = null,
badge: Badge? = null,
icon: () -> LauncherIcon? = { null },
badge: () -> Badge? = { null },
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
shape: Shape = LocalIconShape.current
) {
var currentIcon by remember(icon) {
val _icon = icon()
var currentIcon by remember(_icon) {
mutableStateOf(
when (icon) {
when (_icon) {
is DynamicLauncherIcon -> null
is StaticLauncherIcon -> icon
is StaticLauncherIcon -> _icon
else -> null
}
)
}
if (icon is DynamicLauncherIcon) {
if (_icon is DynamicLauncherIcon) {
val time = LocalTime.current
LaunchedEffect(time) {
currentIcon = icon.getIcon(time)
currentIcon = _icon.getIcon(time)
}
}
@ -113,7 +115,8 @@ fun ShapedLauncherIcon(
)
}
}
if (badge != null) {
val _badge = badge()
if (_badge != null) {
Surface(
shadowElevation = 1.dp,
tonalElevation = 1.dp,
@ -134,7 +137,7 @@ fun ShapedLauncherIcon(
contentAlignment = Alignment.Center
) {
badge.progress?.let {
_badge.progress?.let {
val progress by animateFloatAsState(it)
CircularProgressIndicator(
modifier = Modifier.fillMaxSize(),
@ -143,10 +146,10 @@ fun ShapedLauncherIcon(
color = MaterialTheme.colorScheme.secondaryContainer
)
}
val badgeIconRes = badge.iconRes
val badgeIcon = badge.icon
val badgeIconRes = _badge.iconRes
val badgeIcon = _badge.icon
val number = badge.number
val number = _badge.number
if (badgeIconRes != null) {
Image(
modifier = Modifier
@ -188,6 +191,13 @@ fun ShapedLauncherIcon(
}
}
@Composable
private fun Badge(
badge: () -> Badge?
) {
}
@Composable
private fun IconLayer(
layer: LauncherIconLayer,

View File

@ -169,8 +169,8 @@ fun AppItem(
size = 84.dp,
modifier = Modifier
.padding(16.dp),
badge = badge,
icon = icon,
badge = { badge },
icon = { icon },
)
}

View File

@ -87,10 +87,12 @@ fun CustomizeSearchableSheet(
ShapedLauncherIcon(
size = iconSize,
icon = icon,
badge = Badge(
icon = badgeDrawable
),
icon = { icon },
badge = {
Badge(
icon = badgeDrawable
)
},
onClick = {
viewModel.openIconPicker()
}
@ -239,7 +241,7 @@ fun IconPreview(
) {
ShapedLauncherIcon(
size = iconSize,
icon = item?.preview,
icon = { item?.preview },
onClick = onClick
)
}

View File

@ -82,8 +82,8 @@ fun GridItem(modifier: Modifier = Modifier, item: Searchable, showLabels: Boolea
bounds = it.boundsInWindow()
},
size = LocalGridIconSize.current,
badge = badge,
icon = icon,
badge = { badge },
icon = { icon },
onClick = {
if (!launchOnPress || !viewModel.launch(context, bounds)) {
showPopup = true

View File

@ -70,7 +70,7 @@ fun ContactItem(
size = 48.dp,
modifier = Modifier
.padding(start = padding, top = padding, bottom = padding),
icon = icon,
icon = { icon },
)
Column(
modifier = Modifier.padding(horizontal = 16.dp)

View File

@ -132,8 +132,8 @@ fun FileItem(
size = 48.dp,
modifier = Modifier
.padding(end = padding, top = padding, bottom = padding),
icon = icon,
badge = badge
icon = { icon },
badge = { badge }
)
}

View File

@ -93,8 +93,8 @@ fun AppShortcutItem(
size = size,
modifier = Modifier
.padding(padding),
badge = badge,
icon = icon,
badge = { badge },
icon = { icon },
)
}

View File

@ -408,22 +408,25 @@ fun IconShapePreference(
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val context = LocalContext.current
ShapedLauncherIcon(
size = 48.dp,
icon = StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = ContextCompat.getDrawable(
LocalContext.current,
R.mipmap.ic_launcher_foreground
)!!,
scale = 1.5f,
),
backgroundLayer = StaticIconLayer(
icon = ColorDrawable(
LocalContext.current.getColor(R.color.ic_launcher_background)
icon = {
StaticLauncherIcon(
foregroundLayer = StaticIconLayer(
icon = ContextCompat.getDrawable(
context,
R.mipmap.ic_launcher_foreground
)!!,
scale = 1.5f,
),
backgroundLayer = StaticIconLayer(
icon = ColorDrawable(
context.getColor(R.color.ic_launcher_background)
)
)
)
),
},
onClick = {
onValueChanged(it)
showDialog = false

View File

@ -186,7 +186,7 @@ fun HiddenItem(
) {
ShapedLauncherIcon(
size = 32.dp,
icon = icon,
icon = { icon },
modifier = Modifier.padding(end = 16.dp)
)
Text(