Pārlūkot izejas kodu

增加老师端我的课程页面-课程状态选择逻辑

Pq 3 gadi atpakaļ
vecāks
revīzija
84da9f4491

+ 183 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/PopupUtil.java

@@ -0,0 +1,183 @@
+package com.cooleshow.base.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.PopupWindow;
+
+import com.cooleshow.base.R;
+import com.cooleshow.base.widgets.CommonPopupWindow;
+
+
+/**
+ * PopupWindow工具类
+ */
+public class PopupUtil {
+
+    public interface ShowListener {
+        void onShow(View view, PopupWindow popupWindow);
+    }
+
+    /*居中显示PopupWindow*/
+    public static void showInCenter(Activity activity, int resourcesId, ShowListener showListener) {
+        View popupView = LayoutInflater.from(Utils.getApp()).inflate(resourcesId, null);
+        PopupWindow popupWindow = createPopupWindow(popupView, activity, true);
+        popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*居中显示PopupWindow带动画*/
+    public static void showInCenter(Activity activity, int resourcesId, int animationStyle, ShowListener showListener) {
+        View popupView = LayoutInflater.from(Utils.getApp()).inflate(resourcesId, null);
+        PopupWindow popupWindow = createPopupWindow(popupView, activity, animationStyle, true);
+        popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+
+    /*底部显示PopupWindow*/
+    public static void showInBottom(Activity activity, int resourcesId, ShowListener showListener) {
+        View popupView = LayoutInflater.from(Utils.getApp()).inflate(resourcesId, null);
+        PopupWindow popupWindow = createPopupWindow(popupView, activity, true);
+        popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*顶部显示PopupWindow*/
+    public static void showInTop(Activity activity, int resourcesId, ShowListener showListener) {
+        View popupView = LayoutInflater.from(Utils.getApp()).inflate(resourcesId, null);
+        PopupWindow popupWindow = createPopupWindow(popupView, activity, true);
+        popupWindow.showAtLocation(activity.getWindow().getDecorView(), Gravity.TOP, 0, 0);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*下方显示PopupWindow*/
+    public static void showInDrop(Context activity, int resourcesId, View anchor, ShowListener showListener) {
+        View popupView = LayoutInflater.from(activity).inflate(resourcesId, null);
+        PopupWindow popupWindow = createNoBackPopupWindow(popupView, activity, ViewGroup.LayoutParams.MATCH_PARENT,
+                ViewGroup.LayoutParams.MATCH_PARENT, true);
+        popupWindow.showAsDropDown(anchor);
+        showListener.onShow(popupView, popupWindow);
+    } /*下方显示PopupWindow*/
+
+
+    /*下方显示PopupWindow,有偏移值*/
+    public static void showInDrop(Context activity, int resourcesId, View anchor, int x, int y, ShowListener showListener) {
+        View popupView = LayoutInflater.from(activity).inflate(resourcesId, null);
+        PopupWindow popupWindow = createNoBackPopupWindow(popupView, activity, ViewGroup.LayoutParams.WRAP_CONTENT,
+                ViewGroup.LayoutParams.MATCH_PARENT, false);
+        popupWindow.showAsDropDown(anchor, x, y);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*下方显示PopupWindow,包裹内容有偏移值*/
+    public static PopupWindow showInDropWrapNObg(Context activity, int resourcesId, View anchor, ShowListener showListener) {
+        View popupView = LayoutInflater.from(activity).inflate(resourcesId, null);
+        PopupWindow popupWindow = createNoBackPopupWindow(popupView, activity, ViewGroup.LayoutParams.MATCH_PARENT,
+                ViewGroup.LayoutParams.WRAP_CONTENT, true);
+        popupWindow.showAsDropDown(anchor);
+        showListener.onShow(popupView, popupWindow);
+        return popupWindow;
+    }
+    /*下方显示PopupWindow,包裹内容有偏移值*/
+    public static void showInDropWrapNObg(Activity activity, int resourcesId, View anchor, int x, int y, ShowListener showListener) {
+        View popupView = LayoutInflater.from(activity).inflate(resourcesId, null);
+        PopupWindow popupWindow = createNoBackPopupWindow(popupView, activity, ViewGroup.LayoutParams.WRAP_CONTENT,
+                ViewGroup.LayoutParams.WRAP_CONTENT, true);
+        //        popupWindow.showAsDropDown(anchor, x, y);
+        int[] location = new int[2];
+        anchor.getLocationOnScreen(location);
+        popupWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, location[0] - anchor.getWidth() * 2 + x, location[1] + anchor.getHeight() - y);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*下方显示PopupWindow,包裹内容有偏移值*/
+
+    public static void showInDropWrap(Context activity, int resourcesId, View anchor, ShowListener showListener) {
+        View popupView = LayoutInflater.from(activity).inflate(resourcesId, null);
+        PopupWindow popupWindow = createPopupWindow(popupView, activity, true);
+        popupWindow.showAsDropDown(anchor);
+        showListener.onShow(popupView, popupWindow);
+    }
+
+    /*创建PopupWindow*/
+    public static PopupWindow createPopupWindow(View popupView, Context activity, int animationStyle, boolean touchable) {
+        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(activity)
+                //设置PopupWindow布局
+                .setView(popupView)
+                //设置宽高
+                .setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT,
+                        ViewGroup.LayoutParams.WRAP_CONTENT)
+                //设置动画
+                .setOutsideTouchable(touchable)
+                .setAnimationStyle(animationStyle)
+                //设置背景颜色,取值范围0.0f-1.0f 值越小越暗 1.0f为透明
+                .setBackGroundLevel(0.5f)
+                //设置PopupWindow里的子View及点击事件
+                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
+                    @Override
+                    public void getChildView(View view, int layoutResId) {
+
+                    }
+                })
+                //设置外部是否可点击 默认是true
+                .setOutsideTouchable(true)
+                //开始构建
+                .create();
+        return popupWindow;
+
+    } /*创建PopupWindow*/
+
+    public static PopupWindow createPopupWindow(View popupView, Context activity, boolean touchable) {
+        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(activity)
+                //设置PopupWindow布局
+                .setView(popupView)
+                .setOutsideTouchable(touchable)
+                //设置宽高
+                .setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT,
+                        ViewGroup.LayoutParams.WRAP_CONTENT)
+                //设置动画
+                //设置背景颜色,取值范围0.0f-1.0f 值越小越暗 1.0f为透明
+                .setBackGroundLevel(0.5f)
+                //设置PopupWindow里的子View及点击事件
+                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
+                    @Override
+                    public void getChildView(View view, int layoutResId) {
+
+                    }
+                })
+                //设置外部是否可点击 默认是true
+                .setOutsideTouchable(true)
+                //开始构建
+                .create();
+        return popupWindow;
+
+    }
+
+    public static PopupWindow createNoBackPopupWindow(View popupView, Context activity, int width, int height, boolean touchable) {
+        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(activity)
+                //设置PopupWindow布局
+                .setView(popupView)
+                .setOutsideTouchable(touchable)
+                .setAnimationStyle(R.style.TopAnimation)
+                //设置宽高
+                .setWidthAndHeight(width, height)
+                //设置动画
+                //设置PopupWindow里的子View及点击事件
+                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
+                    @Override
+                    public void getChildView(View view, int layoutResId) {
+
+                    }
+                })
+                //设置外部是否可点击 默认是true
+                .setOutsideTouchable(touchable)
+                //开始构建
+                .create();
+        return popupWindow;
+
+    }
+}

