Added navigation
parent
19e052c7b3
commit
680658fd86
|
@ -49,7 +49,7 @@ dependencies {
|
|||
implementation(libs.androidx.ui.tooling.preview)
|
||||
implementation(libs.androidx.material3)
|
||||
implementation(libs.androidx.documentfile)
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
|
@ -57,6 +57,10 @@ dependencies {
|
|||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
|
||||
implementation(libs.androidx.navigation.fragment)
|
||||
implementation(libs.androidx.navigation.navigation.ui)
|
||||
implementation(libs.androidx.navigation.navigation.compose)
|
||||
|
||||
implementation(libs.jtoml)
|
||||
implementation(libs.commonmark)
|
||||
}
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
package xyz.pixelatedw.recipe
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
@ -50,7 +44,6 @@ import androidx.compose.ui.text.withStyle
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.em
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.text.trimmedLength
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
@ -69,14 +62,15 @@ import org.commonmark.node.OrderedList
|
|||
import org.commonmark.node.Paragraph
|
||||
import org.commonmark.node.SoftLineBreak
|
||||
import org.commonmark.node.StrongEmphasis
|
||||
import org.commonmark.node.Text
|
||||
import org.commonmark.node.ThematicBreak
|
||||
import org.commonmark.parser.Parser
|
||||
import org.commonmark.renderer.html.HtmlRenderer
|
||||
import xyz.pixelatedw.recipe.ui.theme.RecipeTheme
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
@ -106,7 +100,7 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
|
||||
val getContent = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri ->
|
||||
getRecipes(uri)
|
||||
}
|
||||
|
@ -208,43 +202,57 @@ data class Recipe(
|
|||
val content: String
|
||||
)
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Composable
|
||||
fun RecipeList(padding: PaddingValues, view: RecipesView) {
|
||||
val recipes = view.recipes.collectAsState()
|
||||
val active = view.activeRecipe.collectAsState()
|
||||
|
||||
if (active.value == null) {
|
||||
LazyColumn(modifier = Modifier.padding(padding)) {
|
||||
items(recipes.value) { recipe ->
|
||||
RecipePreview(recipe, view)
|
||||
val navController = rememberNavController()
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = "list"
|
||||
) {
|
||||
composable("list") {
|
||||
LazyColumn(modifier = Modifier.padding(padding)) {
|
||||
items(recipes.value) { recipe ->
|
||||
RecipePreview(recipe, onClick = {
|
||||
view.setActive(recipe)
|
||||
navController.navigate("info")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Column(modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(padding)) {
|
||||
composable("info") {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(padding)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = active.value!!.title,
|
||||
style = MaterialTheme.typography.displayLarge,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
|
||||
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
text = active.value!!.title,
|
||||
style = MaterialTheme.typography.displayLarge,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
val annotatedString =
|
||||
parseMarkdown(active.value!!.content, MaterialTheme.typography)
|
||||
Text(text = annotatedString)
|
||||
}
|
||||
|
||||
val annotatedString = parseMarkdown(active.value!!.content, MaterialTheme.typography)
|
||||
Text(text = annotatedString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RecipePreview(recipe: Recipe, view: RecipesView) {
|
||||
fun RecipePreview(recipe: Recipe, onClick: () -> Unit) {
|
||||
Column(modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.clickable { view.setActive(recipe) }) {
|
||||
.clickable(onClick = onClick)) {
|
||||
Row(horizontalArrangement = Arrangement.Center, modifier = Modifier.fillMaxWidth()) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.ic_launcher_background),
|
||||
|
@ -343,7 +351,7 @@ private fun AnnotatedString.Builder.visitMarkdownNode(
|
|||
visitChildren(node, typography)
|
||||
}
|
||||
}
|
||||
is Text -> {
|
||||
is org.commonmark.node.Text -> {
|
||||
append(node.literal)
|
||||
visitChildren(node, typography)
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ junitVersion = "1.3.0"
|
|||
espressoCore = "3.7.0"
|
||||
lifecycleRuntimeKtx = "2.9.2"
|
||||
activityCompose = "1.10.1"
|
||||
composeBom = "2024.04.01"
|
||||
composeBom = "2025.07.00"
|
||||
documentfile = "1.1.0"
|
||||
commonmark = "0.25.1"
|
||||
navVersion = "2.9.3"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
|
@ -30,6 +31,9 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit
|
|||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
androidx-documentfile = { group = "androidx.documentfile", name = "documentfile", version.ref = "documentfile" }
|
||||
commonmark = { group = "org.commonmark", name = "commonmark", version.ref = "commonmark"}
|
||||
androidx-navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navVersion"}
|
||||
androidx-navigation-navigation-ui = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navVersion"}
|
||||
androidx-navigation-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navVersion"}
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
|
Loading…
Reference in New Issue