From 18a524266bf7ec234512d6e4a1dd92a20a039aa2 Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 18 Dec 2019 22:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/search/SearchActivity.kt | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 72008b68a..0ffefda51 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -3,6 +3,8 @@ package io.legado.app.ui.book.search import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.View.GONE +import android.view.View.VISIBLE import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -28,6 +30,7 @@ import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity + class SearchActivity : VMBaseActivity(R.layout.activity_book_search), SearchViewModel.CallBack, BookAdapter.CallBack, @@ -110,10 +113,10 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } }) search_view.setOnQueryTextFocusChangeListener { _, hasFocus -> - if (hasFocus) { - ll_history.visible() + if (!hasFocus && search_view.query.toString().trim().isEmpty()) { + finish() } else { - ll_history.invisible() + openOrCloseHistory(hasFocus) } } } @@ -175,6 +178,15 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } } + private fun openOrCloseHistory(open: Boolean) { + if (open) { + upHistory("") + ll_history.visibility = VISIBLE + } else { + ll_history.visibility = GONE + } + } + private fun upGroupMenu() { val selectedGroup = getPrefString("searchGroup") ?: "" menu?.removeGroup(R.id.source_group) @@ -216,7 +228,13 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } else { App.db.searchKeywordDao().liveDataSearch(key) } - historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) }) + historyData?.observe(this, Observer { historyKeyAdapter.setItems(it) + if (it.isEmpty()) { + tv_clear_history.invisible() + } else { + tv_clear_history.visible() + } + }) } override fun startSearch() { @@ -254,4 +272,4 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } } } -} +} \ No newline at end of file