|
@@ -27,6 +27,7 @@ import com.cooleshow.student.bean.PracticeVideoWorkBean;
|
|
|
import com.cooleshow.student.constants.CourseConstants;
|
|
|
import com.cooleshow.student.ui.work.HomeWorkDetailActivity;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
|
|
@@ -47,6 +48,7 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
private RecyclerView mRecyclerView;
|
|
|
private LinearLayout mLlUploadEmptyView;
|
|
|
private PracticeVideoWorkAdapter mVideoWorkAdapter;
|
|
|
+ private boolean isChangeHomeWork = false;
|
|
|
|
|
|
public UploadHomeworkVideoDialog(@NonNull Context context) {
|
|
|
super(context, R.style.MyBottomDialogStyle);
|
|
@@ -56,6 +58,8 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.dialog_upload_homework_video_layout);
|
|
|
+ setCancelable(false);
|
|
|
+ setCanceledOnTouchOutside(false);
|
|
|
initParams();
|
|
|
initViews();
|
|
|
initData();
|
|
@@ -89,8 +93,8 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
PracticeVideoWorkBean practiceVideoWorkBean = mVideoWorkAdapter.getData().get(position);
|
|
|
if (id == R.id.iv_del) {
|
|
|
if (mEventListener != null) {
|
|
|
+ isChangeHomeWork= true;
|
|
|
mVideoWorkAdapter.getData().remove(position);
|
|
|
- mEventListener.onDel(position);
|
|
|
checkVideoList();
|
|
|
mVideoWorkAdapter.notifyDataSetChanged();
|
|
|
}
|
|
@@ -101,6 +105,7 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
if (UiUtils.isFastClick()) {
|
|
|
return;
|
|
|
}
|
|
|
+ isChangeHomeWork =true;
|
|
|
if (mEventListener != null) {
|
|
|
mEventListener.goUpload();
|
|
|
}
|
|
@@ -119,29 +124,44 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
}
|
|
|
|
|
|
public void setData(List<PracticeVideoWorkBean> data) {
|
|
|
- if (data != null && data.size() > 0) {
|
|
|
- mLlUploadEmptyView.setVisibility(View.GONE);
|
|
|
- mRecyclerView.setVisibility(View.VISIBLE);
|
|
|
- if (mVideoWorkAdapter != null) {
|
|
|
- mVideoWorkAdapter.setList(data);
|
|
|
+ if (mVideoWorkAdapter != null) {
|
|
|
+ mVideoWorkAdapter.getData().clear();
|
|
|
+ if (data.size() > CourseConstants.COURSE_HOMEWORK_MAX_VIDEO_COUNT) {
|
|
|
+ data = data.subList(0, CourseConstants.COURSE_HOMEWORK_MAX_VIDEO_COUNT);
|
|
|
}
|
|
|
+ mVideoWorkAdapter.addData(data);
|
|
|
checkVideoList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void addItem(PracticeVideoWorkBean bean) {
|
|
|
+ if (mVideoWorkAdapter.getData().size() == 0) {
|
|
|
+ mVideoWorkAdapter.addData(bean);
|
|
|
} else {
|
|
|
- mLlUploadEmptyView.setVisibility(View.VISIBLE);
|
|
|
- mRecyclerView.setVisibility(View.GONE);
|
|
|
+ mVideoWorkAdapter.setData(mVideoWorkAdapter.getData().size() - 1, bean);
|
|
|
}
|
|
|
+ checkVideoList();
|
|
|
}
|
|
|
|
|
|
private void checkVideoList() {
|
|
|
List<PracticeVideoWorkBean> data = mVideoWorkAdapter.getData();
|
|
|
- if (data.size() < CourseConstants.COURSE_HOMEWORK_MAX_VIDEO_COUNT) {
|
|
|
- if (!checkAddItemExist(data)) {
|
|
|
- //老师未点评的情况下才添加add按钮
|
|
|
- data.add(PracticeVideoWorkBean.defaultInstance());
|
|
|
+ if (data.size() > 0) {
|
|
|
+ mLlUploadEmptyView.setVisibility(View.GONE);
|
|
|
+ mRecyclerView.setVisibility(View.VISIBLE);
|
|
|
+ if (data.size() < CourseConstants.COURSE_HOMEWORK_MAX_VIDEO_COUNT) {
|
|
|
+ if (!checkAddItemExist(data)) {
|
|
|
+ //老师未点评的情况下才添加add按钮
|
|
|
+ mVideoWorkAdapter.addData(PracticeVideoWorkBean.defaultInstance());
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ mLlUploadEmptyView.setVisibility(View.VISIBLE);
|
|
|
+ mRecyclerView.setVisibility(View.GONE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private boolean checkAddItemExist(List<PracticeVideoWorkBean> data) {
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
PracticeVideoWorkBean videoWorkBean = data.get(i);
|
|
@@ -180,7 +200,13 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
}
|
|
|
if (id == R.id.tv_confirm) {
|
|
|
if (mEventListener != null) {
|
|
|
- mEventListener.onResult();
|
|
|
+ //提交
|
|
|
+ if (!isChangeHomeWork) {
|
|
|
+ ToastUtil.getInstance().showShort("请选择视频文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String videoHomeworkResult = getVideoHomeworkResult();
|
|
|
+ mEventListener.onResult(videoHomeworkResult);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -200,10 +226,23 @@ public class UploadHomeworkVideoDialog extends Dialog implements View.OnClickLis
|
|
|
}
|
|
|
|
|
|
public interface OnEventListener {
|
|
|
- void onResult();
|
|
|
+ void onResult(String result);
|
|
|
|
|
|
void goUpload();
|
|
|
|
|
|
- void onDel(int pos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getVideoHomeworkResult() {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (int i = 0; i < mVideoWorkAdapter.getData().size(); i++) {
|
|
|
+ PracticeVideoWorkBean videoWorkBean = mVideoWorkAdapter.getData().get(i);
|
|
|
+ if (!TextUtils.isEmpty(videoWorkBean.videoUrl)) {
|
|
|
+ if (i != 0) {
|
|
|
+ stringBuilder.append(",");
|
|
|
+ }
|
|
|
+ stringBuilder.append(videoWorkBean.videoUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
}
|
|
|
}
|