|
@@ -0,0 +1,303 @@
|
|
|
+package com.cooleshow.teacher.ui.course;
|
|
|
+
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemChildClickListener;
|
|
|
+import com.cooleshow.base.common.WebConstants;
|
|
|
+import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.constanst.CourseGroupStatusType;
|
|
|
+import com.cooleshow.base.interfaces.IFilterViewData;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.LOG;
|
|
|
+import com.cooleshow.base.utils.PopupUtil;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.base.utils.UiUtils;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIDeviceHelper;
|
|
|
+import com.cooleshow.base.widgets.CourseGroupFilterView;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.base.widgets.GridItemDecoration;
|
|
|
+import com.cooleshow.chatmodule.utils.helper.ChatHelper;
|
|
|
+import com.cooleshow.teacher.R;
|
|
|
+import com.cooleshow.teacher.adapter.LiveCourseListAdapter;
|
|
|
+import com.cooleshow.teacher.adapter.MineGroupCourseListAdapter;
|
|
|
+import com.cooleshow.teacher.bean.LiveCourseListBean;
|
|
|
+import com.cooleshow.teacher.bean.QuerySubjectBean;
|
|
|
+import com.cooleshow.teacher.constants.CourseConstants;
|
|
|
+import com.cooleshow.teacher.contract.GroupCourseContract;
|
|
|
+import com.cooleshow.teacher.contract.LiveCourseContract;
|
|
|
+import com.cooleshow.teacher.databinding.FragmentLiveCourseLayoutBinding;
|
|
|
+import com.cooleshow.teacher.presenter.course.GroupCoursePresenter;
|
|
|
+import com.cooleshow.teacher.presenter.course.LiveCoursePresenter;
|
|
|
+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.Arrays;
|
|
|
+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 2022/4/25.
|
|
|
+ */
|
|
|
+public class GroupCourseGroupFragment extends BaseMVPFragment<FragmentLiveCourseLayoutBinding, GroupCoursePresenter> implements GroupCourseContract.CourseView, View.OnClickListener {
|
|
|
+ private String currentCourseFilterStatus = CourseConstants.COURSE_FILTER_ALL;
|
|
|
+ private String currentSubjectId;
|
|
|
+ private String searchCondition;
|
|
|
+ private int currentPage;
|
|
|
+ private MineGroupCourseListAdapter mAdapter;
|
|
|
+ private EmptyViewLayout mEmptyView;
|
|
|
+ private ArrayList<IFilterViewData> mCourseFilterStatusBeans;
|
|
|
+ private List<IFilterViewData> subjectBeanList = new ArrayList<>();
|
|
|
+ private boolean hasNext = true;
|
|
|
+ private CourseGroupFilterView mCourseGroupFilterView;
|
|
|
+ private PopupWindow mPopupWindow;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FragmentLiveCourseLayoutBinding getLayoutView() {
|
|
|
+ return FragmentLiveCourseLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected GroupCoursePresenter createPresenter() {
|
|
|
+ return new GroupCoursePresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+ mViewBinding.refreshLayout.setRefreshFooter(new ClassicsFooter(getContext()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildDefaultCourseStatusFilterList() {
|
|
|
+ CourseGroupStatusType[] values = CourseGroupStatusType.values();
|
|
|
+ List<CourseGroupStatusType> courseGroupStatusTypes = Arrays.asList(values);
|
|
|
+ mCourseFilterStatusBeans = new ArrayList<IFilterViewData>(courseGroupStatusTypes);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void reBuildFilter(String status, String subjectId) {
|
|
|
+ if (!TextUtils.isEmpty(currentCourseFilterStatus) &&
|
|
|
+ !TextUtils.isEmpty(currentSubjectId) &&
|
|
|
+ TextUtils.equals(currentCourseFilterStatus, status) &&
|
|
|
+ TextUtils.equals(currentSubjectId, subjectId)) {
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ currentCourseFilterStatus = !TextUtils.isEmpty(status) ? status : CourseConstants.COURSE_FILTER_ALL;
|
|
|
+ GroupCourseGroupFragment.this.currentSubjectId = subjectId;
|
|
|
+ currentPage = 1;
|
|
|
+ getData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+ mAdapter = new MineGroupCourseListAdapter();
|
|
|
+ initListener();
|
|
|
+ if (mEmptyView == null) {
|
|
|
+ mEmptyView = new EmptyViewLayout(getContext());
|
|
|
+ }
|
|
|
+ mEmptyView.setContent(com.cooleshow.base.R.drawable.icon_empty_course, "暂无课程~");
|
|
|
+ mAdapter.setEmptyView(mEmptyView);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ buildDefaultCourseStatusFilterList();
|
|
|
+ reBuildFilter(CourseConstants.COURSE_FILTER_ALL, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mViewBinding.tvFilter.setOnClickListener(this);
|
|
|
+ mViewBinding.tvSearch.setOnClickListener(this);
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ currentPage = 1;
|
|
|
+ getData(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ 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((adapter, view, position) -> {
|
|
|
+ LiveCourseListBean.RowsBean item = (LiveCourseListBean.RowsBean) adapter.getItem(position);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ mAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ int id = view.getId();
|
|
|
+ if (id == R.id.iv_chat) {
|
|
|
+ LiveCourseListBean.RowsBean item = (LiveCourseListBean.RowsBean) adapter.getItem(position);
|
|
|
+ if (item != null) {
|
|
|
+ ChatHelper.getInstance().goGroupChat(item.imGroupId, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getData(boolean isShowLoading) {
|
|
|
+
|
|
|
+ if (currentPage == 1) {
|
|
|
+ mViewBinding.refreshLayout.resetNoMoreData();
|
|
|
+ }
|
|
|
+ presenter.queryGroupCourse(isShowLoading, currentCourseFilterStatus, currentSubjectId, searchCondition, currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constants.DEFAULT_DATA_SIZE;
|
|
|
+ mViewBinding.refreshLayout.setNoMoreData(!hasNext);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetGroupCourseSuccess(int page, LiveCourseListBean 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();
|
|
|
+ checkHasNext(dataList.getRows().size());
|
|
|
+ mAdapter.addData(dataList.getRows());
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGetCourseError(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) {
|
|
|
+
|
|
|
+ showFilterView();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_search) {
|
|
|
+ currentPage = 1;
|
|
|
+ searchCondition = mViewBinding.etTargetName.getText().toString().trim();
|
|
|
+ getData(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showFilterView() {
|
|
|
+ if (mCourseGroupFilterView == null) {
|
|
|
+ mCourseGroupFilterView = new CourseGroupFilterView(getContext());
|
|
|
+ mCourseGroupFilterView.setOnEventListener(new CourseGroupFilterView.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ if (mPopupWindow != null) {
|
|
|
+ mPopupWindow.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onQuery(String obj, String obj2) {
|
|
|
+ if (mPopupWindow != null) {
|
|
|
+ mPopupWindow.dismiss();
|
|
|
+ }
|
|
|
+ currentPage = 1;
|
|
|
+ reBuildFilter(obj, obj2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ mCourseGroupFilterView.setData(mCourseFilterStatusBeans, subjectBeanList);
|
|
|
+ ViewGroup parent = (ViewGroup) mCourseGroupFilterView.getParent();
|
|
|
+ if (parent != null) {
|
|
|
+ parent.removeView(mCourseGroupFilterView);
|
|
|
+ }
|
|
|
+ mPopupWindow = PopupUtil.showInDropWrapNObg(getContext(), mCourseGroupFilterView, mViewBinding.viewTopLine, new PopupUtil.ShowListener() {
|
|
|
+ @Override
|
|
|
+ public void onShow(View view, PopupWindow popupWindow) {
|
|
|
+ UiUtils.refreshFilterTextStyle(true, mViewBinding.tvFilter);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ UiUtils.refreshFilterTextStyle(false, mViewBinding.tvFilter);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void querySubjectItemSuccess(List<QuerySubjectBean> data) {
|
|
|
+ subjectBeanList.clear();
|
|
|
+ subjectBeanList.add(new QuerySubjectBean("全部", ""));
|
|
|
+ subjectBeanList.addAll(data);
|
|
|
+ }
|
|
|
+}
|