diff --git a/app/src/main/java/xyz/pixelatedw/recipe/MainActivity.kt b/app/src/main/java/xyz/pixelatedw/recipe/MainActivity.kt index 0506858..ec56190 100644 --- a/app/src/main/java/xyz/pixelatedw/recipe/MainActivity.kt +++ b/app/src/main/java/xyz/pixelatedw/recipe/MainActivity.kt @@ -1,6 +1,7 @@ package xyz.pixelatedw.recipe import android.content.Intent +import android.graphics.Color import android.net.Uri import android.os.Bundle import android.util.Log @@ -10,11 +11,14 @@ import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.compose.foundation.Image +import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -22,6 +26,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold @@ -68,11 +73,15 @@ import xyz.pixelatedw.recipe.ui.theme.RecipeTheme import java.io.BufferedReader import java.io.InputStreamReader import androidx.compose.material3.Typography +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Shadow +import androidx.compose.ui.text.style.LineBreak import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController - class MainActivity : ComponentActivity() { private val recipeView: RecipesView by viewModels() @@ -240,9 +249,16 @@ fun RecipeList(padding: PaddingValues, view: RecipesView) { ) } - val annotatedString = - parseMarkdown(active.value!!.content, MaterialTheme.typography) - Text(text = annotatedString) + Box( + modifier = Modifier.fillMaxWidth() + ) { + val annotatedString = + parseMarkdown(active.value!!.content, MaterialTheme.typography) + Text( + text = annotatedString, + modifier = Modifier.padding(16.dp), + ) + } } } } @@ -257,7 +273,7 @@ fun RecipePreview(recipe: Recipe, onClick: () -> Unit) { Image( painter = painterResource(R.drawable.ic_launcher_background), contentDescription = "Recipe image", - modifier = Modifier.size(256.dp) + modifier = Modifier.size(256.dp).padding(top = 16.dp, bottom = 16.dp) ) } Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) { @@ -270,12 +286,19 @@ fun RecipePreview(recipe: Recipe, onClick: () -> Unit) { ) ) } - Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) { + Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp)) { for (tag in recipe.tags) { - Text( - text = tag, - modifier = Modifier.padding(start = 8.dp) - ) + Box( + modifier = Modifier + .padding(start = 8.dp) + .clip(RoundedCornerShape(percent = 50)) + .background(androidx.compose.ui.graphics.Color(0, 153, 170)) + ) { + Text( + modifier = Modifier.padding(start = 8.dp, end = 8.dp), + text = tag + ) + } } } } @@ -379,15 +402,17 @@ private fun AnnotatedString.Builder.visitMarkdownNode( } } is ListItem -> { - if (node.parents.any { it is BulletList }) { - append("• ") - } else if (node.parents.any { it is OrderedList }) { - val startNumber = (node.parents.first { it is OrderedList } as OrderedList).markerStartNumber - val index = startNumber + node.previousSiblings.filterIsInstance().size - append("$index. ") + withStyle(ParagraphStyle(lineHeight = 18.sp)) { + if (node.parents.any { it is BulletList }) { + append("• ") + } else if (node.parents.any { it is OrderedList }) { + val startNumber = (node.parents.first { it is OrderedList } as OrderedList).markerStartNumber + val index = startNumber + node.previousSiblings.filterIsInstance().size + append("$index. ") + } + visitChildren(node, typography) + appendLine() } - visitChildren(node, typography) - appendLine() } is Document -> { visitChildren(node, typography)