pull/34/head
kunfei 5 years ago
parent 425e40b167
commit 134cab4e12
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 22
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt

@ -17,6 +17,9 @@ interface BookSourceDao {
@Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc")
fun liveExplore(): LiveData<List<BookSource>> fun liveExplore(): LiveData<List<BookSource>>
@Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc")
fun liveExplore(key: String): LiveData<List<BookSource>>
@Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''")
fun liveGroup(): LiveData<List<String>> fun liveGroup(): LiveData<List<String>>

@ -2,6 +2,8 @@ package io.legado.app.ui.main.explore
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
@ -26,6 +28,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_
private lateinit var adapter: ExploreAdapter private lateinit var adapter: ExploreAdapter
private lateinit var linearLayoutManager: LinearLayoutManager private lateinit var linearLayoutManager: LinearLayoutManager
private var liveExplore: LiveData<List<BookSource>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportToolbar(toolbar)
@ -40,6 +43,15 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_
search_view.isSubmitButtonEnabled = true search_view.isSubmitButtonEnabled = true
search_view.queryHint = getString(R.string.screen_find) search_view.queryHint = getString(R.string.screen_find)
search_view.clearFocus() search_view.clearFocus()
search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
return false
}
})
} }
private fun initRecyclerView() { private fun initRecyclerView() {
@ -50,8 +62,14 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_find_
rv_find.adapter = adapter rv_find.adapter = adapter
} }
private fun initData() { private fun initData(key: String? = null) {
App.db.bookSourceDao().liveExplore().observe(viewLifecycleOwner, Observer { liveExplore?.removeObservers(viewLifecycleOwner)
liveExplore = if (key.isNullOrBlank()) {
App.db.bookSourceDao().liveExplore()
} else {
App.db.bookSourceDao().liveExplore("%$key%")
}
liveExplore?.observe(viewLifecycleOwner, Observer {
adapter.setItems(it) adapter.setItems(it)
}) })
} }

Loading…
Cancel
Save