Menghilangkan Fitur Tahan Untuk Hapus Pada Kategori Dan Catatan

This commit is contained in:
202310715051 DENDI YOGIA PRATAMA 2025-12-13 02:45:00 +07:00
parent 14bf2f2f24
commit 220381dc21

View File

@ -52,6 +52,7 @@ import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.outlined.StarBorder
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.zIndex
@ -114,7 +115,7 @@ class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NotesApp() {
val context = androidx.compose.ui.platform.LocalContext.current
val context = LocalContext.current
val dataStoreManager = remember { DataStoreManager(context) }
val scope = rememberCoroutineScope()
@ -155,7 +156,7 @@ fun NotesApp() {
// Simpan categories dengan debounce
LaunchedEffect(categories.size) {
if (categories.isNotEmpty()) {
kotlinx.coroutines.delay(500)
delay(500)
try {
dataStoreManager.saveCategories(categories)
} catch (e: Exception) {
@ -167,7 +168,7 @@ fun NotesApp() {
// Simpan notes dengan debounce
LaunchedEffect(notes.size) {
if (notes.isNotEmpty()) {
kotlinx.coroutines.delay(500)
delay(500)
try {
dataStoreManager.saveNotes(notes)
} catch (e: Exception) {
@ -311,19 +312,13 @@ fun NotesApp() {
fullScreenNote = note
showFullScreenNote = true
},
onNoteLongClick = { note ->
notes = notes.map {
if (it.id == note.id) it.copy(isArchived = true)
else it
}
},
onPinToggle = { note ->
notes = notes.map {
if (it.id == note.id) it.copy(isPinned = !it.isPinned)
else it
}
},
onCategoryLongClick = { category ->
onCategoryDelete = { category ->
// Delete kategori dan semua catatan di dalamnya
categories = categories.filter { it.id != category.id }
notes = notes.filter { it.categoryId != category.id }
@ -824,9 +819,8 @@ fun MainScreen(
searchQuery: String,
onCategoryClick: (Category) -> Unit,
onNoteClick: (Note) -> Unit,
onNoteLongClick: (Note) -> Unit,
onPinToggle: (Note) -> Unit,
onCategoryLongClick: (Category) -> Unit
onCategoryDelete: (Category) -> Unit
) {
Column(modifier = Modifier.fillMaxSize()) {
if (selectedCategory == null) {
@ -866,10 +860,8 @@ fun MainScreen(
category = category,
noteCount = notes.count { it.categoryId == category.id && !it.isDeleted && !it.isArchived },
onClick = { onCategoryClick(category) },
onLongClick = { onCategoryLongClick(category) },
onDelete = {
// Delete kategori dan semua catatan di dalamnya
onCategoryLongClick(category)
onCategoryDelete(category)
}
)
}
@ -906,8 +898,7 @@ fun MainScreen(
NoteCard(
note = note,
onClick = { onNoteClick(note) },
onLongClick = { onNoteLongClick(note) },
onPinClick = { onPinToggle(note) }
onPinClick = { onPinToggle(note) },
)
}
}
@ -922,7 +913,6 @@ fun CategoryCard(
category: Category,
noteCount: Int,
onClick: () -> Unit,
onLongClick: () -> Unit,
onDelete: () -> Unit = {}
) {
var showDeleteConfirm by remember { mutableStateOf(false) }
@ -931,9 +921,9 @@ fun CategoryCard(
if (showDeleteConfirm) {
AlertDialog(
onDismissRequest = { showDeleteConfirm = false },
title = { Text("Hapus Kategori?") },
title = { Text("Hapus Kategori?", color = Color.White) },
text = {
Text("Kategori '$${category.name}' dan semua catatan di dalamnya akan dihapus. Tindakan ini tidak dapat dibatalkan.")
Text("Kategori '${category.name}' dan semua catatan di dalamnya akan dihapus. Tindakan ini tidak dapat dibatalkan.", color = Color.White)
},
confirmButton = {
Button(
@ -957,17 +947,15 @@ fun CategoryCard(
) {
Text("Batal", color = Color.White)
}
}
},
containerColor = Color(0xFF1E293B)
)
}
Card(
modifier = Modifier
.fillMaxWidth()
.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
),
.clickable(onClick = onClick),
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(containerColor = Color.Transparent),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp)
@ -1009,7 +997,9 @@ fun CategoryCard(
// Delete button di top-right corner
IconButton(
onClick = { showDeleteConfirm = true },
onClick = {
showDeleteConfirm = true
},
modifier = Modifier
.align(Alignment.TopEnd)
.size(40.dp)
@ -1030,7 +1020,6 @@ fun CategoryCard(
fun NoteCard(
note: Note,
onClick: () -> Unit,
onLongClick: () -> Unit,
onPinClick: () -> Unit
) {
val dateFormat = SimpleDateFormat("dd MMM, HH:mm", Locale("id", "ID"))
@ -1040,7 +1029,6 @@ fun NoteCard(
.fillMaxWidth()
.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(