+ 250 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/CommonPopupWindow.java

@@ -0,0 +1,250 @@
+package com.cooleshow.base.widgets;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.Build;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.PopupWindow;
+
+import com.cooleshow.base.utils.Utils;
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
+
+
+public class CommonPopupWindow extends PopupWindow {
+    final PopupController controller;
+    private static WindowManager wm;
+
+    @Override
+    public int getWidth() {
+        return controller.mPopupView.getMeasuredWidth();
+    }
+
+    @Override
+    public int getHeight() {
+        return controller.mPopupView.getMeasuredHeight();
+    }
+
+    public interface ViewInterface {
+        void getChildView(View view, int layoutResId);
+    }
+
+    private CommonPopupWindow(Context context) {
+        controller = new PopupController(context, this);
+    }
+
+    @Override
+    public void dismiss() {
+        super.dismiss();
+        controller.setBackGroundLevel(1.0f);
+    }
+
+    public static class Builder {
+        private final PopupController.PopupParams params;
+        private ViewInterface listener;
+
+        public Builder(Context context) {
+            params = new PopupController.PopupParams(context);
+        }
+
+        /**
+         * @param layoutResId 设置PopupWindow 布局ID
+         * @return Builder
+         */
+        public Builder setView(int layoutResId) {
+            params.mView = null;
+            params.layoutResId = layoutResId;
+            return this;
+        }
+
+        /**
+         * @param view 设置PopupWindow布局
+         * @return Builder
+         */
+        public Builder setView(View view) {
+            params.mView = view;
+            params.layoutResId = 0;
+            return this;
+        }
+
+        /**
+         * 设置子View
+         *
+         * @param listener ViewInterface
+         * @return Builder
+         */
+        public Builder setViewOnclickListener(ViewInterface listener) {
+            this.listener = listener;
+            return this;
+        }
+
+        /**
+         * 设置宽度和高度 如果不设置 默认是wrap_content
+         *
+         * @param width 宽
+         * @return Builder
+         */
+        public Builder setWidthAndHeight(int width, int height) {
+            params.mWidth = width;
+            params.mHeight = height;
+            return this;
+        }
+
+        /**
+         * 设置背景灰色程度
+         *
+         * @param level 0.0f-1.0f
+         * @return Builder
+         */
+        public Builder setBackGroundLevel(float level) {
+            params.isShowBg = true;
+            params.bg_level = level;
+            return this;
+        }
+
+        /**
+         * 是否可点击Outside消失
+         *
+         * @param touchable 是否可点击
+         * @return Builder
+         */
+        public Builder setOutsideTouchable(boolean touchable) {
+            params.isTouchable = touchable;
+            return this;
+        }
+
+        /**
+         * 设置动画
+         *
+         * @return Builder
+         */
+        public Builder setAnimationStyle(int animationStyle) {
+            params.isShowAnim = true;
+            params.animationStyle = animationStyle;
+            return this;
+        }
+
+        public CommonPopupWindow create() {
+            final CommonPopupWindow popupWindow = new CommonPopupWindow(params.mContext);
+            params.apply(popupWindow.controller);
+            if (listener != null && params.layoutResId != 0) {
+                listener.getChildView(popupWindow.controller.mPopupView, params.layoutResId);
+            }
+            measureWidthAndHeight(popupWindow.controller.mPopupView);
+            return popupWindow;
+        }
+
+        public void measureWidthAndHeight(View view) {
+            int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
+            int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
+            view.measure(widthMeasureSpec, heightMeasureSpec);
+        }
+
+    }
+
+    /**
+     * 在Android7.0以后,PopupWindow的显示会有一个判断,当PopupWindow的高度大于屏幕的剩余高度时,会往控件上方超出。
+     *
+     * @param anchor
+     */
+    @Override
+    public void showAsDropDown(View anchor) {
+        adapterApiV24ForShowAsDropDown(anchor, 0, 0);
+        super.showAsDropDown(anchor);
+    }
+
+    @Override
+    public void showAsDropDown(View anchor, int xoff, int yoff) {
+        adapterApiV24ForShowAsDropDown(anchor, xoff, yoff);
+        super.showAsDropDown(anchor, xoff, yoff);
+    }
+
+
+    public void adapterApiV24ForShowAsDropDown(View parent, int xoff, int offsetY) {
+
+        if (null == parent) {
+            return;
+        }
+        if (Build.VERSION.SDK_INT >= 24) {
+            Rect visibleFrame = new Rect();
+            parent.getGlobalVisibleRect(visibleFrame);
+            int height;
+            /**
+             * 判断是否有导航栏
+             */
+            if (isShowNavBar(getContentView().getContext())) {
+                height = parent.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom + Math.abs(offsetY);
+            } else {
+                /**
+                 * 获取物理真实高度 才能在android 7.0以上遮住下面的TabHost
+                 */
+                height = getRealHeight() - visibleFrame.bottom + Math.abs(offsetY);
+            }
+            setHeight(height);
+        }
+        super.showAsDropDown(parent, xoff, offsetY);
+    }
+
+    public boolean isShowNavBar(Context context) {
+        if (null == context) {
+            return false;
+        }
+/**
+ * 获取应用区域高度
+ */
+        Rect outRect1 = new Rect();
+        try {
+            ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect1);
+        } catch (ClassCastException e) {
+            e.printStackTrace();
+            return false;
+        }
+        int activityHeight = outRect1.height();
+/**
+ * 获取状态栏高度
+ */
+        int statuBarHeight = getStatusBarHeight();
+/**
+ * 屏幕物理高度 减去 状态栏高度
+ */
+        int remainHeight = getRealHeight() - statuBarHeight;
+/**
+ * 剩余高度跟应用区域高度相等 说明导航栏没有显示 否则相反
+ */
+        if (activityHeight == remainHeight) {
+            return false;
+        } else {
+            return true;
+        }
+
+    }
+
+    /**
+     * 获取真实屏幕高度
+     *
+     * @return
+     */
+    public int getRealHeight() {
+        if (null == wm) {
+            wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
+        }
+        Point point = new Point();
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+            wm.getDefaultDisplay().getRealSize(point);
+        } else {
+            wm.getDefaultDisplay().getSize(point);
+        }
+        return point.y;
+    }
+
+    /**
+     * 获取状态栏高度
+     *
+     * @return
+     */
+    public int getStatusBarHeight() {
+        return QMUIStatusBarHelper.getStatusbarHeight(Utils.getApp());
+    }
+}

