Migrate PatchAPK to Kotlin

This commit is contained in:
topjohnwu
2019-08-04 13:00:27 -07:00
parent 8706d834b4
commit 33b7ab593c
7 changed files with 156 additions and 173 deletions
@@ -23,8 +23,9 @@ interface DBConfig {
fun dbStrings(
name: String,
default: String
) = DBStringsValue(name, default)
default: String,
sync: Boolean = false
) = DBStringsValue(name, default, sync)
}
@@ -70,7 +71,8 @@ class DBBoolSettings(
class DBStringsValue(
private val name: String,
private val default: String
private val default: String,
private val sync: Boolean
) : ReadWriteProperty<DBConfig, String> {
private var value: String? = null
@@ -88,8 +90,12 @@ class DBStringsValue(
synchronized(this) {
this.value = value
}
thisRef.stringDao.put(getKey(property), value)
.subscribeOn(Schedulers.io())
.subscribe()
if (sync) {
thisRef.stringDao.put(getKey(property), value).blockingAwait()
} else {
thisRef.stringDao.put(getKey(property), value)
.subscribeOn(Schedulers.io())
.subscribe()
}
}
}