feat: 优化代码

pull/120/head
kunfei 5 years ago
parent 864a7b4d09
commit 7fae9506fd
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  4. 26
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.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)

@ -62,16 +62,16 @@ class DiffCallBack(private val oldItems: List<SearchBook>, 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
}

@ -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(

@ -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)
}

Loading…
Cancel
Save