More refactoring

Cleanups, move classes to sane locations, etc.
This commit is contained in:
topjohnwu
2020-08-19 02:05:23 -07:00
parent 846bbb4da1
commit 34450cdddd
85 changed files with 365 additions and 522 deletions
@@ -1,12 +1,12 @@
package com.topjohnwu.magisk.data.database
import androidx.room.*
import com.topjohnwu.magisk.model.entity.MagiskLog
import com.topjohnwu.magisk.core.model.su.SuLog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.*
@Database(version = 1, entities = [MagiskLog::class], exportSchema = false)
@Database(version = 1, entities = [SuLog::class], exportSchema = false)
abstract class SuLogDatabase : RoomDatabase() {
abstract fun suLogDao(): SuLogDao
@@ -20,18 +20,18 @@ abstract class SuLogDao(private val db: SuLogDatabase) {
suspend fun deleteAll() = withContext(Dispatchers.IO) { db.clearAllTables() }
suspend fun fetchAll(): MutableList<MagiskLog> {
suspend fun fetchAll(): MutableList<SuLog> {
deleteOutdated()
return fetch()
}
@Query("SELECT * FROM logs ORDER BY time DESC")
protected abstract suspend fun fetch(): MutableList<MagiskLog>
protected abstract suspend fun fetch(): MutableList<SuLog>
@Query("DELETE FROM logs WHERE time < :timeout")
protected abstract suspend fun deleteOutdated(timeout: Long = twoWeeksAgo)
@Insert
abstract suspend fun insert(log: MagiskLog)
abstract suspend fun insert(log: SuLog)
}