Explorar o código

增加老师端首页声部筛选的逻辑

Pq %!s(int64=2) %!d(string=hai) anos
pai
achega
bd928bcbcb

+ 8 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/UiUtils.java

@@ -186,6 +186,14 @@ public class UiUtils {
         return split;
     }
 
+    public static String[] splitSubjectId(String subjectId) {
+        if (TextUtils.isEmpty(subjectId)) {
+            return null;
+        }
+        String[] split = subjectId.split(",");
+        return split;
+    }
+
 
     /**
      * 保留2位小数

BIN=BIN
BaseLibrary/src/main/res/drawable-xhdpi/icon_arrow_down2.png


BIN=BIN
BaseLibrary/src/main/res/drawable-xxhdpi/icon_arrow_down2.png


+ 9 - 0
teacher/src/main/java/com/cooleshow/teacher/api/APIService.java

@@ -793,4 +793,13 @@ public interface APIService {
      */
     @GET(TEACHER_GROUP + "activity/checkReceiveReward")
     Observable<BaseResponse<AwardStatusBean>> getAwardStatus();
+
+    /**
+     * 手机验证码修改密码
+     *
+     * @return
+     */
+    @FormUrlEncoded
+    @POST(TEACHER_GROUP + "teacher/defaultSubject")
+    Observable<BaseResponse<Object>> syncSubjectFilter(@FieldMap Map<String, String> params);
 }

+ 26 - 0
teacher/src/main/java/com/cooleshow/teacher/bean/SubjectBean.java

@@ -0,0 +1,26 @@
+package com.cooleshow.teacher.bean;
+
+import com.contrarywind.interfaces.IPickerViewData;
+
+import java.util.List;
+
+/**
+ * 创建日期:2022/5/30 11:53
+ *
+ * @author Ryan
+ * 类说明:
+ */
+public class SubjectBean implements IPickerViewData {
+    public SubjectBean(String name, String id) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public String id;
+    public String name;
+
+    @Override
+    public String getPickerViewText() {
+        return name;
+    }
+}

+ 2 - 0
teacher/src/main/java/com/cooleshow/teacher/bean/TeacherUserInfo.java

@@ -88,4 +88,6 @@ public class TeacherUserInfo implements Serializable {
     public boolean isSettlement;
     public String tag;//用于显示老师徽章
     public int isVip;//0非会员 1会员
+    public String defaultSubject;//当前声部id
+    public String defaultSubjectName;//当前声部name
 }

+ 25 - 2
teacher/src/main/java/com/cooleshow/teacher/presenter/main/HomePresenter.java

@@ -1,5 +1,7 @@
 package com.cooleshow.teacher.presenter.main;
 
+import android.text.TextUtils;
+
 import com.cooleshow.base.constanst.Constants;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
@@ -21,7 +23,9 @@ import com.cooleshow.usercenter.helper.UserHelper;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Author by pq, Date on 2022/4/20.
@@ -180,13 +184,16 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
     /**
      * 获取热门专辑
      */
-    public void getHotAlbumList() {
+    public void getHotAlbumList(String currentSubjectId) {
         if (getView() != null) {
             getView().showLoading();
         }
         JSONObject jsonObject = new JSONObject();
         try {
             jsonObject.putOpt("albumStatus", "YES");
+            if (!TextUtils.isEmpty(currentSubjectId)) {
+                jsonObject.putOpt("subjectIds", currentSubjectId);
+            }
         } catch (JSONException e) {
             e.printStackTrace();
         }
@@ -203,13 +210,16 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
     /**
      * 获取热门曲目
      */
-    public void getHotMusicSheetList(){
+    public void getHotMusicSheetList(String currentSubjectId) {
         if (getView() != null) {
             getView().showLoading();
         }
         JSONObject jsonObject = new JSONObject();
         try {
             jsonObject.putOpt("myself", false);
+            if (!TextUtils.isEmpty(currentSubjectId)) {
+                jsonObject.putOpt("subjectIds", currentSubjectId);
+            }
         } catch (JSONException e) {
             e.printStackTrace();
         }
@@ -238,4 +248,17 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
             }
         });
     }
