Migrasi Utilities
This commit is contained in:
parent
efabb0a172
commit
594ea05206
53
app/src/main/java/com/example/notesai/util/Constants.kt
Normal file
53
app/src/main/java/com/example/notesai/util/Constants.kt
Normal file
@ -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
|
||||
}
|
||||
42
app/src/main/java/com/example/notesai/util/DateFormatter.kt
Normal file
42
app/src/main/java/com/example/notesai/util/DateFormatter.kt
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/com/example/notesai/util/Extensions.kt
Normal file
27
app/src/main/java/com/example/notesai/util/Extensions.kt
Normal file
@ -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 <T> List<T>.replaceWhere(predicate: (T) -> Boolean, transform: (T) -> T): List<T> {
|
||||
return this.map { if (predicate(it)) transform(it) else it }
|
||||
}
|
||||
|
||||
fun <T> List<T>.removeWhere(predicate: (T) -> Boolean): List<T> {
|
||||
return this.filter { !predicate(it) }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user