@@ -2,14 +2,18 @@ package com.fmt.github.base.fragment
2
2
3
3
import androidx.databinding.ObservableArrayList
4
4
import androidx.lifecycle.Observer
5
+ import androidx.recyclerview.widget.RecyclerView
6
+ import com.bumptech.glide.Glide
5
7
import com.fmt.github.R
6
8
import com.fmt.github.ext.otherwise
7
9
import com.fmt.github.ext.yes
8
10
import com.kennyc.view.MultiStateView
9
11
import com.scwang.smartrefresh.layout.api.RefreshLayout
10
12
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
11
13
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
14
+ import kotlinx.android.synthetic.main.common_recyclerview.*
12
15
import kotlinx.android.synthetic.main.common_refresh_recyclerview.*
16
+ import kotlinx.android.synthetic.main.common_refresh_recyclerview.mRecyclerView
13
17
14
18
/* *
15
19
* 分页列表页面封装
@@ -21,13 +25,34 @@ abstract class BaseListMVFragment<M> : BaseVMFragment(), OnRefreshListener,
21
25
22
26
protected var mPage = 1
23
27
28
+ private var mIsScrolling = false
29
+
24
30
override fun getLayoutRes (): Int = R .layout.common_refresh_recyclerview
25
31
26
32
override fun initView () {
27
33
initRefreshLayout()
34
+ initScrollListener()
28
35
initRecyclerView()
29
36
}
30
37
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
+
31
56
private fun initRefreshLayout () {
32
57
mRefreshLayout.run {
33
58
setOnRefreshListener(this @BaseListMVFragment)
0 commit comments