riku
2022-02-18 d59d55575d913646b7a90fca651904ab889c6723
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cn.flightfeather.thirdappmodule.view.recyclerview
 
import android.support.v4.widget.SwipeRefreshLayout
 
/**
 * @author riku
 * Date: 2019/5/17
 */
interface SwipeRefreshLayoutSetInterface {
 
    fun initSwipeRefreshLayout(){
        //下拉刷新
        getSwipeRefreshLayout()?.let {
            it.isEnabled = needSwipeRefresh()
            if (getColorList().size == 3) {
                it.setColorSchemeColors(getColorList()[0], getColorList()[1], getColorList()[2])
            }
            it.setOnRefreshListener {
                onRefreshRequested()
                it.postDelayed({
                    it.isRefreshing = false
                }, 10000)
            }
        }
    }
 
    fun startRefresh(){
        if (enableRefresh()) {
            onRefreshRequested()
            if (needSwipeRefresh()) {
                getSwipeRefreshLayout()?.let {
                    it.isRefreshing = true
                    it.postDelayed({
                        it.isRefreshing = false
                    }, 10000)
                }
            }
        }
    }
 
    fun stopRefresh(){
        if (enableRefresh()) {
            if (getSwipeRefreshLayout()?.isRefreshing == true) {
                getSwipeRefreshLayout()?.isRefreshing = false
            }
        }
    }
 
    fun getSwipeRefreshLayout(): SwipeRefreshLayout?
 
    //是否允许默认第一次自动刷新
    fun enableRefresh(): Boolean
 
    //启用layout动画效果的下拉刷新,能够手动刷新
    fun needSwipeRefresh():Boolean
 
    fun onRefreshRequested()
 
    fun getColorList(): Array<Int>
 
}