From 594ea0520678fb0b45e7ada2939928a6bfb966b7 Mon Sep 17 00:00:00 2001 From: Raihan Ariq <202310715297@mhs.ubharajaya.ac.id> Date: Sat, 13 Dec 2025 13:53:49 +0700 Subject: [PATCH] Migrasi Utilities --- .../com/example/notesai/util/Constants.kt | 53 +++++++++++++++++++ .../com/example/notesai/util/DateFormatter.kt | 42 +++++++++++++++ .../com/example/notesai/util/Extensions.kt | 27 ++++++++++ 3 files changed, 122 insertions(+) create mode 100644 app/src/main/java/com/example/notesai/util/Constants.kt create mode 100644 app/src/main/java/com/example/notesai/util/DateFormatter.kt create mode 100644 app/src/main/java/com/example/notesai/util/Extensions.kt diff --git a/app/src/main/java/com/example/notesai/util/Constants.kt b/app/src/main/java/com/example/notesai/util/Constants.kt new file mode 100644 index 0000000..4575ccb --- /dev/null +++ b/app/src/main/java/com/example/notesai/util/Constants.kt @@ -0,0 +1,53 @@ +// File: util/Constants.kt +package com.example.notesai.util + +import androidx.compose.ui.graphics.Color + +object Constants { + // App Info + const val APP_NAME = "AI Notes" + const val APP_VERSION = "1.0.0" + + // DataStore + const val DATASTORE_NAME = "notes_prefs" + const val DEBOUNCE_DELAY = 500L + + // UI Constants + const val MAX_NOTE_PREVIEW_LINES = 4 + const val MAX_CHAT_PREVIEW_LINES = 2 + const val GRID_COLUMNS = 2 + + // Gradients + val GRADIENT_PRESETS = listOf( + Pair(0xFF6366F1L, 0xFFA855F7L), + Pair(0xFFEC4899L, 0xFFF59E0BL), + Pair(0xFF8B5CF6L, 0xFFEC4899L), + Pair(0xFF06B6D4L, 0xFF3B82F6L), + Pair(0xFF10B981L, 0xFF059669L), + Pair(0xFFF59E0BL, 0xFFEF4444L), + Pair(0xFF6366F1L, 0xFF8B5CF6L), + Pair(0xFFEF4444L, 0xFFDC2626L) + ) + + // Colors + object AppColors { + val Primary = Color(0xFF6366F1) + val Secondary = Color(0xFFA855F7) + val Background = Color(0xFF0F172A) + val Surface = Color(0xFF1E293B) + val SurfaceVariant = Color(0xFF334155) + val OnBackground = Color(0xFFE2E8F0) + val OnSurface = Color(0xFFE2E8F0) + val Success = Color(0xFF10B981) + val Error = Color(0xFFEF4444) + val Warning = Color(0xFFFBBF24) + val TextSecondary = Color(0xFF94A3B8) + val TextTertiary = Color(0xFF64748B) + val Divider = Color(0xFF334155) + } + + // Animation + const val ANIMATION_DURATION = 300 + const val FADE_IN_DURATION = 200 + const val FADE_OUT_DURATION = 200 +} \ No newline at end of file diff --git a/app/src/main/java/com/example/notesai/util/DateFormatter.kt b/app/src/main/java/com/example/notesai/util/DateFormatter.kt new file mode 100644 index 0000000..0bb545d --- /dev/null +++ b/app/src/main/java/com/example/notesai/util/DateFormatter.kt @@ -0,0 +1,42 @@ +// File: util/DateFormatter.kt +package com.example.notesai.util + +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +object DateFormatter { + private val shortFormat = SimpleDateFormat("dd MMM, HH:mm", Locale("id", "ID")) + private val longFormat = SimpleDateFormat("dd MMMM yyyy, HH:mm", Locale("id", "ID")) + private val timeOnlyFormat = SimpleDateFormat("HH:mm", Locale("id", "ID")) + private val dateOnlyFormat = SimpleDateFormat("dd MMM yyyy", Locale("id", "ID")) + + fun formatShort(timestamp: Long): String { + return shortFormat.format(Date(timestamp)) + } + + fun formatLong(timestamp: Long): String { + return longFormat.format(Date(timestamp)) + } + + fun formatTimeOnly(timestamp: Long): String { + return timeOnlyFormat.format(Date(timestamp)) + } + + fun formatDateOnly(timestamp: Long): String { + return dateOnlyFormat.format(Date(timestamp)) + } + + fun formatRelative(timestamp: Long): String { + val now = System.currentTimeMillis() + val diff = now - timestamp + + return when { + diff < 60000 -> "Baru saja" + diff < 3600000 -> "${diff / 60000} menit yang lalu" + diff < 86400000 -> "${diff / 3600000} jam yang lalu" + diff < 604800000 -> "${diff / 86400000} hari yang lalu" + else -> formatDateOnly(timestamp) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/notesai/util/Extensions.kt b/app/src/main/java/com/example/notesai/util/Extensions.kt new file mode 100644 index 0000000..6c7f86b --- /dev/null +++ b/app/src/main/java/com/example/notesai/util/Extensions.kt @@ -0,0 +1,27 @@ +// File: util/Extensions.kt +package com.example.notesai.util + +import androidx.compose.ui.graphics.Color + +// String Extensions +fun String.truncate(maxLength: Int, suffix: String = "..."): String { + return if (this.length > maxLength) { + this.substring(0, maxLength) + suffix + } else { + this + } +} + +// Color Extensions +fun Long.toColor(): Color = Color(this) + +fun Color.withAlpha(alpha: Float): Color = this.copy(alpha = alpha) + +// List Extensions +fun List.replaceWhere(predicate: (T) -> Boolean, transform: (T) -> T): List { + return this.map { if (predicate(it)) transform(it) else it } +} + +fun List.removeWhere(predicate: (T) -> Boolean): List { + return this.filter { !predicate(it) } +} \ No newline at end of file