Commit 21e7841a449508db5f4e9993377de73ae716483e
1 parent
82701f774d
Exists in
master
dialog优化
Showing
2 changed files
with
161 additions
and
148 deletions
Show diff stats
app/src/main/java/com/hjx/parent/dialog/AddHomeworkDialog.java
| 1 | package com.hjx.parent.dialog; | 1 | package com.hjx.parent.dialog; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | import android.util.Pair; | 5 | import android.util.Pair; |
| 6 | import android.view.View; | 6 | import android.view.View; |
| 7 | import android.view.WindowManager; | ||
| 7 | import android.widget.AdapterView; | 8 | import android.widget.AdapterView; |
| 8 | import android.widget.ArrayAdapter; | 9 | import android.widget.ArrayAdapter; |
| 9 | import android.widget.Toast; | 10 | import android.widget.Toast; |
| 10 | 11 | ||
| 11 | import androidx.annotation.NonNull; | 12 | import androidx.annotation.NonNull; |
| 12 | 13 | ||
| 13 | import com.bigkoo.pickerview.builder.TimePickerBuilder; | 14 | import com.bigkoo.pickerview.builder.TimePickerBuilder; |
| 14 | import com.google.gson.Gson; | 15 | import com.google.gson.Gson; |
| 15 | import com.hjx.parent.R; | 16 | import com.hjx.parent.R; |
| 16 | import com.hjx.parent.bean.StudentBean; | 17 | import com.hjx.parent.bean.StudentBean; |
| 17 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; | 18 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; |
| 18 | import com.hjx.parent.function.Function0; | 19 | import com.hjx.parent.function.Function0; |
| 19 | import com.hjx.parent.function.Function1; | 20 | import com.hjx.parent.function.Function1; |
| 20 | import com.hjx.parent.rx.BaseRxActivity; | 21 | import com.hjx.parent.rx.BaseRxActivity; |
| 21 | import com.prws.common.bean.GradeAndSubject; | 22 | import com.prws.common.bean.GradeAndSubject; |
| 22 | import com.prws.common.bean.ResponseResult; | 23 | import com.prws.common.bean.ResponseResult; |
| 23 | import com.prws.common.bean.Student; | 24 | import com.prws.common.bean.Student; |
| 24 | import com.prws.common.bean.Subject; | 25 | import com.prws.common.bean.Subject; |
| 25 | import com.prws.common.bean.baidu.BaiduInput; | 26 | import com.prws.common.bean.baidu.BaiduInput; |
| 26 | import com.prws.common.net.NetWorks; | 27 | import com.prws.common.net.NetWorks; |
| 27 | import com.prws.common.utils.SharedPreferencesUtil; | 28 | import com.prws.common.utils.SharedPreferencesUtil; |
| 28 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 29 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
| 29 | 30 | ||
| 30 | import java.io.File; | 31 | import java.io.File; |
| 31 | import java.text.SimpleDateFormat; | 32 | import java.text.SimpleDateFormat; |
| 32 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
| 33 | import java.util.Date; | 34 | import java.util.Date; |
| 34 | import java.util.HashMap; | 35 | import java.util.HashMap; |
| 35 | import java.util.List; | 36 | import java.util.List; |
| 36 | import java.util.Locale; | 37 | import java.util.Locale; |
| 37 | import java.util.Map; | 38 | import java.util.Map; |
| 38 | 39 | ||
| 39 | import io.reactivex.Observable; | 40 | import io.reactivex.Observable; |
| 40 | import io.reactivex.android.schedulers.AndroidSchedulers; | 41 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 41 | import io.reactivex.schedulers.Schedulers; | 42 | import io.reactivex.schedulers.Schedulers; |
| 42 | 43 | ||
| 43 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ | 44 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ |
| 44 | private final BaseRxActivity<?> activity; | 45 | private final BaseRxActivity<?> activity; |
| 45 | 46 | ||
| 46 | private Function1<Student> callback; | 47 | private Function1<Student> callback; |
| 47 | 48 | ||
| 48 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); | 49 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); |
| 49 | List<Student> studentList; | 50 | List<Student> studentList; |
| 50 | List<GradeAndSubject> gradeAndSubjectList; | 51 | List<GradeAndSubject> gradeAndSubjectList; |
| 51 | 52 | ||
| 52 | List<String> images; | 53 | List<String> images; |
| 53 | 54 | ||
| 54 | Student student; | 55 | Student student; |
| 55 | String grade; | 56 | String grade; |
| 56 | String term; | 57 | String term; |
| 57 | String subject; | 58 | String subject; |
| 58 | Date uploadTime = new Date(); | 59 | Date uploadTime = new Date(); |
| 59 | 60 | ||
| 60 | public AddHomeworkDialog(BaseRxActivity<?> context) { | 61 | public AddHomeworkDialog(BaseRxActivity<?> context) { |
| 61 | super((Context) context); | 62 | super((Context) context); |
| 62 | activity = context; | 63 | activity = context; |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | public void show(List<String> paths, Function1<Student> callback) { | 66 | public void show(List<String> paths, Function1<Student> callback) { |
| 66 | images = paths; | 67 | images = paths; |
| 67 | this.callback = callback; | 68 | this.callback = callback; |
| 68 | super.show(); | 69 | super.show(); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | @SuppressLint("SetTextI18n") | 72 | @SuppressLint("SetTextI18n") |
| 72 | @Override | 73 | @Override |
| 73 | public void initView() { | 74 | public void initView() { |
| 75 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); | ||
| 74 | binding.btnClose.setOnClickListener(v -> dismiss()); | 76 | binding.btnClose.setOnClickListener(v -> dismiss()); |
| 75 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 77 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 76 | @Override | 78 | @Override |
| 77 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 79 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 78 | student = studentList.get(position); | 80 | student = studentList.get(position); |
| 79 | if (gradeAndSubjectList == null) return; | 81 | if (gradeAndSubjectList == null) return; |
| 80 | int p = 0; | 82 | int p = 0; |
| 81 | for (GradeAndSubject it: gradeAndSubjectList) { | 83 | for (GradeAndSubject it: gradeAndSubjectList) { |
| 82 | if (it.getGrade().getGrade().equals(student.grade)) { | 84 | if (it.getGrade().getGrade().equals(student.grade)) { |
| 83 | p = gradeAndSubjectList.indexOf(it); | 85 | p = gradeAndSubjectList.indexOf(it); |
| 84 | break; | 86 | break; |
| 85 | } | 87 | } |
| 86 | } | 88 | } |
| 87 | binding.spGrade.setSelection(p); | 89 | binding.spGrade.setSelection(p); |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | @Override | 92 | @Override |
| 91 | public void onNothingSelected(AdapterView<?> parent) { | 93 | public void onNothingSelected(AdapterView<?> parent) { |
| 92 | } | 94 | } |
| 93 | }); | 95 | }); |
| 94 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 96 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 95 | @Override | 97 | @Override |
| 96 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 98 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 97 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; | 99 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; |
| 98 | } | 100 | } |
| 99 | @Override | 101 | @Override |
| 100 | public void onNothingSelected(AdapterView<?> parent) { | 102 | public void onNothingSelected(AdapterView<?> parent) { |
| 101 | } | 103 | } |
| 102 | }); | 104 | }); |
| 103 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 105 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 104 | @Override | 106 | @Override |
| 105 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 107 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 106 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); | 108 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); |
| 107 | refreshSubjects(position); | 109 | refreshSubjects(position); |
| 108 | } | 110 | } |
| 109 | 111 | ||
| 110 | @Override | 112 | @Override |
| 111 | public void onNothingSelected(AdapterView<?> parent) { | 113 | public void onNothingSelected(AdapterView<?> parent) { |
| 112 | } | 114 | } |
| 113 | }); | 115 | }); |
| 114 | 116 | ||
| 115 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 117 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
| 116 | binding.tvDate.setOnClickListener(v -> { | 118 | binding.tvDate.setOnClickListener(v -> { |
| 117 | new TimePickerBuilder(getContext(), (date, v1) -> { | 119 | new TimePickerBuilder(getContext(), (date, v1) -> { |
| 118 | uploadTime = date; | 120 | uploadTime = date; |
| 119 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 121 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
| 120 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 122 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
| 121 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); | 123 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); |
| 122 | }); | 124 | }); |
| 123 | 125 | ||
| 124 | binding.btnConfirm.setOnClickListener(v -> { | 126 | binding.btnConfirm.setOnClickListener(v -> { |
| 125 | String name = binding.etName.getText().toString().trim(); | 127 | String name = binding.etName.getText().toString().trim(); |
| 126 | if (name.isEmpty()) { | 128 | if (name.isEmpty()) { |
| 127 | Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); | 129 | Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); |
| 128 | return; | 130 | return; |
| 129 | } | 131 | } |
| 130 | uploadImage(name); | 132 | uploadImage(name); |
| 131 | }); | 133 | }); |
| 132 | 134 | ||
| 133 | getGrade(); | 135 | getGrade(); |
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | private String getCurrentStuId() { | 138 | private String getCurrentStuId() { |
| 137 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 139 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 138 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 140 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
| 139 | return studentBean.getStuId(); | 141 | return studentBean.getStuId(); |
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | @SuppressLint("CheckResult") | 144 | @SuppressLint("CheckResult") |
| 143 | private void getStudents() { | 145 | private void getStudents() { |
| 144 | NetWorks.listStudent() | 146 | NetWorks.listStudent() |
| 145 | .subscribeOn(Schedulers.io()) | 147 | .subscribeOn(Schedulers.io()) |
| 146 | .observeOn(AndroidSchedulers.mainThread()) | 148 | .observeOn(AndroidSchedulers.mainThread()) |
| 147 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 149 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
| 148 | .map(ResponseResult::getData) | 150 | .map(ResponseResult::getData) |
| 149 | .subscribe((data, th) -> { | 151 | .subscribe((data, th) -> { |
| 150 | if (th != null) th.printStackTrace(); | 152 | if (th != null) th.printStackTrace(); |
| 151 | if (data != null && data.size() > 0) { | 153 | if (data != null && data.size() > 0) { |
| 152 | studentList = data; | 154 | studentList = data; |
| 153 | int position = 0; | 155 | int position = 0; |
| 154 | String stuId = getCurrentStuId(); | 156 | String stuId = getCurrentStuId(); |
| 155 | for (int i = 0; i < data.size(); i++) { | 157 | for (int i = 0; i < data.size(); i++) { |
| 156 | if (data.get(i).stuId.equals(stuId)) { | 158 | if (data.get(i).stuId.equals(stuId)) { |
| 157 | position = i; | 159 | position = i; |
| 158 | break; | 160 | break; |
| 159 | } | 161 | } |
| 160 | } | 162 | } |
| 161 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); | 163 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); |
| 162 | binding.spStudent.setSelection(position); | 164 | binding.spStudent.setSelection(position); |
| 163 | } | 165 | } |
| 164 | }); | 166 | }); |
| 165 | } | 167 | } |
| 166 | 168 | ||
| 167 | @SuppressLint("CheckResult") | 169 | @SuppressLint("CheckResult") |
| 168 | private void getGrade() { | 170 | private void getGrade() { |
| 169 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) | 171 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) |
| 170 | .subscribeOn(Schedulers.io()) | 172 | .subscribeOn(Schedulers.io()) |
| 171 | .observeOn(AndroidSchedulers.mainThread()) | 173 | .observeOn(AndroidSchedulers.mainThread()) |
| 172 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 174 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
| 173 | .map(ResponseResult::getData) | 175 | .map(ResponseResult::getData) |
| 174 | .firstOrError() | 176 | .firstOrError() |
| 175 | .subscribe((data, th) -> { | 177 | .subscribe((data, th) -> { |
| 176 | if (th != null) th.printStackTrace(); | 178 | if (th != null) th.printStackTrace(); |
| 177 | if (data != null && data.size() > 0) { | 179 | if (data != null && data.size() > 0) { |
| 178 | gradeAndSubjectList = data; | 180 | gradeAndSubjectList = data; |
| 179 | List<String> grades = new ArrayList<>(); | 181 | List<String> grades = new ArrayList<>(); |
| 180 | for (GradeAndSubject it: data) { | 182 | for (GradeAndSubject it: data) { |
| 181 | grades.add(it.getGrade().getGrade()); | 183 | grades.add(it.getGrade().getGrade()); |
| 182 | } | 184 | } |
| 183 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); | 185 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); |
| 184 | } | 186 | } |
| 185 | getStudents(); | 187 | getStudents(); |
| 186 | }); | 188 | }); |
| 187 | } | 189 | } |
| 188 | 190 | ||
| 189 | private void refreshSubjects(int gradePosition) { | 191 | private void refreshSubjects(int gradePosition) { |
| 190 | if (gradeAndSubjectList == null) return; | 192 | if (gradeAndSubjectList == null) return; |
| 191 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); | 193 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); |
| 192 | List<String> subjects = new ArrayList<>(); | 194 | List<String> subjects = new ArrayList<>(); |
| 193 | for (Subject s: subjectList) { | 195 | for (Subject s: subjectList) { |
| 194 | subjects.add(s.getSubject()); | 196 | subjects.add(s.getSubject()); |
| 195 | } | 197 | } |
| 196 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 198 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 197 | @SuppressLint("SetTextI18n") | 199 | @SuppressLint("SetTextI18n") |
| 198 | @Override | 200 | @Override |
| 199 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 201 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 200 | subject = subjects.get(position); | 202 | subject = subjects.get(position); |
| 201 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 203 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
| 202 | } | 204 | } |
| 203 | @Override | 205 | @Override |
| 204 | public void onNothingSelected(AdapterView<?> parent) { | 206 | public void onNothingSelected(AdapterView<?> parent) { |
| 205 | } | 207 | } |
| 206 | }); | 208 | }); |
| 207 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); | 209 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 210 | @SuppressLint("CheckResult") | 212 | @SuppressLint("CheckResult") |
| 211 | public void uploadImage(String name) { | 213 | public void uploadImage(String name) { |
| 212 | activity.showLoadingDialog("上传作业中..."); | 214 | activity.showLoadingDialog("上传作业中..."); |
| 213 | Observable.fromIterable(images) | 215 | Observable.fromIterable(images) |
| 214 | .map(path -> { | 216 | .map(path -> { |
| 215 | int index = images.indexOf(path); | 217 | int index = images.indexOf(path); |
| 216 | return new Pair<>(index, path); | 218 | return new Pair<>(index, path); |
| 217 | }) | 219 | }) |
| 218 | .subscribeOn(Schedulers.io()) | 220 | .subscribeOn(Schedulers.io()) |
| 219 | .flatMap(pair -> { | 221 | .flatMap(pair -> { |
| 220 | int index = pair.first; | 222 | int index = pair.first; |
| 221 | String path = pair.second; | 223 | String path = pair.second; |
| 222 | File file = new File(path); | 224 | File file = new File(path); |
| 223 | String id = file.getName().substring(0, file.getName().lastIndexOf(".")); | 225 | String id = file.getName().substring(0, file.getName().lastIndexOf(".")); |
| 224 | return Observable.just(file) | 226 | return Observable.just(file) |
| 225 | .map(var -> { | 227 | .map(var -> { |
| 226 | BaiduInput baiduInput = NetWorks.inputImage(path, id).blockingGet(); | 228 | BaiduInput baiduInput = NetWorks.inputImage(path, id).blockingGet(); |
| 227 | if (baiduInput.getError_code() != null) { | 229 | if (baiduInput.getError_code() != null) { |
| 228 | throw new RuntimeException("图片入库失败"); | 230 | throw new RuntimeException("图片入库失败"); |
| 229 | } else { | 231 | } else { |
| 230 | return baiduInput; | 232 | return baiduInput; |
| 231 | } | 233 | } |
| 232 | }) | 234 | }) |
| 233 | .map(var -> NetWorks.uploadImage(path, id).blockingGet()) | 235 | .map(var -> NetWorks.uploadImage(path, id).blockingGet()) |
| 234 | .map(var -> { | 236 | .map(var -> { |
| 235 | Map<String, Object> map = new HashMap<>(); | 237 | Map<String, Object> map = new HashMap<>(); |
| 236 | map.put("brief", id); | 238 | map.put("brief", id); |
| 237 | map.put("sort", index); | 239 | map.put("sort", index); |
| 238 | return map; | 240 | return map; |
| 239 | }); | 241 | }); |
| 240 | }, 2) | 242 | }, 2) |
| 241 | .toList() | 243 | .toList() |
| 242 | .map(list -> { | 244 | .map(list -> { |
| 243 | List<String> stuIds = new ArrayList<>(); | 245 | List<String> stuIds = new ArrayList<>(); |
| 244 | stuIds.add(student.stuId); | 246 | stuIds.add(student.stuId); |
| 245 | String userId = NetWorks.getUserId(); | 247 | String userId = NetWorks.getUserId(); |
| 246 | 248 | ||
| 247 | Map<String, Object> map = new HashMap<>(); | 249 | Map<String, Object> map = new HashMap<>(); |
| 248 | map.put("name", name); | 250 | map.put("name", name); |
| 249 | map.put("grade", grade); | 251 | map.put("grade", grade); |
| 250 | map.put("term", term); | 252 | map.put("term", term); |
| 251 | map.put("subject", subject); | 253 | map.put("subject", subject); |
| 252 | map.put("userId", userId); | 254 | map.put("userId", userId); |
| 253 | map.put("stuIds", stuIds); | 255 | map.put("stuIds", stuIds); |
| 254 | map.put("briefList", list); | 256 | map.put("briefList", list); |
| 255 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); | 257 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
| 256 | map.put("uploadTime", format.format(uploadTime)); | 258 | map.put("uploadTime", format.format(uploadTime)); |
| 257 | return map; | 259 | return map; |
| 258 | }) | 260 | }) |
| 259 | .flatMap(body -> { | 261 | .flatMap(body -> { |
| 260 | return NetWorks.service_url.uploadHomework(NetWorks.getHeader(), body); | 262 | return NetWorks.service_url.uploadHomework(NetWorks.getHeader(), body); |
| 261 | }) | 263 | }) |
| 262 | .observeOn(AndroidSchedulers.mainThread()) | 264 | .observeOn(AndroidSchedulers.mainThread()) |
| 263 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 265 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
| 264 | .subscribe((response, th) -> { | 266 | .subscribe((response, th) -> { |
| 265 | if (th != null) th.printStackTrace(); | 267 | if (th != null) th.printStackTrace(); |
| 266 | if (response != null && response.getSuccess()) { | 268 | if (response != null && response.getSuccess()) { |
| 267 | activity.cancelLoadingDialog(); | 269 | activity.cancelLoadingDialog(); |
| 268 | dismiss(); | 270 | dismiss(); |
| 269 | if (callback != null) callback.invoke(student); | 271 | if (callback != null) callback.invoke(student); |
| 270 | } else { | 272 | } else { |
| 271 | activity.loadFail("上传作业失败"); | 273 | activity.loadFail("上传作业失败"); |
| 272 | } | 274 | } |
| 273 | }) | 275 | }) |
| 274 | ; | 276 | ; |
| 275 | } | 277 | } |
| 276 | 278 | ||
| 277 | @NonNull | 279 | @NonNull |
| 278 | @Override | 280 | @Override |
| 279 | public DialogAddHomeworkBinding getBinding() { | 281 | public DialogAddHomeworkBinding getBinding() { |
| 280 | return DialogAddHomeworkBinding.inflate(getLayoutInflater()); | 282 | return DialogAddHomeworkBinding.inflate(getLayoutInflater()); |
| 281 | } | 283 | } |
| 282 | } | 284 | } |
| 283 | 285 |
app/src/main/res/layout/dialog_add_homework.xml
| 1 | <FrameLayout | 1 | <FrameLayout |
| 2 | xmlns:android="http://schemas.android.com/apk/res/android" | 2 | xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | xmlns:app="http://schemas.android.com/apk/res-auto" | 3 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 4 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
| 5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
| 6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
| 7 | tools:ignore="HardcodedText,ContentDescription,UselessParent" > | 7 | tools:ignore="HardcodedText,ContentDescription,UselessParent" > |
| 8 | 8 | ||
| 9 | <LinearLayout | 9 | <LinearLayout |
| 10 | android:orientation="vertical" | 10 | android:orientation="vertical" |
| 11 | android:background="@drawable/shape_radius_top_10" | 11 | android:background="@drawable/shape_radius_top_10" |
| 12 | android:layout_marginTop="80dp" | 12 | android:layout_marginTop="80dp" |
| 13 | android:layout_width="match_parent" | 13 | android:layout_width="match_parent" |
| 14 | android:layout_height="match_parent"> | 14 | android:layout_height="match_parent"> |
| 15 | 15 | ||
| 16 | <FrameLayout | 16 | <FrameLayout |
| 17 | android:layout_marginTop="8dp" | 17 | android:layout_marginTop="8dp" |
| 18 | android:layout_marginBottom="-12dp" | 18 | android:layout_marginBottom="8dp" |
| 19 | android:layout_width="match_parent" | 19 | android:layout_width="match_parent" |
| 20 | android:layout_height="wrap_content"> | 20 | android:layout_height="wrap_content"> |
| 21 | 21 | ||
| 22 | <TextView | 22 | <TextView |
| 23 | android:id="@+id/tvTitle" | 23 | android:id="@+id/tvTitle" |
| 24 | android:text="录入作业" | 24 | android:text="录入作业" |
| 25 | android:textSize="17sp" | 25 | android:textSize="17sp" |
| 26 | android:textStyle="bold" | 26 | android:textStyle="bold" |
| 27 | android:layout_gravity="center" | 27 | android:layout_gravity="center" |
| 28 | android:textColor="@color/text_title" | 28 | android:textColor="@color/text_title" |
| 29 | android:layout_width="wrap_content" | 29 | android:layout_width="wrap_content" |
| 30 | android:layout_height="wrap_content" /> | 30 | android:layout_height="wrap_content" /> |
| 31 | 31 | ||
| 32 | <ImageView | 32 | <ImageView |
| 33 | android:id="@+id/btnClose" | 33 | android:id="@+id/btnClose" |
| 34 | android:padding="12dp" | 34 | android:padding="12dp" |
| 35 | android:src="@mipmap/ic_close" | 35 | android:src="@mipmap/ic_close" |
| 36 | android:layout_gravity="end|center_vertical" | 36 | android:layout_gravity="end|center_vertical" |
| 37 | android:layout_width="35dp" | 37 | android:layout_width="35dp" |
| 38 | android:layout_height="35dp" /> | 38 | android:layout_height="35dp" /> |
| 39 | </FrameLayout> | 39 | </FrameLayout> |
| 40 | 40 | ||
| 41 | <TextView | 41 | <androidx.core.widget.NestedScrollView |
| 42 | android:id="@+id/tvStu" | ||
| 43 | android:layout_marginTop="20dp" | ||
| 44 | android:layout_width="wrap_content" | ||
| 45 | android:layout_height="wrap_content" | ||
| 46 | android:layout_marginHorizontal="15dp" | ||
| 47 | android:text="学生" | ||
| 48 | android:textColor="@color/text_title" | ||
| 49 | android:textSize="14sp" | ||
| 50 | android:textStyle="bold" /> | ||
| 51 | |||
| 52 | <androidx.appcompat.widget.AppCompatSpinner | ||
| 53 | android:id="@+id/spStudent" | ||
| 54 | style="@style/customSpinnerStyle" | ||
| 55 | android:layout_width="match_parent" | 42 | android:layout_width="match_parent" |
| 56 | android:layout_height="40dp" | 43 | android:layout_height="match_parent"> |
| 57 | android:layout_marginTop="10dp" | 44 | <LinearLayout |
| 58 | android:layout_marginHorizontal="15dp" | 45 | android:orientation="vertical" |
| 59 | android:background="@drawable/selector_for_input_spinner" | 46 | android:layout_marginTop="-20dp" |
| 60 | android:popupBackground="@drawable/shape_for_input_spinner" | 47 | android:layout_width="match_parent" |
| 61 | android:scrollbars="none" /> | 48 | android:layout_height="wrap_content"> |
| 62 | 49 | ||
| 63 | <TextView | 50 | <TextView |
| 64 | android:layout_width="wrap_content" | 51 | android:id="@+id/tvStu" |
| 65 | android:layout_height="wrap_content" | 52 | android:layout_marginTop="20dp" |
| 66 | android:layout_marginHorizontal="15dp" | 53 | android:layout_width="wrap_content" |
| 67 | android:layout_marginTop="20dp" | 54 | android:layout_height="wrap_content" |
| 68 | android:text="年级" | 55 | android:layout_marginHorizontal="15dp" |
| 69 | android:textColor="@color/text_title" | 56 | android:text="学生" |
| 70 | android:textSize="14sp" | 57 | android:textColor="@color/text_title" |
| 71 | android:textStyle="bold" /> | 58 | android:textSize="14sp" |
| 72 | 59 | android:textStyle="bold" /> | |
| 73 | <androidx.appcompat.widget.AppCompatSpinner | 60 | |
| 74 | android:id="@+id/spGrade" | 61 | <androidx.appcompat.widget.AppCompatSpinner |
| 75 | style="@style/customSpinnerStyle" | 62 | android:id="@+id/spStudent" |
| 76 | android:layout_width="match_parent" | 63 | style="@style/customSpinnerStyle" |
| 77 | android:layout_height="40dp" | 64 | android:layout_width="match_parent" |
| 78 | android:layout_marginTop="10dp" | 65 | android:layout_height="40dp" |
| 79 | android:layout_marginHorizontal="15dp" | 66 | android:layout_marginTop="10dp" |
| 80 | android:background="@drawable/selector_for_input_spinner" | 67 | android:layout_marginHorizontal="15dp" |
| 81 | android:popupBackground="@drawable/shape_for_input_spinner" | 68 | android:background="@drawable/selector_for_input_spinner" |
| 82 | android:scrollbars="none" /> | 69 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 83 | 70 | android:scrollbars="none" /> | |
| 84 | <TextView | 71 | |
| 85 | android:layout_width="wrap_content" | 72 | <TextView |
| 86 | android:layout_height="wrap_content" | 73 | android:layout_width="wrap_content" |
| 87 | android:layout_marginHorizontal="15dp" | 74 | android:layout_height="wrap_content" |
| 88 | android:layout_marginTop="20dp" | 75 | android:layout_marginHorizontal="15dp" |
| 89 | android:text="学期" | 76 | android:layout_marginTop="20dp" |
| 90 | android:textColor="@color/text_title" | 77 | android:text="年级" |
| 91 | android:textSize="14sp" | 78 | android:textColor="@color/text_title" |
| 92 | android:textStyle="bold" /> | 79 | android:textSize="14sp" |
| 93 | 80 | android:textStyle="bold" /> | |
| 94 | <androidx.appcompat.widget.AppCompatSpinner | 81 | |
| 95 | android:id="@+id/spTerm" | 82 | <androidx.appcompat.widget.AppCompatSpinner |
| 96 | style="@style/customSpinnerStyle" | 83 | android:id="@+id/spGrade" |
| 97 | android:layout_width="match_parent" | 84 | style="@style/customSpinnerStyle" |
| 98 | android:layout_height="40dp" | 85 | android:layout_width="match_parent" |
| 99 | android:layout_marginTop="10dp" | 86 | android:layout_height="40dp" |
| 100 | android:layout_marginHorizontal="15dp" | 87 | android:layout_marginTop="10dp" |
| 101 | android:background="@drawable/selector_for_input_spinner" | 88 | android:layout_marginHorizontal="15dp" |
| 102 | android:entries="@array/grade_array" | 89 | android:background="@drawable/selector_for_input_spinner" |
| 103 | android:popupBackground="@drawable/shape_for_input_spinner" | 90 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 104 | android:scrollbars="none" /> | 91 | android:scrollbars="none" /> |
| 105 | 92 | ||
| 106 | <TextView | 93 | <TextView |
| 107 | android:layout_width="wrap_content" | 94 | android:layout_width="wrap_content" |
| 108 | android:layout_height="wrap_content" | 95 | android:layout_height="wrap_content" |
| 109 | android:layout_marginHorizontal="15dp" | 96 | android:layout_marginHorizontal="15dp" |
| 110 | android:layout_marginTop="20dp" | 97 | android:layout_marginTop="20dp" |
| 111 | android:text="科目" | 98 | android:text="学期" |
| 112 | android:textColor="@color/text_title" | 99 | android:textColor="@color/text_title" |
| 113 | android:textSize="14sp" | 100 | android:textSize="14sp" |
| 114 | android:textStyle="bold" /> | 101 | android:textStyle="bold" /> |
| 115 | 102 | ||
| 116 | <androidx.appcompat.widget.AppCompatSpinner | 103 | <androidx.appcompat.widget.AppCompatSpinner |
| 117 | android:id="@+id/spSubject" | 104 | android:id="@+id/spTerm" |
| 118 | style="@style/customSpinnerStyle" | 105 | style="@style/customSpinnerStyle" |
| 119 | android:layout_width="match_parent" | 106 | android:layout_width="match_parent" |
| 120 | android:layout_height="40dp" | 107 | android:layout_height="40dp" |
| 121 | android:layout_marginTop="10dp" | 108 | android:layout_marginTop="10dp" |
| 122 | android:layout_marginHorizontal="15dp" | 109 | android:layout_marginHorizontal="15dp" |
| 123 | android:background="@drawable/selector_for_input_spinner" | 110 | android:background="@drawable/selector_for_input_spinner" |
| 124 | android:popupBackground="@drawable/shape_for_input_spinner" | 111 | android:entries="@array/grade_array" |
| 125 | android:scrollbars="none" /> | 112 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 126 | 113 | android:scrollbars="none" /> | |
| 127 | <TextView | 114 | |
| 128 | android:layout_width="wrap_content" | 115 | <TextView |
| 129 | android:layout_height="wrap_content" | 116 | android:layout_width="wrap_content" |
| 130 | android:layout_marginHorizontal="15dp" | 117 | android:layout_height="wrap_content" |
| 131 | android:layout_marginTop="20dp" | 118 | android:layout_marginHorizontal="15dp" |
| 132 | android:text="日期" | 119 | android:layout_marginTop="20dp" |
| 133 | android:textColor="@color/text_title" | 120 | android:text="科目" |
| 134 | android:textSize="14sp" | 121 | android:textColor="@color/text_title" |
| 135 | android:textStyle="bold" /> | 122 | android:textSize="14sp" |
| 136 | 123 | android:textStyle="bold" /> | |
| 137 | <TextView | 124 | |
| 138 | android:id="@+id/tvDate" | 125 | <androidx.appcompat.widget.AppCompatSpinner |
| 139 | tools:text="2024-09-18" | 126 | android:id="@+id/spSubject" |
| 140 | android:textSize="16sp" | 127 | style="@style/customSpinnerStyle" |
| 141 | android:textColor="#333" | 128 | android:layout_width="match_parent" |
| 142 | android:gravity="center_vertical" | 129 | android:layout_height="40dp" |
| 143 | android:paddingHorizontal="16dp" | 130 | android:layout_marginTop="10dp" |
| 144 | android:layout_width="match_parent" | 131 | android:layout_marginHorizontal="15dp" |
| 145 | android:layout_height="40dp" | 132 | android:background="@drawable/selector_for_input_spinner" |
| 146 | android:layout_marginTop="10dp" | 133 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 147 | android:layout_marginHorizontal="15dp" | 134 | android:scrollbars="none" /> |
| 148 | android:background="@drawable/selector_for_input_spinner" /> | 135 | |
| 149 | 136 | <TextView | |
| 150 | <TextView | 137 | android:layout_width="wrap_content" |
| 151 | android:layout_width="wrap_content" | 138 | android:layout_height="wrap_content" |
| 152 | android:layout_height="wrap_content" | 139 | android:layout_marginHorizontal="15dp" |
| 153 | android:layout_marginHorizontal="15dp" | 140 | android:layout_marginTop="20dp" |
| 154 | android:layout_marginTop="20dp" | 141 | android:text="日期" |
| 155 | android:text="作业名称" | 142 | android:textColor="@color/text_title" |
| 156 | android:textColor="@color/text_title" | 143 | android:textSize="14sp" |
| 157 | android:textSize="14sp" | 144 | android:textStyle="bold" /> |
| 158 | android:textStyle="bold" /> | 145 | |
| 159 | 146 | <TextView | |
| 160 | <EditText | 147 | android:id="@+id/tvDate" |
| 161 | android:id="@+id/etName" | 148 | tools:text="2024-09-18" |
| 162 | android:layout_width="match_parent" | 149 | android:textSize="16sp" |
| 163 | android:layout_height="40dp" | 150 | android:textColor="#333" |
| 164 | android:layout_marginTop="10dp" | 151 | android:gravity="center_vertical" |
| 165 | android:layout_marginHorizontal="15dp" | 152 | android:paddingHorizontal="16dp" |
| 166 | android:background="@drawable/shape_for_input_spinner" | 153 | android:layout_width="match_parent" |
| 167 | android:fillViewport="true" | 154 | android:layout_height="40dp" |
| 168 | android:gravity="center_vertical" | 155 | android:layout_marginTop="10dp" |
| 169 | android:maxLength="50" | 156 | android:layout_marginHorizontal="15dp" |
| 170 | android:paddingHorizontal="16dp" | 157 | android:background="@drawable/selector_for_input_spinner" /> |
| 171 | android:textColor="@color/text_title" | 158 | |
| 172 | android:textSize="13sp" | 159 | <TextView |
| 173 | android:inputType="text" | 160 | android:layout_width="wrap_content" |
| 174 | tools:ignore="Autofill,LabelFor" /> | 161 | android:layout_height="wrap_content" |
| 175 | 162 | android:layout_marginHorizontal="15dp" | |
| 176 | <Space style="@style/empty_space"/> | 163 | android:layout_marginTop="20dp" |
| 177 | <TextView | 164 | android:text="作业名称" |
| 178 | android:id="@+id/btnConfirm" | 165 | android:textColor="@color/text_title" |
| 179 | android:text="确认录入" | 166 | android:textSize="14sp" |
| 180 | android:gravity="center" | 167 | android:textStyle="bold" /> |
| 181 | android:textSize="16sp" | 168 | |
| 182 | android:textColor="@color/white" | 169 | <EditText |
| 183 | android:background="@drawable/shape_radius_5" | 170 | android:id="@+id/etName" |
| 184 | android:backgroundTint="#1C90F3" | 171 | android:layout_width="match_parent" |
| 185 | android:layout_gravity="center_horizontal" | 172 | android:layout_height="40dp" |
| 186 | android:layout_marginBottom="16dp" | 173 | android:layout_marginTop="10dp" |
| 187 | android:layout_width="224dp" | 174 | android:layout_marginHorizontal="15dp" |
| 188 | android:layout_height="36dp"/> | 175 | android:background="@drawable/shape_for_input_spinner" |
| 176 | android:fillViewport="true" | ||
| 177 | android:gravity="center_vertical" | ||
| 178 | android:maxLength="50" | ||
| 179 | android:paddingHorizontal="16dp" | ||
| 180 | android:textColor="@color/text_title" | ||
| 181 | android:textSize="13sp" | ||
| 182 | android:inputType="text" | ||
| 183 | tools:ignore="Autofill,LabelFor" /> | ||
| 184 | |||
| 185 | <TextView | ||
| 186 | android:id="@+id/btnConfirm" | ||
| 187 | android:text="确认录入" | ||
| 188 | android:gravity="center" |