詹子聪 5 лет назад
Родитель
Сommit
d3f6e30fc6

+ 4 - 0
app/src/main/java/com/miekir/eden/ui/home/video/KwyVideoActivity.java

@@ -24,6 +24,8 @@ import io.reactivex.disposables.Disposable;
 import io.reactivex.schedulers.Schedulers;
 import q.rorbin.qrefreshlayout.QRefreshLayout;
 import q.rorbin.qrefreshlayout.listener.RefreshHandler;
+import q.rorbin.qrefreshlayout.widget.material.MaterialFooterView;
+import q.rorbin.qrefreshlayout.widget.material.MaterialHeaderView;
 
 
 /**
@@ -73,6 +75,8 @@ public class KwyVideoActivity extends Activity {
         js_video.setUp(EdenManager.getInstance().getVideoUrl(), mTitle);
         js_video.startVideo();
         refresh_video = findViewById(R.id.refresh_video);
+        refresh_video.setHeaderView(new MaterialHeaderView(this));
+        refresh_video.setFooterView(new MaterialFooterView(this));
 
         refresh_video.setLoadMoreEnable(true);
         refresh_video.setRefreshHandler(new RefreshHandler() {

+ 237 - 0
app/src/main/java/com/miekir/eden/widget/refresh/HeaderView.java

@@ -0,0 +1,237 @@
+package com.miekir.eden.widget.refresh;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
+import android.content.Context;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.miekir.eden.tool.StringTool;
+
+import q.rorbin.qrefreshlayout.QRefreshLayout;
+import q.rorbin.qrefreshlayout.R;
+import q.rorbin.qrefreshlayout.listener.TargetHandler;
+import q.rorbin.qrefreshlayout.util.RefreshAnimeUtil;
+import q.rorbin.qrefreshlayout.util.RefreshUtil;
+import q.rorbin.qrefreshlayout.widget.QLoadView;
+
+import static q.rorbin.qrefreshlayout.widget.ILoadView.STATE.COMPLETE;
+import static q.rorbin.qrefreshlayout.widget.ILoadView.STATE.PULL;
+import static q.rorbin.qrefreshlayout.widget.ILoadView.STATE.REFRESH;
+import static q.rorbin.qrefreshlayout.widget.ILoadView.STATE.START;
+
+
+/**
+ * LoadView默认实现
+ *
+ * @author chqiu
+ */
+public class HeaderView extends QLoadView {
+    protected STATE mState;
+    protected int mMeasuredHeight;
+    protected ImageView mIvIcon;
+    protected TextView mTvTips;
+    protected ProgressBar mProgressBar;
+    protected final int mMargin = RefreshUtil.dp2px(getContext(), 15);
+    protected ViewGroup mContent;
+//    int i = 0;
+
+    public HeaderView(Context context) {
+        super(context);
+        init();
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
+        int width = getMeasuredWidth();
+        int height = getMeasuredHeight();
+        mMeasuredHeight = mContent.getMeasuredHeight() + mMargin * 2;
+        mContent.layout(0, height - mContent.getMeasuredHeight() - mMargin, width, height - mMargin);
+    }
+
+    @Override
+    public boolean canTargetScroll() {
+        return getHeight() <= 0;
+    }
+
+    private void setRefreshState() {
+        if (mState != REFRESH) {
+            mIvIcon.setVisibility(View.GONE);
+            mProgressBar.setVisibility(View.VISIBLE);
+            mTvTips.setText(getStateTips(REFRESH));
+            mState = REFRESH;
+        }
+    }
+
+    private void setStartState() {
+        if (mState != START) {
+            mIvIcon.setVisibility(View.VISIBLE);
+            mProgressBar.setVisibility(View.GONE);
+            if (mState == PULL) {
+                ObjectAnimator.ofFloat(mIvIcon, "rotation", 180, 0).start();
+            }
+            mTvTips.setText(getStateTips(START));
+            mState = START;
+        }
+    }
+
+    private void setPullState() {
+        if (mState != PULL) {
+            mIvIcon.setVisibility(View.VISIBLE);
+            mProgressBar.setVisibility(View.GONE);
+            if (mState == START) {
+                ObjectAnimator.ofFloat(mIvIcon, "rotation", 0, 180).start();
+            }
+            mTvTips.setText(getStateTips(PULL));
+            mState = PULL;
+        }
+    }
+
+    private void setCompleteState() {
+        if (mState != COMPLETE) {
+            mIvIcon.setVisibility(View.GONE);
+            mProgressBar.setVisibility(View.GONE);
+            mTvTips.setText(getStateTips(COMPLETE));
+            mState = COMPLETE;
+            mIvIcon.setRotation(0);
+        }
+    }
+
+    protected String getStateTips(STATE state) {
+        /*if (state == REFRESH) {
+            return getContext().getString(R.string.loading_tips);
+        } else if (state == START) {
+            return getContext().getString(R.string.normal_tips);
+        } else if (state == PULL) {
+            return getContext().getString(R.string.pulling_tips);
+        } else if (state == COMPLETE) {
+            return getContext().getString(R.string.complete_tips);
+        }*/
+        return StringTool.getString(com.miekir.eden.R.string.text_loading);
+    }
+
+    @Override
+    public STATE getState() {
+        return mState;
+    }
+
+    @Override
+    public void setState(STATE state) {
+        if (state == REFRESH) {
+            setRefreshState();
+        } else if (state == START) {
+            setStartState();
+        } else if (state == PULL) {
+            setPullState();
+        } else if (state == COMPLETE) {
+            setCompleteState();
+        }
+    }
+
+    @Override
+    public void onPrepare(View targetView) {
+        RefreshAnimeUtil.startHeightAnime(this, targetView, getTargetHandler(), 0, new AnimeListener());
+    }
+
+    @Override
+    public void onRefreshBegin(View targetView) {
+        RefreshAnimeUtil.startHeightAnime(this, targetView, getTargetHandler(), mMeasuredHeight, null);
+    }
+
+    @Override
+    public void onPulling(float dis, View targetView) {
+        LayoutParams params = (LayoutParams) getLayoutParams();
+        if (dis > 0) {
+            if (mState == REFRESH) {
+                params.height += 30;
+                if (params.height > mMeasuredHeight) params.height = mMeasuredHeight;
+            } else {
+//                i += dis;
+                params.height += dis;
+            }
+        } else if (dis < 0) {
+            params.height += dis;
+            if (params.height < 0) {
+                params.height = 0;
+            }
+        }
+        setLayoutParams(params);
+        getTargetHandler().handleTarget(targetView, params.height);
+    }
+
+    @Override
+    public void addToRefreshLayout(QRefreshLayout layout) {
+        QRefreshLayout.LayoutParams params =
+                new QRefreshLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+        layout.addView(this, params);
+        params.height = 0;
+        setLayoutParams(params);
+    }
+
+    protected TargetHandler getTargetHandler() {
+        return new TargetHandler() {
+            @Override
+            public void handleTarget(View targetView, float dis) {
+                targetView.setTranslationY(dis);
+            }
+        };
+    }
+
+    private void init() {
+        LinearLayout content = new LinearLayout(getContext());
+        content.setGravity(Gravity.CENTER);
+        content.setOrientation(LinearLayout.HORIZONTAL);
+        mContent = content;
+        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+        addView(mContent, lp);
+        initContentView();
+    }
+
+    protected int getIconRes() {
+        return R.drawable.icon_pull;
+    }
+
+    private void initContentView() {
+        mContent.removeAllViews();
+        ImageView imageView = new ImageView(getContext());
+        LinearLayout.LayoutParams imageViewParmas =
+                new LinearLayout.LayoutParams(RefreshUtil.dp2px(getContext(), 20), RefreshUtil.dp2px(getContext(), 20));
+        imageViewParmas.setMargins(0, 0, RefreshUtil.dp2px(getContext(), 10), 0);
+        imageView.setLayoutParams(imageViewParmas);
+        imageView.setImageResource(getIconRes());
+        mContent.addView(imageView);
+
+        ProgressBar progress = new ProgressBar(getContext());
+        LinearLayout.LayoutParams progressParmas =
+                new LinearLayout.LayoutParams(RefreshUtil.dp2px(getContext(), 20), RefreshUtil.dp2px(getContext(), 20));
+        progressParmas.setMargins(0, 0, RefreshUtil.dp2px(getContext(), 10), 0);
+        progress.setLayoutParams(progressParmas);
+        progress.setVisibility(View.GONE);
+        mContent.addView(progress);
+
+        TextView tvTips = new TextView(getContext());
+        tvTips.setText(getStateTips(START));
+        mContent.addView(tvTips);
+
+        mIvIcon = imageView;
+        mTvTips = tvTips;
+        mTvTips.setTextColor(getContext().getResources().getColor(com.miekir.eden.R.color.white));
+        mProgressBar = progress;
+
+        mState = START;
+    }
+
+    private class AnimeListener extends AnimatorListenerAdapter {
+
+        @Override
+        public void onAnimationEnd(Animator animation) {
+            setState(START);
+        }
+    }
+}

