Commit 8e8b21a1 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Don't block the UI by populating the adapter

parent b6d372a2
...@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView ...@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.frostnerd.cacheadapter.DefaultViewHolder import com.frostnerd.cacheadapter.DefaultViewHolder
import com.frostnerd.cacheadapter.ModelAdapterBuilder import com.frostnerd.cacheadapter.ModelAdapterBuilder
import com.frostnerd.dnstunnelproxy.QueryListener import com.frostnerd.dnstunnelproxy.QueryListener
import com.frostnerd.lifecyclemanagement.launchWithLifecycle
import com.frostnerd.smokescreen.R import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.database.entities.DnsQuery import com.frostnerd.smokescreen.database.entities.DnsQuery
import com.frostnerd.smokescreen.database.getDatabase import com.frostnerd.smokescreen.database.getDatabase
...@@ -51,13 +52,16 @@ class QueryLogListFragment: Fragment(), SearchView.OnQueryTextListener { ...@@ -51,13 +52,16 @@ class QueryLogListFragment: Fragment(), SearchView.OnQueryTextListener {
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val live = requireContext().getDatabase().dnsQueryDao().getAllLive() launchWithLifecycle(false) {
val source = LiveDataSource(this, live, true) val live = requireContext().getDatabase().dnsQueryDao().getAllLive()
unfilteredAdapter = createAdapter(source) unfilteredAdapter = createAdapter(LiveDataSource(this@QueryLogListFragment, live, true))
list.layoutManager = LinearLayoutManager(requireContext()) launchWithLifecycle(true) {
list.adapter = unfilteredAdapter list.layoutManager = LinearLayoutManager(requireContext())
progress.visibility = View.GONE list.adapter = unfilteredAdapter
progress.visibility = View.GONE
}
}
} }
private fun createAdapter(source:LiveDataSource<DnsQuery>): RecyclerView.Adapter<DefaultViewHolder> { private fun createAdapter(source:LiveDataSource<DnsQuery>): RecyclerView.Adapter<DefaultViewHolder> {
......
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