更新界面

增加搜索进度
增加初次使用引导界面
This commit is contained in:
HapeLee committed 2025-08-27 03:44:43 +08:00
1 parent 50abb9b552
commit 3327f181bd
5 files changed
+57 -11

No files matched your search

@@ -1,5 +1,6 @@
package io.legato.kazusa.ui.book.search
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
@@ -199,7 +200,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
)
}
searchBar.setOnMenuItemClickListener { item ->
onCompatOptionsItemSelected(item)
}
@@ -429,6 +429,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
*/
private fun startSearch() {
binding.refreshProgressBar.visible()
binding.cdProgress.gone()
//binding.refreshProgressBar.isAutoLoading = true
binding.fbStartStop.setImageResource(R.drawable.ic_stop_black_24dp)
binding.fbStartStop.visible()
@@ -438,7 +439,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 搜索结束
*/
private fun searchFinally() {
binding.refreshProgressBar.gone()
binding.refreshProgressBar.invisible()
binding.cdProgress.gone()
if (!isManualStopSearch && viewModel.hasMore) {
binding.fbStartStop.setImageResource(R.drawable.ic_play_24dp)
} else {
@@ -446,10 +448,16 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
}
@SuppressLint("SetTextI18n")
override fun observeLiveBus() {
viewModel.upAdapterLiveData.observe(this) {
adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(it to null))
}
viewModel.searchProgressLiveData.observe(this) { (processed, total) ->
val progress = (processed * 100 / total).coerceAtMost(100)
binding.refreshProgressBar.setProgress(progress, true)
binding.tvProgress.text = "$processed / $total"
}
viewModel.searchFinishLiveData.observe(this) { isEmpty ->
if (!isEmpty || viewModel.searchScope.isAll()) return@observe
alert("搜索结果为空") {
@@ -29,6 +29,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
var searchFinishLiveData = MutableLiveData<Boolean>()
var isSearchLiveData = MutableLiveData<Boolean>()
val searchProgressLiveData = MutableLiveData<Pair<Int, Int>>()
var searchKey: String = ""
var hasMore = true
private var searchID = 0L
@@ -42,8 +45,11 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
isSearchLiveData.postValue(true)
}
override fun onSearchSuccess(searchBooks: List<SearchBook>) {
override fun onSearchSuccess(
searchBooks: List<SearchBook>, processedSources: Int, totalSources: Int
) {
searchBookLiveData.postValue(searchBooks)
searchProgressLiveData.postValue(Pair(processedSources, totalSources))
}
override fun onSearchFinish(isEmpty: Boolean, hasMore: Boolean) {