+ 130 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/PopupController.java

@@ -0,0 +1,130 @@
+package com.cooleshow.base.widgets;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.PopupWindow;
+
+class PopupController {
+    private int         layoutResId;//布局id
+    private Context     context;
+    private PopupWindow popupWindow;
+    View mPopupView;//弹窗布局View
+    private View   mView;
+    private Window mWindow;
+
+    PopupController(Context context, PopupWindow popupWindow) {
+        this.context = context;
+        this.popupWindow = popupWindow;
+    }
+
+    public void setView(int layoutResId) {
+        mView = null;
+        this.layoutResId = layoutResId;
+        installContent();
+    }
+
+    public void setView(View view) {
+        mView = view;
+        this.layoutResId = 0;
+        installContent();
+    }
+
+    private void installContent() {
+        if (layoutResId != 0) {
+            mPopupView = LayoutInflater.from(context).inflate(layoutResId, null);
+        } else if (mView != null) {
+            mPopupView = mView;
+        }
+        popupWindow.setContentView(mPopupView);
+    }
+
+    /**
+     * 设置宽度
+     *
+     * @param width  宽
+     * @param height 高
+     */
+    private void setWidthAndHeight(int width, int height) {
+        if (width == 0 || height == 0) {
+            //如果没设置宽高,默认是WRAP_CONTENT
+            popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
+            popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
+        } else {
+            popupWindow.setWidth(width);
+            popupWindow.setHeight(height);
+        }
+    }
+
+
+    /**
+     * 设置背景灰色程度
+     *
+     * @param level 0.0f-1.0f
+     */
+    void setBackGroundLevel(float level) {
+        mWindow = ((Activity) context).getWindow();
+        WindowManager.LayoutParams params = mWindow.getAttributes();
+        params.alpha = level;
+        mWindow.setAttributes(params);
+    }
+
+
+    /**
+     * 设置动画
+     */
+    private void setAnimationStyle(int animationStyle) {
+        popupWindow.setAnimationStyle(animationStyle);
+    }
+
+    /**
+     * 设置Outside是否可点击
+     *
+     * @param touchable 是否可点击
+     */
+    private void setOutsideTouchable(boolean touchable) {
+        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));//设置透明背景
+        popupWindow.setOutsideTouchable(touchable);//设置outside可点击
+        popupWindow.setFocusable(touchable);
+    }
+
+
+    static class PopupParams {
+        public int layoutResId;//布局id
+        public Context mContext;
+        public int mWidth, mHeight;//弹窗的宽和高
+        public boolean isShowBg, isShowAnim;
+        public float bg_level;//屏幕背景灰色程度
+        public int animationStyle;//动画Id
+        public View mView;
+        public boolean isTouchable = true;
+
+        public PopupParams(Context mContext) {
+            this.mContext = mContext;
+        }
+
+        public void apply(PopupController controller) {
+            if (mView != null) {
+                controller.setView(mView);
+            } else if (layoutResId != 0) {
+                controller.setView(layoutResId);
+            } else {
+                throw new IllegalArgumentException("PopupView's contentView is null");
+            }
+            controller.setWidthAndHeight(mWidth, mHeight);
+            controller.setOutsideTouchable(isTouchable);//设置outside可点击
+            if (isShowBg) {
+                //设置背景
+                controller.setBackGroundLevel(bg_level);
+            }
+            if (isShowAnim) {
+                controller.setAnimationStyle(animationStyle);
+            }
+        }
+    }
+}

