|
@@ -0,0 +1,255 @@
|
|
|
+package com.cooleshow.musicmerge.ui.work;
|
|
|
+
|
|
|
+import android.view.View;
|
|
|
+import android.widget.CompoundButton;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.listener.OnItemClickListener;
|
|
|
+import com.cooleshow.base.constanst.Constants;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
+import com.cooleshow.base.utils.Utils;
|
|
|
+import com.cooleshow.base.widgets.EmptyViewLayout;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonConfirmDialog;
|
|
|
+import com.cooleshow.base.widgets.dialog.CommonConfirmDialog2;
|
|
|
+import com.cooleshow.musicmerge.adapter.MyDraftWorkListAdapter;
|
|
|
+import com.cooleshow.musicmerge.bean.MyWorkListBean;
|
|
|
+import com.cooleshow.musicmerge.contract.MyWorkContract;
|
|
|
+import com.cooleshow.musicmerge.databinding.FgMyWorkDraftLayoutBinding;
|
|
|
+import com.cooleshow.musicmerge.presenter.work.MyWorkPresenter;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2023/10/30.
|
|
|
+ */
|
|
|
+public class MyWorkDraftFragment extends BaseMVPFragment<FgMyWorkDraftLayoutBinding, MyWorkPresenter> implements MyWorkContract.View {
|
|
|
+ public static final int REQUEST_CODE = 10001;
|
|
|
+ private int currentPage = 1;
|
|
|
+ private boolean hasNext = true;
|
|
|
+ private MyDraftWorkListAdapter mListAdapter;
|
|
|
+
|
|
|
+ private boolean isEditMode = false;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FgMyWorkDraftLayoutBinding getLayoutView() {
|
|
|
+ return FgMyWorkDraftLayoutBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected MyWorkPresenter createPresenter() {
|
|
|
+ return new MyWorkPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView(View rootView) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initData() {
|
|
|
+ mListAdapter = new MyDraftWorkListAdapter();
|
|
|
+ EmptyViewLayout emptyViewLayout = new EmptyViewLayout(getContext());
|
|
|
+ emptyViewLayout.setContent(com.cooleshow.base.R.drawable.icon_empty_content, "暂无内容");
|
|
|
+ mListAdapter.setEmptyView(emptyViewLayout);
|
|
|
+ mViewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
|
+ mViewBinding.recyclerView.setAdapter(mListAdapter);
|
|
|
+ initListener();
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void refreshData() {
|
|
|
+ refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void refresh() {
|
|
|
+ currentPage = 1;
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void handleSelectMode(boolean isEditMode) {
|
|
|
+ if (isAdded()) {
|
|
|
+ this.isEditMode = isEditMode;
|
|
|
+ mViewBinding.csBottom.setVisibility(isEditMode ? View.VISIBLE : View.GONE);
|
|
|
+ mListAdapter.setEditMode(isEditMode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isEditMode() {
|
|
|
+ return isEditMode;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initListener() {
|
|
|
+ mListAdapter.setOnItemClickListener(new OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
|
|
|
+ if (position < mListAdapter.getData().size()) {
|
|
|
+ MyWorkListBean.RowsBean rowsBean = mListAdapter.getData().get(position);
|
|
|
+ if (isEditMode) {
|
|
|
+ mListAdapter.setSelectId(rowsBean.getId());
|
|
|
+ updateSelectNum();
|
|
|
+ } else {
|
|
|
+ ARouter.getInstance().build(RouterPath.MusicTuner.MUSIC_MERGE_PAGE)
|
|
|
+ .withString("recordId", rowsBean.getMusicPracticeRecordId())
|
|
|
+ .withString("worksId", rowsBean.getId())
|
|
|
+ .withString("coverImg", rowsBean.getImg())
|
|
|
+ .withString("title", rowsBean.getMusicSheetName())
|
|
|
+ .navigation(getActivity(), REQUEST_CODE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ currentPage = 1;
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mViewBinding.refreshLayout.setOnLoadMoreListener(new com.scwang.smart.refresh.layout.listener.OnLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ //上拉加载
|
|
|
+ if (hasNext) {
|
|
|
+ currentPage++;
|
|
|
+ getData();
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mViewBinding.selectCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
+ if (buttonView.isPressed()) {
|
|
|
+ if (isChecked) {
|
|
|
+ mListAdapter.checkAll();
|
|
|
+ } else {
|
|
|
+ mListAdapter.clearAllCheck();
|
|
|
+ }
|
|
|
+ updateSelectNum();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mViewBinding.tvDel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ ArrayList<String> selectIds = mListAdapter.getSelectIds();
|
|
|
+ if (selectIds == null || selectIds.isEmpty()) {
|
|
|
+ ToastUtil.getInstance().showShort("请选择需要删除的草稿");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ showConfirmDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateSelectNum() {
|
|
|
+ ArrayList<String> selectIds = mListAdapter.getSelectIds();
|
|
|
+ if (selectIds != null) {
|
|
|
+ int num = selectIds.size();
|
|
|
+ mViewBinding.selectCheckbox.setText("全选(已选择" + num + ")");
|
|
|
+ int size = mListAdapter.getData().size();
|
|
|
+ mViewBinding.selectCheckbox.setChecked(num == size);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleDel() {
|
|
|
+ ArrayList<String> selectIds = mListAdapter.getSelectIds();
|
|
|
+ String ids = Utils.getIds(selectIds);
|
|
|
+ presenter.delWorks(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showConfirmDialog() {
|
|
|
+ CommonConfirmDialog2 commonConfirmDialog = new CommonConfirmDialog2(getContext());
|
|
|
+ commonConfirmDialog.show();
|
|
|
+ commonConfirmDialog.setTitle("提示");
|
|
|
+ commonConfirmDialog.setContent("确认删除吗?");
|
|
|
+ commonConfirmDialog.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
+ handleDel();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ commonConfirmDialog.setOnCancelClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ commonConfirmDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getData() {
|
|
|
+ if (presenter != null) {
|
|
|
+ presenter.getMyDraftWorks(currentPage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getMyPublishWorkSuccess(int page, MyWorkListBean data) {
|
|
|
+ if (data != null) {
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ 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) {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore();
|
|
|
+ mListAdapter.addData(data.getRows());
|
|
|
+ checkHasNext(data.getRows().size());
|
|
|
+ } else {
|
|
|
+ mViewBinding.refreshLayout.finishLoadMoreWithNoMoreData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getMyPublishWorkError(int page) {
|
|
|
+ if (page == 1) {
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ } else {
|
|
|
+ if (mListAdapter != null) {
|
|
|
+ currentPage--;
|
|
|
+ mViewBinding.refreshLayout.finishLoadMore(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delSuccess() {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mListAdapter.clearAllCheck();
|
|
|
+ ToastUtil.getInstance().showShort("删除成功");
|
|
|
+ updateSelectNum();
|
|
|
+ refreshData();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否还有下一页
|
|
|
+ *
|
|
|
+ * @param dataSize
|
|
|
+ */
|
|
|
+ private void checkHasNext(int dataSize) {
|
|
|
+ hasNext = dataSize >= Constants.DEFAULT_DATA_SIZE;
|
|
|
+ mViewBinding.refreshLayout.setNoMoreData(!hasNext);
|
|
|
+ }
|
|
|
+}
|