Split the view in 3 columns instead of only 1
parent
0507bbf4c7
commit
7f67e3e4b7
|
|
@ -4,10 +4,15 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||||
|
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||||
|
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||||
|
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material.icons.filled.Settings
|
import androidx.compose.material.icons.filled.Settings
|
||||||
|
|
@ -56,6 +61,8 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
var openTagFilterDialog by remember { mutableStateOf(false) }
|
var openTagFilterDialog by remember { mutableStateOf(false) }
|
||||||
var selectedEntries by remember { mutableStateOf(listOf<RecipeWithTags>()) }
|
var selectedEntries by remember { mutableStateOf(listOf<RecipeWithTags>()) }
|
||||||
|
|
||||||
|
val gridState = rememberLazyStaggeredGridState()
|
||||||
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = "list"
|
startDestination = "list"
|
||||||
|
|
@ -129,7 +136,13 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LazyColumn {
|
LazyVerticalStaggeredGrid(
|
||||||
|
columns = StaggeredGridCells.Fixed(3),
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalItemSpacing = 8.dp,
|
||||||
|
state = gridState,
|
||||||
|
) {
|
||||||
items(activeRecipes) { entry ->
|
items(activeRecipes) { entry ->
|
||||||
val isSelected = selectedEntries.contains(entry)
|
val isSelected = selectedEntries.contains(entry)
|
||||||
RecipePreview(entry, isSelected, onClick = {
|
RecipePreview(entry, isSelected, onClick = {
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
|
@ -22,6 +22,7 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ImageBitmap
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
|
|
@ -32,7 +33,6 @@ import androidx.compose.ui.res.imageResource
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.em
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import xyz.pixelatedw.recipe.R
|
import xyz.pixelatedw.recipe.R
|
||||||
import xyz.pixelatedw.recipe.data.RecipeWithTags
|
import xyz.pixelatedw.recipe.data.RecipeWithTags
|
||||||
|
|
@ -58,17 +58,15 @@ fun RecipePreview(
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(color = if (isSelected) Color(0x11FF0000) else Color(0x00FFFFFF))
|
.background(color = if (isSelected) Color(0x11FF0000) else Color(0x00FFFFFF))
|
||||||
.padding(8.dp)
|
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
onLongClick = { onSelected(!isSelected) },
|
onLongClick = { onSelected(!isSelected) },
|
||||||
onClick = onClick
|
onClick = onClick
|
||||||
)
|
)
|
||||||
|
.height(192.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
modifier = Modifier
|
modifier = Modifier.weight(0.7f)
|
||||||
.fillMaxWidth()
|
|
||||||
.height(256.dp)
|
|
||||||
) {
|
) {
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
displayImageId,
|
displayImageId,
|
||||||
|
|
@ -83,47 +81,42 @@ fun RecipePreview(
|
||||||
Image(
|
Image(
|
||||||
bitmap = displayImage.asImageBitmap(),
|
bitmap = displayImage.asImageBitmap(),
|
||||||
contentDescription = "Recipe image",
|
contentDescription = "Recipe image",
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.FillHeight,
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize(),
|
||||||
.size(256.dp)
|
|
||||||
.padding(top = 16.dp, bottom = 8.dp),
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Image(
|
Image(
|
||||||
bitmap = ImageBitmap.imageResource(R.drawable.missing_image),
|
bitmap = ImageBitmap.imageResource(R.drawable.missing_image),
|
||||||
contentDescription = "Missing recipe image",
|
contentDescription = "Missing recipe image",
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.FillWidth,
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize(),
|
||||||
.size(256.dp)
|
|
||||||
.padding(top = 16.dp, bottom = 8.dp),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
modifier = Modifier
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth().weight(0.2f)
|
||||||
.padding(bottom = 8.dp)
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = entry.recipe.title,
|
text = entry.recipe.title,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
style = TextStyle(
|
style = TextStyle(
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
fontSize = 7.em,
|
// fontSize = 7.em,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Row(
|
// Row(
|
||||||
horizontalArrangement = Arrangement.End,
|
// horizontalArrangement = Arrangement.End,
|
||||||
modifier = Modifier
|
// modifier = Modifier
|
||||||
.fillMaxWidth()
|
// .weight(0.15f)
|
||||||
.padding(bottom = 16.dp)
|
// .fillMaxWidth()
|
||||||
) {
|
// ) {
|
||||||
for (tag in entry.tags) {
|
// for (tag in entry.tags) {
|
||||||
Tag(tag)
|
// Tag(tag)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,20 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import xyz.pixelatedw.recipe.data.Tag
|
import xyz.pixelatedw.recipe.data.Tag
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Tag(tag: Tag) {
|
fun Tag(tag: Tag) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(start = 8.dp)
|
.padding(start = 4.dp)
|
||||||
.clip(RoundedCornerShape(percent = 50))
|
.clip(RoundedCornerShape(percent = 25))
|
||||||
.background(Color(0, 153, 170))
|
.background(Color(0, 153, 170))
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.padding(start = 8.dp, end = 8.dp),
|
modifier = Modifier.padding(start = 4.dp, end = 4.dp),
|
||||||
|
fontSize = 12.sp,
|
||||||
text = tag.name
|
text = tag.name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue