Browse Source

修改机构端个人中心常用功能模块样式

Pq 1 year ago
parent
commit
df6427014d

+ 45 - 0
institution/src/main/java/com/cooleshow/institution/stu/adapter/JGMineCommonFunctionAdapter2.java

@@ -0,0 +1,45 @@
+package com.cooleshow.institution.stu.adapter;
+
+import java.util.ArrayList;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
+import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+
+/**
+ * Author by pq, Date on 2024/4/9.
+ */
+public class JGMineCommonFunctionAdapter2 extends FragmentStateAdapter {
+    private ArrayList<Fragment> mFragments;
+    public JGMineCommonFunctionAdapter2(@NonNull Fragment fragment) {
+        super(fragment);
+    }
+
+    public void setData(ArrayList<Fragment> fragments) {
+        this.mFragments = fragments;
+        notifyDataSetChanged();
+    }
+
+    @NonNull
+    @Override
+    public Fragment createFragment(int position) {
+        return mFragments.get(position);
+    }
+
+    @Override
+    public int getItemCount() {
+        return mFragments != null ? mFragments.size() : 0;
+    }
+
+    @Override
+    public long getItemId(int position) {
+        Fragment fragment = mFragments.get(position);
+        return fragment != null ? fragment.hashCode() : super.getItemId(position);
+    }
+
+    @Override
+    public boolean containsItem(long itemId) {
+        return super.containsItem(itemId);
+    }
+}

+ 60 - 57
institution/src/main/java/com/cooleshow/institution/stu/ui/main/MineFragment.java

@@ -2,6 +2,8 @@ package com.cooleshow.institution.stu.ui.main;
 
 import android.text.TextUtils;
 import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
 
 import com.alibaba.android.arouter.launcher.ARouter;
 import com.chad.library.adapter.base.BaseQuickAdapter;
@@ -11,12 +13,14 @@ import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.DateUtil;
 import com.cooleshow.base.utils.GlideUtils;
+import com.cooleshow.base.utils.SizeUtils;
 import com.cooleshow.base.utils.TimeUtils;
 import com.cooleshow.base.utils.UiUtils;
 import com.cooleshow.base.utils.Utils;
 import com.cooleshow.base.utils.helper.QMUIDeviceHelper;
 import com.cooleshow.institution.stu.R;
 import com.cooleshow.institution.stu.adapter.JGMineCommonFunctionAdapter;
+import com.cooleshow.institution.stu.adapter.JGMineCommonFunctionAdapter2;
 import com.cooleshow.institution.stu.bean.CountOfUnreadBean;
 import com.cooleshow.institution.stu.constants.JGMineCommonFunctionType;
 import com.cooleshow.institution.stu.constants.JGWebConstants;
@@ -31,14 +35,15 @@ import java.util.Arrays;
 import java.util.List;
 
 import androidx.annotation.NonNull;
