CommonRefreshFooter.java
11.2 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package com.wd.common.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import com.scwang.smart.drawable.ProgressDrawable;
import com.scwang.smart.refresh.classics.ArrowDrawable;
import com.scwang.smart.refresh.classics.ClassicsAbstract;
import com.scwang.smart.refresh.layout.api.RefreshFooter;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.constant.RefreshState;
import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
import com.scwang.smart.refresh.layout.util.SmartUtil;
import com.wd.fastcoding.base.R;
/**
* 上拉加载更多 顶部
*
* @author liyubing
* @version [V1.0.0, 2022/8/29]
* @since V1.0.0
*/
public class CommonRefreshFooter extends ClassicsAbstract<CommonRefreshFooter> implements RefreshFooter {
public static String REFRESH_FOOTER_PULLING = null;//"上拉加载更多";
public static String REFRESH_FOOTER_RELEASE = null;//"释放立即加载";
public static String REFRESH_FOOTER_LOADING = null;//"正在加载...";
public static String REFRESH_FOOTER_REFRESHING = null;//"正在刷新...";
public static String REFRESH_FOOTER_FINISH = null;//"加载完成";
public static String REFRESH_FOOTER_FAILED = null;//"加载失败";
public static String REFRESH_FOOTER_NOTHING = null;//"没有更多数据了";
protected String mTextPulling;//"上拉加载更多";
protected String mTextRelease;//"释放立即加载";
protected String mTextLoading;//"正在加载...";
protected String mTextRefreshing;//"正在刷新...";
protected String mTextFinish;//"加载完成";
protected String mTextFailed;//"加载失败";
protected String mTextNothing;//"没有更多数据了";
protected boolean mNoMoreData = false;
private View leftLine;
private View rightLine;
//<editor-fold desc="LinearLayout">
public CommonRefreshFooter(Context context) {
this(context, null);
}
public CommonRefreshFooter(Context context, AttributeSet attrs) {
super(context, attrs, 0);
View.inflate(context, R.layout.common_classics_footer, this);
final View thisView = this;
final View arrowView = mArrowView = thisView.findViewById(R.id.srl_classics_arrow);
final View progressView = mProgressView = thisView.findViewById(R.id.srl_classics_progress);
mTitleText = thisView.findViewById(R.id.srl_classics_title);
leftLine = thisView.findViewById(R.id.vLeftLine);
rightLine = thisView.findViewById(R.id.vRightLine);
TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.ClassicsFooter);
LayoutParams lpArrow = (LayoutParams) arrowView.getLayoutParams();
LayoutParams lpProgress = (LayoutParams) progressView.getLayoutParams();
lpProgress.rightMargin = ta.getDimensionPixelSize(R.styleable.ClassicsFooter_srlDrawableMarginRight, SmartUtil.dp2px(20));
lpArrow.rightMargin = lpProgress.rightMargin;
lpArrow.width = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableArrowSize, lpArrow.width);
lpArrow.height = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableArrowSize, lpArrow.height);
lpProgress.width = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableProgressSize, lpProgress.width);
lpProgress.height = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableProgressSize, lpProgress.height);
lpArrow.width = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableSize, lpArrow.width);
lpArrow.height = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableSize, lpArrow.height);
lpProgress.width = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableSize, lpProgress.width);
lpProgress.height = ta.getLayoutDimension(R.styleable.ClassicsFooter_srlDrawableSize, lpProgress.height);
mFinishDuration = ta.getInt(R.styleable.ClassicsFooter_srlFinishDuration, mFinishDuration);
mSpinnerStyle = SpinnerStyle.values[ta.getInt(R.styleable.ClassicsFooter_srlClassicsSpinnerStyle, mSpinnerStyle.ordinal)];
if (ta.hasValue(R.styleable.ClassicsFooter_srlDrawableArrow)) {
mArrowView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsFooter_srlDrawableArrow));
} else if (mArrowView.getDrawable() == null) {
mArrowDrawable = new ArrowDrawable();
mArrowDrawable.setColor(0xff666666);
mArrowView.setImageDrawable(mArrowDrawable);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlDrawableProgress)) {
mProgressView.setImageDrawable(ta.getDrawable(R.styleable.ClassicsFooter_srlDrawableProgress));
} else if (mProgressView.getDrawable() == null) {
mProgressDrawable = new ProgressDrawable();
mProgressDrawable.setColor(0xff666666);
mProgressView.setImageDrawable(mProgressDrawable);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextSizeTitle)) {
mTitleText.setTextSize(TypedValue.COMPLEX_UNIT_PX, ta.getDimensionPixelSize(R.styleable.ClassicsFooter_srlTextSizeTitle, SmartUtil.dp2px(16)));
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlPrimaryColor)) {
super.setPrimaryColor(ta.getColor(R.styleable.ClassicsFooter_srlPrimaryColor, 0));
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlAccentColor)) {
super.setAccentColor(ta.getColor(R.styleable.ClassicsFooter_srlAccentColor, 0));
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextPulling)) {
mTextPulling = ta.getString(R.styleable.ClassicsFooter_srlTextPulling);
} else if (REFRESH_FOOTER_PULLING != null) {
mTextPulling = REFRESH_FOOTER_PULLING;
} else {
mTextPulling = context.getString(R.string.srl_footer_pulling);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextRelease)) {
mTextRelease = ta.getString(R.styleable.ClassicsFooter_srlTextRelease);
} else if (REFRESH_FOOTER_RELEASE != null) {
mTextRelease = REFRESH_FOOTER_RELEASE;
} else {
mTextRelease = context.getString(R.string.srl_footer_release);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextLoading)) {
mTextLoading = ta.getString(R.styleable.ClassicsFooter_srlTextLoading);
} else if (REFRESH_FOOTER_LOADING != null) {
mTextLoading = REFRESH_FOOTER_LOADING;
} else {
mTextLoading = context.getString(R.string.srl_footer_loading);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextRefreshing)) {
mTextRefreshing = ta.getString(R.styleable.ClassicsFooter_srlTextRefreshing);
} else if (REFRESH_FOOTER_REFRESHING != null) {
mTextRefreshing = REFRESH_FOOTER_REFRESHING;
} else {
mTextRefreshing = context.getString(R.string.srl_footer_refreshing);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextFinish)) {
mTextFinish = ta.getString(R.styleable.ClassicsFooter_srlTextFinish);
} else if (REFRESH_FOOTER_FINISH != null) {
mTextFinish = REFRESH_FOOTER_FINISH;
} else {
mTextFinish = context.getString(R.string.srl_footer_finish);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextFailed)) {
mTextFailed = ta.getString(R.styleable.ClassicsFooter_srlTextFailed);
} else if (REFRESH_FOOTER_FAILED != null) {
mTextFailed = REFRESH_FOOTER_FAILED;
} else {
mTextFailed = context.getString(R.string.srl_footer_failed);
}
if (ta.hasValue(R.styleable.ClassicsFooter_srlTextNothing)) {
mTextNothing = ta.getString(R.styleable.ClassicsFooter_srlTextNothing);
} else if (REFRESH_FOOTER_NOTHING != null) {
mTextNothing = REFRESH_FOOTER_NOTHING;
} else {
mTextNothing = context.getString(R.string.srl_footer_nothing);
}
ta.recycle();
progressView.animate().setInterpolator(null);
mTitleText.setText(thisView.isInEditMode() ? mTextLoading : mTextPulling);
if (thisView.isInEditMode()) {
arrowView.setVisibility(GONE);
} else {
progressView.setVisibility(GONE);
}
}
//</editor-fold>
//<editor-fold desc="RefreshFooter">
// @Override
// public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
// if (!mNoMoreData) {
// super.onStartAnimator(refreshLayout, height, maxDragHeight);
// }
// }
@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
super.onFinish(layout, success);
if (!mNoMoreData) {
mTitleText.setText(success ? mTextFinish : mTextFailed);
return mFinishDuration;
}
return 0;
}
/**
* @param colors 对应Xml中配置的 srlPrimaryColor srlAccentColor
* @deprecated 只由框架调用
* 使用者使用 {@link RefreshLayout#setPrimaryColorsId(int...)}
*/
@Override
@Deprecated
public void setPrimaryColors(@ColorInt int... colors) {
if (mSpinnerStyle == SpinnerStyle.FixedBehind) {
super.setPrimaryColors(colors);
}
}
/**
* 设置数据全部加载完成,将不能再次触发加载功能
*/
@Override
public boolean setNoMoreData(boolean noMoreData) {
if (mNoMoreData != noMoreData) {
mNoMoreData = noMoreData;
final View arrowView = mArrowView;
if (noMoreData) {
mTitleText.setText(mTextNothing);
arrowView.setVisibility(GONE);
leftLine.setVisibility(VISIBLE);
rightLine.setVisibility(VISIBLE);
} else {
mTitleText.setText(mTextPulling);
arrowView.setVisibility(VISIBLE);
leftLine.setVisibility(GONE);
rightLine.setVisibility(GONE);
}
}
return true;
}
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
final View arrowView = mArrowView;
if (!mNoMoreData) {
switch (newState) {
case None:
arrowView.setVisibility(VISIBLE);
case PullUpToLoad:
mTitleText.setText(mTextPulling);
arrowView.animate().rotation(180);
break;
case Loading:
case LoadReleased:
arrowView.setVisibility(GONE);
mTitleText.setText(mTextLoading);
break;
case ReleaseToLoad:
mTitleText.setText(mTextRelease);
arrowView.animate().rotation(0);
break;
case Refreshing:
mTitleText.setText(mTextRefreshing);
arrowView.setVisibility(GONE);
break;
}
}
}
//</editor-fold>
}