Commit 25e17c06b185875e09fa06706129c6286f6a81f5

Authored by shixianjie
1 parent f536f83fe3
Exists in master

批改后录入错题

app/src/main/java/com/hjx/parent/ImageActivity.java
... ... @@ -430,7 +430,11 @@ public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implemen
430 430 private void save(List<TopicBean> topicBeans) {
431 431 if (type == 0) {
432 432 ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans);
433   - dialog.show();
  433 + dialog.show(() -> {
  434 + Intent intent = new Intent(this, AddSuccessActivity.class);
  435 + startActivity(intent);
  436 + finish();
  437 + });
434 438 } else {
435 439 List<String> paths = new ArrayList<>();
436 440 for (TopicBean it: topicBeans) {
... ...
app/src/main/java/com/hjx/parent/JudgeActivity.java
1 1 package com.hjx.parent;
2 2  
3 3 import android.annotation.SuppressLint;
  4 +import android.content.Intent;
4 5 import android.graphics.Bitmap;
5 6 import android.graphics.Rect;
6 7 import android.os.Bundle;
... ... @@ -10,12 +11,15 @@ import com.bumptech.glide.Glide;
10 11 import com.hjx.parent.api.JudgeRepository;
11 12 import com.hjx.parent.databinding.ActivityJudgeBinding;
12 13 import com.hjx.parent.databinding.LayoutJudgeRectBinding;
  14 +import com.hjx.parent.dialog.ErrorInputDialog;
13 15 import com.hjx.parent.rx.BaseRxActivity;
14 16 import com.hjx.parent.utils.CutUtil;
  17 +import com.prws.common.bean.TopicBean;
15 18  
16 19 import java.io.File;
17 20 import java.util.ArrayList;
18 21 import java.util.List;
  22 +import java.util.stream.Collectors;
19 23  
20 24 import io.reactivex.Observable;
21 25 import io.reactivex.Single;
... ... @@ -57,6 +61,23 @@ public class JudgeActivity extends BaseRxActivity&lt;ActivityJudgeBinding&gt; {
57 61 mList.forEach(it -> it.vb.getRoot().setSelected(true));
58 62 checkCount();
59 63 });
  64 + binding.btnAdd.setOnClickListener(v -> {
  65 + if (mList.isEmpty()) return;
  66 + List<TopicBean> selected = mList.stream()
  67 + .filter(it -> it.vb.getRoot().isSelected())
  68 + .map(it -> {
  69 + TopicBean bean = new TopicBean();
  70 + bean.setPath(it.getPath());
  71 + return bean;
  72 + })
  73 + .collect(Collectors.toList());
  74 +
  75 + ErrorInputDialog dialog = new ErrorInputDialog(this, selected);
  76 + dialog.show(() -> {
  77 + showToast("已加入错题本");
  78 + finish();
  79 + });
  80 + });
60 81 }
61 82  
62 83 private void prepareRects(List<Rect> rects) {
... ... @@ -169,5 +190,13 @@ public class JudgeActivity extends BaseRxActivity&lt;ActivityJudgeBinding&gt; {
169 190 this.rect = rect;
170 191 this.vb = vb;
171 192 }
  193 +
  194 + private String path;
  195 +
  196 + public String getPath() {
  197 + if (path != null) return path;
  198 + path = CutUtil.saveBitmapToCache(bitmap, App.getInstance());
  199 + return path;
  200 + }
172 201 }
173 202 }
... ...
app/src/main/java/com/hjx/parent/dialog/ErrorInputDialog.java
... ... @@ -17,6 +17,7 @@ import android.widget.RadioButton;
17 17 import android.widget.RadioGroup;
18 18  
19 19 import androidx.annotation.NonNull;
  20 +import androidx.fragment.app.FragmentActivity;
20 21 import androidx.recyclerview.widget.LinearLayoutManager;
21 22 import androidx.recyclerview.widget.RecyclerView;
22 23  
... ... @@ -30,6 +31,7 @@ import com.hjx.parent.ImageActivity;
30 31 import com.hjx.parent.R;
31 32 import com.hjx.parent.bean.StudentBean;
32 33 import com.hjx.parent.databinding.DialogAddErrorBinding;
  34 +import com.hjx.parent.function.Function0;