+import androidx.fragment.app.Fragment;
 import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.viewpager2.widget.ViewPager2;
 
 /**
  * Author by pq, Date on 2023/9/13.
  */
 public class MineFragment extends BaseMVPFragment<FgMineLayoutBinding, MinePresenter> implements View.OnClickListener, MineContract.MineContractView {
-
-    private JGMineCommonFunctionAdapter mAdapter;
+    public static final int MAX_ITEM_FOR_PAGE = 4;
 
     @Override
     protected void initView(View rootView) {
@@ -49,16 +54,51 @@ public class MineFragment extends BaseMVPFragment<FgMineLayoutBinding, MinePrese
     protected void initData() {
         JGMineCommonFunctionType[] values = JGMineCommonFunctionType.values();
         ArrayList<JGMineCommonFunctionType> list = new ArrayList<>(Arrays.asList(values));
-        mAdapter = new JGMineCommonFunctionAdapter();
-        mAdapter.setList(list);
-        boolean isTablet = QMUIDeviceHelper.isTablet(getContext());
-        int count = isTablet ? 6 : 5;
-        GridLayoutManager layoutManager = new GridLayoutManager(getContext(), count);
-        mViewBinding.recyclerViewCommon.setLayoutManager(layoutManager);
-        mViewBinding.recyclerViewCommon.setAdapter(mAdapter);
+        ArrayList<Fragment> fragments = initHomeMenu(list);
+        initIndicator(fragments);
+        JGMineCommonFunctionAdapter2 adapter2 = new JGMineCommonFunctionAdapter2(this);
+        adapter2.setData(fragments);
+        mViewBinding.viewpagerMenu.setAdapter(adapter2);
+
         initListener();
     }
 
+    private ArrayList<Fragment> initHomeMenu(ArrayList<JGMineCommonFunctionType> data) {
+        ArrayList<Fragment> fragments = new ArrayList<>();
+        if (data != null && data.size() > 0) {
+            int count = data.size() / MAX_ITEM_FOR_PAGE;
+            if (data.size() % MAX_ITEM_FOR_PAGE > 0) {
+                count++;
+            }
+
+            for (int i = 0; i < count; i++) {
+                ArrayList<String> dataList = new ArrayList<String>();
+                int j = i * MAX_ITEM_FOR_PAGE;
+                while (j < data.size() && j < (i + 1) * MAX_ITEM_FOR_PAGE) {
+                    dataList.add(data.get(j).getId());
+                    j++;
+                }
+                fragments.add(MineMenuFragment.newInstance(dataList));
+            }
+        }
+        return fragments;
+    }
+
+    private void initIndicator(ArrayList<Fragment> fragments) {
+        mViewBinding.rgGroup.removeAllViews();
+        for (int i = 0; i < fragments.size(); i++) {
+            RadioButton indicator = createIndicator();
+            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(SizeUtils.dp2px(12), SizeUtils.dp2px(4));
+            mViewBinding.rgGroup.addView(indicator, layoutParams);
+        }
+    }
+
+    private RadioButton createIndicator() {
+        RadioButton radioButton = new RadioButton(getContext());
+        radioButton.setButtonDrawable(R.drawable.selector_common_indicator);
+        return radioButton;
+    }
+
     private void initListener() {
         mViewBinding.ivSetting.setOnClickListener(this);
         mViewBinding.viewClassNum.setOnClickListener(this);
@@ -70,17 +110,22 @@ public class MineFragment extends BaseMVPFragment<FgMineLayoutBinding, MinePrese
         mViewBinding.tvAboutUs.setOnClickListener(this);
         mViewBinding.imMessage.setOnClickListener(this);
 
-        mAdapter.setOnItemClickListener(new OnItemClickListener() {
+        mViewBinding.viewpagerMenu.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
             @Override
-            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
-                if (position < mAdapter.getData().size()) {
-                    JGMineCommonFunctionType jgMineCommonFunctionType = mAdapter.getData().get(position);
-                    goPage(jgMineCommonFunctionType);
-                }
+            public void onPageSelected(int position) {
+                super.onPageSelected(position);
+                checkIndicator(position);
             }
         });
     }
 
+    private void checkIndicator(int position) {
+        if (position < mViewBinding.rgGroup.getChildCount()) {
+            int id = mViewBinding.rgGroup.getChildAt(position).getId();
+            mViewBinding.rgGroup.check(id);
+        }
+    }
+
     @Override
     protected FgMineLayoutBinding getLayoutView() {
         return FgMineLayoutBinding.inflate(getLayoutInflater());
@@ -97,48 +142,6 @@ public class MineFragment extends BaseMVPFragment<FgMineLayoutBinding, MinePrese
         presenter.queryCountOfUnread();
     }
 
-    private void goPage(JGMineCommonFunctionType functionType) {
-        if (UiUtils.isFastClick(500)) {
-            return;
-        }
-        if (functionType == JGMineCommonFunctionType.MINE_TRACK_LIST) {
-            //我的曲库
-            JGWebStartHelper.startMineMusicList();
-            return;
-        }
-
-        if (functionType == JGMineCommonFunctionType.PRACTICE_INFO) {
-            //练习详情
-            JGWebStartHelper.startPracticeRecord();
-            return;
-        }
-
-        if (functionType == JGMineCommonFunctionType.ORDER_INFO) {
-            //订单信息
-            JGWebStartHelper.startOrderInfo();
-            return;
-        }
-
-        if (functionType == JGMineCommonFunctionType.RANK_BOARD) {
-            //排行榜
-            JGWebStartHelper.startRankBoard();
-            return;
-        }
-
-        if (functionType == JGMineCommonFunctionType.ACTIVATION_CODE) {
-            //激活码
-            JGWebStartHelper.startActivationCodePage();
-            return;
-        }
-
-        if (functionType == JGMineCommonFunctionType.MINE_WORKS) {
-            //我的作品
-            ARouter.getInstance().build(RouterPath.Homework.MY_WORK)
-                    .navigation();
-            return;
-        }
-    }
-
     public void refreshUserInfo(StudentUserInfo data) {
         if (isDetached()) {
             return;

+ 120 - 0
institution/src/main/java/com/cooleshow/institution/stu/ui/main/MineMenuFragment.java

@@ -0,0 +1,120 @@
+package com.cooleshow.institution.stu.ui.main;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+
+import com.alibaba.android.arouter.launcher.ARouter;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.listener.OnItemClickListener;
+import com.cooleshow.base.router.RouterPath;
+import com.cooleshow.base.ui.fragment.BaseFragment;
+import com.cooleshow.base.utils.UiUtils;
+import com.cooleshow.institution.stu.adapter.JGMineCommonFunctionAdapter;
+import com.cooleshow.institution.stu.constants.JGMineCommonFunctionType;
+import com.cooleshow.institution.stu.constants.JGWebStartHelper;
+import com.cooleshow.institution.stu.databinding.FragmentMineMenuBinding;
+
+import java.util.ArrayList;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+/**
+ * 创建日期:2022/5/26 17:33
+ *
+ * @author Ryan
+ * 类说明:
+ */
+public class MineMenuFragment extends BaseFragment<FragmentMineMenuBinding> {
+    private ArrayList<JGMineCommonFunctionType> itemBeanList = new ArrayList<>();
+    private JGMineCommonFunctionAdapter mAdapter;
+
+
+    public static MineMenuFragment newInstance(ArrayList<String> itemBeanList) {
+        Bundle args = new Bundle();
+        MineMenuFragment fragment = new MineMenuFragment();
+        args.putStringArrayList("itemBeanList", itemBeanList);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    protected FragmentMineMenuBinding getLayoutView() {
+        return FragmentMineMenuBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected void initView(View rootView) {
+        if (getArguments() != null) {
+            itemBeanList = new ArrayList<>();
+            ArrayList<String> itemBeanList1 = getArguments().getStringArrayList("itemBeanList");
+            for (int i = 0; i < itemBeanList1.size(); i++) {
+                String s = itemBeanList1.get(i);
+                itemBeanList.add(JGMineCommonFunctionType.valueOf(s));
+            }
+        }
+        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), MineFragment.MAX_ITEM_FOR_PAGE);
+        mViewBinding.rvMenu.setLayoutManager(gridLayoutManager);
+        mAdapter = new JGMineCommonFunctionAdapter();
+        mViewBinding.rvMenu.setAdapter(mAdapter);
+        mAdapter.setNewInstance(itemBeanList);
+        mAdapter.setOnItemClickListener(new OnItemClickListener() {
+            @Override
+            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
+                if (position < mAdapter.getData().size()) {
+                    JGMineCommonFunctionType jgMineCommonFunctionType = mAdapter.getData().get(position);
+                    goPage(jgMineCommonFunctionType);
+                }
+            }
+        });
+    }
+
+    @Override
+    protected void initData() {
+
+    }
+
+    private void goPage(JGMineCommonFunctionType functionType) {
+        if (UiUtils.isFastClick(500)) {
+            return;
+        }
+        if (functionType == JGMineCommonFunctionType.MINE_TRACK_LIST) {
+            //我的曲库
+            JGWebStartHelper.startMineMusicList();
+            return;
+        }
+
+        if (functionType == JGMineCommonFunctionType.PRACTICE_INFO) {
+            //练习详情
+            JGWebStartHelper.startPracticeRecord();
+            return;
+        }
+
+        if (functionType == JGMineCommonFunctionType.ORDER_INFO) {
+            //订单信息
+            JGWebStartHelper.startOrderInfo();
+            return;
+        }
+
+        if (functionType == JGMineCommonFunctionType.RANK_BOARD) {
+            //排行榜
+            JGWebStartHelper.startRankBoard();
+            return;
+        }
+
+        if (functionType == JGMineCommonFunctionType.ACTIVATION_CODE) {
+            //激活码
+            JGWebStartHelper.startActivationCodePage();
+            return;
+        }
+
+        if (functionType == JGMineCommonFunctionType.MINE_WORKS) {
+            //我的作品
+            ARouter.getInstance().build(RouterPath.Homework.MY_WORK)
+                    .navigation();
+            return;
+        }
+    }
+}

+ 6 - 0
institution/src/main/res/drawable/selector_common_indicator.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:drawable="@drawable/shape_ff497b_4dp" android:state_selected="true"/>
+    <item android:drawable="@drawable/shape_ff497b_4dp" android:state_checked="true"/>
+    <item android:drawable="@drawable/shape_mine_menu_indicator_normal"/>
+</selector>

+ 7 - 0
institution/src/main/res/drawable/shape_ff497b_4dp.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/color_ff497b"/>
+    <corners android:radius="4dp"/>
+    <size android:width="12dp"
+        android:height="4dp"/>
+</shape>

+ 17 - 0
institution/src/main/res/drawable/shape_mine_menu_indicator_normal.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- 连框颜色值 -->
+    <item>
+        <shape>
+            <size android:width="12dp" android:height="4dp"/>
+        </shape>
+    </item>
+    <!-- 主体背景颜色值 -->
+    <item android:gravity="center">
+        <shape android:shape="oval">
+            <size android:height="4dp" android:width="4dp"/>
+            <solid android:color="@color/color_e8e8e8" />/>
+        </shape>
+    </item>
+
+</layer-list>

+ 17 - 7
institution/src/main/res/layout/fg_mine_layout.xml

@@ -10,8 +10,8 @@
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
-        android:clipChildren="false"
         android:layout_height="wrap_content"
+        android:clipChildren="false"
         android:paddingBottom="12dp">
 
 
@@ -204,9 +204,9 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="27dp"
-            android:paddingBottom="15dp"
             android:clipChildren="false"
             android:clipToPadding="false"
+            android:paddingBottom="15dp"
             app:layout_constraintLeft_toLeftOf="parent"
             app:layout_constraintTop_toBottomOf="@+id/iv_avatar">
 
@@ -373,7 +373,6 @@
         </androidx.constraintlayout.widget.ConstraintLayout>
 
 
-
         <androidx.constraintlayout.widget.ConstraintLayout
             android:id="@+id/cs_common_function"
             android:layout_width="match_parent"
@@ -382,7 +381,7 @@
             android:layout_marginTop="12dp"
             android:layout_marginEnd="13dp"
             android:background="@drawable/shape_10dp_white"
-            android:paddingBottom="16dp"
+            android:paddingBottom="10dp"
             app:layout_constraintTop_toBottomOf="@+id/view_top_white_bg">
 
 
@@ -401,17 +400,28 @@
                 app:layout_constraintLeft_toLeftOf="parent"
                 app:layout_constraintTop_toTopOf="parent" />
 
-            <androidx.recyclerview.widget.RecyclerView
-                android:id="@+id/recyclerView_common"
+            <androidx.viewpager2.widget.ViewPager2
+                android:id="@+id/viewpager_menu"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="4dp"
+                android:layout_marginTop="5dp"
+                android:minHeight="53dp"
                 android:overScrollMode="never"
                 android:scrollbars="none"
                 app:layout_constraintLeft_toLeftOf="parent"
                 app:layout_constraintRight_toRightOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/tv_common_function" />
 
+            <RadioGroup
+                android:orientation="horizontal"
+                app:layout_constraintRight_toRightOf="parent"
+                app:layout_constraintLeft_toLeftOf="parent"
+                android:layout_marginTop="20dp"
+                app:layout_constraintTop_toBottomOf="@+id/viewpager_menu"
+                android:id="@+id/rg_group"
+                android:layout_width="wrap_content"
+                android:layout_height="4dp"/>
+
         </androidx.constraintlayout.widget.ConstraintLayout>
 
         <androidx.constraintlayout.widget.ConstraintLayout

+ 14 - 0
institution/src/main/res/layout/fragment_mine_menu.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="horizontal">
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/rv_menu"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:overScrollMode="never"
+        android:scrollbars="none" />
+</FrameLayout>