|
@@ -1,21 +1,36 @@
|
|
|
package com.cooleshow.teacher.ui.course;
|
|
|
|
|
|
import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.chad.library.adapter.base.listener.OnLoadMoreListener;
|
|
|
-import com.cooleshow.base.presenter.BasePresenter;
|
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+import com.cooleshow.base.utils.TimeUtils;
|
|
|
import com.cooleshow.teacher.R;
|
|
|
import com.cooleshow.teacher.adapter.SparringCourseListAdapter;
|
|
|
+import com.cooleshow.teacher.bean.SparringCourseListBean;
|
|
|
+import com.cooleshow.teacher.constants.CourseFilterConstants;
|
|
|
+import com.cooleshow.teacher.contract.SparringCourseContract;
|
|
|
import com.cooleshow.teacher.databinding.FragmentSparringCourseLayoutBinding;
|
|
|
import com.cooleshow.teacher.presenter.course.SparringCoursePresenter;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
|
|
|
-import androidx.viewbinding.ViewBinding;
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2022/4/25.
|
|
|
*/
|
|
|
-public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCourseLayoutBinding, SparringCoursePresenter> {
|
|
|
+public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCourseLayoutBinding, SparringCoursePresenter> implements SparringCourseContract.SparringCourseView {
|
|
|
+ private String currentCourseFilterStatus = CourseFilterConstants.COURSE_FILTER_ALL;
|
|
|
+ private String currentFilterDate;
|
|
|
+ private int currentSubjectId;
|
|
|
+ private int currentPage;
|
|
|
+ private SparringCourseListAdapter mAdapter;
|
|
|
+ private View mEmptyView;
|
|
|
+ private TextView mTvEmptyTip;
|
|
|
|
|
|
@Override
|
|
|
protected FragmentSparringCourseLayoutBinding getLayoutView() {
|
|
@@ -27,20 +42,105 @@ public class SparringCourseFragment extends BaseMVPFragment<FragmentSparringCour
|
|
|
return new SparringCoursePresenter();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void initView(View rootView) {
|
|
|
+ buildDefaultFilter();
|
|
|
+ mViewBinding.tvTime.setText(currentFilterDate);
|
|
|
+ }
|
|
|
|
|
|
+ private void buildDefaultFilter() {
|
|
|
+ currentFilterDate = TimeUtils.getNowString(TimeUtils.getSafeDateFormat("yyyy-MM"));
|
|
|
+ currentCourseFilterStatus = CourseFilterConstants.COURSE_FILTER_ALL;
|
|
|
+ currentPage = 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
protected void initData() {
|
|
|
- SparringCourseListAdapter sparringCourseListAdapter = new SparringCourseListAdapter(R.layout.item_sparring_course_list_layout);
|
|
|
- sparringCourseListAdapter.getLoadMoreModule().setOnLoadMoreListener(new OnLoadMoreListener() {
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ currentPage = 1;
|
|
|
+ queryCourse();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mAdapter = new SparringCourseListAdapter(R.layout.item_sparring_course_list_layout);
|
|
|
+ mAdapter.getLoadMoreModule().setOnLoadMoreListener(new OnLoadMoreListener() {
|
|
|
@Override
|
|
|
public void onLoadMore() {
|
|
|
//上拉加载
|
|
|
+ currentPage++;
|
|
|
+ queryCourse();
|
|
|
}
|
|
|
});
|
|
|
+ mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
|
|
+ mViewBinding.recyclerView.setAdapter(mAdapter);
|
|
|
+ queryCourse();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryCourse() {
|
|
|
+ //根据默认筛选条件查询
|
|
|
+ LogUtils.i("pq", "currentFilterDate:" + currentFilterDate);
|
|
|
+ LogUtils.i("pq", "currentCourseFilterStatus:" + currentCourseFilterStatus);
|
|
|
+ LogUtils.i("pq", "currentSubjectId:" + currentSubjectId);
|
|
|
+ LogUtils.i("pq", "currentPage:" + currentPage);
|
|
|
+ presenter.querySparringCourse(currentFilterDate, currentCourseFilterStatus, currentSubjectId, currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetSparringCourseSuccess(int page, SparringCourseListBean sparringCourseBean) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sparringCourseBean != null) {
|
|
|
+ if (page == 1) {
|
|
|
+ //第一页
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ if (mAdapter != null) {
|
|
|
+ if (sparringCourseBean.rows != null && sparringCourseBean.rows.size() > 0) {
|
|
|
+ mAdapter.getData().clear();
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+ mAdapter.setNewInstance(sparringCourseBean.rows);
|
|
|
+ } else {
|
|
|
+ showEmptyView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ if (mAdapter != null) {
|
|
|
+ if (sparringCourseBean.rows != null && sparringCourseBean.rows.size() > 0) {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore();
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreComplete();
|
|
|
+ mAdapter.addData(sparringCourseBean.rows);
|
|
|
+ } else {
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreEnd(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetCourseError(int page) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ if (mAdapter != null) {
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreFail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showEmptyView() {
|
|
|
+ if (mEmptyView == null) {
|
|
|
+ mEmptyView = getLayoutInflater().inflate(com.cooleshow.base.R.layout.empty_layout, mAdapter.getEmptyLayout(), false);
|
|
|
+ mTvEmptyTip = mEmptyView.findViewById(com.cooleshow.base.R.id.tv_empty_tip);
|
|
|
+ }
|
|
|
+ mTvEmptyTip.setText("暂无数据");
|
|
|
+ mAdapter.setEmptyView(mEmptyView);
|
|
|
}
|
|
|
}
|