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

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

Loading…
Cancel
Save