feat: initialize GaCy Android project foundation (Kotlin, Jetpack Compose, Material 3)
This commit is contained in:
commit
3eab1e7e49
61 files changed
+5821
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package com.gacy.android.service
|
||||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
object LogBuffer {
|
||||
|
||||
private const val MAX_LOG_LINES = 500
|
||||
private val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
|
||||
private val _logs = MutableStateFlow<List<String>>(emptyList())
|
||||
val logs: StateFlow<List<String>> = _logs.asStateFlow()
|
||||
|
||||
@Synchronized
|
||||
fun append(message: String) {
|
||||
val timestamp = timeFormat.format(Date())
|
||||
val formatted = "[$timestamp] $message"
|
||||
val current = _logs.value.toMutableList()
|
||||
current.add(formatted)
|
||||
if (current.size > MAX_LOG_LINES) {
|
||||
current.removeAt(0)
|
||||
}
|
||||
_logs.value = current
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clear() {
|
||||
_logs.value = emptyList()
|
||||
}
|
||||
|
||||
fun getAllText(): String {
|
||||
return _logs.value.joinToString("\n")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user