+
+    /**
+     * 获取热门专辑
+     */
+    public void syncSubjectFilter(String currentSubjectId) {
+        Map<String, String> params = new HashMap<>();
+        params.put("subjectId", currentSubjectId);
+        addSubscribe(create(APIService.class).syncSubjectFilter(params), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+            }
+        });
+    }
 }

+ 81 - 7
teacher/src/main/java/com/cooleshow/teacher/ui/main/NewHomeFragment.java

@@ -3,8 +3,11 @@ package com.cooleshow.teacher.ui.main;
 import android.text.TextUtils;
 import android.view.Gravity;
 import android.view.View;
+import android.widget.TextView;
 
 import com.alibaba.android.arouter.launcher.ARouter;
+import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
+import com.bigkoo.pickerview.view.OptionsPickerView;
 import com.bumptech.glide.Glide;
 import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.chad.library.adapter.base.listener.OnItemClickListener;
@@ -34,6 +37,8 @@ import com.cooleshow.teacher.bean.HomeHotMusicSheetBean;
 import com.cooleshow.teacher.bean.HomeHotMusicSheetItemBean;
 import com.cooleshow.teacher.bean.HomeLiveAndVideoBean;
 import com.cooleshow.teacher.bean.HomeMenuBean;
+import com.cooleshow.teacher.bean.QuerySubjectBean;
+import com.cooleshow.teacher.bean.SubjectBean;
 import com.cooleshow.teacher.bean.TeacherUserInfo;
 import com.cooleshow.teacher.constants.CourseConstants;
 import com.cooleshow.teacher.constants.TeacherInfoConstants;
@@ -88,7 +93,10 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     private SmartRefreshLayout refreshLayout;
     private HomeHotMusicSheetAdapter mRecommendAdapter;
     private HomeHotMusicSheetAdapter mLatestAdapter;
