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