Commit 06daaf123b5d0629ed8c83516721632eb2b5bf8d
1 parent
8d5120ae75
Exists in
master
编辑作业
Showing
5 changed files
with
237 additions
and
1 deletions
Show diff stats
app/src/main/java/com/hjx/parent/HomeworkDetailActivity.java
| ... | ... | @@ -12,6 +12,7 @@ import com.bumptech.glide.Glide; |
| 12 | 12 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 13 | 13 | import com.chad.library.adapter.base.BaseViewHolder; |
| 14 | 14 | import com.hjx.parent.databinding.ActivityHomeworkDetailBinding; |
| 15 | +import com.hjx.parent.dialog.EditHomeworkDialog; | |
| 15 | 16 | import com.hjx.parent.rx.BaseRxActivity; |
| 16 | 17 | import com.prws.common.bean.ResponseResult; |
| 17 | 18 | import com.prws.common.bean.Student; |
| ... | ... | @@ -20,6 +21,8 @@ import com.prws.common.bean.homework.HomeworkList; |
| 20 | 21 | import com.prws.common.net.NetWorks; |
| 21 | 22 | |
| 22 | 23 | import java.util.ArrayList; |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.Map; | |
| 23 | 26 | |
| 24 | 27 | public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetailBinding> { |
| 25 | 28 | |
| ... | ... | @@ -27,12 +30,14 @@ public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetai |
| 27 | 30 | private Student student; |
| 28 | 31 | |
| 29 | 32 | private Adapter mAdapter = new Adapter(); |
| 33 | + private EditHomeworkDialog mDialog; | |
| 30 | 34 | |
| 31 | 35 | @Override |
| 32 | 36 | public void initView(Bundle savedInstanceState) { |
| 33 | 37 | binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); |
| 34 | 38 | mData = (HomeworkList) getIntent().getSerializableExtra("data"); |
| 35 | 39 | student = (Student) getIntent().getSerializableExtra("student"); |
| 40 | + mDialog = new EditHomeworkDialog(this, mData); | |
| 36 | 41 | binding.tvTitle.setText(mData.getName()); |
| 37 | 42 | |
| 38 | 43 | binding.recyclerView.setAdapter(mAdapter); |
| ... | ... | @@ -46,6 +51,9 @@ public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetai |
| 46 | 51 | intent.putExtra("list", new ArrayList<>(mAdapter.getData())); |
| 47 | 52 | startActivity(intent); |
| 48 | 53 | }); |
| 54 | + binding.btnEdit.setOnClickListener(v -> mDialog.show(data -> { | |
| 55 | + edit(data); | |
| 56 | + })); | |
| 49 | 57 | } |
| 50 | 58 | |
| 51 | 59 | @SuppressLint("CheckResult") |
| ... | ... | @@ -59,6 +67,29 @@ public class HomeworkDetailActivity extends BaseRxActivity<ActivityHomeworkDetai |
| 59 | 67 | }); |
| 60 | 68 | } |
| 61 | 69 | |
| 70 | + @SuppressLint("CheckResult") | |
| 71 | + private void edit(HomeworkList data) { | |
| 72 | + Map<String, Object> body = new HashMap<>(); | |
| 73 | + body.put("homeworkId", data.getId()); | |
| 74 | + body.put("name", data.getName()); | |
| 75 | + body.put("grade", data.getGrade()); | |
| 76 | + body.put("subject", data.getSubject()); | |
| 77 | + body.put("term", data.getTerm()); | |
| 78 | + body.put("uploadTime", data.uploadTime); | |
| 79 | + showLoadingDialog("请稍等···"); | |
| 80 | + NetWorks.service_url.editHomework(NetWorks.getHeader(), body) | |
| 81 | + .compose(transformSingle()) | |
| 82 | + .subscribe((response, th) -> { | |
| 83 | + if (th != null) th.printStackTrace(); | |
| 84 | + if (response != null && response.getSuccess()) { | |
| 85 | + cancelLoadingDialog(); | |
| 86 | + binding.tvTitle.setText(data.getName()); | |
| 87 | + } else { | |
| 88 | + loadFail(response == null ? "" : response.getMsg()); | |
| 89 | + } | |
| 90 | + }); | |
| 91 | + } | |
| 92 | + | |
| 62 | 93 | @Override |
| 63 | 94 | protected ActivityHomeworkDetailBinding getViewBinding() { |
| 64 | 95 | return ActivityHomeworkDetailBinding.inflate(getLayoutInflater()); | ... | ... |
app/src/main/java/com/hjx/parent/dialog/EditHomeworkDialog.java
| ... | ... | @@ -0,0 +1,189 @@ |
| 1 | +package com.hjx.parent.dialog; | |
| 2 | + | |
| 3 | +import android.annotation.SuppressLint; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.util.Pair; | |
| 6 | +import android.view.View; | |
| 7 | +import android.widget.AdapterView; | |
| 8 | +import android.widget.ArrayAdapter; | |
| 9 | +import android.widget.Toast; | |
| 10 | + | |
| 11 | +import androidx.annotation.NonNull; | |
| 12 | + | |
| 13 | +import com.bigkoo.pickerview.builder.TimePickerBuilder; | |
| 14 | +import com.google.gson.Gson; | |
| 15 | +import com.hjx.parent.R; | |
| 16 | +import com.hjx.parent.bean.StudentBean; | |
| 17 | +import com.hjx.parent.databinding.DialogAddHomeworkBinding; | |
| 18 | +import com.hjx.parent.function.Function1; | |
| 19 | +import com.hjx.parent.rx.BaseRxActivity; | |
| 20 | +import com.prws.common.bean.GradeAndSubject; | |
| 21 | +import com.prws.common.bean.ResponseResult; | |
| 22 | +import com.prws.common.bean.Student; | |
| 23 | +import com.prws.common.bean.Subject; | |
| 24 | +import com.prws.common.bean.baidu.BaiduInput; | |
| 25 | +import com.prws.common.bean.homework.HomeworkList; | |
| 26 | +import com.prws.common.net.NetWorks; | |
| 27 | +import com.prws.common.utils.SharedPreferencesUtil; | |
| 28 | +import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | |
| 29 | + | |
| 30 | +import java.io.File; | |
| 31 | +import java.text.SimpleDateFormat; | |
| 32 | +import java.util.ArrayList; | |
| 33 | +import java.util.Calendar; | |
| 34 | +import java.util.Date; | |
| 35 | +import java.util.HashMap; | |
| 36 | +import java.util.List; | |
| 37 | +import java.util.Locale; | |
| 38 | +import java.util.Map; | |
| 39 | + | |
| 40 | +import io.reactivex.Observable; | |
| 41 | +import io.reactivex.android.schedulers.AndroidSchedulers; | |
| 42 | +import io.reactivex.schedulers.Schedulers; | |
| 43 | + | |
| 44 | +public class EditHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ | |
| 45 | + private final BaseRxActivity<?> activity; | |
| 46 | + | |
| 47 | + private Function1<HomeworkList> callback; | |
| 48 | + | |
| 49 | + HomeworkList mData; | |
| 50 | + | |
| 51 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); | |
| 52 | + List<GradeAndSubject> gradeAndSubjectList; | |
| 53 | + | |
| 54 | + String grade; | |
| 55 | + String term; | |
| 56 | + String subject; | |
| 57 | + Date uploadTime; | |
| 58 | + | |
| 59 | + public EditHomeworkDialog(BaseRxActivity<?> context, HomeworkList data) { | |
| 60 | + super((Context) context); | |
| 61 | + activity = context; | |
| 62 | + mData = data; | |
| 63 | + uploadTime = data.uploadTime; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void show(Function1<HomeworkList> callback) { | |
| 67 | + this.callback = callback; | |
| 68 | + super.show(); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @SuppressLint("SetTextI18n") | |
| 72 | + @Override | |
| 73 | + public void initView() { | |
| 74 | + binding.tvTitle.setText("编辑作业"); | |
| 75 | + binding.btnClose.setOnClickListener(v -> dismiss()); | |
| 76 | + binding.tvStu.setVisibility(View.GONE); | |
| 77 | + binding.spStudent.setVisibility(View.GONE); | |
| 78 | + binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 79 | + @Override | |
| 80 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 81 | + term = getContext().getResources().getStringArray(R.array.grade_array)[position]; | |
| 82 | + } | |
| 83 | + @Override | |
| 84 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 85 | + } | |
| 86 | + }); | |
| 87 | + binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 88 | + @Override | |
| 89 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 90 | + grade = gradeAndSubjectList.get(position).getGrade().getGrade(); | |
| 91 | + refreshSubjects(position); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @Override | |
| 95 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 96 | + } | |
| 97 | + }); | |
| 98 | + | |
| 99 | + binding.tvDate.setText(dateFormat.format(uploadTime)); | |
| 100 | + binding.tvDate.setOnClickListener(v -> { | |
| 101 | + Calendar calendar = Calendar.getInstance(); | |
| 102 | + calendar.setTime(uploadTime); | |
| 103 | + new TimePickerBuilder(getContext(), (date, v1) -> { | |
| 104 | + uploadTime = date; | |
| 105 | + binding.tvDate.setText(dateFormat.format(uploadTime)); | |
| 106 | + binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | |
| 107 | + }).setType(new boolean[]{true, true, true, false, false, false}).setDate(calendar) | |
| 108 | + .isDialog(true).build().show(); | |
| 109 | + }); | |
| 110 | + | |
| 111 | + binding.btnConfirm.setOnClickListener(v -> { | |
| 112 | + String name = binding.etName.getText().toString().trim(); | |
| 113 | + if (name.isEmpty()) { | |
| 114 | + Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + dismiss(); | |
| 118 | + if (callback != null) { | |
| 119 | + mData.setGrade(grade); | |
| 120 | + mData.setTerm(term); | |
| 121 | + mData.setSubject(subject); | |
| 122 | + mData.uploadTime = uploadTime; | |
| 123 | + mData.setName(name); | |
| 124 | + callback.invoke(mData); | |
| 125 | + } | |
| 126 | + }); | |
| 127 | + | |
| 128 | + getGrade(); | |
| 129 | + } | |
| 130 | + | |
| 131 | + @SuppressLint("CheckResult") | |
| 132 | + private void getGrade() { | |
| 133 | + NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) | |
| 134 | + .subscribeOn(Schedulers.io()) | |
| 135 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 136 | + .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | |
| 137 | + .map(ResponseResult::getData) | |
| 138 | + .firstOrError() | |
| 139 | + .subscribe((data, th) -> { | |
| 140 | + if (th != null) th.printStackTrace(); | |
| 141 | + if (data != null && data.size() > 0) { | |
| 142 | + gradeAndSubjectList = data; | |
| 143 | + List<String> grades = new ArrayList<>(); | |
| 144 | + for (GradeAndSubject it: data) { | |
| 145 | + grades.add(it.getGrade().getGrade()); | |
| 146 | + } | |
| 147 | + binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); | |
| 148 | + | |
| 149 | + int p = 0; | |
| 150 | + for (GradeAndSubject it: gradeAndSubjectList) { | |
| 151 | + if (it.getGrade().getGrade().equals(mData.getGrade())) { | |
| 152 | + p = gradeAndSubjectList.indexOf(it); | |
| 153 | + break; | |
| 154 | + } | |
| 155 | + } | |
| 156 | + binding.spGrade.setSelection(p); | |
| 157 | + } | |
| 158 | + }); | |
| 159 | + } | |
| 160 | + | |
| 161 | + private void refreshSubjects(int gradePosition) { | |
| 162 | + if (gradeAndSubjectList == null) return; | |
| 163 | + List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); | |
| 164 | + List<String> subjects = new ArrayList<>(); | |
| 165 | + for (Subject s: subjectList) { | |
| 166 | + subjects.add(s.getSubject()); | |
| 167 | + } | |
| 168 | + int position = Math.max(subjects.indexOf(mData.getSubject()), 0); | |
| 169 | + binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 170 | + @SuppressLint("SetTextI18n") | |
| 171 | + @Override | |
| 172 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 173 | + subject = subjects.get(position); | |
| 174 | + binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | |
| 175 | + } | |
| 176 | + @Override | |
| 177 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 178 | + } | |
| 179 | + }); | |
| 180 | + binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); | |
| 181 | + binding.spSubject.setSelection(position); | |
| 182 | + } | |
| 183 | + | |
| 184 | + @NonNull | |
| 185 | + @Override | |
| 186 | + public DialogAddHomeworkBinding getBinding() { | |
| 187 | + return DialogAddHomeworkBinding.inflate(getLayoutInflater()); | |
| 188 | + } | |
| 189 | +} | ... | ... |
app/src/main/res/layout/activity_homework_detail.xml
| ... | ... | @@ -25,6 +25,12 @@ |
| 25 | 25 | android:textStyle="bold" |
| 26 | 26 | android:layout_width="wrap_content" |
| 27 | 27 | android:layout_height="wrap_content"/> |
| 28 | + <androidx.appcompat.widget.AppCompatImageView | |
| 29 | + android:id="@+id/btnEdit" | |
| 30 | + android:src="@drawable/svg_homework_edit" | |
| 31 | + android:layout_marginStart="5dp" | |
| 32 | + android:layout_width="18dp" | |
| 33 | + android:layout_height="18dp"/> | |
| 28 | 34 | <TextView |
| 29 | 35 | android:id="@+id/btnFeedback" |
| 30 | 36 | android:text="反馈作业" | ... | ... |
app/src/main/res/layout/dialog_add_homework.xml
| ... | ... | @@ -14,11 +14,13 @@ |
| 14 | 14 | android:layout_height="match_parent"> |
| 15 | 15 | |
| 16 | 16 | <FrameLayout |
| 17 | - android:layout_marginVertical="8dp" | |
| 17 | + android:layout_marginTop="8dp" | |
| 18 | + android:layout_marginBottom="-12dp" | |
| 18 | 19 | android:layout_width="match_parent" |
| 19 | 20 | android:layout_height="wrap_content"> |
| 20 | 21 | |
| 21 | 22 | <TextView |
| 23 | + android:id="@+id/tvTitle" | |
| 22 | 24 | android:text="录入作业" |
| 23 | 25 | android:textSize="17sp" |
| 24 | 26 | android:textStyle="bold" |
| ... | ... | @@ -37,6 +39,8 @@ |
| 37 | 39 | </FrameLayout> |
| 38 | 40 | |
| 39 | 41 | <TextView |
| 42 | + android:id="@+id/tvStu" | |
| 43 | + android:layout_marginTop="20dp" | |
| 40 | 44 | android:layout_width="wrap_content" |
| 41 | 45 | android:layout_height="wrap_content" |
| 42 | 46 | android:layout_marginHorizontal="15dp" | ... | ... |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| ... | ... | @@ -205,6 +205,12 @@ public class NetWorks extends RetrofitUtils { |
| 205 | 205 | @POST("api/v1/homework/uploadHomeworkFeedback") |
| 206 | 206 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); |
| 207 | 207 | |
| 208 | + @POST("api/v1/homework/editHomeworkInfo") | |
| 209 | + Single<ResponseResult<Boolean>> editHomework( | |
| 210 | + @Header("Authorization") String token, | |
| 211 | + @Body Object body | |
| 212 | + ); | |
| 213 | + | |
| 208 | 214 | } |
| 209 | 215 | |
| 210 | 216 | public static String getUserId() { | ... | ... |