优化
This commit is contained in:
@@ -27,6 +27,7 @@ import io.legado.app.help.config.AppConfig
|
|||||||
import io.legado.app.help.config.LocalConfig
|
import io.legado.app.help.config.LocalConfig
|
||||||
import io.legado.app.lib.dialogs.alert
|
import io.legado.app.lib.dialogs.alert
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
|
import io.legado.app.lib.theme.primaryTextColor
|
||||||
import io.legado.app.ui.book.group.GroupManageDialog
|
import io.legado.app.ui.book.group.GroupManageDialog
|
||||||
import io.legado.app.ui.book.group.GroupSelectDialog
|
import io.legado.app.ui.book.group.GroupSelectDialog
|
||||||
import io.legado.app.ui.widget.SelectActionBar
|
import io.legado.app.ui.widget.SelectActionBar
|
||||||
@@ -62,7 +63,9 @@ class BookshelfManageActivity :
|
|||||||
private val itemTouchCallback by lazy { ItemTouchCallback(adapter) }
|
private val itemTouchCallback by lazy { ItemTouchCallback(adapter) }
|
||||||
private var booksFlowJob: Job? = null
|
private var booksFlowJob: Job? = null
|
||||||
private var menu: Menu? = null
|
private var menu: Menu? = null
|
||||||
private var searchView: SearchView? = null
|
private val searchView: SearchView by lazy {
|
||||||
|
binding.titleBar.findViewById(R.id.search_view)
|
||||||
|
}
|
||||||
private var books: List<Book>? = null
|
private var books: List<Book>? = null
|
||||||
private val waitDialog by lazy { WaitDialog(this) }
|
private val waitDialog by lazy { WaitDialog(this) }
|
||||||
|
|
||||||
@@ -73,8 +76,9 @@ class BookshelfManageActivity :
|
|||||||
appDb.bookGroupDao.getByID(viewModel.groupId)?.groupName
|
appDb.bookGroupDao.getByID(viewModel.groupId)?.groupName
|
||||||
?: getString(R.string.no_group)
|
?: getString(R.string.no_group)
|
||||||
}
|
}
|
||||||
binding.titleBar.subtitle = viewModel.groupName
|
upTitle()
|
||||||
}
|
}
|
||||||
|
initSearchView()
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
initOtherView()
|
initOtherView()
|
||||||
initGroupData()
|
initGroupData()
|
||||||
@@ -109,7 +113,6 @@ class BookshelfManageActivity :
|
|||||||
|
|
||||||
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.bookshelf_manage, menu)
|
menuInflater.inflate(R.menu.bookshelf_manage, menu)
|
||||||
initSearchView(menu)
|
|
||||||
return super.onCompatCreateOptionsMenu(menu)
|
return super.onCompatCreateOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,40 +134,26 @@ class BookshelfManageActivity :
|
|||||||
selectGroup(groupRequestCode, 0)
|
selectGroup(groupRequestCode, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showTitle() {
|
private fun upTitle() {
|
||||||
binding.titleBar.title = getString(R.string.bookshelf_management)
|
searchView.queryHint = getString(R.string.screen) + " • " + viewModel.groupName
|
||||||
binding.titleBar.subtitle = viewModel.groupName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initSearchView(menu: Menu) {
|
private fun initSearchView() {
|
||||||
searchView = menu.findItem(R.id.menu_screen).actionView as SearchView
|
searchView.applyTint(primaryTextColor)
|
||||||
searchView?.run {
|
searchView.onActionViewExpanded()
|
||||||
setOnCloseListener {
|
searchView.isSubmitButtonEnabled = true
|
||||||
showTitle()
|
searchView.clearFocus()
|
||||||
false
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
setOnSearchClickListener {
|
|
||||||
binding.titleBar.title = ""
|
|
||||||
binding.titleBar.subtitle = ""
|
|
||||||
}
|
|
||||||
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String?): Boolean {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
upBookData()
|
upBookData()
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
setOnQueryTextFocusChangeListener { _, hasFocus ->
|
|
||||||
if (!hasFocus) {
|
|
||||||
searchView?.isIconified = true
|
|
||||||
showTitle()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
@@ -241,7 +230,7 @@ class BookshelfManageActivity :
|
|||||||
|
|
||||||
private fun upBookData() {
|
private fun upBookData() {
|
||||||
books?.let { books ->
|
books?.let { books ->
|
||||||
val searchKey = searchView?.query
|
val searchKey = searchView.query
|
||||||
if (searchKey.isNullOrEmpty()) {
|
if (searchKey.isNullOrEmpty()) {
|
||||||
adapter.setItems(books)
|
adapter.setItems(books)
|
||||||
} else {
|
} else {
|
||||||
@@ -259,7 +248,7 @@ class BookshelfManageActivity :
|
|||||||
R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
|
R.id.menu_group_manage -> showDialogFragment<GroupManageDialog>()
|
||||||
else -> if (item.groupId == R.id.menu_group) {
|
else -> if (item.groupId == R.id.menu_group) {
|
||||||
viewModel.groupName = item.title.toString()
|
viewModel.groupName = item.title.toString()
|
||||||
binding.titleBar.subtitle = item.title
|
upTitle()
|
||||||
viewModel.groupId =
|
viewModel.groupId =
|
||||||
appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
|
appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
|
||||||
upBookDataByGroupId()
|
upBookDataByGroupId()
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:title="@string/bookshelf_management"
|
app:title="@string/bookshelf_management"
|
||||||
|
app:contentInsetStartWithNavigation="0dp"
|
||||||
|
app:contentLayout="@layout/view_search"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
|||||||
@@ -4,13 +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_screen"
|
|
||||||
android:icon="@drawable/ic_screen"
|
|
||||||
android:title="@string/screen"
|
|
||||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
|
||||||
app:showAsAction="always" />
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_book_group"
|
android:id="@+id/menu_book_group"
|
||||||
android:icon="@drawable/ic_groups"
|
android:icon="@drawable/ic_groups"
|
||||||
|
|||||||
Reference in New Issue
Block a user