书籍导入添加筛选
This commit is contained in:
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.import
|
|||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
|
import androidx.appcompat.widget.SearchView
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
import io.legado.app.help.config.AppConfig
|
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>() {
|
abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel> : VMBaseActivity<VB, VM>() {
|
||||||
|
|
||||||
private var localBookTreeSelectListener: ((Boolean) -> Unit)? = null
|
private var localBookTreeSelectListener: ((Boolean) -> Unit)? = null
|
||||||
|
private val searchView: SearchView by lazy {
|
||||||
|
binding.titleBar.findViewById(R.id.search_view)
|
||||||
|
}
|
||||||
|
|
||||||
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
|
private val localBookTreeSelect = registerForActivityResult(HandleFileContract()) {
|
||||||
it.uri?.let { treeUri ->
|
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?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
binding.titleBar.setTitle(R.string.book_local)
|
|
||||||
launch {
|
launch {
|
||||||
initView()
|
initView()
|
||||||
initEvent()
|
initEvent()
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
list.clear()
|
list.clear()
|
||||||
trySend(emptyList())
|
trySend(emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun screen(key: String?) {
|
||||||
|
trySend(list)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
@@ -163,6 +168,10 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateCallBackFlow(filterKey: String?) {
|
||||||
|
dataCallback?.screen(filterKey)
|
||||||
|
}
|
||||||
|
|
||||||
interface DataCallback {
|
interface DataCallback {
|
||||||
|
|
||||||
fun setItems(fileDocs: List<FileDoc>)
|
fun setItems(fileDocs: List<FileDoc>)
|
||||||
@@ -171,6 +180,8 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
|
|
||||||
fun clear()
|
fun clear()
|
||||||
|
|
||||||
|
fun screen(key: String?)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,6 @@ class RemoteBookActivity : BaseImportBookActivity<ActivityImportBookBinding, Rem
|
|||||||
private var groupMenu: SubMenu? = null
|
private var groupMenu: SubMenu? = null
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
binding.titleBar.setTitle(R.string.remote_book)
|
|
||||||
launch {
|
launch {
|
||||||
if (!setBookStorage()) {
|
if (!setBookStorage()) {
|
||||||
finish()
|
finish()
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
list.clear()
|
list.clear()
|
||||||
trySend(emptyList())
|
trySend(emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun screen(key: String?) {
|
||||||
|
trySend(list)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitClose {
|
awaitClose {
|
||||||
@@ -137,6 +141,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateCallBackFlow(filterKey: String?) {
|
||||||
|
dataCallback?.screen(filterKey)
|
||||||
|
}
|
||||||
|
|
||||||
interface DataCallback {
|
interface DataCallback {
|
||||||
|
|
||||||
fun setItems(remoteFiles: List<RemoteBook>)
|
fun setItems(remoteFiles: List<RemoteBook>)
|
||||||
@@ -145,5 +153,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
|
|
||||||
fun clear()
|
fun clear()
|
||||||
|
|
||||||
|
fun screen(key: String?)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,9 @@
|
|||||||
android:id="@+id/titleBar"
|
android:id="@+id/titleBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:attachToActivity="false"
|
||||||
|
app:contentLayout="@layout/view_search" />
|
||||||
|
|
||||||
<!--path-->
|
<!--path-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -4,12 +4,6 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:ignore="AlwaysShowAction">
|
tools:ignore="AlwaysShowAction">
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_search"
|
|
||||||
android:icon="@drawable/ic_search"
|
|
||||||
android:title="@string/search"
|
|
||||||
app:showAsAction="always" />
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_refresh"
|
android:id="@+id/menu_refresh"
|
||||||
android:icon="@drawable/ic_refresh_black_24dp"
|
android:icon="@drawable/ic_refresh_black_24dp"
|
||||||
|
|||||||
@@ -4,12 +4,6 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:ignore="AlwaysShowAction">
|
tools:ignore="AlwaysShowAction">
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_search"
|
|
||||||
android:icon="@drawable/ic_search"
|
|
||||||
android:title="@string/search"
|
|
||||||
app:showAsAction="always" />
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_select_folder"
|
android:id="@+id/menu_select_folder"
|
||||||
android:icon="@drawable/ic_folder_open"
|
android:icon="@drawable/ic_folder_open"
|
||||||
|
|||||||
Reference in New Issue
Block a user