From 7fae9506fd452ddca462272a1b093b91c4e75bad Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 15:32:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 2 +- .../legado/app/ui/book/search/DiffCallBack.kt | 8 +++--- .../app/ui/book/search/SearchAdapter.kt | 6 ++--- .../app/ui/book/search/SearchViewModel.kt | 26 ++++++++++++++++++- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 4b133a001..dabf7caa3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -79,7 +79,7 @@ object ChapterProvider { durY = joinBody(text, durY, textPages, pageLines, pageLengths, stringBuilder) } } - textPages.last().height = durY + textPages.last().height = durY + 20.dp textPages.last().text = stringBuilder.toString() if (pageLines.size < textPages.size) { pageLines.add(textPages.last().textLines.size) 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 index 2bba67405..07a3b16c5 100644 --- 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 @@ -62,16 +62,16 @@ class DiffCallBack(private val oldItems: List, private val newItems: payload.putInt("origins", newItem.origins.size) } if (oldItem.coverUrl != newItem.coverUrl) { - payload.putString("group", newItem.coverUrl) + payload.putString("cover", newItem.coverUrl) } if (oldItem.kind != newItem.kind) { - payload.putString("enabled", newItem.kind) + payload.putString("kind", newItem.kind) } if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { - payload.putString("enabled", newItem.latestChapterTitle) + payload.putString("last", newItem.latestChapterTitle) } if (oldItem.intro != newItem.intro) { - payload.putString("enabled", newItem.intro) + payload.putString("intro", newItem.intro) } return payload } 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 38d1154d6..a96244113 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 @@ -56,9 +56,9 @@ class SearchAdapter(context: Context, val callBack: CallBack) : "name" -> tv_name.text = searchBook.name "author" -> tv_author.text = context.getString(R.string.author_show, searchBook.author) - "originCount" -> bv_originCount.setBadgeCount(searchBook.origins.size) - "lasted" -> upLasted(itemView, searchBook.latestChapterTitle) - "introduce" -> tv_introduce.text = + "origins" -> bv_originCount.setBadgeCount(searchBook.origins.size) + "last" -> upLasted(itemView, searchBook.latestChapterTitle) + "intro" -> tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) "kind" -> upKind(itemView, searchBook.getKindList()) "cover" -> iv_cover.load( diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 33df6bde5..f56ad21d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -141,7 +141,31 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } - + searchBooks.sortWith(Comparator { o1, o2 -> + if (o1.name == searchKey && o2.name != searchKey) { + 1 + } else if (o1.name != searchKey && o2.name == searchKey) { + -1 + } else if (o1.author == searchKey && o2.author != searchKey) { + 1 + } else if (o1.author != searchKey && o2.author == searchKey) { + -1 + } else if (o1.name == o2.name) { + when { + o1.origins.size > o2.origins.size -> { + 1 + } + o1.origins.size < o2.origins.size -> { + -1 + } + else -> { + 0 + } + } + } else { + 0 + } + }) searchBooks = copyDataS searchBookLiveData.postValue(copyDataS) }