From cc7816949fba0dd8992a0ced7ad4d738c66dfe69 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 5 Aug 2019 23:07:13 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/SearchBookDao.kt | 3 +++ .../io/legado/app/data/entities/SearchShow.kt | 27 +++++++++++++++++++ .../io/legado/app/ui/search/SearchActivity.kt | 6 ++--- .../io/legado/app/ui/search/SearchAdapter.kt | 16 +++++------ 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/SearchShow.kt diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index fb58efd8a..0336d7ef7 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.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 + @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 @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg searchBook: SearchBook): List diff --git a/app/src/main/java/io/legado/app/data/entities/SearchShow.kt b/app/src/main/java/io/legado/app/data/entities/SearchShow.kt new file mode 100644 index 000000000..31268aefb --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/SearchShow.kt @@ -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 { + val kindList = arrayListOf() + wordCount?.let { + if (it.isNotBlank()) kindList.add(it) + } + kind?.let { + val kinds = it.splitNotBlank(",", "\n") + kindList.addAll(kinds) + } + return kindList + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt index eb26a882c..25a47169b 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchActivity.kt @@ -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(R.layout.activity_search) get() = getViewModel(SearchViewModel::class.java) private lateinit var adapter: SearchAdapter - private var searchBookData: LiveData>? = null + private var searchBookData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -70,7 +70,7 @@ class SearchActivity : VMBaseActivity(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) }) } diff --git a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt index 4488d9f8c..2c46fd479 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt @@ -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(DIFF_CALLBACK) { +class SearchAdapter : PagedListAdapter(DIFF_CALLBACK) { companion object { @JvmField - val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean = + val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { + 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(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(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?) } } \ No newline at end of file