Browse Source

修改学生端首页吸顶动画

Pq 2 years ago
parent
commit
3fbdb889bb

+ 1 - 0
BaseLibrary/src/main/res/values/colors.xml

@@ -123,6 +123,7 @@
     <color name="color_ff8b39">#FF8B39</color>
     <color name="color_ff4046">#ff4046</color>
     <color name="color_ff8901">#FF8901</color>
+    <color name="color_f9f9f9">#f9f9f9</color>
 
     <color name="color_25292e">#25292E</color>
     <color name="color_F8F8F8">#F8F8F8</color>

+ 15 - 0
student/src/main/java/com/cooleshow/student/adapter/HomeHotNewsAdapter.java

@@ -12,6 +12,8 @@ import com.cooleshow.student.bean.AppHomeBean;
 
 import java.util.List;
 
+import androidx.constraintlayout.widget.ConstraintLayout;
+
 /**
  * 创建日期:2022/5/27 10:37
  *
@@ -40,6 +42,19 @@ public class HomeHotNewsAdapter extends BaseQuickAdapter<AppHomeBean.ItemBean, B
         int position = helper.getLayoutPosition();
         View lineView = helper.getView(R.id.view_line);
         lineView.setVisibility(position == 0 ? View.GONE : View.VISIBLE);
+        ConstraintLayout cs_root = helper.getView(R.id.cs_root);
+        int size = getData().size();
+        if(size == 1){
+            cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_10dp);
+        }else{
+            if(position == 0){
+                cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_top_10dp);
+            }else if(position == size-1){
+                cs_root.setBackgroundResource(com.cooleshow.base.R.drawable.bg_white_bottom_10dp);
+            }else{
+                cs_root.setBackgroundColor(getContext().getResources().getColor(R.color.white));
+            }
+        }
     }
 
 }

+ 39 - 33
student/src/main/java/com/cooleshow/student/presenter/main/HomePresenter.java

@@ -218,13 +218,13 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
                         Log.i("pq", "匹配直播线程:" + Thread.currentThread().getName());
                         if (arrayListBaseResponse != null) {
                             ArrayList<TempLiveTeacherListBean> data = arrayListBaseResponse.getData();
-                            if (data != null && data.size() > 0) {
-                                for (int i = data.size() - 1; i >= 0; i--) {
-                                    if (homeStyleBeanBaseResponse != null && homeStyleBeanBaseResponse.getData() != null) {
-                                        List<HomeStyleBean.RowsBean> rows = homeStyleBeanBaseResponse.getData().rows;
-                                        if (rows == null) {
-                                            rows = new ArrayList<>();
-                                        }
+                            if (homeStyleBeanBaseResponse != null && homeStyleBeanBaseResponse.getData() != null) {
+                                List<HomeStyleBean.RowsBean> rows = homeStyleBeanBaseResponse.getData().rows;
+                                if (rows == null) {
+                                    rows = new ArrayList<>();
+                                }
+                                if (data != null && data.size() > 0) {
+                                    for (int i = data.size() - 1; i >= 0; i--) {
                                         TempLiveTeacherListBean tempLiveTeacherListBean = data.get(i);
                                         HomeStyleBean.RowsBean rowsBean = new HomeStyleBean.RowsBean();
                                         rowsBean.liveCoverImg = tempLiveTeacherListBean.liveCoverImg;
@@ -259,36 +259,42 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
                     }
                 });
             }
-        }).subscribeOn(Schedulers.newThread())
-                .observeOn(AndroidSchedulers.mainThread())
-                .subscribe(new Observer<BaseResponse<HomeStyleBean>>() {
-                    @Override
-                    public void onSubscribe(@NonNull Disposable d) {
+        }).
 
-                    }
+                subscribeOn(Schedulers.newThread())
+                .
 
-                    @Override
-                    public void onNext(@NonNull BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) {
-                        if (getView() != null && homeStyleBeanBaseResponse != null) {
-                            getView().getStylePageSuccess(homeStyleBeanBaseResponse.getData());
-                        }
-                    }
+                        observeOn(AndroidSchedulers.mainThread())
+                .
 
-                    @Override
-                    public void onError(@NonNull Throwable e) {
-                        if (getView() != null) {
-                            getView().onError(e);
-                            getView().hideLoading();
-                        }
-                    }
+                        subscribe(new Observer<BaseResponse<HomeStyleBean>>() {
+                            @Override
+                            public void onSubscribe(@NonNull Disposable d) {
 
-                    @Override
-                    public void onComplete() {
-                        if (getView() != null) {
-                            getView().hideLoading();
-                        }
-                    }
-                });
+                            }
+
+                            @Override
+                            public void onNext(@NonNull BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) {
+                                if (getView() != null && homeStyleBeanBaseResponse != null) {
+                                    getView().getStylePageSuccess(homeStyleBeanBaseResponse.getData());
+                                }
+                            }
+
+                            @Override
+                            public void onError(@NonNull Throwable e) {
+                                if (getView() != null) {
+                                    getView().onError(e);
+                                    getView().hideLoading();
+                                }
+                            }
+
+                            @Override
+                            public void onComplete() {
+                                if (getView() != null) {
+                                    getView().hideLoading();
+                                }
+                            }
+                        });
         //        addSubscribe(create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomeStyleBean>(getView()) {
 //            @Override
 //            protected void onSuccess(HomeStyleBean data) {

+ 15 - 0
student/src/main/java/com/cooleshow/student/ui/main/HotNewsFragment.java

@@ -1,5 +1,6 @@
 package com.cooleshow.student.ui.main;
 
+import android.graphics.Rect;
 import android.util.Log;
 import android.view.View;
 
@@ -9,6 +10,7 @@ import com.chad.library.adapter.base.listener.OnItemClickListener;
 import com.cooleshow.base.common.WebConstants;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.fragment.BaseFragment;
+import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.student.adapter.HomeHotNewsAdapter;
 import com.cooleshow.student.bean.AppHomeBean;
 import com.cooleshow.student.databinding.FragmentHomeHotNewsLayoutBinding;
@@ -17,6 +19,7 @@ import java.util.List;
 
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
 /**
  * Author by pq, Date on 2022/8/31.
@@ -36,6 +39,18 @@ public class HotNewsFragment extends BaseFragment<FragmentHomeHotNewsLayoutBindi
         mHomeHotNewsAdapter = getAdapter();
         mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
         mViewBinding.recyclerView.setAdapter(mHomeHotNewsAdapter);
+        mViewBinding.recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
+            @Override
+            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
+                //每行都只有2个
+                int childLayoutPosition = parent.getChildLayoutPosition(view);
+                if (childLayoutPosition == 0) {
+                    outRect.top = SizeUtils.dp2px(5);
+                } else {
+                    outRect.top = SizeUtils.dp2px(0);
+                }
+            }
+        });
         mHomeHotNewsAdapter.setOnItemClickListener(new OnItemClickListener() {
             @Override
             public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

+ 48 - 5
student/src/main/java/com/cooleshow/student/ui/main/NewHomeFragment.java

@@ -1,5 +1,7 @@
 package com.cooleshow.student.ui.main;
 
+import android.animation.ArgbEvaluator;
+import android.animation.ValueAnimator;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
@@ -88,6 +90,9 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     private NewHomeVideoCourseAdapter mHomeVideoCourseAdapter;
     private TalentStyleFragment mTalentStyleFragment;
     private HotNewsFragment mHotNewsFragment;
+    private ValueAnimator bottomTabValueAnimator;
+    private boolean isCollapsed = false;//控制底部tab
+    
     private ViewPager2.OnPageChangeCallback onPageChangeCallback = new ViewPager2.OnPageChangeCallback() {
         @Override
         public void onPageSelected(int position) {
@@ -305,24 +310,34 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
 
 
         mViewBinding.appBarLayout.addOnOffsetChangedListener(new AppBarLayoutStateChangeListener() {
-
             @Override
             public void onStateChanged(AppBarLayout appBarLayout, State state) {
                 switch (state) {
                     case EXPANDED:    //展开
-                        Log.i("pq","展开");
+                        Log.i("pq", "展开");
                         break;
                     case COLLAPSED:    //折叠
-                        Log.i("pq","折叠");
+                        Log.i("pq", "折叠");
+                        if (!isCollapsed) {
+                            isCollapsed = true;
+                            mViewBinding.viewDivideLine2.setVisibility(View.VISIBLE);
+                            handleTabAnim(1);
+                        }
                         break;
                     case INTERMEDIATE: //中间状态
-                        Log.i("pq","中间状态");
+                        Log.i("pq", "中间状态");
+                        if (isCollapsed) {
+                            handleTabAnim(0);
+                            isCollapsed = false;
+                            mViewBinding.viewDivideLine2.setVisibility(View.GONE);
+                        }
                         break;
                 }
             }
         });
     }
 
+
     private void resetBannerAuto() {
         boolean localVisibleRect = UiUtils.getLocalVisibleRect(getActivity(), banner, 10);
         //banner可见的时候就自动循环,否则就停止,解决问题:在scrollview到最底部时候,由于banner自动到第一个时候就往上顶一段距离
@@ -502,7 +517,7 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     @Override
     public void getStylePageSuccess(HomeStyleBean data) {
         if (mTalentStyleFragment != null) {
-            mTalentStyleFragment.setData(data.rows);
+            mTalentStyleFragment.setData(data);
         }
     }
 
@@ -711,6 +726,30 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     }
 
 
+
+    private void handleTabAnim(int animationMode) {
+        int colorFrom = getResources().getColor(animationMode == 0 ? com.cooleshow.base.R.color.white : com.cooleshow.base.R.color.color_f6f8f9);
+        int colorTo = getResources().getColor(animationMode == 0 ? com.cooleshow.base.R.color.color_f6f8f9 : com.cooleshow.base.R.color.white);
+        if (bottomTabValueAnimator == null) {
+            bottomTabValueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
+            bottomTabValueAnimator.setDuration(150);
+            bottomTabValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    if (mViewBinding != null) {
+                        int colorValue = (int) animation.getAnimatedValue();
+                        mViewBinding.csBottomTab.setBackgroundColor(colorValue);
+                    }
+                }
+            });
+        }
+        if (bottomTabValueAnimator.isRunning()) {
+            bottomTabValueAnimator.cancel();
+        }
+        bottomTabValueAnimator.setObjectValues(colorFrom, colorTo);
+        bottomTabValueAnimator.start();
+    }
+
     /**
      * 跳转直播课详情页面
      *
@@ -745,5 +784,9 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     @Override
     public void onDestroy() {
         super.onDestroy();
+        if (bottomTabValueAnimator != null) {
+            bottomTabValueAnimator.cancel();
+            bottomTabValueAnimator = null;
+        }
     }
 }

+ 6 - 2
student/src/main/java/com/cooleshow/student/ui/main/TalentStyleFragment.java

@@ -63,9 +63,13 @@ public class TalentStyleFragment extends BaseFragment<FragmentHomeTalentLayoutBi
         });
     }
 
-    public void setData(List<HomeStyleBean.RowsBean> data) {
+    public void setData(HomeStyleBean data) {
         if (mTalentStyleAdapter != null) {
-            mTalentStyleAdapter.setNewInstance(data);
+            if (data != null && data.rows != null && data.rows.size() > 0) {
+                mTalentStyleAdapter.setNewInstance(data.rows);
+            } else {
+                //showEmpty
+            }
         }
     }
 }

+ 3 - 4
student/src/main/res/layout/fragment_home_hot_news_layout.xml

@@ -5,11 +5,10 @@
 
     <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/recyclerView"
-        android:background="@drawable/bg_white_10dp"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="14dp"
-        android:layout_marginEnd="14dp"
+        android:layout_height="match_parent"
+        android:paddingStart="14dp"
+        android:paddingEnd="14dp"
         android:overScrollMode="never"
         android:scrollbars="none" />
 </FrameLayout>

+ 13 - 4
student/src/main/res/layout/fragment_new_home_layout.xml

@@ -14,6 +14,15 @@
         app:layout_constraintTop_toTopOf="parent" />
 
     <View
+        android:visibility="gone"
+        android:id="@+id/view_divide_line2"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintBottom_toBottomOf="@+id/view_top_bg"
+        android:background="@color/color_f9f9f9"
+        android:layout_width="match_parent"
+        android:layout_height="1dp"/>
+
+    <View
         android:id="@+id/view_status_bar"
         android:layout_width="match_parent"
         android:layout_height="1px"
@@ -128,10 +137,10 @@
                 android:theme="@style/AppTheme.AppBarOverlay">
 
                 <com.google.android.material.appbar.CollapsingToolbarLayout
-                    android:layout_marginBottom="20dp"
                     android:id="@+id/collapsing_toolbar_layout"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
+                    android:layout_marginBottom="20dp"
                     android:paddingBottom="0dp"
                     app:layout_scrollFlags="scroll"
                     app:scrimAnimationDuration="50"
@@ -645,9 +654,10 @@
                 </com.google.android.material.appbar.CollapsingToolbarLayout>
 
                 <androidx.constraintlayout.widget.ConstraintLayout
+                    android:id="@+id/cs_bottom_tab"
                     android:layout_width="match_parent"
-                    android:layout_marginTop="10dp"
                     android:layout_height="wrap_content"
+                    android:paddingTop="8dp"
                     app:layout_constraintLeft_toLeftOf="parent"
                     app:layout_constraintTop_toBottomOf="@+id/cl_video_course">
 
@@ -731,10 +741,9 @@
                         android:id="@+id/view_help_line3"
                         android:layout_width="1px"
                         android:layout_height="1px"
-                        android:layout_marginTop="18dp"
+                        android:layout_marginTop="10dp"
                         app:layout_constraintLeft_toLeftOf="parent"
                         app:layout_constraintTop_toBottomOf="@+id/tv_talent_style_title" />
-
                 </androidx.constraintlayout.widget.ConstraintLayout>
             </com.google.android.material.appbar.AppBarLayout>
 

+ 2 - 1
student/src/main/res/layout/item_home_hot_news.xml

@@ -3,6 +3,7 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
+    android:id="@+id/cs_root"
     android:layout_height="wrap_content"
     android:paddingBottom="20dp">
 
@@ -68,6 +69,6 @@
         android:layout_height="0.5dp"
         android:layout_marginStart="11dp"
         android:layout_marginEnd="11dp"
-        android:background="@color/color_e8e8e8"
+        android:background="@color/color_f2f2f2"
         app:layout_constraintTop_toTopOf="parent" />
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 1
student/src/main/res/layout/item_home_talent_style_layout.xml

@@ -4,9 +4,10 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:layout_marginTop="5dp"
     android:layout_marginStart="6dp"
     android:layout_marginEnd="6dp"
-    android:layout_marginBottom="12dp"
+    android:layout_marginBottom="7dp"
     android:background="@drawable/bg_white_10dp"
     android:paddingBottom="14dp">
 

+ 1 - 1
student/src/main/res/layout/view_hot_music_sheet_child_layout.xml

@@ -95,6 +95,6 @@
         android:id="@+id/view_line"
         android:layout_width="match_parent"
         android:layout_height="0.5dp"
-        android:background="@color/color_e8e8e8"
+        android:background="@color/color_f2f2f2"
         app:layout_constraintBottom_toBottomOf="parent" />
 </androidx.constraintlayout.widget.ConstraintLayout>