Remove more RxJava

This commit is contained in:
topjohnwu
2020-07-09 04:49:14 -07:00
parent 4631077c49
commit 8647ba4729
26 changed files with 351 additions and 397 deletions
@@ -2,8 +2,8 @@ package com.topjohnwu.magisk.data.database
import androidx.room.*
import com.topjohnwu.magisk.model.entity.MagiskLog
import io.reactivex.Completable
import io.reactivex.Single
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.*
@Database(version = 1, entities = [MagiskLog::class], exportSchema = false)
@@ -18,19 +18,20 @@ abstract class SuLogDao(private val db: SuLogDatabase) {
private val twoWeeksAgo =
Calendar.getInstance().apply { add(Calendar.WEEK_OF_YEAR, -2) }.timeInMillis
fun deleteAll() = Completable.fromAction { db.clearAllTables() }
suspend fun deleteAll() = withContext(Dispatchers.IO) { db.clearAllTables() }
fun fetchAll() = deleteOutdated().andThen(fetch())
suspend fun fetchAll(): MutableList<MagiskLog> {
deleteOutdated()
return fetch()
}
@Query("SELECT * FROM logs ORDER BY time DESC")
protected abstract fun fetch(): Single<MutableList<MagiskLog>>
@Insert
abstract fun insert(log: MagiskLog): Completable
protected abstract suspend fun fetch(): MutableList<MagiskLog>
@Query("DELETE FROM logs WHERE time < :timeout")
protected abstract fun deleteOutdated(
timeout: Long = twoWeeksAgo
): Completable
protected abstract suspend fun deleteOutdated(timeout: Long = twoWeeksAgo)
@Insert
abstract suspend fun insert(log: MagiskLog)
}