项目中下拉刷新 自定义相关
JerryAlexLiang opened this issue · 3 comments
JerryAlexLiang commented
你好,请问 项目中 下拉刷新自定义 布局 作者是在哪个地方进行修改的呢?
JerryAlexLiang commented
BaseApp
我看到这里了,我是想咨询 最新版本的项目中 下拉刷新 自定义的诗句刷新 布局 是在哪里写的?没找到,谢谢
goweii commented
最新的代码没有上传,暂时不上传了。
刷新头移到WanApp里了
public class WanApp extends BaseApp {
static {
SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
@NonNull
@Override
public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
return new ShiciRefreshHeader(context);
}
});
SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
@NonNull
@Override
public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
return new ClassicsFooter(context);
}
});
}
}
诗词刷新头
public class ShiciRefreshHeader extends InternalClassics<ShiciRefreshHeader> implements RefreshHeader {
public static String REFRESH_HEADER_PULLING = "下拉刷新";
public static String REFRESH_HEADER_REFRESHING = "正在刷新";
public static String REFRESH_HEADER_LOADING = "正在加载";
public static String REFRESH_HEADER_RELEASE = "释放刷新";
public static String REFRESH_HEADER_FINISH = "刷新完成";
public static String REFRESH_HEADER_FAILED = "刷新失败";
private String textPulling() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_PULLING;
}
return shici;
}
private String textRefreshing() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_REFRESHING;
}
return shici;
}
private String textLoading() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_LOADING;
}
return shici;
}
private String textRelease() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_RELEASE;
}
return shici;
}
private String textFinish() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_FINISH;
}
return shici;
}
private String textFailed() {
String shici = ShiciRefreshHolder.instance().get();
if (TextUtils.isEmpty(shici)) {
return REFRESH_HEADER_FAILED;
}
return shici;
}
public ShiciRefreshHeader(Context context) {
this(context, null);
}
public ShiciRefreshHeader(Context context, AttributeSet attrs) {
super(context, attrs, 0);
View.inflate(context, R.layout.layout_shici_refresh_header, 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);
int color = ContextCompat.getColor(context, R.color.text_surface);
mTitleText = thisView.findViewById(R.id.srl_classics_title);
progressView.animate().setInterpolator(null);
mTitleText.setTextColor(color);
mArrowDrawable = new ArrowDrawable();
mArrowDrawable.setColor(color);
mArrowView.setImageDrawable(mArrowDrawable);
mProgressDrawable = new ProgressDrawable();
mProgressDrawable.setColor(color);
mProgressView.setImageDrawable(mProgressDrawable);
if (thisView.isInEditMode()) {
arrowView.setVisibility(GONE);
} else {
progressView.setVisibility(GONE);
}
setAlpha(0.4F);
ShiciRefreshHolder.instance();
}
@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
if (success) {
mTitleText.setText(textFinish());
} else {
mTitleText.setText(textFailed());
}
return super.onFinish(layout, success);
}
private boolean shouldRefreshShici = false;
@Override
public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
final View arrowView = mArrowView;
switch (newState) {
case None:
if (shouldRefreshShici) {
shouldRefreshShici = false;
ShiciRefreshHolder.instance().refresh();
}
case PullDownToRefresh:
mTitleText.setText(textPulling());
arrowView.setVisibility(VISIBLE);
arrowView.animate().rotation(0);
break;
case Refreshing:
shouldRefreshShici = true;
case RefreshReleased:
mTitleText.setText(textRefreshing());
arrowView.setVisibility(GONE);
break;
case ReleaseToRefresh:
mTitleText.setText(textRelease());
arrowView.animate().rotation(180);
break;
case Loading:
arrowView.setVisibility(GONE);
mTitleText.setText(textLoading());
break;
}
}
}
public class ShiciRefreshHolder {
private static ShiciRefreshHolder instance = null;
private static final int MAX_SIZE = 3;
public static ShiciRefreshHolder instance() {
if (instance == null) {
instance = new ShiciRefreshHolder();
}
return instance;
}
private final RxLife mRxLife;
private final List<String> mCache = new ArrayList<>(MAX_SIZE);
private ShiciRefreshHolder() {
mRxLife = RxLife.create();
request();
}
private void request() {
if (mCache.size() >= MAX_SIZE) {
return;
}
MainRequest.getJinrishici(mRxLife, new RequestCallback<JinrishiciBean>() {
@Override
public void onSuccess(int code, JinrishiciBean data) {
mCache.add(data.getContent());
request();
}
@Override
public void onFailed(int code, String msg) {
}
});
}
public void refresh() {
if (mCache.size() >= 2) {
mCache.remove(0);
}
request();
}
public String get() {
if (mCache.isEmpty()) {
return null;
}
return mCache.get(0);
}
}