From 134cab4e12e1703566ff029123d067ddb9bfa862 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 18 Sep 2019 21:37:27 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/BookSourceDao.kt | 3 +++ .../app/ui/main/explore/ExploreFragment.kt | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 36dfc3d22..39dc91264 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.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") fun liveExplore(): LiveData> + @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> + @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") fun liveGroup(): LiveData> diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 8ac9c93bd..55df1a26a 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -2,6 +2,8 @@ package io.legado.app.ui.main.explore import android.os.Bundle import android.view.View +import androidx.appcompat.widget.SearchView +import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App @@ -26,6 +28,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ private lateinit var adapter: ExploreAdapter private lateinit var linearLayoutManager: LinearLayoutManager + private var liveExplore: LiveData>? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -40,6 +43,15 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ search_view.isSubmitButtonEnabled = true search_view.queryHint = getString(R.string.screen_find) 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() { @@ -50,8 +62,14 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ rv_find.adapter = adapter } - private fun initData() { - App.db.bookSourceDao().liveExplore().observe(viewLifecycleOwner, Observer { + private fun initData(key: String? = null) { + liveExplore?.removeObservers(viewLifecycleOwner) + liveExplore = if (key.isNullOrBlank()) { + App.db.bookSourceDao().liveExplore() + } else { + App.db.bookSourceDao().liveExplore("%$key%") + } + liveExplore?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) }) }