Removed direct static usages of database from app

This commit is contained in:
Viktor De Pasquale
2019-05-12 15:49:42 +02:00
parent d4561507b8
commit c275326d59
16 changed files with 375 additions and 296 deletions
@@ -14,8 +14,8 @@ class SettingsDao : BaseDao() {
values(key to value.toString())
}.ignoreElement()
fun fetch(key: String) = query<Select> {
fun fetch(key: String, default: Int = -1) = query<Select> {
condition { equals("key", key) }
}.map { it.first().values.first().toIntOrNull() ?: -1 }
}.map { it.firstOrNull()?.values?.firstOrNull()?.toIntOrNull() ?: default }
}
@@ -31,6 +31,8 @@ class LogRepository(
.toSingle()
.map { it.exec() }
fun put(log: MagiskLog) = logDao.put(log)
private fun List<MagiskLog>.wrap(): List<WrappedMagiskLog> {
val day = TimeUnit.DAYS.toMillis(1)
return groupBy { it.date.time / day }
@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.data.database.SettingsDao
class SettingRepository(private val settingsDao: SettingsDao) {
fun fetch(key: String) = settingsDao.fetch(key)
fun fetch(key: String, default: Int) = settingsDao.fetch(key, default)
fun put(key: String, value: Int) = settingsDao.put(key, value)
fun delete(key: String) = settingsDao.delete(key)
@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.data.database.StringDao
class StringRepository(private val stringDao: StringDao) {
fun fetch(key: String) = stringDao.fetch(key)
fun fetch(key: String, default: String) = stringDao.fetch(key, default)
fun put(key: String, value: String) = stringDao.put(key, value)
fun delete(key: String) = stringDao.delete(key)