|
@@ -0,0 +1,154 @@
|
|
|
+package io.rong.imkit.widget.refresh.wrapper;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+
|
|
|
+import com.airbnb.lottie.LottieAnimationView;
|
|
|
+import com.cooleshow.base.R;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import io.rong.imkit.widget.refresh.api.RefreshHeader;
|
|
|
+import io.rong.imkit.widget.refresh.api.RefreshKernel;
|
|
|
+import io.rong.imkit.widget.refresh.api.RefreshLayout;
|
|
|
+import io.rong.imkit.widget.refresh.constant.RefreshState;
|
|
|
+import io.rong.imkit.widget.refresh.constant.SpinnerStyle;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2022/7/29.
|
|
|
+ */
|
|
|
+public class RongCustomRefreshHeader extends FrameLayout implements RefreshHeader {
|
|
|
+
|
|
|
+ private LottieAnimationView mViewAnim;
|
|
|
+
|
|
|
+ public RongCustomRefreshHeader(@NonNull Context context) {
|
|
|
+ this(context, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RongCustomRefreshHeader(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
+ this(context, attrs, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RongCustomRefreshHeader(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() {
|
|
|
+ LayoutInflater.from(getContext()).inflate(R.layout.view_custom_refresh_header_layout, this);
|
|
|
+ mViewAnim = findViewById(R.id.view_anim);
|
|
|
+ mViewAnim.setAnimation("lottie/refresh_anim.json");
|
|
|
+ mViewAnim.loop(true);
|
|
|
+ mViewAnim.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public View getView() {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public SpinnerStyle getSpinnerStyle() {
|
|
|
+ return SpinnerStyle.Translate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setPrimaryColors(int... colors) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDragHeight) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onMoving(boolean isDragging, float percent, int offset, int height, int maxDragHeight) {
|
|
|
+ LogUtils.i("pq", "onMoving isDragging:" + isDragging + "\npercent:" + percent + "\noffset:" + offset
|
|
|
+ + "\nheight:" + height + "\nmaxDragHeight:" + maxDragHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReleased(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
|
|
|
+ LogUtils.i("pq", "onReleased height:" + height + "\nmaxDragHeight:" + maxDragHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) {
|
|
|
+ if (mViewAnim != null) {
|
|
|
+ mViewAnim.cancelAnimation();
|
|
|
+ mViewAnim.clearAnimation();
|
|
|
+ }
|
|
|
+ LogUtils.i("pq", "onFinish");
|
|
|
+ return 500;//延迟500毫秒之后再弹回;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onHorizontalDrag(float percentX, int offsetX, int offsetMax) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isSupportHorizontalDrag() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
|
|
|
+ switch (newState) {
|
|
|
+ case None:
|
|
|
+ LogUtils.i("pq", "None");
|
|
|
+ mViewAnim.setFrame(0);
|
|
|
+ mViewAnim.setProgress(0);
|
|
|
+ break;
|
|
|
+ case PullDownToRefresh:
|
|
|
+ LogUtils.i("pq", "PullDownToRefresh");
|
|
|
+ playAnim();
|
|
|
+ mViewAnim.setVisibility(View.VISIBLE);
|
|
|
+ break;
|
|
|
+ case PullDownCanceled:
|
|
|
+ if (mViewAnim != null) {
|
|
|
+ clearAnim();
|
|
|
+ }
|
|
|
+ LogUtils.i("pq", "PullDownCanceled");
|
|
|
+ break;
|
|
|
+ case ReleaseToRefresh:
|
|
|
+ LogUtils.i("pq", "ReleaseToRefresh");
|
|
|
+ mViewAnim.setVisibility(View.VISIBLE);
|
|
|
+ break;
|
|
|
+ case Refreshing:
|
|
|
+ LogUtils.i("pq", "Refreshing");
|
|
|
+ break;
|
|
|
+ case RefreshReleased:
|
|
|
+ LogUtils.i("pq", "RefreshReleased");
|
|
|
+ break;
|
|
|
+ case RefreshFinish:
|
|
|
+ LogUtils.i("pq", "RefreshFinish");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void playAnim() {
|
|
|
+ if (mViewAnim != null) {
|
|
|
+ mViewAnim.playAnimation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearAnim() {
|
|
|
+ if (mViewAnim != null) {
|
|
|
+ mViewAnim.cancelAnimation();
|
|
|
+ mViewAnim.clearAnimation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|