Commit 8f79866a79a9fca7a458cab7406d755edbfe2004
1 parent
d454c09d63
Exists in
master
录入作业dialog
Showing
15 changed files
with
627 additions
and
48 deletions
Show diff stats
app/build.gradle
| ... | ... | @@ -82,4 +82,7 @@ dependencies { |
| 82 | 82 | // rx |
| 83 | 83 | implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") |
| 84 | 84 | implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") |
| 85 | + | |
| 86 | + implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") | |
| 87 | + implementation("com.contrarywind:Android-PickerView:4.1.9") | |
| 85 | 88 | } |
| 86 | 89 | \ No newline at end of file | ... | ... |
app/src/main/java/com/hjx/parent/ImageActivity.java
| 1 | 1 | package com.hjx.parent; |
| 2 | 2 | |
| 3 | +import android.annotation.SuppressLint; | |
| 3 | 4 | import android.app.Dialog; |
| 4 | 5 | import android.content.Intent; |
| 5 | 6 | import android.graphics.Bitmap; |
| ... | ... | @@ -23,8 +24,10 @@ import com.google.gson.Gson; |
| 23 | 24 | import com.google.gson.JsonObject; |
| 24 | 25 | import com.hjx.parent.adapter.ImageAdapter; |
| 25 | 26 | import com.hjx.parent.databinding.ActivityImageBinding; |
| 27 | +import com.hjx.parent.dialog.AddHomeworkDialog; | |
| 26 | 28 | import com.hjx.parent.dialog.ErrorInputDialog; |
| 27 | 29 | import com.hjx.parent.dialog.TipDialog; |
| 30 | +import com.hjx.parent.rx.BaseRxActivity; | |
| 28 | 31 | import com.prws.common.bean.CutPicBean; |
| 29 | 32 | import com.prws.common.bean.ImageBean; |
| 30 | 33 | import com.prws.common.bean.TopicBean; |
| ... | ... | @@ -43,18 +46,24 @@ import retrofit2.Call; |
| 43 | 46 | import retrofit2.Callback; |
| 44 | 47 | import retrofit2.Response; |
| 45 | 48 | |
| 46 | -public class ImageActivity extends BaseActivity<ActivityImageBinding> implements View.OnClickListener { | |
| 49 | +public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implements View.OnClickListener { | |
| 47 | 50 | |
| 48 | 51 | private List<String> images = new ArrayList<>(); |
| 49 | 52 | private ImageAdapter imageAdapter; |
| 50 | 53 | private List<ImageBean> list = new ArrayList<>(); |
| 51 | 54 | private String filePath; |
| 52 | 55 | |
| 56 | + private int type = 0; | |
| 57 | + private AddHomeworkDialog addHomeworkDialog; | |
| 58 | + | |
| 53 | 59 | @Override |
| 54 | 60 | public void initView(Bundle savedInstanceState) { |
| 61 | + type = getIntent().getIntExtra("type", 0); | |
| 62 | + binding.tvSave.setText(type == 0 ? "保存错题" : "录入题目"); | |
| 63 | + | |
| 55 | 64 | images = getIntent().getStringArrayListExtra("images"); |
| 56 | 65 | for (String s : images) { |
| 57 | - String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | |
| 66 | + String filepath = context.getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | |
| 58 | 67 | ImageBean imageBean = new ImageBean(); |
| 59 | 68 | Bitmap bitmap = BitmapUtils.getimage(s); |
| 60 | 69 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| ... | ... | @@ -250,6 +259,7 @@ public class ImageActivity extends BaseActivity<ActivityImageBinding> implements |
| 250 | 259 | return ActivityImageBinding.inflate(getLayoutInflater()); |
| 251 | 260 | } |
| 252 | 261 | |
| 262 | + @SuppressLint("SetTextI18n") | |
| 253 | 263 | public void refreshNum() { |
| 254 | 264 | int num = 0; |
| 255 | 265 | for (ImageBean imageBean : list) { |
| ... | ... | @@ -261,14 +271,15 @@ public class ImageActivity extends BaseActivity<ActivityImageBinding> implements |
| 261 | 271 | } |
| 262 | 272 | } |
| 263 | 273 | } |
| 274 | + String btnText = type == 0 ? "保存错题" : "录入题目"; | |
| 264 | 275 | if (num > 0) { |
| 265 | 276 | binding.tvSave.setEnabled(true); |
| 266 | 277 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); |
| 267 | - binding.tvSave.setText("保存错题(" + num + ")"); | |
| 278 | + binding.tvSave.setText(btnText + "(" + num + ")"); | |
| 268 | 279 | } else { |
| 269 | 280 | binding.tvSave.setEnabled(false); |
| 270 | 281 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); |
| 271 | - binding.tvSave.setText("保存错题"); | |
| 282 | + binding.tvSave.setText(btnText); | |
| 272 | 283 | } |
| 273 | 284 | } |
| 274 | 285 | |
| ... | ... | @@ -326,12 +337,23 @@ public class ImageActivity extends BaseActivity<ActivityImageBinding> implements |
| 326 | 337 | } |
| 327 | 338 | } |
| 328 | 339 | } |
| 329 | - ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); | |
| 330 | - dialog.show(); | |
| 340 | + save(topicBeans); | |
| 331 | 341 | break; |
| 332 | 342 | } |
| 333 | 343 | } |
| 334 | 344 | |
| 345 | + private void save(List<TopicBean> topicBeans) { | |
| 346 | + if (type == 0) { | |
| 347 | + ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); | |
| 348 | + dialog.show(); | |
| 349 | + } else { | |
| 350 | + if (addHomeworkDialog == null) { | |
| 351 | + addHomeworkDialog = new AddHomeworkDialog(this); | |
| 352 | + } | |
| 353 | + addHomeworkDialog.show(); | |
| 354 | + } | |
| 355 | + } | |
| 356 | + | |
| 335 | 357 | @Override |
| 336 | 358 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 337 | 359 | super.onActivityResult(requestCode, resultCode, data); | ... | ... |
app/src/main/java/com/hjx/parent/dialog/AddHomeworkDialog.java
| ... | ... | @@ -0,0 +1,191 @@ |
| 1 | +package com.hjx.parent.dialog; | |
| 2 | + | |
| 3 | +import android.annotation.SuppressLint; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.view.View; | |
| 6 | +import android.widget.AdapterView; | |
| 7 | +import android.widget.ArrayAdapter; | |
| 8 | + | |
| 9 | +import androidx.annotation.NonNull; | |
| 10 | + | |
| 11 | +import com.bigkoo.pickerview.builder.TimePickerBuilder; | |
| 12 | +import com.bigkoo.pickerview.listener.OnTimeSelectListener; | |
| 13 | +import com.bigkoo.pickerview.view.TimePickerView; | |
| 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.rx.ILifecycleActivity; | |
| 19 | +import com.prws.common.bean.GradeAndSubject; | |
| 20 | +import com.prws.common.bean.ResponseResult; | |
| 21 | +import com.prws.common.bean.Student; | |
| 22 | +import com.prws.common.bean.Subject; | |
| 23 | +import com.prws.common.net.NetWorks; | |
| 24 | +import com.prws.common.utils.SharedPreferencesUtil; | |
| 25 | +import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | |
| 26 | + | |
| 27 | +import java.text.SimpleDateFormat; | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.Date; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.Locale; | |
| 32 | + | |
| 33 | +import io.reactivex.android.schedulers.AndroidSchedulers; | |
| 34 | +import io.reactivex.schedulers.Schedulers; | |
| 35 | + | |
| 36 | +public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ | |
| 37 | + private final ILifecycleActivity activity; | |
| 38 | + | |
| 39 | + String stuId; | |
| 40 | + | |
| 41 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); | |
| 42 | + List<Student> studentList; | |
| 43 | + List<GradeAndSubject> gradeAndSubjectList; | |
| 44 | + | |
| 45 | + Student student; | |
| 46 | + String grade; | |
| 47 | + String term; | |
| 48 | + String subject; | |
| 49 | + Date uploadTime = new Date(); | |
| 50 | + | |
| 51 | + public AddHomeworkDialog(ILifecycleActivity context) { | |
| 52 | + super((Context) context); | |
| 53 | + activity = context; | |
| 54 | + } | |
| 55 | + | |
| 56 | + @SuppressLint("SetTextI18n") | |
| 57 | + @Override | |
| 58 | + public void initView() { | |
| 59 | + binding.btnClose.setOnClickListener(v -> dismiss()); | |
| 60 | + stuId = getCurrentStuId(); | |
| 61 | + binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 62 | + @Override | |
| 63 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 64 | + student = studentList.get(position); | |
| 65 | + if (gradeAndSubjectList == null) return; | |
| 66 | + int p = 0; | |
| 67 | + for (GradeAndSubject it: gradeAndSubjectList) { | |
| 68 | + if (it.getGrade().getGrade().equals(student.grade)) { | |
| 69 | + p = gradeAndSubjectList.indexOf(it); | |
| 70 | + break; | |
| 71 | + } | |
| 72 | + } | |
| 73 | + binding.spGrade.setSelection(p); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 78 | + } | |
| 79 | + }); | |
| 80 | + binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 81 | + @Override | |
| 82 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 83 | + term = getContext().getResources().getStringArray(R.array.grade_array)[position]; | |
| 84 | + } | |
| 85 | + @Override | |
| 86 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 87 | + } | |
| 88 | + }); | |
| 89 | + binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 90 | + @Override | |
| 91 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 92 | + grade = gradeAndSubjectList.get(position).getGrade().getGrade(); | |
| 93 | + refreshSubjects(position); | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Override | |
| 97 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 98 | + } | |
| 99 | + }); | |
| 100 | + | |
| 101 | + binding.tvDate.setText(dateFormat.format(uploadTime)); | |
| 102 | + binding.tvDate.setOnClickListener(v -> { | |
| 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}).isDialog(true).build().show(); | |
| 108 | + }); | |
| 109 | + | |
| 110 | + getGrade(); | |
| 111 | + } | |
| 112 | + | |
| 113 | + private String getCurrentStuId() { | |
| 114 | + String student = (String) SharedPreferencesUtil.getData("student", ""); | |
| 115 | + StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | |
| 116 | + return studentBean.getStuId(); | |
| 117 | + } | |
| 118 | + | |
| 119 | + @SuppressLint("CheckResult") | |
| 120 | + private void getStudents() { | |
| 121 | + NetWorks.listStudent() | |
| 122 | + .subscribeOn(Schedulers.io()) | |
| 123 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 124 | + .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | |
| 125 | + .map(ResponseResult::getData) | |
| 126 | + .subscribe((data, th) -> { | |
| 127 | + if (th != null) th.printStackTrace(); | |
| 128 | + if (data != null && data.size() > 0) { | |
| 129 | + studentList = data; | |
| 130 | + int position = 0; | |
| 131 | + for (int i = 0; i < data.size(); i++) { | |
| 132 | + if (data.get(i).stuId.equals(stuId)) { | |
| 133 | + position = i; | |
| 134 | + break; | |
| 135 | + } | |
| 136 | + } | |
| 137 | + binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); | |
| 138 | + binding.spStudent.setSelection(position); | |
| 139 | + } | |
| 140 | + }); | |
| 141 | + } | |
| 142 | + | |
| 143 | + @SuppressLint("CheckResult") | |
| 144 | + private void getGrade() { | |
| 145 | + NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) | |
| 146 | + .subscribeOn(Schedulers.io()) | |
| 147 | + .observeOn(AndroidSchedulers.mainThread()) | |
| 148 | + .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | |
| 149 | + .map(ResponseResult::getData) | |
| 150 | + .firstOrError() | |
| 151 | + .subscribe((data, th) -> { | |
| 152 | + if (th != null) th.printStackTrace(); | |
| 153 | + if (data != null && data.size() > 0) { | |
| 154 | + gradeAndSubjectList = data; | |
| 155 | + List<String> grades = new ArrayList<>(); | |
| 156 | + for (GradeAndSubject it: data) { | |
| 157 | + grades.add(it.getGrade().getGrade()); | |
| 158 | + } | |
| 159 | + binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); | |
| 160 | + } | |
| 161 | + getStudents(); | |
| 162 | + }); | |
| 163 | + } | |
| 164 | + | |
| 165 | + private void refreshSubjects(int gradePosition) { | |
| 166 | + if (gradeAndSubjectList == null) return; | |
| 167 | + List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); | |
| 168 | + List<String> subjects = new ArrayList<>(); | |
| 169 | + for (Subject s: subjectList) { | |
| 170 | + subjects.add(s.getSubject()); | |
| 171 | + } | |
| 172 | + binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
| 173 | + @SuppressLint("SetTextI18n") | |
| 174 | + @Override | |
| 175 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
| 176 | + subject = subjects.get(position); | |
| 177 | + binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | |
| 178 | + } | |
| 179 | + @Override | |
| 180 | + public void onNothingSelected(AdapterView<?> parent) { | |
| 181 | + } | |
| 182 | + }); | |
| 183 | + binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); | |
| 184 | + } | |
| 185 | + | |
| 186 | + @NonNull | |
| 187 | + @Override | |
| 188 | + public DialogAddHomeworkBinding getBinding() { | |
| 189 | + return DialogAddHomeworkBinding.inflate(getLayoutInflater()); | |
| 190 | + } | |
| 191 | +} | ... | ... |
app/src/main/java/com/hjx/parent/dialog/BaseDialog.java
| ... | ... | @@ -0,0 +1,72 @@ |
| 1 | +package com.hjx.parent.dialog; | |
| 2 | + | |
| 3 | +import android.app.AlertDialog; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.view.ViewGroup; | |
| 7 | +import android.view.Window; | |
| 8 | +import android.view.WindowManager; | |
| 9 | + | |
| 10 | +import androidx.annotation.NonNull; | |
| 11 | +import androidx.viewbinding.ViewBinding; | |
| 12 | + | |
| 13 | +import com.hjx.parent.R; | |
| 14 | + | |
| 15 | + | |
| 16 | +public abstract class BaseDialog<VB extends ViewBinding> extends AlertDialog { | |
| 17 | + | |
| 18 | + public BaseDialog(Context context) { | |
| 19 | + this(context, R.style.BaseDialog); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public BaseDialog(Context context, int themeResId) { | |
| 23 | + super(context, themeResId); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public VB binding; | |
| 27 | + private boolean isDialogCreated = false; | |
| 28 | + public boolean isDialogCreated() { | |
| 29 | + return isDialogCreated; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public void onCreate(Bundle savedInstanceState) { | |
| 33 | + super.onCreate(savedInstanceState); | |
| 34 | + binding = getBinding(); | |
| 35 | + setContentView(binding.getRoot()); | |
| 36 | + Window window = getWindow(); | |
| 37 | + if (window != null) { | |
| 38 | + setWindowsLayout(window); | |
| 39 | + window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); | |
| 40 | + } | |
| 41 | + | |
| 42 | + initView(); | |
| 43 | + isDialogCreated = true; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void onAttachedToWindow() { | |
| 47 | + super.onAttachedToWindow(); | |
| 48 | + onDialogStart(); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void onDetachedFromWindow() { | |
| 52 | + super.onDetachedFromWindow(); | |
| 53 | + onDialogStop(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setWindowsLayout(Window window) { | |
| 57 | + window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void initView() { | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void onDialogStart() { | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void onDialogStop() { | |
| 67 | + } | |
| 68 | + | |
| 69 | + @NonNull | |
| 70 | + public abstract VB getBinding(); | |
| 71 | + | |
| 72 | +} | ... | ... |
app/src/main/java/com/hjx/parent/fragment/ErrorFragment.java
| ... | ... | @@ -74,7 +74,6 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 74 | 74 | private int subject; |
| 75 | 75 | private ErrorAdapter errorAdapter; |
| 76 | 76 | private HomeworkAdapter homeworkAdapter; |
| 77 | - private int REQUEST_CODE_IMAGE = 123; | |
| 78 | 77 | private String filePath; |
| 79 | 78 | |
| 80 | 79 | @Override |
| ... | ... | @@ -105,31 +104,8 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 105 | 104 | getBinding().tvName.setText(name); |
| 106 | 105 | refreshStudent(); |
| 107 | 106 | getBinding().tvChoose.setOnClickListener(v -> startActivity(new Intent(getContext(), TeacherChooseActivity.class))); |
| 108 | - getBinding().rlTakePhoto.setOnClickListener(v -> { | |
| 109 | - if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | |
| 110 | - XXPermissions.with(getContext()) | |
| 111 | - // 申请多个权限 | |
| 112 | - .permission(Permission.CAMERA).request(new OnPermissionCallback() { | |
| 113 | - @Override | |
| 114 | - public void onGranted(List<String> permissions, boolean all) { | |
| 115 | - if (all) { | |
| 116 | - //开启扫码界面 | |
| 117 | - showButtonDialog(); | |
| 118 | - } else { | |
| 119 | - Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - @Override | |
| 124 | - public void onDenied(List<String> permissions, boolean never) { | |
| 125 | - XXPermissions.startPermissionActivity(getContext(), permissions); | |
| 126 | - } | |
| 127 | - }); | |
| 128 | - } else { | |
| 129 | - showButtonDialog(); | |
| 130 | - } | |
| 131 | - | |
| 132 | - }); | |
| 107 | + getBinding().rlTakePhoto.setOnClickListener(v -> takePhoto(0)); | |
| 108 | + getBinding().flEntryHomework.setOnClickListener(v -> takePhoto(1)); | |
| 133 | 109 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_subject, Arrays.asList(getResources().getStringArray(R.array.filter_subject))) { |
| 134 | 110 | @Override |
| 135 | 111 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| ... | ... | @@ -207,7 +183,32 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 207 | 183 | }); |
| 208 | 184 | } |
| 209 | 185 | |
| 210 | - private void showButtonDialog() { | |
| 186 | + private void takePhoto(int type) { | |
| 187 | + if (!XXPermissions.isGranted(getContext(), Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | |
| 188 | + XXPermissions.with(getContext()) | |
| 189 | + // 申请多个权限 | |
| 190 | + .permission(Permission.CAMERA).request(new OnPermissionCallback() { | |
| 191 | + @Override | |
| 192 | + public void onGranted(List<String> permissions, boolean all) { | |
| 193 | + if (all) { | |
| 194 | + //开启扫码界面 | |
| 195 | + showButtonDialog(type); | |
| 196 | + } else { | |
| 197 | + Toast.makeText(getContext(), "需要权限", Toast.LENGTH_SHORT).show(); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + | |
| 201 | + @Override | |
| 202 | + public void onDenied(List<String> permissions, boolean never) { | |
| 203 | + XXPermissions.startPermissionActivity(getContext(), permissions); | |
| 204 | + } | |
| 205 | + }); | |
| 206 | + } else { | |
| 207 | + showButtonDialog(type); | |
| 208 | + } | |
| 209 | + } | |
| 210 | + | |
| 211 | + private void showButtonDialog(int type) { | |
| 211 | 212 | MyButtomDialog dialog = new MyButtomDialog(getActivity(), R.style.BottomSheetDialog); |
| 212 | 213 | View bottomView = LayoutInflater.from(getActivity()).inflate(R.layout.bottom_sheet_layout, null); |
| 213 | 214 | dialog.setContentView(bottomView); |
| ... | ... | @@ -217,15 +218,14 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 217 | 218 | dialog.dismiss(); |
| 218 | 219 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 219 | 220 | //确保有相机来处理Intent |
| 220 | - filePath = getActivity().getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | |
| 221 | + filePath = requireActivity().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | |
| 221 | 222 | File photoFile = new File(filePath); |
| 222 | - if (photoFile != null) { | |
| 223 | - //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | |
| 224 | - Uri photoUri = FileProvider.getUriForFile(getActivity(), "com.hjx.parent.fileprovider", photoFile); | |
| 225 | - takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | |
| 226 | - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | |
| 227 | - startActivityForResult(takePictureIntent, REQUEST_CODE_IMAGE); | |
| 228 | - } | |
| 223 | + | |
| 224 | + //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | |
| 225 | + Uri photoUri = FileProvider.getUriForFile(requireActivity(), "com.hjx.parent.fileprovider", photoFile); | |
| 226 | + takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | |
| 227 | + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | |
| 228 | + startActivityForResult(takePictureIntent, type == 0 ? 0xA01 : 0xA02); | |
| 229 | 229 | } |
| 230 | 230 | }); |
| 231 | 231 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
| ... | ... | @@ -233,7 +233,7 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 233 | 233 | public void onClick(View view) { |
| 234 | 234 | dialog.dismiss(); |
| 235 | 235 | ImagePickerConfig imagePickerConfig = new ImagePickerConfig.Builder().provider(getActivity().getPackageName() + ".fileprovider").imageLoader(new GlideImageLoader()) //图片加载器 |
| 236 | - .iHandlerCallBack(new HandlerCallBack()) //图片选择器生命周期监听(直接打开摄像头时无效) | |
| 236 | + .iHandlerCallBack(new HandlerCallBack(type)) //图片选择器生命周期监听(直接打开摄像头时无效) | |
| 237 | 237 | .multiSelect(true) //是否多选 |
| 238 | 238 | .isShowCamera(false).isVideoPicker(false) //是否选择视频 默认false |
| 239 | 239 | .isImagePicker(true).imagePickerType(ImagePickerEnum.PHOTO_PICKER) //选择器打开类型 |
| ... | ... | @@ -316,6 +316,11 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
| 319 | + int type; | |
| 320 | + public HandlerCallBack(int type) { | |
| 321 | + this.type = type; | |
| 322 | + } | |
| 323 | + | |
| 319 | 324 | private String TAG = "---ImagePicker---"; |
| 320 | 325 | List<ImageInfo> photoList = new ArrayList<>(); |
| 321 | 326 | |
| ... | ... | @@ -338,12 +343,13 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 338 | 343 | @Override |
| 339 | 344 | public void onFinish(List<ImageInfo> selectImage) { |
| 340 | 345 | if (selectImage.size() == photoList.size()) { |
| 341 | - List<String> strings = new ArrayList<>(); | |
| 346 | + ArrayList<String> strings = new ArrayList<>(); | |
| 342 | 347 | Intent intent = new Intent(getActivity(), ImageActivity.class); |
| 343 | 348 | for (ImageInfo imageInfo : selectImage) { |
| 344 | 349 | strings.add(imageInfo.getPath()); |
| 345 | 350 | } |
| 346 | - intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | |
| 351 | + intent.putStringArrayListExtra("images", strings); | |
| 352 | + intent.putExtra("type", type); | |
| 347 | 353 | startActivity(intent); |
| 348 | 354 | } |
| 349 | 355 | } |
| ... | ... | @@ -357,14 +363,16 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
| 357 | 363 | @Override |
| 358 | 364 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 359 | 365 | super.onActivityResult(requestCode, resultCode, data); |
| 360 | - if (requestCode == REQUEST_CODE_IMAGE && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | |
| 366 | + if (resultCode != RESULT_OK) return; | |
| 367 | + if (requestCode == 0xA01 || requestCode == 0xA02 && !TextUtils.isEmpty(filePath)) { | |
| 361 | 368 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 362 | - String path = getContext().getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | |
| 369 | + String path = getContext().getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | |
| 363 | 370 | CommonUtil.saveBitmapToUri(b, path); |
| 364 | - List<String> strings = new ArrayList<>(); | |
| 371 | + ArrayList<String> strings = new ArrayList<>(); | |
| 365 | 372 | Intent intent = new Intent(getContext(), ImageActivity.class); |
| 366 | 373 | strings.add(path); |
| 367 | - intent.putStringArrayListExtra("images", (ArrayList<String>) strings); | |
| 374 | + intent.putStringArrayListExtra("images", strings); | |
| 375 | + intent.putExtra("type", requestCode == 0xA01 ? 0 : 1); | |
| 368 | 376 | startActivity(intent); |
| 369 | 377 | } |
| 370 | 378 | } | ... | ... |
app/src/main/res/drawable/ic_filter_down_black.png
427 Bytes
app/src/main/res/drawable/selector_for_input_spinner.xml
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item> | |
| 4 | + <shape> | |
| 5 | + <corners android:radius="6dp" /> | |
| 6 | + | |
| 7 | + <solid android:color="#F5F5F5" /> | |
| 8 | + </shape> | |
| 9 | + </item> | |
| 10 | + <item | |
| 11 | + android:width="10dp" | |
| 12 | + android:height="6dp" | |
| 13 | + android:end="15dp" | |
| 14 | + android:gravity="center_vertical|end" | |
| 15 | + android:drawable="@drawable/ic_filter_down_black"> | |
| 16 | + </item> | |
| 17 | +</layer-list> | ... | ... |
app/src/main/res/drawable/shape_for_input_spinner.xml
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <item | |
| 4 | + android:top="-3dp"> | |
| 5 | + <shape> | |
| 6 | + <corners android:radius="6dp" /> | |
| 7 | + <solid android:color="#F5F5F5" /> | |
| 8 | + </shape> | |
| 9 | + </item> | |
| 10 | +</layer-list> | |
| 0 | 11 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/shape_radius_5.xml
app/src/main/res/drawable/shape_radius_top_10.xml
| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + <corners android:topRightRadius="10dp" android:topLeftRadius="10dp"/> | |
| 4 | + <solid android:color="@color/white"/> | |
| 5 | +</shape> | |
| 0 | 6 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/dialog_add_homework.xml
| ... | ... | @@ -0,0 +1,185 @@ |
| 1 | +<FrameLayout | |
| 2 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | + xmlns:tools="http://schemas.android.com/tools" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="match_parent" | |
| 7 | + tools:ignore="HardcodedText,ContentDescription,UselessParent" > | |
| 8 | + | |
| 9 | + <LinearLayout | |
| 10 | + android:orientation="vertical" | |
| 11 | + android:background="@drawable/shape_radius_top_10" | |
| 12 | + android:layout_marginTop="80dp" | |
| 13 | + android:layout_width="match_parent" | |
| 14 | + android:layout_height="match_parent"> | |
| 15 | + | |
| 16 | + <FrameLayout | |
| 17 | + android:layout_marginVertical="8dp" | |
| 18 | + android:layout_width="match_parent" | |
| 19 | + android:layout_height="wrap_content"> | |
| 20 | + | |
| 21 | + <TextView | |
| 22 | + android:text="录入作业" | |
| 23 | + android:textSize="17sp" | |
| 24 | + android:textStyle="bold" | |
| 25 | + android:layout_gravity="center" | |
| 26 | + android:textColor="@color/text_title" | |
| 27 | + android:layout_width="wrap_content" | |
| 28 | + android:layout_height="wrap_content" /> | |
| 29 | + | |
| 30 | + <ImageView | |
| 31 | + android:id="@+id/btnClose" | |
| 32 | + android:padding="12dp" | |
| 33 | + android:src="@mipmap/ic_close" | |
| 34 | + android:layout_gravity="end|center_vertical" | |
| 35 | + android:layout_width="35dp" | |
| 36 | + android:layout_height="35dp" /> | |
| 37 | + </FrameLayout> | |
| 38 | + | |
| 39 | + <TextView | |
| 40 | + android:layout_width="wrap_content" | |
| 41 | + android:layout_height="wrap_content" | |
| 42 | + android:layout_marginHorizontal="15dp" | |
| 43 | + android:text="学生" | |
| 44 | + android:textColor="@color/text_title" | |
| 45 | + android:textSize="14sp" | |
| 46 | + android:textStyle="bold" /> | |
| 47 | + | |
| 48 | + <androidx.appcompat.widget.AppCompatSpinner | |
| 49 | + android:id="@+id/spStudent" | |
| 50 | + style="@style/customSpinnerStyle" | |
| 51 | + android:layout_width="match_parent" | |
| 52 | + android:layout_height="40dp" | |
| 53 | + android:layout_marginTop="10dp" | |
| 54 | + android:layout_marginHorizontal="15dp" | |
| 55 | + android:background="@drawable/selector_for_input_spinner" | |
| 56 | + android:popupBackground="@drawable/shape_for_input_spinner" | |
| 57 | + android:scrollbars="none" /> | |
| 58 | + | |
| 59 | + <TextView | |
| 60 | + android:layout_width="wrap_content" | |
| 61 | + android:layout_height="wrap_content" | |
| 62 | + android:layout_marginHorizontal="15dp" | |
| 63 | + android:layout_marginTop="20dp" | |
| 64 | + android:text="年级" | |
| 65 | + android:textColor="@color/text_title" | |
| 66 | + android:textSize="14sp" | |
| 67 | + android:textStyle="bold" /> | |
| 68 | + | |
| 69 | + <androidx.appcompat.widget.AppCompatSpinner | |
| 70 | + android:id="@+id/spGrade" | |
| 71 | + style="@style/customSpinnerStyle" | |
| 72 | + android:layout_width="match_parent" | |
| 73 | + android:layout_height="40dp" | |
| 74 | + android:layout_marginTop="10dp" | |
| 75 | + android:layout_marginHorizontal="15dp" | |
| 76 | + android:background="@drawable/selector_for_input_spinner" | |
| 77 | + android:popupBackground="@drawable/shape_for_input_spinner" | |
| 78 | + android:scrollbars="none" /> | |
| 79 | + | |
| 80 | + <TextView | |
| 81 | + android:layout_width="wrap_content" | |
| 82 | + android:layout_height="wrap_content" | |
| 83 | + android:layout_marginHorizontal="15dp" | |
| 84 | + android:layout_marginTop="20dp" | |
| 85 | + android:text="学期" | |
| 86 | + android:textColor="@color/text_title" | |
| 87 | + android:textSize="14sp" | |
| 88 | + android:textStyle="bold" /> | |
| 89 | + | |
| 90 | + <androidx.appcompat.widget.AppCompatSpinner | |
| 91 | + android:id="@+id/spTerm" | |
| 92 | + style="@style/customSpinnerStyle" | |
| 93 | + android:layout_width="match_parent" | |
| 94 | + android:layout_height="40dp" | |
| 95 | + android:layout_marginTop="10dp" | |
| 96 | + android:layout_marginHorizontal="15dp" | |
| 97 | + android:background="@drawable/selector_for_input_spinner" | |
| 98 | + android:entries="@array/grade_array" | |
| 99 | + android:popupBackground="@drawable/shape_for_input_spinner" | |
| 100 | + android:scrollbars="none" /> | |
| 101 | + | |
| 102 | + <TextView | |
| 103 | + android:layout_width="wrap_content" | |
| 104 | + android:layout_height="wrap_content" | |
| 105 | + android:layout_marginHorizontal="15dp" | |
| 106 | + android:layout_marginTop="20dp" | |
| 107 | + android:text="科目" | |
| 108 | + android:textColor="@color/text_title" | |
| 109 | + android:textSize="14sp" | |
| 110 | + android:textStyle="bold" /> | |
| 111 | + | |
| 112 | + <androidx.appcompat.widget.AppCompatSpinner | |
| 113 | + android:id="@+id/spSubject" | |
| 114 | + style="@style/customSpinnerStyle" | |
| 115 | + android:layout_width="match_parent" | |
| 116 | + android:layout_height="40dp" | |
| 117 | + android:layout_marginTop="10dp" | |
| 118 | + android:layout_marginHorizontal="15dp" | |
| 119 | + android:background="@drawable/selector_for_input_spinner" | |
| 120 | + android:popupBackground="@drawable/shape_for_input_spinner" | |
| 121 | + android:scrollbars="none" /> | |
| 122 | + | |
| 123 | + <TextView | |
| 124 | + android:layout_width="wrap_content" | |
| 125 | + android:layout_height="wrap_content" | |
| 126 | + android:layout_marginHorizontal="15dp" | |
| 127 | + android:layout_marginTop="20dp" | |
| 128 | + android:text="日期" | |
| 129 | + android:textColor="@color/text_title" | |
| 130 | + android:textSize="14sp" | |
| 131 | + android:textStyle="bold" /> | |
| 132 | + | |
| 133 | + <TextView | |
| 134 | + android:id="@+id/tvDate" | |
| 135 | + tools:text="2024-09-18" | |
| 136 | + android:textSize="16sp" | |
| 137 | + android:textColor="#333" | |
| 138 | + android:gravity="center_vertical" | |
| 139 | + android:paddingHorizontal="16dp" | |
| 140 | + android:layout_width="match_parent" | |
| 141 | + android:layout_height="40dp" | |
| 142 | + android:layout_marginTop="10dp" | |
| 143 | + android:layout_marginHorizontal="15dp" | |
| 144 | + android:background="@drawable/selector_for_input_spinner" /> | |
| 145 | + | |
| 146 | + <TextView | |
| 147 | + android:layout_width="wrap_content" | |
| 148 | + android:layout_height="wrap_content" | |
| 149 | + android:layout_marginHorizontal="15dp" | |
| 150 | + android:layout_marginTop="20dp" | |
| 151 | + android:text="作业名称" | |
| 152 | + android:textColor="@color/text_title" | |
| 153 | + android:textSize="14sp" | |
| 154 | + android:textStyle="bold" /> | |
| 155 | + | |
| 156 | + <EditText | |
| 157 | + android:id="@+id/etName" | |
| 158 | + android:layout_width="match_parent" | |
| 159 | + android:layout_height="40dp" | |
| 160 | + android:layout_marginTop="10dp" | |
| 161 | + android:layout_marginHorizontal="15dp" | |
| 162 | + android:background="@drawable/shape_for_input_spinner" | |
| 163 | + android:fillViewport="true" | |
| 164 | + android:gravity="center_vertical" | |
| 165 | + android:maxLength="50" | |
| 166 | + android:paddingHorizontal="16dp" | |
| 167 | + android:textColor="@color/text_title" | |
| 168 | + android:textSize="18sp" | |
| 169 | + android:inputType="text" | |
| 170 | + tools:ignore="Autofill,LabelFor" /> | |
| 171 | + | |
| 172 | + <Space style="@style/empty_space"/> | |
| 173 | + <TextView | |
| 174 | + android:text="确认录入" | |
| 175 | + android:gravity="center" | |
| 176 | + android:textSize="16sp" | |
| 177 | + android:textColor="@color/white" | |
| 178 | + android:background="@drawable/shape_radius_5" | |
| 179 | + android:backgroundTint="#1C90F3" | |
| 180 | + android:layout_gravity="center_horizontal" | |
| 181 | + android:layout_marginBottom="16dp" | |
| 182 | + android:layout_width="224dp" | |
| 183 | + android:layout_height="36dp"/> | |
| 184 | + </LinearLayout> | |
| 185 | +</FrameLayout> | |
| 0 | 186 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/item_spinner.xml
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + android:layout_width="match_parent" | |
| 3 | + android:layout_height="40dp" | |
| 4 | + android:ellipsize="marquee" | |
| 5 | + android:gravity="center_vertical" | |
| 6 | + android:paddingHorizontal="14dp" | |
| 7 | + android:singleLine="true" | |
| 8 | + android:textColor="@color/text_title" | |
| 9 | + android:textSize="13sp" /> | |
| 10 | + | ... | ... |
app/src/main/res/values/styles.xml
| ... | ... | @@ -59,4 +59,11 @@ |
| 59 | 59 | <item name="android:layout_weight">1</item> |
| 60 | 60 | </style> |
| 61 | 61 | |
| 62 | + | |
| 63 | + <style name="BaseDialog"> | |
| 64 | + <item name="android:background">@android:color/transparent</item> | |
| 65 | + <item name="android:windowBackground">@android:color/transparent</item> | |
| 66 | + <item name="android:windowIsFloating">true</item> | |
| 67 | + </style> | |
| 68 | + | |
| 62 | 69 | </resources> |
| 63 | 70 | \ No newline at end of file | ... | ... |
libs/common/src/main/java/com/prws/common/bean/Student.java
| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | +package com.prws.common.bean; | |
| 2 | + | |
| 3 | +import androidx.annotation.NonNull; | |
| 4 | + | |
| 5 | +public class Student { | |
| 6 | + | |
| 7 | + public String stuId; | |
| 8 | + public String stuName; | |
| 9 | + public int gender; | |
| 10 | + public String term; | |
| 11 | + public String account; | |
| 12 | + public String nickName; | |
| 13 | + public String address; | |
| 14 | + public String phone; | |
| 15 | + public String photo; | |
| 16 | + public int fromType; | |
| 17 | + public int gradeId; | |
| 18 | + public String oriSchool; | |
| 19 | + public String parentPhone; | |
| 20 | + public String parentIdentity; | |
| 21 | + public String teacherName; | |
| 22 | + public int teacherId; | |
| 23 | + public String teacherAvatar; | |
| 24 | + public String grade; | |
| 25 | + public String teacherIdentity; | |
| 26 | + public int sex; | |
| 27 | + public Integer state; | |
| 28 | + | |
| 29 | + @NonNull | |
| 30 | + @Override | |
| 31 | + public String toString() { | |
| 32 | + return stuName; | |
| 33 | + } | |
| 34 | +} | ... | ... |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| ... | ... | @@ -9,6 +9,7 @@ import com.prws.common.bean.GradeAndSubject; |
| 9 | 9 | import com.prws.common.bean.PageInfo; |
| 10 | 10 | import com.prws.common.bean.ResponseResult; |
| 11 | 11 | import com.prws.common.bean.ScheduleBean; |
| 12 | +import com.prws.common.bean.Student; | |
| 12 | 13 | import com.prws.common.bean.Teacher; |
| 13 | 14 | import com.prws.common.bean.TopicBean; |
| 14 | 15 | import com.prws.common.bean.UpdateBean; |
| ... | ... | @@ -170,6 +171,9 @@ public class NetWorks extends RetrofitUtils { |
| 170 | 171 | @GET("api/v1/teacher/getStudentList") |
| 171 | 172 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
| 172 | 173 | |
| 174 | + @GET("api/v1/teacher/getStudentList") | |
| 175 | + Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | |
| 176 | + | |
| 173 | 177 | @GET("api/v1/answer/listRecordForTeacher") |
| 174 | 178 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
| 175 | 179 | |
| ... | ... | @@ -178,6 +182,9 @@ public class NetWorks extends RetrofitUtils { |
| 178 | 182 | |
| 179 | 183 | } |
| 180 | 184 | |
| 185 | + public static String getUserId() { | |
| 186 | + return (String) SharedPreferencesUtil.getData("userId", ""); | |
| 187 | + } | |
| 181 | 188 | |
| 182 | 189 | public static String getHeader() { |
| 183 | 190 | return (String) SharedPreferencesUtil.getData("token", ""); |
| ... | ... | @@ -310,6 +317,10 @@ public class NetWorks extends RetrofitUtils { |
| 310 | 317 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 311 | 318 | } |
| 312 | 319 | |
| 320 | + public static Single<ResponseResult<List<Student>>> listStudent() { | |
| 321 | + return service_url.getStudentList2(getHeader(), getUserId()); | |
| 322 | + } | |
| 323 | + | |
| 313 | 324 | public static void listRecord(Observer<ResponseBody> observer) { |
| 314 | 325 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 315 | 326 | } | ... | ... |