+ 11 - 0
BaseLibrary/src/main/res/anim/top_enter_anim.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:duration="200">
+    <!--<translate-->
+        <!--android:fromYDelta="-100%p"-->
+        <!--android:toYDelta="0%p" />-->
+
+    <alpha
+        android:fromAlpha="0.0"
+        android:toAlpha="1.0" />
+</set>

+ 13 - 0
BaseLibrary/src/main/res/anim/top_exit_anim.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:duration="200">
+    <!--<translate-->
+        <!--android:duration="@android:integer/config_mediumAnimTime"-->
+        <!--android:fromYDelta="0%p"-->
+        <!--android:toYDelta="-100%p" />-->
+
+    <alpha
+        android:duration="@android:integer/config_mediumAnimTime"
+        android:fromAlpha="1.0"
+        android:toAlpha="0.3" />
+</set>

+ 25 - 0
BaseLibrary/src/main/res/layout/list_popu_layout.xml

@@ -0,0 +1,25 @@
+<?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="match_parent"
+    android:orientation="vertical">
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerView"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/dp_2"
+        android:background="@color/white"
+        android:focusable="true"
+        android:focusableInTouchMode="true"
+        android:overScrollMode="never"
+        android:paddingTop="@dimen/dp_5"
+        android:scrollbars="none" />
+
+    <View
+        android:id="@+id/view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="#50000000" />
+
+</LinearLayout>

