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

Null check for finding the source by ID

parent c965d5f9
......@@ -225,19 +225,19 @@ class DnsRuleFragment : Fragment() {
notifyRulesChanged()
}, editSource = { hostSource ->
NewHostSourceDialog(context!!, onSourceCreated = { newSource ->
val currentSource = getDatabase().hostSourceDao().findById(hostSource.id)!!.apply {
getDatabase().hostSourceDao().findById(hostSource.id)?.apply {
this.name = newSource.name
this.source = newSource.source
this.whitelistSource = newSource.whitelistSource
}
getDatabase().hostSourceDao().update(currentSource)
}?.also {
getDatabase().hostSourceDao().update(it)
val index = sourceAdapterList.indexOf(hostSource).takeIf { it >= 0 } ?: sourceAdapterList.indexOfFirst { it.id == hostSource.id }
sourceAdapterList[index] = currentSource
sourceRuleCount[currentSource] = sourceRuleCount[hostSource]
sourceRuleCount.remove(hostSource)
sourceAdapter.notifyItemChanged(index)
val index = sourceAdapterList.indexOf(hostSource).takeIf { it >= 0 } ?: sourceAdapterList.indexOfFirst { it.id == hostSource.id }
sourceAdapterList[index] = it
sourceRuleCount[it] = sourceRuleCount[hostSource]
sourceRuleCount.remove(hostSource)
sourceAdapter.notifyItemChanged(index)
}
}, showFileChooser = { callback ->
fileChosenCallback = callback
startActivityForResult(Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
......
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