浏览代码

声部选择 pop修改

邓琴文 3 年之前
父节点
当前提交
161da9d160

+ 40 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/poplist/CourseStatusFilterAdapter.java

@@ -0,0 +1,40 @@
+package com.cooleshow.base.widgets.poplist;
+
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.viewholder.BaseViewHolder;
+import com.cooleshow.base.R;
+
+/**
+ * Author by pq, Date on 2022/4/25.
+ */
+public class CourseStatusFilterAdapter extends BaseQuickAdapter<PopMenuBean, BaseViewHolder> {
+    private int selectPosition = -1;
+
+    public CourseStatusFilterAdapter() {
+        super(R.layout.notice_popu_list_item);
+    }
+
+    @Override
+    protected void convert(@NonNull BaseViewHolder holder, PopMenuBean bean) {
+        holder.setText(R.id.tv_title, bean.getActionName());
+        TextView tv_title = holder.getView(R.id.tv_title);
+        if (getItemPosition(bean) == 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();
+    }
+}

+ 40 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/poplist/PopMenuBean.java

@@ -0,0 +1,40 @@
+package com.cooleshow.base.widgets.poplist;
+
+import android.graphics.Bitmap;
+
+/**
+ * @author dengqw
+ * @time 2022/6/28 10:38
+ * @describe:
+ **/
+public class PopMenuBean {
+    private String actionName;
+    private Bitmap icon;
+    private int iconResId;
+
+    public String getActionName() {
+        return actionName;
+    }
+
+    public void setActionName(String actionName) {
+        this.actionName = actionName;
+    }
+
+    public Bitmap getIcon() {
+        return icon;
+    }
+
+    public void setIcon(Bitmap mIcon) {
+        this.icon = mIcon;
+    }
+
+
+    public int getIconResId() {
+        return iconResId;
+    }
+
+    public void setIconResId(int iconResId) {
+        this.iconResId = iconResId;
+    }
+
+}

+ 81 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/poplist/PopupListWindow.java

@@ -0,0 +1,81 @@
+package com.cooleshow.base.widgets.poplist;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.PopupWindow;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.cooleshow.base.R;
+import com.cooleshow.base.utils.PopupUtil;
+
+import java.util.List;
+
+/**
+ * @author dengqw
+ * @time 2022/6/28 10:24
+ * @describe:
+ **/
+public class PopupListWindow {
+
+    private Context mContext;
+    private View mAnchorView;
+    private List<PopMenuBean> mPopupItemList;
+    private PopupListListener mPopupListListener;
+    private PopupWindow mPopupWindow;
+
+    public PopupListWindow(Context context) {
+        mContext = context;
+    }
+
+    public void showListPop(View anchorView, List<PopMenuBean> popupItemList, PopupListListener popupListListener) {
+        this.mAnchorView = anchorView;
+        this.mPopupItemList = popupItemList;
+        this.mPopupListListener = popupListListener;
+        this.mPopupWindow = null;
+        showPopupListWindow();
+    }
+
+    private void showPopupListWindow() {
+        if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
+            return;
+        }
+        if (mPopupWindow == null) {
+            View popupContentView = LayoutInflater.from(mContext).inflate(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(v -> {
+                if (mPopupWindow != null) {
+                    mPopupWindow.dismiss();
+                }
+            });
+            CourseStatusFilterAdapter listAdapter = new CourseStatusFilterAdapter();
+            listAdapter.setOnItemClickListener((adapter, view, position) -> {
+                PopMenuBean bean = listAdapter.getData().get(position);
+                if (listAdapter != null) {
+                    listAdapter.setSelect(position);
+                }
+                if (mPopupListListener != null) {
+                    mPopupListListener.onPopupListClick(position);
+                }
+                mPopupWindow.dismiss();
+            });
+            recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+            recyclerView.setAdapter(listAdapter);
+            listAdapter.setNewInstance(mPopupItemList);
+            mPopupWindow = PopupUtil.createNoBackPopupWindow(popupContentView, mContext, ViewGroup.LayoutParams.MATCH_PARENT,
+                    ViewGroup.LayoutParams.WRAP_CONTENT, true);
+        }
+        if (!mPopupWindow.isShowing()) {
+            mPopupWindow.showAsDropDown(mAnchorView);
+        }
+    }
+
+    public interface PopupListListener {
+        void onPopupListClick(int position);
+    }
+}

+ 34 - 39
student/src/main/java/com/cooleshow/student/ui/course/LiveCourseFragment.java

@@ -32,6 +32,8 @@ import com.cooleshow.base.utils.PopupUtil;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.base.widgets.EmptyViewLayout;
 
+import com.cooleshow.base.widgets.poplist.PopMenuBean;
+import com.cooleshow.base.widgets.poplist.PopupListWindow;
 import com.cooleshow.student.R;
 import com.cooleshow.student.adapter.CourseStatusFilterAdapter;
 import com.cooleshow.student.adapter.LiveCourseListAdapter;
@@ -61,12 +63,9 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
     private int currentPage;
     private LiveCourseListAdapter mAdapter;
     private EmptyViewLayout mEmptyView;
-    private TextView mTvEmptyTip;
-    private ImageView mEmptyIcon;
     private TimePickerView pvTime;
-    private PopupWindow mPopupWindow;
     private ArrayList<CourseFilterStatusBean> mCourseFilterStatusBeans;
-    private CourseStatusFilterAdapter mCourseStatusFilterAdapter;
+    private List<QuerySubjectBean> subjectBeanList = new ArrayList<>();
     private boolean hasNext = true;
     private boolean isFirstLoad = true;
 
@@ -261,38 +260,6 @@ 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(v -> {
-                if (mPopupWindow != null) {
-                    mPopupWindow.dismiss();
-                }
-            });
-            mCourseStatusFilterAdapter = new CourseStatusFilterAdapter(com.cooleshow.base.R.layout.notice_popu_list_item);
-            mCourseStatusFilterAdapter.setOnItemClickListener((adapter, view, 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) {
@@ -303,18 +270,46 @@ public class LiveCourseFragment extends BaseMVPFragment<FragmentLiveCourseLayout
 
         if (v.getId() == R.id.tv_course_status) {
             //课程状态筛选
-            initPopu(mViewBinding.tvCourseStatus);
+            List<PopMenuBean> popList = new ArrayList<>();
+            for (CourseFilterStatusBean bean : mCourseFilterStatusBeans) {
+                PopMenuBean popMenuBean = new PopMenuBean();
+                popMenuBean.setActionName(bean.showText);
+                popList.add(popMenuBean);
+            }
+            initCoursePop(mViewBinding.tvCourseStatus, popList, position -> {
+                CourseFilterStatusBean bean = mCourseFilterStatusBeans.get(position);
+                mViewBinding.tvCourseStatus.setText(bean.showText);
+                reBuildFilter(currentSelectDate, bean.value);
+            });
             return;
         }
 
         if (v.getId() == R.id.tv_agency) {
             //选择声部
-            selectSubject();
+            if (subjectBeanList.size() == 0) {
+                subjectBeanList.add(new QuerySubjectBean("全部声部", 0));
+            }
+            List<PopMenuBean> popList = new ArrayList<>();
+            for (QuerySubjectBean bean : subjectBeanList) {
+                PopMenuBean popMenuBean = new PopMenuBean();
+                popMenuBean.setActionName(bean.name);
+                popList.add(popMenuBean);
+            }
+            initCoursePop(mViewBinding.tvCourseStatus, popList, position -> {
+                QuerySubjectBean bean = subjectBeanList.get(position);
+                currentSubjectId = bean.id;
+                mViewBinding.tvAgency.setText(bean.name);
+                queryCourse(true);
+            });
             return;
         }
     }
 
-    private List<QuerySubjectBean> subjectBeanList = new ArrayList<>();
+
+    private void initCoursePop(View targetView, List<PopMenuBean> popList, PopupListWindow.PopupListListener listener) {
+        PopupListWindow popWindow = new PopupListWindow(getContext());
+        popWindow.showListPop(targetView, popList, position -> listener.onPopupListClick(position));
+    }
 
     public void querySubjectItemSuccess(List<QuerySubjectBean> data) {
         subjectBeanList.clear();

+ 39 - 43
student/src/main/java/com/cooleshow/student/ui/course/MinePracticeCourseFragment.java

@@ -28,6 +28,8 @@ import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.PopupUtil;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.base.widgets.EmptyViewLayout;
+import com.cooleshow.base.widgets.poplist.PopMenuBean;
+import com.cooleshow.base.widgets.poplist.PopupListWindow;
 import com.cooleshow.student.R;
 import com.cooleshow.student.adapter.CourseStatusFilterAdapter;
 import com.cooleshow.student.adapter.PracticeCourseListAdapter;
@@ -75,18 +77,39 @@ public class MinePracticeCourseFragment extends BaseMVPFragment<FragmentPractice
 
     @Override
     public void onClick(View view) {
-        switch (view.getId()) {
-            case R.id.tv_time:
-                //时间筛选
-                showTimeSelectPicker();
-                break;
-            case R.id.tv_course_status:
-                //课程状态筛选
-                initPopu(mViewBinding.tvCourseStatus);
-                break;
-            case R.id.tv_agency:
-                selectSubject();
-                break;
+        int id = view.getId();
+        if (id == R.id.tv_time) {
+            //时间筛选
+            showTimeSelectPicker();
+        } else if (id == R.id.tv_course_status) {
+            //课程状态筛选
+            List<PopMenuBean> popList = new ArrayList<>();
+            for (CourseFilterStatusBean bean : mCourseFilterStatusBeans) {
+                PopMenuBean popMenuBean = new PopMenuBean();
+                popMenuBean.setActionName(bean.showText);
+                popList.add(popMenuBean);
+            }
+            initCoursePop(mViewBinding.tvCourseStatus, popList, position -> {
+                CourseFilterStatusBean bean = mCourseFilterStatusBeans.get(position);
+                mViewBinding.tvCourseStatus.setText(bean.showText);
+                reBuildFilter(currentSelectDate, bean.value);
+            });
+        } else if (id == R.id.tv_agency) {
+            if (subjectBeanList.size() == 0) {
+                subjectBeanList.add(new QuerySubjectBean("全部声部", 0));
+            }
+            List<PopMenuBean> popList = new ArrayList<>();
+            for (QuerySubjectBean bean : subjectBeanList) {
+                PopMenuBean popMenuBean = new PopMenuBean();
+                popMenuBean.setActionName(bean.name);
+                popList.add(popMenuBean);
+            }
+            initCoursePop(mViewBinding.tvCourseStatus, popList, position -> {
+                QuerySubjectBean bean = subjectBeanList.get(position);
+                currentSubjectId = bean.id;
+                mViewBinding.tvAgency.setText(bean.name);
+                queryCourse(true);
+            });
         }
     }
 
@@ -287,36 +310,9 @@ public class MinePracticeCourseFragment extends BaseMVPFragment<FragmentPractice
         }
     }
 
-    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(v -> {
-                if (mPopupWindow != null) {
-                    mPopupWindow.dismiss();
-                }
-            });
-            mCourseStatusFilterAdapter = new CourseStatusFilterAdapter(com.cooleshow.base.R.layout.notice_popu_list_item);
-            mCourseStatusFilterAdapter.setOnItemClickListener((adapter, view, 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);
+    private void initCoursePop(View targetView, List<PopMenuBean> popList, PopupListWindow.PopupListListener listener) {
+        PopupListWindow popWindow = new PopupListWindow(getContext());
+        popWindow.showListPop(targetView, popList, position -> listener.onPopupListClick(position));
     }
 
     private OptionsPickerView pvOptions;
@@ -325,7 +321,7 @@ public class MinePracticeCourseFragment extends BaseMVPFragment<FragmentPractice
         if (subjectBeanList.size() == 0) {
             subjectBeanList.add(new QuerySubjectBean("全部声部", 0));
         }
-            pvOptions = new OptionsPickerBuilder(getContext(), (options1, options2, options3, v) -> {
+        pvOptions = new OptionsPickerBuilder(getContext(), (options1, options2, options3, v) -> {
             currentSubjectId = subjectBeanList.get(options1).id;
             mViewBinding.tvAgency.setText(subjectBeanList.get(options1).name);
             queryCourse(true);

+ 22 - 1
student/src/main/java/com/cooleshow/student/ui/course/VideoCourseFragment.java

@@ -23,6 +23,8 @@ import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.widgets.EmptyViewLayout;
+import com.cooleshow.base.widgets.poplist.PopMenuBean;
+import com.cooleshow.base.widgets.poplist.PopupListWindow;
 import com.cooleshow.student.R;
 import com.cooleshow.student.adapter.CourseStatusFilterAdapter;
 import com.cooleshow.student.adapter.VideoCourseListAdapter;
@@ -234,10 +236,29 @@ public class VideoCourseFragment extends BaseMVPFragment<FragmentVideoCourseLayo
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.tv_subject) {
-            selectSubject();
+            if (subjectBeanList.size() == 0) {
+                subjectBeanList.add(new QuerySubjectBean("全部声部", 0));
+            }
+            List<PopMenuBean> popList = new ArrayList<>();
+            for (QuerySubjectBean bean : subjectBeanList) {
+                PopMenuBean popMenuBean = new PopMenuBean();
+                popMenuBean.setActionName(bean.name);
+                popList.add(popMenuBean);
+            }
+            initCoursePop(mViewBinding.tvSubject, popList, position -> {
+                QuerySubjectBean bean = subjectBeanList.get(position);
+                currentSubjectId = bean.id;
+                mViewBinding.tvSubject.setText(bean.name);
+                queryCourse(true);
+            });
         }
     }
 
+    private void initCoursePop(View targetView, List<PopMenuBean> popList, PopupListWindow.PopupListListener listener) {
+        PopupListWindow popWindow = new PopupListWindow(getContext());
+        popWindow.showListPop(targetView, popList, position -> listener.onPopupListClick(position));
+    }
+
     private void selectSubject() {
         if (subjectBeanList.size() == 0) {
             subjectBeanList.add(new QuerySubjectBean("全部声部", 0));