+ 26 - 0
BaseLibrary/src/main/res/layout/notice_popu_list_item.xml

@@ -0,0 +1,26 @@
+<?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">
+
+    <TextView
+        android:id="@+id/tv_title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:paddingStart="@dimen/dp_20"
+        android:paddingTop="@dimen/dp_18"
+        android:paddingEnd="@dimen/dp_20"
+        android:paddingBottom="@dimen/dp_18"
+        android:textColor="@color/black_333"
+        android:textSize="@dimen/dp_16" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/dp_1"
+        android:layout_marginStart="@dimen/dp_12"
+        android:layout_marginEnd="@dimen/dp_12"
+        android:background="@color/color_ededed" />
+
+</LinearLayout>

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

@@ -50,4 +50,5 @@
     <color name="color_ededed">#EDEDED</color>
     <color name="colorPrimaryStudent">#01C1B5</color>
     <color name="color_ff802c">#FF802C</color>
+    <color name="black_333">#494757</color>
 </resources>

+ 5 - 0
BaseLibrary/src/main/res/values/styles.xml

@@ -239,4 +239,9 @@
         <item name="android:dropDownHorizontalOffset">0dip</item>
         <item name="android:dropDownVerticalOffset">4dip</item>
     </style>
+
+    <style name="TopAnimation" parent="android:Animation">
+        <item name="android:windowEnterAnimation">@anim/top_enter_anim</item>
+        <item name="android:windowExitAnimation">@anim/top_exit_anim</item>
+    </style>
 </resources>

+ 42 - 0
teacher/src/main/java/com/cooleshow/teacher/adapter/CourseStatusFilterAdapter.java

@@ -0,0 +1,42 @@
+package com.cooleshow.teacher.adapter;
+
+import android.view.View;
+import android.widget.TextView;
+
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.viewholder.BaseViewHolder;
+import com.cooleshow.teacher.R;
+import com.cooleshow.teacher.bean.CourseFilterStatusBean;
+
+import androidx.annotation.NonNull;
+
+/**
+ * Author by pq, Date on 2022/4/25.
+ */
+public class CourseStatusFilterAdapter extends BaseQuickAdapter<CourseFilterStatusBean, BaseViewHolder> {
+    private int selectPosition = -1;
+
+    public CourseStatusFilterAdapter(int layoutResId) {
+        super(layoutResId);
+    }
+
+    @Override
+    protected void convert(@NonNull BaseViewHolder holder, CourseFilterStatusBean bean) {
+        holder.setText(R.id.tv_title, bean.showText);
+        TextView tv_title = holder.getView(R.id.tv_title);
+        if(holder.getLayoutPosition() == selectPosition){
+            tv_title.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
+        }else{
+            tv_title.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.black_333));
+        }
+    }
+
+    public int getSelectPosition() {
+        return selectPosition;
+    }
+
+    public void setSelect(int selectPosition) {
+        this.selectPosition = selectPosition;
+        notifyDataSetChanged();
+    }
+}