-    //    private HomeGoodMusicSheetAdapter mGoodMusicSheetAdapter;
+    private OptionsPickerView pvOptions;
+    private List<SubjectBean> subjectBeanList = new ArrayList<>();
+    private int currentSelectSubjectPosition = 0;
+    private String currentSubjectId = "";
 
     @Override
     protected void initView(View rootView) {
@@ -171,10 +179,10 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         mViewBinding.tvHotTrackMore.setOnClickListener(this);
         mViewBinding.tvRecommendTrackMore.setOnClickListener(this);
         mViewBinding.tvLatestTrackMore.setOnClickListener(this);
+        mViewBinding.tvCurrentSubject.setOnClickListener(this);
         mViewBinding.refreshLayout.setOnRefreshListener(refreshLayout -> {
             mViewBinding.refreshLayout.finishRefresh();
-            presenter.getHotAlbumList();
-            presenter.getHotMusicSheetList();
+            refreshMusicData();
             presenter.queryCountOfUnread();
             presenter.queryLiveAndVideo();
             presenter.appHome();
@@ -218,10 +226,6 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
             presenter.queryCountOfUnread();
             presenter.queryLiveAndVideo();
             presenter.appHome();
-            //热门专辑
-            presenter.getHotAlbumList();
-            //热门曲目
-            presenter.getHotMusicSheetList();
             //获取领奖状态
             presenter.getAwardStatus();
         }
@@ -526,6 +530,11 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         if (mViewBinding == null || mViewBinding.tvTeacherName == null) {
             return;
         }
+        //处理声部
+        currentSubjectId = teacherUserInfo.defaultSubject;
+        mViewBinding.tvCurrentSubject.setText(!TextUtils.isEmpty(teacherUserInfo.defaultSubjectName) ? teacherUserInfo.defaultSubjectName : "全部");
+        handleSubjects(teacherUserInfo.subjectName, teacherUserInfo.subjectId);
+        refreshMusicData();
         //昵称
         if (teacherUserInfo != null) {
             String teacherName = UserHelper.getTeacherName(teacherUserInfo.username, teacherUserInfo.userId);
@@ -580,6 +589,24 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         }
     }
 
+    private void handleSubjects(String subjectName, String subjectId) {
+        try {
+            subjectBeanList.clear();
+            String[] subjectNames = UiUtils.splitSubjectName(subjectName);
+            String[] subjectIds = UiUtils.splitSubjectId(subjectId);
+            if (subjectIds != null && subjectIds.length > 0) {
+                for (int i = 0; i < subjectIds.length; i++) {
+                    String id = subjectIds[i];
+                    String name = subjectNames[i];
+                    SubjectBean querySubjectBean = new SubjectBean(name, id);
+                    subjectBeanList.add(querySubjectBean);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     private void handleBadgeUI(String tag) {
         int badgeAbleCount = 0;
         boolean enableStyleBadge = isEnableForBadge(tag, STYLE_TYPE);
@@ -699,6 +726,11 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
             showBadgeDialog();
             return;
         }
+
+        if (id == R.id.tv_current_subject) {
+            selectSubject();
+            return;
+        }
     }
 
     private void showRecommendMenuDialog() {
@@ -728,4 +760,46 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         BadgeDesDialog badgeDesDialog = new BadgeDesDialog(getContext());
         badgeDesDialog.show();
     }
+
+    private void selectSubject() {
+        if (subjectBeanList.size() == 0) {
+            subjectBeanList.add(new SubjectBean("全部", ""));
+        }
+        pvOptions = new OptionsPickerBuilder(getContext(), (options1, options2, options3, v) -> {
+            this.currentSelectSubjectPosition = options1;
+            SubjectBean bean = subjectBeanList.get(options1);
+            currentSubjectId = bean.id;
+            mViewBinding.tvCurrentSubject.setText(bean.name);
+            if (presenter != null) {
+                //同步选中id
+                presenter.syncSubjectFilter(currentSubjectId);
+            }
+            refreshMusicData();
+        }).setLayoutRes(R.layout.pickerview_address_layout, v -> {
+            //自定义布局中的控件初始化及事件处理
+            final TextView tvSubmit = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_finish);
+            TextView ivCancel = (TextView) v.findViewById(com.cooleshow.base.R.id.tv_cancel);
+            tvSubmit.setOnClickListener(v12 -> {
+                pvOptions.returnData();
+                pvOptions.dismiss();
+            });
+            ivCancel.setOnClickListener(v1 -> pvOptions.dismiss());
+
+        }).isDialog(false).build();
+        pvOptions.setPicker(subjectBeanList);
+        if (currentSelectSubjectPosition < subjectBeanList.size()) {
+            pvOptions.setSelectOptions(currentSelectSubjectPosition);
+        }
+        pvOptions.show();
+    }
+
+    /**
+     * 刷新专辑和曲目数据
+     */
+    private void refreshMusicData() {
+        //热门专辑
+        presenter.getHotAlbumList(currentSubjectId);
+        //热门曲目
+        presenter.getHotMusicSheetList(currentSubjectId);
+    }
 }

+ 41 - 11
teacher/src/main/res/layout/fragment_new_home_layout.xml

@@ -116,13 +116,14 @@
                     android:id="@+id/tv_score_name"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:layout_marginStart="14dp"
                     android:layout_marginTop="2dp"
+                    android:layout_marginEnd="4dp"
                     android:text="评分"
                     android:textColor="@color/color_666666"
                     android:textSize="@dimen/sp_12"
-                    app:layout_constraintLeft_toLeftOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
+                    app:layout_constraintBottom_toBottomOf="@+id/rating_bar"
+                    app:layout_constraintRight_toLeftOf="@+id/rating_bar"
+                    app:layout_constraintTop_toTopOf="@+id/rating_bar" />
 
                 <RatingBar
                     android:id="@+id/rating_bar"
@@ -130,13 +131,14 @@
                     android:layout_width="wrap_content"
                     android:layout_height="19dp"
                     android:layout_marginStart="4dp"
+                    android:layout_marginEnd="25dp"
                     android:numStars="5"
                     android:rating="0"
                     android:stepSize="1"
                     android:visibility="visible"
-                    app:layout_constraintBottom_toBottomOf="@+id/tv_score_name"
-                    app:layout_constraintLeft_toRightOf="@+id/tv_score_name"
-                    app:layout_constraintTop_toTopOf="@+id/tv_score_name" />
+                    app:layout_constraintBottom_toBottomOf="@+id/view_badge"
+                    app:layout_constraintRight_toRightOf="parent"
+                    app:layout_constraintTop_toTopOf="@+id/view_badge" />
 
 
                 <ImageView
@@ -144,10 +146,10 @@
                     android:layout_width="23dp"
                     android:layout_height="23dp"
                     android:layout_marginStart="14dp"
-                    android:layout_marginTop="23dp"
+                    android:layout_marginTop="5dp"
                     android:background="@drawable/icon_style_badge_new_enable"
                     app:layout_constraintLeft_toLeftOf="parent"
-                    app:layout_constraintTop_toBottomOf="@+id/rating_bar" />
+                    app:layout_constraintTop_toTopOf="@+id/top_view_bg" />
 
                 <ImageView
                     android:id="@+id/iv_video_badge"
@@ -221,13 +223,13 @@
                     android:id="@+id/iv_cert"
                     android:layout_width="wrap_content"
                     android:layout_height="30dp"
+                    android:layout_marginTop="13dp"
                     android:layout_marginEnd="25dp"
                     android:adjustViewBounds="true"
                     android:clickable="false"
                     android:src="@drawable/icon_home_un_certification"
-                    app:layout_constraintBottom_toBottomOf="@+id/iv_style_badge"
                     app:layout_constraintRight_toRightOf="parent"
-                    app:layout_constraintTop_toTopOf="@+id/iv_style_badge" />
+                    app:layout_constraintTop_toBottomOf="@+id/iv_style_badge" />
 
                 <TextView
                     android:id="@+id/tv_cert_fail_tip"
@@ -256,11 +258,39 @@
                     app:layout_constraintRight_toRightOf="@+id/iv_cert"
                     app:layout_constraintTop_toTopOf="@+id/iv_cert" />
 
+                <TextView
+                    android:id="@+id/tv_subject_title"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_marginStart="14dp"
+                    android:text="声部:"
+                    android:textColor="@color/color_333333"
+                    android:textSize="@dimen/sp_14"
+                    app:layout_constraintBottom_toBottomOf="@+id/iv_cert"
+                    app:layout_constraintLeft_toLeftOf="parent"
+                    app:layout_constraintTop_toTopOf="@+id/iv_cert" />
+
+                <TextView
+                    android:gravity="center"
+                    android:id="@+id/tv_current_subject"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:drawableRight="@drawable/icon_arrow_down2"
+                    android:drawablePadding="5dp"
+                    android:paddingTop="5dp"
+                    android:paddingBottom="5dp"
+                    android:textColor="@color/color_666666"
+                    android:textSize="@dimen/sp_14"
+                    app:layout_constraintBottom_toBottomOf="@+id/tv_subject_title"
+                    app:layout_constraintLeft_toRightOf="@+id/tv_subject_title"
+                    app:layout_constraintTop_toTopOf="@+id/tv_subject_title"
+                    tools:text="中音萨克斯" />
+
                 <View
                     android:id="@+id/top_help_line"
                     android:layout_width="1px"
                     android:layout_height="1px"
-                    android:layout_marginTop="17dp"
+                    android:layout_marginTop="10dp"
                     app:layout_constraintLeft_toLeftOf="parent"
                     app:layout_constraintTop_toBottomOf="@+id/iv_cert" />