pull/32/head
kunfei 5 years ago
parent 1bd522181e
commit ea49ae88b7
  1. 5
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/SearchShow.kt
  3. 7
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  4. 11
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  6. 4
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt
  7. 4
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt
  8. 2
      app/src/main/res/layout/dialog_change_source.xml
  9. 2
      app/src/main/res/layout/item_change_source.xml

@ -24,7 +24,10 @@ interface SearchBookDao {
fun getSearchBook(bookUrl: String): SearchBook?
@Query("select * from searchBooks where name = :name and author = :author order by originOrder limit 1")
fun getByNameAuthor(name: String, author: String?): SearchBook?
fun getFirstByNameAuthor(name: String, author: String): SearchBook?
@Query("select * from searchBooks where name = :name and author = :author order by originOrder")
fun getByNameAuthor(name: String, author: String): List<SearchBook>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg searchBook: SearchBook): List<Long>

@ -3,8 +3,8 @@ package io.legado.app.data.entities
import io.legado.app.utils.splitNotBlank
data class SearchShow(
var name: String? = null,
var author: String? = null,
var name: String = "",
var author: String = "",
var kind: String? = null,
var coverUrl: String? = null,
var intro: String? = null,

@ -5,8 +5,11 @@ import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.data.entities.Book
@ -70,7 +73,11 @@ class ChangeSourceDialog : DialogFragment() {
private fun initRecyclerView() {
changeSourceAdapter = ChangeSourceAdapter(requireContext())
recycler_view.layoutManager = LinearLayoutManager(context)
recycler_view.addItemDecoration(DividerItemDecoration(requireContext(), LinearLayout.VERTICAL))
recycler_view.adapter = changeSourceAdapter
viewModel.searchBookData.observe(viewLifecycleOwner, Observer {
changeSourceAdapter.addItems(it)
})
}
private fun initSearchView() {

@ -1,15 +1,22 @@
package io.legado.app.ui.changesource
import android.app.Application
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.SearchBook
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var name: String = ""
var author: String = ""
val searchBookData = MutableLiveData<List<SearchBook>>()
fun startSearch() {
execute {
App.db.searchBookDao().getByNameAuthor(name, author).let {
searchBookData.postValue(it)
}
}
}
}

@ -78,7 +78,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
searchBookData?.observe(this, Observer { adapter.submitList(it) })
}
override fun showBookInfo(name: String, author: String?) {
override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let {
startActivity<BookInfoActivity>(Pair("searchBookUrl", it.bookUrl))

@ -96,12 +96,12 @@ class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(D
.setAsDrawable(iv_cover)
}
onClick {
callBack?.showBookInfo(searchBook.name!!, searchBook.author)
callBack?.showBookInfo(searchBook.name, searchBook.author)
}
}
}
interface CallBack {
fun showBookInfo(name: String, author: String?)
fun showBookInfo(name: String, author: String)
}
}

@ -48,9 +48,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
task?.cancel()
}
fun getSearchBook(name: String, author: String?, success: ((searchBook: SearchBook?) -> Unit)?) {
fun getSearchBook(name: String, author: String, success: ((searchBook: SearchBook?) -> Unit)?) {
execute {
val searchBook = App.db.searchBookDao().getByNameAuthor(name, author)
val searchBook = App.db.searchBookDao().getFirstByNameAuthor(name, author)
success?.invoke(searchBook)
}
}

@ -18,7 +18,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/tool_bar"
app:layout_constraintBottom_toBottomOf="parent" />

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView

Loading…
Cancel
Save