+ 14 - 0
teacher/src/main/java/com/cooleshow/teacher/bean/CourseFilterStatusBean.java

@@ -0,0 +1,14 @@
+package com.cooleshow.teacher.bean;
+
+/**
+ * Author by pq, Date on 2022/4/25.
+ */
+public class CourseFilterStatusBean {
+    public String value;
+    public String showText;
+
+    public CourseFilterStatusBean(String value,String showText) {
+        this.value = value;
+        this.showText = showText;
+    }
+}

+ 73 - 5
teacher/src/main/java/com/cooleshow/teacher/ui/course/LiveCourseFragment.java

@@ -1,19 +1,27 @@
 package com.cooleshow.teacher.ui.course;
 
 import android.text.TextUtils;
+import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
+import android.widget.PopupWindow;
 import android.widget.TextView;
 
 import com.bigkoo.pickerview.builder.TimePickerBuilder;
 import com.bigkoo.pickerview.listener.CustomListener;
 import com.bigkoo.pickerview.view.TimePickerView;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.listener.OnItemClickListener;
 import com.chad.library.adapter.base.listener.OnLoadMoreListener;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.LogUtils;
+import com.cooleshow.base.utils.PopupUtil;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.teacher.R;
+import com.cooleshow.teacher.adapter.CourseStatusFilterAdapter;
 import com.cooleshow.teacher.adapter.LiveCourseListAdapter;
 import com.cooleshow.teacher.adapter.SparringCourseListAdapter;
+import com.cooleshow.teacher.bean.CourseFilterStatusBean;
 import com.cooleshow.teacher.bean.LiveCourseListBean;
 import com.cooleshow.teacher.bean.SparringCourseListBean;
 import com.cooleshow.teacher.constants.CourseFilterConstants;
