@@ -2,14 +2,18 @@ package com.fmt.github.base.fragment
22
33import androidx.databinding.ObservableArrayList
44import androidx.lifecycle.Observer
5+ import androidx.recyclerview.widget.RecyclerView
6+ import com.bumptech.glide.Glide
57import com.fmt.github.R
68import com.fmt.github.ext.otherwise
79import com.fmt.github.ext.yes
810import com.kennyc.view.MultiStateView
911import com.scwang.smartrefresh.layout.api.RefreshLayout
1012import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
1113import com.scwang.smartrefresh.layout.listener.OnRefreshListener
14+ import kotlinx.android.synthetic.main.common_recyclerview.*
1215import kotlinx.android.synthetic.main.common_refresh_recyclerview.*
16+ import kotlinx.android.synthetic.main.common_refresh_recyclerview.mRecyclerView
1317
1418/* *
1519 * 分页列表页面封装
@@ -21,13 +25,34 @@ abstract class BaseListMVFragment<M> : BaseVMFragment(), OnRefreshListener,
2125
2226 protected var mPage = 1
2327
28+ private var mIsScrolling = false
29+
2430 override fun getLayoutRes (): Int = R .layout.common_refresh_recyclerview
2531
2632 override fun initView () {
2733 initRefreshLayout()
34+ initScrollListener()
2835 initRecyclerView()
2936 }
3037
38+ // RecyclerView 滑动时图片加载的优化
39+ private fun initScrollListener () {
40+ mRecyclerView.addOnScrollListener(object : RecyclerView .OnScrollListener () {
41+ override fun onScrollStateChanged (recyclerView : RecyclerView , newState : Int ) {
42+ super .onScrollStateChanged(recyclerView, newState)
43+ if (newState == RecyclerView .SCROLL_STATE_DRAGGING || newState == RecyclerView .SCROLL_STATE_SETTLING ) {
44+ mIsScrolling = true
45+ Glide .with (this @BaseListMVFragment).pauseRequests()
46+ } else if (newState == RecyclerView .SCROLL_STATE_IDLE ) {
47+ if (mIsScrolling) {
48+ Glide .with (this @BaseListMVFragment).resumeRequests()
49+ }
50+ mIsScrolling = false
51+ }
52+ }
53+ })
54+ }
55+
3156 private fun initRefreshLayout () {
3257 mRefreshLayout.run {
3358 setOnRefreshListener(this @BaseListMVFragment)
0 commit comments