|
@@ -1,17 +1,112 @@
|
|
|
package com.cooleshow.teacher.ui.mine;
|
|
|
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemClickListener;
|
|
|
+import com.chad.library.adapter.base.listener.OnLoadMoreListener;
|
|
|
+import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.teacher.R;
|
|
|
+import com.cooleshow.teacher.adapter.CoursewareListAdapter;
|
|
|
+import com.cooleshow.teacher.contract.CoursewareContract;
|
|
|
import com.cooleshow.teacher.databinding.ActivityCoursewareListLayoutBinding;
|
|
|
import com.cooleshow.teacher.presenter.mine.CoursewareListPresenter;
|
|
|
+import com.daya.live_teaching.model.CoursewareListBean;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2022/11/18.
|
|
|
*/
|
|
|
-public class CoursewareListActivity extends BaseMVPActivity<ActivityCoursewareListLayoutBinding, CoursewareListPresenter> {
|
|
|
+@Route(path = RouterPath.MineCenter.MINE_COURSE_WARE)
|
|
|
+public class CoursewareListActivity extends BaseMVPActivity<ActivityCoursewareListLayoutBinding, CoursewareListPresenter> implements View.OnClickListener, CoursewareContract.CoursewareView {
|
|
|
+
|
|
|
+ private CoursewareListAdapter mListAdapter;
|
|
|
+ private String searchStr = "";
|
|
|
+ private int currentPage = 1;
|
|
|
+ private boolean hasNext = true;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
|
+ initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "我的课件");
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setVisibility(View.VISIBLE);
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setText("编辑");
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setOnClickListener(this);
|
|
|
+ viewBinding.tvDelete.setOnClickListener(this);
|
|
|
+ viewBinding.tvSearch.setOnClickListener(this);
|
|
|
+ viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
+ mListAdapter = new CoursewareListAdapter();
|
|
|
+ EmptyViewLayout emptyViewLayout = new EmptyViewLayout(this);
|
|
|
+ emptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_content, "暂无内容~");
|
|
|
+ mListAdapter.setEmptyView(emptyViewLayout);
|
|
|
+ viewBinding.recyclerView.setAdapter(mListAdapter);
|
|
|
+ initListener();
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ viewBinding.refreshLayout.setOnRefreshListener(refreshLayout -> {
|
|
|
+ refresh();
|
|
|
+ });
|
|
|
+
|
|
|
+ mListAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ boolean selectMode = mListAdapter.isSelectMode();
|
|
|
+ if (!selectMode) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mListAdapter.setSelectPos(position);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mListAdapter.getLoadMoreModule().setOnLoadMoreListener(new OnLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore() {
|
|
|
+ //上拉加载
|
|
|
+ if (hasNext) {
|
|
|
+ loadMore();
|
|
|
+ } else {
|
|
|
+ mListAdapter.getLoadMoreModule().loadMoreEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void query(boolean isShowLoading) {
|
|
|
+ presenter.getCoursewareList(isShowLoading, searchStr, currentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void refresh() {
|
|
|
+ currentPage = 1;
|
|
|
+ query(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载更多
|
|
|
+ */
|
|
|
+ private void loadMore() {
|
|
|
+ currentPage++;
|
|
|
+ query(false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -23,4 +118,123 @@ public class CoursewareListActivity extends BaseMVPActivity<ActivityCoursewareLi
|
|
|
protected CoursewareListPresenter createPresenter() {
|
|
|
return new CoursewareListPresenter();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ int id = v.getId();
|
|
|
+ if (id == com.cooleshow.base.R.id.tv_right_text) {
|
|
|
+ if (mListAdapter.isSelectMode()) {
|
|
|
+ //全选
|
|
|
+ mListAdapter.selectAll();
|
|
|
+ } else {
|
|
|
+ //编辑->全选
|
|
|
+ if (mListAdapter.getData().size() > 0) {
|
|
|
+ mListAdapter.setSelectMode(true);
|
|
|
+ updateSelectAllUI();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_delete) {
|
|
|
+ //删除
|
|
|
+ String selectDataIds = mListAdapter.getSelectDataIds();
|
|
|
+ if (!TextUtils.isEmpty(selectDataIds)) {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.delCourseware(selectDataIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mListAdapter.setSelectMode(false);
|
|
|
+ updateSelectAllUI();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == R.id.tv_search) {
|
|
|
+ //搜索
|
|
|
+ searchStr = viewBinding.etSearchContent.getText().toString().trim();
|
|
|
+ refresh();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateSelectAllUI() {
|
|
|
+ if (mListAdapter.isSelectMode()) {
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setText("全选");
|
|
|
+ viewBinding.tvDelete.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ viewBinding.toolbarInclude.tvRightText.setText("编辑");
|
|
|
+ viewBinding.tvDelete.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getCoursewareListSuccess(int page, CoursewareListBean data) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (data != null) {
|
|
|
+ viewBinding.refreshLayout.finishRefresh();
|
|
|
+ if (page == 1) {
|
|
|
+ mListAdapter.getData().clear();
|
|
|
+ mListAdapter.notifyDataSetChanged();
|
|
|
+ if (data.getRows() != null && data.getRows().size() > 0) {
|
|
|
+ checkHasNext(data.getRows().size());
|
|
|
+ mListAdapter.setNewInstance(data.getRows());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (data.getRows() != null && data.getRows().size() > 0) {
|
|
|
+ mListAdapter.getLoadMoreModule().loadMoreComplete();
|
|
|
+ mListAdapter.addData(data.getRows());
|
|
|
+ checkHasNext(data.getRows().size());
|
|
|
+ } else {
|
|
|
+ mListAdapter.getLoadMoreModule().loadMoreEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getCoursewareListError(int page) {
|
|
|
+ if (mListAdapter == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (page == 1) {
|
|
|
+ viewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ currentPage--;
|
|
|
+ mListAdapter.getLoadMoreModule().loadMoreFail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delCoursewareSuccess(String delDataIds) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mListAdapter != null) {
|
|
|
+ String[] ids = delDataIds.split(",");
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
+ String id = ids[i];
|
|
|
+ for (int j = 0; j < mListAdapter.getData().size(); j++) {
|
|
|
+ CoursewareListBean.RowsBean rowsBean = mListAdapter.getData().get(j);
|
|
|
+ if (TextUtils.equals(id, String.valueOf(rowsBean.id))) {
|
|
|
+ mListAdapter.getData().remove(rowsBean);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否还有下一页
|
|
|
+ *
|
|
|
+ * @param dataSize
|
|
|
+ */
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constants.DEFAULT_DATA_SIZE;
|
|
|
+ }
|
|
|
}
|