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(
|
fun ShapedLauncherIcon(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
size: Dp,
|
size: Dp,
|
||||||
icon: LauncherIcon? = null,
|
icon: () -> LauncherIcon? = { null },
|
||||||
badge: Badge? = null,
|
badge: () -> Badge? = { null },
|
||||||
onClick: (() -> Unit)? = null,
|
onClick: (() -> Unit)? = null,
|
||||||
onLongClick: (() -> Unit)? = null,
|
onLongClick: (() -> Unit)? = null,
|
||||||
shape: Shape = LocalIconShape.current
|
shape: Shape = LocalIconShape.current
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var currentIcon by remember(icon) {
|
val _icon = icon()
|
||||||
|
|
||||||
|
var currentIcon by remember(_icon) {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
when (icon) {
|
when (_icon) {
|
||||||
is DynamicLauncherIcon -> null
|
is DynamicLauncherIcon -> null
|
||||||
is StaticLauncherIcon -> icon
|
is StaticLauncherIcon -> _icon
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon is DynamicLauncherIcon) {
|
if (_icon is DynamicLauncherIcon) {
|
||||||
val time = LocalTime.current
|
val time = LocalTime.current
|
||||||
LaunchedEffect(time) {
|
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(
|
Surface(
|
||||||
shadowElevation = 1.dp,
|
shadowElevation = 1.dp,
|
||||||
tonalElevation = 1.dp,
|
tonalElevation = 1.dp,
|
||||||
@ -134,7 +137,7 @@ fun ShapedLauncherIcon(
|
|||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
|
|
||||||
badge.progress?.let {
|
_badge.progress?.let {
|
||||||
val progress by animateFloatAsState(it)
|
val progress by animateFloatAsState(it)
|
||||||
CircularProgressIndicator(
|
CircularProgressIndicator(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@ -143,10 +146,10 @@ fun ShapedLauncherIcon(
|
|||||||
color = MaterialTheme.colorScheme.secondaryContainer
|
color = MaterialTheme.colorScheme.secondaryContainer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val badgeIconRes = badge.iconRes
|
val badgeIconRes = _badge.iconRes
|
||||||
val badgeIcon = badge.icon
|
val badgeIcon = _badge.icon
|
||||||
|
|
||||||
val number = badge.number
|
val number = _badge.number
|
||||||
if (badgeIconRes != null) {
|
if (badgeIconRes != null) {
|
||||||
Image(
|
Image(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -188,6 +191,13 @@ fun ShapedLauncherIcon(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun Badge(
|
||||||
|
badge: () -> Badge?
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun IconLayer(
|
private fun IconLayer(
|
||||||
layer: LauncherIconLayer,
|
layer: LauncherIconLayer,
|
||||||
|
|||||||
@ -169,8 +169,8 @@ fun AppItem(
|
|||||||
size = 84.dp,
|
size = 84.dp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
badge = badge,
|
badge = { badge },
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -87,10 +87,12 @@ fun CustomizeSearchableSheet(
|
|||||||
|
|
||||||
ShapedLauncherIcon(
|
ShapedLauncherIcon(
|
||||||
size = iconSize,
|
size = iconSize,
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
badge = Badge(
|
badge = {
|
||||||
icon = badgeDrawable
|
Badge(
|
||||||
),
|
icon = badgeDrawable
|
||||||
|
)
|
||||||
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
viewModel.openIconPicker()
|
viewModel.openIconPicker()
|
||||||
}
|
}
|
||||||
@ -239,7 +241,7 @@ fun IconPreview(
|
|||||||
) {
|
) {
|
||||||
ShapedLauncherIcon(
|
ShapedLauncherIcon(
|
||||||
size = iconSize,
|
size = iconSize,
|
||||||
icon = item?.preview,
|
icon = { item?.preview },
|
||||||
onClick = onClick
|
onClick = onClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,8 +82,8 @@ fun GridItem(modifier: Modifier = Modifier, item: Searchable, showLabels: Boolea
|
|||||||
bounds = it.boundsInWindow()
|
bounds = it.boundsInWindow()
|
||||||
},
|
},
|
||||||
size = LocalGridIconSize.current,
|
size = LocalGridIconSize.current,
|
||||||
badge = badge,
|
badge = { badge },
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
onClick = {
|
onClick = {
|
||||||
if (!launchOnPress || !viewModel.launch(context, bounds)) {
|
if (!launchOnPress || !viewModel.launch(context, bounds)) {
|
||||||
showPopup = true
|
showPopup = true
|
||||||
|
|||||||
@ -70,7 +70,7 @@ fun ContactItem(
|
|||||||
size = 48.dp,
|
size = 48.dp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(start = padding, top = padding, bottom = padding),
|
.padding(start = padding, top = padding, bottom = padding),
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
)
|
)
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(horizontal = 16.dp)
|
modifier = Modifier.padding(horizontal = 16.dp)
|
||||||
|
|||||||
@ -132,8 +132,8 @@ fun FileItem(
|
|||||||
size = 48.dp,
|
size = 48.dp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(end = padding, top = padding, bottom = padding),
|
.padding(end = padding, top = padding, bottom = padding),
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
badge = badge
|
badge = { badge }
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,8 +93,8 @@ fun AppShortcutItem(
|
|||||||
size = size,
|
size = size,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(padding),
|
.padding(padding),
|
||||||
badge = badge,
|
badge = { badge },
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -408,22 +408,25 @@ fun IconShapePreference(
|
|||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
ShapedLauncherIcon(
|
ShapedLauncherIcon(
|
||||||
size = 48.dp,
|
size = 48.dp,
|
||||||
icon = StaticLauncherIcon(
|
icon = {
|
||||||
foregroundLayer = StaticIconLayer(
|
StaticLauncherIcon(
|
||||||
icon = ContextCompat.getDrawable(
|
foregroundLayer = StaticIconLayer(
|
||||||
LocalContext.current,
|
icon = ContextCompat.getDrawable(
|
||||||
R.mipmap.ic_launcher_foreground
|
context,
|
||||||
)!!,
|
R.mipmap.ic_launcher_foreground
|
||||||
scale = 1.5f,
|
)!!,
|
||||||
),
|
scale = 1.5f,
|
||||||
backgroundLayer = StaticIconLayer(
|
),
|
||||||
icon = ColorDrawable(
|
backgroundLayer = StaticIconLayer(
|
||||||
LocalContext.current.getColor(R.color.ic_launcher_background)
|
icon = ColorDrawable(
|
||||||
|
context.getColor(R.color.ic_launcher_background)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
onValueChanged(it)
|
onValueChanged(it)
|
||||||
showDialog = false
|
showDialog = false
|
||||||
|
|||||||
@ -186,7 +186,7 @@ fun HiddenItem(
|
|||||||
) {
|
) {
|
||||||
ShapedLauncherIcon(
|
ShapedLauncherIcon(
|
||||||
size = 32.dp,
|
size = 32.dp,
|
||||||
icon = icon,
|
icon = { icon },
|
||||||
modifier = Modifier.padding(end = 16.dp)
|
modifier = Modifier.padding(end = 16.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user