pull/36/head
kunfei 5 years ago
parent 27d0768470
commit c77c257556
  1. 8
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -1,12 +1,16 @@
package io.legado.app.ui.book.search
import android.content.Context
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.ui.widget.anima.explosion_field.ExplosionField
import kotlinx.android.synthetic.main.item_text.view.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
@ -24,7 +28,9 @@ class HistoryKeyAdapter(context: Context, val callBack: CallBack) :
it?.let {
ExplosionField(context).explode(it, true)
}
GlobalScope.launch(IO) {
App.db.searchKeywordDao().delete(item)
}
true
}
}

@ -44,6 +44,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
initSearchView()
initOtherView()
initData()
intent.getStringExtra("key")?.let {
search_view.setQuery(it, true)
@ -105,6 +106,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
fb_stop.onClick { viewModel.stop() }
}
private fun initOtherView() {
tv_clear_history.onClick {
viewModel.clearHistory()
}
}
private fun initData() {
searchBookData?.removeObservers(this)
searchBookData = LivePagedListBuilder(

@ -71,4 +71,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
} ?: App.db.searchKeywordDao().insert(SearchKeyword(key, 1))
}
}
fun clearHistory() {
execute {
App.db.searchKeywordDao().deleteAll()
}
}
}

Loading…
Cancel
Save