33 35 import com.prws.common.bean.Grade;
34 36 import com.prws.common.bean.GradeAndSubject;
35 37 import com.prws.common.bean.ResponseResult;
... ... @@ -54,7 +56,7 @@ import io.reactivex.disposables.Disposable;
54 56 import okhttp3.ResponseBody;
55 57  
56 58 public class ErrorInputDialog extends Dialog {
57   - private ImageActivity context;
  59 + private FragmentActivity context;
58 60 private DialogAddErrorBinding binding;
59 61 private List<TopicBean> list;
60 62 private int select = 0;
... ... @@ -65,7 +67,13 @@ public class ErrorInputDialog extends Dialog {
65 67 private int type = 0;
66 68 BaseQuickAdapter adapter;
67 69  
68   - public ErrorInputDialog(@NonNull ImageActivity context, List<TopicBean> list) {
  70 + private Function0 function = () -> {};
  71 + public void show(Function0 callback) {
  72 + this.function = callback;
  73 + super.show();
  74 + }
  75 +
  76 + public ErrorInputDialog(@NonNull FragmentActivity context, List<TopicBean> list) {
69 77 super(context, R.style.MyAlertDialog);
70 78 this.context = context;
71 79 this.list = list;
... ... @@ -271,9 +279,10 @@ public class ErrorInputDialog extends Dialog {
271 279 }
272 280 if (isAllAdd) {
273 281 dismiss();
274   - Intent intent = new Intent(context, AddSuccessActivity.class);
275   - context.startActivity(intent);
276   - context.finish();
  282 + function.invoke();
  283 +// Intent intent = new Intent(context, AddSuccessActivity.class);
  284 +// context.startActivity(intent);
  285 +// context.finish();
277 286 }
278 287 }
279 288 }
... ...
app/src/main/java/com/hjx/parent/utils/CutUtil.java
... ... @@ -12,9 +12,11 @@ import android.view.ViewTreeObserver;
12 12 import com.bumptech.glide.Glide;
13 13 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
14 14 import com.hjx.parent.function.Function1;
  15 +import com.prws.common.utils.CommonUtil;
15 16  
16 17 import java.io.ByteArrayOutputStream;
17 18 import java.io.File;
  19 +import java.io.FileOutputStream;
18 20 import java.io.IOException;
19 21 import java.util.List;
20 22  
... ... @@ -99,4 +101,29 @@ public class CutUtil {
99 101 .load(originList)
100 102 .get();
101 103 }
  104 +
  105 + public static String saveBitmapToCache(Bitmap bitmap, Context context) {
  106 + String fileName = System.currentTimeMillis() + CommonUtil.getStr() + ".jpg";
  107 + String path = context.getExternalCacheDir().getPath() + "/images/" + fileName;
  108 + try {
  109 + File file = new File(path);
  110 + File parent = file.getParentFile();
  111 + if (parent != null && !parent.exists()) {
  112 + parent.mkdirs();
  113 + }
  114 +
  115 + FileOutputStream fos = new FileOutputStream(file);
  116 + boolean success = bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  117 + fos.flush();
  118 + fos.close();
  119 +
  120 + if (success) {
  121 + return path;
  122 + }
  123 + } catch (Exception e) {
  124 + e.printStackTrace();
  125 + }
  126 + return null;
  127 + }
  128 +
102 129 }
... ...
app/src/main/res/drawable/bg_error_add_enabled.xml
... ... @@ -0,0 +1,15 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<selector xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <item android:state_enabled="false">
  4 + <shape>
  5 + <corners android:radius="5dp"/>
  6 + <solid android:color="#8DC7F9"/>
  7 + </shape>
  8 + </item>
  9 + <item>
  10 + <shape>
  11 + <corners android:radius="5dp"/>
  12 + <solid android:color="#1C90F3"/>
  13 + </shape>
  14 + </item>
  15 +</selector>
0 16 \ No newline at end of file
... ...
app/src/main/res/layout/activity_judge.xml
... ... @@ -60,12 +60,12 @@
60 60 <Space style="@style/empty_space"/>
61 61 <TextView
62 62 android:id="@+id/btnAdd"
  63 + android:enabled="false"
63 64 android:text="加入错题"
64 65 android:textSize="16sp"
65 66 android:textColor="@color/white"
66 67 android:gravity="center"
67   - android:background="@drawable/shape_radius_5"
68   - android:backgroundTint="#1C90F3"
  68 + android:background="@drawable/bg_error_add_enabled"
69 69 android:layout_width="112dp"
70 70 android:layout_height="36dp"/>
71 71 </LinearLayout>
... ...