Commit 92e1a3f9 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Refactor logic

parent e646f26c
...@@ -50,29 +50,19 @@ class DnsQueryRepository(private val dnsQueryDao: DnsQueryDao) { ...@@ -50,29 +50,19 @@ class DnsQueryRepository(private val dnsQueryDao: DnsQueryDao) {
} }
private fun filterDnsQuery(filterConfig: QueryLogFilterDialog.FilterConfig, liveData: LiveData<List<DnsQuery>>):LiveData<List<DnsQuery>> { private fun filterDnsQuery(filterConfig: QueryLogFilterDialog.FilterConfig, liveData: LiveData<List<DnsQuery>>):LiveData<List<DnsQuery>> {
if(filterConfig.showForwarded && filterConfig.showBlockedByDns) { return if(filterConfig.showForwarded == filterConfig.showBlockedByDns) {
return liveData liveData
} else{ } else {
val holdsAllData = liveData.value?.let { if(filterConfig.showForwarded && !filterConfig.showBlockedByDns) {
dnsQueryDao.getCount() == it.size Transformations.map(liveData) {
} ?: false it.filterNot { query ->
query.isHostBlockedByDnsServer
return when {
holdsAllData -> {
liveData
}
filterConfig.showForwarded -> {
Transformations.map(liveData) {
it.filter {
!it.isHostBlockedByDnsServer
}
} }
} }
else -> { // showForwarded = false, showBlockedByDns = true } else {
Transformations.map(liveData) { Transformations.map(liveData) {
it.filter { it.filter { query ->
it.isHostBlockedByDnsServer query.isHostBlockedByDnsServer
}
} }
} }
} }
......
Markdown is supported
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