|
@@ -1,16 +1,47 @@
|
|
|
package com.cooleshow.teacher.ui.comment;
|
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.bigkoo.pickerview.builder.TimePickerBuilder;
|
|
|
+import com.bigkoo.pickerview.listener.CustomListener;
|
|
|
+import com.bigkoo.pickerview.view.TimePickerView;
|
|
|
+import com.chad.library.adapter.base.listener.OnLoadMoreListener;
|
|
|
+import com.cooleshow.base.constanst.Constanst;
|
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.TimeUtils;
|
|
|
+import com.cooleshow.teacher.R;
|
|
|
+import com.cooleshow.teacher.adapter.CourseCommentNotReplyAdapter;
|
|
|
+import com.cooleshow.teacher.bean.CourseCommentListBean;
|
|
|
import com.cooleshow.teacher.contract.CourseCommentContract;
|
|
|
import com.cooleshow.teacher.databinding.FragmentCourseCommentNoReplyLayoutBinding;
|
|
|
import com.cooleshow.teacher.presenter.comment.CourseCommentPresenter;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2022/5/5.
|
|
|
+ * 陪练课评价-未评价学生
|
|
|
*/
|
|
|
-public class CourseCommentNoReplyFragment extends BaseMVPFragment<FragmentCourseCommentNoReplyLayoutBinding, CourseCommentPresenter> implements CourseCommentContract.CourseCommentView {
|
|
|
+public class CourseCommentNoReplyFragment extends BaseMVPFragment<FragmentCourseCommentNoReplyLayoutBinding, CourseCommentPresenter> implements CourseCommentContract.CourseCommentView, View.OnClickListener {
|
|
|
+ public int courseCommentNotReply = 0;//未回复
|
|
|
+ private TimePickerView pvTime;
|
|
|
+ private Date currentSelectDate;
|
|
|
+ private String currentFilterDate;
|
|
|
+ private String currentStudentName;
|
|
|
+ private int currentPage = 1;
|
|
|
+ private View mEmptyView;
|
|
|
+ private TextView mTvEmptyTip;
|
|
|
+ private boolean hasNext = true;
|
|
|
+ private CourseCommentNotReplyAdapter mAdapter;
|
|
|
+
|
|
|
@Override
|
|
|
protected FragmentCourseCommentNoReplyLayoutBinding getLayoutView() {
|
|
|
return FragmentCourseCommentNoReplyLayoutBinding.inflate(getLayoutInflater());
|
|
@@ -28,6 +59,187 @@ public class CourseCommentNoReplyFragment extends BaseMVPFragment<FragmentCourse
|
|
|
|
|
|
@Override
|
|
|
protected void initData() {
|
|
|
+ currentSelectDate = TimeUtils.getNowDate();
|
|
|
+ mAdapter = new CourseCommentNotReplyAdapter(R.layout.item_course_comment_list_layout);
|
|
|
+ mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
+ mViewBinding.recyclerView.setAdapter(mAdapter);
|
|
|
+ initListener();
|
|
|
+ reBuildFilter(currentSelectDate, currentStudentName);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mViewBinding.tvDate.setOnClickListener(this);
|
|
|
+ mViewBinding.tvSearch.setOnClickListener(this);
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ currentPage = 1;
|
|
|
+ queryComment(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mAdapter.getLoadMoreModule().setOnLoadMoreListener(new OnLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore() {
|
|
|
+ //上拉加载
|
|
|
+ if (hasNext) {
|
|
|
+ currentPage++;
|
|
|
+ queryComment(false);
|
|
|
+ } else {
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 构造筛选条件
|
|
|
+ *
|
|
|
+ * @param date
|
|
|
+ * @param targetStr
|
|
|
+ */
|
|
|
+ private void reBuildFilter(Date date, String targetStr) {
|
|
|
+ currentSelectDate = date != null ? date : TimeUtils.getNowDate();
|
|
|
+ String targetDateTimeStr = TimeUtils.date2String(currentSelectDate, TimeUtils.getSafeDateFormat("yyyy-MM"));
|
|
|
+ if (TextUtils.equals(targetDateTimeStr, currentFilterDate) && TextUtils.equals(targetStr, currentStudentName)) {
|
|
|
+ //防止重复条件触发
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ currentStudentName = targetStr;
|
|
|
+ currentFilterDate = targetDateTimeStr;
|
|
|
+ currentPage = 1;
|
|
|
+ mViewBinding.tvDate.setText(currentFilterDate);
|
|
|
+ queryComment(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryComment(boolean isShowLoading) {
|
|
|
+ presenter.queryCourseCommentList(isShowLoading, courseCommentNotReply, currentFilterDate, currentStudentName, currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示时间选择器
|
|
|
+ */
|
|
|
+ private void showTimeSelectPicker() {
|
|
|
+ if (pvTime == null) {
|
|
|
+ pvTime = new TimePickerBuilder(requireContext(), (date, v) -> {//选中事件回调
|
|
|
+ reBuildFilter(date, currentStudentName);
|
|
|
+ }).setLayoutRes(com.cooleshow.base.R.layout.pickerview_default_layout, new CustomListener() {
|
|
|
+ @Override
|
|
|
+ public void customLayout(View 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(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ pvTime.returnData();
|
|
|
+ pvTime.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ivCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ pvTime.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setLineSpacingMultiplier(2.5f)
|
|
|
+ .setType(new boolean[]{true, true, false, false, false, false})// 默认全部显示
|
|
|
+ .setTextColorCenter(getResources().getColor(com.cooleshow.base.R.color.color_1a1a1a))//设置选中项的颜色
|
|
|
+ .isDialog(false)//是否显示为对话框样式
|
|
|
+ .setLabel("年", "月", "", "", "", "")
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(currentSelectDate);
|
|
|
+ pvTime.setDate(calendar);
|
|
|
+ if (!pvTime.isShowing()) {
|
|
|
+ pvTime.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.tv_date) {
|
|
|
+ //显示时间选择器
|
|
|
+ showTimeSelectPicker();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (v.getId() == R.id.tv_search) {
|
|
|
+ //搜索
|
|
|
+ String targetName = mViewBinding.etTargetName.getText().toString();
|
|
|
+ reBuildFilter(currentSelectDate, targetName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void queryCourseCommentSuccess(int page, CourseCommentListBean commentListBean) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (commentListBean != null) {
|
|
|
+ if (page == 1) {
|
|
|
+ //第一页
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ if (mAdapter != null) {
|
|
|
+ mAdapter.getData().clear();
|
|
|
+ mAdapter.notifyDataSetChanged();
|
|
|
+ if (commentListBean.rows != null && commentListBean.rows.size() > 0) {
|
|
|
+ checkHasNext(commentListBean.rows.size());
|
|
|
+ mAdapter.setNewInstance(commentListBean.rows);
|
|
|
+ } else {
|
|
|
+ showEmptyView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ if (mAdapter != null) {
|
|
|
+ if (commentListBean.rows != null && commentListBean.rows.size() > 0) {
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreComplete();
|
|
|
+ checkHasNext(commentListBean.rows.size());
|
|
|
+ mAdapter.addData(commentListBean.rows);
|
|
|
+ } else {
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否还有下一页
|
|
|
+ *
|
|
|
+ * @param dataSize
|
|
|
+ */
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constanst.DEFAULT_DATA_SIZE;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void queryCourseCommentError(int page) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ if (mAdapter != null) {
|
|
|
+ currentPage--;
|
|
|
+ mAdapter.getLoadMoreModule().loadMoreFail();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|