From ea57c8d609700b40fa515a2d7c64cabd95c87ce9 Mon Sep 17 00:00:00 2001 From: shixianjie Date: Wed, 9 Oct 2024 11:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=A8=E6=80=BB=E7=BB=93=E5=92=8C=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E6=80=A7=E6=80=BB=E7=BB=93=E5=88=97=E8=A1=A8=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetDropDown.xml | 15 +- .../java/com/hjx/parent/StuHomeworkActivity.java | 214 ++++++++++++++++++++- .../com/hjx/parent/dialog/StageHuyouDialog.java | 96 +++++++++ .../main/res/color/color_huyou_subject_select.xml | 5 + app/src/main/res/drawable/bg_huyou_time_select.xml | 7 + app/src/main/res/drawable/btn_general_huyou.xml | 7 + .../main/res/drawable/btn_huyou_subject_select.xml | 18 ++ app/src/main/res/drawable/svg_close_24.xml | 10 + .../main/res/layout/activity_student_homework.xml | 58 ++++++ app/src/main/res/layout/dialog_stage_huyou.xml | 173 +++++++++++++++++ app/src/main/res/values/appearance.xml | 4 + .../com/prws/common/bean/homework/StDetail.java | 70 +++++++ .../main/java/com/prws/common/net/NetWorks.java | 29 +++ 13 files changed, 704 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/hjx/parent/dialog/StageHuyouDialog.java create mode 100644 app/src/main/res/color/color_huyou_subject_select.xml create mode 100644 app/src/main/res/drawable/bg_huyou_time_select.xml create mode 100644 app/src/main/res/drawable/btn_general_huyou.xml create mode 100644 app/src/main/res/drawable/btn_huyou_subject_select.xml create mode 100644 app/src/main/res/drawable/svg_close_24.xml create mode 100644 app/src/main/res/layout/dialog_stage_huyou.xml create mode 100644 libs/common/src/main/java/com/prws/common/bean/homework/StDetail.java diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c338..6d1ad88 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -3,7 +3,20 @@ - + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/hjx/parent/StuHomeworkActivity.java b/app/src/main/java/com/hjx/parent/StuHomeworkActivity.java index 2fdcd20..bf705e4 100644 --- a/app/src/main/java/com/hjx/parent/StuHomeworkActivity.java +++ b/app/src/main/java/com/hjx/parent/StuHomeworkActivity.java @@ -3,12 +3,21 @@ package com.hjx.parent; import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupMenu; import android.widget.PopupWindow; +import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.MutableLiveData; +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.BaseViewHolder; +import com.google.android.material.tabs.TabLayout; import com.google.gson.Gson; import com.hjx.parent.adapter.HomeworkListAdapter; import com.hjx.parent.databinding.ActivityStudentHomeworkBinding; @@ -17,14 +26,27 @@ import com.hjx.parent.databinding.PopupFilterGradeBinding; import com.hjx.parent.databinding.PopupFilterSubjectBinding; import com.hjx.parent.databinding.PopupFilterTermBinding; import com.hjx.parent.dialog.MsgConfirmDialog; +import com.hjx.parent.dialog.StageHuyouDialog; +import com.hjx.parent.function.Function1; import com.hjx.parent.rx.BaseRxActivity; +import com.prws.common.bean.ResponseResult; import com.prws.common.bean.Student; import com.prws.common.bean.homework.HomeworkList; +import com.prws.common.bean.homework.StDetail; import com.prws.common.net.NetWorks; import com.prws.common.utils.SharedPreferencesUtil; import com.trello.rxlifecycle2.android.RxLifecycleAndroid; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -34,8 +56,14 @@ public class StuHomeworkActivity extends BaseRxActivity mWeekList = new ArrayList<>(); + private final List mStageList = new ArrayList<>(); + private final HuyouAdapter weekAdapter = new HuyouAdapter(mWeekList); + private final HuyouAdapter stageAdapter = new HuyouAdapter(mStageList); + PopupWindow subjectFilter, gradeFilter, termFilter, feedbackFilter; MsgConfirmDialog deleteDialog; + StageHuyouDialog stageHuyouDialog; State state = new State(); private void handlerIntent() { @@ -55,7 +83,7 @@ public class StuHomeworkActivity extends BaseRxActivity onBackPressed()); binding.tvTitle.setText(state.student.stuName + "的全部作业"); - + setupTab(); binding.recyclerView.setAdapter(homeworkAdapter); binding.ftSubject.setOnClickListener(v -> showSubjectFilter()); @@ -96,6 +124,15 @@ public class StuHomeworkActivity extends BaseRxActivity generalWeek()); + binding.btnStageHuyou.setOnClickListener(v -> { + if (stageHuyouDialog == null) stageHuyouDialog = new StageHuyouDialog(this); + stageHuyouDialog.show(this::generalStage); + }); + + getWeekHuyou(); + getStageHuyou(); } @Override @@ -114,11 +151,43 @@ public class StuHomeworkActivity extends BaseRxActivity { + if (throwable != null) { + throwable.printStackTrace(); + return; + } + if (list != null) { + mWeekList.clear(); + mWeekList.addAll(list); + weekAdapter.notifyDataSetChanged(); + + boolean exist = false; + int thisWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR); + for (StDetail bean: mWeekList) { + Calendar other = Calendar.getInstance(); + other.setTime(bean.endTime); + if (other.get(Calendar.WEEK_OF_YEAR) == thisWeek) { + exist = true; + break; + } + } + binding.btnGeneralHuyou.setVisibility(exist ? View.GONE : View.VISIBLE); + } + }); + } + + @SuppressLint({"CheckResult", "NotifyDataSetChanged"}) + private void getStageHuyou() { + NetWorks.service_url.getHuyouList(NetWorks.getHeader(), state.student.stuId, 1) + .compose(transformSingle()) + .map(ResponseResult::getData) + .subscribe((list, throwable) -> { + if (throwable != null) { + throwable.printStackTrace(); + return; + } + if (list != null) { + mStageList.clear(); + mStageList.addAll(list); + stageAdapter.notifyDataSetChanged(); + } + }); + } + + @SuppressLint("CheckResult") + private void generalWeek() { + showLoadingDialog("稍等..."); + NetWorks.service_url.generalHuyou() + .compose(transformSingle()) + .subscribe((response, throwable) -> { + cancelLoadingDialog(); + if (throwable != null) { + loadFail("失败"); + throwable.printStackTrace(); + return; + } + if (response != null && response.getSuccess()) { + binding.btnGeneralHuyou.setVisibility(View.GONE); + getWeekHuyou(); + } + }); + } + + @SuppressLint("CheckResult") + private void generalStage(Date startDate, Date endDate, String subject) { + SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd HH:mm:ss", Locale.CHINA); + Map body = new HashMap<>(); + body.put("stuId", state.student.stuId); + body.put("startTime", format.format(startDate)); + body.put("endTime", format.format(endDate)); + body.put("subject", subject); + showLoadingDialog("稍等..."); + NetWorks.service_url.generalStageHuyou(NetWorks.getHeader(), body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) + .subscribe((response, throwable) -> { + if (throwable != null) { + loadFail("失败"); + throwable.printStackTrace(); + return; + } + if (response.getSuccess()) { + getStageHuyou(); + cancelLoadingDialog(); + } else { + loadFail(response.getMsg()); + } + }); + } + private void showSubjectFilter() { if (subjectFilter == null) { PopupFilterSubjectBinding db = PopupFilterSubjectBinding.inflate(getLayoutInflater()); @@ -255,4 +419,52 @@ public class StuHomeworkActivity extends BaseRxActivity { + public Function1 deleteCall; + public Student student; + + public HuyouAdapter(@Nullable List data) { + super(R.layout.item_homework_list, data); + } + + @SuppressLint("SetTextI18n,SimpleDateFormat") + @Override + protected void convert(@NonNull BaseViewHolder holder, StDetail data) { + holder.setGone(R.id.tvFlag, false); + int subjectImg; + switch (data.homeworkSubject) { + case "语文": + subjectImg = R.drawable.ic_chinese; + break; + case "英语": + subjectImg = R.drawable.ic_english; + break; + case "物理": + subjectImg = R.drawable.ic_physics; + break; + case "化学": + subjectImg = R.drawable.ic_chemistry; + break; + case "数学": + default: + subjectImg = R.drawable.ic_math; + } + holder.setImageResource(R.id.ivSubject, subjectImg); + Date endDate = new Date(data.endTime.getTime() - 1000); + String startStr = new SimpleDateFormat("yyyy.M.d").format(data.startTime); + String endStr = new SimpleDateFormat("-M.d").format(endDate); + String typeStr = data.type == 0 ? "作业周总结" : "作业阶段性总结"; + String title = startStr + endStr + data.homeworkSubject + typeStr; + holder.setText(R.id.tvName, title); + holder.setText(R.id.tvGrade, data.grade); + } + + private SimpleDateFormat getFormatWithGmt8(String pattern) { + SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA); + //format.setTimeZone(TimeZone.getTimeZone("GMT+16")); + return format; + } + } + } diff --git a/app/src/main/java/com/hjx/parent/dialog/StageHuyouDialog.java b/app/src/main/java/com/hjx/parent/dialog/StageHuyouDialog.java new file mode 100644 index 0000000..b0d753a --- /dev/null +++ b/app/src/main/java/com/hjx/parent/dialog/StageHuyouDialog.java @@ -0,0 +1,96 @@ +package com.hjx.parent.dialog; + +import android.content.Context; +import android.view.View; +import android.widget.RadioButton; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import com.bigkoo.pickerview.builder.TimePickerBuilder; +import com.bigkoo.pickerview.view.TimePickerView; +import com.hjx.parent.databinding.DialogStageHuyouBinding; +import com.hjx.parent.function.Function3; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class StageHuyouDialog extends BaseDialog{ + + Function3 callback; + Date startDate; + Date endDate; + + public StageHuyouDialog(Context context) { + super(context); + } + + @Override + public void initView() { + super.initView(); + RadioButton firstRb = (RadioButton) binding.rgSubject.getChildAt(0); + firstRb.setChecked(true); + binding.btnClose.setOnClickListener(v -> { + dismiss(); + }); + binding.tvStart.setOnClickListener(v -> { + TimePickerView pickerView = new TimePickerBuilder(getContext(), (date, p) -> { + long t = date.getTime(); + long day = 24 * 60 * 60 * 1000; + long h8 = 8 * 60 * 60 * 1000; + startDate = new Date(t / day * day - h8); + binding.tvStart.setText(new SimpleDateFormat("yyyy-MM-dd").format(startDate)); + }).setType(new boolean[] {true, true, true, false, false, false}).isDialog(true).build(); + pickerView.show(); + }); + binding.tvEnd.setOnClickListener(v -> { + TimePickerView pickerView = new TimePickerBuilder(getContext(), (date, p) -> { + long t = date.getTime(); + long day = 24 * 60 * 60 * 1000; + long h8 = 8 * 60 * 60 * 1000; + endDate = new Date(t / day * day - h8 + day - 1000); + binding.tvEnd.setText(new SimpleDateFormat("yyyy-MM-dd").format(endDate)); + }).setType(new boolean[] {true, true, true, false, false, false}).isDialog(true).build(); + pickerView.show(); + }); + binding.btnConfirm.setOnClickListener(v -> { + if (startDate == null) { + Toast.makeText(getContext(), "请先设置开始时间和截止时间。", Toast.LENGTH_SHORT).show(); + return; + } + if (endDate == null) { + Toast.makeText(getContext(), "请先设置开始时间和截止时间。", Toast.LENGTH_SHORT).show(); + return; + } + if (endDate.before(startDate)) { + Toast.makeText(getContext(), "结束时间不能早于开始时间", Toast.LENGTH_SHORT).show(); + return; + } + String subject = ""; + for (int i = 0; i < binding.rgSubject.getChildCount(); i++) { + View view = binding.rgSubject.getChildAt(i); + if (!(view instanceof RadioButton)) { + continue; + } + RadioButton rb = (RadioButton) view; + if (rb.isChecked()) { + subject = rb.getText().toString(); + break; + } + } + if (callback != null) callback.invoke(startDate, endDate, subject); + dismiss(); + }); + } + + public void show(Function3 callback) { + this.callback = callback; + super.show(); + } + + @NonNull + @Override + public DialogStageHuyouBinding getBinding() { + return DialogStageHuyouBinding.inflate(getLayoutInflater()); + } +} diff --git a/app/src/main/res/color/color_huyou_subject_select.xml b/app/src/main/res/color/color_huyou_subject_select.xml new file mode 100644 index 0000000..142cb49 --- /dev/null +++ b/app/src/main/res/color/color_huyou_subject_select.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_huyou_time_select.xml b/app/src/main/res/drawable/bg_huyou_time_select.xml new file mode 100644 index 0000000..fc6ba33 --- /dev/null +++ b/app/src/main/res/drawable/bg_huyou_time_select.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_general_huyou.xml b/app/src/main/res/drawable/btn_general_huyou.xml new file mode 100644 index 0000000..af83ea1 --- /dev/null +++ b/app/src/main/res/drawable/btn_general_huyou.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_huyou_subject_select.xml b/app/src/main/res/drawable/btn_huyou_subject_select.xml new file mode 100644 index 0000000..48e854b --- /dev/null +++ b/app/src/main/res/drawable/btn_huyou_subject_select.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/svg_close_24.xml b/app/src/main/res/drawable/svg_close_24.xml new file mode 100644 index 0000000..1290f9d --- /dev/null +++ b/app/src/main/res/drawable/svg_close_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_student_homework.xml b/app/src/main/res/layout/activity_student_homework.xml index 838665f..b25c473 100644 --- a/app/src/main/res/layout/activity_student_homework.xml +++ b/app/src/main/res/layout/activity_student_homework.xml @@ -32,7 +32,23 @@ android:layout_width="20dp" android:layout_height="20dp"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/appearance.xml b/app/src/main/res/values/appearance.xml index a334b8f..3369d80 100644 --- a/app/src/main/res/values/appearance.xml +++ b/app/src/main/res/values/appearance.xml @@ -6,4 +6,8 @@ bold + + \ No newline at end of file diff --git a/libs/common/src/main/java/com/prws/common/bean/homework/StDetail.java b/libs/common/src/main/java/com/prws/common/bean/homework/StDetail.java new file mode 100644 index 0000000..5748481 --- /dev/null +++ b/libs/common/src/main/java/com/prws/common/bean/homework/StDetail.java @@ -0,0 +1,70 @@ +package com.prws.common.bean.homework; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class StDetail { + + public String id; + + public String stuId; + public Date startTime; + public Date endTime; + public String homeworkSubject; + public String scId; + public String grade; + + public int total; + public int correct; + + public float mondayCorrection; + public float tuesdayCorrection; + public float wednesdayCorrection; + public float thursdayCorrection; + public float fridayCorrection; + + public String correction; + public transient List correctionList; + + public List points; + + public int type; + + public void formatCollection() { + correctionList = new ArrayList<>(); + if (correction == null) { + return; + } + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); + try { + List list = gson.fromJson(correction, new TypeToken>(){}.getType()); + for (Correction item: list) { + if (item != null && item.date != null) { + correctionList.add(item); + } + } + } catch (Exception e){ + e.printStackTrace(); + } + } + + public static class Point { + public String pointId; + public String pointName; + public float beforeState; + public float afterState; + public float gap; + public float correctness; + } + + public static class Correction { + public float correction; + public Date date; + } + +} diff --git a/libs/common/src/main/java/com/prws/common/net/NetWorks.java b/libs/common/src/main/java/com/prws/common/net/NetWorks.java index ee84a96..549a6d9 100644 --- a/libs/common/src/main/java/com/prws/common/net/NetWorks.java +++ b/libs/common/src/main/java/com/prws/common/net/NetWorks.java @@ -17,6 +17,7 @@ import com.prws.common.bean.baidu.BaiduInput; import com.prws.common.bean.homework.HomeWork; import com.prws.common.bean.homework.HomeworkDetail; import com.prws.common.bean.homework.HomeworkList; +import com.prws.common.bean.homework.StDetail; import com.prws.common.utils.BitmapUtils; import com.prws.common.utils.SharedPreferencesUtil; @@ -221,6 +222,34 @@ public class NetWorks extends RetrofitUtils { @Query("type") boolean type ); + @GET("api/v1/homework/listHomeworkStatistics") + Single>> getHuyouList( + @Header("Authorization") String token, + @Query("stuId") String stuId, + @Query("type") int type //0: 周报, 1:阶段总结 + ); + + @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") + Single> getHuyouDetail( + @Header("Authorization") String token, + @Query("homeworkStatisticsId") String homeworkId + ); + + @GET("api/v1/demo/generalStatisticsHomework") + Single> generalHuyou(); + + @POST("api/v1/homework/generalHomeworkStageStatistics") + Single> generalStageHuyou( + @Header("Authorization") String token, + @Body Object body + ); + + @GET("api/v1/homework/removeHomeworkStatistics") + Single> deleteHuyou( + @Header("Authorization") String token, + @Query("homeworkStatisticsId") String homeworkId + ); + } public static String getUserId() { -- 1.9.0