ErrorDetailActivity.java
7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.hjx.parent;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.widget.AdapterView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.bumptech.glide.Glide;
import com.hjx.parent.databinding.ActivityErrorDetailBinding;
import com.hjx.parent.dialog.ErrorEditDialog;
import com.prws.common.bean.ErrorDetailBean;
import com.prws.common.bean.ResponseResult;
import com.prws.common.bean.TopicBean;
import com.prws.common.net.NetWorks;
import com.prws.common.utils.CommonUtil;
import com.prws.common.utils.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding> {
private TopicBean bean;
@Override
public void initView(Bundle savedInstanceState) {
bean = (TopicBean) getIntent().getSerializableExtra("errorBean");
loadError();
}
public void loadError() {
if (bean.getBean() != null) {
binding.tvTip.setVisibility(View.GONE);
ErrorDetailBean errorDetailBean = bean.getBean();
if (TextUtils.isEmpty(errorDetailBean.getContent())) {
binding.llOrigin.setVisibility(View.GONE);
} else {
String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">";
StringBuilder sb = new StringBuilder(4096);
if (!TextUtils.isEmpty(errorDetailBean.getLabel())) {
sb.append(errorDetailBean.getLabel());
}
sb.append(errorDetailBean.getContent());
if (errorDetailBean.getOptions() != null && errorDetailBean.getOptions().size() > 0) {
sb.append("<div class='pt1'>");
sb.append(StringUtils.OptionsHtml(errorDetailBean.getOptions(), null));
sb.append("</div>");
}
String body = "<html><header>" + linkCss + "</header>" + sb.toString() + "</body></html>";
binding.webContent.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null);
binding.webContent.setVisibility(View.VISIBLE);
binding.llOrigin.setVisibility(View.VISIBLE);
binding.webContent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}
if (TextUtils.isEmpty(errorDetailBean.getMethod())) {
binding.llAnalyse.setVisibility(View.GONE);
} else {
binding.llAnalyse.setVisibility(View.VISIBLE);
String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">";
String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getMethod() + "</body></html>";
binding.webAnalyse.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null);
binding.webAnalyse.setBackgroundColor(Color.parseColor("#F5F5F5"));
}
if (TextUtils.isEmpty(errorDetailBean.getDisplayAnswer())) {
binding.llAnswer.setVisibility(View.GONE);
} else {
binding.llAnswer.setVisibility(View.VISIBLE);
String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">";
String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getDisplayAnswer() + "</body></html>";
binding.webAnswer.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null);
binding.webAnswer.setBackgroundColor(Color.parseColor("#F5F5F5"));
}
if (errorDetailBean.getPoints().size() > 0) {
List<String> points = new ArrayList<>();
String topic = "";
for (int j = 0; j < errorDetailBean.getPoints().size(); j++) {
if (j > 0) {
topic += "、";
}
topic += errorDetailBean.getPoints().get(j).getValue();
points.add(errorDetailBean.getPoints().get(j).getKey());
}
binding.llPoints.setVisibility(View.VISIBLE);
binding.tvPoints.setText(topic);
} else {
binding.llPoints.setVisibility(View.GONE);
}
} else {
binding.tvTip.setVisibility(View.VISIBLE);
binding.llAnalyse.setVisibility(View.GONE);
binding.llAnswer.setVisibility(View.GONE);
binding.llOrigin.setVisibility(View.GONE);
binding.llPoints.setVisibility(View.GONE);
}
if (TextUtils.isEmpty(bean.getPath())) {
binding.llPic.setVisibility(View.GONE);
} else {
Glide.with(context).load(bean.getPath()).override(CommonUtil.getScreenWidth(context) - CommonUtil.dpToPx(context, 40), CommonUtil.dpToPx(context, 90)).fitCenter().into(binding.ivTopic);
}
// binding.tvTitle.setText(bean.getName());
refresh();
binding.ivBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
binding.tvEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<TopicBean> topicBeans = new ArrayList<>();
topicBeans.add(bean);
ErrorEditDialog errorEditDialog = new ErrorEditDialog(context, topicBeans, new ErrorEditDialog.EditInterface() {
@Override
public void edit(String name, String grade, String subject, int type, int reason, int done) {
// binding.tvTitle.setText(name);
bean.setGrade(grade);
bean.setSubject(subject);
bean.setType(type);
bean.setDone(done == 0);
bean.setReason(reason);
refresh();
}
});
errorEditDialog.show();
}
});
}
private void refresh() {
binding.tvSubject.setText(Html.fromHtml(getString(R.string.topic_subject, bean.getSubject())));
binding.tvGrade.setText(Html.fromHtml(getString(R.string.topic_grade, bean.getGrade())));
binding.tvReason.setText(Html.fromHtml(getString(R.string.topic_reason, getResources().getStringArray(R.array.error_reason)[bean.getReason()])));
binding.tvManager.setText(Html.fromHtml(getString(R.string.topic_manager, bean.getIsDone() == 0 ? "已掌握" : "未掌握")));
binding.tvType.setText(Html.fromHtml(getString(R.string.topic_type, bean.getType() == 0 ? "课内" : "课外")));
}
@Override
protected ActivityErrorDetailBinding getViewBinding() {
return ActivityErrorDetailBinding.inflate(getLayoutInflater());
}
}