Wrap icon and badge parameters of ShapedLauncherIcon in lambda
This commit is contained in:
parent
9134085088
commit
6e411e9555
@ -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,
|
||||
|
||||
@ -169,8 +169,8 @@ fun AppItem(
|
||||
size = 84.dp,
|
||||
modifier = Modifier
|
||||
.padding(16.dp),
|
||||
badge = badge,
|
||||
icon = icon,
|
||||
badge = { badge },
|
||||
icon = { icon },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 }
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ fun AppShortcutItem(
|
||||
size = size,
|
||||
modifier = Modifier
|
||||
.padding(padding),
|
||||
badge = badge,
|
||||
icon = icon,
|
||||
badge = { badge },
|
||||
icon = { icon },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -186,7 +186,7 @@ fun HiddenItem(
|
||||
) {
|
||||
ShapedLauncherIcon(
|
||||
size = 32.dp,
|
||||
icon = icon,
|
||||
icon = { icon },
|
||||
modifier = Modifier.padding(end = 16.dp)
|
||||
)
|
||||
Text(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user