|
@@ -1,25 +1,55 @@
|
|
|
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.cooleshow.base.constanst.Constants;
|
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.student.R;
|
|
|
+import com.cooleshow.student.adapter.LiveCourseAppointAdapter;
|
|
|
+import com.cooleshow.student.adapter.VideoCourseAppointAdapter;
|
|
|
import com.cooleshow.student.bean.QuerySubjectBean;
|
|
|
+import com.cooleshow.student.bean.VideoCourseListBean;
|
|
|
import com.cooleshow.student.contract.LiveCourseAppointListContract;
|
|
|
import com.cooleshow.student.contract.VideoCourseAppointListContract;
|
|
|
import com.cooleshow.student.databinding.FgLiveCourseAppointListLayoutBinding;
|
|
|
import com.cooleshow.student.databinding.FgVideoCourseAppointListLayoutBinding;
|
|
|
import com.cooleshow.student.presenter.course.LiveCourseAppointListPresenter;
|
|
|
import com.cooleshow.student.presenter.course.VideoCourseAppointListPresenter;
|
|
|
+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.LinearLayoutManager;
|
|
|
+
|
|
|
/**
|
|
|
* Author by pq, Date on 2024/11/13.
|
|
|
* 视频课约课
|
|
|
*/
|
|
|
-public class VideoCourseAppointListFragment extends BaseMVPFragment<FgVideoCourseAppointListLayoutBinding, VideoCourseAppointListPresenter> implements VideoCourseAppointListContract.View {
|
|
|
+public class VideoCourseAppointListFragment extends BaseMVPFragment<FgVideoCourseAppointListLayoutBinding, VideoCourseAppointListPresenter> implements VideoCourseAppointListContract.View, View.OnClickListener {
|
|
|
private List<QuerySubjectBean> subjectBeanList = new ArrayList<>();
|
|
|
+ private OptionsPickerView pvOptions;
|
|
|
+ private int currentSelectSubjectPosition = -1;
|
|
|
+ private String currentSubjectId;
|
|
|
+ private int currentPage = 1;
|
|
|
+ private boolean hasNext = true;
|
|
|
+ private String searchCondition;
|
|
|
+ private VideoCourseAppointAdapter mAdapter;
|
|
|
+
|
|
|
+
|
|
|
public static VideoCourseAppointListFragment newInstance() {
|
|
|
VideoCourseAppointListFragment fragment = new VideoCourseAppointListFragment();
|
|
|
return fragment;
|
|
@@ -37,7 +67,50 @@ public class VideoCourseAppointListFragment extends BaseMVPFragment<FgVideoCours
|
|
|
|
|
|
@Override
|
|
|
protected void initData() {
|
|
|
+ currentSubjectId = UserHelper.getSubjectId();
|
|
|
+ String subjectName = UserHelper.getSubjectName();
|
|
|
+ mViewBinding.tvFilter.setText(subjectName);
|
|
|
|
|
|
+ mAdapter = new VideoCourseAppointAdapter();
|
|
|
+ EmptyViewLayout emptyViewLayout = new EmptyViewLayout(getContext());
|
|
|
+ emptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_course, "暂无课程");
|
|
|
+ mAdapter.setEmptyView(emptyViewLayout);
|
|
|
+ mViewBinding.recyclerViewList.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
+ mViewBinding.recyclerViewList.setAdapter(mAdapter);
|
|
|
+ initListener();
|
|
|
+ getData(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getData(boolean isShowLoading) {
|
|
|
+ if (currentPage == 1) {
|
|
|
+ mViewBinding.refreshLayout.resetNoMoreData();
|
|
|
+ }
|
|
|
+ presenter.queryVideoCourse(isShowLoading,currentSubjectId,searchCondition,currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -47,7 +120,125 @@ public class VideoCourseAppointListFragment extends BaseMVPFragment<FgVideoCours
|
|
|
|
|
|
public void querySubjectItemSuccess(List<QuerySubjectBean> data) {
|
|
|
subjectBeanList.clear();
|
|
|
- subjectBeanList.add(new QuerySubjectBean("全部声部", 0));
|
|
|
subjectBeanList.addAll(data);
|
|
|
+ String subjectId = UserHelper.getSubjectId();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ QuerySubjectBean querySubjectBean = data.get(i);
|
|
|
+ if (TextUtils.equals(subjectId, querySubjectBean.getId())) {
|
|
|
+ currentSelectSubjectPosition = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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 selectSubjectType() {
|
|
|
+ if (subjectBeanList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (pvOptions == null) {
|
|
|
+ pvOptions = new OptionsPickerBuilder(getContext(), (options1, options2, options3, v) -> {
|
|
|
+ this.currentSelectSubjectPosition = options1;
|
|
|
+ QuerySubjectBean 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetVideoCourseSuccess(int page, VideoCourseListBean dataList) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LOG.i("pq", "onGetVideoCourseSuccess:" + 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();
|
|
|
+ checkHasNext(dataList.getRows().size());
|
|
|
+ mAdapter.addData(dataList.getRows());
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constants.DEFAULT_DATA_SIZE;
|
|
|
+ mViewBinding.refreshLayout.setNoMoreData(!hasNext);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetCourseError(int page) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ if (mAdapter != null) {
|
|
|
+ currentPage--;
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|