Bunch of style updates

master
Wynd 2025-08-08 21:14:55 +03:00
parent 680658fd86
commit 968691a8fe
1 changed files with 43 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package xyz.pixelatedw.recipe package xyz.pixelatedw.recipe
import android.content.Intent import android.content.Intent
import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
@ -10,11 +11,14 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
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.Spacer
import androidx.compose.foundation.layout.fillMaxSize 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
@ -22,6 +26,7 @@ import androidx.compose.foundation.layout.size
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.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
@ -68,11 +73,15 @@ import xyz.pixelatedw.recipe.ui.theme.RecipeTheme
import java.io.BufferedReader import java.io.BufferedReader
import java.io.InputStreamReader import java.io.InputStreamReader
import androidx.compose.material3.Typography 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.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
private val recipeView: RecipesView by viewModels() private val recipeView: RecipesView by viewModels()
@ -240,9 +249,16 @@ fun RecipeList(padding: PaddingValues, view: RecipesView) {
) )
} }
val annotatedString = Box(
parseMarkdown(active.value!!.content, MaterialTheme.typography) modifier = Modifier.fillMaxWidth()
Text(text = annotatedString) ) {
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( Image(
painter = painterResource(R.drawable.ic_launcher_background), painter = painterResource(R.drawable.ic_launcher_background),
contentDescription = "Recipe image", 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()) { 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) { for (tag in recipe.tags) {
Text( Box(
text = tag, modifier = Modifier
modifier = Modifier.padding(start = 8.dp) .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 -> { is ListItem -> {
if (node.parents.any { it is BulletList }) { withStyle(ParagraphStyle(lineHeight = 18.sp)) {
append("") if (node.parents.any { it is BulletList }) {
} else if (node.parents.any { it is OrderedList }) { append("")
val startNumber = (node.parents.first { it is OrderedList } as OrderedList).markerStartNumber } else if (node.parents.any { it is OrderedList }) {
val index = startNumber + node.previousSiblings.filterIsInstance<ListItem>().size val startNumber = (node.parents.first { it is OrderedList } as OrderedList).markerStartNumber
append("$index. ") val index = startNumber + node.previousSiblings.filterIsInstance<ListItem>().size
append("$index. ")
}
visitChildren(node, typography)
appendLine()
} }
visitChildren(node, typography)
appendLine()
} }
is Document -> { is Document -> {
visitChildren(node, typography) visitChildren(node, typography)