+ 0 - 57
app/src/main/java/com/miekir/eden/widget/refresh/LoadView.java

@@ -1,57 +0,0 @@
-package com.miekir.eden.widget.refresh;
-
-import android.view.View;
-
-import q.rorbin.qrefreshlayout.QRefreshLayout;
-import q.rorbin.qrefreshlayout.widget.ILoadView;
-
-/**
- * Copyright (C), 2019-2020, Miekir
- *
- * @author Miekir
- * @date 2020/9/21 14:26
- * Description:
- */
-public class LoadView implements ILoadView {
-
-
-    @Override
-    public STATE getState() {
-        return null;
-    }
-
-    @Override
-    public boolean canTargetScroll() {
-        return false;
-    }
-
-    @Override
-    public void onRefreshBegin(View targetView) {
-
-    }
-
-    @Override
-    public void setState(STATE state) {
-
-    }
-
-    @Override
-    public void onPrepare(View targetView) {
-
-    }
-
-    @Override
-    public void onPulling(float dis, View targetView) {
-
-    }
-
-    @Override
-    public void addToRefreshLayout(QRefreshLayout layout) {
-
-    }
-
-    @Override
-    public View getView() {
-        return null;
-    }
-}

+ 1 - 1
app/src/main/res/layout/activity_goods_detail.xml

