Menyesuaikan Note Card pada Catatan berbintang, arsip, dan sampah
This commit is contained in:
parent
9d6ba5d63d
commit
2e3cb39244
@ -20,7 +20,8 @@ data class SerializableNote(
|
||||
val id: String,
|
||||
val categoryId: String,
|
||||
val title: String,
|
||||
val content: String,
|
||||
val description: String = "",
|
||||
val content: String = "",
|
||||
val timestamp: Long,
|
||||
val isArchived: Boolean,
|
||||
val isDeleted: Boolean,
|
||||
@ -35,7 +36,7 @@ fun Category.toSerializable() = SerializableCategory(
|
||||
gradientEnd = gradientEnd,
|
||||
timestamp = timestamp,
|
||||
isDeleted = isDeleted,
|
||||
isPinned = isPinned // NEW: Tambahkan ini
|
||||
isPinned = isPinned
|
||||
)
|
||||
|
||||
fun SerializableCategory.toCategory() = Category(
|
||||
@ -45,13 +46,14 @@ fun SerializableCategory.toCategory() = Category(
|
||||
gradientEnd = gradientEnd,
|
||||
timestamp = timestamp,
|
||||
isDeleted = isDeleted,
|
||||
isPinned = isPinned // NEW: Tambahkan ini
|
||||
isPinned = isPinned
|
||||
)
|
||||
|
||||
fun Note.toSerializable() = SerializableNote(
|
||||
id = id,
|
||||
categoryId = categoryId,
|
||||
title = title,
|
||||
description = description,
|
||||
content = content,
|
||||
timestamp = timestamp,
|
||||
isArchived = isArchived,
|
||||
@ -63,6 +65,7 @@ fun SerializableNote.toNote() = Note(
|
||||
id = id,
|
||||
categoryId = categoryId,
|
||||
title = title,
|
||||
description = description,
|
||||
content = content,
|
||||
timestamp = timestamp,
|
||||
isArchived = isArchived,
|
||||
|
||||
@ -25,6 +25,24 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.notesai.data.model.Note
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
// Helper function untuk extract plain text dari AnnotatedString JSON
|
||||
private fun extractPlainText(jsonContent: String): String {
|
||||
return try {
|
||||
if (jsonContent.trim().startsWith("{")) {
|
||||
val jsonElement = Json.parseToJsonElement(jsonContent)
|
||||
val jsonObject = jsonElement.jsonObject
|
||||
jsonObject["text"]?.jsonPrimitive?.content ?: ""
|
||||
} else {
|
||||
jsonContent
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
jsonContent
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ArchiveNoteCard(
|
||||
@ -33,6 +51,12 @@ fun ArchiveNoteCard(
|
||||
onRestore: () -> Unit,
|
||||
onDelete: () -> Unit
|
||||
) {
|
||||
val displayContent = if (note.description.isNotEmpty()) {
|
||||
note.description
|
||||
} else {
|
||||
extractPlainText(note.content)
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
@ -62,10 +86,10 @@ fun ArchiveNoteCard(
|
||||
}
|
||||
}
|
||||
|
||||
if (note.content.isNotEmpty()) {
|
||||
if (displayContent.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
note.content,
|
||||
displayContent,
|
||||
maxLines = 2,
|
||||
color = Color(0xFF94A3B8),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
|
||||
@ -146,14 +146,23 @@ fun EditableFullScreenNoteView(
|
||||
Icon(
|
||||
if (note.isPinned) Icons.Filled.Star
|
||||
else Icons.Outlined.StarBorder,
|
||||
null
|
||||
contentDescription = null,
|
||||
tint = if (note.isPinned) Color(0xFFFFB300) else MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onArchive) {
|
||||
Icon(Icons.Default.Archive, null)
|
||||
Icon(
|
||||
Icons.Default.Archive,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFF4CAF50)
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onDelete) {
|
||||
Icon(Icons.Default.Delete, null)
|
||||
Icon(
|
||||
Icons.Default.Delete,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFFF44336)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@ -29,6 +29,27 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.notesai.data.model.Note
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
// Helper function untuk extract plain text dari AnnotatedString JSON
|
||||
private fun extractPlainText(jsonContent: String): String {
|
||||
return try {
|
||||
if (jsonContent.trim().startsWith("{")) {
|
||||
val jsonElement = Json.parseToJsonElement(jsonContent)
|
||||
val jsonObject = jsonElement.jsonObject
|
||||
|
||||
// Extract field "text" yang berisi plain text content
|
||||
jsonObject["text"]?.jsonPrimitive?.content ?: ""
|
||||
} else {
|
||||
jsonContent
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Jika parsing gagal, coba tampilkan content mentah
|
||||
jsonContent
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun StarredNoteCard(
|
||||
@ -37,8 +58,15 @@ fun StarredNoteCard(
|
||||
onClick: () -> Unit,
|
||||
onUnpin: () -> Unit
|
||||
) {
|
||||
// Gunakan description jika ada, jika tidak extract dari content JSON
|
||||
val displayContent = if (note.description.isNotEmpty()) {
|
||||
note.description
|
||||
} else {
|
||||
extractPlainText(note.content)
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier.Companion
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
@ -47,31 +75,31 @@ fun StarredNoteCard(
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||
) {
|
||||
Column(modifier = Modifier.Companion.padding(16.dp)) {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.Companion.fillMaxWidth(),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.Companion.Top
|
||||
verticalAlignment = Alignment.Top
|
||||
) {
|
||||
Column(modifier = Modifier.Companion.weight(1f)) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.Companion.CenterVertically
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.Star,
|
||||
contentDescription = null,
|
||||
tint = Color(0xFFFBBF24),
|
||||
modifier = Modifier.Companion.size(16.dp)
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.Companion.width(8.dp))
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
note.title,
|
||||
fontWeight = FontWeight.Companion.Bold,
|
||||
color = Color.Companion.White,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.Companion.height(4.dp))
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
categoryName,
|
||||
color = Color(0xFF64748B),
|
||||
@ -80,19 +108,19 @@ fun StarredNoteCard(
|
||||
}
|
||||
}
|
||||
|
||||
if (note.content.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.Companion.height(8.dp))
|
||||
if (displayContent.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
note.content,
|
||||
displayContent,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Companion.Ellipsis,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = Color(0xFF94A3B8),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.Companion
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 12.dp),
|
||||
horizontalArrangement = Arrangement.End
|
||||
@ -101,29 +129,29 @@ fun StarredNoteCard(
|
||||
Icon(
|
||||
Icons.Default.Info,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.Companion.size(18.dp),
|
||||
modifier = Modifier.size(18.dp),
|
||||
tint = Color(0xFF6366F1)
|
||||
)
|
||||
Spacer(modifier = Modifier.Companion.width(4.dp))
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Text(
|
||||
"Lihat Detail",
|
||||
color = Color(0xFF6366F1),
|
||||
fontWeight = FontWeight.Companion.Bold
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.Companion.width(8.dp))
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
TextButton(onClick = onUnpin) {
|
||||
Icon(
|
||||
Icons.Outlined.StarBorder,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.Companion.size(18.dp),
|
||||
modifier = Modifier.size(18.dp),
|
||||
tint = Color(0xFFFBBF24)
|
||||
)
|
||||
Spacer(modifier = Modifier.Companion.width(4.dp))
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Text(
|
||||
"Hapus Bintang",
|
||||
color = Color(0xFFFBBF24),
|
||||
fontWeight = FontWeight.Companion.Bold
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,24 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.notesai.data.model.Note
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
// Helper function untuk extract plain text dari AnnotatedString JSON
|
||||
private fun extractPlainText(jsonContent: String): String {
|
||||
return try {
|
||||
if (jsonContent.trim().startsWith("{")) {
|
||||
val jsonElement = Json.parseToJsonElement(jsonContent)
|
||||
val jsonObject = jsonElement.jsonObject
|
||||
jsonObject["text"]?.jsonPrimitive?.content ?: ""
|
||||
} else {
|
||||
jsonContent
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
jsonContent
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TrashNoteCard(
|
||||
@ -33,6 +51,12 @@ fun TrashNoteCard(
|
||||
onRestore: () -> Unit,
|
||||
onDeletePermanent: () -> Unit
|
||||
) {
|
||||
val displayContent = if (note.description.isNotEmpty()) {
|
||||
note.description
|
||||
} else {
|
||||
extractPlainText(note.content)
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
@ -62,10 +86,10 @@ fun TrashNoteCard(
|
||||
}
|
||||
}
|
||||
|
||||
if (note.content.isNotEmpty()) {
|
||||
if (displayContent.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
note.content,
|
||||
displayContent,
|
||||
maxLines = 2,
|
||||
color = Color(0xFF94A3B8),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user