mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -61,6 +61,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
binding.titleBar.findViewById(R.id.search_view)
|
||||
}
|
||||
private var menu: Menu? = null
|
||||
private var groups: List<String>? = null
|
||||
private var historyFlowJob: Job? = null
|
||||
private var booksFlowJob: Job? = null
|
||||
private var precisionSearchMenuItem: MenuItem? = null
|
||||
@@ -82,8 +83,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否切换到全部分组?")
|
||||
yesButton {
|
||||
viewModel.searchScope.update("")
|
||||
viewModel.searchScope.save()
|
||||
viewModel.search(searchView.query.toString())
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
@@ -114,6 +113,30 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
return super.onCompatCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
||||
menu.removeGroup(R.id.menu_group_1)
|
||||
menu.removeGroup(R.id.menu_group_2)
|
||||
val searchScopeNames = viewModel.searchScope.displayNames
|
||||
searchScopeNames.forEach {
|
||||
menu.add(R.id.menu_group_1, Menu.NONE, Menu.NONE, it).apply {
|
||||
isChecked = true
|
||||
}
|
||||
}
|
||||
menu.add(R.id.menu_group_2, R.id.menu_1, Menu.NONE, getString(R.string.all_source)).apply {
|
||||
if (searchScopeNames.isEmpty()) {
|
||||
isChecked = true
|
||||
}
|
||||
}
|
||||
groups?.forEach {
|
||||
if (!searchScopeNames.contains(it)) {
|
||||
menu.add(R.id.menu_group_2, Menu.NONE, Menu.NONE, it)
|
||||
}
|
||||
}
|
||||
menu.setGroupCheckable(R.id.menu_group_1, true, false)
|
||||
menu.setGroupCheckable(R.id.menu_group_2, true, true)
|
||||
return super.onMenuOpened(featureId, menu)
|
||||
}
|
||||
|
||||
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.menu_precision_search -> {
|
||||
@@ -129,6 +152,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
R.id.menu_search_scope -> alertSearchScope()
|
||||
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
|
||||
R.id.menu_log -> showDialogFragment(AppLogDialog())
|
||||
R.id.menu_1 -> viewModel.searchScope.update("")
|
||||
else -> {
|
||||
if (item.groupId == R.id.menu_group_1) {
|
||||
viewModel.searchScope.remove(item.title.toString())
|
||||
} else if (item.groupId == R.id.menu_group_2) {
|
||||
viewModel.searchScope.update(item.title.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
}
|
||||
@@ -219,7 +250,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
|
||||
private fun initData() {
|
||||
viewModel.searchScope.stateLiveData.observe(this) {
|
||||
upSearchScope()
|
||||
if (!binding.llInputHelp.isVisible) {
|
||||
searchView.query?.toString()?.trim()?.let {
|
||||
searchView.setQuery(it, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModel.isSearchLiveData.observe(this) {
|
||||
if (it) {
|
||||
@@ -234,10 +269,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun upSearchScope() {
|
||||
binding.tvSearchScope.text = viewModel.searchScope.display
|
||||
launch {
|
||||
appDb.bookSourceDao.flowEnabledGroups().collect {
|
||||
groups = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +283,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
val searchScope = intent?.getStringExtra("searchScope")
|
||||
searchScope?.let {
|
||||
viewModel.searchScope.update(searchScope)
|
||||
upSearchScope()
|
||||
}
|
||||
val key = intent?.getStringExtra("key")
|
||||
if (key.isNullOrBlank()) {
|
||||
@@ -384,13 +419,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
|
||||
|
||||
override fun onSearchScopeOk(searchScope: SearchScope) {
|
||||
searchScope.save()
|
||||
viewModel.searchScope.update(searchScope.toString())
|
||||
if (!binding.llInputHelp.isVisible) {
|
||||
searchView.query?.toString()?.trim()?.let {
|
||||
searchView.setQuery(it, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun alertSearchScope() {
|
||||
|
||||
@@ -29,16 +29,19 @@ data class SearchScope(private var scope: String) {
|
||||
fun update(scope: String) {
|
||||
this.scope = scope
|
||||
stateLiveData.postValue(scope)
|
||||
save()
|
||||
}
|
||||
|
||||
fun update(groups: List<String>) {
|
||||
scope = groups.joinToString(",")
|
||||
stateLiveData.postValue(scope)
|
||||
save()
|
||||
}
|
||||
|
||||
fun update(source: BookSource) {
|
||||
scope = "${source.bookSourceName}::${source.bookSourceUrl}"
|
||||
stateLiveData.postValue(scope)
|
||||
save()
|
||||
}
|
||||
|
||||
fun isSource(): Boolean {
|
||||
@@ -69,12 +72,27 @@ data class SearchScope(private var scope: String) {
|
||||
list.add(it)
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
list.add(appCtx.getString(R.string.all_source))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun remove(scope: String) {
|
||||
if (isSource()) {
|
||||
this.scope = ""
|
||||
} else {
|
||||
val stringBuilder = StringBuilder()
|
||||
this.scope.split(",").forEach {
|
||||
if (it != scope) {
|
||||
if (stringBuilder.isNotEmpty()) {
|
||||
stringBuilder.append(",")
|
||||
}
|
||||
stringBuilder.append(it)
|
||||
}
|
||||
}
|
||||
this.scope = stringBuilder.toString()
|
||||
}
|
||||
stateLiveData.postValue(this.scope)
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索范围书源
|
||||
*/
|
||||
|
||||
@@ -48,15 +48,6 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title_bar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_searchScope"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp"
|
||||
android:text="@string/all_source"
|
||||
android:singleLine="true"
|
||||
android:gravity="center" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_book_show"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:ignore="AlwaysShowAction">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_search_scope"
|
||||
android:title="@string/search_scope"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_precision_search"
|
||||
android:checkable="true"
|
||||
@@ -19,9 +14,15 @@
|
||||
android:title="@string/book_source_manage"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_search_scope"
|
||||
android:title="@string/change_search_scope"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_log"
|
||||
android:title="@string/log"
|
||||
android:orderInCategory="9999"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -1047,4 +1047,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -1050,4 +1050,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -1050,4 +1050,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -1047,4 +1047,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -1049,4 +1049,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -1049,4 +1049,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
<item name="tag1" type="id" />
|
||||
<item name="tag2" type="id" />
|
||||
|
||||
<item name="menu_group_1" type="id" />
|
||||
<item name="menu_group_2" type="id" />
|
||||
|
||||
<item name="menu_1" type="id" />
|
||||
|
||||
<item name="fast_scroller" type="id" />
|
||||
|
||||
<item name="bettermovementmethod_highlight_background_span" type="id" />
|
||||
|
||||
@@ -1050,4 +1050,5 @@
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
<string name="change_search_scope">切换搜索范围</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user