Skip to content

Commit 0d6c68d

Browse files
committed
add markdown preview in the note screen
1 parent db2eec9 commit 0d6c68d

5 files changed

Lines changed: 66 additions & 26 deletions

File tree

.idea/workspace.xml

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/opennotes/feature_node/presentation/MainActivity.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
66
import androidx.activity.viewModels
7-
import androidx.compose.animation.ExperimentalAnimationApi
7+
import androidx.compose.animation.EnterTransition
8+
import androidx.compose.animation.ExitTransition
89
import androidx.compose.material3.MaterialTheme
910
import androidx.compose.material3.Surface
1011
import androidx.compose.runtime.collectAsState
@@ -29,7 +30,6 @@ class MainActivity : ComponentActivity() {
2930

3031
private val settingsViewModel: SettingsViewModel by viewModels()
3132

32-
@OptIn(ExperimentalAnimationApi::class)
3333
override fun onCreate(savedInstanceState: Bundle?) {
3434
val splashScreen = installSplashScreen()
3535
super.onCreate(savedInstanceState)
@@ -48,7 +48,10 @@ class MainActivity : ComponentActivity() {
4848
NavHost(
4949
navController = navController,
5050
startDestination = Screen.NotesScreen.route,
51-
51+
enterTransition = { EnterTransition.None },
52+
exitTransition = { ExitTransition.None },
53+
popEnterTransition = { EnterTransition.None },
54+
popExitTransition = { ExitTransition.None }
5255
) {
5356
composable(route = Screen.NotesScreen.route) {
5457
NotesScreen(navController = navController)

app/src/main/java/com/opennotes/feature_node/presentation/add_edit_note/AddEditNoteScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ fun AddEditNoteScreen(
229229
textStyle = MaterialTheme.typography.bodyLarge.copy(color = contentColor),
230230
singleLine = false,
231231
focusRequester = contentFocusRequester,
232-
modifier = Modifier.fillMaxWidth()
232+
modifier = Modifier
233+
.fillMaxWidth()
234+
.wrapContentHeight(unbounded = true)
233235
)
234236
}
235237
}

app/src/main/java/com/opennotes/feature_node/presentation/notes/Components/NoteItem.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import androidx.compose.ui.graphics.Color
1515
import androidx.compose.ui.graphics.luminance
1616
import androidx.compose.ui.text.font.FontWeight
1717
import androidx.compose.ui.text.style.TextOverflow
18+
1819
import androidx.compose.ui.unit.Dp
1920
import androidx.compose.ui.unit.dp
2021
import androidx.compose.ui.unit.sp
2122
import com.opennotes.feature_node.domain.model.Note
23+
import com.opennotes.feature_node.presentation.add_edit_note.components.markdown.MarkdownText
2224

2325
@Composable
2426
fun NoteItem(
@@ -79,12 +81,17 @@ fun NoteItem(
7981
Spacer(modifier = Modifier.height(8.dp))
8082
}
8183
if (note.content.isNotBlank()) {
82-
Text(
83-
text = note.content,
84+
MarkdownText(
85+
radius = cornerRadius.value.toInt(),
86+
markdown = note.content,
87+
isPreview = true,
88+
isEnabled = true,
89+
modifier = Modifier
90+
.fillMaxWidth()
91+
.heightIn(max = 180.dp),
8492
fontSize = 14.sp,
85-
maxLines = 8,
86-
overflow = TextOverflow.Ellipsis,
87-
color = textColor
93+
spacing = 1.dp,
94+
textColor = textColor
8895
)
8996
}
9097
}

app/src/main/java/com/opennotes/feature_node/presentation/notes/NotesScreen.kt

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import androidx.compose.material.icons.filled.Search
1111
import androidx.compose.material.icons.filled.Settings
1212
import androidx.compose.material3.*
1313
import androidx.compose.runtime.*
14+
import androidx.compose.ui.text.font.FontWeight
1415
import androidx.compose.ui.Modifier
1516
import androidx.compose.ui.graphics.Color
1617
import androidx.compose.ui.unit.dp
1718
import androidx.hilt.navigation.compose.hiltViewModel
1819
import androidx.navigation.NavController
20+
import com.opennotes.feature_node.domain.model.Note
1921
import com.opennotes.feature_node.presentation.notes.Components.NoteItem
2022
import com.opennotes.feature_node.presentation.util.Screen
2123
import kotlinx.coroutines.launch
@@ -28,6 +30,47 @@ fun NotesScreen(
2830
val state = viewModel.state.value
2931
val snackbarHostState = remember { SnackbarHostState() }
3032
val scope = rememberCoroutineScope()
33+
val notePendingDeleteState = remember { mutableStateOf<Note?>(null) }
34+
35+
notePendingDeleteState.value?.let { noteToDelete ->
36+
AlertDialog(
37+
onDismissRequest = { notePendingDeleteState.value = null },
38+
title = {
39+
Text(
40+
text = "Delete note?",
41+
fontWeight = FontWeight.SemiBold
42+
)
43+
},
44+
text = {
45+
Text("This action cannot be undone.")
46+
},
47+
confirmButton = {
48+
TextButton(
49+
onClick = {
50+
notePendingDeleteState.value = null
51+
viewModel.onEvent(NotesEvent.DeleteNote(noteToDelete))
52+
scope.launch {
53+
val result = snackbarHostState.showSnackbar(
54+
message = "Note deleted",
55+
actionLabel = "Undo",
56+
duration = SnackbarDuration.Short
57+
)
58+
if (result == SnackbarResult.ActionPerformed) {
59+
viewModel.onEvent(NotesEvent.RestoreNote)
60+
}
61+
}
62+
}
63+
) {
64+
Text("Delete")
65+
}
66+
},
67+
dismissButton = {
68+
TextButton(onClick = { notePendingDeleteState.value = null }) {
69+
Text("Cancel")
70+
}
71+
}
72+
)
73+
}
3174

3275
Scaffold(
3376
snackbarHost = { SnackbarHost(snackbarHostState) },
@@ -133,17 +176,7 @@ fun NotesScreen(
133176
)
134177
},
135178
onDeleteClick = {
136-
viewModel.onEvent(NotesEvent.DeleteNote(note))
137-
scope.launch {
138-
val result = snackbarHostState.showSnackbar(
139-
message = "Note deleted",
140-
actionLabel = "Undo",
141-
duration = SnackbarDuration.Short
142-
)
143-
if (result == SnackbarResult.ActionPerformed) {
144-
viewModel.onEvent(NotesEvent.RestoreNote)
145-
}
146-
}
179+
notePendingDeleteState.value = note
147180
}
148181
)
149182
}

0 commit comments

Comments
 (0)