pull/32/head
kunfei 5 years ago
parent 7d398f5226
commit cc7816949f
  1. 3
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 27
      app/src/main/java/io/legado/app/data/entities/SearchShow.kt
  3. 6
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  4. 16
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt

@ -6,6 +6,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchShow
@Dao
interface SearchBookDao {
@ -16,6 +17,8 @@ interface SearchBookDao {
@Query("SELECT * FROM searchBooks where time >= :time")
fun observeNew(time: Long): DataSource.Factory<Int, SearchBook>
@Query("SELECT name, author, min(time) time, max(kind) kind, max(coverUrl) coverUrl, max(intro) intro, max(wordCount) wordCount, max(latestChapterTitle) latestChapterTitle, count(origin) originCount FROM searchBooks where time >= :time group by name, author")
fun observeShow(time: Long): DataSource.Factory<Int, SearchShow>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg searchBook: SearchBook): List<Long>

@ -0,0 +1,27 @@
package io.legado.app.data.entities
import io.legado.app.utils.splitNotBlank
data class SearchShow(
var name: String? = null,
var author: String? = null,
var kind: String? = null,
var coverUrl: String? = null,
var intro: String? = null,
var wordCount: String? = null,
var latestChapterTitle: String? = null,
var time: Long = 0L,
var originCount: Int = 0
) {
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
}
}

@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchShow
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_search.*
@ -23,7 +23,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
get() = getViewModel(SearchViewModel::class.java)
private lateinit var adapter: SearchAdapter
private var searchBookData: LiveData<PagedList<SearchBook>>? = null
private var searchBookData: LiveData<PagedList<SearchShow>>? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
@ -70,7 +70,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
private fun initData(startTime: Long) {
searchBookData?.removeObservers(this)
searchBookData = LivePagedListBuilder(App.db.searchBookDao().observeNew(startTime), 30).build()
searchBookData = LivePagedListBuilder(App.db.searchBookDao().observeShow(startTime), 30).build()
searchBookData?.observe(this, Observer { adapter.submitList(it) })
}

@ -7,7 +7,7 @@ import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchShow
import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone
import io.legado.app.utils.visible
@ -16,17 +16,17 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name
import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter : PagedListAdapter<SearchBook, SearchAdapter.MyViewHolder>(DIFF_CALLBACK) {
class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<SearchBook>() {
override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean =
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<SearchShow>() {
override fun areItemsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean =
oldItem.name == newItem.name
&& oldItem.author == newItem.author
override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean =
override fun areContentsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean =
oldItem.name == newItem.name
&& oldItem.author == newItem.author
}
@ -47,7 +47,7 @@ class SearchAdapter : PagedListAdapter<SearchBook, SearchAdapter.MyViewHolder>(D
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(searchBook: SearchBook, callBack: CallBack?) = with(itemView) {
fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) {
tv_name.text = searchBook.name
tv_author.text = searchBook.author
tv_lasted.text = context.getString(R.string.book_search_last, searchBook.latestChapterTitle)
@ -90,12 +90,12 @@ class SearchAdapter : PagedListAdapter<SearchBook, SearchAdapter.MyViewHolder>(D
.setAsDrawable(iv_cover)
}
onClick {
callBack?.showBookInfo(searchBook)
callBack?.showBookInfo(searchBook.name, searchBook.author)
}
}
}
interface CallBack {
fun showBookInfo(searchBook: SearchBook)
fun showBookInfo(name: String?, author: String?)
}
}
Loading…
Cancel
Save