|
@@ -54,7 +54,6 @@ import kotlinx.coroutines.flow.flowOn
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
import splitties.init.appCtx
|
|
import splitties.init.appCtx
|
|
|
-import kotlin.math.abs
|
|
|
|
|
|
|
|
|
|
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
|
|
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
|
|
|
BookAdapter.CallBack,
|
|
BookAdapter.CallBack,
|
|
@@ -240,20 +239,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
|
super.onScrolled(recyclerView, dx, dy)
|
|
super.onScrolled(recyclerView, dx, dy)
|
|
|
if (!recyclerView.canScrollVertically(1)) {
|
|
if (!recyclerView.canScrollVertically(1)) {
|
|
|
- val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
|
|
|
|
- val lastPosition = layoutManager.findLastCompletelyVisibleItemPosition()
|
|
|
|
|
- if (lastPosition == RecyclerView.NO_POSITION) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- val lastView = layoutManager.findViewByPosition(lastPosition)
|
|
|
|
|
- if (lastView == null) {
|
|
|
|
|
- scrollToBottom()
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- val bottom = abs(lastView.bottom - recyclerView.height)
|
|
|
|
|
- if (bottom <= 1) {
|
|
|
|
|
- scrollToBottom()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ scrollToBottom()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -324,6 +310,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|
|
}
|
|
}
|
|
|
if (viewModel.isSearchLiveData.value == false
|
|
if (viewModel.isSearchLiveData.value == false
|
|
|
&& viewModel.searchKey.isNotEmpty()
|
|
&& viewModel.searchKey.isNotEmpty()
|
|
|
|
|
+ && viewModel.hasMore
|
|
|
) {
|
|
) {
|
|
|
viewModel.search("")
|
|
viewModel.search("")
|
|
|
}
|
|
}
|
|
@@ -407,8 +394,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|
|
if (!isEmpty || viewModel.searchScope.isAll()) return@observe
|
|
if (!isEmpty || viewModel.searchScope.isAll()) return@observe
|
|
|
alert("搜索结果为空") {
|
|
alert("搜索结果为空") {
|
|
|
val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
|
|
val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
|
|
|
|
|
+ val displayScope = viewModel.searchScope.display
|
|
|
if (precisionSearch) {
|
|
if (precisionSearch) {
|
|
|
- setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否关闭精准搜索?")
|
|
|
|
|
|
|
+ setMessage("${displayScope}分组搜索结果为空,是否关闭精准搜索?")
|
|
|
yesButton {
|
|
yesButton {
|
|
|
appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
|
|
appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
|
|
|
precisionSearchMenuItem?.isChecked = false
|
|
precisionSearchMenuItem?.isChecked = false
|
|
@@ -416,7 +404,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|
|
viewModel.search(searchView.query.toString())
|
|
viewModel.search(searchView.query.toString())
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否切换到全部分组?")
|
|
|
|
|
|
|
+ setMessage("${displayScope}分组搜索结果为空,是否切换到全部分组?")
|
|
|
yesButton {
|
|
yesButton {
|
|
|
viewModel.searchScope.update("")
|
|
viewModel.searchScope.update("")
|
|
|
}
|
|
}
|