Commit c79568a5 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Persist the edit of a dns rule to the database

parent 2ae8425d
......@@ -173,6 +173,7 @@ class DnsRuleActivity : BaseActivity() {
sourceAdapter.notifyItemRemoved(sourceAdapterList.size + 1 + index)
}, editRule = {
DnsRuleDialog(this, it) { newRule ->
getDatabase().dnsRuleRepository().updateAsync(newRule)
val index = userDnsRules.indexOf(it)
userDnsRules[index] = newRule
sourceAdapter.notifyItemChanged(sourceAdapterList.size + 1 + index)
......
......@@ -27,6 +27,9 @@ import org.minidns.record.Record
@TypeConverters(DnsTypeConverter::class)
interface DnsRuleDao {
@Update
fun update(dnsRule: DnsRule)
@Insert
fun insert(dnsRule: DnsRule)
......
......@@ -28,6 +28,12 @@ import kotlinx.coroutines.launch
*/
class DnsRuleRepository(val dnsRuleDao: DnsRuleDao) {
fun updateAsync(dnsRule: DnsRule, coroutineScope: CoroutineScope = GlobalScope) {
coroutineScope.launch {
dnsRuleDao.update(dnsRule)
}
}
fun insertAsync(dnsRule: DnsRule, coroutineScope: CoroutineScope = GlobalScope) {
coroutineScope.launch {
dnsRuleDao.insert(dnsRule)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment