书籍导入添加筛选
This commit is contained in:
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.import
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -13,6 +14,9 @@ import kotlin.coroutines.suspendCoroutine
|
||||
abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel> : VMBaseActivity<VB, VM>() {
|
||||
|
||||
private var localBookTreeSelectListener: ((Boolean) -> Unit)? = null
|
||||
private val searchView: SearchView by lazy {
|
||||
binding.titleBar.findViewById(R.id.search_view)
|
||||
}
|
||||
|
||||
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let { treeUri ->
|
||||
@@ -51,5 +55,22 @@ abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel> : VMBase
|
||||
}
|
||||
}
|
||||
|
||||
private fun initSearchView() {
|
||||
searchView.applyTint(primaryTextColor)
|
||||
searchView.onActionViewExpanded()
|
||||
searchView.isSubmitButtonEnabled = true
|
||||
searchView.queryHint = getString(R.string.screen_find)
|
||||
searchView.clearFocus()
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
viewModel.updateCallBackFlow(newText)
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,7 +52,6 @@ class ImportBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Imp
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
binding.titleBar.setTitle(R.string.book_local)
|
||||
launch {
|
||||
initView()
|
||||
initEvent()
|
||||
|
||||
@@ -48,6 +48,11 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
list.clear()
|
||||
trySend(emptyList())
|
||||
}
|
||||
|
||||
override fun screen(key: String?) {
|
||||
trySend(list)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
withContext(Main) {
|
||||
@@ -163,6 +168,10 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCallBackFlow(filterKey: String?) {
|
||||
dataCallback?.screen(filterKey)
|
||||
}
|
||||
|
||||
interface DataCallback {
|
||||
|
||||
fun setItems(fileDocs: List<FileDoc>)
|
||||
@@ -170,6 +179,8 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
fun addItems(fileDocs: List<FileDoc>)
|
||||
|
||||
fun clear()
|
||||
|
||||
fun screen(key: String?)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
|
||||
private var groupMenu: SubMenu? = null
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
binding.titleBar.setTitle(R.string.remote_book)
|
||||
launch {
|
||||
if (!setBookStorage()) {
|
||||
finish()
|
||||
|
||||
@@ -49,6 +49,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
list.clear()
|
||||
trySend(emptyList())
|
||||
}
|
||||
|
||||
override fun screen(key: String?) {
|
||||
trySend(list)
|
||||
}
|
||||
}
|
||||
|
||||
awaitClose {
|
||||
@@ -137,6 +141,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCallBackFlow(filterKey: String?) {
|
||||
dataCallback?.screen(filterKey)
|
||||
}
|
||||
|
||||
interface DataCallback {
|
||||
|
||||
fun setItems(remoteFiles: List<RemoteBook>)
|
||||
@@ -144,6 +152,8 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
fun addItems(remoteFiles: List<RemoteBook>)
|
||||
|
||||
fun clear()
|
||||
|
||||
fun screen(key: String?)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user