pull/43/head
kunfei 5 years ago
parent 7d98431dcb
commit e32694d426
  1. 16
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -6,8 +6,6 @@ import android.view.MenuItem
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
@ -15,7 +13,6 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.data.entities.SearchShow
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
@ -32,6 +29,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_search),
SearchViewModel.CallBack,
BookAdapter.CallBack,
HistoryKeyAdapter.CallBack,
SearchAdapter.CallBack {
@ -43,7 +41,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private lateinit var bookAdapter: BookAdapter
private lateinit var historyKeyAdapter: HistoryKeyAdapter
private lateinit var loadMoreView: LoadMoreView
private var searchBookData: LiveData<PagedList<SearchShow>>? = null
private var historyData: LiveData<List<SearchKeyword>>? = null
private var bookData: LiveData<List<Book>>? = null
private var menu: Menu? = null
@ -51,6 +48,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var groups = hashSetOf<String>()
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.callBack = this
initRecyclerView()
initSearchView()
initOtherView()
@ -150,16 +148,6 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
}
private fun initData() {
searchBookData?.removeObservers(this)
searchBookData = LivePagedListBuilder(
App.db.searchBookDao().observeShow(
viewModel.searchKey,
viewModel.startTime
), 30
).build()
searchBookData?.observe(this, Observer {
//ToDo
})
App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer {
groups.clear()
it.map { group ->

@ -16,6 +16,7 @@ import java.util.concurrent.Executors
class SearchViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher()
private var task: Coroutine<*>? = null
var callBack: CallBack? = null
var searchKey: String = ""
var startTime: Long = 0
var searchPage = 0
@ -105,4 +106,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
super.onCleared()
searchPool.close()
}
interface CallBack {
}
}

Loading…
Cancel
Save