|
|
|
|
@ -3,19 +3,25 @@ package org.tasks.compose
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
|
import androidx.compose.foundation.layout.defaultMinSize
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
|
import androidx.compose.material.*
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.outlined.Cancel
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
|
|
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.draw.alpha
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import com.google.android.material.composethemeadapter.MdcTheme
|
|
|
|
|
import org.tasks.R
|
|
|
|
|
import org.tasks.themes.CustomIcons
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
@ -27,12 +33,14 @@ fun Chip(
|
|
|
|
|
showIcon: Boolean,
|
|
|
|
|
onClick: () -> Unit,
|
|
|
|
|
colorProvider: (Int) -> Int,
|
|
|
|
|
clear: (() -> Unit)? = null,
|
|
|
|
|
) {
|
|
|
|
|
Chip(
|
|
|
|
|
color = Color(colorProvider(theme)),
|
|
|
|
|
text = if (showText) name else null,
|
|
|
|
|
icon = if (showIcon && icon != null) icon else null,
|
|
|
|
|
onClick = onClick,
|
|
|
|
|
clear = clear,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -43,11 +51,13 @@ fun Chip(
|
|
|
|
|
icon: Int? = null,
|
|
|
|
|
color: Color,
|
|
|
|
|
onClick: () -> Unit = {},
|
|
|
|
|
clear: (() -> Unit)? = null,
|
|
|
|
|
) {
|
|
|
|
|
CompositionLocalProvider(
|
|
|
|
|
LocalMinimumTouchTargetEnforcement provides false
|
|
|
|
|
) {
|
|
|
|
|
Chip(
|
|
|
|
|
FilterChip(
|
|
|
|
|
selected = false,
|
|
|
|
|
onClick = onClick,
|
|
|
|
|
border = BorderStroke(1.dp, color = color),
|
|
|
|
|
leadingIcon = {
|
|
|
|
|
@ -55,8 +65,20 @@ fun Chip(
|
|
|
|
|
ChipIcon(iconRes = icon)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
clear?.let { onClearClick ->
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Outlined.Cancel,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(16.dp)
|
|
|
|
|
.alpha(ContentAlpha.medium)
|
|
|
|
|
.clickable { onClearClick() },
|
|
|
|
|
contentDescription = stringResource(id = R.string.delete),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier.defaultMinSize(minHeight = 26.dp),
|
|
|
|
|
colors = ChipDefaults.chipColors(
|
|
|
|
|
colors = ChipDefaults.outlinedFilterChipColors(
|
|
|
|
|
backgroundColor = color.copy(alpha = .1f),
|
|
|
|
|
contentColor = MaterialTheme.colors.onSurface
|
|
|
|
|
),
|
|
|
|
|
@ -101,6 +123,21 @@ fun TasksChipIconAndTextPreview() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ExperimentalComposeUiApi
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
|
|
|
|
@Composable
|
|
|
|
|
fun TasksChipIconTextAndClearPreview() {
|
|
|
|
|
MdcTheme {
|
|
|
|
|
Chip(
|
|
|
|
|
text = "Home",
|
|
|
|
|
icon = CustomIcons.getIconResId(CustomIcons.LABEL),
|
|
|
|
|
color = Color.Red,
|
|
|
|
|
clear = {},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ExperimentalComposeUiApi
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
|
|
|
|
|