Compare View

switch
from
...
to
 
Commits (3)
1 apply plugin: 'com.android.application' 1 apply plugin: 'com.android.application'
2 2
3 3
4 def androidId = rootProject.ext.androidId 4 def androidId = rootProject.ext.androidId
5 def support = rootProject.ext.dependencies 5 def support = rootProject.ext.dependencies
6 def url = rootProject.ext.url 6 def url = rootProject.ext.url
7 7
8 8
9 android { 9 android {
10 signingConfigs { 10 signingConfigs {
11 11
12 config { 12 config {
13 keyAlias 'alias' 13 keyAlias 'alias'
14 keyPassword '123456' 14 keyPassword '123456'
15 storeFile file('key.jks') 15 storeFile file('key.jks')
16 storePassword '123456' 16 storePassword '123456'
17 } 17 }
18 debug { 18 debug {
19 } 19 }
20 } 20 }
21 compileSdk 32 21 compileSdk 32
22 22
23 defaultConfig { 23 defaultConfig {
24 applicationId "com.hjx.parent" 24 applicationId "com.hjx.parent"
25 minSdk 26 25 minSdk 26
26 targetSdk 32 26 targetSdk 32
27 versionCode 1011 27 versionCode 1012
28 versionName "1.0.11" 28 versionName "1.0.12"
29 29
30 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 30 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31 } 31 }
32 32
33 android.applicationVariants.all { 33 android.applicationVariants.all {
34 variant -> 34 variant ->
35 variant.outputs.all { 35 variant.outputs.all {
36 //在这里修改apk文件名 36 //在这里修改apk文件名
37 outputFileName = "parent-${variant.name}-v${variant.versionName}.apk" 37 outputFileName = "parent-${variant.name}-v${variant.versionName}.apk"
38 } 38 }
39 } 39 }
40 buildTypes { 40 buildTypes {
41 debug { 41 debug {
42 debuggable true 42 debuggable true
43 minifyEnabled false 43 minifyEnabled false
44 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 44 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
45 signingConfig signingConfigs.config 45 signingConfig signingConfigs.config
46 } 46 }
47 release { 47 release {
48 debuggable true 48 debuggable true
49 minifyEnabled false 49 minifyEnabled false
50 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 50 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
51 signingConfig signingConfigs.config 51 signingConfig signingConfigs.config
52 } 52 }
53 } 53 }
54 lintOptions { 54 lintOptions {
55 checkReleaseBuilds false 55 checkReleaseBuilds false
56 abortOnError false 56 abortOnError false
57 } 57 }
58 buildFeatures { 58 buildFeatures {
59 viewBinding true 59 viewBinding true
60 dataBinding true 60 dataBinding true
61 } 61 }
62 compileOptions { 62 compileOptions {
63 sourceCompatibility JavaVersion.VERSION_1_8 63 sourceCompatibility JavaVersion.VERSION_1_8
64 targetCompatibility JavaVersion.VERSION_1_8 64 targetCompatibility JavaVersion.VERSION_1_8
65 } 65 }
66 } 66 }
67 67
68 dependencies { 68 dependencies {
69 support.each { k, v -> implementation v } 69 support.each { k, v -> implementation v }
70 api project(path: ':libs:common') 70 api project(path: ':libs:common')
71 implementation 'androidx.appcompat:appcompat:1.5.1' 71 implementation 'androidx.appcompat:appcompat:1.5.1'
72 implementation 'com.google.android.material:material:1.6.1' 72 implementation 'com.google.android.material:material:1.6.1'
73 implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 73 implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
74 implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50' 74 implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50'
75 implementation 'com.github.ForgetAll:LoadingDialog:1.1.2' 75 implementation 'com.github.ForgetAll:LoadingDialog:1.1.2'
76 implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0' 76 implementation 'com.github.DL-ZhangTeng:ImagePicker:1.5.0'
77 //使用的三方 77 //使用的三方
78 implementation 'com.yalantis:ucrop:2.2.0' 78 implementation 'com.yalantis:ucrop:2.2.0'
79 implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0' 79 implementation 'com.github.DL-ZhangTeng:RequestPermission:1.3.0'
80 implementation 'com.github.DL-ZhangTeng:Utils:2.2.0' 80 implementation 'com.github.DL-ZhangTeng:Utils:2.2.0'
81 81
82 // rx 82 // rx
83 implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2") 83 implementation("com.trello.rxlifecycle2:rxlifecycle:2.2.2")
84 implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2") 84 implementation("com.trello.rxlifecycle2:rxlifecycle-android:2.2.2")
85 85
86 implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") 86 implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
87 implementation("com.contrarywind:Android-PickerView:4.1.9") 87 implementation("com.contrarywind:Android-PickerView:4.1.9")
88 88
89 implementation 'com.google.android:flexbox:1.0.0' 89 implementation 'com.google.android:flexbox:1.0.0'
90 90
91 // 沉浸式状态栏和他的Kotlin拓展 91 // 沉浸式状态栏和他的Kotlin拓展
92 implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' 92 implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
93 implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2' 93 implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
94 94
95 // 图片查看 95 // 图片查看
96 implementation 'com.github.chrisbanes:PhotoView:2.0.0' 96 implementation 'com.github.chrisbanes:PhotoView:2.0.0'
97 97
98 implementation 'com.jakewharton:butterknife:10.2.3' 98 implementation 'com.jakewharton:butterknife:10.2.3'
99 annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' 99 annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
100 } 100 }
app/src/main/java/com/hjx/parent/HomeworkFeedbackActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.view.View; 6 import android.view.View;
7 import android.widget.ImageView; 7 import android.widget.ImageView;
8 import android.widget.RadioButton; 8 import android.widget.RadioButton;
9 import android.widget.Toast; 9 import android.widget.Toast;
10 10
11 import androidx.annotation.NonNull; 11 import androidx.annotation.NonNull;
12 import androidx.annotation.Nullable; 12 import androidx.annotation.Nullable;
13 13
14 import com.bumptech.glide.Glide; 14 import com.bumptech.glide.Glide;
15 import com.chad.library.adapter.base.BaseQuickAdapter; 15 import com.chad.library.adapter.base.BaseQuickAdapter;
16 import com.chad.library.adapter.base.BaseViewHolder; 16 import com.chad.library.adapter.base.BaseViewHolder;
17 import com.google.android.flexbox.FlexboxLayoutManager; 17 import com.google.android.flexbox.FlexboxLayoutManager;
18 import com.google.gson.Gson; 18 import com.google.gson.Gson;
19 import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding; 19 import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding;
20 import com.hjx.parent.rx.BaseRxActivity; 20 import com.hjx.parent.rx.BaseRxActivity;
21 import com.prws.common.bean.Student; 21 import com.prws.common.bean.Student;
22 import com.prws.common.bean.homework.CorrectionPoint; 22 import com.prws.common.bean.homework.CorrectionPoint;
23 import com.prws.common.bean.homework.CorrectionSer; 23 import com.prws.common.bean.homework.CorrectionSer;
24 import com.prws.common.bean.homework.HomeWork; 24 import com.prws.common.bean.homework.HomeWork;
25 import com.prws.common.bean.homework.HomeworkList; 25 import com.prws.common.bean.homework.HomeworkList;
26 import com.prws.common.bean.homework.KeyValue; 26 import com.prws.common.bean.homework.KeyValue;
27 import com.prws.common.net.NetWorks; 27 import com.prws.common.net.NetWorks;
28 28
29 import java.text.DecimalFormat; 29 import java.text.DecimalFormat;
30 import java.text.SimpleDateFormat; 30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList; 31 import java.util.ArrayList;
32 import java.util.HashMap; 32 import java.util.HashMap;
33 import java.util.HashSet; 33 import java.util.HashSet;
34 import java.util.List; 34 import java.util.List;
35 import java.util.Locale; 35 import java.util.Locale;
36 import java.util.Map; 36 import java.util.Map;
37 import java.util.Set; 37 import java.util.Set;
38 38
39 public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> { 39 public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> {
40 private Student student; 40 private Student student;
41 private HomeworkList mData; 41 private HomeworkList mData;
42 private ArrayList<HomeWork> mList; 42 private ArrayList<HomeWork> mList;
43 private List<CorrectionSer> corrections = new ArrayList<>(); 43 private List<CorrectionSer> corrections = new ArrayList<>();
44 44
45 @SuppressWarnings("unchecked") 45 @SuppressWarnings("unchecked")
46 @Override 46 @Override
47 public void initView(Bundle savedInstanceState) { 47 public void initView(Bundle savedInstanceState) {
48 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); 48 binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());
49 student = (Student) getIntent().getSerializableExtra("student"); 49 student = (Student) getIntent().getSerializableExtra("student");
50 mData = (HomeworkList) getIntent().getSerializableExtra("data"); 50 mData = (HomeworkList) getIntent().getSerializableExtra("data");
51 mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list"); 51 mList = (ArrayList<HomeWork>) getIntent().getSerializableExtra("list");
52 52
53 binding.tvStuName.setText(student.stuName); 53 binding.tvStuName.setText(student.stuName);
54 binding.tvGrade.setText(student.grade); 54 binding.tvGrade.setText(student.grade);
55 55
56 List<HomeWork> correctList = new ArrayList<>(); 56 List<HomeWork> correctList = new ArrayList<>();
57 List<HomeWork> errorList = new ArrayList<>(); 57 List<HomeWork> errorList = new ArrayList<>();
58 List<HomeWork> blankList = new ArrayList<>(); 58 List<HomeWork> blankList = new ArrayList<>();
59 int correctNo = 0, blankNo = 0; 59 int correctNo = 0, blankNo = 0;
60 for (HomeWork homeWork: mList) { 60 for (HomeWork homeWork: mList) {
61 homeWork.state = 1; 61 homeWork.state = 1;
62 homeWork.index = mList.indexOf(homeWork); 62 homeWork.index = mList.indexOf(homeWork);
63 corrections.add(homeWork.toSer()); 63 corrections.add(homeWork.toSer());
64 if (homeWork.correction == 0) { 64 if (homeWork.correction == 0) {
65 correctList.add(homeWork); 65 correctList.add(homeWork);
66 correctNo ++; 66 correctNo ++;
67 } 67 }
68 else if (homeWork.correction == 1) { 68 else if (homeWork.correction == 1) {
69 correctList.add(homeWork); 69 correctList.add(homeWork);
70 errorList.add(homeWork); 70 errorList.add(homeWork);
71 } 71 }
72 else if (homeWork.correction == 2) { 72 else if (homeWork.correction == 2) {
73 blankList.add(homeWork); 73 blankList.add(homeWork);
74 blankNo ++; 74 blankNo ++;
75 } 75 }
76 } 76 }
77 binding.viewBlank.setVisibility(blankList.isEmpty() ? View.GONE : View.VISIBLE); 77 binding.viewBlank.setVisibility(blankList.isEmpty() ? View.GONE : View.VISIBLE);
78 binding.rvBlank.setVisibility(blankList.isEmpty() ? View.GONE : View.VISIBLE); 78 binding.rvBlank.setVisibility(blankList.isEmpty() ? View.GONE : View.VISIBLE);
79 79
80 float rate = 1f * correctNo / Math.max(mList.size() - blankNo, 1); 80 float rate = 1f * correctNo / Math.max(mList.size() - blankNo, 1);
81 binding.tvPercent.setText(new DecimalFormat("0%").format(rate)); 81 binding.tvPercent.setText(new DecimalFormat("0%").format(rate));
82 82
83 binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this)); 83 binding.rvCorrect.setLayoutManager(new FlexboxLayoutManager(this));
84 binding.rvBlank.setLayoutManager(new FlexboxLayoutManager(this)); 84 binding.rvBlank.setLayoutManager(new FlexboxLayoutManager(this));
85 NumberAdapter numberAdapter = new NumberAdapter(correctList); 85 NumberAdapter numberAdapter = new NumberAdapter(correctList);
86 NumberAdapter blankAdapter = new NumberAdapter(blankList); 86 NumberAdapter blankAdapter = new NumberAdapter(blankList);
87 binding.rvCorrect.setAdapter(numberAdapter); 87 binding.rvCorrect.setAdapter(numberAdapter);
88 binding.rvBlank.setAdapter(blankAdapter); 88 binding.rvBlank.setAdapter(blankAdapter);
89 89
90 binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE); 90 binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE);
91 binding.rvError.setAdapter(new EvalAdapter(errorList)); 91 binding.rvError.setAdapter(new EvalAdapter(errorList));
92 if (errorList.isEmpty()) { 92 if (errorList.isEmpty()) {
93 binding.flEval.setVisibility(View.GONE); 93 binding.flEval.setVisibility(View.GONE);
94 } 94 }
95 95
96 binding.btnDetail.setOnClickListener(v -> { 96 binding.btnDetail.setOnClickListener(v -> {
97 viewTopicDetail(0); 97 viewTopicDetail(0);
98 }); 98 });
99 binding.btnDetail2.setOnClickListener(v -> { 99 binding.btnDetail2.setOnClickListener(v -> {
100 viewTopicDetail(0); 100 viewTopicDetail(0);
101 }); 101 });
102 numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { 102 numberAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> {
103 viewTopicDetail(i); 103 viewTopicDetail(i);
104 }); 104 });
105 blankAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> { 105 blankAdapter.setOnItemClickListener((baseQuickAdapter, view, i) -> {
106 viewTopicDetail(i); 106 viewTopicDetail(i);
107 }); 107 });
108 binding.btnPublish.setOnClickListener(v -> submit()); 108 binding.btnPublish.setOnClickListener(v -> submit());
109 } 109 }
110 110
111 private void viewTopicDetail(int position) { 111 private void viewTopicDetail(int position) {
112 Intent intent = new Intent(this, HomeworkTopicActivity.class); 112 Intent intent = new Intent(this, HomeworkTopicActivity.class);
113 intent.putExtra("list", mList); 113 intent.putExtra("list", mList);
114 intent.putExtra("position", position); 114 intent.putExtra("position", position);
115 startActivity(intent); 115 startActivity(intent);
116 } 116 }
117 117
118 @SuppressLint("CheckResult") 118 @SuppressLint("CheckResult")
119 private void submit() { 119 private void submit() {
120 Map<String, Object> body = new HashMap<>(); 120 Map<String, Object> body = new HashMap<>();
121 body.put("homeworkId", mData.getId()); 121 body.put("homeworkId", mData.getId());
122 body.put("comment", binding.etComment.getText().toString()); 122 body.put("comment", binding.etComment.getText().toString());
123 body.put("stuId", student.stuId); 123 body.put("stuId", student.stuId);
124 body.put("points", countPoint()); 124 body.put("points", countPoint());
125 body.put("correctionList", corrections); 125 body.put("correctionList", corrections);
126 body.put("extra", buildExtra()); 126 body.put("extra", buildExtra());
127 NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body) 127 NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body)
128 .compose(transformSingle()) 128 .compose(transformSingle())
129 .subscribe((response, th) -> { 129 .subscribe((response, th) -> {
130 if (th != null) th.printStackTrace(); 130 if (th != null) th.printStackTrace();
131 if (response != null && response.getSuccess()) { 131 if (response != null && response.getSuccess()) {
132 Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show(); 132 Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show();
133 133
134 Intent intent = new Intent(this, HomeworkShareActivity.class); 134 Intent intent = new Intent(this, HomeworkShareActivity.class);
135 intent.putExtra("student", student); 135 intent.putExtra("student", student);
136 intent.putExtra("id", mData.getId()); 136 intent.putExtra("id", mData.getId());
137 intent.putExtra("grade", mData.getGrade()); 137 intent.putExtra("grade", mData.getGrade());
138 intent.putExtra("subject", mData.getSubject()); 138 intent.putExtra("subject", mData.getSubject());
139 String name = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(mData.uploadTime); 139 String name = new SimpleDateFormat("yyyy年M月d日作业", Locale.CHINA).format(mData.uploadTime);
140 intent.putExtra("name", name); 140 intent.putExtra("name", name);
141 startActivity(intent); 141 startActivity(intent);
142 142
143 setResult(RESULT_OK); 143 setResult(RESULT_OK);
144 finish(); 144 finish();
145 } else { 145 } else {
146 Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show(); 146 Toast.makeText(this, "反馈失败", Toast.LENGTH_SHORT).show();
147 } 147 }
148 }); 148 });
149 } 149 }
150 150
151 private String buildExtra() { 151 private String buildExtra() {
152 if (mList == null || mList.isEmpty()) return null; 152 if (mList == null || mList.isEmpty()) return null;
153 List<CorrectionSer> maps = new ArrayList<>(); 153 List<CorrectionSer> maps = new ArrayList<>();
154 for (HomeWork item: mList) { 154 for (HomeWork item: mList) {
155 if (item.correction == 2) continue;
155 if (item.correction == 2) continue; 156 maps.add(item.toSer());
156 maps.add(item.toSer()); 157 }
158 if (maps.isEmpty()) return null;
157 } 159 Gson gson = new Gson();
158 if (maps.isEmpty()) return null; 160 return gson.toJson(maps);
159 Gson gson = new Gson(); 161 }
160 return gson.toJson(maps); 162
161 } 163 @SuppressLint("CheckResult")
162 164 private List<CorrectionPoint> countPoint() {
163 @SuppressLint("CheckResult") 165 Set<KeyValue> set = new HashSet<>();
164 private List<CorrectionPoint> countPoint() { 166 Map<String, Integer> totalTimes = new HashMap<>();
165 Set<KeyValue> set = new HashSet<>(); 167 Map<String, Integer> correctTimes = new HashMap<>();
166 Map<String, Integer> totalTimes = new HashMap<>(); 168 Map<String, Integer> underTimes = new HashMap<>();
167 Map<String, Integer> correctTimes = new HashMap<>(); 169 Map<String, Integer> baseTimes = new HashMap<>();
168 Map<String, Integer> underTimes = new HashMap<>(); 170 Map<String, Integer> normalTimes = new HashMap<>();
169 Map<String, Integer> baseTimes = new HashMap<>(); 171 Gson gson = new Gson();
170 Map<String, Integer> normalTimes = new HashMap<>(); 172 for (HomeWork homeWork: mList) {
173 if (homeWork.correction == 2) continue;
171 Gson gson = new Gson(); 174 homeWork.formatPoints(gson);
172 for (HomeWork homeWork: mList) { 175
173 if (homeWork.correction == 2) continue; 176 set.addAll(homeWork.pointsObj);
174 homeWork.formatPoints(gson); 177 for (KeyValue keyValue: homeWork.pointsObj) {
175 178 String key = keyValue.Key;
176 set.addAll(homeWork.pointsObj); 179 if (totalTimes.containsKey(key)) {
177 for (KeyValue keyValue: homeWork.pointsObj) { 180 totalTimes.put(key, totalTimes.get(key) + 1);
178 String key = keyValue.Key; 181 } else {
179 if (totalTimes.containsKey(key)) { 182 totalTimes.put(key, 1);
180 totalTimes.put(key, totalTimes.get(key) + 1); 183 }
181 } else { 184 if (homeWork.correction == 0) {
182 totalTimes.put(key, 1); 185 if (correctTimes.containsKey(key)) {
183 } 186 correctTimes.put(key, correctTimes.get(key) + 1);
184 if (homeWork.correction == 0) { 187 } else {
185 if (correctTimes.containsKey(key)) { 188 correctTimes.put(key, 1);
186 correctTimes.put(key, correctTimes.get(key) + 1); 189 }
187 } else { 190 } else if (homeWork.correction == 1) {
188 correctTimes.put(key, 1); 191 if (homeWork.state == 1) {
189 } 192 if (underTimes.containsKey(key)) {
190 } else if (homeWork.correction == 1) { 193 underTimes.put(key, underTimes.get(key) + 1);
191 if (homeWork.state == 1) { 194 } else {
192 if (underTimes.containsKey(key)) { 195 underTimes.put(key, 1);
193 underTimes.put(key, underTimes.get(key) + 1); 196 }
194 } else { 197 } else if (homeWork.state == 2) {
195 underTimes.put(key, 1); 198 if (baseTimes.containsKey(key)) {
196 } 199 baseTimes.put(key, baseTimes.get(key) + 1);
197 } else if (homeWork.state == 2) { 200 } else {
198 if (baseTimes.containsKey(key)) { 201 baseTimes.put(key, 1);
199 baseTimes.put(key, baseTimes.get(key) + 1); 202 }
200 } else { 203 } else if (homeWork.state == 3) {
201 baseTimes.put(key, 1); 204 if (normalTimes.containsKey(key)) {
202 } 205 normalTimes.put(key, normalTimes.get(key) + 1);
203 } else if (homeWork.state == 3) { 206 } else {
204 if (normalTimes.containsKey(key)) { 207 normalTimes.put(key, 1);
205 normalTimes.put(key, normalTimes.get(key) + 1); 208 }
206 } else { 209 }
207 normalTimes.put(key, 1); 210 }
208 } 211 }
209 } 212 }
210 } 213 List<CorrectionPoint> points = new ArrayList<>();
211 } 214 for (KeyValue obj: set) {
212 } 215 CorrectionPoint point = new CorrectionPoint();
213 List<CorrectionPoint> points = new ArrayList<>(); 216 point.pointId = obj.Key;
214 for (KeyValue obj: set) { 217 point.pointName = obj.Value;
215 CorrectionPoint point = new CorrectionPoint(); 218 point.totalCount = ifNull(totalTimes.get(obj.Key), 1);
216 point.pointId = obj.Key; 219 point.correctCount = ifNull(correctTimes.get(obj.Key), 0);
217 point.pointName = obj.Value; 220 point.understandCount = ifNull(underTimes.get(obj.Key), 0);
218 point.totalCount = ifNull(totalTimes.get(obj.Key), 1); 221 point.basicCount = ifNull(baseTimes.get(obj.Key), 0);
219 point.correctCount = ifNull(correctTimes.get(obj.Key), 0); 222 point.normalCount = ifNull(normalTimes.get(obj.Key), 0);
220 point.understandCount = ifNull(underTimes.get(obj.Key), 0); 223
221 point.basicCount = ifNull(baseTimes.get(obj.Key), 0); 224 points.add(point);
222 point.normalCount = ifNull(normalTimes.get(obj.Key), 0); 225 }
223 226
224 points.add(point); 227 return points;
225 } 228 }
226 229
227 return points; 230 private int ifNull(Integer src, int defaultVal) {
228 } 231 if (src == null) return defaultVal;
229 232 else return src;
230 private int ifNull(Integer src, int defaultVal) { 233 }
231 if (src == null) return defaultVal; 234
232 else return src; 235
233 } 236 @Override
234 237 protected ActivityHomeworkFeedbackBinding getViewBinding() {
235 238 return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater());
236 @Override 239 }
237 protected ActivityHomeworkFeedbackBinding getViewBinding() { 240
238 return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater()); 241 static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
239 } 242
240 243 public NumberAdapter(List<HomeWork> list) {
241 static class NumberAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 244 super(R.layout.item_feedback_num, list);
242 245 }
243 public NumberAdapter(List<HomeWork> list) { 246
244 super(R.layout.item_feedback_num, list); 247 @Override
245 } 248 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
246 249 int position = getData().indexOf(homeWork);
247 @Override 250 holder.setText(R.id.tvNum, String.valueOf(position + 1));
248 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 251 if (homeWork.correction == 1) {
249 int position = getData().indexOf(homeWork); 252 holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small);
250 holder.setText(R.id.tvNum, String.valueOf(position + 1)); 253 } else if (homeWork.correction == 0){
251 if (homeWork.correction == 1) { 254 holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small);
252 holder.setImageResource(R.id.ivType, R.drawable.ic_wrong_small); 255 } else {
253 } else if (homeWork.correction == 0){ 256 holder.setImageDrawable(R.id.ivType, null);
254 holder.setImageResource(R.id.ivType, R.drawable.ic_correct_small); 257 }
255 } else { 258 }
256 holder.setImageDrawable(R.id.ivType, null); 259 }
257 } 260
258 } 261 static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> {
259 } 262
260 263 public EvalAdapter(@Nullable List<HomeWork> data) {
261 static class EvalAdapter extends BaseQuickAdapter<HomeWork, BaseViewHolder> { 264 super(R.layout.item_homework_eval, data);
262 265 }
263 public EvalAdapter(@Nullable List<HomeWork> data) { 266
264 super(R.layout.item_homework_eval, data); 267 @Override
265 } 268 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) {
266 269 holder.itemView.setClipToOutline(true);
267 @Override 270 holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1));
268 protected void convert(@NonNull BaseViewHolder holder, HomeWork homeWork) { 271 ImageView iv = holder.getView(R.id.ivTopic);
269 holder.itemView.setClipToOutline(true); 272 Glide.with(mContext).load(homeWork.url).into(iv);
270 holder.setText(R.id.tvNo, "题目" + (homeWork.index + 1)); 273
271 ImageView iv = holder.getView(R.id.ivTopic); 274 RadioButton chk1 = holder.getView(R.id.chk1);
272 Glide.with(mContext).load(homeWork.url).into(iv); 275 RadioButton chk2 = holder.getView(R.id.chk2);
273 276 RadioButton chk3 = holder.getView(R.id.chk3);
274 RadioButton chk1 = holder.getView(R.id.chk1); 277 chk1.setOnCheckedChangeListener((v, b) -> {
275 RadioButton chk2 = holder.getView(R.id.chk2); 278 if (b) {
276 RadioButton chk3 = holder.getView(R.id.chk3); 279 homeWork.state = 1;
277 chk1.setOnCheckedChangeListener((v, b) -> { 280 }
278 if (b) { 281 });
279 homeWork.state = 1; 282 chk2.setOnCheckedChangeListener((v, b) -> {
280 } 283 if (b) {
281 }); 284 homeWork.state = 2;
282 chk2.setOnCheckedChangeListener((v, b) -> { 285 }
283 if (b) { 286 });
284 homeWork.state = 2; 287 chk3.setOnCheckedChangeListener((v, b) -> {
285 } 288 if (b) {
286 }); 289 homeWork.state = 3;
287 chk3.setOnCheckedChangeListener((v, b) -> { 290 }
288 if (b) { 291 });
289 homeWork.state = 3; 292 chk1.setChecked(homeWork.state == 1);
290 } 293 chk2.setChecked(homeWork.state == 2);
291 }); 294 chk3.setChecked(homeWork.state == 3);
292 chk1.setChecked(homeWork.state == 1); 295 }
293 chk2.setChecked(homeWork.state == 2); 296 }
294 chk3.setChecked(homeWork.state == 3); 297 }
295 } 298
app/src/main/java/com/hjx/parent/HuyouDetailActivity.java
1 package com.hjx.parent; 1 package com.hjx.parent;
2 2
3 3
4 import android.annotation.SuppressLint; 4 import android.annotation.SuppressLint;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.content.res.ColorStateList; 6 import android.content.res.ColorStateList;
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.net.Uri; 8 import android.net.Uri;
9 import android.os.Bundle; 9 import android.os.Bundle;
10 import android.text.Html; 10 import android.text.Html;
11 import android.view.View; 11 import android.view.View;
12 import android.widget.TextView; 12 import android.widget.TextView;
13 13
14 import androidx.annotation.NonNull; 14 import androidx.annotation.NonNull;
15 import androidx.annotation.Nullable; 15 import androidx.annotation.Nullable;
16 import androidx.core.content.res.ResourcesCompat; 16 import androidx.core.content.res.ResourcesCompat;
17 17
18 import com.bumptech.glide.Glide; 18 import com.bumptech.glide.Glide;
19 import com.chad.library.adapter.base.BaseQuickAdapter; 19 import com.chad.library.adapter.base.BaseQuickAdapter;
20 import com.chad.library.adapter.base.BaseViewHolder; 20 import com.chad.library.adapter.base.BaseViewHolder;
21 import com.github.mikephil.charting.components.Legend; 21 import com.github.mikephil.charting.components.Legend;
22 import com.github.mikephil.charting.components.XAxis; 22 import com.github.mikephil.charting.components.XAxis;
23 import com.github.mikephil.charting.components.YAxis; 23 import com.github.mikephil.charting.components.YAxis;
24 import com.github.mikephil.charting.data.Entry; 24 import com.github.mikephil.charting.data.Entry;
25 import com.github.mikephil.charting.data.LineData; 25 import com.github.mikephil.charting.data.LineData;
26 import com.github.mikephil.charting.data.LineDataSet; 26 import com.github.mikephil.charting.data.LineDataSet;
27 import com.github.mikephil.charting.formatter.ValueFormatter; 27 import com.github.mikephil.charting.formatter.ValueFormatter;
28 import com.gyf.immersionbar.ImmersionBar; 28 import com.gyf.immersionbar.ImmersionBar;
29 import com.hjx.parent.databinding.ActivityHuyouDetailBinding; 29 import com.hjx.parent.databinding.ActivityHuyouDetailBinding;
30 import com.hjx.parent.rx.BaseRxActivity; 30 import com.hjx.parent.rx.BaseRxActivity;
31 import com.prws.common.bean.Student; 31 import com.prws.common.bean.Student;
32 import com.prws.common.bean.homework.StDetail; 32 import com.prws.common.bean.homework.StDetail;
33 import com.prws.common.net.NetWorks; 33 import com.prws.common.net.NetWorks;
34 import com.prws.common.utils.BitmapUtils; 34 import com.prws.common.utils.BitmapUtils;
35 import com.prws.common.utils.ContentUtil; 35 import com.prws.common.utils.ContentUtil;
36 import com.trello.rxlifecycle2.android.RxLifecycleAndroid; 36 import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
37 37
38 import java.text.DecimalFormat; 38 import java.text.DecimalFormat;
39 import java.text.SimpleDateFormat; 39 import java.text.SimpleDateFormat;
40 import java.util.ArrayList; 40 import java.util.ArrayList;
41 import java.util.Date; 41 import java.util.Date;
42 import java.util.List; 42 import java.util.List;
43 import java.util.Locale; 43 import java.util.Locale;
44 import java.util.TimeZone; 44 import java.util.TimeZone;
45 45
46 import io.reactivex.android.schedulers.AndroidSchedulers; 46 import io.reactivex.android.schedulers.AndroidSchedulers;
47 import io.reactivex.schedulers.Schedulers; 47 import io.reactivex.schedulers.Schedulers;
48 48
49 public class HuyouDetailActivity extends BaseRxActivity<ActivityHuyouDetailBinding> { 49 public class HuyouDetailActivity extends BaseRxActivity<ActivityHuyouDetailBinding> {
50 50
51 private String id; 51 private String id;
52 private int type; // 0:周 1:阶段 52 private int type; // 0:周 1:阶段
53 private Student student; 53 private Student student;
54 54
55 private StDetail mData; 55 private StDetail mData;
56 56
57 final String indent = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 57 final String indent = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
58 58
59 private boolean a4 = false; 59 private boolean a4 = false;
60 60
61 @Override 61 @Override
62 protected void onResume() { 62 protected void onResume() {
63 super.onResume(); 63 super.onResume();
64 binding.root.postDelayed(() -> { 64 binding.root.postDelayed(() -> {
65 float scale = 1f * binding.getRoot().getWidth() / binding.root.getWidth(); 65 float scale = 1f * binding.getRoot().getWidth() / binding.root.getWidth();
66 if (scale >= 1) return; 66 if (scale >= 1) return;
67 binding.root.setScaleX(scale); 67 binding.root.setScaleX(scale);
68 binding.root.setScaleY(scale); 68 binding.root.setScaleY(scale);
69 }, 100); 69 }, 100);
70 } 70 }
71 71
72 @SuppressLint("CheckResult") 72 @SuppressLint("CheckResult")
73 @Override 73 @Override
74 public void initView(Bundle savedInstanceState) { 74 public void initView(Bundle savedInstanceState) {
75 binding.btnBack.setOnClickListener(v -> onBackPressed()); 75 binding.btnBack.setOnClickListener(v -> onBackPressed());
76 id = getIntent().getStringExtra("id"); 76 id = getIntent().getStringExtra("id");
77 type = getIntent().getIntExtra("type", 0); 77 type = getIntent().getIntExtra("type", 0);
78 student = (Student) getIntent().getSerializableExtra("student"); 78 student = (Student) getIntent().getSerializableExtra("student");
79 79
80 if (type == 1) { 80 if (type == 1) {
81 binding.tvTitle.setText("阶段作业学习总结"); 81 binding.tvTitle.setText("阶段作业学习总结");
82 binding.viewWeekTable.setVisibility(View.GONE); 82 binding.viewWeekTable.setVisibility(View.GONE);
83 } else { 83 } else {
84 binding.viewPointTotal.setVisibility(View.GONE); 84 binding.viewPointTotal.setVisibility(View.GONE);
85 binding.viewTable.setVisibility(View.GONE); 85 binding.viewTable.setVisibility(View.GONE);
86 } 86 }
87 87
88 Glide.with(this).load(student.photo).into(binding.ivAvatar); 88 Glide.with(this).load(student.photo).into(binding.ivAvatar);
89 binding.tvStuName.setText(student.stuName); 89 binding.tvStuName.setText(student.stuName);
90 90
91 setupChart(); 91 setupChart();
92 NetWorks.service_url.getHuyouDetail(NetWorks.getHeader(), id) 92 NetWorks.service_url.getHuyouDetail(NetWorks.getHeader(), id)
93 .subscribeOn(Schedulers.io()) 93 .subscribeOn(Schedulers.io())
94 .map(response -> response.getData()) 94 .map(response -> response.getData())
95 .map(data -> { 95 .map(data -> {
96 if (type == 1) data.formatCollection(); 96 if (type == 1) data.formatCollection();
97 return data; 97 return data;
98 }) 98 })
99 .observeOn(AndroidSchedulers.mainThread()) 99 .observeOn(AndroidSchedulers.mainThread())
100 .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle())) 100 .compose(RxLifecycleAndroid.bindActivity(getRxLifecycle()))
101 .subscribe((data, th) -> { 101 .subscribe((data, th) -> {
102 mData = data; 102 mData = data;
103 if (th != null) th.printStackTrace(); 103 if (th != null) th.printStackTrace();
104 if (data != null) showData(data); 104 if (data != null) showData(data);
105 }); 105 });
106 106
107 binding.btnShare.setOnClickListener(v -> { 107 binding.btnShare.setOnClickListener(v -> {
108 Uri shareUri = prepareShare(); 108 Uri shareUri = prepareShare();
109 if (shareUri != null) { 109 if (shareUri != null) {
110 Intent shareIntent = new Intent(Intent.ACTION_SEND); 110 Intent shareIntent = new Intent(Intent.ACTION_SEND);
111 shareIntent.setType("image/jpeg"); 111 shareIntent.setType("image/jpeg");
112 shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri); 112 shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri);
113 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 113 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
114 114
115 startActivity(shareIntent); 115 startActivity(shareIntent);
116 } 116 }
117 }); 117 });
118 118
119 binding.btnSwitch.setOnClickListener(v -> { 119 binding.btnSwitch.setOnClickListener(v -> {
120 switchPage(); 120 switchPage();
121 }); 121 });
122 122
123 } 123 }
124 124
125 private SimpleDateFormat getFormatWithGmt8(String pattern) { 125 private SimpleDateFormat getFormatWithGmt8(String pattern) {
126 SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA); 126 SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA);
127 format.setTimeZone(TimeZone.getTimeZone("GMT+16")); 127 format.setTimeZone(TimeZone.getTimeZone("GMT+16"));
128 return format; 128 return format;
129 } 129 }
130 130
131 @SuppressLint("SetTextI18n") 131 @SuppressLint("SetTextI18n")
132 private void showData(StDetail data) { 132 private void showData(StDetail data) {
133 binding.tvGrade.setText(data.grade); 133 binding.tvGrade.setText(data.grade);
134 binding.tvSubject.setText(data.homeworkSubject); 134 binding.tvSubject.setText(data.homeworkSubject);
135 String start = getFormatWithGmt8("yyyy.M.d").format(data.startTime); 135 String start = getFormatWithGmt8("yyyy.M.d").format(data.startTime);
136 String end = new SimpleDateFormat(" - M.d", Locale.CHINA).format(data.endTime); 136 String end = new SimpleDateFormat(" - M.d", Locale.CHINA).format(data.endTime);
137 binding.tvDate.setText(start + end); 137 binding.tvDate.setText(start + end);
138 138
139 if (data.points == null) data.points = new ArrayList<>(); 139 if (data.points == null) data.points = new ArrayList<>();
140 if (data.points.size() == 0) { 140 if (data.points.size() == 0) {
141 binding.cpBefore.setValue(0); 141 binding.cpBefore.setValue(0);
142 binding.cpAfter.setValue(0); 142 binding.cpAfter.setValue(0);
143 binding.pgBefore.setText("0"); 143 binding.pgBefore.setText("0");
144 binding.pgAfter.setText("0"); 144 binding.pgAfter.setText("0");
145 } else { 145 } else {
146 float before = 0; 146 float before = 0;
147 float after = 0; 147 float after = 0;
148 for (StDetail.Point point: data.points) { 148 for (StDetail.Point point: data.points) {
149 before += point.beforeState; 149 before += point.beforeState;
150 after += point.afterState; 150 after += point.afterState;
151 } 151 }
152 before = (int) (100f * before / data.points.size() + 0.5f); 152 before = (int) (100f * before / data.points.size() + 0.5f);
153 after = (int) (100f * after / data.points.size() + 0.5f); 153 after = (int) (100f * after / data.points.size() + 0.5f);
154 binding.cpBefore.setValue(before); 154 binding.cpBefore.setValue(before);
155 binding.cpAfter.setValue(after); 155 binding.cpAfter.setValue(after);
156 DecimalFormat format = new DecimalFormat("0"); 156 DecimalFormat format = new DecimalFormat("0");
157 binding.pgBefore.setText(format.format(before)); 157 binding.pgBefore.setText(format.format(before));
158 binding.pgAfter.setText(format.format(after)); 158 binding.pgAfter.setText(format.format(after));
159 159
160 String comment; 160 String comment;
161 if (after >= 90) { 161 if (after >= 90) {
162 comment = "知识点掌握的比较扎实,多练习多巩固掌握一般的知识点会有很大帮助。"; 162 comment = "知识点掌握的比较扎实,多练习多巩固掌握一般的知识点会有很大帮助。";
163 } else if (after >= 80) { 163 } else if (after >= 80) {
164 comment = "知识点掌握程度有进步,还要再继续学习,多练习,不断巩固。"; 164 comment = "知识点掌握程度有进步,还要再继续学习,多练习,不断巩固。";
165 } else if (after >= 60) { 165 } else if (after >= 60) {
166 comment = "薄弱知识点还有进步空间,再多做一些类似题目来巩固知识点,继续努力。"; 166 comment = "薄弱知识点还有进步空间,再多做一些类似题目来巩固知识点,继续努力。";
167 } else { 167 } else {
168 comment = "你的薄弱知识点还需要再深入了解,有不清楚的地方及时问老师,继续加油。"; 168 comment = "你的薄弱知识点还需要再深入了解,有不清楚的地方及时问老师,继续加油。";
169 } 169 }
170 String percent = new DecimalFormat("0%").format(after / 100); 170 String percent = new DecimalFormat("0%").format(after / 100);
171 String temp = indent + "通过学习,你的知识点掌握程度为 %s," + comment; 171 String temp = indent + "通过学习,你的知识点掌握程度为 %s," + comment;
172 temp = String.format(temp, fromColor(percent, "#F24E38")); 172 temp = String.format(temp, fromColor(percent, "#F24E38"));
173 binding.tvWeakRate.setText(Html.fromHtml(temp, Html.FROM_HTML_MODE_COMPACT)); 173 binding.tvWeakRate.setText(Html.fromHtml(temp, Html.FROM_HTML_MODE_COMPACT));
174 } 174 }
175 175
176 int exNo = 0, goodNo = 0, normalNo = 0, weakNo = 0; 176 int exNo = 0, goodNo = 0, normalNo = 0, weakNo = 0;
177 float total = 0; 177 float total = 0;
178 if (data.points != null) { 178 if (data.points != null) {
179 if (type == 0) { 179 if (type == 0) {
180 for (StDetail.Point point: data.points) { 180 for (StDetail.Point point: data.points) {
181 total += point.beforeState; 181 total += point.beforeState;
182 if (point.beforeState >= 0.9) { 182 if (point.beforeState >= 0.9) {
183 exNo ++; 183 exNo ++;
184 } else if (point.beforeState >= 0.8) { 184 } else if (point.beforeState >= 0.8) {
185 goodNo ++; 185 goodNo ++;
186 } else if (point.beforeState >= 0.6) { 186 } else if (point.beforeState >= 0.6) {
187 normalNo ++; 187 normalNo ++;
188 } else { 188 } else {
189 weakNo ++; 189 weakNo ++;
190 } 190 }
191 } 191 }
192 } else { 192 } else {
193 for (StDetail.Point point: data.points) { 193 for (StDetail.Point point: data.points) {
194 total += point.afterState; 194 total += point.afterState;
195 if (point.afterState >= 0.9) { 195 if (point.afterState >= 0.9) {
196 exNo ++; 196 exNo ++;
197 } else if (point.afterState >= 0.8) { 197 } else if (point.afterState >= 0.8) {
198 goodNo ++; 198 goodNo ++;
199 } else if (point.afterState >= 0.6) { 199 } else if (point.afterState >= 0.6) {
200 normalNo ++; 200 normalNo ++;
201 } else { 201 } else {
202 weakNo ++; 202 weakNo ++;
203 } 203 }
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 float rate = 100f * data.correct / Math.max(data.total - data.unfinished, 1); 208 float rate = 100f * data.correct / Math.max(data.total - data.unfinished, 1);
209 binding.tvTotalRate.setText(new DecimalFormat("0").format(rate)); 209 binding.tvTotalRate.setText(new DecimalFormat("0").format(rate));
210 binding.tvTotalCorrect.setText(String.valueOf(data.correct)); 210 binding.tvTotalCorrect.setText(String.valueOf(data.correct));
211 binding.tvTotalError.setText(String.valueOf(data.total - data.correct - data.unfinished)); 211 binding.tvTotalError.setText(String.valueOf(data.total - data.correct - data.unfinished));
212 binding.tvTotalBlank.setText(String.valueOf(data.unfinished)); 212 binding.tvTotalBlank.setText(String.valueOf(data.unfinished));
213 if (data.total == 0) { 213 if (data.total == 0) {
214 binding.tvRating.setText(""); 214 binding.tvRating.setText("");
215 } else { 215 } else {
216 String rateComment; 216 String rateComment;
217 String encComment; 217 String encComment;
218 if (rate >= 90) { 218 if (rate >= 90) {
219 rateComment = "知识点掌握得比较优秀,多练习多巩固掌握一般的知识点会有很大帮助。"; 219 rateComment = "知识点掌握得比较优秀,多练习多巩固掌握一般的知识点会有很大帮助。";
220 encComment = "在未来的学习中,请保持这份优秀,继续挑战更难的题目,勇攀高峰"; 220 encComment = "在未来的学习中,请保持这份优秀,继续挑战更难的题目,勇攀高峰!";
221 } else if (rate >= 80) { 221 } else if (rate >= 80) {
222 rateComment = "知识点掌握程度有进步,还要再继续学习,多练习,不断巩固。"; 222 rateComment = "知识点掌握程度有进步,还要再继续学习,多练习,不断巩固。";
223 encComment = "在未来的学习中,请保持这份优秀,继续挑战更难的题目,勇攀高峰"; 223 encComment = "在未来的学习中,请保持这份优秀,继续挑战更难的题目,勇攀高峰!";
224 } else if (rate >= 60) { 224 } else if (rate >= 60) {
225 rateComment = "薄弱知识点还有进步空间,再多做一些类似题目来巩固知识点,继续努力。"; 225 rateComment = "薄弱知识点还有进步空间,再多做一些类似题目来巩固知识点,继续努力。";
226 encComment = "在未来的学习中,请不要灰心,继续努力"; 226 encComment = "在未来的学习中,请不要灰心,继续努力!";
227 } else { 227 } else {
228 rateComment = "你的薄弱知识点还需要再深入了解,有不清楚的地方及时问老师,继续加油。"; 228 rateComment = "你的薄弱知识点还需要再深入了解,有不清楚的地方及时问老师,继续加油。";
229 encComment = "在未来的学习中,请不要灰心,继续努力"; 229 encComment = "在未来的学习中,请不要灰心,继续努力!";
230 } 230 }
231 231
232 String correctNumHt = fromColor(String.valueOf(data.correct), "#3BC3B6"); 232 String correctNumHt = fromColor(String.valueOf(data.correct), "#3BC3B6");
233 String errNumHt = fromColor(String.valueOf(data.total - data.correct - data.unfinished), "#3BC3B6"); 233 String errNumHt = fromColor(String.valueOf(data.total - data.correct - data.unfinished), "#3BC3B6");
234 StringBuilder pointComment = new StringBuilder("其中,答对题目 ") 234 StringBuilder pointComment = new StringBuilder("其中,答对题目 ")
235 .append(correctNumHt).append(" 个,答错题目 ") 235 .append(correctNumHt).append(" 个,答错题目 ")
236 .append(errNumHt).append(" 个"); 236 .append(errNumHt).append(" 个");
237 if (exNo > 0) { 237 if (exNo > 0) {
238 String ht = fromColor(String.valueOf(exNo), "#3BC3B6"); 238 String ht = fromColor(String.valueOf(exNo), "#3BC3B6");
239 pointComment.append(",").append(ht).append(" 个知识点非常棒"); 239 pointComment.append(",").append(ht).append(" 个知识点非常棒");
240 } 240 }
241 if (weakNo > 0) { 241 if (weakNo > 0) {
242 String ht = fromColor(String.valueOf(weakNo), "#3BC3B6"); 242 String ht = fromColor(String.valueOf(weakNo), "#3BC3B6");
243 pointComment.append(",").append(ht).append(" 个知识点还需努力,这部分还要再加强学习"); 243 pointComment.append(",").append(ht).append(" 个知识点还需努力,这部分还要再加强学习");
244 } 244 }
245 pointComment.append("。"); 245 pointComment.append("。");
246 String rateStr = new DecimalFormat("0%").format(rate / 100f); 246 String rateStr = new DecimalFormat("0%").format(rate / 100f);
247 String temp; 247 String temp;
248 if (type == 0) { 248 if (type == 0) {
249 temp = indent + "在本周作业中,你的综合正确率是 %s," + pointComment + rateComment + encComment; 249 temp = indent + "在本周作业中,你的综合正确率是 %s," + pointComment + rateComment + encComment;
250 } else { 250 } else {
251 temp = indent + "在本阶段作业中,你的综合正确率是 %s," + pointComment + rateComment + encComment; 251 temp = indent + "在本阶段作业中,你的综合正确率是 %s," + pointComment + rateComment + encComment;
252 } 252 }
253 temp = String.format(temp, fromColor(rateStr, "#3BC3B6")); 253 temp = String.format(temp, fromColor(rateStr, "#3BC3B6"));
254 binding.tvRating.setText(Html.fromHtml(temp, Html.FROM_HTML_MODE_COMPACT)); 254 binding.tvRating.setText(Html.fromHtml(temp, Html.FROM_HTML_MODE_COMPACT));
255 } 255 }
256 256
257 List<Entry> entries = new ArrayList<>(); 257 List<Entry> entries = new ArrayList<>();
258 if (type == 0) { 258 if (type == 0) {
259 entries.add(new Entry(1, data.mondayCorrection)); 259 entries.add(new Entry(1, data.mondayCorrection));
260 entries.add(new Entry(2, data.tuesdayCorrection)); 260 entries.add(new Entry(2, data.tuesdayCorrection));
261 entries.add(new Entry(3, data.wednesdayCorrection)); 261 entries.add(new Entry(3, data.wednesdayCorrection));
262 entries.add(new Entry(4, data.thursdayCorrection)); 262 entries.add(new Entry(4, data.thursdayCorrection));
263 entries.add(new Entry(5, data.fridayCorrection)); 263 entries.add(new Entry(5, data.fridayCorrection));
264 } else { 264 } else {
265 for (int i = 0; i < data.correctionList.size(); i ++) { 265 for (int i = 0; i < data.correctionList.size(); i ++) {
266 StDetail.Correction c = data.correctionList.get(i); 266 StDetail.Correction c = data.correctionList.get(i);
267 entries.add(new Entry(i, c.correction)); 267 entries.add(new Entry(i, c.correction));
268 } 268 }
269 XAxis xAxis = binding.lineChart.getXAxis(); 269 XAxis xAxis = binding.lineChart.getXAxis();
270 xAxis.setLabelCount(Math.min(entries.size(), 5), true); 270 xAxis.setLabelCount(Math.min(entries.size(), 5), true);
271 xAxis.setValueFormatter(new ValueFormatter() { 271 xAxis.setValueFormatter(new ValueFormatter() {
272 SimpleDateFormat format = new SimpleDateFormat("M.d", Locale.CHINA); 272 SimpleDateFormat format = new SimpleDateFormat("M.d", Locale.CHINA);
273 @Override 273 @Override
274 public String getFormattedValue(float value) { 274 public String getFormattedValue(float value) {
275 int index = (int) value; 275 int index = (int) value;
276 if (index < 0 || index >= data.correctionList.size()) return ""; 276 if (index < 0 || index >= data.correctionList.size()) return "";
277 Date date = data.correctionList.get(index).date; 277 Date date = data.correctionList.get(index).date;
278 return format.format(date); 278 return format.format(date);
279 } 279 }
280 }); 280 });
281 } 281 }
282 282
283 LineDataSet set = new LineDataSet(entries, ""); 283 LineDataSet set = new LineDataSet(entries, "");
284 set.setColor(0xFF3BC3B6); 284 set.setColor(0xFF3BC3B6);
285 set.setCircleColor(0xFF3BC3B6); 285 set.setCircleColor(0xFF3BC3B6);
286 set.setDrawFilled(true); 286 set.setDrawFilled(true);
287 set.setDrawCircles(type == 0 || entries.size() == 1); 287 set.setDrawCircles(type == 0 || entries.size() == 1);
288 set.setDrawValues(false); 288 set.setDrawValues(false);
289 set.setHighlightEnabled(false); 289 set.setHighlightEnabled(false);
290 set.setDrawHighlightIndicators(false); 290 set.setDrawHighlightIndicators(false);
291 set.setFillDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.bg_line_chart_fill2, null)); 291 set.setFillDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.bg_line_chart_fill2, null));
292 binding.lineChart.setData(new LineData(set)); 292 binding.lineChart.setData(new LineData(set));
293 binding.lineChart.invalidate(); 293 binding.lineChart.invalidate();
294 294
295 if (!data.points.isEmpty()) { 295 if (!data.points.isEmpty()) {
296 binding.tvExcellent.setText(String.valueOf(exNo)); 296 binding.tvExcellent.setText(String.valueOf(exNo));
297 binding.tvGood.setText(String.valueOf(goodNo)); 297 binding.tvGood.setText(String.valueOf(goodNo));
298 binding.tvNormal.setText(String.valueOf(normalNo)); 298 binding.tvNormal.setText(String.valueOf(normalNo));
299 binding.tvWeak.setText(String.valueOf(weakNo)); 299 binding.tvWeak.setText(String.valueOf(weakNo));
300 300
301 float exRate = 100f * exNo / data.points.size(); 301 float exRate = 100f * exNo / data.points.size();
302 float goodRate = 100f * goodNo / data.points.size(); 302 float goodRate = 100f * goodNo / data.points.size();
303 float normalRate = 100f * normalNo / data.points.size(); 303 float normalRate = 100f * normalNo / data.points.size();
304 float weakRate = 100f * weakNo / data.points.size(); 304 float weakRate = 100f * weakNo / data.points.size();
305 binding.cpGood.setValue(goodRate + normalRate + weakRate); 305 binding.cpGood.setValue(goodRate + normalRate + weakRate);
306 binding.cpNormal.setValue(normalRate + weakRate); 306 binding.cpNormal.setValue(normalRate + weakRate);
307 binding.cpWeak.setValue(weakRate); 307 binding.cpWeak.setValue(weakRate);
308 binding.tvAvePoint.setText(new DecimalFormat("0").format(100f * total / data.points.size())); 308 binding.tvAvePoint.setText(new DecimalFormat("0").format(100f * total / data.points.size()));
309 } 309 }
310 310
311 List<StDetail.Point> points = new ArrayList<>(); 311 List<StDetail.Point> points = new ArrayList<>();
312 for (StDetail.Point point: data.points) { 312 for (StDetail.Point point: data.points) {
313 if (point.beforeState < 1) points.add(point); 313 if (point.beforeState < 1) points.add(point);
314 } 314 }
315 binding.tableRoot.setClipToOutline(true); 315 binding.tableRoot.setClipToOutline(true);
316 binding.tableWeekRoot.setClipToOutline(true); 316 binding.tableWeekRoot.setClipToOutline(true);
317 binding.rvPoint.setAdapter(new Adapter(points)); 317 binding.rvPoint.setAdapter(new Adapter(points));
318 binding.rvWeekPoint.setAdapter(new WeekAdapter(data.points)); 318 binding.rvWeekPoint.setAdapter(new WeekAdapter(data.points));
319 binding.tableRoot.setVisibility(points.isEmpty() ? View.GONE : View.VISIBLE); 319 binding.tableRoot.setVisibility(points.isEmpty() ? View.GONE : View.VISIBLE);
320 binding.flPointDesc.setVisibility(points.isEmpty() ? View.GONE : View.VISIBLE); 320 binding.flPointDesc.setVisibility(points.isEmpty() ? View.GONE : View.VISIBLE);
321 binding.flEmptyPoints.setVisibility(points.isEmpty() ? View.VISIBLE : View.GONE); 321 binding.flEmptyPoints.setVisibility(points.isEmpty() ? View.VISIBLE : View.GONE);
322 } 322 }
323 323
324 private void setupChart() { 324 private void setupChart() {
325 binding.lineChart.getLegend().setForm(Legend.LegendForm.NONE); 325 binding.lineChart.getLegend().setForm(Legend.LegendForm.NONE);
326 binding.lineChart.setScaleEnabled(false); 326 binding.lineChart.setScaleEnabled(false);
327 binding.lineChart.setTouchEnabled(false); 327 binding.lineChart.setTouchEnabled(false);
328 binding.lineChart.setDescription(null); 328 binding.lineChart.setDescription(null);
329 binding.lineChart.getAxisRight().setEnabled(false); 329 binding.lineChart.getAxisRight().setEnabled(false);
330 YAxis yAxis = binding.lineChart.getAxisLeft(); 330 YAxis yAxis = binding.lineChart.getAxisLeft();
331 yAxis.setDrawAxisLine(false); 331 yAxis.setDrawAxisLine(false);
332 yAxis.setDrawGridLines(true); 332 yAxis.setDrawGridLines(true);
333 yAxis.setGridColor(0xFFDDDDDD); 333 yAxis.setGridColor(0xFFDDDDDD);
334 yAxis.setTextColor(0xFF333333); 334 yAxis.setTextColor(0xFF333333);
335 if (type == 0) { 335 if (type == 0) {
336 yAxis.setTextSize(16); 336 yAxis.setTextSize(16);
337 yAxis.setXOffset(16); 337 yAxis.setXOffset(16);
338 } else { 338 } else {
339 yAxis.setTextSize(13); 339 yAxis.setTextSize(13);
340 } 340 }
341 yAxis.setAxisMinimum(0); 341 yAxis.setAxisMinimum(0);
342 yAxis.setAxisMaximum(1); 342 yAxis.setAxisMaximum(1);
343 yAxis.setLabelCount(5, true); 343 yAxis.setLabelCount(5, true);
344 yAxis.setValueFormatter(new ValueFormatter() { 344 yAxis.setValueFormatter(new ValueFormatter() {
345 @Override 345 @Override
346 public String getFormattedValue(float value) { 346 public String getFormattedValue(float value) {
347 return new DecimalFormat("0%").format(value); 347 return new DecimalFormat("0%").format(value);
348 } 348 }
349 }); 349 });
350 350
351 XAxis xAxis = binding.lineChart.getXAxis(); 351 XAxis xAxis = binding.lineChart.getXAxis();
352 xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 352 xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
353 xAxis.setDrawAxisLine(false); 353 xAxis.setDrawAxisLine(false);
354 xAxis.setDrawGridLines(false); 354 xAxis.setDrawGridLines(false);
355 xAxis.setTextColor(0xFF333333); 355 xAxis.setTextColor(0xFF333333);
356 xAxis.setTextSize(16); 356 xAxis.setTextSize(16);
357 xAxis.setYOffset(16); 357 xAxis.setYOffset(16);
358 if (type == 0) { 358 if (type == 0) {
359 xAxis.setAxisMinimum(0.5f); 359 xAxis.setAxisMinimum(0.5f);
360 xAxis.setAxisMaximum(5.5f); 360 xAxis.setAxisMaximum(5.5f);
361 xAxis.setLabelCount(11, true); 361 xAxis.setLabelCount(11, true);
362 xAxis.setValueFormatter(new ValueFormatter() { 362 xAxis.setValueFormatter(new ValueFormatter() {
363 @Override 363 @Override
364 public String getFormattedValue(float value) { 364 public String getFormattedValue(float value) {
365 if (value == 1) { 365 if (value == 1) {
366 return "周一"; 366 return "周一";
367 } else if (value == 2) { 367 } else if (value == 2) {
368 return "周二"; 368 return "周二";
369 } else if (value == 3) { 369 } else if (value == 3) {
370 return "周三"; 370 return "周三";
371 } else if (value == 4) { 371 } else if (value == 4) {
372 return "周四"; 372 return "周四";
373 } else if (value == 5) { 373 } else if (value == 5) {
374 return "周五"; 374 return "周五";
375 } 375 }
376 return ""; 376 return "";
377 } 377 }
378 }); 378 });
379 } else { 379 } else {
380 xAxis.setTextSize(13); 380 xAxis.setTextSize(13);
381 } 381 }
382 } 382 }
383 383
384 private String fromColor(String str, String color) { 384 private String fromColor(String str, String color) {
385 return String.format("<font color='%s'><b>%s</b></font>", color, str); 385 return String.format("<font color='%s'><b>%s</b></font>", color, str);
386 } 386 }
387 387
388 private void switchPage() { 388 private void switchPage() {
389 Intent intent = new Intent(getIntent()); 389 Intent intent = new Intent(getIntent());
390 intent.putExtra("a4", !a4); 390 intent.putExtra("a4", !a4);
391 startActivity(intent); 391 startActivity(intent);
392 finish(); 392 finish();
393 } 393 }
394 394
395 private Uri prepareShare() { 395 private Uri prepareShare() {
396 try { 396 try {
397 binding.toolbar.setVisibility(View.INVISIBLE); 397 binding.toolbar.setVisibility(View.INVISIBLE);
398 Bitmap bitmap = BitmapUtils.shotView(binding.root); 398 Bitmap bitmap = BitmapUtils.shotView(binding.root);
399 binding.toolbar.setVisibility(View.VISIBLE); 399 binding.toolbar.setVisibility(View.VISIBLE);
400 400
401 String fileName = student.stuName + "_周作业学习报告_" + System.currentTimeMillis(); 401 String fileName = student.stuName + "_周作业学习报告_" + System.currentTimeMillis();
402 return ContentUtil.saveBitmapToGallery(this, bitmap, fileName); 402 return ContentUtil.saveBitmapToGallery(this, bitmap, fileName);
403 } catch (Exception e) { 403 } catch (Exception e) {
404 e.printStackTrace(); 404 e.printStackTrace();
405 } 405 }
406 return null; 406 return null;
407 } 407 }
408 408
409 @Override 409 @Override
410 protected ActivityHuyouDetailBinding getViewBinding() { 410 protected ActivityHuyouDetailBinding getViewBinding() {
411 a4 = getIntent().getBooleanExtra("a4", false); 411 a4 = getIntent().getBooleanExtra("a4", false);
412 View view; 412 View view;
413 if (a4) view = getLayoutInflater().inflate(R.layout.activity_huyou_detail_a4, null); 413 if (a4) view = getLayoutInflater().inflate(R.layout.activity_huyou_detail_a4, null);
414 else view = getLayoutInflater().inflate(R.layout.activity_huyou_detail, null); 414 else view = getLayoutInflater().inflate(R.layout.activity_huyou_detail, null);
415 return ActivityHuyouDetailBinding.bind(view); 415 return ActivityHuyouDetailBinding.bind(view);
416 } 416 }
417 417
418 public static class Adapter extends BaseQuickAdapter<StDetail.Point, BaseViewHolder> { 418 public static class Adapter extends BaseQuickAdapter<StDetail.Point, BaseViewHolder> {
419 419
420 public Adapter(@Nullable List<StDetail.Point> data) { 420 public Adapter(@Nullable List<StDetail.Point> data) {
421 super(R.layout.item_huyou_point, data); 421 super(R.layout.item_huyou_point, data);
422 } 422 }
423 423
424 @Override 424 @Override
425 protected void convert(@NonNull BaseViewHolder holder, StDetail.Point point) { 425 protected void convert(@NonNull BaseViewHolder holder, StDetail.Point point) {
426 DecimalFormat format1 = new DecimalFormat("0%"); 426 DecimalFormat format1 = new DecimalFormat("0%");
427 DecimalFormat format2 = new DecimalFormat("0"); 427 DecimalFormat format2 = new DecimalFormat("0");
428 holder.setText(R.id.tvName, point.pointName); 428 holder.setText(R.id.tvName, point.pointName);
429 holder.setText(R.id.tvBefore, format1.format(point.beforeState)); 429 holder.setText(R.id.tvBefore, format1.format(point.beforeState));
430 holder.setText(R.id.tvAfter, format1.format(point.afterState)); 430 holder.setText(R.id.tvAfter, format1.format(point.afterState));
431 holder.setText(R.id.tvGap, format2.format(point.gap * 100)); 431 holder.setText(R.id.tvGap, format2.format(point.gap * 100));
432 holder.setGone(R.id.ivFlag, getData().indexOf(point) == 0); 432 holder.setGone(R.id.ivFlag, getData().indexOf(point) == 0);
433 holder.<TextView>getView(R.id.tvName).setTooltipText(point.pointName); 433 holder.<TextView>getView(R.id.tvName).setTooltipText(point.pointName);
434 434
435 TextView before = holder.getView(R.id.tvBeforeState); 435 TextView before = holder.getView(R.id.tvBeforeState);
436 TextView after = holder.getView(R.id.tvAfterState); 436 TextView after = holder.getView(R.id.tvAfterState);
437 437
438 if (point.beforeState >= 0.9) { 438 if (point.beforeState >= 0.9) {
439 before.setText("掌握优秀"); 439 before.setText("掌握优秀");
440 before.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A)); 440 before.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A));
441 } else if (point.beforeState >= 0.8) { 441 } else if (point.beforeState >= 0.8) {
442 before.setText("掌握良好"); 442 before.setText("掌握良好");
443 before.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA)); 443 before.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA));
444 } else if (point.beforeState >= 0.6) { 444 } else if (point.beforeState >= 0.6) {
445 before.setText("掌握一般"); 445 before.setText("掌握一般");
446 before.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725)); 446 before.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725));
447 } else { 447 } else {
448 before.setText("掌握薄弱"); 448 before.setText("掌握薄弱");
449 before.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127)); 449 before.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127));
450 } 450 }
451 if (point.afterState >= 0.9) { 451 if (point.afterState >= 0.9) {
452 after.setText("掌握优秀"); 452 after.setText("掌握优秀");
453 after.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A)); 453 after.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A));
454 } else if (point.afterState >= 0.8) { 454 } else if (point.afterState >= 0.8) {
455 after.setText("掌握良好"); 455 after.setText("掌握良好");
456 after.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA)); 456 after.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA));
457 } else if (point.afterState >= 0.6) { 457 } else if (point.afterState >= 0.6) {
458 after.setText("掌握一般"); 458 after.setText("掌握一般");
459 after.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725)); 459 after.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725));
460 } else { 460 } else {
461 after.setText("掌握薄弱"); 461 after.setText("掌握薄弱");
462 after.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127)); 462 after.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127));
463 } 463 }
464 464
465 holder.setText(R.id.tvHuyou, format1.format(point.correctness)); 465 holder.setText(R.id.tvHuyou, format1.format(point.correctness));
466 } 466 }
467 467
468 } 468 }
469 469
470 public static class WeekAdapter extends BaseQuickAdapter<StDetail.Point, BaseViewHolder> { 470 public static class WeekAdapter extends BaseQuickAdapter<StDetail.Point, BaseViewHolder> {
471 public WeekAdapter(@Nullable List<StDetail.Point> data) { 471 public WeekAdapter(@Nullable List<StDetail.Point> data) {
472 super(R.layout.item_huyou_week_point, data); 472 super(R.layout.item_huyou_week_point, data);
473 } 473 }
474 474
475 @Override 475 @Override
476 protected void convert(@NonNull BaseViewHolder holder, StDetail.Point point) { 476 protected void convert(@NonNull BaseViewHolder holder, StDetail.Point point) {
477 holder.setText(R.id.tvName, point.pointName); 477 holder.setText(R.id.tvName, point.pointName);
478 478
479 TextView after = holder.getView(R.id.tvState); 479 TextView after = holder.getView(R.id.tvState);
480 if (point.beforeState >= 0.9) { 480 if (point.beforeState >= 0.9) {
481 after.setText("掌握优秀"); 481 after.setText("掌握优秀");
482 after.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A)); 482 after.setBackgroundTintList(ColorStateList.valueOf(0xFF4FBB7A));
483 } else if (point.beforeState >= 0.8) { 483 } else if (point.beforeState >= 0.8) {
484 after.setText("掌握良好"); 484 after.setText("掌握良好");
485 after.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA)); 485 after.setBackgroundTintList(ColorStateList.valueOf(0xFF489AFA));
486 } else if (point.beforeState >= 0.6) { 486 } else if (point.beforeState >= 0.6) {
487 after.setText("掌握一般"); 487 after.setText("掌握一般");
488 after.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725)); 488 after.setBackgroundTintList(ColorStateList.valueOf(0xFFF58725));
489 } else { 489 } else {
490 after.setText("掌握薄弱"); 490 after.setText("掌握薄弱");
491 after.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127)); 491 after.setBackgroundTintList(ColorStateList.valueOf(0xFFEA5127));
492 } 492 }
493 493
494 DecimalFormat format1 = new DecimalFormat("0%"); 494 DecimalFormat format1 = new DecimalFormat("0%");
495 holder.setText(R.id.tvHuyou, format1.format(point.beforeState)); 495 holder.setText(R.id.tvHuyou, format1.format(point.beforeState));
496 } 496 }
497 } 497 }
498 498
499 } 499 }
500 500