|
@@ -0,0 +1,279 @@
|
|
|
+package com.cooleshow.student.ui.course;
|
|
|
+
|
|
|
+import android.graphics.Color;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
|
|
+import com.bigkoo.pickerview.listener.OnDismissListener;
|
|
|
+import com.bigkoo.pickerview.view.OptionsPickerView;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemClickListener;
|
|
|
+import com.cooleshow.base.bean.SubjectListBean;
|
|
|
+import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIDeviceHelper;
|
|
|
+import com.cooleshow.base.utils.helper.WebStartHelper;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.base.widgets.GridItemDecoration;
|
|
|
+import com.cooleshow.student.R;
|
|
|
+import com.cooleshow.student.adapter.GroupCourseAppointAdapter;
|
|
|
+import com.cooleshow.student.adapter.LiveCourseAppointAdapter;
|
|
|
+import com.cooleshow.student.bean.LiveCourseAppointListBean;
|
|
|
+import com.cooleshow.student.contract.GroupCourseAppointListContract;
|
|
|
+import com.cooleshow.student.contract.LiveCourseAppointListContract;
|
|
|
+import com.cooleshow.student.databinding.FgGroupCourseAppointListLayoutBinding;
|
|
|
+import com.cooleshow.student.databinding.FgLiveCourseAppointListLayoutBinding;
|
|
|
+import com.cooleshow.student.presenter.course.GroupCourseAppointListPresenter;
|
|
|
+import com.cooleshow.student.presenter.course.LiveCourseAppointListPresenter;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.scwang.smart.refresh.footer.ClassicsFooter;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2024/11/13.
|
|
|
+ * 小组课约课
|
|
|
+ */
|
|
|
+public class GroupCourseAppointListFragment extends BaseMVPFragment<FgGroupCourseAppointListLayoutBinding, GroupCourseAppointListPresenter> implements GroupCourseAppointListContract.View, View.OnClickListener {
|
|
|
+ private List<SubjectListBean.RowsBean> subjectBeanList = new ArrayList<>();
|
|
|
+ private GroupCourseAppointAdapter mAdapter;
|
|
|
+ private OptionsPickerView pvOptions;
|
|
|
+ private int currentSelectSubjectPosition = -1;
|
|
|
+ private String currentSubjectId;
|
|
|
+ private int currentPage = 1;
|
|
|
+ private boolean hasNext = true;
|
|
|
+ private String searchCondition;
|
|
|
+
|
|
|
+ public static GroupCourseAppointListFragment newInstance() {
|
|
|
+ GroupCourseAppointListFragment fragment = new GroupCourseAppointListFragment();
|
|
|
+ return fragment;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FgGroupCourseAppointListLayoutBinding getLayoutView() {
|
|
|
+ return FgGroupCourseAppointListLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+ currentSubjectId = UserHelper.getSubjectId();
|
|
|
+ String subjectName = UserHelper.getSubjectName();
|
|
|
+ mViewBinding.tvFilter.setText(subjectName);
|
|
|
+
|
|
|
+ mAdapter = new GroupCourseAppointAdapter();
|
|
|
+ EmptyViewLayout emptyViewLayout = new EmptyViewLayout(getContext());
|
|
|
+ emptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_course, "暂无课程");
|
|
|
+ mAdapter.setEmptyView(emptyViewLayout);
|
|
|
+ RecyclerView.LayoutManager layoutManager;
|
|
|
+ if(QMUIDeviceHelper.isTablet(getContext())){
|
|
|
+ layoutManager = new GridLayoutManager(getContext(),2);
|
|
|
+ GridItemDecoration itemDecoration =new GridItemDecoration(2,0,0, SizeUtils.dp2px(6));
|
|
|
+ mViewBinding.recyclerViewList.addItemDecoration(itemDecoration);
|
|
|
+ }else{
|
|
|
+ layoutManager =new LinearLayoutManager(getContext());
|
|
|
+ }
|
|
|
+ mViewBinding.recyclerViewList.setLayoutManager(layoutManager);
|
|
|
+ mViewBinding.recyclerViewList.setAdapter(mAdapter);
|
|
|
+ initListener();
|
|
|
+ getData(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mViewBinding.tvFilter.setOnClickListener(this);
|
|
|
+ mViewBinding.tvSearch.setOnClickListener(this);
|
|
|
+ mViewBinding.refreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ currentPage = 1;
|
|
|
+ getData(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mViewBinding.refreshLayout.setOnLoadMoreListener(new com.scwang.smart.refresh.layout.listener.OnLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ //上拉加载
|
|
|
+ if (hasNext) {
|
|
|
+ currentPage++;
|
|
|
+ getData(false);
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ mAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ if(position<mAdapter.getData().size()){
|
|
|
+ LiveCourseAppointListBean.RowsBean rowsBean = mAdapter.getData().get(position);
|
|
|
+ WebStartHelper.startAppointmentGroupCourse(rowsBean.getCourseGroupId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected GroupCourseAppointListPresenter createPresenter() {
|
|
|
+ return new GroupCourseAppointListPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void querySubjectItemSuccess(SubjectListBean subjectListBean) {
|
|
|
+ ArrayList<SubjectListBean.RowsBean> data = subjectListBean.getRows();
|
|
|
+ if (data != null) {
|
|
|
+ subjectBeanList.clear();
|
|
|
+ subjectBeanList.addAll(data);
|
|
|
+ if (currentSelectSubjectPosition == -1) {
|
|
|
+ String subjectId = UserHelper.getSubjectId();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ SubjectListBean.RowsBean rowsBean = data.get(i);
|
|
|
+ if (TextUtils.equals(subjectId, rowsBean.getId())) {
|
|
|
+ currentSelectSubjectPosition = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetLiveCourseSuccess(int page, LiveCourseAppointListBean dataList) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LOG.i("pq", "onGetLiveCourseSuccess:" + dataList);
|
|
|
+ if (dataList != null) {
|
|
|
+ if (page == 1) {
|
|
|
+ //第一页
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ if (mAdapter != null) {
|
|
|
+ mAdapter.getData().clear();
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+ if (dataList.getRows() != null && dataList.getRows().size() > 0) {
|
|
|
+ checkHasNext(dataList.getRows().size());
|
|
|
+ mAdapter.setNewInstance(dataList.getRows());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ if (mAdapter != null) {
|
|
|
+ if (dataList.getRows() != null && dataList.getRows().size() > 0) {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore();
|
|
|
+ mAdapter.addData(dataList.getRows());
|
|
|
+ checkHasNext(dataList.getRows().size());
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constants.DEFAULT_DATA_SIZE;
|
|
|
+// mViewBinding.refreshLayout.setNoMoreData(!hasNext);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetLiveCourseError(int page) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ if (mAdapter != null) {
|
|
|
+ currentPage--;
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ int id = v.getId();
|
|
|
+ if (id == R.id.tv_filter) {
|
|
|
+ selectSubjectType();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (id == R.id.tv_search) {
|
|
|
+ searchCondition = mViewBinding.etTargetName.getText().toString().trim();
|
|
|
+ currentPage = 1;
|
|
|
+ getData(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getData(boolean isShowLoading) {
|
|
|
+ if (currentPage == 1) {
|
|
|
+ mViewBinding.refreshLayout.resetNoMoreData();
|
|
|
+ }
|
|
|
+ presenter.queryGroupCourse(isShowLoading, currentSubjectId, searchCondition, currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectSubjectType() {
|
|
|
+ if (subjectBeanList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (pvOptions == null) {
|
|
|
+ pvOptions = new OptionsPickerBuilder(getContext(), (options1, options2, options3, v) -> {
|
|
|
+ this.currentSelectSubjectPosition = options1;
|
|
|
+ SubjectListBean.RowsBean subjectBean = subjectBeanList.get(options1);
|
|
|
+ this.currentSubjectId = subjectBean.getId();
|
|
|
+ mViewBinding.tvFilter.setText(subjectBean.getPickerViewText());
|
|
|
+ currentPage = 1;
|
|
|
+ getData(false);
|
|
|
+ }).setLayoutRes(com.cooleshow.base.R.layout.pickerview_select_options_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());
|
|
|
+
|
|
|
+ }).setTextColorOut(getResources().getColor(com.cooleshow.base.R.color.color_aaaaaa))
|
|
|
+ .setDividerColor(Color.TRANSPARENT)
|
|
|
+ .setBgColor(Color.TRANSPARENT).isDialog(false).build();
|
|
|
+ pvOptions.setOnDismissListener(new OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss(Object o) {
|
|
|
+ UiUtils.refreshFilterTextStyle(false, mViewBinding.tvFilter);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onShow() {
|
|
|
+ UiUtils.refreshFilterTextStyle(true, mViewBinding.tvFilter);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ pvOptions.setPicker(subjectBeanList);
|
|
|
+ if (currentSelectSubjectPosition != -1 && currentSelectSubjectPosition < subjectBeanList.size()) {
|
|
|
+ pvOptions.setSelectOptions(currentSelectSubjectPosition);
|
|
|
+ }
|
|
|
+ pvOptions.show();
|
|
|
+ }
|
|
|
+}
|