优化
This commit is contained in:
@@ -51,6 +51,7 @@ 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,
|
||||||
@@ -235,7 +236,20 @@ 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)) {
|
||||||
scrollToBottom()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -367,6 +381,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
* 开始搜索
|
* 开始搜索
|
||||||
*/
|
*/
|
||||||
private fun startSearch() {
|
private fun startSearch() {
|
||||||
|
binding.refreshProgressBar.visible()
|
||||||
binding.refreshProgressBar.isAutoLoading = true
|
binding.refreshProgressBar.isAutoLoading = true
|
||||||
binding.fbStop.visible()
|
binding.fbStop.visible()
|
||||||
}
|
}
|
||||||
@@ -376,6 +391,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
*/
|
*/
|
||||||
private fun searchFinally() {
|
private fun searchFinally() {
|
||||||
binding.refreshProgressBar.isAutoLoading = false
|
binding.refreshProgressBar.isAutoLoading = false
|
||||||
|
binding.refreshProgressBar.gone()
|
||||||
binding.fbStop.invisible()
|
binding.fbStop.invisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user