|
|
|
@ -8,8 +8,6 @@ import androidx.compose.foundation.Canvas
|
|
|
|
|
import androidx.compose.foundation.Image
|
|
|
|
|
import androidx.compose.foundation.ScrollState
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.BoxScope
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
@ -32,7 +30,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|
|
|
|
import androidx.compose.foundation.lazy.itemsIndexed
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
import androidx.compose.foundation.text.BasicTextField
|
|
|
|
|
import androidx.compose.material.ripple.rememberRipple
|
|
|
|
|
import androidx.compose.material3.ButtonColors
|
|
|
|
|
import androidx.compose.material3.Card
|
|
|
|
|
import androidx.compose.material3.HorizontalDivider
|
|
|
|
@ -43,7 +40,6 @@ import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.material3.TextButton
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
@ -65,13 +61,9 @@ import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.semantics.contentDescription
|
|
|
|
|
import androidx.compose.ui.semantics.semantics
|
|
|
|
|
import androidx.compose.ui.text.TextStyle
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.Dp
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.compose.ui.viewinterop.AndroidView
|
|
|
|
|
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
@ -97,7 +89,7 @@ interface Callbacks<in T> {
|
|
|
|
|
fun setValue(value: T)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object NoOpCallbacks : Callbacks<Any> {
|
|
|
|
|
object NoOpCallbacks: Callbacks<Any> {
|
|
|
|
|
override fun onSetClick() {}
|
|
|
|
|
override fun setValue(value: Any) {}
|
|
|
|
|
}
|
|
|
|
@ -166,12 +158,7 @@ fun ItemButtonWithDrawable(
|
|
|
|
|
modifier = modifier,
|
|
|
|
|
icon = {
|
|
|
|
|
Image(
|
|
|
|
|
painter = rememberDrawablePainter(
|
|
|
|
|
drawable = AppCompatResources.getDrawable(
|
|
|
|
|
context,
|
|
|
|
|
icon
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
painter = rememberDrawablePainter(drawable = AppCompatResources.getDrawable(context, icon)),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
modifier = Modifier.align(Alignment.Center)
|
|
|
|
|
)
|
|
|
|
@ -278,10 +265,10 @@ fun ItemButton(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base [ItemButton] implementation.
|
|
|
|
|
* Base [ItemButton] implementation.
|
|
|
|
|
*
|
|
|
|
|
* A button to be used in a list of buttons, usually in a [Cell] or [Card]
|
|
|
|
|
*/
|
|
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
fun ItemButton(
|
|
|
|
|
text: String,
|
|
|
|
@ -573,148 +560,3 @@ fun SearchBar(
|
|
|
|
|
cursorBrush = SolidColor(LocalColors.current.text)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun NavigationBar(
|
|
|
|
|
title: String,
|
|
|
|
|
titleAlignment: Alignment = Alignment.Center,
|
|
|
|
|
onBack: (() -> Unit)? = null,
|
|
|
|
|
actionElement: (@Composable BoxScope.() -> Unit)? = null
|
|
|
|
|
) {
|
|
|
|
|
Row(
|
|
|
|
|
Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.height(64.dp)
|
|
|
|
|
) {
|
|
|
|
|
// Optional back button, layout should still take up space
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxHeight()
|
|
|
|
|
.aspectRatio(1.0f, true)
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
) {
|
|
|
|
|
if (onBack != null) {
|
|
|
|
|
Icon(
|
|
|
|
|
painter = painterResource(id = R.drawable.ic_arrow_back_24),
|
|
|
|
|
contentDescription = stringResource(
|
|
|
|
|
id = R.string.AccessibilityId_navigateBack
|
|
|
|
|
),
|
|
|
|
|
Modifier
|
|
|
|
|
.clickable(
|
|
|
|
|
interactionSource = remember { MutableInteractionSource() },
|
|
|
|
|
indication = rememberRipple(bounded = false, radius = 16.dp),
|
|
|
|
|
) { onBack() }
|
|
|
|
|
.align(Alignment.Center)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Main title
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxHeight()
|
|
|
|
|
.weight(1f)
|
|
|
|
|
.padding(8.dp)
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = title,
|
|
|
|
|
Modifier.align(titleAlignment),
|
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
|
fontSize = 26.sp,
|
|
|
|
|
fontWeight = FontWeight.Bold
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
// Optional action
|
|
|
|
|
if (actionElement != null) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxHeight()
|
|
|
|
|
.align(Alignment.CenterVertically)
|
|
|
|
|
.aspectRatio(1.0f, true),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
actionElement(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun BoxScope.CloseIcon(onClose: () -> Unit) {
|
|
|
|
|
Icon(
|
|
|
|
|
painter = painterResource(id = R.drawable.ic_baseline_close_24),
|
|
|
|
|
contentDescription = stringResource(
|
|
|
|
|
id = R.string.close
|
|
|
|
|
),
|
|
|
|
|
Modifier
|
|
|
|
|
.clickable { onClose() }
|
|
|
|
|
.align(Alignment.Center)
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun RowScope.WeightedOptionButton(
|
|
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
@StringRes label: Int,
|
|
|
|
|
destructive: Boolean = false,
|
|
|
|
|
weight: Float = 1f,
|
|
|
|
|
onClick: () -> Unit
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = stringResource(label),
|
|
|
|
|
modifier = modifier
|
|
|
|
|
.padding(16.dp)
|
|
|
|
|
.weight(weight)
|
|
|
|
|
.clickable {
|
|
|
|
|
onClick()
|
|
|
|
|
},
|
|
|
|
|
textAlign = TextAlign.Center,
|
|
|
|
|
fontSize = 16.sp,
|
|
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
|
|
color = if (destructive) LocalColors.current.danger else Color.Unspecified
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Preview
|
|
|
|
|
@Composable
|
|
|
|
|
fun PreviewWeightedOptionButtons() {
|
|
|
|
|
Column(modifier = Modifier.fillMaxWidth()) {
|
|
|
|
|
// two equal sized
|
|
|
|
|
Row(modifier = Modifier.fillMaxWidth()) {
|
|
|
|
|
WeightedOptionButton(label = R.string.ok) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
WeightedOptionButton(label = R.string.cancel, destructive = true) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// single left justified
|
|
|
|
|
Row(modifier = Modifier.fillMaxWidth()) {
|
|
|
|
|
WeightedOptionButton(label = R.string.cancel, destructive = true, weight = 1f) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// press F to pay respects to `android:weightSum`
|
|
|
|
|
Box(Modifier.weight(1f))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
@Preview
|
|
|
|
|
fun PreviewNavigationBar() {
|
|
|
|
|
NavigationBar(title = "Create Group", onBack = {}, actionElement = {
|
|
|
|
|
CloseIcon {}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
@Preview
|
|
|
|
|
fun PreviewSearchBar() {
|
|
|
|
|
PreviewTheme {
|
|
|
|
|
Column(Modifier.background(LocalColors.current.backgroundSecondary)) {
|
|
|
|
|
SearchBar("Search query", {})
|
|
|
|
|
SearchBar("", {}, placeholder = "Hint text")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|