diff --git a/smartlog/src/commonMain/composeResources/drawable/outline_delete_24.xml b/smartlog/src/commonMain/composeResources/drawable/outline_delete_24.xml
new file mode 100644
index 0000000..87f3617
--- /dev/null
+++ b/smartlog/src/commonMain/composeResources/drawable/outline_delete_24.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/LogDatabaseImpl.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/LogDatabaseImpl.kt
index 2fd7c6d..e2451fb 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/LogDatabaseImpl.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/LogDatabaseImpl.kt
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
class LogDatabaseImpl @OptIn(DelicateCoroutinesApi::class) constructor(
private val dao: LogDao,
@@ -69,4 +70,10 @@ class LogDatabaseImpl @OptIn(DelicateCoroutinesApi::class) constructor(
it.map { it.toEntity() }
}
}
+
+ override suspend fun deleteAll() {
+ withContext(ioDispatcher) {
+ dao.deleteAll()
+ }
+ }
}
\ No newline at end of file
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/model/LogDao.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/model/LogDao.kt
index ddb732c..ade36b1 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/model/LogDao.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/database/model/LogDao.kt
@@ -22,4 +22,7 @@ interface LogDao {
@Query("SELECT * FROM Log JOIN log_fts ON log.id = log_fts.rowid WHERE log_fts MATCH :query AND log_level >= :logLevel ORDER BY date DESC")
fun filter(query: String, logLevel: Int = LogLevel.VERBOSE.priority): Flow>
+
+ @Query("DELETE FROM Log")
+ suspend fun deleteAll()
}
\ No newline at end of file
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/LogRepository.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/LogRepository.kt
index 93a394c..2794b5c 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/LogRepository.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/LogRepository.kt
@@ -31,6 +31,10 @@ class LogRepository(
return logDatabase.filter(filter)
}
+ suspend fun deleteAll() {
+ logDatabase.deleteAll()
+ }
+
companion object{
private var instance: LogRepository? = null
}
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/database/LogDatabase.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/database/LogDatabase.kt
index f4300c2..e2ee727 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/database/LogDatabase.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/repository/database/LogDatabase.kt
@@ -14,4 +14,5 @@ interface LogDatabase {
fun filter(logLevel: LogLevel): Flow>
fun filter(filterEntity: FilterEntity): Flow>
+ suspend fun deleteAll()
}
\ No newline at end of file
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogContent.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogContent.kt
index 71f30b8..c77a813 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogContent.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogContent.kt
@@ -116,6 +116,14 @@ fun LogContent(state: LogState,
null
)
}
+ IconButton(onClick = {
+ event(LogEvent.DeleteAllLogsEvent)
+ }) {
+ Icon(
+ painter = painterResource(Res.drawable.outline_delete_24),
+ contentDescription = "Delete all logs"
+ )
+ }
})
}
) {
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogEvent.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogEvent.kt
index 0c16134..861f55e 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogEvent.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogEvent.kt
@@ -5,4 +5,5 @@ sealed interface LogEvent {
object ScrollTopEvent: LogEvent
object PlayStopEvent: LogEvent
data class CardClickEvent(val id: Long): LogEvent
+ object DeleteAllLogsEvent: LogEvent
}
\ No newline at end of file
diff --git a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogViewModel.kt b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogViewModel.kt
index ef27dd3..1dd88c8 100644
--- a/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogViewModel.kt
+++ b/smartlog/src/commonMain/kotlin/com/jefryjacky/smartlog/ui/logs/LogViewModel.kt
@@ -60,6 +60,12 @@ class LogViewModel(
_state.update { it.copy(isPlaying = !it.isPlaying) }
}
+ is LogEvent.DeleteAllLogsEvent -> {
+ viewModelScope.launch {
+ logRepository.deleteAll()
+ }
+ }
+
else -> {}
}
}