@@ -4,7 +4,7 @@
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"
     android:orientation="vertical"
-    android:background="@color/white">
+    android:background="@color/white_default">
 
     <include layout="@layout/view_toolbar" />
 

+ 1 - 1
app/src/main/res/layout/activity_json.xml

@@ -3,7 +3,7 @@
     android:id="@+id/ll_search"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="@color/white"
+    android:background="@color/white_default"
     android:focusable="true"
     android:focusableInTouchMode="true"
     android:fitsSystemWindows="true"

+ 2 - 1
app/src/main/res/layout/activity_login.xml

@@ -6,7 +6,8 @@
     android:fitsSystemWindows="true"
     android:orientation="vertical"
     android:focusable="true"
-    android:focusableInTouchMode="true">
+    android:focusableInTouchMode="true"
+    android:background="@color/white_default">
     <!--启用深色模式之后,需要使用fitsSystemWindows来不让布局上滑-->
 
     <include layout="@layout/view_toolbar" />

+ 4 - 3
app/src/main/res/layout/activity_mine.xml

@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="vertical">
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:background="@color/white_default">
     <include layout="@layout/view_toolbar"/>
 
     <ScrollView
@@ -11,7 +12,7 @@
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:fillViewport="true"
         android:fitsSystemWindows="true"
-        android:background="@color/white">
+        android:background="@color/white_default">
 
         <LinearLayout
             android:layout_width="match_parent"

+ 3 - 2
app/src/main/res/layout/activity_my_fav.xml

@@ -2,12 +2,13 @@
 <!--搜索栏-->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="match_parent"
     android:orientation="vertical"
     android:id="@+id/ll_search"
     android:focusable="true"
     android:focusableInTouchMode="true"
-    android:fitsSystemWindows="true">
+    android:fitsSystemWindows="true"
+    android:background="@color/white_default">
 
     <include layout="@layout/view_toolbar"/>
 

+ 5 - 5
app/src/main/res/layout/activity_search.xml

@@ -2,12 +2,13 @@
 <!--搜索栏-->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="match_parent"
     android:orientation="vertical"
     android:id="@+id/ll_search"
     android:focusable="true"
     android:focusableInTouchMode="true"