@@ -26,11 +34,13 @@ import com.cooleshow.teacher.presenter.course.SparringCoursePresenter;
 import com.scwang.smart.refresh.layout.api.RefreshLayout;
 import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
 /**
  * Author by pq, Date on 2022/4/25.
@@ -45,6 +55,9 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
     private View mEmptyView;
     private TextView mTvEmptyTip;
     private TimePickerView pvTime;
+    private PopupWindow mPopupWindow;
+    private ArrayList<CourseFilterStatusBean> mCourseFilterStatusBeans;
+    private CourseStatusFilterAdapter mCourseStatusFilterAdapter;
 
     @Override
     protected FragmentLiveCourseLayoutBinding getLayoutView() {
@@ -58,14 +71,22 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
 
     @Override
     protected void initView(View rootView) {
-        reBuildFilter(null,CourseFilterConstants.COURSE_FILTER_ALL);
         mViewBinding.tvTime.setOnClickListener(this);
+        mViewBinding.tvCourseStatus.setOnClickListener(this);
+    }
+
+    private void buildDefaultCourseStatusFilterList() {
+        mCourseFilterStatusBeans = new ArrayList<>();
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_ALL, "全部"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_HAS_NOT_STARTED, "未开始"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_IN_PROGRESS, "进行中"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_COMPLETED, "已结束"));
     }
 
     private void reBuildFilter(Date date, String status) {
         currentSelectDate = date != null ? date : TimeUtils.getNowDate();
         String targetDateTimeStr = TimeUtils.date2String(currentSelectDate, TimeUtils.getSafeDateFormat("yyyy-MM"));
-        if (TextUtils.equals(targetDateTimeStr, currentFilterDate) && TextUtils.equals(currentCourseFilterStatus,status)) {
+        if (TextUtils.equals(targetDateTimeStr, currentFilterDate) && TextUtils.equals(currentCourseFilterStatus, status)) {
             //防止重复条件触发
             return;
         }
@@ -87,6 +108,7 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
         });
 
         mAdapter = new LiveCourseListAdapter(R.layout.item_live_course_list_layout);
+        mAdapter.getLoadMoreModule().setEnableLoadMoreIfNotFullPage(false);
         mAdapter.getLoadMoreModule().setOnLoadMoreListener(new OnLoadMoreListener() {
             @Override
             public void onLoadMore() {
@@ -97,7 +119,9 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
         });
         mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
         mViewBinding.recyclerView.setAdapter(mAdapter);
-        queryCourse();
+
+        buildDefaultCourseStatusFilterList();
+        reBuildFilter(null, CourseFilterConstants.COURSE_FILTER_ALL);
     }
 
     private void queryCourse() {
@@ -119,9 +143,9 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
                 //第一页
                 mViewBinding.refreshLayout.finishRefresh();
                 if (mAdapter != null) {
+                    mAdapter.getData().clear();
+                    mAdapter.notifyDataSetChanged();
                     if (liveCourseListBean.rows != null && liveCourseListBean.rows.size() > 0) {
-                        mAdapter.getData().clear();
-                        mAdapter.notifyDataSetChanged();
                         mAdapter.setNewInstance(liveCourseListBean.rows);
                     } else {
                         showEmptyView();
@@ -207,6 +231,44 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
         }
     }
 
+    private void initPopu(View targetView) {
+        if (mPopupWindow == null) {
+            View popupContentView = LayoutInflater.from(requireContext()).inflate(com.cooleshow.base.R.layout.list_popu_layout, null);
+            RecyclerView recyclerView = popupContentView.findViewById(R.id.recyclerView);
+            View bg = popupContentView.findViewById(com.cooleshow.base.R.id.view);
+            bg.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (mPopupWindow != null) {
+                        mPopupWindow.dismiss();
+                    }
+                }
+            });
+            mCourseStatusFilterAdapter = new CourseStatusFilterAdapter(com.cooleshow.base.R.layout.notice_popu_list_item);
+            mCourseStatusFilterAdapter.setOnItemClickListener(new OnItemClickListener() {
+                @Override
+                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
+                    Object object = mCourseStatusFilterAdapter.getData().get(position);
+                    if (object instanceof CourseFilterStatusBean) {
+                        if (mCourseStatusFilterAdapter != null) {
+                            mCourseStatusFilterAdapter.setSelect(position);
+                        }
+                        CourseFilterStatusBean filterStatusBean = (CourseFilterStatusBean) object;
+                        mViewBinding.tvCourseStatus.setText(filterStatusBean.showText);
+                        reBuildFilter(currentSelectDate, filterStatusBean.value);
+                    }
+                    mPopupWindow.dismiss();
+                }
+            });
+            recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
+            recyclerView.setAdapter(mCourseStatusFilterAdapter);
+            mCourseStatusFilterAdapter.setNewInstance(mCourseFilterStatusBeans);
+            mPopupWindow = PopupUtil.createNoBackPopupWindow(popupContentView, requireContext(), ViewGroup.LayoutParams.MATCH_PARENT,
+                    ViewGroup.LayoutParams.WRAP_CONTENT, true);
+        }
+        mPopupWindow.showAsDropDown(targetView);
+    }
+
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.tv_time) {
@@ -214,5 +276,11 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
             showTimeSelectPicker();
             return;
         }
+
+        if (v.getId() == R.id.tv_course_status) {
+            //课程状态筛选
+            initPopu(mViewBinding.tvCourseStatus);
+            return;
+        }
     }
 }

+ 70 - 3
teacher/src/main/java/com/cooleshow/teacher/ui/course/SparringCourseFragment.java

@@ -2,18 +2,27 @@ package com.cooleshow.teacher.ui.course;
 
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
+import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
+import android.widget.PopupWindow;
 import android.widget.TextView;
 
 import com.bigkoo.pickerview.builder.TimePickerBuilder;
 import com.bigkoo.pickerview.listener.CustomListener;
 import com.bigkoo.pickerview.view.TimePickerView;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.listener.OnItemClickListener;
 import com.chad.library.adapter.base.listener.OnLoadMoreListener;
+import com.chad.library.adapter.base.viewholder.BaseViewHolder;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.LogUtils;
+import com.cooleshow.base.utils.PopupUtil;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.teacher.R;
+import com.cooleshow.teacher.adapter.CourseStatusFilterAdapter;
 import com.cooleshow.teacher.adapter.SparringCourseListAdapter;
+import com.cooleshow.teacher.bean.CourseFilterStatusBean;
 import com.cooleshow.teacher.bean.SparringCourseListBean;
 import com.cooleshow.teacher.constants.CourseFilterConstants;
 import com.cooleshow.teacher.contract.SparringCourseContract;
@@ -22,11 +31,14 @@ import com.cooleshow.teacher.presenter.course.SparringCoursePresenter;
 import com.scwang.smart.refresh.layout.api.RefreshLayout;
 import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
 /**
  * Author by pq, Date on 2022/4/25.
@@ -41,6 +53,9 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
     private View mEmptyView;
     private TextView mTvEmptyTip;
     private TimePickerView pvTime;
+    private PopupWindow mPopupWindow;
+    private ArrayList<CourseFilterStatusBean> mCourseFilterStatusBeans;
+    private CourseStatusFilterAdapter mCourseStatusFilterAdapter;
 
     @Override
     protected FragmentSparringCourseLayoutBinding getLayoutView() {
@@ -54,14 +69,22 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
 
     @Override
     protected void initView(View rootView) {
-        reBuildFilter(null, CourseFilterConstants.COURSE_FILTER_ALL);
         mViewBinding.tvTime.setOnClickListener(this);
+        mViewBinding.tvCourseStatus.setOnClickListener(this);
+    }
+
+    private void buildDefaultCourseStatusFilterList() {
+        mCourseFilterStatusBeans = new ArrayList<>();
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_ALL, "全部"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_HAS_NOT_STARTED, "未开始"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_IN_PROGRESS, "进行中"));
+        mCourseFilterStatusBeans.add(new CourseFilterStatusBean(CourseFilterConstants.COURSE_FILTER_COMPLETED, "已结束"));
     }
 
     private void reBuildFilter(Date date, String status) {
         currentSelectDate = date != null ? date : TimeUtils.getNowDate();
         String targetDateTimeStr = TimeUtils.date2String(currentSelectDate, TimeUtils.getSafeDateFormat("yyyy-MM"));
-        if (TextUtils.equals(targetDateTimeStr, currentFilterDate) && TextUtils.equals(currentCourseFilterStatus,status)) {
+        if (TextUtils.equals(targetDateTimeStr, currentFilterDate) && TextUtils.equals(currentCourseFilterStatus, status)) {
             //防止重复条件触发
             return;
         }
@@ -94,7 +117,8 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
         });
         mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
         mViewBinding.recyclerView.setAdapter(mAdapter);
-        queryCourse();
+        buildDefaultCourseStatusFilterList();
+        reBuildFilter(null, CourseFilterConstants.COURSE_FILTER_ALL);
     }
 
     private void queryCourse() {
@@ -203,6 +227,44 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
         }
     }
 
+    private void initPopu(View targetView) {
+        if (mPopupWindow == null) {
+            View popupContentView = LayoutInflater.from(requireContext()).inflate(com.cooleshow.base.R.layout.list_popu_layout, null);
+            RecyclerView recyclerView = popupContentView.findViewById(R.id.recyclerView);
+            View bg = popupContentView.findViewById(com.cooleshow.base.R.id.view);
+            bg.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (mPopupWindow != null) {
+                        mPopupWindow.dismiss();
+                    }
+                }
+            });
+            mCourseStatusFilterAdapter = new CourseStatusFilterAdapter(com.cooleshow.base.R.layout.notice_popu_list_item);
+            mCourseStatusFilterAdapter.setOnItemClickListener(new OnItemClickListener() {
+                @Override
+                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
+                    Object object = mCourseStatusFilterAdapter.getData().get(position);
+                    if (object instanceof CourseFilterStatusBean) {
+                        if (mCourseStatusFilterAdapter != null) {
+                            mCourseStatusFilterAdapter.setSelect(position);
+                        }
+                        CourseFilterStatusBean filterStatusBean = (CourseFilterStatusBean) object;
+                        mViewBinding.tvCourseStatus.setText(filterStatusBean.showText);
+                        reBuildFilter(currentSelectDate, filterStatusBean.value);
+                    }
+                    mPopupWindow.dismiss();
+                }
+            });
+            recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
+            recyclerView.setAdapter(mCourseStatusFilterAdapter);
+            mCourseStatusFilterAdapter.setNewInstance(mCourseFilterStatusBeans);
+            mPopupWindow = PopupUtil.createNoBackPopupWindow(popupContentView, requireContext(), ViewGroup.LayoutParams.MATCH_PARENT,
+                    ViewGroup.LayoutParams.WRAP_CONTENT, true);
+        }
+        mPopupWindow.showAsDropDown(targetView);
+    }
+
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.tv_time) {
@@ -210,5 +272,10 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
             showTimeSelectPicker();
             return;
         }
+        if (v.getId() == R.id.tv_course_status) {
+            //课程状态筛选
+            initPopu(mViewBinding.tvCourseStatus);
+            return;
+        }
     }
 }