From b63b7e00e4642c313bab67e7b94f1a56c58d518a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 15 Dec 2020 16:03:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/search/DiffCallBack.kt | 42 ------------------- .../app/ui/book/search/SearchActivity.kt | 1 - .../app/ui/book/search/SearchAdapter.kt | 11 ++++- 3 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt deleted file mode 100644 index 7cd271c19..000000000 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ /dev/null @@ -1,42 +0,0 @@ -package io.legado.app.ui.book.search - -import android.os.Bundle -import androidx.recyclerview.widget.DiffUtil -import io.legado.app.data.entities.SearchBook - -class DiffCallBack : DiffUtil.ItemCallback() { - - override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { - return when { - oldItem.name != newItem.name -> false - oldItem.author != newItem.author -> false - else -> true - } - } - - override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { - return when { - oldItem.origins.size != newItem.origins.size -> false - oldItem.coverUrl != newItem.coverUrl -> false - oldItem.kind != newItem.kind -> false - oldItem.latestChapterTitle != newItem.latestChapterTitle -> false - oldItem.intro != newItem.intro -> false - else -> true - } - } - - override fun getChangePayload(oldItem: SearchBook, newItem: SearchBook): Any? { - val payload = Bundle() - if (oldItem.name != newItem.name) payload.putString("name", newItem.name) - if (oldItem.author != newItem.author) payload.putString("author", newItem.author) - if (oldItem.origins.size != newItem.origins.size) - payload.putInt("origins", newItem.origins.size) - if (oldItem.coverUrl != newItem.coverUrl) payload.putString("cover", newItem.coverUrl) - if (oldItem.kind != newItem.kind) payload.putString("kind", newItem.kind) - if (oldItem.latestChapterTitle != newItem.latestChapterTitle) - payload.putString("last", newItem.latestChapterTitle) - if (oldItem.intro != newItem.intro) payload.putString("intro", newItem.intro) - if (payload.isEmpty) return null - return payload - } -} \ No newline at end of file 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 74bd36c27..34a947270 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 @@ -299,7 +299,6 @@ class SearchActivity : VMBaseActivity) { adapter.setItems(items) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 20636f42f..c3d77b2fe 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -17,7 +17,16 @@ class SearchAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback - get() = DiffCallBack() + get() = object : DiffUtil.ItemCallback() { + + override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return true + } + + override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { + return false + } + } override fun getViewBinding(parent: ViewGroup): ItemSearchBinding { return ItemSearchBinding.inflate(inflater, parent, false) From e1e3ec1dda427cbca7257f8da6570aa771cc929b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 15 Dec 2020 16:06:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/search/SearchActivity.kt | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 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 34a947270..7aa11f1c5 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 @@ -44,7 +44,7 @@ class SearchActivity : VMBaseActivity>? = null private var bookData: LiveData>? = null private var menu: Menu? = null @@ -57,7 +57,7 @@ class SearchActivity : VMBaseActivity startActivity() @@ -99,8 +99,8 @@ class SearchActivity : VMBaseActivity - if (!hasFocus && serchView.query.toString().trim().isEmpty()) { + searchView.setOnQueryTextFocusChangeListener { _, hasFocus -> + if (!hasFocus && searchView.query.toString().trim().isEmpty()) { finish() } else { openOrCloseHistory(hasFocus) @@ -207,9 +207,9 @@ class SearchActivity : VMBaseActivity { - serchView.setQuery(key, true) + searchView.query.toString() == key -> { + searchView.setQuery(key, true) } withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> { - serchView.setQuery(key, true) + searchView.setQuery(key, true) } else -> { - serchView.setQuery(key, false) + searchView.setQuery(key, false) } } }