|
@@ -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;
|