-    android:fitsSystemWindows="true">
+    android:fitsSystemWindows="true"
+    android:background="@color/white_default">
 
     <include layout="@layout/view_toolbar"/>
 
@@ -15,15 +16,14 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
-        android:gravity="center_vertical"
-        android:background="@color/white">
+        android:gravity="center_vertical">
         <EditText
             android:id="@+id/et_search"
             android:layout_width="0dp"
             android:layout_weight="1"
             android:layout_height="wrap_content"
             android:minHeight="@dimen/height_tab_bar"
-            android:background="@color/white"
+            android:background="@color/white_default"
             android:singleLine="true"
             android:paddingStart="@dimen/margin_default"
             android:paddingEnd="@dimen/margin_default"

+ 3 - 1
app/src/main/res/layout/activity_video_play.xml

@@ -1,8 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <q.rorbin.qrefreshlayout.QRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:id="@+id/refresh_video">
+    android:id="@+id/refresh_video"
+    app:resistance="0.1">
 
     <cn.jzvd.JzvdStd
         android:id="@+id/js_video"

+ 4 - 3
app/src/main/res/values-v28/styles.xml

@@ -10,7 +10,7 @@
         <item name="colorAccent">@color/colorAccent</item>
 
         <!--导航栏颜色-->
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
         <item name="android:windowLightNavigationBar">true</item>
     </style>
@@ -34,6 +34,7 @@
 
         <!--不需要动画-->
         <!--<item name="android:windowAnimationStyle">@null</item>-->
+        <item name="android:navigationBarColor">@color/white_default</item>
     </style>
 
 
@@ -76,7 +77,7 @@
         <!--<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>-->
 
         <!--导航栏颜色-->
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
         <item name="android:windowLightNavigationBar">true</item>
     </style>
@@ -96,7 +97,7 @@
 
         <!--<item name="android:windowAnimationStyle">@null</item>-->
         <!--导航栏颜色-->
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
         <item name="android:windowDrawsSystemBarBackgrounds">true</item>
         <item name="android:windowLightNavigationBar">true</item>
     </style>

+ 1 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -105,4 +105,5 @@
     <string name="video_beauty">美女短视频</string>
     <string name="video_play_next">播放下一个</string>
     <string name="resource_copied">已拷贝链接</string>
+    <string name="text_loading">加载中...</string>
 </resources>

+ 1 - 1
app/src/main/res/values/colors.xml

@@ -27,7 +27,7 @@
     <color name="gray_divider_light">#d9d9d9</color>
     <color name="gray_divider_light_transparent">#80D9D9D9</color>
     <color name="gray_divider_light_s">#ebebeb</color>
-    <color name="gray_divider_light_ss">#eeeeee</color>
+    <color name="white_default">#eeeeee</color>
     <!--<color name="gray_divider_light_ss">#f0f0f0</color>-->
     <color name="gray_loading">#26E0E0E0</color>
     <color name="gray_tab_unchecked">#717171</color>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -105,4 +105,5 @@
     <string name="video_beauty">Video of beauty</string>
     <string name="video_play_next">Play Next Video</string>
     <string name="resource_copied">Resource url copied</string>
+    <string name="text_loading">Loading...</string>
 </resources>

+ 4 - 4
app/src/main/res/values/styles.xml

@@ -9,7 +9,7 @@
         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
         <item name="colorAccent">@color/colorAccent</item>
 
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
     </style>
 
     <style name="SplashTheme" parent="AppTheme">
@@ -31,7 +31,7 @@
 
         <!--不需要动画-->
         <!--<item name="android:windowAnimationStyle">@null</item>-->
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
     </style>
 
 
@@ -73,7 +73,7 @@
         <!--加了下面这句会导致状态栏文字颜色变黑色-->
         <!--<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>-->
 
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
     </style>
 
 
@@ -91,7 +91,7 @@
 
         <!--<item name="android:windowAnimationStyle">@null</item>-->
 
-        <item name="android:navigationBarColor">@color/white</item>
+        <item name="android:navigationBarColor">@color/white_default</item>
     </style>
 
     <style name="AppTheme.MeizhiDetail" parent="Theme.AppCompat.Light.NoActionBar">