Compare View
Commits (3)
Showing
15 changed files
Show diff stats
.idea/inspectionProfiles/Project_Default.xml
1 | <component name="InspectionProjectProfileManager"> | 1 | <component name="InspectionProjectProfileManager"> |
2 | <profile version="1.0"> | 2 | <profile version="1.0"> |
3 | <option name="myName" value="Project Default" /> | 3 | <option name="myName" value="Project Default" /> |
4 | <inspection_tool class="Deprecation" enabled="false" level="WARNING" enabled_by_default="false" /> | ||
4 | <inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false"> | 5 | <inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false"> |
5 | <option name="m_reportAllNonLibraryCalls" value="false" /> | 6 | <option name="m_reportAllNonLibraryCalls" value="false" /> |
6 | <option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.AbstractStringBuilder,capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigDecimal,.*,java.math.BigInteger,.*,java.net.InetAddress,.*,java.net.URI,.*,java.nio.channels.AsynchronousChannelGroup,.*,java.nio.channels.Channel,isOpen,java.nio.channels.FileChannel,open|map|lock|tryLock|write,java.nio.channels.ScatteringByteChannel,read,java.nio.channels.SocketChannel,open|socket|isConnected|isConnectionPending,java.util.Arrays,.*,java.util.Collections,(?!addAll).*,java.util.List,of,java.util.Map,of|ofEntries|entry,java.util.Set,of,java.util.UUID,.*,java.util.concurrent.BlockingQueue,offer|remove,java.util.concurrent.CountDownLatch,await|getCount,java.util.concurrent.ExecutorService,awaitTermination|isShutdown|isTerminated,java.util.concurrent.ForkJoinPool,awaitQuiescence,java.util.concurrent.Semaphore,tryAcquire|availablePermits|isFair|hasQueuedThreads|getQueueLength|getQueuedThreads,java.util.concurrent.locks.Condition,await|awaitNanos|awaitUntil,java.util.concurrent.locks.Lock,tryLock|newCondition,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*,java.util.stream.DoubleStream,.*,java.util.stream.IntStream,.*,java.util.stream.LongStream,.*,java.util.stream.Stream,.*" /> | 7 | <option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.AbstractStringBuilder,capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigDecimal,.*,java.math.BigInteger,.*,java.net.InetAddress,.*,java.net.URI,.*,java.nio.channels.AsynchronousChannelGroup,.*,java.nio.channels.Channel,isOpen,java.nio.channels.FileChannel,open|map|lock|tryLock|write,java.nio.channels.ScatteringByteChannel,read,java.nio.channels.SocketChannel,open|socket|isConnected|isConnectionPending,java.util.Arrays,.*,java.util.Collections,(?!addAll).*,java.util.List,of,java.util.Map,of|ofEntries|entry,java.util.Set,of,java.util.UUID,.*,java.util.concurrent.BlockingQueue,offer|remove,java.util.concurrent.CountDownLatch,await|getCount,java.util.concurrent.ExecutorService,awaitTermination|isShutdown|isTerminated,java.util.concurrent.ForkJoinPool,awaitQuiescence,java.util.concurrent.Semaphore,tryAcquire|availablePermits|isFair|hasQueuedThreads|getQueueLength|getQueuedThreads,java.util.concurrent.locks.Condition,await|awaitNanos|awaitUntil,java.util.concurrent.locks.Lock,tryLock|newCondition,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*,java.util.stream.DoubleStream,.*,java.util.stream.IntStream,.*,java.util.stream.LongStream,.*,java.util.stream.Stream,.*" /> |
7 | </inspection_tool> | 8 | </inspection_tool> |
8 | </profile> | 9 | </profile> |
9 | </component> | 10 | </component> |
app/src/main/java/com/hjx/parent/ChooseActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.text.TextUtils; | 4 | import android.text.TextUtils; |
5 | import android.view.View; | 5 | import android.view.View; |
6 | import android.widget.ImageView; | 6 | import android.widget.ImageView; |
7 | import android.widget.ListView; | 7 | import android.widget.ListView; |
8 | 8 | ||
9 | import androidx.annotation.NonNull; | 9 | import androidx.annotation.NonNull; |
10 | import androidx.recyclerview.widget.LinearLayoutManager; | 10 | import androidx.recyclerview.widget.LinearLayoutManager; |
11 | import androidx.recyclerview.widget.RecyclerView; | 11 | import androidx.recyclerview.widget.RecyclerView; |
12 | 12 | ||
13 | import com.bumptech.glide.Glide; | 13 | import com.bumptech.glide.Glide; |
14 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 14 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
15 | import com.bumptech.glide.request.RequestOptions; | 15 | import com.bumptech.glide.request.RequestOptions; |
16 | import com.chad.library.adapter.base.BaseQuickAdapter; | 16 | import com.chad.library.adapter.base.BaseQuickAdapter; |
17 | import com.chad.library.adapter.base.BaseViewHolder; | 17 | import com.chad.library.adapter.base.BaseViewHolder; |
18 | import com.google.gson.Gson; | 18 | import com.google.gson.Gson; |
19 | import com.hjx.parent.bean.StudentBean; | 19 | import com.hjx.parent.bean.StudentBean; |
20 | import com.prws.common.base.BaseActivity; | 20 | import com.prws.common.base.BaseActivity; |
21 | import com.prws.common.base.BasePresenter; | 21 | import com.prws.common.base.BasePresenter; |
22 | import com.prws.common.net.NetWorks; | 22 | import com.prws.common.net.NetWorks; |
23 | import com.prws.common.utils.LogUtil; | 23 | import com.prws.common.utils.LogUtil; |
24 | import com.prws.common.utils.ScreenUtils; | 24 | import com.prws.common.utils.ScreenUtils; |
25 | import com.prws.common.utils.SharedPreferencesUtil; | 25 | import com.prws.common.utils.SharedPreferencesUtil; |
26 | 26 | ||
27 | import org.json.JSONArray; | 27 | import org.json.JSONArray; |
28 | import org.json.JSONObject; | 28 | import org.json.JSONObject; |
29 | 29 | ||
30 | import java.util.ArrayList; | 30 | import java.util.ArrayList; |
31 | 31 | ||
32 | import butterknife.BindView; | 32 | import butterknife.BindView; |
33 | import butterknife.OnClick; | 33 | import butterknife.OnClick; |
34 | import io.reactivex.Observer; | 34 | import io.reactivex.Observer; |
35 | import io.reactivex.disposables.Disposable; | 35 | import io.reactivex.disposables.Disposable; |
36 | import okhttp3.ResponseBody; | 36 | import okhttp3.ResponseBody; |
37 | 37 | ||
38 | public class ChooseActivity extends BaseActivity { | 38 | public class ChooseActivity extends BaseActivity { |
39 | @BindView(R.id.recycle) | 39 | @BindView(R.id.recycle) |
40 | RecyclerView recycle; | 40 | RecyclerView recycle; |
41 | private int select = 0; | 41 | private int select = 0; |
42 | 42 | ||
43 | @Override | 43 | @Override |
44 | protected int layoutResId() { | 44 | protected int layoutResId() { |
45 | return R.layout.choose_activity; | 45 | return R.layout.choose_activity; |
46 | } | 46 | } |
47 | 47 | ||
48 | @Override | 48 | @Override |
49 | public Object getContract() { | 49 | public Object getContract() { |
50 | return null; | 50 | return null; |
51 | } | 51 | } |
52 | 52 | ||
53 | @Override | 53 | @Override |
54 | public BasePresenter getPresenter() { | 54 | public BasePresenter getPresenter() { |
55 | return null; | 55 | return null; |
56 | } | 56 | } |
57 | 57 | ||
58 | @Override | 58 | @Override |
59 | protected void initView() { | 59 | protected void initView() { |
60 | 60 | ||
61 | } | 61 | } |
62 | 62 | ||
63 | @Override | 63 | @Override |
64 | protected void initListener() { | 64 | protected void initListener() { |
65 | 65 | ||
66 | } | 66 | } |
67 | 67 | ||
68 | @Override | 68 | @Override |
69 | protected void initData() { | 69 | protected void initData() { |
70 | 70 | ||
71 | } | 71 | } |
72 | 72 | ||
73 | @Override | 73 | @Override |
74 | public void onNetChanged(int netWorkState) { | 74 | public void onNetChanged(int netWorkState) { |
75 | 75 | ||
76 | } | 76 | } |
77 | 77 | ||
78 | @Override | 78 | @Override |
79 | protected void onResume() { | 79 | protected void onResume() { |
80 | super.onResume(); | 80 | super.onResume(); |
81 | loadChildList(); | 81 | loadChildList(); |
82 | } | 82 | } |
83 | 83 | ||
84 | ArrayList<StudentBean> alist = new ArrayList<>(); | 84 | ArrayList<StudentBean> alist = new ArrayList<>(); |
85 | 85 | ||
86 | public void loadChildList() { | 86 | public void loadChildList() { |
87 | NetWorks.listChildren(new Observer<ResponseBody>() { | 87 | NetWorks.listChildren(new Observer<ResponseBody>() { |
88 | @Override | 88 | @Override |
89 | public void onSubscribe(Disposable d) { | 89 | public void onSubscribe(Disposable d) { |
90 | 90 | ||
91 | } | 91 | } |
92 | 92 | ||
93 | @Override | 93 | @Override |
94 | public void onNext(ResponseBody responseBody) { | 94 | public void onNext(ResponseBody responseBody) { |
95 | try { | 95 | try { |
96 | String str = responseBody.string().toString(); | 96 | String str = responseBody.string().toString(); |
97 | LogUtil.e("TAG", "----" + str); | 97 | LogUtil.e("TAG", "----" + str); |
98 | JSONObject jo = new JSONObject(str); | 98 | JSONObject jo = new JSONObject(str); |
99 | boolean isSucceed = jo.getBoolean("success"); | 99 | boolean isSucceed = jo.getBoolean("success"); |
100 | if (isSucceed) { | 100 | if (isSucceed) { |
101 | JSONArray jarr = jo.getJSONArray("data"); | 101 | JSONArray jarr = jo.getJSONArray("data"); |
102 | alist.clear(); | 102 | alist.clear(); |
103 | for (int i = 0; i < jarr.length(); i++) { | 103 | for (int i = 0; i < jarr.length(); i++) { |
104 | JSONObject jo2 = jarr.getJSONObject(i); | 104 | JSONObject jo2 = jarr.getJSONObject(i); |
105 | Gson gson = new Gson(); | 105 | Gson gson = new Gson(); |
106 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); | 106 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); |
107 | alist.add(sb); | 107 | alist.add(sb); |
108 | } | 108 | } |
109 | loadList(); | 109 | loadList(); |
110 | } else { | 110 | } else { |
111 | 111 | ||
112 | } | 112 | } |
113 | } catch (Exception e) { | 113 | } catch (Exception e) { |
114 | e.printStackTrace(); | 114 | e.printStackTrace(); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | @Override | 118 | @Override |
119 | public void onError(Throwable e) { | 119 | public void onError(Throwable e) { |
120 | 120 | ||
121 | } | 121 | } |
122 | 122 | ||
123 | @Override | 123 | @Override |
124 | public void onComplete() { | 124 | public void onComplete() { |
125 | 125 | ||
126 | } | 126 | } |
127 | }); | 127 | }); |
128 | } | 128 | } |
129 | 129 | ||
130 | public void loadList() { | 130 | public void loadList() { |
131 | StudentBean sb = new StudentBean(); | 131 | StudentBean sb = new StudentBean(); |
132 | sb.setNickName("添加学生"); | 132 | sb.setNickName("添加学生"); |
133 | alist.add(sb); | 133 | alist.add(sb); |
134 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 134 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
135 | try { | 135 | try { |
136 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 136 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
137 | for (int i = 0; i < alist.size(); i++) { | 137 | for (int i = 0; i < alist.size(); i++) { |
138 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { | 138 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { |
139 | select = i; | 139 | select = i; |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | } catch (Exception e) { | 143 | } catch (Exception e) { |
144 | 144 | ||
145 | } | 145 | } |
146 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { | 146 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { |
147 | @Override | 147 | @Override |
148 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 148 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
149 | 149 | ||
150 | } | 150 | } |
151 | 151 | ||
152 | @Override | 152 | @Override |
153 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 153 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
154 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 154 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
155 | item.setText(R.id.tv_name, studentBean.getNickName()); | 155 | item.setText(R.id.tv_name, studentBean.getNickName()); |
156 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 156 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
157 | item.setVisible(R.id.rl_add, true); | 157 | item.setVisible(R.id.rl_add, true); |
158 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 158 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
159 | @Override | 159 | @Override |
160 | public void onClick(View view) { | 160 | public void onClick(View view) { |
161 | startActivity(new Intent(ChooseActivity.this, AddStudentActivity.class)); | 161 | startActivity(new Intent(ChooseActivity.this, AddStudentActivity.class)); |
162 | } | 162 | } |
163 | }); | 163 | }); |
164 | } else { | 164 | } else { |
165 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); | 165 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); |
166 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); | 166 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); |
167 | item.setVisible(R.id.rl_add, false); | 167 | item.setVisible(R.id.rl_add, false); |
168 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 168 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
169 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 169 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
170 | } else { | 170 | } else { |
171 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); | 171 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); |
172 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 172 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
173 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 173 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
174 | } | 174 | } |
175 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); | 175 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); |
176 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 176 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
177 | @Override | 177 | @Override |
178 | public void onClick(View view) { | 178 | public void onClick(View view) { |
179 | select = item.getAdapterPosition(); | 179 | select = item.getAdapterPosition(); |
180 | notifyDataSetChanged(); | 180 | notifyDataSetChanged(); |
181 | } | 181 | } |
182 | }); | 182 | }); |
183 | } | 183 | } |
184 | } | 184 | } |
185 | }; | 185 | }; |
186 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); | 186 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); |
187 | recycle.setAdapter(adapter); | 187 | recycle.setAdapter(adapter); |
188 | } | 188 | } |
189 | 189 | ||
190 | @OnClick(R.id.tv_confirm) | 190 | @OnClick(R.id.tv_confirm) |
191 | public void confirm(View view) { | 191 | public void confirm(View view) { |
192 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { | 192 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { |
193 | StudentBean studentBean = alist.get(select); | 193 | StudentBean studentBean = alist.get(select); |
194 | if (studentBean.getStuId() != null) { | 194 | if (studentBean.getStuId() != null) { |
195 | if (getIntent().getBooleanExtra("needBack", false)) { | 195 | if (getIntent().getBooleanExtra("needBack", false)) { |
196 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 196 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
197 | } else { | 197 | } else { |
198 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); | 198 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); |
199 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 199 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
200 | startActivity(intent); | 200 | startActivity(intent); |
201 | } | 201 | } |
202 | finish(); | 202 | finish(); |
203 | } | 203 | } |
204 | } | 204 | } |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 |
app/src/main/java/com/hjx/parent/EditStudentActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.annotation.SuppressLint; | ||
3 | import android.content.DialogInterface; | 4 | import android.content.DialogInterface; |
4 | import android.content.Intent; | 5 | import android.content.Intent; |
5 | import android.graphics.Bitmap; | 6 | import android.graphics.Bitmap; |
6 | import android.graphics.Color; | 7 | import android.graphics.Color; |
7 | import android.net.Uri; | 8 | import android.net.Uri; |
8 | import android.os.Build; | 9 | import android.os.Build; |
9 | import android.os.Bundle; | 10 | import android.os.Bundle; |
10 | import android.os.Environment; | 11 | import android.os.Environment; |
11 | import android.provider.MediaStore; | 12 | import android.provider.MediaStore; |
12 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
13 | import android.util.Log; | 14 | import android.util.Log; |
14 | import android.view.LayoutInflater; | 15 | import android.view.LayoutInflater; |
15 | import android.view.View; | 16 | import android.view.View; |
16 | import android.widget.Button; | 17 | import android.widget.Button; |
17 | import android.widget.ImageView; | 18 | import android.widget.ImageView; |
18 | import android.widget.LinearLayout; | 19 | import android.widget.LinearLayout; |
19 | import android.widget.RelativeLayout; | 20 | import android.widget.RelativeLayout; |
20 | import android.widget.TextView; | 21 | import android.widget.TextView; |
21 | import android.widget.Toast; | 22 | import android.widget.Toast; |
22 | 23 | ||
23 | import androidx.core.content.FileProvider; | 24 | import androidx.core.content.FileProvider; |
24 | 25 | ||
25 | import com.bumptech.glide.Glide; | 26 | import com.bumptech.glide.Glide; |
26 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 27 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
27 | import com.bumptech.glide.request.RequestOptions; | 28 | import com.bumptech.glide.request.RequestOptions; |
28 | import com.google.android.material.bottomsheet.BottomSheetDialog; | 29 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
29 | import com.google.gson.Gson; | 30 | import com.google.gson.Gson; |
30 | import com.hjq.permissions.OnPermissionCallback; | 31 | import com.hjq.permissions.OnPermissionCallback; |
31 | import com.hjq.permissions.Permission; | 32 | import com.hjq.permissions.Permission; |
32 | import com.hjq.permissions.XXPermissions; | 33 | import com.hjq.permissions.XXPermissions; |
33 | import com.hjx.parent.bean.StudentBean; | 34 | import com.hjx.parent.bean.StudentBean; |
34 | import com.prws.common.base.BaseActivity; | 35 | import com.prws.common.base.BaseActivity; |
35 | import com.prws.common.base.BasePresenter; | 36 | import com.prws.common.base.BasePresenter; |
36 | import com.prws.common.bean.ResponseResult; | 37 | import com.prws.common.bean.ResponseResult; |
37 | import com.prws.common.bean.Teacher; | 38 | import com.prws.common.bean.Teacher; |
38 | import com.prws.common.net.NetWorks; | 39 | import com.prws.common.net.NetWorks; |
39 | import com.prws.common.utils.LogUtil; | 40 | import com.prws.common.utils.LogUtil; |
40 | import com.prws.common.utils.ScreenUtils; | 41 | import com.prws.common.utils.ScreenUtils; |
41 | import com.prws.common.utils.SharedPreferencesUtil; | 42 | import com.prws.common.utils.SharedPreferencesUtil; |
42 | 43 | ||
43 | import org.json.JSONObject; | 44 | import org.json.JSONObject; |
44 | 45 | ||
45 | import java.io.File; | 46 | import java.io.File; |
46 | import java.io.FileOutputStream; | 47 | import java.io.FileOutputStream; |
47 | import java.io.IOException; | 48 | import java.io.IOException; |
48 | import java.util.HashMap; | 49 | import java.util.HashMap; |
49 | import java.util.List; | 50 | import java.util.List; |
50 | import java.util.Map; | 51 | import java.util.Map; |
51 | 52 | ||
52 | import butterknife.BindView; | 53 | import butterknife.BindView; |
53 | import butterknife.OnClick; | 54 | import butterknife.OnClick; |
54 | import io.reactivex.Observer; | 55 | import io.reactivex.Observer; |
55 | import io.reactivex.disposables.Disposable; | 56 | import io.reactivex.disposables.Disposable; |
56 | 57 | ||
57 | public class EditStudentActivity extends BaseActivity { | 58 | public class EditStudentActivity extends BaseActivity { |
58 | View view_2; | 59 | View view_2; |
59 | View view_3; | 60 | View view_3; |
60 | View view_4; | 61 | View view_4; |
61 | View view_5; | 62 | View view_5; |
62 | Button btn_next; | 63 | Button btn_next; |
63 | TextView tv_name, tv_sex, tv_nian, tv_shen; | 64 | TextView tv_name, tv_sex, tv_nian, tv_shen; |
64 | @BindView(R.id.iv_avatar) | 65 | @BindView(R.id.iv_avatar) |
65 | ImageView iv_avatar; | 66 | ImageView iv_avatar; |
66 | @BindView(R.id.tv_teacher) | 67 | @BindView(R.id.tv_teacher) |
67 | TextView tv_teacher; | 68 | TextView tv_teacher; |
68 | @BindView(R.id.iv_teacher) | 69 | @BindView(R.id.iv_teacher) |
69 | ImageView iv_teacher; | 70 | ImageView iv_teacher; |
70 | @BindView(R.id.rl_teacher) | 71 | @BindView(R.id.rl_teacher) |
71 | RelativeLayout rl_teacher; | 72 | RelativeLayout rl_teacher; |
72 | @BindView(R.id.tv_bind) | 73 | @BindView(R.id.tv_bind) |
73 | TextView tv_bind; | 74 | TextView tv_bind; |
74 | @BindView(R.id.view_6) | 75 | @BindView(R.id.view_6) |
75 | LinearLayout view_6; | 76 | LinearLayout view_6; |
76 | private static int CAMERA_REQUEST_CODE = 343; | 77 | private static int CAMERA_REQUEST_CODE = 343; |
77 | private static int ALBUM_REQUEST_CODE = 456; | 78 | private static int ALBUM_REQUEST_CODE = 456; |
78 | private static int CROP_REQUEST_CODE = 234; | 79 | private static int CROP_REQUEST_CODE = 234; |
79 | 80 | ||
80 | private static int BIND_TEACHER_CODE = 345; | 81 | private static int BIND_TEACHER_CODE = 345; |
81 | private File tempFile; | 82 | private File tempFile; |
82 | private String path; | 83 | private String path; |
83 | StudentBean studentBean; | 84 | StudentBean studentBean; |
84 | private Teacher teacher; | 85 | private Teacher teacher; |
85 | 86 | ||
86 | @Override | 87 | @Override |
87 | protected int layoutResId() { | 88 | protected int layoutResId() { |
88 | return R.layout.activity_edit_stu; | 89 | return R.layout.activity_edit_stu; |
89 | } | 90 | } |
90 | 91 | ||
91 | @Override | 92 | @Override |
92 | public Object getContract() { | 93 | public Object getContract() { |
93 | return null; | 94 | return null; |
94 | } | 95 | } |
95 | 96 | ||
96 | @Override | 97 | @Override |
97 | public BasePresenter getPresenter() { | 98 | public BasePresenter getPresenter() { |
98 | return null; | 99 | return null; |
99 | } | 100 | } |
100 | 101 | ||
101 | @Override | 102 | @Override |
102 | protected void initView() { | 103 | protected void initView() { |
103 | view_2 = findViewById(R.id.view_2); | 104 | view_2 = findViewById(R.id.view_2); |
104 | view_3 = findViewById(R.id.view_3); | 105 | view_3 = findViewById(R.id.view_3); |
105 | view_4 = findViewById(R.id.view_4); | 106 | view_4 = findViewById(R.id.view_4); |
106 | view_5 = findViewById(R.id.view_5); | 107 | view_5 = findViewById(R.id.view_5); |
107 | tv_name = findViewById(R.id.tv_name); | 108 | tv_name = findViewById(R.id.tv_name); |
108 | tv_sex = findViewById(R.id.tv_sex); | 109 | tv_sex = findViewById(R.id.tv_sex); |
109 | tv_nian = findViewById(R.id.tv_nian); | 110 | tv_nian = findViewById(R.id.tv_nian); |
110 | tv_shen = findViewById(R.id.tv_shen); | 111 | tv_shen = findViewById(R.id.tv_shen); |
111 | btn_next = findViewById(R.id.btn_next); | 112 | btn_next = findViewById(R.id.btn_next); |
112 | } | 113 | } |
113 | 114 | ||
115 | @SuppressLint({"SetTextI18n", "UseCompatLoadingForDrawables"}) | ||
114 | @Override | 116 | @Override |
115 | protected void onStart() { | 117 | protected void onStart() { |
116 | super.onStart(); | 118 | super.onStart(); |
117 | String name = (String) SharedPreferencesUtil.getData("setName", ""); | 119 | String name = (String) SharedPreferencesUtil.getData("setName", ""); |
118 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); | 120 | String sex = (String) SharedPreferencesUtil.getData("setSex", ""); |
119 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); | 121 | String nian = (String) SharedPreferencesUtil.getData("setNian", ""); |
120 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); | 122 | String shen = (String) SharedPreferencesUtil.getData("setShen", ""); |
121 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); | 123 | String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); |
122 | btn_next.setTextColor(Color.WHITE); | 124 | btn_next.setTextColor(Color.WHITE); |
123 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); | 125 | btn_next.setBackground(getResources().getDrawable(R.drawable.bg_solid_btn)); |
124 | studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class); | 126 | studentBean = new Gson().fromJson(getIntent().getStringExtra("student"), StudentBean.class); |
125 | if (name != null && name.length() > 0) { | 127 | if (name != null && name.length() > 0) { |
126 | studentBean.setNickName(name); | 128 | studentBean.setNickName(name); |
127 | } | 129 | } |
128 | if (sex != null && sex.length() > 0) { | 130 | if (sex != null && sex.length() > 0) { |
129 | studentBean.setGender("男".equals(sex) ? 0 : 1); | 131 | studentBean.setGender(sex); |
130 | } | 132 | } |
131 | if (nian != null && nian.length() > 0) { | 133 | if (nian != null && nian.length() > 0) { |
132 | studentBean.setGrade(nian); | 134 | studentBean.setGrade(nian); |
133 | studentBean.setGradeId((Integer) SharedPreferencesUtil.getData("grade", 1)); | ||
134 | } | 135 | } |
135 | if (xueq != null && xueq.length() > 0) { | 136 | if (xueq != null && xueq.length() > 0) { |
136 | studentBean.setTerm(xueq); | 137 | studentBean.setTerm(xueq); |
137 | } | 138 | } |
138 | if (shen != null && shen.length() > 0) { | 139 | if (shen != null && shen.length() > 0) { |
139 | studentBean.setParentIdentity(shen); | 140 | studentBean.setParentIdentity(shen); |
140 | } | 141 | } |
141 | tv_name.setText(studentBean.getNickName()); | 142 | tv_name.setText(studentBean.getNickName()); |
142 | tv_nian.setText(studentBean.getGrade() + studentBean.getTerm()); | 143 | tv_nian.setText(studentBean.getGrade() + studentBean.getTerm()); |
143 | tv_sex.setText(studentBean.getGender() == 0 ? "男" : "女"); | 144 | tv_sex.setText(studentBean.getGender()); |
144 | tv_shen.setText(studentBean.getParentIdentity()); | 145 | tv_shen.setText(studentBean.getParentIdentity()); |
145 | if (!TextUtils.isEmpty(studentBean.getPhoto())) { | 146 | if (!TextUtils.isEmpty(studentBean.getPhoto())) { |
146 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); | 147 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 45)); |
147 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 148 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
148 | Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar); | 149 | Glide.with(this).load(studentBean.getPhoto()).apply(options).into(iv_avatar); |
149 | } else { | 150 | } else { |
150 | iv_avatar.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 151 | iv_avatar.setImageResource("男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
151 | } | 152 | } |
152 | if (!"虚拟".equals(studentBean.getTeacherIdentity())) { | 153 | if (studentBean.getIsIntention() == 1) { |
153 | rl_teacher.setVisibility(View.VISIBLE); | 154 | rl_teacher.setVisibility(View.VISIBLE); |
154 | tv_bind.setText("重新绑定"); | 155 | tv_bind.setText("重新绑定"); |
155 | tv_teacher.setText(studentBean.getTeacherName()); | 156 | tv_teacher.setText(studentBean.getTeacherName()); |
156 | if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { | 157 | if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { |
157 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25)); | 158 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25)); |
158 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 159 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
159 | Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher); | 160 | Glide.with(this).load(studentBean.getTeacherAvatar()).apply(options).into(iv_teacher); |
160 | } else { | 161 | } else { |
161 | iv_teacher.setImageResource(studentBean.getSex() == 0 ? R.mipmap.ic_teacher_male : R.mipmap.ic_teacher_female); | 162 | iv_teacher.setImageResource(R.mipmap.ic_teacher_female); |
162 | } | 163 | } |
163 | } else { | 164 | } else { |
164 | rl_teacher.setVisibility(View.GONE); | 165 | rl_teacher.setVisibility(View.GONE); |
165 | if ((studentBean.getState() != null && studentBean.getState() == 0)) { | 166 | if ((studentBean.getState() != null && studentBean.getState() == 0)) { |
166 | tv_bind.setText("待通过"); | 167 | tv_bind.setText("待通过"); |
167 | tv_bind.setTextColor(Color.parseColor("#FF3737")); | 168 | tv_bind.setTextColor(Color.parseColor("#FF3737")); |
168 | view_6.setEnabled(false); | 169 | view_6.setEnabled(false); |
169 | } | 170 | } |
170 | } | 171 | } |
171 | 172 | ||
172 | } | 173 | } |
173 | 174 | ||
174 | @Override | 175 | @Override |
175 | protected void initListener() { | 176 | protected void initListener() { |
176 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); | 177 | view_2.setOnClickListener(view -> startActivity(NickActivity.class)); |
177 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); | 178 | view_3.setOnClickListener(view -> startActivity(SexActivity.class)); |
178 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); | 179 | view_4.setOnClickListener(view -> startActivity(NianActivity.class)); |
179 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); | 180 | view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); |
180 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); | 181 | findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); |
181 | btn_next.setOnClickListener(view -> { | 182 | btn_next.setOnClickListener(view -> { |
182 | if (teacher != null || !"虚拟".equals(studentBean.getTeacherIdentity()) || (studentBean.getState() != null && studentBean.getState() == 0)) { | 183 | if (teacher != null || studentBean.getIsIntention() == 1 || (studentBean.getState() != null && studentBean.getState() == 0)) { |
183 | editStudent(); | 184 | editStudent(); |
184 | } else { | 185 | } else { |
185 | showDialog("温馨提示", "您还未绑定老师,是否绑定?", "去绑定", "暂不绑定", new DialogInterface.OnClickListener() { | 186 | showDialog("温馨提示", "您还未绑定老师,是否绑定?", "去绑定", "暂不绑定", new DialogInterface.OnClickListener() { |
186 | @Override | 187 | @Override |
187 | public void onClick(DialogInterface dialogInterface, int i) { | 188 | public void onClick(DialogInterface dialogInterface, int i) { |
188 | dialogInterface.dismiss(); | 189 | dialogInterface.dismiss(); |
189 | showDialog("温馨提示", "您暂未绑定老师,如需绑定老师\n" + "请联系400-800-3813", "确定", "", null, new DialogInterface.OnClickListener() { | 190 | showDialog("温馨提示", "您暂未绑定老师,如需绑定老师\n" + "请联系400-800-3813", "确定", "", null, new DialogInterface.OnClickListener() { |
190 | @Override | 191 | @Override |
191 | public void onClick(DialogInterface dialogInterface, int i) { | 192 | public void onClick(DialogInterface dialogInterface, int i) { |
192 | editStudent(); | 193 | editStudent(); |
193 | } | 194 | } |
194 | }); | 195 | }); |
195 | } | 196 | } |
196 | }, new DialogInterface.OnClickListener() { | 197 | }, new DialogInterface.OnClickListener() { |
197 | @Override | 198 | @Override |
198 | public void onClick(DialogInterface dialogInterface, int i) { | 199 | public void onClick(DialogInterface dialogInterface, int i) { |
199 | Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); | 200 | Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); |
200 | startActivityForResult(intent, BIND_TEACHER_CODE); | 201 | startActivityForResult(intent, BIND_TEACHER_CODE); |
201 | } | 202 | } |
202 | }); | 203 | }); |
203 | } | 204 | } |
204 | }); | 205 | }); |
205 | } | 206 | } |
206 | 207 | ||
207 | @OnClick(R.id.view_6) | 208 | @OnClick(R.id.view_6) |
208 | public void toAddTeacher(View view) { | 209 | public void toAddTeacher(View view) { |
209 | Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); | 210 | Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); |
210 | startActivityForResult(intent, BIND_TEACHER_CODE); | 211 | startActivityForResult(intent, BIND_TEACHER_CODE); |
211 | } | 212 | } |
212 | 213 | ||
213 | public void editStudent() { | 214 | public void editStudent() { |
214 | Map map = new HashMap(); | 215 | Map<String, Object> map = new HashMap<>(); |
215 | map.put("nickName", studentBean.getNickName()); | 216 | map.put("nickName", studentBean.getNickName()); |
216 | map.put("gender", studentBean.getGender()); | 217 | map.put("gender", studentBean.getGender()); |
217 | map.put("gradeId", studentBean.getGradeId()); | ||
218 | map.put("parentIdentity", studentBean.getParentIdentity()); | 218 | map.put("parentIdentity", studentBean.getParentIdentity()); |
219 | map.put("term", studentBean.getTerm()); | 219 | map.put("term", studentBean.getTerm()); |
220 | if (teacher != null) { | 220 | if (teacher != null) { |
221 | map.put("teacherId", teacher.getId()); | 221 | map.put("teacherId", teacher.getId()); |
222 | } | 222 | } |
223 | map.put("stuId", studentBean.getStuId()); | 223 | map.put("stuId", studentBean.getStuId()); |
224 | NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() { | 224 | NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer<ResponseResult>() { |
225 | @Override | 225 | @Override |
226 | public void onSubscribe(Disposable d) { | 226 | public void onSubscribe(Disposable d) { |
227 | 227 | ||
228 | } | 228 | } |
229 | 229 | ||
230 | @Override | 230 | @Override |
231 | public void onNext(ResponseResult responseResult) { | 231 | public void onNext(ResponseResult responseResult) { |
232 | try { | 232 | try { |
233 | boolean isSucceed = responseResult.getSuccess(); | 233 | boolean isSucceed = responseResult.getSuccess(); |
234 | if (isSucceed) { | 234 | if (isSucceed) { |
235 | finish(); | 235 | finish(); |
236 | } else { | 236 | } else { |
237 | Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show(); | 237 | Toast.makeText(EditStudentActivity.this, responseResult.getMsg(), Toast.LENGTH_SHORT).show(); |
238 | } | 238 | } |
239 | } catch (Exception e) { | 239 | } catch (Exception e) { |
240 | 240 | ||
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | @Override | 244 | @Override |
245 | public void onError(Throwable e) { | 245 | public void onError(Throwable e) { |
246 | 246 | ||
247 | } | 247 | } |
248 | 248 | ||
249 | @Override | 249 | @Override |
250 | public void onComplete() { | 250 | public void onComplete() { |
251 | 251 | ||
252 | } | 252 | } |
253 | }); | 253 | }); |
254 | } | 254 | } |
255 | 255 | ||
256 | @Override | 256 | @Override |
257 | protected void initData() { | 257 | protected void initData() { |
258 | 258 | ||
259 | } | 259 | } |
260 | 260 | ||
261 | @Override | 261 | @Override |
262 | public void onNetChanged(int netWorkState) { | 262 | public void onNetChanged(int netWorkState) { |
263 | 263 | ||
264 | } | 264 | } |
265 | 265 | ||
266 | private void cropPhoto(Uri uri) { | 266 | private void cropPhoto(Uri uri) { |
267 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); | 267 | Uri contentUri = Uri.fromFile(new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg")); |
268 | Intent intent = new Intent("com.android.camera.action.CROP"); | 268 | Intent intent = new Intent("com.android.camera.action.CROP"); |
269 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 269 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
270 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 | 270 | //Android 7.0需要临时添加读取Url的权限, 添加此属性是为了解决:调用裁剪框时候提示:图片无法加载或者加载图片失败或者无法加载此图片 |
271 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 271 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
272 | } | 272 | } |
273 | intent.setDataAndType(uri, "image/*"); | 273 | intent.setDataAndType(uri, "image/*"); |
274 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 | 274 | intent.putExtra("crop", "true");//发送裁剪信号,去掉也能进行裁剪 |
275 | intent.putExtra("scale", true);// 设置缩放 | 275 | intent.putExtra("scale", true);// 设置缩放 |
276 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 | 276 | intent.putExtra("scaleUpIfNeeded", true);// 去黑边 |
277 | intent.putExtra("aspectX", 1); | 277 | intent.putExtra("aspectX", 1); |
278 | intent.putExtra("aspectY", 1); | 278 | intent.putExtra("aspectY", 1); |
279 | //上述两个属性控制裁剪框的缩放比例。 | 279 | //上述两个属性控制裁剪框的缩放比例。 |
280 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 | 280 | //当用户用手拉伸裁剪框时候,裁剪框会按照上述比例缩放。 |
281 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 | 281 | intent.putExtra("outputX", 300);//属性控制裁剪完毕,保存的图片的大小格式。 |
282 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, | 282 | intent.putExtra("outputY", 300);//你按照1:1的比例来裁剪的,如果最后成像是800*400,那么按照2:1的样式保存, |
283 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 | 283 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出裁剪文件的格式 |
284 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap | 284 | intent.putExtra("return-data", true);//是否返回裁剪后图片的Bitmap |
285 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 | 285 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);//设置输出路径 |
286 | startActivityForResult(intent, CROP_REQUEST_CODE); | 286 | startActivityForResult(intent, CROP_REQUEST_CODE); |
287 | } | 287 | } |
288 | 288 | ||
289 | @Override | 289 | @Override |
290 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | 290 | protected void onActivityResult(int requestCode, int resultCode, Intent intent) { |
291 | super.onActivityResult(requestCode, resultCode, intent); | 291 | super.onActivityResult(requestCode, resultCode, intent); |
292 | if (requestCode == CAMERA_REQUEST_CODE) { | 292 | if (requestCode == CAMERA_REQUEST_CODE) { |
293 | if (resultCode == RESULT_OK) { | 293 | if (resultCode == RESULT_OK) { |
294 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 | 294 | //用相机返回的照片去调用剪裁也需要对Uri进行处理 |
295 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 295 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
296 | Uri contentUri = FileProvider.getUriForFile(this, | 296 | Uri contentUri = FileProvider.getUriForFile(this, |
297 | this.getPackageName() + ".fileprovider", tempFile); | 297 | this.getPackageName() + ".fileprovider", tempFile); |
298 | cropPhoto(contentUri); | 298 | cropPhoto(contentUri); |
299 | } else { | 299 | } else { |
300 | cropPhoto(Uri.fromFile(tempFile)); | 300 | cropPhoto(Uri.fromFile(tempFile)); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | } else if (requestCode == ALBUM_REQUEST_CODE) { | 303 | } else if (requestCode == ALBUM_REQUEST_CODE) { |
304 | if (resultCode == RESULT_OK) { | 304 | if (resultCode == RESULT_OK) { |
305 | Uri uri = intent.getData(); | 305 | Uri uri = intent.getData(); |
306 | cropPhoto(uri); | 306 | cropPhoto(uri); |
307 | } | 307 | } |
308 | } else if (requestCode == CROP_REQUEST_CODE) { | 308 | } else if (requestCode == CROP_REQUEST_CODE) { |
309 | if (intent == null) { | 309 | if (intent == null) { |
310 | return; | 310 | return; |
311 | } | 311 | } |
312 | Bundle bundle = intent.getExtras(); | 312 | Bundle bundle = intent.getExtras(); |
313 | if (bundle != null) { | 313 | if (bundle != null) { |
314 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 | 314 | //在这里获得了剪裁后的Bitmap对象,可以用于上传 |
315 | Bitmap image = bundle.getParcelable("data"); | 315 | Bitmap image = bundle.getParcelable("data"); |
316 | //设置到ImageView上 | 316 | //设置到ImageView上 |
317 | //也可以进行一些保存、压缩等操作后上传 | 317 | //也可以进行一些保存、压缩等操作后上传 |
318 | File file = saveImage("head_output", image); | 318 | File file = saveImage("head_output", image); |
319 | uploadAvatar(file); | 319 | uploadAvatar(file); |
320 | // Log.d("dsadsadsa",path); | 320 | // Log.d("dsadsadsa",path); |
321 | } | 321 | } |
322 | } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) { | 322 | } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) { |
323 | String t = intent.getStringExtra("teacher"); | 323 | String t = intent.getStringExtra("teacher"); |
324 | teacher = new Gson().fromJson(t, Teacher.class); | 324 | teacher = new Gson().fromJson(t, Teacher.class); |
325 | rl_teacher.setVisibility(View.VISIBLE); | 325 | rl_teacher.setVisibility(View.VISIBLE); |
326 | tv_bind.setText("重新绑定"); | 326 | tv_bind.setText("重新绑定"); |
327 | tv_teacher.setText(teacher.getUserName()); | 327 | tv_teacher.setText(teacher.getUserName()); |
328 | if (!TextUtils.isEmpty(teacher.getPhoto())) { | 328 | if (!TextUtils.isEmpty(teacher.getPhoto())) { |
329 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 20)); | 329 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 20)); |
330 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 330 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
331 | Glide.with(EditStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); | 331 | Glide.with(EditStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | private void uploadAvatar(File file) { | 336 | private void uploadAvatar(File file) { |
337 | NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() { | 337 | NetWorks.uploadStudentAvatar(file, studentBean.getStuId(), new Observer<ResponseResult<Map<String, String>>>() { |
338 | @Override | 338 | @Override |
339 | public void onSubscribe(Disposable d) { | 339 | public void onSubscribe(Disposable d) { |
340 | 340 | ||
341 | } | 341 | } |
342 | 342 | ||
343 | @Override | 343 | @Override |
344 | public void onNext(ResponseResult<Map<String, String>> responseBody) { | 344 | public void onNext(ResponseResult<Map<String, String>> responseBody) { |
345 | if (responseBody.getData() != null && responseBody.getCode() == 200) { | 345 | if (responseBody.getData() != null && responseBody.getCode() == 200) { |
346 | String filePath = responseBody.getData().get("imageUrl"); | 346 | String filePath = responseBody.getData().get("imageUrl"); |
347 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45)); | 347 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 45)); |
348 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 348 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
349 | Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar); | 349 | Glide.with(EditStudentActivity.this).load(filePath).apply(options).into(iv_avatar); |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | @Override | 353 | @Override |
354 | public void onError(Throwable e) { | 354 | public void onError(Throwable e) { |
355 | e.toString(); | 355 | e.toString(); |
356 | } | 356 | } |
357 | 357 | ||
358 | @Override | 358 | @Override |
359 | public void onComplete() { | 359 | public void onComplete() { |
360 | 360 | ||
361 | } | 361 | } |
362 | }); | 362 | }); |
363 | } | 363 | } |
364 | 364 | ||
365 | public File saveImage(String name, Bitmap bmp) { | 365 | public File saveImage(String name, Bitmap bmp) { |
366 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); | 366 | File appDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath()); |
367 | if (!appDir.exists()) { | 367 | if (!appDir.exists()) { |
368 | appDir.mkdir(); | 368 | appDir.mkdir(); |
369 | } | 369 | } |
370 | String fileName = name + ".jpg"; | 370 | String fileName = name + ".jpg"; |
371 | File file = new File(appDir, fileName); | 371 | File file = new File(appDir, fileName); |
372 | try { | 372 | try { |
373 | FileOutputStream fos = new FileOutputStream(file); | 373 | FileOutputStream fos = new FileOutputStream(file); |
374 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); | 374 | bmp.compress(Bitmap.CompressFormat.PNG, 100, fos); |
375 | fos.flush(); | 375 | fos.flush(); |
376 | fos.close(); | 376 | fos.close(); |
377 | return file; | 377 | return file; |
378 | } catch (IOException e) { | 378 | } catch (IOException e) { |
379 | Log.d("dsadsadsa", e.getLocalizedMessage()); | 379 | Log.d("dsadsadsa", e.getLocalizedMessage()); |
380 | e.printStackTrace(); | 380 | e.printStackTrace(); |
381 | } | 381 | } |
382 | return null; | 382 | return null; |
383 | } | 383 | } |
384 | 384 | ||
385 | private void getPicFromCamera() { | 385 | private void getPicFromCamera() { |
386 | //用于保存调用相机拍照后所生成的文件 | 386 | //用于保存调用相机拍照后所生成的文件 |
387 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); | 387 | tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"); |
388 | //跳转到调用系统相机 | 388 | //跳转到调用系统相机 |
389 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 389 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
390 | //判断版本 | 390 | //判断版本 |
391 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri | 391 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //如果在Android7.0以上,使用FileProvider获取Uri |
392 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 392 | intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
393 | Uri contentUri = FileProvider.getUriForFile(this, | 393 | Uri contentUri = FileProvider.getUriForFile(this, |
394 | this.getPackageName() + ".fileprovider", tempFile); | 394 | this.getPackageName() + ".fileprovider", tempFile); |
395 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); | 395 | intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri); |
396 | } else { //否则使用Uri.fromFile(file)方法获取Uri | 396 | } else { //否则使用Uri.fromFile(file)方法获取Uri |
397 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); | 397 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); |
398 | } | 398 | } |
399 | startActivityForResult(intent, CAMERA_REQUEST_CODE); | 399 | startActivityForResult(intent, CAMERA_REQUEST_CODE); |
400 | } | 400 | } |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * 从相册获取图片 | 403 | * 从相册获取图片 |
404 | */ | 404 | */ |
405 | private void getPicFromAlbm() { | 405 | private void getPicFromAlbm() { |
406 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); | 406 | Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); |
407 | photoPickerIntent.setType("image/*"); | 407 | photoPickerIntent.setType("image/*"); |
408 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); | 408 | startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); |
409 | } | 409 | } |
410 | 410 | ||
411 | @Override | 411 | @Override |
412 | protected void onDestroy() { | 412 | protected void onDestroy() { |
413 | super.onDestroy(); | 413 | super.onDestroy(); |
414 | SharedPreferencesUtil.putData("setName", ""); | 414 | SharedPreferencesUtil.putData("setName", ""); |
415 | SharedPreferencesUtil.putData("setSex", ""); | 415 | SharedPreferencesUtil.putData("setSex", ""); |
416 | SharedPreferencesUtil.putData("setNian", ""); | 416 | SharedPreferencesUtil.putData("setNian", ""); |
417 | SharedPreferencesUtil.putData("setShen", ""); | 417 | SharedPreferencesUtil.putData("setShen", ""); |
418 | SharedPreferencesUtil.putData("setXueq", ""); | 418 | SharedPreferencesUtil.putData("setXueq", ""); |
419 | SharedPreferencesUtil.putData("grade", 0); | 419 | SharedPreferencesUtil.putData("grade", 0); |
420 | } | 420 | } |
421 | 421 | ||
422 | @OnClick(R.id.iv_avatar) | 422 | @OnClick(R.id.iv_avatar) |
423 | public void showButtonDialog(View view) { | 423 | public void showButtonDialog(View view) { |
424 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); | 424 | BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); |
425 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); | 425 | View bottomView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_layout, null); |
426 | dialog.setContentView(bottomView); | 426 | dialog.setContentView(bottomView); |
427 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { | 427 | bottomView.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() { |
428 | @Override | 428 | @Override |
429 | public void onClick(View view) { | 429 | public void onClick(View view) { |
430 | dialog.dismiss(); | 430 | dialog.dismiss(); |
431 | if (!XXPermissions.isGranted(EditStudentActivity.this, Permission.CAMERA)) { | 431 | if (!XXPermissions.isGranted(EditStudentActivity.this, Permission.CAMERA)) { |
432 | XXPermissions.with(EditStudentActivity.this) | 432 | XXPermissions.with(EditStudentActivity.this) |
433 | // 申请多个权限 | 433 | // 申请多个权限 |
434 | .permission(Permission.CAMERA) | 434 | .permission(Permission.CAMERA) |
435 | .request(new OnPermissionCallback() { | 435 | .request(new OnPermissionCallback() { |
436 | @Override | 436 | @Override |
437 | public void onGranted(List<String> permissions, boolean all) { | 437 | public void onGranted(List<String> permissions, boolean all) { |
438 | if (all) { | 438 | if (all) { |
439 | //开启扫码界面 | 439 | //开启扫码界面 |
440 | getPicFromCamera(); | 440 | getPicFromCamera(); |
441 | } else { | 441 | } else { |
442 | Toast.makeText(EditStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | 442 | Toast.makeText(EditStudentActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); |
443 | } | 443 | } |
444 | } | 444 | } |
445 | 445 | ||
446 | @Override | 446 | @Override |
447 | public void onDenied(List<String> permissions, boolean never) { | 447 | public void onDenied(List<String> permissions, boolean never) { |
448 | XXPermissions.startPermissionActivity(EditStudentActivity.this, permissions); | 448 | XXPermissions.startPermissionActivity(EditStudentActivity.this, permissions); |
449 | } | 449 | } |
450 | }); | 450 | }); |
451 | } else { | 451 | } else { |
452 | getPicFromCamera(); | 452 | getPicFromCamera(); |
453 | } | 453 | } |
454 | 454 | ||
455 | } | 455 | } |
456 | }); | 456 | }); |
457 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { | 457 | bottomView.findViewById(R.id.choose_photo).setOnClickListener(new View.OnClickListener() { |
458 | @Override | 458 | @Override |
459 | public void onClick(View view) { | 459 | public void onClick(View view) { |
460 | dialog.dismiss(); | 460 | dialog.dismiss(); |
461 | getPicFromAlbm(); | 461 | getPicFromAlbm(); |
462 | } | 462 | } |
463 | }); | 463 | }); |
464 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { | 464 | bottomView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { |
465 | @Override | 465 | @Override |
466 | public void onClick(View view) { | 466 | public void onClick(View view) { |
467 | dialog.dismiss(); | 467 | dialog.dismiss(); |
468 | } | 468 | } |
469 | }); | 469 | }); |
470 | dialog.show(); | 470 | dialog.show(); |
471 | } | 471 | } |
472 | 472 | ||
473 | 473 |
app/src/main/java/com/hjx/parent/LoginActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.telephony.PhoneNumberUtils; | 5 | import android.telephony.PhoneNumberUtils; |
6 | import android.text.InputType; | 6 | import android.text.InputType; |
7 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
8 | import android.text.method.HideReturnsTransformationMethod; | 8 | import android.text.method.HideReturnsTransformationMethod; |
9 | import android.text.method.PasswordTransformationMethod; | 9 | import android.text.method.PasswordTransformationMethod; |
10 | import android.widget.Button; | 10 | import android.widget.Button; |
11 | import android.widget.CheckBox; | 11 | import android.widget.CheckBox; |
12 | import android.widget.EditText; | 12 | import android.widget.EditText; |
13 | import android.widget.ImageView; | 13 | import android.widget.ImageView; |
14 | import android.widget.TextView; | 14 | import android.widget.TextView; |
15 | import android.widget.Toast; | 15 | import android.widget.Toast; |
16 | 16 | ||
17 | import androidx.appcompat.app.AppCompatActivity; | 17 | import androidx.appcompat.app.AppCompatActivity; |
18 | 18 | ||
19 | import com.prws.common.base.BaseActivity; | 19 | import com.prws.common.base.BaseActivity; |
20 | import com.prws.common.base.BasePresenter; | 20 | import com.prws.common.base.BasePresenter; |
21 | import com.prws.common.bean.BaseEntity; | 21 | import com.prws.common.bean.BaseEntity; |
22 | import com.prws.common.net.NetWorks; | 22 | import com.prws.common.net.NetWorks; |
23 | import com.prws.common.utils.LogUtil; | 23 | import com.prws.common.utils.LogUtil; |
24 | import com.prws.common.utils.SharedPreferencesUtil; | 24 | import com.prws.common.utils.SharedPreferencesUtil; |
25 | import com.prws.common.utils.acmanager.ActivityManager; | 25 | import com.prws.common.utils.acmanager.ActivityManager; |
26 | 26 | ||
27 | import org.json.JSONObject; | 27 | import org.json.JSONObject; |
28 | 28 | ||
29 | import java.io.IOException; | 29 | import java.io.IOException; |
30 | import java.util.HashMap; | 30 | import java.util.HashMap; |
31 | import java.util.Map; | 31 | import java.util.Map; |
32 | 32 | ||
33 | import io.reactivex.Observer; | 33 | import io.reactivex.Observer; |
34 | import io.reactivex.disposables.Disposable; | 34 | import io.reactivex.disposables.Disposable; |
35 | import okhttp3.ResponseBody; | 35 | import okhttp3.ResponseBody; |
36 | 36 | ||
37 | 37 | ||
38 | public class LoginActivity extends BaseActivity { | 38 | public class LoginActivity extends BaseActivity { |
39 | 39 | ||
40 | 40 | ||
41 | EditText et_phone; | 41 | EditText et_phone; |
42 | EditText et_pwd; | 42 | EditText et_pwd; |
43 | ImageView iv_show; | 43 | ImageView iv_show; |
44 | ImageView iv_delete; | 44 | ImageView iv_delete; |
45 | Button btn_login; | 45 | Button btn_login; |
46 | TextView tv_reg; | 46 | TextView tv_reg; |
47 | CheckBox cb_1; | 47 | CheckBox cb_1; |
48 | TextView tv_user; | 48 | TextView tv_user; |
49 | TextView tv_ys; | 49 | TextView tv_ys; |
50 | 50 | ||
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | protected int layoutResId() { | 53 | protected int layoutResId() { |
54 | return R.layout.activity_login; | 54 | return R.layout.activity_login; |
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | public Object getContract() { | 58 | public Object getContract() { |
59 | return null; | 59 | return null; |
60 | } | 60 | } |
61 | 61 | ||
62 | @Override | 62 | @Override |
63 | public BasePresenter getPresenter() { | 63 | public BasePresenter getPresenter() { |
64 | return null; | 64 | return null; |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | @Override | 68 | @Override |
69 | protected void initView() { | 69 | protected void initView() { |
70 | et_phone = findViewById(R.id.et_phone); | 70 | et_phone = findViewById(R.id.et_phone); |
71 | et_pwd = findViewById(R.id.et_pwd); | 71 | et_pwd = findViewById(R.id.et_pwd); |
72 | iv_show = findViewById(R.id.iv_4); | 72 | iv_show = findViewById(R.id.iv_4); |
73 | iv_delete = findViewById(R.id.iv_2); | 73 | iv_delete = findViewById(R.id.iv_2); |
74 | btn_login = findViewById(R.id.btn_1); | 74 | btn_login = findViewById(R.id.btn_1); |
75 | tv_reg = findViewById(R.id.tv_2); | 75 | tv_reg = findViewById(R.id.tv_2); |
76 | cb_1 = findViewById(R.id.cb_1); | 76 | cb_1 = findViewById(R.id.cb_1); |
77 | tv_user = findViewById(R.id.tv_4); | 77 | tv_user = findViewById(R.id.tv_4); |
78 | tv_ys = findViewById(R.id.tv_6); | 78 | tv_ys = findViewById(R.id.tv_6); |
79 | 79 | ||
80 | 80 | ||
81 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 81 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
82 | 82 | ||
83 | if (!TextUtils.isEmpty(student)) { | 83 | if (!TextUtils.isEmpty(student)) { |
84 | LogUtil.e(TAG, "role 不是空----"); | 84 | LogUtil.e(TAG, "role 不是空----"); |
85 | if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { | 85 | if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { |
86 | Intent intent = new Intent(this, MainActivity.class); | 86 | Intent intent = new Intent(this, MainActivity.class); |
87 | startActivity(intent); | 87 | startActivity(intent); |
88 | finish(); | 88 | finish(); |
89 | } else { | 89 | } else { |
90 | Intent intent = new Intent(this, TeacherMainActivity.class); | 90 | Intent intent = new Intent(this, TeacherMainActivity.class); |
91 | startActivity(intent); | 91 | startActivity(intent); |
92 | finish(); | 92 | finish(); |
93 | } | 93 | } |
94 | return; | 94 | return; |
95 | } else { | 95 | } else { |
96 | LogUtil.e(TAG, "role 是空----"); | 96 | LogUtil.e(TAG, "role 是空----"); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | } | 100 | } |
101 | 101 | ||
102 | @Override | 102 | @Override |
103 | protected void initListener() { | 103 | protected void initListener() { |
104 | iv_delete.setOnClickListener(view -> { | 104 | iv_delete.setOnClickListener(view -> { |
105 | et_phone.setText(""); | 105 | et_phone.setText(""); |
106 | }); | 106 | }); |
107 | iv_show.setOnClickListener(view -> { | 107 | iv_show.setOnClickListener(view -> { |
108 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { | 108 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { |
109 | iv_show.setBackgroundResource(R.mipmap.yc); | 109 | iv_show.setBackgroundResource(R.mipmap.yc); |
110 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | 110 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
111 | et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | 111 | et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); |
112 | } else { | 112 | } else { |
113 | iv_show.setBackgroundResource(R.mipmap.xs); | 113 | iv_show.setBackgroundResource(R.mipmap.xs); |
114 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | 114 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
115 | et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); | 115 | et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
116 | } | 116 | } |
117 | }); | 117 | }); |
118 | 118 | ||
119 | 119 | ||
120 | btn_login.setOnClickListener(view -> { | 120 | btn_login.setOnClickListener(view -> { |
121 | 121 | ||
122 | String phone = et_phone.getText().toString().trim(); | 122 | String phone = et_phone.getText().toString().trim(); |
123 | String pwd = et_pwd.getText().toString().trim(); | 123 | String pwd = et_pwd.getText().toString().trim(); |
124 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { | 124 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { |
125 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); | 125 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | 128 | ||
129 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { | 129 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { |
130 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); | 130 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | 133 | ||
134 | if (!cb_1.isChecked()) { | 134 | if (!cb_1.isChecked()) { |
135 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); | 135 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); |
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | 138 | ||
139 | login(phone, pwd); | 139 | login(phone, pwd); |
140 | 140 | ||
141 | }); | 141 | }); |
142 | 142 | ||
143 | tv_reg.setOnClickListener(view -> { | 143 | tv_reg.setOnClickListener(view -> { |
144 | startActivity(RegisterActivity.class); | 144 | startActivity(RegisterActivity.class); |
145 | finish(); | 145 | finish(); |
146 | }); | 146 | }); |
147 | 147 | ||
148 | tv_ys.setOnClickListener(view -> { | 148 | tv_ys.setOnClickListener(view -> { |
149 | startActivity(YinsiActivity.class); | 149 | startActivity(YinsiActivity.class); |
150 | }); | 150 | }); |
151 | tv_user.setOnClickListener(view -> { | 151 | tv_user.setOnClickListener(view -> { |
152 | startActivity(UserAgreementActivity.class); | 152 | startActivity(UserAgreementActivity.class); |
153 | }); | 153 | }); |
154 | } | 154 | } |
155 | 155 | ||
156 | public void login(final String phone, String pwd) { | 156 | public void login(final String phone, String pwd) { |
157 | 157 | ||
158 | Map map = new HashMap(); | 158 | Map map = new HashMap(); |
159 | map.put("username", phone); | 159 | map.put("username", phone); |
160 | map.put("password", pwd); | 160 | map.put("password", pwd); |
161 | 161 | ||
162 | 162 | ||
163 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 163 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
164 | @Override | 164 | @Override |
165 | public void onSubscribe(Disposable d) { | 165 | public void onSubscribe(Disposable d) { |
166 | 166 | ||
167 | } | 167 | } |
168 | 168 | ||
169 | @Override | 169 | @Override |
170 | public void onNext(ResponseBody responseBody) { | 170 | public void onNext(ResponseBody responseBody) { |
171 | try { | 171 | try { |
172 | String str = responseBody.string().toString(); | 172 | String str = responseBody.string().toString(); |
173 | LogUtil.e(TAG, "----" + str); | 173 | LogUtil.e(TAG, "----" + str); |
174 | JSONObject jo = new JSONObject(str); | 174 | JSONObject jo = new JSONObject(str); |
175 | boolean isSucceed = jo.getBoolean("success"); | 175 | boolean isSucceed = jo.getBoolean("success"); |
176 | if (isSucceed) { | 176 | if (isSucceed) { |
177 | JSONObject jo2 = jo.getJSONObject("data"); | 177 | JSONObject jo2 = jo.getJSONObject("data"); |
178 | String role = jo2.getString("role"); | 178 | String role = jo2.getString("role"); |
179 | if ("parent".equals(role)) { | ||
179 | if ("parent".equals(role)) { | 180 | SharedPreferencesUtil.putData("phone", phone); |
180 | SharedPreferencesUtil.putData("phone", phone); | 181 | SharedPreferencesUtil.putData("role", role); |
181 | SharedPreferencesUtil.putData("role", role); | 182 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); |
182 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); | 183 | SharedPreferencesUtil.putData("token", jo2.getString("token")); |
183 | SharedPreferencesUtil.putData("token", jo2.getString("token")); | 184 | if (jo2.has("photo") && !jo2.getString("photo").equals("null")) { |
184 | if (jo2.has("photo") && !jo2.getString("photo").equals("null")) { | 185 | SharedPreferencesUtil.putData("photo", jo2.getString("photo")); |
185 | SharedPreferencesUtil.putData("photo", jo2.getString("photo")); | ||
186 | } | 186 | } |
187 | SharedPreferencesUtil.putData("name", jo2.getString("username")); | 187 | SharedPreferencesUtil.putData("name", jo2.getString("username")); |
188 | startActivity(ChooseActivity.class); | 188 | startActivity(ChooseActivity.class); |
189 | finish(); | 189 | finish(); |
190 | } else if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) { | 190 | } else if ("member_advisor".equals(role) || "teaching_supervision".equals(role)) { |
191 | SharedPreferencesUtil.putData("phone", phone); | 191 | SharedPreferencesUtil.putData("phone", phone); |
192 | SharedPreferencesUtil.putData("role", role); | 192 | SharedPreferencesUtil.putData("role", role); |
193 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); | 193 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); |
194 | SharedPreferencesUtil.putData("token", jo2.getString("token")); | 194 | SharedPreferencesUtil.putData("token", jo2.getString("token")); |
195 | SharedPreferencesUtil.putData("name", jo2.getString("username")); | 195 | SharedPreferencesUtil.putData("name", jo2.getString("username")); |
196 | SharedPreferencesUtil.putData("photo", jo2.getString("photo")); | 196 | SharedPreferencesUtil.putData("photo", jo2.getString("photo")); |
197 | startActivity(TeacherChooseActivity.class); | ||
198 | finish(); | 197 | startActivity(TeacherChooseActivity.class); |
199 | } else { | 198 | finish(); |
200 | showToast("您没有权限"); | 199 | } else { |
201 | } | 200 | showToast("您没有权限"); |
202 | 201 | } | |
203 | } else { | 202 | |
204 | Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 203 | } else { |
205 | } | 204 | Toast.makeText(LoginActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
206 | } catch (Exception e) { | 205 | } |
207 | e.printStackTrace(); | 206 | } catch (Exception e) { |
208 | Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 207 | e.printStackTrace(); |
209 | } | 208 | Toast.makeText(LoginActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
210 | } | 209 | } |
211 | 210 | } | |
212 | @Override | 211 | |
213 | public void onError(Throwable e) { | 212 | @Override |
214 | 213 | public void onError(Throwable e) { | |
215 | } | 214 | |
216 | 215 | } | |
217 | @Override | 216 | |
218 | public void onComplete() { | 217 | @Override |
219 | 218 | public void onComplete() { | |
220 | } | 219 | |
221 | }); | 220 | } |
222 | } | 221 | }); |
223 | 222 | } | |
224 | 223 | ||
225 | @Override | 224 | |
226 | protected void initData() { | 225 | @Override |
227 | 226 | protected void initData() { | |
228 | } | 227 | |
229 | 228 | } | |
230 | @Override | 229 | |
231 | public void onNetChanged(int netWorkState) { | 230 | @Override |
232 | 231 | public void onNetChanged(int netWorkState) { | |
233 | } | 232 |
app/src/main/java/com/hjx/parent/RegisterActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.telephony.PhoneNumberUtils; | 5 | import android.telephony.PhoneNumberUtils; |
6 | import android.text.InputType; | 6 | import android.text.InputType; |
7 | import android.text.method.HideReturnsTransformationMethod; | 7 | import android.text.method.HideReturnsTransformationMethod; |
8 | import android.text.method.PasswordTransformationMethod; | 8 | import android.text.method.PasswordTransformationMethod; |
9 | import android.widget.Button; | 9 | import android.widget.Button; |
10 | import android.widget.CheckBox; | 10 | import android.widget.CheckBox; |
11 | import android.widget.EditText; | 11 | import android.widget.EditText; |
12 | import android.widget.ImageView; | 12 | import android.widget.ImageView; |
13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
14 | import android.widget.Toast; | 14 | import android.widget.Toast; |
15 | 15 | ||
16 | import androidx.annotation.Nullable; | 16 | import androidx.annotation.Nullable; |
17 | 17 | ||
18 | import com.google.gson.Gson; | 18 | import com.google.gson.Gson; |
19 | import com.hjq.permissions.OnPermissionCallback; | 19 | import com.hjq.permissions.OnPermissionCallback; |
20 | import com.hjq.permissions.Permission; | 20 | import com.hjq.permissions.Permission; |
21 | import com.hjq.permissions.XXPermissions; | 21 | import com.hjq.permissions.XXPermissions; |
22 | import com.hjx.parent.bean.RegisterBean; | 22 | import com.hjx.parent.bean.RegisterBean; |
23 | import com.prws.common.base.BaseActivity; | 23 | import com.prws.common.base.BaseActivity; |
24 | import com.prws.common.base.BasePresenter; | 24 | import com.prws.common.base.BasePresenter; |
25 | import com.prws.common.bean.BaseEntity; | 25 | import com.prws.common.bean.BaseEntity; |
26 | import com.prws.common.net.NetWorks; | 26 | import com.prws.common.net.NetWorks; |
27 | import com.prws.common.utils.Common; | 27 | import com.prws.common.utils.Common; |
28 | import com.prws.common.utils.GsonUtil; | 28 | import com.prws.common.utils.GsonUtil; |
29 | import com.prws.common.utils.LogUtil; | 29 | import com.prws.common.utils.LogUtil; |
30 | import com.prws.common.utils.SharedPreferencesUtil; | 30 | import com.prws.common.utils.SharedPreferencesUtil; |
31 | import com.uuzuche.lib_zxing.activity.CaptureActivity; | 31 | import com.uuzuche.lib_zxing.activity.CaptureActivity; |
32 | import com.uuzuche.lib_zxing.activity.CodeUtils; | 32 | import com.uuzuche.lib_zxing.activity.CodeUtils; |
33 | 33 | ||
34 | import org.json.JSONObject; | 34 | import org.json.JSONObject; |
35 | 35 | ||
36 | import java.io.IOException; | 36 | import java.io.IOException; |
37 | import java.util.HashMap; | 37 | import java.util.HashMap; |
38 | import java.util.List; | 38 | import java.util.List; |
39 | import java.util.Map; | 39 | import java.util.Map; |
40 | 40 | ||
41 | import io.reactivex.Observer; | 41 | import io.reactivex.Observer; |
42 | import io.reactivex.disposables.Disposable; | 42 | import io.reactivex.disposables.Disposable; |
43 | import okhttp3.ResponseBody; | 43 | import okhttp3.ResponseBody; |
44 | 44 | ||
45 | public class RegisterActivity extends BaseActivity { | 45 | public class RegisterActivity extends BaseActivity { |
46 | 46 | ||
47 | EditText et_phone; | 47 | EditText et_phone; |
48 | EditText et_pwd; | 48 | EditText et_pwd; |
49 | EditText et_pwd_2; | 49 | EditText et_pwd_2; |
50 | ImageView iv_show; | 50 | ImageView iv_show; |
51 | ImageView iv_show_2; | 51 | ImageView iv_show_2; |
52 | ImageView iv_delete; | 52 | ImageView iv_delete; |
53 | Button btn_reg; | 53 | Button btn_reg; |
54 | TextView tv_log; | 54 | TextView tv_log; |
55 | CheckBox cb_1; | 55 | CheckBox cb_1; |
56 | TextView tv_user; | 56 | TextView tv_user; |
57 | TextView tv_ys; | 57 | TextView tv_ys; |
58 | 58 | ||
59 | 59 | ||
60 | @Override | 60 | @Override |
61 | protected int layoutResId() { | 61 | protected int layoutResId() { |
62 | return R.layout.activity_register; | 62 | return R.layout.activity_register; |
63 | } | 63 | } |
64 | 64 | ||
65 | @Override | 65 | @Override |
66 | public Object getContract() { | 66 | public Object getContract() { |
67 | return null; | 67 | return null; |
68 | } | 68 | } |
69 | 69 | ||
70 | @Override | 70 | @Override |
71 | public BasePresenter getPresenter() { | 71 | public BasePresenter getPresenter() { |
72 | return null; | 72 | return null; |
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | protected void initView() { | 76 | protected void initView() { |
77 | et_phone = findViewById(R.id.et_phone); | 77 | et_phone = findViewById(R.id.et_phone); |
78 | et_pwd = findViewById(R.id.et_pwd); | 78 | et_pwd = findViewById(R.id.et_pwd); |
79 | iv_show = findViewById(R.id.iv_4); | 79 | iv_show = findViewById(R.id.iv_4); |
80 | iv_show_2 = findViewById(R.id.iv_6); | 80 | iv_show_2 = findViewById(R.id.iv_6); |
81 | et_pwd_2 = findViewById(R.id.et_pwd_2); | 81 | et_pwd_2 = findViewById(R.id.et_pwd_2); |
82 | iv_delete = findViewById(R.id.iv_2); | 82 | iv_delete = findViewById(R.id.iv_2); |
83 | btn_reg = findViewById(R.id.btn_1); | 83 | btn_reg = findViewById(R.id.btn_1); |
84 | tv_log = findViewById(R.id.tv_2); | 84 | tv_log = findViewById(R.id.tv_2); |
85 | cb_1 = findViewById(R.id.cb_1); | 85 | cb_1 = findViewById(R.id.cb_1); |
86 | tv_user = findViewById(R.id.tv_4); | 86 | tv_user = findViewById(R.id.tv_4); |
87 | tv_ys = findViewById(R.id.tv_6); | 87 | tv_ys = findViewById(R.id.tv_6); |
88 | 88 | ||
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | protected void initListener() { | 93 | protected void initListener() { |
94 | iv_delete.setOnClickListener(view -> { | 94 | iv_delete.setOnClickListener(view -> { |
95 | et_phone.setText(""); | 95 | et_phone.setText(""); |
96 | }); | 96 | }); |
97 | iv_show.setOnClickListener(view -> { | 97 | iv_show.setOnClickListener(view -> { |
98 | 98 | ||
99 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { | 99 | if (iv_show.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { |
100 | iv_show.setBackgroundResource(R.mipmap.yc); | 100 | iv_show.setBackgroundResource(R.mipmap.yc); |
101 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | 101 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
102 | et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | 102 | et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); |
103 | } else { | 103 | } else { |
104 | iv_show.setBackgroundResource(R.mipmap.xs); | 104 | iv_show.setBackgroundResource(R.mipmap.xs); |
105 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | 105 | et_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
106 | et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); | 106 | et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | }); | 110 | }); |
111 | 111 | ||
112 | iv_show_2.setOnClickListener(view -> { | 112 | iv_show_2.setOnClickListener(view -> { |
113 | 113 | ||
114 | if (iv_show_2.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { | 114 | if (iv_show_2.getBackground().getConstantState().equals(getDrawable(R.mipmap.xs).getConstantState())) { |
115 | iv_show_2.setBackgroundResource(R.mipmap.yc); | 115 | iv_show_2.setBackgroundResource(R.mipmap.yc); |
116 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | 116 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); |
117 | et_pwd_2.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); | 117 | et_pwd_2.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); |
118 | } else { | 118 | } else { |
119 | iv_show_2.setBackgroundResource(R.mipmap.xs); | 119 | iv_show_2.setBackgroundResource(R.mipmap.xs); |
120 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | 120 | et_pwd_2.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
121 | et_pwd_2.setTransformationMethod(PasswordTransformationMethod.getInstance()); | 121 | et_pwd_2.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | }); | 125 | }); |
126 | 126 | ||
127 | 127 | ||
128 | btn_reg.setOnClickListener(view -> { | 128 | btn_reg.setOnClickListener(view -> { |
129 | 129 | ||
130 | String phone = et_phone.getText().toString().trim(); | 130 | String phone = et_phone.getText().toString().trim(); |
131 | String pwd = et_pwd.getText().toString().trim(); | 131 | String pwd = et_pwd.getText().toString().trim(); |
132 | String pwd2 = et_pwd_2.getText().toString().trim(); | 132 | String pwd2 = et_pwd_2.getText().toString().trim(); |
133 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { | 133 | if (phone.isEmpty() || pwd.isEmpty() || phone.length() == 0 || pwd.length() == 0) { |
134 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); | 134 | Toast.makeText(this, "手机号以及密码不能为空", Toast.LENGTH_SHORT).show(); |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | if (pwd.length() < 6 || pwd.length() > 16 || pwd2.length() < 6 || pwd2.length() > 16) { | 137 | if (pwd.length() < 6 || pwd.length() > 16 || pwd2.length() < 6 || pwd2.length() > 16) { |
138 | Toast.makeText(this, "密码必须为6-16位,数字或字母", Toast.LENGTH_SHORT).show(); | 138 | Toast.makeText(this, "密码必须为6-16位,数字或字母", Toast.LENGTH_SHORT).show(); |
139 | } | 139 | } |
140 | if (!Common.isValidPhoneNumber(phone)) { | 140 | if (!Common.isValidPhoneNumber(phone)) { |
141 | Toast.makeText(this, "请输入有效手机号", Toast.LENGTH_SHORT).show(); | 141 | Toast.makeText(this, "请输入有效手机号", Toast.LENGTH_SHORT).show(); |
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { | 145 | if (!PhoneNumberUtils.isGlobalPhoneNumber(et_phone.getText().toString())) { |
146 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); | 146 | Toast.makeText(this, "请输入正确的手机号码", Toast.LENGTH_SHORT).show(); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | 149 | ||
150 | if (!cb_1.isChecked()) { | 150 | if (!cb_1.isChecked()) { |
151 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); | 151 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | if (!pwd.equals(pwd2)) { | 154 | if (!pwd.equals(pwd2)) { |
155 | Toast.makeText(this, "两次密码需要一致", Toast.LENGTH_SHORT).show(); | 155 | Toast.makeText(this, "两次密码需要一致", Toast.LENGTH_SHORT).show(); |
156 | return; | 156 | return; |
157 | } | 157 | } |
158 | 158 | ||
159 | reg(phone, pwd); | 159 | reg(phone, pwd); |
160 | 160 | ||
161 | }); | 161 | }); |
162 | 162 | ||
163 | tv_log.setOnClickListener(view -> { | 163 | tv_log.setOnClickListener(view -> { |
164 | startActivity(LoginActivity.class); | 164 | startActivity(LoginActivity.class); |
165 | finish(); | 165 | finish(); |
166 | }); | 166 | }); |
167 | 167 | ||
168 | tv_ys.setOnClickListener(view -> { | 168 | tv_ys.setOnClickListener(view -> { |
169 | startActivity(YinsiActivity.class); | 169 | startActivity(YinsiActivity.class); |
170 | }); | 170 | }); |
171 | tv_user.setOnClickListener(view -> { | 171 | tv_user.setOnClickListener(view -> { |
172 | startActivity(UserActivity.class); | 172 | startActivity(UserActivity.class); |
173 | }); | 173 | }); |
174 | } | 174 | } |
175 | 175 | ||
176 | public void reg(final String phone, String pwd) { | 176 | public void reg(final String phone, String pwd) { |
177 | 177 | ||
178 | Map map = new HashMap(); | 178 | Map map = new HashMap(); |
179 | map.put("username", phone); | 179 | map.put("username", phone); |
180 | map.put("password", pwd); | 180 | map.put("password", pwd); |
181 | 181 | ||
182 | 182 | ||
183 | NetWorks.registerParent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 183 | NetWorks.registerParent(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
184 | @Override | 184 | @Override |
185 | public void onSubscribe(Disposable d) { | 185 | public void onSubscribe(Disposable d) { |
186 | 186 | ||
187 | } | 187 | } |
188 | 188 | ||
189 | @Override | 189 | @Override |
190 | public void onNext(ResponseBody responseBody) { | 190 | public void onNext(ResponseBody responseBody) { |
191 | String str = null; | 191 | String str = null; |
192 | try { | 192 | try { |
193 | str = responseBody.string(); | 193 | str = responseBody.string(); |
194 | } catch (IOException e) { | 194 | } catch (IOException e) { |
195 | e.printStackTrace(); | 195 | e.printStackTrace(); |
196 | } | 196 | } |
197 | 197 | ||
198 | if (str == null || str.length() == 0) { | 198 | if (str == null || str.length() == 0) { |
199 | Toast.makeText(RegisterActivity.this, "服务器繁忙", Toast.LENGTH_SHORT).show(); | 199 | Toast.makeText(RegisterActivity.this, "服务器繁忙", Toast.LENGTH_SHORT).show(); |
200 | return; | 200 | return; |
201 | } | 201 | } |
202 | 202 | ||
203 | RegisterBean registerBean = new Gson().fromJson(str, RegisterBean.class); | 203 | RegisterBean registerBean = new Gson().fromJson(str, RegisterBean.class); |
204 | 204 | ||
205 | if (!registerBean.isSuccess()) { | 205 | if (!registerBean.isSuccess()) { |
206 | Toast.makeText(RegisterActivity.this, registerBean.getMsg(), Toast.LENGTH_SHORT).show(); | 206 | Toast.makeText(RegisterActivity.this, registerBean.getMsg(), Toast.LENGTH_SHORT).show(); |
207 | return; | 207 | return; |
208 | } | 208 | } |
209 | 209 | ||
210 | if (registerBean.getData().getUserName() != null && registerBean.getData().getUserName().length() > 0) { | 210 | if (registerBean.getData().getUserName() != null && registerBean.getData().getUserName().length() > 0) { |
211 | SharedPreferencesUtil.putData("phone", phone); | 211 | SharedPreferencesUtil.putData("phone", phone); |
212 | SharedPreferencesUtil.putData("role", registerBean.getData().getUserName()); | 212 | SharedPreferencesUtil.putData("role", registerBean.getData().getUserName()); |
213 | SharedPreferencesUtil.putData("userId", registerBean.getData().getUserName()); | 213 | SharedPreferencesUtil.putData("userId", registerBean.getData().getUserName()); |
214 | login(phone, pwd); | 214 | login(phone, pwd); |
215 | 215 | ||
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | @Override | 221 | @Override |
222 | public void onError(Throwable e) { | 222 | public void onError(Throwable e) { |
223 | 223 | ||
224 | } | 224 | } |
225 | 225 | ||
226 | @Override | 226 | @Override |
227 | public void onComplete() { | 227 | public void onComplete() { |
228 | 228 | ||
229 | } | 229 | } |
230 | }); | 230 | }); |
231 | } | 231 | } |
232 | 232 | ||
233 | public void login(final String phone, String pwd) { | 233 | public void login(final String phone, String pwd) { |
234 | Map map = new HashMap(); | 234 | Map map = new HashMap(); |
235 | map.put("username", phone); | 235 | map.put("username", phone); |
236 | map.put("password", pwd); | 236 | map.put("password", pwd); |
237 | 237 | ||
238 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { | 238 | NetWorks.login(NetWorks.getMapRequestBody(map), new Observer<ResponseBody>() { |
239 | @Override | 239 | @Override |
240 | public void onSubscribe(Disposable d) { | 240 | public void onSubscribe(Disposable d) { |
241 | 241 | ||
242 | } | 242 | } |
243 | 243 | ||
244 | @Override | 244 | @Override |
245 | public void onNext(ResponseBody responseBody) { | 245 | public void onNext(ResponseBody responseBody) { |
246 | try { | 246 | try { |
247 | String str = responseBody.string().toString(); | 247 | String str = responseBody.string().toString(); |
248 | LogUtil.e(TAG, "----" + str); | 248 | LogUtil.e(TAG, "----" + str); |
249 | JSONObject jo = new JSONObject(str); | 249 | JSONObject jo = new JSONObject(str); |
250 | boolean isSucceed = jo.getBoolean("success"); | 250 | boolean isSucceed = jo.getBoolean("success"); |
251 | if (isSucceed) { | 251 | if (isSucceed) { |
252 | JSONObject jo2 = jo.getJSONObject("data"); | 252 | JSONObject jo2 = jo.getJSONObject("data"); |
253 | SharedPreferencesUtil.putData("phone", phone); | 253 | SharedPreferencesUtil.putData("phone", phone); |
254 | SharedPreferencesUtil.putData("role", jo2.getString("role")); | 254 | SharedPreferencesUtil.putData("role", jo2.getString("role")); |
255 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); | 255 | SharedPreferencesUtil.putData("userId", jo2.getString("id")); |
256 | SharedPreferencesUtil.putData("token", jo2.getString("token")); | 256 | SharedPreferencesUtil.putData("token", jo2.getString("token")); |
257 | startActivity(ChooseActivity.class); | 257 | startActivity(ChooseActivity.class); |
258 | finish(); | 258 | finish(); |
259 | } else { | 259 | } else { |
260 | Toast.makeText(RegisterActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); | 260 | Toast.makeText(RegisterActivity.this, jo.getString("msg"), Toast.LENGTH_SHORT).show(); |
261 | } | 261 | } |
262 | } catch (Exception e) { | 262 | } catch (Exception e) { |
263 | e.printStackTrace(); | 263 | e.printStackTrace(); |
264 | Toast.makeText(RegisterActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); | 264 | Toast.makeText(RegisterActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); |
265 | } | 265 | } |
266 | 266 | ||
267 | } | 267 | } |
268 | 268 | ||
269 | @Override | 269 | @Override |
270 | public void onError(Throwable e) { | 270 | public void onError(Throwable e) { |
271 | 271 | ||
272 | } | 272 | } |
273 | 273 | ||
274 | @Override | 274 | @Override |
275 | public void onComplete() { | 275 | public void onComplete() { |
276 | 276 | ||
277 | } | 277 | } |
278 | }); | 278 | }); |
279 | } | 279 | } |
280 | 280 | ||
281 | public void goQRView() { | 281 | public void goQRView() { |
282 | 282 | ||
283 | if (!XXPermissions.isGranted(this, Permission.CAMERA)) { | 283 | if (!XXPermissions.isGranted(this, Permission.CAMERA)) { |
284 | XXPermissions.with(this) | 284 | XXPermissions.with(this) |
285 | // 申请多个权限 | 285 | // 申请多个权限 |
286 | .permission(Permission.CAMERA) | 286 | .permission(Permission.CAMERA) |
287 | .request(new OnPermissionCallback() { | 287 | .request(new OnPermissionCallback() { |
288 | @Override | 288 | @Override |
289 | public void onGranted(List<String> permissions, boolean all) { | 289 | public void onGranted(List<String> permissions, boolean all) { |
290 | if (all) { | 290 | if (all) { |
291 | //开启扫码界面 | 291 | //开启扫码界面 |
292 | startQRView(); | 292 | startQRView(); |
293 | 293 | ||
294 | } else { | 294 | } else { |
295 | Toast.makeText(RegisterActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); | 295 | Toast.makeText(RegisterActivity.this, "需要相机权限", Toast.LENGTH_SHORT).show(); |
296 | } | 296 | } |
297 | } | 297 | } |
298 | 298 | ||
299 | @Override | 299 | @Override |
300 | public void onDenied(List<String> permissions, boolean never) { | 300 | public void onDenied(List<String> permissions, boolean never) { |
301 | XXPermissions.startPermissionActivity(RegisterActivity.this, permissions); | 301 | XXPermissions.startPermissionActivity(RegisterActivity.this, permissions); |
302 | } | 302 | } |
303 | }); | 303 | }); |
304 | 304 | ||
305 | 305 | ||
306 | } else { | 306 | } else { |
307 | startQRView(); | 307 | startQRView(); |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | } | 311 | } |
312 | 312 | ||
313 | public void startQRView() { | 313 | public void startQRView() { |
314 | 314 | ||
315 | startActivity(QRActivity.class); | 315 | startActivity(QRActivity.class); |
316 | finish(); | 316 | finish(); |
317 | 317 | ||
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | @Override | 321 | @Override |
322 | protected void initData() { | 322 | protected void initData() { |
323 | 323 | ||
324 | } | 324 | } |
325 | 325 | ||
326 | @Override | 326 | @Override |
327 | public void onNetChanged(int netWorkState) { | 327 | public void onNetChanged(int netWorkState) { |
328 | 328 | ||
329 | } | 329 | } |
330 | } | 330 | } |
app/src/main/java/com/hjx/parent/TeacherChooseActivity.java
1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.text.TextUtils; | 4 | import android.text.TextUtils; |
5 | import android.view.View; | 5 | import android.view.View; |
6 | import android.widget.ImageView; | 6 | import android.widget.ImageView; |
7 | 7 | ||
8 | import androidx.annotation.NonNull; | 8 | import androidx.annotation.NonNull; |
9 | import androidx.recyclerview.widget.LinearLayoutManager; | 9 | import androidx.recyclerview.widget.LinearLayoutManager; |
10 | import androidx.recyclerview.widget.RecyclerView; | 10 | import androidx.recyclerview.widget.RecyclerView; |
11 | 11 | ||
12 | import com.bumptech.glide.Glide; | 12 | import com.bumptech.glide.Glide; |
13 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 13 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
14 | import com.bumptech.glide.request.RequestOptions; | 14 | import com.bumptech.glide.request.RequestOptions; |
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.gson.Gson; | 17 | import com.google.gson.Gson; |
18 | import com.hjx.parent.bean.StudentBean; | 18 | import com.hjx.parent.bean.StudentBean; |
19 | import com.prws.common.base.BaseActivity; | 19 | import com.prws.common.base.BaseActivity; |
20 | import com.prws.common.base.BasePresenter; | 20 | import com.prws.common.base.BasePresenter; |
21 | import com.prws.common.net.NetWorks; | 21 | import com.prws.common.net.NetWorks; |
22 | import com.prws.common.utils.LogUtil; | 22 | import com.prws.common.utils.LogUtil; |
23 | import com.prws.common.utils.ScreenUtils; | 23 | import com.prws.common.utils.ScreenUtils; |
24 | import com.prws.common.utils.SharedPreferencesUtil; | 24 | import com.prws.common.utils.SharedPreferencesUtil; |
25 | 25 | ||
26 | import org.json.JSONArray; | 26 | import org.json.JSONArray; |
27 | import org.json.JSONObject; | 27 | import org.json.JSONObject; |
28 | 28 | ||
29 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
30 | 30 | ||
31 | import butterknife.BindView; | 31 | import butterknife.BindView; |
32 | import butterknife.OnClick; | 32 | import butterknife.OnClick; |
33 | import io.reactivex.Observer; | 33 | import io.reactivex.Observer; |
34 | import io.reactivex.disposables.Disposable; | 34 | import io.reactivex.disposables.Disposable; |
35 | import okhttp3.ResponseBody; | 35 | import okhttp3.ResponseBody; |
36 | 36 | ||
37 | public class TeacherChooseActivity extends BaseActivity { | 37 | public class TeacherChooseActivity extends BaseActivity { |
38 | @BindView(R.id.recycle) | 38 | @BindView(R.id.recycle) |
39 | RecyclerView recycle; | 39 | RecyclerView recycle; |
40 | private int select = 0; | 40 | private int select = 0; |
41 | 41 | ||
42 | @Override | 42 | @Override |
43 | protected int layoutResId() { | 43 | protected int layoutResId() { |
44 | return R.layout.choose_activity; | 44 | return R.layout.choose_activity; |
45 | } | 45 | } |
46 | 46 | ||
47 | @Override | 47 | @Override |
48 | public Object getContract() { | 48 | public Object getContract() { |
49 | return null; | 49 | return null; |
50 | } | 50 | } |
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | public BasePresenter getPresenter() { | 53 | public BasePresenter getPresenter() { |
54 | return null; | 54 | return null; |
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | protected void initView() { | 58 | protected void initView() { |
59 | 59 | ||
60 | } | 60 | } |
61 | 61 | ||
62 | @Override | 62 | @Override |
63 | protected void initListener() { | 63 | protected void initListener() { |
64 | 64 | ||
65 | } | 65 | } |
66 | 66 | ||
67 | @Override | 67 | @Override |
68 | protected void initData() { | 68 | protected void initData() { |
69 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | @Override | 72 | @Override |
73 | public void onNetChanged(int netWorkState) { | 73 | public void onNetChanged(int netWorkState) { |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | @Override | 77 | @Override |
78 | protected void onResume() { | 78 | protected void onResume() { |
79 | super.onResume(); | 79 | super.onResume(); |
80 | loadChildList(); | 80 | loadChildList(); |
81 | } | 81 | } |
82 | 82 | ||
83 | ArrayList<StudentBean> alist = new ArrayList<>(); | 83 | ArrayList<StudentBean> alist = new ArrayList<>(); |
84 | 84 | ||
85 | public void loadChildList() { | 85 | public void loadChildList() { |
86 | NetWorks.listStudent(new Observer<ResponseBody>() { | 86 | NetWorks.listStudent(new Observer<ResponseBody>() { |
87 | @Override | 87 | @Override |
88 | public void onSubscribe(Disposable d) { | 88 | public void onSubscribe(Disposable d) { |
89 | |||
90 | } | 89 | } |
91 | 90 | ||
92 | @Override | 91 | @Override |
93 | public void onNext(ResponseBody responseBody) { | 92 | public void onNext(ResponseBody responseBody) { |
94 | try { | 93 | try { |
95 | String str = responseBody.string().toString(); | 94 | String str = responseBody.string().toString(); |
96 | LogUtil.e("TAG", "----" + str); | 95 | LogUtil.e("TAG", "----" + str); |
97 | JSONObject jo = new JSONObject(str); | 96 | JSONObject jo = new JSONObject(str); |
98 | boolean isSucceed = jo.getBoolean("success"); | 97 | boolean isSucceed = jo.getBoolean("success"); |
99 | if (isSucceed) { | 98 | if (isSucceed) { |
100 | JSONArray jarr = jo.getJSONArray("data"); | 99 | JSONArray jarr = jo.getJSONArray("data"); |
101 | alist.clear(); | 100 | alist.clear(); |
102 | for (int i = 0; i < jarr.length(); i++) { | 101 | for (int i = 0; i < jarr.length(); i++) { |
103 | JSONObject jo2 = jarr.getJSONObject(i); | 102 | JSONObject jo2 = jarr.getJSONObject(i); |
104 | Gson gson = new Gson(); | 103 | Gson gson = new Gson(); |
105 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); | 104 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); |
106 | alist.add(sb); | 105 | alist.add(sb); |
107 | } | 106 | } |
108 | loadList(); | 107 | loadList(); |
109 | } else { | 108 | } else { |
110 | 109 | ||
111 | } | 110 | } |
112 | } catch (Exception e) { | 111 | } catch (Exception e) { |
113 | e.printStackTrace(); | 112 | e.printStackTrace(); |
114 | } | 113 | } |
115 | } | 114 | } |
116 | 115 | ||
117 | @Override | 116 | @Override |
118 | public void onError(Throwable e) { | 117 | public void onError(Throwable e) { |
119 | |||
120 | } | 118 | } |
121 | 119 | ||
122 | @Override | 120 | @Override |
123 | public void onComplete() { | 121 | public void onComplete() { |
124 | |||
125 | } | 122 | } |
126 | }); | 123 | }); |
127 | } | 124 | } |
128 | 125 | ||
129 | public void loadList() { | 126 | public void loadList() { |
130 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 127 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
131 | try { | 128 | try { |
132 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 129 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
133 | for (int i = 0; i < alist.size(); i++) { | 130 | for (int i = 0; i < alist.size(); i++) { |
134 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { | 131 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { |
135 | select = i; | 132 | select = i; |
136 | break; | 133 | break; |
137 | } | 134 | } |
138 | } | 135 | } |
139 | } catch (Exception e) { | 136 | } catch (Exception e) { |
140 | 137 | ||
141 | } | 138 | } |
142 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { | 139 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { |
143 | @Override | 140 | @Override |
144 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 141 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
145 | 142 | ||
146 | } | 143 | } |
147 | 144 | ||
148 | @Override | 145 | @Override |
149 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 146 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
150 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 147 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
151 | item.setText(R.id.tv_name, studentBean.getStuName()); | 148 | item.setText(R.id.tv_name, studentBean.getStuName()); |
152 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); | 149 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); |
153 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); | 150 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); |
154 | item.setVisible(R.id.rl_add, false); | 151 | item.setVisible(R.id.rl_add, false); |
155 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 152 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
156 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 153 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
157 | } else { | 154 | } else { |
158 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(TeacherChooseActivity.this, 45)); | 155 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(TeacherChooseActivity.this, 45)); |
159 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 156 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
160 | Glide.with(TeacherChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 157 | Glide.with(TeacherChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
161 | } | 158 | } |
162 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); | 159 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); |
163 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 160 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
164 | @Override | 161 | @Override |
165 | public void onClick(View view) { | 162 | public void onClick(View view) { |
166 | select = item.getAdapterPosition(); | 163 | select = item.getAdapterPosition(); |
167 | notifyDataSetChanged(); | 164 | notifyDataSetChanged(); |
168 | } | 165 | } |
169 | }); | 166 | }); |
170 | } | 167 | } |
171 | }; | 168 | }; |
172 | recycle.setLayoutManager(new LinearLayoutManager(TeacherChooseActivity.this, LinearLayoutManager.VERTICAL, false)); | 169 | recycle.setLayoutManager(new LinearLayoutManager(TeacherChooseActivity.this, LinearLayoutManager.VERTICAL, false)); |
173 | recycle.setAdapter(adapter); | 170 | recycle.setAdapter(adapter); |
174 | } | 171 | } |
175 | 172 | ||
176 | @OnClick(R.id.tv_confirm) | 173 | @OnClick(R.id.tv_confirm) |
177 | public void confirm(View view) { | 174 | public void confirm(View view) { |
178 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { | 175 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { |
179 | StudentBean studentBean = alist.get(select); | 176 | StudentBean studentBean = alist.get(select); |
180 | if (studentBean.getStuId() != null) { | 177 | if (studentBean.getStuId() != null) { |
181 | if (getIntent().getBooleanExtra("needBack", false)) { | 178 | if (getIntent().getBooleanExtra("needBack", false)) { |
182 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 179 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
183 | } else { | 180 | } else { |
184 | Intent intent = new Intent(TeacherChooseActivity.this, TeacherMainActivity.class); | 181 | Intent intent = new Intent(TeacherChooseActivity.this, TeacherMainActivity.class); |
185 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 182 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
186 | startActivity(intent); | 183 | startActivity(intent); |
187 | } | 184 | } |
188 | setResult(RESULT_OK); | 185 | setResult(RESULT_OK); |
189 | finish(); | 186 | finish(); |
190 | } | 187 | } |
191 | } | 188 | } |
192 | } | 189 | } |
193 | } | 190 | } |
194 | 191 |
app/src/main/java/com/hjx/parent/bean/StudentBean.java
1 | package com.hjx.parent.bean; | 1 | package com.hjx.parent.bean; |
2 | 2 | ||
3 | public class StudentBean { | 3 | public class StudentBean { |
4 | 4 | ||
5 | String stuId; | 5 | private String stuId; |
6 | String stuName; | 6 | private String stuName; |
7 | int gender; | 7 | private String gender; |
8 | String term; | 8 | private String term; |
9 | String account; | 9 | private String account; |
10 | String nickName; | 10 | private String nickName; |
11 | String address; | 11 | private String address; |
12 | String phone; | 12 | private String phone; |
13 | String photo; | 13 | private String photo; |
14 | int fromType; | 14 | private String oriSchool; |
15 | int gradeId; | 15 | private String parentPhone; |
16 | String oriSchool; | 16 | private String parentIdentity; |
17 | String parentPhone; | 17 | private String teacherName; |
18 | String parentIdentity; | 18 | private String grade; |
19 | String teacherName; | 19 | private int isIntention; |
20 | int teacherId; | 20 | |
21 | String teacherAvatar; | 21 | // not exist |
22 | String grade; | 22 | private String teacherAvatar; |
23 | String teacherIdentity; | 23 | private Integer state; |
24 | int sex; | ||
25 | Integer state; | ||
26 | 24 | ||
27 | public void setState(Integer state) { | ||
28 | this.state = state; | ||
29 | } | ||
30 | |||
31 | public Integer getState() { | ||
32 | return state; | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public String toString() { | ||
37 | return "StudentBean{" + | ||
38 | "stuId='" + stuId + '\'' + | ||
39 | ", stuName='" + stuName + '\'' + | ||
40 | ", gender=" + gender + | ||
41 | ", term='" + term + '\'' + | ||
42 | ", account='" + account + '\'' + | ||
43 | ", nickName='" + nickName + '\'' + | ||
44 | ", address='" + address + '\'' + | ||
45 | ", phone='" + phone + '\'' + | ||
46 | ", photo='" + photo + '\'' + | ||
47 | ", fromType=" + fromType + | ||
48 | ", gradeId=" + gradeId + | ||
49 | ", oriSchool='" + oriSchool + '\'' + | ||
50 | ", parentPhone='" + parentPhone + '\'' + | ||
51 | ", parentIdentity='" + parentIdentity + '\'' + | ||
52 | ", teacherName='" + teacherName + '\'' + | ||
53 | ", teacherId=" + teacherId + | ||
54 | ", teacherAvatar=" + teacherAvatar + | ||
55 | ", grade=" + grade + | ||
56 | ", teacherIdentity=" + teacherIdentity + | ||
57 | ", sex=" + sex + | ||
58 | ", state=" + state + | ||
59 | '}'; | ||
60 | } | ||
61 | |||
62 | public void setSex(int sex) { | ||
63 | this.sex = sex; | ||
64 | } | ||
65 | |||
66 | public int getSex() { | ||
67 | return sex; | ||
68 | } | ||
69 | |||
70 | public void setTeacherIdentity(String teacherIdentity) { | ||
71 | this.teacherIdentity = teacherIdentity; | ||
72 | } | ||
73 | |||
74 | public String getTeacherIdentity() { | ||
75 | return teacherIdentity; | ||
76 | } | ||
77 | |||
78 | public void setTeacherAvatar(String teacherAvatar) { | ||
79 | this.teacherAvatar = teacherAvatar; | ||
80 | } | ||
81 | |||
82 | public void setGrade(String grade) { | ||
83 | this.grade = grade; | ||
84 | } | ||
85 | |||
86 | public String getTeacherAvatar() { | ||
87 | return teacherAvatar; | ||
88 | } | ||
89 | |||
90 | public String getGrade() { | ||
91 | return grade; | ||
92 | } | ||
93 | 25 | ||
94 | public String getStuId() { | 26 | public String getStuId() { |
95 | return stuId; | 27 | return stuId; |
96 | } | 28 | } |
97 | 29 | ||
98 | public void setStuId(String stuId) { | 30 | public void setStuId(String stuId) { |
99 | this.stuId = stuId; | 31 | this.stuId = stuId; |
100 | } | 32 | } |
101 | 33 | ||
102 | public String getStuName() { | 34 | public String getStuName() { |
103 | return stuName; | 35 | return stuName; |
104 | } | 36 | } |
105 | 37 | ||
106 | public void setStuName(String stuName) { | 38 | public void setStuName(String stuName) { |
107 | this.stuName = stuName; | 39 | this.stuName = stuName; |
108 | } | 40 | } |
109 | 41 | ||
110 | public int getGender() { | 42 | public String getGender() { |
111 | return gender; | 43 | return gender; |
112 | } | 44 | } |
113 | 45 | ||
114 | public void setGender(int gender) { | 46 | public void setGender(String gender) { |
115 | this.gender = gender; | 47 | this.gender = gender; |
116 | } | 48 | } |
117 | 49 | ||
118 | public String getTerm() { | 50 | public String getTerm() { |
119 | return term; | 51 | return term; |
120 | } | 52 | } |
121 | 53 | ||
122 | public void setTerm(String term) { | 54 | public void setTerm(String term) { |
123 | this.term = term; | 55 | this.term = term; |
124 | } | 56 | } |
125 | 57 | ||
126 | public String getAccount() { | 58 | public String getAccount() { |
127 | return account; | 59 | return account; |
128 | } | 60 | } |
129 | 61 | ||
130 | public void setAccount(String account) { | 62 | public void setAccount(String account) { |
131 | this.account = account; | 63 | this.account = account; |
132 | } | 64 | } |
133 | 65 | ||
134 | public String getNickName() { | 66 | public String getNickName() { |
135 | return nickName; | 67 | return nickName; |
136 | } | 68 | } |
137 | 69 | ||
138 | public void setNickName(String nickName) { | 70 | public void setNickName(String nickName) { |
139 | this.nickName = nickName; | 71 | this.nickName = nickName; |
140 | } | 72 | } |
141 | 73 | ||
142 | public String getAddress() { | 74 | public String getAddress() { |
143 | return address; | 75 | return address; |
144 | } | 76 | } |
145 | 77 | ||
146 | public void setAddress(String address) { | 78 | public void setAddress(String address) { |
147 | this.address = address; | 79 | this.address = address; |
148 | } | 80 | } |
149 | 81 | ||
150 | public String getPhone() { | 82 | public String getPhone() { |
151 | return phone; | 83 | return phone; |
152 | } | 84 | } |
153 | 85 | ||
154 | public void setPhone(String phone) { | 86 | public void setPhone(String phone) { |
155 | this.phone = phone; | 87 | this.phone = phone; |
156 | } | 88 | } |
157 | 89 | ||
158 | public String getPhoto() { | 90 | public String getPhoto() { |
159 | return photo; | 91 | return photo; |
160 | } | 92 | } |
161 | 93 | ||
162 | public void setPhoto(String photo) { | 94 | public void setPhoto(String photo) { |
163 | this.photo = photo; | 95 | this.photo = photo; |
164 | } | 96 | } |
165 | 97 | ||
166 | public int getFromType() { | ||
167 | return fromType; | ||
168 | } | ||
169 | |||
170 | public void setFromType(int fromType) { | ||
171 | this.fromType = fromType; | ||
172 | } | ||
173 | |||
174 | public int getGradeId() { | ||
175 | return gradeId; | ||
176 | } | ||
177 | |||
178 | public void setGradeId(int gradeId) { | ||
179 | this.gradeId = gradeId; | ||
180 | } | ||
181 | |||
182 | public String getOriSchool() { | 98 | public String getOriSchool() { |
183 | return oriSchool; | 99 | return oriSchool; |
184 | } | 100 | } |
185 | 101 | ||
186 | public void setOriSchool(String oriSchool) { | 102 | public void setOriSchool(String oriSchool) { |
187 | this.oriSchool = oriSchool; | 103 | this.oriSchool = oriSchool; |
188 | } | 104 | } |
189 | 105 | ||
190 | public String getParentPhone() { | 106 | public String getParentPhone() { |
191 | return parentPhone; | 107 | return parentPhone; |
192 | } | 108 | } |
193 | 109 | ||
194 | public void setParentPhone(String parentPhone) { | 110 | public void setParentPhone(String parentPhone) { |
195 | this.parentPhone = parentPhone; | 111 | this.parentPhone = parentPhone; |
196 | } | 112 | } |
197 | 113 | ||
198 | public String getParentIdentity() { | 114 | public String getParentIdentity() { |
199 | return parentIdentity; | 115 | return parentIdentity; |
200 | } | 116 | } |
201 | 117 | ||
202 | public void setParentIdentity(String parentIdentity) { | 118 | public void setParentIdentity(String parentIdentity) { |
203 | this.parentIdentity = parentIdentity; | 119 | this.parentIdentity = parentIdentity; |
204 | } | 120 | } |
205 | 121 | ||
206 | public String getTeacherName() { | 122 | public String getTeacherName() { |
207 | return teacherName; | 123 | return teacherName; |
208 | } | 124 | } |
209 | 125 | ||
210 | public void setTeacherName(String teacherName) { | 126 | public void setTeacherName(String teacherName) { |
211 | this.teacherName = teacherName; | 127 | this.teacherName = teacherName; |
212 | } | 128 | } |
213 | 129 | ||
214 | public int getTeacherId() { | 130 | public String getGrade() { |
215 | return teacherId; | 131 | return grade; |
132 | } | ||
133 | |||
134 | public void setGrade(String grade) { | ||
135 | this.grade = grade; | ||
136 | } | ||
137 | |||
138 | public int getIsIntention() { |
app/src/main/java/com/hjx/parent/fragment/HomeFragment.java
1 | package com.hjx.parent.fragment; | 1 | package com.hjx.parent.fragment; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.os.Bundle; | 4 | import android.os.Bundle; |
5 | import android.text.TextUtils; | 5 | import android.text.TextUtils; |
6 | import android.view.LayoutInflater; | 6 | import android.view.LayoutInflater; |
7 | import android.view.View; | 7 | import android.view.View; |
8 | import android.widget.ImageView; | 8 | import android.widget.ImageView; |
9 | import android.widget.LinearLayout; | 9 | import android.widget.LinearLayout; |
10 | import android.widget.TextView; | 10 | import android.widget.TextView; |
11 | import android.widget.Toast; | 11 | import android.widget.Toast; |
12 | 12 | ||
13 | import androidx.annotation.NonNull; | 13 | import androidx.annotation.NonNull; |
14 | import androidx.annotation.Nullable; | 14 | import androidx.annotation.Nullable; |
15 | import androidx.recyclerview.widget.LinearLayoutManager; | 15 | import androidx.recyclerview.widget.LinearLayoutManager; |
16 | import androidx.recyclerview.widget.RecyclerView; | 16 | import androidx.recyclerview.widget.RecyclerView; |
17 | 17 | ||
18 | import com.bumptech.glide.Glide; | 18 | import com.bumptech.glide.Glide; |
19 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 19 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
20 | import com.bumptech.glide.request.RequestOptions; | 20 | import com.bumptech.glide.request.RequestOptions; |
21 | import com.chad.library.adapter.base.BaseQuickAdapter; | 21 | import com.chad.library.adapter.base.BaseQuickAdapter; |
22 | import com.chad.library.adapter.base.BaseViewHolder; | 22 | import com.chad.library.adapter.base.BaseViewHolder; |
23 | import com.google.gson.Gson; | 23 | import com.google.gson.Gson; |
24 | import com.hjq.permissions.OnPermissionCallback; | 24 | import com.hjq.permissions.OnPermissionCallback; |
25 | import com.hjq.permissions.Permission; | 25 | import com.hjq.permissions.Permission; |
26 | import com.hjq.permissions.XXPermissions; | 26 | import com.hjq.permissions.XXPermissions; |
27 | import com.hjx.parent.ChooseActivity; | 27 | import com.hjx.parent.ChooseActivity; |
28 | import com.hjx.parent.ErrorBookActivity; | 28 | import com.hjx.parent.ErrorBookActivity; |
29 | import com.hjx.parent.QRActivity; | 29 | import com.hjx.parent.QRActivity; |
30 | import com.hjx.parent.R; | 30 | import com.hjx.parent.R; |
31 | import com.hjx.parent.bean.StudentBean; | 31 | import com.hjx.parent.bean.StudentBean; |
32 | import com.prws.common.base.BaseFragment; | 32 | import com.prws.common.base.BaseFragment; |
33 | import com.prws.common.bean.ResponseResult; | 33 | import com.prws.common.bean.ResponseResult; |
34 | import com.prws.common.bean.ScheduleBean; | 34 | import com.prws.common.bean.ScheduleBean; |
35 | import com.prws.common.bean.Video; | 35 | import com.prws.common.bean.Video; |
36 | import com.prws.common.net.NetWorks; | 36 | import com.prws.common.net.NetWorks; |
37 | import com.prws.common.utils.ScreenUtils; | 37 | import com.prws.common.utils.ScreenUtils; |
38 | import com.prws.common.utils.SharedPreferencesUtil; | 38 | import com.prws.common.utils.SharedPreferencesUtil; |
39 | import com.uuzuche.lib_zxing.activity.CaptureActivity; | 39 | import com.uuzuche.lib_zxing.activity.CaptureActivity; |
40 | import com.uuzuche.lib_zxing.activity.CodeUtils; | 40 | import com.uuzuche.lib_zxing.activity.CodeUtils; |
41 | 41 | ||
42 | import java.text.SimpleDateFormat; | 42 | import java.text.SimpleDateFormat; |
43 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
44 | import java.util.List; | 44 | import java.util.List; |
45 | 45 | ||
46 | import butterknife.BindView; | 46 | import butterknife.BindView; |
47 | import butterknife.OnClick; | 47 | import butterknife.OnClick; |
48 | import io.reactivex.Observer; | 48 | import io.reactivex.Observer; |
49 | import io.reactivex.disposables.Disposable; | 49 | import io.reactivex.disposables.Disposable; |
50 | 50 | ||
51 | public class HomeFragment extends BaseFragment { | 51 | public class HomeFragment extends BaseFragment { |
52 | @Override | 52 | @Override |
53 | protected int getLayoutRes() { | 53 | protected int getLayoutRes() { |
54 | return R.layout.fragment_home; | 54 | return R.layout.fragment_home; |
55 | } | 55 | } |
56 | 56 | ||
57 | ImageView iv_sapmiao; | 57 | ImageView iv_sapmiao; |
58 | TextView tv_name; | 58 | TextView tv_name; |
59 | StudentBean studentBean; | 59 | StudentBean studentBean; |
60 | ImageView iv_2; | 60 | ImageView iv_2; |
61 | @BindView(R.id.recycle) | 61 | @BindView(R.id.recycle) |
62 | RecyclerView recyclerView; | 62 | RecyclerView recyclerView; |
63 | @BindView(R.id.tv_empty) | 63 | @BindView(R.id.tv_empty) |
64 | TextView tv_empty; | 64 | TextView tv_empty; |
65 | @BindView(R.id.iv_empty) | 65 | @BindView(R.id.iv_empty) |
66 | ImageView iv_empty; | 66 | ImageView iv_empty; |
67 | 67 | ||
68 | @Override | 68 | @Override |
69 | protected void initDatas() { | 69 | protected void initDatas() { |
70 | super.initDatas(); | 70 | super.initDatas(); |
71 | iv_2 = mRootView.findViewById(R.id.iv_2); | 71 | iv_2 = mRootView.findViewById(R.id.iv_2); |
72 | iv_sapmiao = mRootView.findViewById(R.id.iv_sapmiao); | 72 | iv_sapmiao = mRootView.findViewById(R.id.iv_sapmiao); |
73 | tv_name = mRootView.findViewById(R.id.tv_name); | 73 | tv_name = mRootView.findViewById(R.id.tv_name); |
74 | iv_sapmiao.setOnClickListener(view -> { | 74 | iv_sapmiao.setOnClickListener(view -> { |
75 | if (!XXPermissions.isGranted(getActivity(), Permission.CAMERA)) { | 75 | if (!XXPermissions.isGranted(getActivity(), Permission.CAMERA)) { |
76 | XXPermissions.with(getActivity()) | 76 | XXPermissions.with(getActivity()) |
77 | // 申请多个权限 | 77 | // 申请多个权限 |
78 | .permission(Permission.CAMERA) | 78 | .permission(Permission.CAMERA) |
79 | .request(new OnPermissionCallback() { | 79 | .request(new OnPermissionCallback() { |
80 | @Override | 80 | @Override |
81 | public void onGranted(List<String> permissions, boolean all) { | 81 | public void onGranted(List<String> permissions, boolean all) { |
82 | if (all) { | 82 | if (all) { |
83 | //开启扫码界面 | 83 | //开启扫码界面 |
84 | startQRView(); | 84 | startQRView(); |
85 | 85 | ||
86 | 86 | ||
87 | } else { | 87 | } else { |
88 | Toast.makeText(getActivity(), "需要相机权限", Toast.LENGTH_SHORT).show(); | 88 | Toast.makeText(getActivity(), "需要相机权限", Toast.LENGTH_SHORT).show(); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | public void onDenied(List<String> permissions, boolean never) { | 93 | public void onDenied(List<String> permissions, boolean never) { |
94 | XXPermissions.startPermissionActivity(getActivity(), permissions); | 94 | XXPermissions.startPermissionActivity(getActivity(), permissions); |
95 | } | 95 | } |
96 | }); | 96 | }); |
97 | } else { | 97 | } else { |
98 | startQRView(); | 98 | startQRView(); |
99 | } | 99 | } |
100 | 100 | ||
101 | }); | 101 | }); |
102 | } | 102 | } |
103 | 103 | ||
104 | @OnClick({R.id.ll_device, R.id.ll_app}) | 104 | @OnClick({R.id.ll_device, R.id.ll_app}) |
105 | public void goApps(View view) { | 105 | public void goApps(View view) { |
106 | Toast.makeText(getActivity(), "功能暂未上线,敬请期待", Toast.LENGTH_SHORT).show(); | 106 | Toast.makeText(getActivity(), "功能暂未上线,敬请期待", Toast.LENGTH_SHORT).show(); |
107 | } | 107 | } |
108 | 108 | ||
109 | @OnClick(R.id.ll_error) | 109 | @OnClick(R.id.ll_error) |
110 | public void goError(View view) { | 110 | public void goError(View view) { |
111 | Intent intent = new Intent(getActivity(), ErrorBookActivity.class); | 111 | Intent intent = new Intent(getActivity(), ErrorBookActivity.class); |
112 | startActivity(intent); | 112 | startActivity(intent); |
113 | } | 113 | } |
114 | 114 | ||
115 | @Override | 115 | @Override |
116 | public void onResume() { | 116 | public void onResume() { |
117 | super.onResume(); | 117 | super.onResume(); |
118 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 118 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
119 | try { | 119 | try { |
120 | studentBean = new Gson().fromJson(student, StudentBean.class); | 120 | studentBean = new Gson().fromJson(student, StudentBean.class); |
121 | tv_name.setText(studentBean.getNickName()); | 121 | tv_name.setText(studentBean.getNickName()); |
122 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 122 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
123 | iv_2.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 123 | iv_2.setImageResource("男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
124 | } else { | 124 | } else { |
125 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 30)); | 125 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 30)); |
126 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 126 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
127 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into(iv_2); | 127 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into(iv_2); |
128 | } | 128 | } |
129 | getWeekPlan(studentBean.getStuId()); | 129 | getWeekPlan(studentBean.getStuId()); |
130 | } catch (Exception e) { | 130 | } catch (Exception e) { |
131 | 131 | ||
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | public void getWeekPlan(String id) { | 135 | public void getWeekPlan(String id) { |
136 | NetWorks.getWeekPlan(id, new Observer<ResponseResult<ScheduleBean>>() { | 136 | NetWorks.getWeekPlan(id, new Observer<ResponseResult<ScheduleBean>>() { |
137 | @Override | 137 | @Override |
138 | public void onSubscribe(Disposable d) { | 138 | public void onSubscribe(Disposable d) { |
139 | 139 | ||
140 | } | 140 | } |
141 | 141 | ||
142 | @Override | 142 | @Override |
143 | public void onNext(ResponseResult<ScheduleBean> result) { | 143 | public void onNext(ResponseResult<ScheduleBean> result) { |
144 | if (result != null && result.getCode() == 200) { | 144 | if (result != null && result.getCode() == 200) { |
145 | showWeekPlan(result.getData().getList()); | 145 | showWeekPlan(result.getData().getList()); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | @Override | 149 | @Override |
150 | public void onError(Throwable e) { | 150 | public void onError(Throwable e) { |
151 | 151 | ||
152 | } | 152 | } |
153 | 153 | ||
154 | @Override | 154 | @Override |
155 | public void onComplete() { | 155 | public void onComplete() { |
156 | 156 | ||
157 | } | 157 | } |
158 | }); | 158 | }); |
159 | } | 159 | } |
160 | 160 | ||
161 | public void startQRView() { | 161 | public void startQRView() { |
162 | startActivityForResult(new Intent(getActivity(), QRActivity.class), 101); | 162 | startActivityForResult(new Intent(getActivity(), QRActivity.class), 101); |
163 | } | 163 | } |
164 | 164 | ||
165 | @Override | 165 | @Override |
166 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 166 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
167 | super.onActivityResult(requestCode, resultCode, data); | 167 | super.onActivityResult(requestCode, resultCode, data); |
168 | if (requestCode == 101) { | 168 | if (requestCode == 101) { |
169 | if (null != data) { | 169 | if (null != data) { |
170 | Bundle bundle = data.getExtras(); | 170 | Bundle bundle = data.getExtras(); |
171 | if (bundle == null) { | 171 | if (bundle == null) { |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) { | 174 | if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) { |
175 | String result = bundle.getString(CodeUtils.RESULT_STRING); | 175 | String result = bundle.getString(CodeUtils.RESULT_STRING); |
176 | Toast.makeText(getActivity(), "解析结果:" + result, Toast.LENGTH_LONG).show(); | 176 | Toast.makeText(getActivity(), "解析结果:" + result, Toast.LENGTH_LONG).show(); |
177 | } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { | 177 | } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) { |
178 | Toast.makeText(getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show(); | 178 | Toast.makeText(getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show(); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | @OnClick({R.id.iv_3, R.id.tv_name}) | 184 | @OnClick({R.id.iv_3, R.id.tv_name}) |
185 | public void choose(View view) { | 185 | public void choose(View view) { |
186 | Intent intent = new Intent(getActivity(), ChooseActivity.class); | 186 | Intent intent = new Intent(getActivity(), ChooseActivity.class); |
187 | startActivity(intent); | 187 | startActivity(intent); |
188 | } | 188 | } |
189 | 189 | ||
190 | @OnClick(R.id.iv_1) | 190 | @OnClick(R.id.iv_1) |
191 | public void exit(View view) { | 191 | public void exit(View view) { |
192 | getActivity().finish(); | 192 | getActivity().finish(); |
193 | } | 193 | } |
194 | 194 | ||
195 | private void showWeekPlan(List<Video> list) { | 195 | private void showWeekPlan(List<Video> list) { |
196 | iv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); | 196 | iv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); |
197 | tv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); | 197 | tv_empty.setVisibility(list.size() > 0 ? View.GONE : View.VISIBLE); |
198 | List<Schedule> schedules = new ArrayList<>(); | 198 | List<Schedule> schedules = new ArrayList<>(); |
199 | for (int i = 0; i < list.size(); i++) { | 199 | for (int i = 0; i < list.size(); i++) { |
200 | String date = new SimpleDateFormat("yyyy.MM.dd").format(list.get(i).getStudyTime()); | 200 | String date = new SimpleDateFormat("yyyy.MM.dd").format(list.get(i).getStudyTime()); |
201 | if (schedules.size() > 0 && schedules.get(schedules.size() - 1).getDate().equals(date)) { | 201 | if (schedules.size() > 0 && schedules.get(schedules.size() - 1).getDate().equals(date)) { |
202 | schedules.get(schedules.size() - 1).getStrings().add(list.get(i).getSectionChildName()); | 202 | schedules.get(schedules.size() - 1).getStrings().add(list.get(i).getSectionChildName()); |
203 | } else { | 203 | } else { |
204 | List<String> stringList = new ArrayList<>(); | 204 | List<String> stringList = new ArrayList<>(); |
205 | Schedule schedule = new Schedule(); | 205 | Schedule schedule = new Schedule(); |
206 | schedule.setDate(date); | 206 | schedule.setDate(date); |
207 | stringList.add(list.get(i).getSectionChildName()); | 207 | stringList.add(list.get(i).getSectionChildName()); |
208 | schedule.setStrings(stringList); | 208 | schedule.setStrings(stringList); |
209 | schedules.add(schedule); | 209 | schedules.add(schedule); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_schedule, schedules) { | 212 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_schedule, schedules) { |
213 | @Override | 213 | @Override |
214 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 214 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
215 | 215 | ||
216 | } | 216 | } |
217 | 217 | ||
218 | @Override | 218 | @Override |
219 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 219 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
220 | Schedule schedule = schedules.get(item.getAdapterPosition()); | 220 | Schedule schedule = schedules.get(item.getAdapterPosition()); |
221 | item.setText(R.id.tv_date, schedule.getDate()); | 221 | item.setText(R.id.tv_date, schedule.getDate()); |
222 | LinearLayout layout = item.getView(R.id.ll_schedule); | 222 | LinearLayout layout = item.getView(R.id.ll_schedule); |
223 | for (int i = 0; i < schedule.getStrings().size(); i++) { | 223 | for (int i = 0; i < schedule.getStrings().size(); i++) { |
224 | View view = LayoutInflater.from(getContext()).inflate(R.layout.item_video, null); | 224 | View view = LayoutInflater.from(getContext()).inflate(R.layout.item_video, null); |
225 | TextView textView = view.findViewById(R.id.tv_name); | 225 | TextView textView = view.findViewById(R.id.tv_name); |
226 | textView.setText(schedule.getStrings().get(i)); | 226 | textView.setText(schedule.getStrings().get(i)); |
227 | layout.addView(view); | 227 | layout.addView(view); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | }; | 230 | }; |
231 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); | 231 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false)); |
232 | recyclerView.setAdapter(adapter); | 232 | recyclerView.setAdapter(adapter); |
233 | } | 233 | } |
234 | 234 | ||
235 | class Schedule { | 235 | class Schedule { |
236 | String date; | 236 | String date; |
237 | List<String> strings; | 237 | List<String> strings; |
238 | 238 | ||
239 | public void setDate(String date) { | 239 | public void setDate(String date) { |
240 | this.date = date; | 240 | this.date = date; |
241 | } | 241 | } |
242 | 242 | ||
243 | public void setStrings(List<String> strings) { | 243 | public void setStrings(List<String> strings) { |
244 | this.strings = strings; | 244 | this.strings = strings; |
245 | } | 245 | } |
246 | 246 | ||
247 | public String getDate() { | 247 | public String getDate() { |
248 | return date; | 248 | return date; |
249 | } | 249 | } |
250 | 250 | ||
251 | public List<String> getStrings() { | 251 | public List<String> getStrings() { |
252 | return strings; | 252 | return strings; |
253 | } | 253 | } |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 |
app/src/main/java/com/hjx/parent/fragment/MeFragment.java
1 | package com.hjx.parent.fragment; | 1 | package com.hjx.parent.fragment; |
2 | 2 | ||
3 | import android.content.Intent; | ||
4 | import android.text.TextUtils; | ||
5 | import android.view.View; | 3 | import android.content.Intent; |
6 | import android.widget.ImageView; | 4 | import android.text.TextUtils; |
7 | import android.widget.TextView; | 5 | import android.view.View; |
8 | 6 | import android.widget.ImageView; | |
9 | import androidx.annotation.NonNull; | 7 | import android.widget.TextView; |
10 | import androidx.constraintlayout.widget.Group; | ||
11 | import androidx.recyclerview.widget.LinearLayoutManager; | 8 | |
12 | import androidx.recyclerview.widget.RecyclerView; | 9 | import androidx.annotation.NonNull; |
13 | |||
14 | import com.bumptech.glide.Glide; | 10 | import androidx.constraintlayout.widget.Group; |
15 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 11 | import androidx.recyclerview.widget.LinearLayoutManager; |
16 | import com.bumptech.glide.request.RequestOptions; | 12 | import androidx.recyclerview.widget.RecyclerView; |
17 | import com.chad.library.adapter.base.BaseQuickAdapter; | 13 | |
18 | import com.chad.library.adapter.base.BaseViewHolder; | 14 | import com.bumptech.glide.Glide; |
19 | import com.google.gson.Gson; | 15 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
20 | import com.hjx.parent.AccountActivity; | 16 | import com.bumptech.glide.request.RequestOptions; |
21 | import com.hjx.parent.AddStudentActivity; | 17 | import com.chad.library.adapter.base.BaseQuickAdapter; |
22 | import com.hjx.parent.EditStudentActivity; | 18 | import com.chad.library.adapter.base.BaseViewHolder; |
23 | import com.hjx.parent.R; | ||
24 | import com.hjx.parent.UserActivity; | 19 | import com.google.gson.Gson; |
25 | import com.hjx.parent.YinsiActivity; | ||
26 | import com.hjx.parent.bean.StudentBean; | ||
27 | import com.prws.common.base.BaseFragment; | ||
28 | import com.prws.common.net.NetWorks; | ||
29 | import com.prws.common.utils.LogUtil; | 20 | import com.hjx.parent.AccountActivity; |
30 | import com.prws.common.utils.ScreenUtils; | 21 | import com.hjx.parent.AddStudentActivity; |
31 | import com.prws.common.utils.SharedPreferencesUtil; | 22 | import com.hjx.parent.EditStudentActivity; |
32 | |||
33 | import org.json.JSONArray; | ||
34 | import org.json.JSONObject; | ||
35 | 23 | import com.hjx.parent.R; | |
36 | import java.util.ArrayList; | 24 | import com.hjx.parent.UserActivity; |
37 | 25 | import com.hjx.parent.YinsiActivity; | |
38 | import io.reactivex.Observer; | 26 | import com.hjx.parent.bean.StudentBean; |
39 | import io.reactivex.disposables.Disposable; | 27 | import com.prws.common.base.BaseFragment; |
40 | import okhttp3.ResponseBody; | 28 | import com.prws.common.net.NetWorks; |
41 | 29 | import com.prws.common.utils.LogUtil; | |
42 | public class MeFragment extends BaseFragment { | 30 | import com.prws.common.utils.ScreenUtils; |
43 | @Override | 31 | import com.prws.common.utils.SharedPreferencesUtil; |
44 | protected int getLayoutRes() { | 32 | |
45 | return R.layout.fragment_me; | 33 | import org.json.JSONArray; |
46 | } | 34 | import org.json.JSONObject; |
47 | 35 | ||
48 | Group group_1; | 36 | import java.util.ArrayList; |
49 | TextView tv_name; | ||
50 | TextView tv_phone; | ||
51 | ImageView iv_toux; | ||
52 | RecyclerView recycle; | 37 | |
53 | |||
54 | @Override | ||
55 | protected void initDatas() { | 38 | import io.reactivex.Observer; |
56 | super.initDatas(); | 39 | import io.reactivex.disposables.Disposable; |
57 | recycle = mRootView.findViewById(R.id.recycle); | 40 | import okhttp3.ResponseBody; |
58 | group_1 = mRootView.findViewById(R.id.group_1); | 41 | |
59 | String role = (String) SharedPreferencesUtil.getData("role", ""); | 42 | public class MeFragment extends BaseFragment { |
60 | String userId = (String) SharedPreferencesUtil.getData("userId", ""); | 43 | @Override |
61 | String token = (String) SharedPreferencesUtil.getData("token", ""); | 44 | protected int getLayoutRes() { |
62 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); | 45 | return R.layout.fragment_me; |
63 | group_1.setVisibility(View.VISIBLE); | 46 | } |
64 | iv_toux = mRootView.findViewById(R.id.iv_toux); | 47 | |
65 | tv_name = mRootView.findViewById(R.id.tv_name); | 48 | Group group_1; |
66 | tv_phone = mRootView.findViewById(R.id.tv_phone); | 49 | TextView tv_name; |
67 | tv_phone.setVisibility(View.GONE); | 50 | TextView tv_phone; |
68 | // tv_phone.setText(phone); | 51 | ImageView iv_toux; |
69 | tv_name.setText(phone); | 52 | RecyclerView recycle; |
70 | } | 53 | |
71 | 54 | @Override | |
72 | @Override | 55 | protected void initDatas() { |
73 | public void onResume() { | 56 | super.initDatas(); |
74 | super.onResume(); | 57 | recycle = mRootView.findViewById(R.id.recycle); |
75 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 58 | group_1 = mRootView.findViewById(R.id.group_1); |
76 | if (!TextUtils.isEmpty(photo)) { | 59 | String role = (String) SharedPreferencesUtil.getData("role", ""); |
77 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 60 | String userId = (String) SharedPreferencesUtil.getData("userId", ""); |
78 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 61 | String token = (String) SharedPreferencesUtil.getData("token", ""); |
79 | Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux); | 62 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); |
80 | } | 63 | group_1.setVisibility(View.VISIBLE); |
81 | loadChildList(); | 64 | iv_toux = mRootView.findViewById(R.id.iv_toux); |
82 | } | 65 | tv_name = mRootView.findViewById(R.id.tv_name); |
83 | 66 | tv_phone = mRootView.findViewById(R.id.tv_phone); | |
84 | ArrayList<StudentBean> alist = new ArrayList<>(); | 67 | tv_phone.setVisibility(View.GONE); |
85 | 68 | // tv_phone.setText(phone); | |
86 | public void loadChildList() { | 69 | tv_name.setText(phone); |
87 | NetWorks.listChildren(new Observer<ResponseBody>() { | 70 | } |
88 | @Override | 71 | |
89 | public void onSubscribe(Disposable d) { | 72 | @Override |
90 | 73 | public void onResume() { | |
91 | } | 74 | super.onResume(); |
92 | 75 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | |
93 | @Override | 76 | if (!TextUtils.isEmpty(photo)) { |
94 | public void onNext(ResponseBody responseBody) { | 77 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
95 | try { | 78 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
96 | 79 | Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux); | |
97 | String str = responseBody.string().toString(); | 80 | } |
98 | 81 | loadChildList(); | |
99 | 82 | } | |
100 | LogUtil.e("TAG", "----" + str); | 83 | |
101 | JSONObject jo = new JSONObject(str); | 84 | ArrayList<StudentBean> alist = new ArrayList<>(); |
102 | boolean isSucceed = jo.getBoolean("success"); | 85 | |
103 | if (isSucceed) { | 86 | public void loadChildList() { |
104 | JSONArray jarr = jo.getJSONArray("data"); | 87 | NetWorks.listChildren(new Observer<ResponseBody>() { |
105 | alist.clear(); | 88 | @Override |
106 | for (int i = 0; i < jarr.length(); i++) { | 89 | public void onSubscribe(Disposable d) { |
107 | JSONObject jo2 = jarr.getJSONObject(i); | 90 | |
108 | Gson gson = new Gson(); | 91 | } |
109 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); | 92 | |
110 | alist.add(sb); | 93 | @Override |
111 | } | 94 | public void onNext(ResponseBody responseBody) { |
112 | if (alist.size() > 0) { | 95 | try { |
113 | loadList(); | 96 | |
114 | } | 97 | String str = responseBody.string().toString(); |
115 | 98 | ||
116 | } else { | 99 | |
117 | 100 | LogUtil.e("TAG", "----" + str); | |
118 | } | 101 | JSONObject jo = new JSONObject(str); |
119 | } catch (Exception e) { | 102 | boolean isSucceed = jo.getBoolean("success"); |
120 | e.printStackTrace(); | 103 | if (isSucceed) { |
121 | } | 104 | JSONArray jarr = jo.getJSONArray("data"); |
122 | } | 105 | alist.clear(); |
123 | 106 | for (int i = 0; i < jarr.length(); i++) { | |
124 | @Override | 107 | JSONObject jo2 = jarr.getJSONObject(i); |
125 | public void onError(Throwable e) { | 108 | Gson gson = new Gson(); |
126 | e.toString(); | 109 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); |
127 | } | 110 | alist.add(sb); |
128 | 111 | } | |
129 | @Override | 112 | if (alist.size() > 0) { |
130 | public void onComplete() { | 113 | loadList(); |
131 | 114 | } | |
132 | } | 115 | |
133 | }); | 116 | } else { |
134 | mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class))); | 117 | |
135 | mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class))); | 118 | } |
136 | mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003)); | 119 | } catch (Exception e) { |
137 | } | 120 | e.printStackTrace(); |
138 | 121 | } | |
139 | // @Override | 122 | } |
140 | // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 123 | |
141 | // super.onActivityResult(requestCode, resultCode, data); | 124 | @Override |
142 | // Intent intent = new Intent(getActivity(), LoginActivity.class); | 125 | public void onError(Throwable e) { |
143 | // startActivity(intent); | 126 | e.toString(); |
144 | // getActivity().finish(); | 127 | } |
145 | // } | 128 | |
146 | 129 | @Override | |
147 | public void loadList() { | 130 | public void onComplete() { |
148 | StudentBean sb = new StudentBean(); | 131 | |
149 | sb.setNickName("添加学生"); | 132 | } |
150 | alist.add(0, sb); | 133 | }); |
151 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { | 134 | mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class))); |
152 | @Override | 135 | mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class))); |
153 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 136 | mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003)); |
154 | 137 | } | |
155 | } | 138 | |
156 | 139 | // @Override | |
157 | @Override | 140 | // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
158 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 141 | // super.onActivityResult(requestCode, resultCode, data); |
159 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 142 | // Intent intent = new Intent(getActivity(), LoginActivity.class); |
160 | item.setText(R.id.tv_name, studentBean.getNickName()); | 143 | // startActivity(intent); |
161 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 144 | // getActivity().finish(); |
162 | item.setImageResource(R.id.iv_avatar, R.mipmap.tjxss); | 145 | // } |
163 | item.setVisible(R.id.iv_vip, false); | 146 | |
164 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 147 | public void loadList() { |
165 | @Override | 148 | StudentBean sb = new StudentBean(); |
166 | public void onClick(View view) { | 149 | sb.setNickName("添加学生"); |
167 | startActivity(new Intent(getActivity(), AddStudentActivity.class)); | 150 | alist.add(0, sb); |
168 | } | 151 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { |
169 | }); | 152 | @Override |
170 | } else { | 153 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
171 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 154 | |
172 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 155 | } |
173 | } else { | 156 | |
174 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 157 | @Override |
175 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 158 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
176 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 159 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
177 | } | 160 | item.setText(R.id.tv_name, studentBean.getNickName()); |
178 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); | 161 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
179 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 162 | item.setImageResource(R.id.iv_avatar, R.mipmap.tjxss); |
180 | @Override | 163 | item.setVisible(R.id.iv_vip, false); |
181 | public void onClick(View view) { | 164 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
182 | startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); | 165 | @Override |
183 | } | 166 | public void onClick(View view) { |
184 | }); | 167 | startActivity(new Intent(getActivity(), AddStudentActivity.class)); |
185 | } | 168 | } |
186 | } | 169 | }); |
187 | }; | 170 | } else { |
188 | recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | 171 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
189 | recycle.setAdapter(adapter); | 172 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
190 | } | 173 | } else { |
191 | 174 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | |
192 | } | 175 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
193 | 176 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
build.gradle
1 | buildscript { | 1 | buildscript { |
2 | 2 | ||
3 | 3 | ||
4 | ext { | 4 | ext { |
5 | 5 | ||
6 | 6 | ||
7 | androidId = [ | 7 | androidId = [ |
8 | compileSdkVersion: 32, | 8 | compileSdkVersion: 32, |
9 | minSdkVersion : 26, | 9 | minSdkVersion : 26, |
10 | targetSdkVersion : 32, | 10 | targetSdkVersion : 32, |
11 | versionCode : 1, | 11 | versionCode : 1, |
12 | versionName : "0.0.1" | 12 | versionName : "0.0.1" |
13 | 13 | ||
14 | 14 | ||
15 | ] | 15 | ] |
16 | 16 | ||
17 | 17 | ||
18 | url = [ | 18 | url = [ |
19 | server_url : "http://192.168.3.144:8088", //http 请求指令 | 19 | server_url : "http://192.168.3.144:8088", //http 请求指令 |
20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 | 20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 |
21 | ] | 21 | ] |
22 | 22 | ||
23 | 23 | ||
24 | dependencies = [ | 24 | dependencies = [ |
25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', | 25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', |
26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', | 26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', |
27 | cardview : 'androidx.cardview:cardview:1.0.0', | 27 | cardview : 'androidx.cardview:cardview:1.0.0', |
28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', | 28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', |
29 | material : 'com.google.android.material:material:1.0.0', | 29 | material : 'com.google.android.material:material:1.0.0', |
30 | // 依赖RxAndroid 2X 的依赖库 | 30 | // 依赖RxAndroid 2X 的依赖库 |
31 | // 增加RxJava 2X 的依赖库 | 31 | // 增加RxJava 2X 的依赖库 |
32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', | 32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', |
33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', | 33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', |
34 | 34 | ||
35 | // 以下需要使用Retrofit | 35 | // 以下需要使用Retrofit |
36 | //retrofit | 36 | //retrofit |
37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', | 37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', |
38 | //Gson converter | 38 | //Gson converter |
39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', | 39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', |
40 | //RxJava2 Adapter | 40 | //RxJava2 Adapter |
41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', | 41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', |
42 | //okhttp | 42 | //okhttp |
43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', | 43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', |
44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', | 44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', |
45 | // utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', | 45 | // utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', |
46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', | 46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', |
47 | commons_compress: 'org.apache.commons:commons-compress:1.19', | 47 | commons_compress: 'org.apache.commons:commons-compress:1.19', |
48 | commons_c_lang : 'commons-lang:commons-lang:2.3', | 48 | commons_c_lang : 'commons-lang:commons-lang:2.3', |
49 | commons_codec : 'commons-codec:commons-codec:1.7', | 49 | commons_codec : 'commons-codec:commons-codec:1.7', |
50 | eventbus : 'org.greenrobot:eventbus:3.2.0', | 50 | eventbus : 'org.greenrobot:eventbus:3.2.0', |
51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', | 51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', |
52 | glide : 'com.github.bumptech.glide:glide:4.6.1', | 52 | glide : 'com.github.bumptech.glide:glide:4.6.1', |
53 | permissions : 'com.github.getActivity:XXPermissions:18.5', | 53 | permissions : 'com.github.getActivity:XXPermissions:18.5', |
54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' | 54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' |
55 | // push : 'com.umeng.sdk:push:4.1.0', | 55 | // push : 'com.umeng.sdk:push:4.1.0', |
56 | // litepal : 'org.litepal.android:java:3.0.0', | 56 | // litepal : 'org.litepal.android:java:3.0.0', |
57 | 57 | ||
58 | 58 | ||
59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', | 59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', |
60 | 60 | ||
61 | // | 61 | // |
62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', | 62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', |
63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', | 63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', |
64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' | 64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' |
65 | 65 | ||
66 | 66 | ||
67 | ] | 67 | ] |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | repositories { | 71 | repositories { |
72 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } | 72 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } |
73 | maven { url 'https://maven.aliyun.com/repository/public' } | ||
73 | maven { url 'https://maven.aliyun.com/repository/public' } | 74 | maven { url 'https://maven.aliyun.com/repository/google' } |
74 | maven { url 'https://maven.aliyun.com/repository/google' } | 75 | maven { url 'https://repo.huaweicloud.com/repository/maven-public/' } |
76 | //maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' } | ||
77 | |||
75 | maven { url 'https://repo.huaweicloud.com/repository/maven-public/' } | 78 | google() |
76 | //maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' } | 79 | mavenCentral() |
80 | gradlePluginPortal() | ||
81 | maven { url "https://jitpack.io" } | ||
77 | 82 | } | |
78 | google() | 83 | dependencies { |
79 | mavenCentral() | 84 | classpath 'com.android.tools.build:gradle:4.2.2' |
80 | gradlePluginPortal() | 85 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' |
81 | maven { url "https://jitpack.io" } | 86 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' |
82 | } | 87 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' |
83 | dependencies { | 88 | classpath "com.alibaba:arouter-register:1.0.2" |
84 | classpath 'com.android.tools.build:gradle:4.2.2' | 89 | // NOTE: Do not place your application dependencies here; they belong |
85 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' | 90 | // in the individual module build.gradle files |
86 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' | 91 | } |
87 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' | 92 | |
88 | classpath "com.alibaba:arouter-register:1.0.2" | 93 | |
89 | // NOTE: Do not place your application dependencies here; they belong | 94 | } |
90 | // in the individual module build.gradle files | 95 | |
91 | } | 96 | |
92 | 97 | allprojects { | |
93 | 98 | repositories { | |
94 | } | 99 | maven { url 'https://maven.aliyun.com/repository/public' } |
95 | 100 | maven { url 'https://maven.aliyun.com/repository/google' } | |
96 | 101 | maven { url 'https://repo.huaweicloud.com/repository/maven-public/' } | |
102 | //maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' } | ||
103 | |||
97 | allprojects { | 104 | google() |
98 | repositories { | 105 | mavenCentral() |
106 | maven { url "https://jitpack.io" } | ||
99 | maven { url 'https://maven.aliyun.com/repository/public' } | 107 | } |
100 | maven { url 'https://maven.aliyun.com/repository/google' } | 108 | } |
101 | maven { url 'https://repo.huaweicloud.com/repository/maven-public/' } | 109 | task clean(type: Delete) { |
102 | //maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' } | 110 | delete rootProject.buildDir |
103 | 111 | } | |
104 | google() | 112 |
libs/common/src/main/java/com/prws/common/base/BaseActivity.java
1 | package com.prws.common.base; | 1 | package com.prws.common.base; |
2 | 2 | ||
3 | 3 | ||
4 | import android.app.Activity; | 4 | import android.app.Activity; |
5 | import android.app.AlertDialog; | 5 | import android.app.AlertDialog; |
6 | import android.content.Context; | 6 | import android.content.Context; |
7 | import android.content.DialogInterface; | 7 | import android.content.DialogInterface; |
8 | import android.content.Intent; | 8 | import android.content.Intent; |
9 | import android.graphics.Color; | 9 | import android.graphics.Color; |
10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
11 | import android.os.IBinder; | 11 | import android.os.IBinder; |
12 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
13 | import android.util.Log; | 13 | import android.util.Log; |
14 | import android.view.MotionEvent; | 14 | import android.view.MotionEvent; |
15 | import android.view.View; | 15 | import android.view.View; |
16 | import android.view.Window; | 16 | import android.view.Window; |
17 | import android.view.WindowManager; | 17 | import android.view.WindowManager; |
18 | import android.view.inputmethod.InputMethodManager; | 18 | import android.view.inputmethod.InputMethodManager; |
19 | import android.widget.EditText; | 19 | import android.widget.EditText; |
20 | import android.widget.Toast; | 20 | import android.widget.Toast; |
21 | 21 | ||
22 | import androidx.annotation.IdRes; | 22 | import androidx.annotation.IdRes; |
23 | import androidx.annotation.Nullable; | 23 | import androidx.annotation.Nullable; |
24 | import androidx.appcompat.app.AppCompatActivity; | 24 | import androidx.appcompat.app.AppCompatActivity; |
25 | import androidx.fragment.app.Fragment; | 25 | import androidx.fragment.app.Fragment; |
26 | import androidx.fragment.app.FragmentTransaction; | 26 | import androidx.fragment.app.FragmentTransaction; |
27 | import androidx.lifecycle.Lifecycle; | 27 | import androidx.lifecycle.Lifecycle; |
28 | 28 | ||
29 | import com.prws.common.R; | ||
30 | import com.prws.common.net.INetEvent; | 29 | import com.prws.common.R; |
31 | import com.prws.common.utils.LogUtil; | 30 | import com.prws.common.net.INetEvent; |
32 | import com.prws.common.utils.ScreenUtils; | 31 | import com.prws.common.utils.LogUtil; |
33 | import com.prws.common.view.LoadingView; | 32 | import com.prws.common.utils.ScreenUtils; |
34 | |||
35 | import org.simple.eventbus.EventBus; | 33 | import com.prws.common.view.LoadingView; |
36 | 34 | ||
37 | import java.util.ArrayList; | 35 | import org.simple.eventbus.EventBus; |
38 | import java.util.List; | 36 | |
39 | 37 | import java.util.ArrayList; | |
40 | import butterknife.ButterKnife; | 38 | import java.util.List; |
41 | import io.reactivex.disposables.CompositeDisposable; | 39 | |
42 | import io.reactivex.disposables.Disposable; | 40 | import butterknife.ButterKnife; |
43 | 41 | import io.reactivex.disposables.CompositeDisposable; | |
44 | 42 | import io.reactivex.disposables.Disposable; | |
45 | /** | 43 | |
46 | * @author 描述:BaseActivity | 44 | |
47 | */ | 45 | /** |
48 | public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends AppCompatActivity implements INetEvent, BaseView { | 46 | * @author 描述:BaseActivity |
49 | 47 | */ | |
50 | 48 | public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends AppCompatActivity implements INetEvent, BaseView { | |
51 | private LoadingView loading; | 49 | |
52 | 50 | ||
53 | public static INetEvent mINetEvent; | 51 | private LoadingView loading; |
54 | protected final String TAG = getClass().getSimpleName(); | 52 | |
55 | private CompositeDisposable mCompositeDisposable; | 53 | public static INetEvent mINetEvent; |
56 | protected P p; | 54 | protected final String TAG = getClass().getSimpleName(); |
57 | 55 | private CompositeDisposable mCompositeDisposable; | |
58 | /** | 56 | protected P p; |
59 | * 获取布局文件 | 57 | |
60 | * | 58 | /** |
61 | * @return | 59 | * 获取布局文件 |
62 | */ | 60 | * |
63 | protected abstract int layoutResId(); | 61 | * @return |
64 | 62 | */ | |
65 | /** | 63 | protected abstract int layoutResId(); |
66 | * 让P层做相应需求 | 64 | |
67 | */ | 65 | /** |
68 | public abstract CONTRACT getContract(); | 66 | * 让P层做相应需求 |
69 | 67 | */ | |
70 | /** | 68 | public abstract CONTRACT getContract(); |
71 | * 子类获取具体契约 | 69 | |
72 | */ | 70 | /** |
73 | public abstract P getPresenter(); | 71 | * 子类获取具体契约 |
74 | 72 | */ | |
75 | @Override | 73 | public abstract P getPresenter(); |
76 | protected void onCreate(@Nullable Bundle savedInstanceState) { | 74 | |
77 | super.onCreate(savedInstanceState); | 75 | @Override |
78 | setNetEvent(); | 76 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
79 | initPresenter(); | 77 | super.onCreate(savedInstanceState); |
80 | showWhiteStatus(); | 78 | setNetEvent(); |
81 | setContentView(layoutResId()); | 79 | initPresenter(); |
82 | ButterKnife.bind(this); | 80 | showWhiteStatus(); |
83 | registerEventBus(); | 81 | setContentView(layoutResId()); |
84 | initView(); | 82 | ButterKnife.bind(this); |
85 | initListener(); | 83 | registerEventBus(); |
86 | initData(); | 84 | initView(); |
87 | 85 | initListener(); | |
88 | } | 86 | initData(); |
89 | 87 | ||
90 | 88 | } | |
91 | public void showWhiteStatus() { | 89 | |
92 | Window window = getWindow(); | 90 | |
93 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 91 | public void showWhiteStatus() { |
94 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | 92 | Window window = getWindow(); |
95 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 93 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
96 | window.setStatusBarColor(Color.TRANSPARENT); | 94 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
97 | } | 95 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
98 | 96 | window.setStatusBarColor(Color.TRANSPARENT); | |
99 | 97 | } | |
100 | public void fullScreen(){ | 98 | |
101 | Window window = getWindow(); | 99 | |
102 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 100 | public void fullScreen(){ |
103 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 101 | Window window = getWindow(); |
104 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); | 102 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
105 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 103 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
106 | window.setStatusBarColor(Color.TRANSPARENT); | 104 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); |
107 | } | 105 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
108 | 106 | window.setStatusBarColor(Color.TRANSPARENT); | |
109 | protected void blackBar() { | 107 | } |
110 | Window window = getWindow(); | 108 | |
111 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | 109 | protected void blackBar() { |
112 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 110 | Window window = getWindow(); |
113 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | 111 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
114 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | 112 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
115 | window.setStatusBarColor(Color.TRANSPARENT); | 113 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
116 | } | 114 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
117 | 115 | window.setStatusBarColor(Color.TRANSPARENT); | |
118 | @Override | 116 | } |
119 | protected void onResume() { | 117 | |
120 | super.onResume(); | 118 | @Override |
121 | } | 119 | protected void onResume() { |
122 | 120 | super.onResume(); | |
123 | protected abstract void initView(); | 121 | } |
124 | 122 | ||
125 | protected abstract void initListener(); | 123 | protected abstract void initView(); |
126 | 124 | ||
127 | protected abstract void initData(); | 125 | protected abstract void initListener(); |
128 | 126 | ||
129 | 127 | protected abstract void initData(); | |
130 | private void setNetEvent() { | 128 | |
131 | mINetEvent = this; | 129 | |
132 | } | 130 | private void setNetEvent() { |
133 | 131 | mINetEvent = this; | |
134 | private void initPresenter() { | 132 | } |
135 | p = getPresenter(); | 133 | |
136 | if (p != null) | 134 | private void initPresenter() { |
137 | p.bindView(this); | 135 | p = getPresenter(); |
138 | } | 136 | if (p != null) |
139 | 137 | p.bindView(this); | |
140 | 138 | } | |
141 | public void showDialog(String title, String message, String confirm, String cancel, DialogInterface.OnClickListener cancelListener, DialogInterface.OnClickListener listener) { | 139 | |
142 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); | 140 | |
143 | builder.setTitle(title); | 141 | public void showDialog(String title, String message, String confirm, String cancel, DialogInterface.OnClickListener cancelListener, DialogInterface.OnClickListener listener) { |
144 | builder.setMessage(message); | 142 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
145 | builder.setCancelable(false); | 143 | builder.setTitle(title); |
146 | if (!TextUtils.isEmpty(cancel)) { | 144 | builder.setMessage(message); |
147 | builder.setNegativeButton(cancel, cancelListener); | 145 | builder.setCancelable(false); |
148 | } | 146 | if (!TextUtils.isEmpty(cancel)) { |
149 | builder.setPositiveButton(confirm, listener); | 147 | builder.setNegativeButton(cancel, cancelListener); |
150 | builder.show(); | 148 | } |
151 | } | 149 | builder.setPositiveButton(confirm, listener); |
152 | 150 | builder.show(); | |
153 | private void setWindow() { | 151 | } |
154 | Window window = getWindow(); | 152 | |
155 | WindowManager.LayoutParams params = window.getAttributes(); | 153 | private void setWindow() { |
156 | params.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN | 154 | Window window = getWindow(); |
157 | ; | 155 | WindowManager.LayoutParams params = window.getAttributes(); |
158 | window.setAttributes(params); | 156 | params.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN |
159 | } | 157 | ; |
160 | 158 | window.setAttributes(params); | |
161 | 159 | } | |
162 | // public void openFloatWindow() { | 160 | |
163 | // if (FloatWindow.get("navigation") == null) { | 161 | |
164 | // NavigationBarView navigationBarView = new NavigationBarView(this); | ||
165 | // FloatWindow.with(CommonApplication.getAppContext()) | ||
166 | // .setView(navigationBarView) | ||
167 | // .setWidth(Screen.width, 1) | ||
168 | // .setHeight(WindowManager.LayoutParams.WRAP_CONTENT) | ||
169 | // .setX(0) | ||
170 | // .setY(0) | ||
171 | // .setMoveType(MoveType.inactive) | ||
172 | // .setDesktopShow(false) | ||
173 | // .setTag("navigation") | ||
174 | // .build(); | 162 | // public void openFloatWindow() { |
175 | // } | 163 | // if (FloatWindow.get("navigation") == null) { |
176 | // if (!FloatWindow.get("navigation").isShowing()) | 164 | // NavigationBarView navigationBarView = new NavigationBarView(this); |
177 | // FloatWindow.get("navigation").show(); | 165 | // FloatWindow.with(CommonApplication.getAppContext()) |
178 | // | 166 | // .setView(navigationBarView) |
179 | // } | 167 | // .setWidth(Screen.width, 1) |
180 | 168 | // .setHeight(WindowManager.LayoutParams.WRAP_CONTENT) | |
181 | 169 | // .setX(0) | |
182 | public void showAlertDialogOfFloatWindow() { | 170 | // .setY(0) |
183 | //弹窗提示用户开启权限 | 171 | // .setMoveType(MoveType.inactive) |
184 | // new AlertDialog(this).builder().setTitle(getString(R.string.need_permission)) | 172 | // .setDesktopShow(false) |
185 | // .setMsg(getString(R.string.need_permission_window)) | 173 | // .setTag("navigation") |
186 | // .setPositiveButton(getString(R.string.open), new View.OnClickListener() { | 174 | // .build(); |
187 | // @Override | 175 | // } |
188 | // public void onClick(View v) { | 176 | // if (!FloatWindow.get("navigation").isShowing()) |
189 | // Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | 177 | // FloatWindow.get("navigation").show(); |
190 | // intent.setData(Uri.parse("package:" + getPackageName())); | 178 | // |
191 | // startActivity(intent); | 179 | // } |
192 | // } | 180 | |
193 | // }).setNegativeButton(getString(R.string.cancel), new View.OnClickListener() { | 181 | |
194 | // @Override | 182 | public void showAlertDialogOfFloatWindow() { |
195 | // public void onClick(View v) { | 183 | //弹窗提示用户开启权限 |
196 | // } | 184 | // new AlertDialog(this).builder().setTitle(getString(R.string.need_permission)) |
197 | // }).show(); | 185 | // .setMsg(getString(R.string.need_permission_window)) |
198 | LogUtil.toast("请开启浮窗权限"); | 186 | // .setPositiveButton(getString(R.string.open), new View.OnClickListener() { |
199 | } | 187 | // @Override |
200 | 188 | // public void onClick(View v) { | |
201 | 189 | // Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | |
202 | public void showLoading(String title) { | 190 | // intent.setData(Uri.parse("package:" + getPackageName())); |
203 | synchronized (this) { | 191 | // startActivity(intent); |
204 | if (loading != null || !isLiving(this)) return; | 192 | // } |
205 | runOnUiThread(() -> { | 193 | // }).setNegativeButton(getString(R.string.cancel), new View.OnClickListener() { |
206 | loading = new LoadingView(this, R.style.CustomDialog, title); | 194 | // @Override |
207 | loading.show(); | 195 | // public void onClick(View v) { |
208 | ScreenUtils.hideBottomUIMenu(this); | 196 | // } |
209 | ScreenUtils.hideDialogBottomUIMenu(loading); | 197 | // }).show(); |
210 | }); | 198 | LogUtil.toast("请开启浮窗权限"); |
211 | } | 199 | } |
212 | } | 200 | |
213 | 201 | ||
214 | 202 | public void showLoading(String title) { | |
215 | public void setCanAble(boolean canAble) { | 203 | synchronized (this) { |
216 | if (loading != null) | 204 | if (loading != null || !isLiving(this)) return; |
217 | loading.setCancelable(canAble); | 205 | runOnUiThread(() -> { |
218 | 206 | loading = new LoadingView(this, R.style.CustomDialog, title); | |
219 | } | 207 | loading.show(); |
220 | 208 | ScreenUtils.hideBottomUIMenu(this); | |
221 | public boolean isShowLoading() { | 209 | ScreenUtils.hideDialogBottomUIMenu(loading); |
222 | if (loading == null) return false; | 210 | }); |
223 | return loading.isShowing(); | 211 | } |
224 | } | 212 | } |
225 | 213 | ||
226 | public void dismissLoading() { | 214 | |
227 | runOnUiThread(() -> { | 215 | public void setCanAble(boolean canAble) { |
228 | if (loading == null || loading.isShowing() == false || !isLiving(this)) { | 216 | if (loading != null) |
229 | Log.w(TAG, "loading == null" + | 217 | loading.setCancelable(canAble); |
230 | " || loading.isShowing() == false >> return;"); | 218 | |
231 | return; | 219 | } |
232 | } | 220 | |
233 | loading.dismiss(); | 221 | public boolean isShowLoading() { |
234 | loading = null; | 222 | if (loading == null) return false; |
235 | 223 | return loading.isShowing(); | |
236 | }); | 224 | } |
237 | } | 225 | |
238 | 226 | public void dismissLoading() { | |
239 | 227 | runOnUiThread(() -> { | |
240 | private static boolean isLiving(Activity activity) { | 228 | if (loading == null || loading.isShowing() == false || !isLiving(this)) { |
241 | 229 | Log.w(TAG, "loading == null" + | |
242 | if (activity == null) { | 230 | " || loading.isShowing() == false >> return;"); |
243 | Log.d("wisely", "activity == null"); | 231 | return; |
244 | return false; | 232 | } |
245 | } | 233 | loading.dismiss(); |
246 | 234 | loading = null; | |
247 | if (activity.isFinishing()) { | 235 | |
248 | Log.d("wisely", "activity is finishing"); | 236 | }); |
249 | return false; | 237 | } |
250 | } | 238 | |
251 | 239 | ||
252 | return true; | 240 | private static boolean isLiving(Activity activity) { |
253 | } | 241 | |
254 | 242 | if (activity == null) { | |
255 | 243 | Log.d("wisely", "activity == null"); | |
256 | /** | 244 | return false; |
257 | * 是否需要弹窗提示更新 | 245 | } |
258 | */ | 246 | |
259 | protected void isNeedGetVersionUpdate() { | 247 | if (activity.isFinishing()) { |
260 | // View view = findViewById(R.id.view_loading); | 248 | Log.d("wisely", "activity is finishing"); |
261 | //如果显示正在下载的页面,则不弹出更新弹窗 | 249 | return false; |
262 | // if (null == view || view.getVisibility() == View.VISIBLE) return; | 250 | } |
263 | // UpdateUtils.getVersion(this); | 251 | |
264 | } | 252 | return true; |
265 | 253 | } | |
266 | 254 | ||
267 | /** | 255 | |
268 | * 全局检测网络广播的回调 处理网络变化 | 256 | /** |
269 | * 注:在程序第一次启动的时候,没网并不会回调,需要自己在启动页面,或者主页自己再判断一次 | 257 | * 是否需要弹窗提示更新 |
270 | * | 258 | */ |
271 | * @param netWorkState 网络状态 -1:没网络 0:移动网络 1:WiFi网络 | 259 | protected void isNeedGetVersionUpdate() { |
272 | */ | 260 | // View view = findViewById(R.id.view_loading); |
273 | public abstract void onNetChanged(int netWorkState); | 261 | //如果显示正在下载的页面,则不弹出更新弹窗 |
274 | 262 | // if (null == view || view.getVisibility() == View.VISIBLE) return; | |
275 | @Override | 263 | // UpdateUtils.getVersion(this); |
276 | public void onNetChange(int netWorkState) { | 264 | } |
277 | onNetChanged(netWorkState); | 265 | |
278 | } | 266 | |
279 | 267 | /** | |
280 | @Override | 268 | * 全局检测网络广播的回调 处理网络变化 |
281 | protected void onDestroy() { | 269 | * 注:在程序第一次启动的时候,没网并不会回调,需要自己在启动页面,或者主页自己再判断一次 |
282 | super.onDestroy(); | 270 | * |
283 | unSubscribe(); | 271 | * @param netWorkState 网络状态 -1:没网络 0:移动网络 1:WiFi网络 |
284 | cleanFragment(); | 272 | */ |
285 | unregisterEventBus(); | 273 | public abstract void onNetChanged(int netWorkState); |
286 | if (p != null) { | 274 | |
287 | p.onBindView(); | 275 | @Override |
288 | p.cancelAllRequest(); | 276 | public void onNetChange(int netWorkState) { |
289 | } | 277 | onNetChanged(netWorkState); |
290 | } | 278 | } |
291 | 279 | ||
292 | @Override | 280 | @Override |
293 | protected void onPause() { | 281 | protected void onDestroy() { |
294 | super.onPause(); | 282 | super.onDestroy(); |
295 | 283 | unSubscribe(); | |
296 | } | 284 | cleanFragment(); |
297 | 285 | unregisterEventBus(); | |
298 | private void registerEventBus() { | 286 | if (p != null) { |
299 | EventBus.getDefault().register(this); | 287 | p.onBindView(); |
300 | } | 288 | p.cancelAllRequest(); |
301 | 289 | } | |
302 | private void unregisterEventBus() { | 290 | } |
303 | EventBus.getDefault().unregister(this); | 291 | |
304 | } | 292 | @Override |
305 | 293 | protected void onPause() { | |
306 | public void showErrorToast() { | 294 | super.onPause(); |
307 | // LogUtil.toast(MainApplication.getAppContext(), getString(R.string.service_error)); | 295 | |
308 | } | 296 | } |
309 | 297 | ||
310 | public void showToast(String s) { | 298 | private void registerEventBus() { |
311 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); | 299 | EventBus.getDefault().register(this); |
312 | } | 300 | } |
313 | 301 | ||
314 | private void unSubscribe() { | 302 | private void unregisterEventBus() { |
315 | if (mCompositeDisposable != null) { | 303 | EventBus.getDefault().unregister(this); |
316 | mCompositeDisposable.clear(); | 304 | } |
317 | } | 305 | |
318 | } | 306 | public void showErrorToast() { |
319 | 307 | // LogUtil.toast(MainApplication.getAppContext(), getString(R.string.service_error)); | |
320 | protected void addSubscribe(Disposable disposable) { | 308 | } |
321 | if (mCompositeDisposable == null) { | 309 | |
322 | mCompositeDisposable = new CompositeDisposable(); | 310 | public void showToast(String s) { |
323 | } | 311 | Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); |
324 | mCompositeDisposable.add(disposable); | 312 | } |
325 | } | 313 | |
326 | 314 | private void unSubscribe() { | |
327 | protected void startActivity(Class clazz) { | 315 | if (mCompositeDisposable != null) { |
328 | startActivity(new Intent(this, clazz)); | 316 | mCompositeDisposable.clear(); |
329 | } | 317 | } |
330 | 318 | } | |
331 | /******************** 处理fragment *******************************/ | 319 | |
332 | List<Fragment> fragmentList = new ArrayList<>(); | 320 | protected void addSubscribe(Disposable disposable) { |
333 | 321 | if (mCompositeDisposable == null) { | |
334 | protected void showFragment(Fragment fragment, @IdRes int id) { | 322 | mCompositeDisposable = new CompositeDisposable(); |
335 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | 323 | } |
336 | 324 | mCompositeDisposable.add(disposable); | |
337 | if (!fragmentList.contains(fragment)) { | 325 | } |
338 | fragmentList.add(fragment); | 326 | |
339 | fragmentTransaction.add(id, fragment, fragment.getClass().getSimpleName()).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); | 327 | protected void startActivity(Class clazz) { |
340 | } | 328 | startActivity(new Intent(this, clazz)); |
341 | 329 | } | |
342 | fragmentTransaction.show(fragment).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); | 330 | |
343 | 331 | /******************** 处理fragment *******************************/ | |
344 | for (Fragment fragment1 : fragmentList) { | 332 | List<Fragment> fragmentList = new ArrayList<>(); |
345 | if (fragment1 != fragment) { | 333 | |
346 | fragmentTransaction.hide(fragment1).setMaxLifecycle(fragment1, Lifecycle.State.STARTED); | 334 | protected void showFragment(Fragment fragment, @IdRes int id) { |
347 | } | 335 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); |
348 | } | 336 | |
349 | 337 | if (!fragmentList.contains(fragment)) { | |
350 | fragmentTransaction.commitAllowingStateLoss(); | 338 | fragmentList.add(fragment); |
351 | 339 | fragmentTransaction.add(id, fragment, fragment.getClass().getSimpleName()).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); | |
352 | } | 340 | } |
353 | 341 | ||
354 | protected void cleanFragment() { | 342 | fragmentTransaction.show(fragment).setMaxLifecycle(fragment, Lifecycle.State.RESUMED); |
355 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | 343 | |
356 | if (fragmentList.size() > 0) { | 344 | for (Fragment fragment1 : fragmentList) { |
357 | for (Fragment fragment : fragmentList) { | 345 | if (fragment1 != fragment) { |
358 | fragmentTransaction.remove(fragment); | 346 | fragmentTransaction.hide(fragment1).setMaxLifecycle(fragment1, Lifecycle.State.STARTED); |
359 | } | 347 | } |
360 | try { | 348 | } |
361 | fragmentTransaction.commitNowAllowingStateLoss(); | 349 | |
362 | } catch (Exception e) { | 350 | fragmentTransaction.commitAllowingStateLoss(); |
363 | e.printStackTrace(); | 351 | |
364 | } | 352 | } |
365 | } | 353 | |
366 | fragmentList.clear(); | 354 | protected void cleanFragment() { |
367 | } | 355 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); |
368 | 356 | if (fragmentList.size() > 0) { | |
369 | //************************* 用于隐藏键盘 ***************************************// | 357 | for (Fragment fragment : fragmentList) { |
370 | @Override | 358 | fragmentTransaction.remove(fragment); |
371 | public boolean dispatchTouchEvent(MotionEvent ev) { | 359 | } |
372 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { | 360 | try { |
373 | 361 | fragmentTransaction.commitNowAllowingStateLoss(); | |
374 | View v = getCurrentFocus(); | 362 | } catch (Exception e) { |
375 | if (isShouldHideInput(v, ev)) { | 363 | e.printStackTrace(); |
376 | hideSoftInput(v.getWindowToken()); | 364 | } |
377 | } | 365 | } |
378 | } | 366 | fragmentList.clear(); |
379 | return super.dispatchTouchEvent(ev); | 367 | } |
380 | } | 368 | |
381 | 369 | //************************* 用于隐藏键盘 ***************************************// | |
382 | private boolean isShouldHideInput(View v, MotionEvent event) { | 370 | @Override |
383 | if (v != null && (v instanceof EditText)) { | 371 | public boolean dispatchTouchEvent(MotionEvent ev) { |
384 | int[] l = {0, 0}; | 372 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
385 | v.getLocationInWindow(l); | 373 | |
386 | int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left | 374 | View v = getCurrentFocus(); |
387 | + v.getWidth(); | 375 | if (isShouldHideInput(v, ev)) { |
388 | if (event.getX() > left && event.getX() < right | 376 | hideSoftInput(v.getWindowToken()); |
389 | && event.getY() > top && event.getY() < bottom) { | 377 | } |
390 | // 点击EditText的事件,忽略它。 | 378 | } |
391 | return false; | 379 | return super.dispatchTouchEvent(ev); |
392 | } else { | 380 | } |
393 | return true; | 381 | |
394 | } | 382 | private boolean isShouldHideInput(View v, MotionEvent event) { |
395 | } | 383 | if (v != null && (v instanceof EditText)) { |
396 | 384 | int[] l = {0, 0}; | |
397 | return false; | 385 | v.getLocationInWindow(l); |
398 | } | 386 | int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left |
399 | 387 | + v.getWidth(); | |
400 | /** | 388 | if (event.getX() > left && event.getX() < right |
401 | * 多种隐藏软件盘方法的其中一种 | 389 | && event.getY() > top && event.getY() < bottom) { |
402 | * | 390 | // 点击EditText的事件,忽略它。 |
403 | * @param token | 391 | return false; |
404 | */ | 392 | } else { |
405 | private void hideSoftInput(IBinder token) { | 393 | return true; |
406 | LogUtil.i(TAG, "隐藏键盘"); | 394 | } |
407 | if (token != null) { | 395 | } |
408 | InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | 396 | |
409 | im.hideSoftInputFromWindow(token, | 397 | return false; |
410 | InputMethodManager.HIDE_NOT_ALWAYS); | 398 | } |
411 | } | 399 | |
412 | } | 400 | /** |
413 | 401 | * 多种隐藏软件盘方法的其中一种 | |
414 | //************************* 用于隐藏键盘 end***************************************// | 402 | * |
415 | 403 | * @param token | |
416 | 404 | */ | |
417 | } | 405 | private void hideSoftInput(IBinder token) { |
418 | 406 | LogUtil.i(TAG, "隐藏键盘"); |
libs/common/src/main/java/com/prws/common/config/SettingConfig.java
1 | package com.prws.common.config; | 1 | package com.prws.common.config; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.content.SharedPreferences; | 4 | import android.content.SharedPreferences; |
5 | 5 | ||
6 | import com.google.gson.Gson; | 6 | import com.google.gson.Gson; |
7 | import com.prws.common.CommonApplication; | ||
8 | 7 | import com.prws.common.CommonApplication; | |
9 | 8 | ||
10 | public class SettingConfig { | 9 | |
11 | private Boolean showDefaultImage = false; | 10 | public class SettingConfig { |
12 | private Boolean showLogo = false; | 11 | private Boolean showDefaultImage = false; |
13 | 12 | private Boolean showLogo = false; | |
14 | private Boolean loadDisinfectModel = false; // 是否启用消杀 | 13 | |
15 | private Boolean loadCleanModel = true; // 是否启用 | 14 | private Boolean loadDisinfectModel = false; // 是否启用消杀 |
16 | private Boolean loadSidePushModel = false;//是否启用边推 | 15 | private Boolean loadCleanModel = true; // 是否启用 |
17 | 16 | private Boolean loadSidePushModel = false;//是否启用边推 | |
18 | private Integer cleanModelPressureLevel = 2; // 清洁模块的压力等级 | 17 | |
19 | 18 | private Integer cleanModelPressureLevel = 2; // 清洁模块的压力等级 | |
20 | private static volatile SettingConfig mInstance; | 19 | |
21 | 20 | private static volatile SettingConfig mInstance; | |
22 | public static SettingConfig getInstance() { | 21 | |
23 | if (mInstance == null) { | 22 | public static SettingConfig getInstance() { |
24 | synchronized (SettingConfig.class) { | 23 | if (mInstance == null) { |
25 | if (mInstance == null) { | 24 | synchronized (SettingConfig.class) { |
26 | String json = getSharedPreferences().getString("SettingConfig",""); | 25 | if (mInstance == null) { |
27 | if (json == null || json.length() == 0) { | 26 | String json = getSharedPreferences().getString("SettingConfig",""); |
28 | mInstance = new SettingConfig(); | 27 | if (json == null || json.length() == 0) { |
29 | } else { | 28 | mInstance = new SettingConfig(); |
30 | mInstance = new Gson().fromJson(json, SettingConfig.class); | 29 | } else { |
31 | } | 30 | mInstance = new Gson().fromJson(json, SettingConfig.class); |
32 | } | 31 | } |
33 | } | 32 | } |
34 | } | 33 | } |
35 | return mInstance; | 34 | } |
36 | } | 35 | return mInstance; |
37 | 36 | } | |
38 | 37 | ||
39 | public static void cacheToDisk() { | 38 | |
40 | SharedPreferences sp = getSharedPreferences(); | 39 | public static void cacheToDisk() { |
41 | SharedPreferences.Editor editor = sp.edit(); | 40 | SharedPreferences sp = getSharedPreferences(); |
42 | editor.putString("SettingConfig", new Gson().toJson(getInstance())); | 41 | SharedPreferences.Editor editor = sp.edit(); |
43 | editor.commit(); | 42 | editor.putString("SettingConfig", new Gson().toJson(getInstance())); |
44 | } | 43 | editor.commit(); |
45 | public static SharedPreferences getSharedPreferences(){ | 44 | } |
46 | return CommonApplication.getAppContext().getSharedPreferences("Delivery", Context.MODE_PRIVATE); | 45 | public static SharedPreferences getSharedPreferences(){ |
47 | } | 46 | return CommonApplication.getAppContext().getSharedPreferences("Delivery", Context.MODE_PRIVATE); |
48 | 47 | } | |
49 | public Boolean getShowDefaultImage() { | 48 | |
50 | return showDefaultImage; | 49 | public Boolean getShowDefaultImage() { |
51 | } | 50 | return showDefaultImage; |
52 | 51 | } | |
53 | public void setShowDefaultImage(Boolean showDefaultImage) { | 52 | |
54 | this.showDefaultImage = showDefaultImage; | 53 | public void setShowDefaultImage(Boolean showDefaultImage) { |
55 | } | 54 | this.showDefaultImage = showDefaultImage; |
56 | 55 | } | |
57 | public Boolean getShowLogo() { | 56 | |
58 | return showLogo; | 57 | public Boolean getShowLogo() { |
59 | } | 58 | return showLogo; |
60 | 59 | } | |
61 | public void setShowLogo(Boolean showLogo) { | 60 | |
62 | this.showLogo = showLogo; | 61 | public void setShowLogo(Boolean showLogo) { |
63 | } | 62 | this.showLogo = showLogo; |
64 | 63 | } | |
65 | public Boolean getLoadDisinfectModel() { | 64 | |
66 | return loadDisinfectModel; | 65 | public Boolean getLoadDisinfectModel() { |
67 | } | 66 | return loadDisinfectModel; |
68 | 67 | } | |
69 | public void setLoadDisinfectModel(Boolean loadDisinfectModel) { | 68 | |
70 | this.loadDisinfectModel = loadDisinfectModel; | 69 | public void setLoadDisinfectModel(Boolean loadDisinfectModel) { |
71 | } | 70 | this.loadDisinfectModel = loadDisinfectModel; |
72 | 71 | } | |
73 | public Boolean getLoadSidePushModel() { | 72 | |
74 | return loadSidePushModel; | 73 | public Boolean getLoadSidePushModel() { |
75 | } | 74 | return loadSidePushModel; |
76 | 75 | } | |
77 | public void setLoadSidePushModel(Boolean loadSidePushModel) { | 76 | |
78 | this.loadSidePushModel = loadSidePushModel; | 77 | public void setLoadSidePushModel(Boolean loadSidePushModel) { |
79 | } | 78 | this.loadSidePushModel = loadSidePushModel; |
80 | 79 | } | |
81 | public Boolean getLoadCleanModel() { | 80 | |
82 | return loadCleanModel; | 81 | public Boolean getLoadCleanModel() { |
83 | } | 82 | return loadCleanModel; |
84 | 83 | } | |
85 | public void setLoadCleanModel(Boolean loadCleanModel) { | 84 | |
86 | this.loadCleanModel = loadCleanModel; | 85 | public void setLoadCleanModel(Boolean loadCleanModel) { |
87 | } | 86 | this.loadCleanModel = loadCleanModel; |
88 | 87 | } | |
89 | public Integer getCleanModelPressureLevel() { | 88 | |
90 | return cleanModelPressureLevel; | 89 | public Integer getCleanModelPressureLevel() { |
91 | } | 90 | return cleanModelPressureLevel; |
92 | 91 | } | |
93 | public void setCleanModelPressureLevel(Integer cleanModelPressureLevel) { | 92 | |
94 | this.cleanModelPressureLevel = cleanModelPressureLevel; | 93 | public void setCleanModelPressureLevel(Integer cleanModelPressureLevel) { |
95 | } | 94 | this.cleanModelPressureLevel = cleanModelPressureLevel; |
96 | } | 95 | } |
97 | 96 | } |
libs/common/src/main/java/com/prws/common/net/DownloadResponseBody.java
1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
2 | 2 | ||
3 | import android.os.Handler; | 3 | import android.os.Handler; |
4 | import android.os.Looper; | 4 | import android.os.Looper; |
5 | |||
6 | import okhttp3.MediaType; | 5 | |
7 | import okhttp3.ResponseBody; | 6 | import okhttp3.MediaType; |
8 | import okio.Buffer; | 7 | import okhttp3.ResponseBody; |
9 | import okio.BufferedSource; | 8 | import okio.Buffer; |
10 | import okio.ForwardingSource; | 9 | import okio.BufferedSource; |
11 | import okio.Okio; | 10 | import okio.ForwardingSource; |
12 | import okio.Source; | 11 | import okio.Okio; |
13 | 12 | import okio.Source; | |
14 | /** | 13 | |
15 | * @author | 14 | /** |
16 | * | 15 | * @author |
17 | * 描述:DownloadResponseBody | 16 | * |
18 | */ | 17 | * 描述:DownloadResponseBody |
19 | public class DownloadResponseBody extends ResponseBody { | 18 | */ |
20 | private ResponseBody responseBody; | 19 | public class DownloadResponseBody extends ResponseBody { |
21 | // BufferedSource 是okio库中的输入流,这里就当作inputStream来使用。 | 20 | private ResponseBody responseBody; |
22 | private BufferedSource bufferedSource; | 21 | // BufferedSource 是okio库中的输入流,这里就当作inputStream来使用。 |
23 | private DownloadListener mDownloadListener; | 22 | private BufferedSource bufferedSource; |
24 | public DownloadResponseBody(ResponseBody responseBody, DownloadListener downloadListener) { | 23 | private DownloadListener mDownloadListener; |
25 | this.responseBody = responseBody; | 24 | public DownloadResponseBody(ResponseBody responseBody, DownloadListener downloadListener) { |
26 | this.mDownloadListener = downloadListener; | 25 | this.responseBody = responseBody; |
27 | downloadListener.onStartDownload(responseBody.contentLength()); | 26 | this.mDownloadListener = downloadListener; |
28 | } | 27 | downloadListener.onStartDownload(responseBody.contentLength()); |
29 | @Override | 28 | } |
30 | public MediaType contentType() { | 29 | @Override |
31 | return responseBody.contentType(); | 30 | public MediaType contentType() { |
32 | } | 31 | return responseBody.contentType(); |
33 | @Override | 32 | } |
34 | public long contentLength() { | 33 | @Override |
35 | return responseBody.contentLength(); | 34 | public long contentLength() { |
36 | } | 35 | return responseBody.contentLength(); |
37 | @Override | 36 | } |
38 | public BufferedSource source() { | 37 | @Override |
39 | if (bufferedSource == null) { | 38 | public BufferedSource source() { |
40 | bufferedSource = Okio.buffer(source(responseBody.source())); | 39 | if (bufferedSource == null) { |
41 | } | 40 | bufferedSource = Okio.buffer(source(responseBody.source())); |
42 | return bufferedSource; | 41 | } |
43 | } | 42 | return bufferedSource; |
44 | private Source source(Source source) { | 43 | } |
45 | return new ForwardingSource(source) { | 44 | private Source source(Source source) { |
46 | long totalBytesRead = 0L; | 45 | return new ForwardingSource(source) { |
47 | @Override | 46 | long totalBytesRead = 0L; |
48 | public long read(Buffer sink, long byteCount) { | 47 | @Override |
49 | long bytesRead = 0; | 48 | public long read(Buffer sink, long byteCount) { |
50 | try { | 49 | long bytesRead = 0; |
51 | bytesRead = super.read(sink, byteCount); | 50 | try { |
52 | }catch (final Exception e){ | 51 | bytesRead = super.read(sink, byteCount); |
53 | e.printStackTrace(); | 52 | }catch (final Exception e){ |
54 | if (null != mDownloadListener) { | 53 | e.printStackTrace(); |
55 | new Handler(Looper.getMainLooper()).post(new Runnable() { | 54 | if (null != mDownloadListener) { |
56 | @Override | 55 | new Handler(Looper.getMainLooper()).post(new Runnable() { |
57 | public void run() { | 56 | @Override |
58 | mDownloadListener.onError(e); | 57 | public void run() { |
59 | } | 58 | mDownloadListener.onError(e); |
60 | }); | 59 | } |
61 | 60 | }); | |
62 | } | 61 | |
63 | } | 62 | } |
64 | totalBytesRead += bytesRead != -1 ? bytesRead : 0; | 63 | } |
65 | // LogUtil.e("download", "read: "+ (int) (totalBytesRead * 100 / responseBody.contentLength())); | 64 | totalBytesRead += bytesRead != -1 ? bytesRead : 0; |
66 | if (null != mDownloadListener) { | 65 | // LogUtil.e("download", "read: "+ (int) (totalBytesRead * 100 / responseBody.contentLength())); |
67 | if (bytesRead != -1) { | 66 | if (null != mDownloadListener) { |
68 | mDownloadListener.onProgress((int) (totalBytesRead * 100 / responseBody.contentLength())); | 67 | if (bytesRead != -1) { |
69 | }else{ | 68 | mDownloadListener.onProgress((int) (totalBytesRead * 100 / responseBody.contentLength())); |
70 | mDownloadListener.onDownloadComplete(); | 69 | }else{ |
71 | } | 70 | mDownloadListener.onDownloadComplete(); |
72 | } | 71 | } |
73 | return bytesRead; | 72 | } |
74 | } | 73 | return bytesRead; |
75 | }; | 74 | } |
76 | } | 75 | }; |
77 | 76 | } | |
78 | 77 | ||
79 | /** | 78 | |
80 | * length 文件总大小 | 79 | /** |
81 | * | 80 | * length 文件总大小 |
82 | * progress 已下载进度 | 81 | * |
83 | */ | 82 | * progress 已下载进度 |
84 | public interface DownloadListener { | 83 | */ |
85 | void onStartDownload(long length); | 84 | public interface DownloadListener { |
86 | void onProgress(int progress); | 85 | void onStartDownload(long length); |
87 | void onDownloadComplete(); | 86 | void onProgress(int progress); |
88 | void onError(Exception e); | 87 | void onDownloadComplete(); |
89 | } | 88 | void onError(Exception e); |
90 | } | 89 | } |
91 | 90 | } |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
2 | 2 | ||
3 | 3 | ||
4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
7 | import com.prws.common.bean.CutPicBean; | 7 | import com.prws.common.bean.CutPicBean; |
8 | import com.prws.common.bean.GradeAndSubject; | 8 | import com.prws.common.bean.GradeAndSubject; |
9 | import com.prws.common.bean.PageInfo; | 9 | import com.prws.common.bean.PageInfo; |
10 | import com.prws.common.bean.ResponseResult; | 10 | import com.prws.common.bean.ResponseResult; |
11 | import com.prws.common.bean.ScheduleBean; | 11 | import com.prws.common.bean.ScheduleBean; |
12 | import com.prws.common.bean.Student; | 12 | import com.prws.common.bean.Student; |
13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
15 | import com.prws.common.bean.UpdateBean; | 15 | import com.prws.common.bean.UpdateBean; |
16 | import com.prws.common.bean.baidu.BaiduInput; | 16 | import com.prws.common.bean.baidu.BaiduInput; |
17 | import com.prws.common.bean.homework.HomeWork; | 17 | import com.prws.common.bean.homework.HomeWork; |
18 | import com.prws.common.bean.homework.HomeworkDetail; | 18 | import com.prws.common.bean.homework.HomeworkDetail; |
19 | import com.prws.common.bean.homework.HomeworkList; | 19 | import com.prws.common.bean.homework.HomeworkList; |
20 | import com.prws.common.bean.homework.StDetail; | 20 | import com.prws.common.bean.homework.StDetail; |
21 | import com.prws.common.utils.BitmapUtils; | 21 | import com.prws.common.utils.BitmapUtils; |
22 | import com.prws.common.utils.SharedPreferencesUtil; | 22 | import com.prws.common.utils.SharedPreferencesUtil; |
23 | 23 | ||
24 | import java.io.File; | 24 | import java.io.File; |
25 | import java.util.HashMap; | 25 | import java.util.HashMap; |
26 | import java.util.List; | 26 | import java.util.List; |
27 | import java.util.Map; | 27 | import java.util.Map; |
28 | 28 | ||
29 | import io.reactivex.Observable; | 29 | import io.reactivex.Observable; |
30 | import io.reactivex.Observer; | 30 | import io.reactivex.Observer; |
31 | import io.reactivex.Single; | 31 | import io.reactivex.Single; |
32 | import io.reactivex.android.schedulers.AndroidSchedulers; | 32 | import io.reactivex.android.schedulers.AndroidSchedulers; |
33 | import io.reactivex.schedulers.Schedulers; | 33 | import io.reactivex.schedulers.Schedulers; |
34 | import okhttp3.MediaType; | 34 | import okhttp3.MediaType; |
35 | import okhttp3.MultipartBody; | 35 | import okhttp3.MultipartBody; |
36 | import okhttp3.RequestBody; | 36 | import okhttp3.RequestBody; |
37 | import okhttp3.ResponseBody; | 37 | import okhttp3.ResponseBody; |
38 | import retrofit2.Call; | 38 | import retrofit2.Call; |
39 | import retrofit2.Callback; | 39 | import retrofit2.Callback; |
40 | import retrofit2.http.Body; | 40 | import retrofit2.http.Body; |
41 | import retrofit2.http.GET; | 41 | import retrofit2.http.GET; |
42 | import retrofit2.http.Header; | 42 | import retrofit2.http.Header; |
43 | import retrofit2.http.Headers; | 43 | import retrofit2.http.Headers; |
44 | import retrofit2.http.Multipart; | 44 | import retrofit2.http.Multipart; |
45 | import retrofit2.http.POST; | 45 | import retrofit2.http.POST; |
46 | import retrofit2.http.PUT; | 46 | import retrofit2.http.PUT; |
47 | import retrofit2.http.Part; | 47 | import retrofit2.http.Part; |
48 | import retrofit2.http.PartMap; | 48 | import retrofit2.http.PartMap; |
49 | import retrofit2.http.Query; | 49 | import retrofit2.http.Query; |
50 | import retrofit2.http.Url; | 50 | import retrofit2.http.Url; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * 类名称:NetWorks | 53 | * 类名称:NetWorks |
54 | * 创建人: | 54 | * 创建人: |
55 | * <p> | 55 | * <p> |
56 | * 类描述:网络请求的操作类 | 56 | * 类描述:网络请求的操作类 |
57 | */ | 57 | */ |
58 | public class NetWorks extends RetrofitUtils { | 58 | public class NetWorks extends RetrofitUtils { |
59 | //服务器路径 | 59 | //服务器路径 |
60 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 60 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); |
61 | 61 | ||
62 | //设缓存有效期为1天 | 62 | //设缓存有效期为1天 |
63 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 63 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
64 | //查询缓存的Cache-Control设置,使用缓存 | 64 | //查询缓存的Cache-Control设置,使用缓存 |
65 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 65 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
66 | //查询网络的Cache-Control设置。不使用缓存 | 66 | //查询网络的Cache-Control设置。不使用缓存 |
67 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 67 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
68 | 68 | ||
69 | 69 | ||
70 | public interface NetService { | 70 | public interface NetService { |
71 | 71 | ||
72 | 72 | ||
73 | @GET("/api/v1/user/logout") | 73 | @GET("/api/v1/user/logout") |
74 | Observable<ResponseBody> logout(); | 74 | Observable<ResponseBody> logout(); |
75 | 75 | ||
76 | @Multipart | 76 | @Multipart |
77 | @POST("/api/v1/user/upLoadAvatar") | 77 | @POST("/api/v1/user/upLoadAvatar") |
78 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 78 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
79 | 79 | ||
80 | 80 | ||
81 | @Headers("Content-Type: application/json") | 81 | @Headers("Content-Type: application/json") |
82 | @POST("/api/v1/user/editUser") | 82 | @POST("/api/v1/user/editUser") |
83 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 83 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
84 | 84 | ||
85 | @Headers("Content-Type: application/json") | 85 | @Headers("Content-Type: application/json") |
86 | @POST("/api/v1/user/changePassword") | 86 | @POST("/api/v1/user/changePassword") |
87 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 87 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
88 | 88 | ||
89 | 89 | ||
90 | @GET("/api/v1/user/searchById") | 90 | @GET("/api/v1/user/searchById") |
91 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 91 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
92 | 92 | ||
93 | 93 | ||
94 | @Headers("Content-Type: application/json") | 94 | @Headers("Content-Type: application/json") |
95 | @POST("/api/v1/login/userLogin") | 95 | @POST("/api/v1/login/userLogin") |
96 | Observable<ResponseBody> login(@Body RequestBody body); | 96 | Observable<ResponseBody> login(@Body RequestBody body); |
97 | 97 | ||
98 | @GET("/api/v1/resource/listGradeAndSubject") | 98 | @GET("/api/v1/resource/listGradeAndSubject") |
99 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 99 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
100 | 100 | ||
101 | 101 | ||
102 | @GET("/api/v1/manager/generalQrCode") | 102 | @GET("/api/v1/manager/generalQrCode") |
103 | Observable<ResponseBody> generalQrCode(); | 103 | Observable<ResponseBody> generalQrCode(); |
104 | 104 | ||
105 | @GET("/api/v1/parent/scanAndLogin?") | 105 | @GET("/api/v1/parent/scanAndLogin?") |
106 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); | 106 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
107 | 107 | ||
108 | @GET("/api/v1/parent/getChildrenList") | 108 | @GET("/api/v1/parent/getChildrenList") |
109 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 109 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
110 | 110 | ||
111 | 111 | ||
112 | @Headers("Content-Type: application/json") | 112 | @Headers("Content-Type: application/json") |
113 | @POST("/api/v1/parent/registerParent") | 113 | @POST("/api/v1/parent/registerParent") |
114 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 114 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
115 | 115 | ||
116 | 116 | ||
117 | @GET("/api/v1/parent/listChildren") | 117 | @GET("/api/v1/parent/listChildren") |
118 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 118 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
119 | 119 | ||
120 | 120 | ||
121 | @Headers("Content-Type: application/json") | 121 | @Headers("Content-Type: application/json") |
122 | @POST("/api/v1/parent/registerStudent") | 122 | @POST("/api/v1/parent/registerStudent") |
123 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 123 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
124 | 124 | ||
125 | @Headers("Content-Type: application/json") | 125 | @Headers("Content-Type: application/json") |
126 | @POST("/api/v1/parent/bindTeacher") | 126 | @POST("/api/v1/parent/bindTeacher") |
127 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 127 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
128 | 128 | ||
129 | @Multipart | 129 | @Multipart |
130 | @POST("/api/v1/user/upLoadAvatar") | 130 | @POST("/api/v1/user/upLoadAvatar") |
131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
132 | 132 | ||
133 | 133 | ||
134 | @Multipart | 134 | @Multipart |
135 | @POST("/api/v1/student/editStudentAvatar") | 135 | @POST("/api/v1/student/editStudentAvatar") |
136 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 136 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
137 | 137 | ||
138 | @Headers("Content-Type: application/json") | 138 | @Headers("Content-Type: application/json") |
139 | @POST("/api/v1/parent/editChild") | 139 | @POST("/api/v1/parent/editChild") |
140 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 140 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
141 | 141 | ||
142 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 142 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
143 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 143 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
144 | 144 | ||
145 | @GET("api/v1/parent/searchTeacher") | 145 | @GET("api/v1/parent/searchTeacher") |
146 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 146 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
147 | 147 | ||
148 | @POST("api/v1/question/listErrorBook") | 148 | @POST("api/v1/question/listErrorBook") |
149 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 149 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
150 | 150 | ||
151 | @POST | 151 | @POST |
152 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 152 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
153 | 153 | ||
154 | @POST | 154 | @POST |
155 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 155 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
156 | 156 | ||
157 | @POST | 157 | @POST |
158 | Observable<JsonObject> getBaiduToken(@Url String url); | 158 | Observable<JsonObject> getBaiduToken(@Url String url); |
159 | 159 | ||
160 | @Multipart | 160 | @Multipart |
161 | @POST("api/v1/pad/addErrorBook") | 161 | @POST("api/v1/pad/addErrorBook") |
162 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 162 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
163 | 163 | ||
164 | @POST("api/v1/pad/deleteStuErrorBook") | 164 | @POST("api/v1/pad/deleteStuErrorBook") |
165 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 165 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
166 | 166 | ||
167 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 167 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
168 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 168 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
169 | 169 | ||
170 | @POST("api/v1/question/editErrorBook") | 170 | @POST("api/v1/question/editErrorBook") |
171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
172 | 172 | ||
173 | @GET("api/v1/resource/checkUpdate") | 173 | @GET("api/v1/resource/checkUpdate") |
174 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 174 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
175 | 175 | ||
176 | @GET("api/v1/teacher/getStudentList") | 176 | @GET("api/v1/teacher/getStudentList") |
177 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 177 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
178 | 178 | ||
179 | @GET("api/v1/teacher/getStudentList") | 179 | @GET("api/v1/teacher/getStudentList") |
180 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | 180 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); |
181 | 181 | ||
182 | @GET("api/v1/answer/listRecordForTeacher") | 182 | @GET("api/v1/answer/listRecordForTeacher") |
183 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 183 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
184 | 184 | ||
185 | @GET("api/v1/homework/listHomeworkByStuId") | 185 | @GET("api/v1/homework/listHomeworkByStuId") |
186 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); | 186 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); |
187 | 187 | ||
188 | @POST | 188 | @POST |
189 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); | 189 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); |
190 | 190 | ||
191 | @Multipart | 191 | @Multipart |
192 | @POST("api/v1/homework/uploadHomework") | 192 | @POST("api/v1/homework/uploadHomework") |
193 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); | 193 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); |
194 | 194 | ||
195 | @POST("api/v1/homework/uploadHomeworkAction") | 195 | @POST("api/v1/homework/uploadHomeworkAction") |
196 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); | 196 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); |
197 | 197 | ||
198 | @GET("api/v1/homework/removeHomework") | 198 | @GET("api/v1/homework/removeHomework") |
199 | Single<ResponseResult<Boolean>> deleteHomework( | 199 | Single<ResponseResult<Boolean>> deleteHomework( |
200 | @Header("Authorization") String token, | 200 | @Header("Authorization") String token, |
201 | @Query("homeworkId") String homeworkId | 201 | @Query("homeworkId") String homeworkId |
202 | ); | 202 | ); |
203 | 203 | ||
204 | @GET("api/v1/homework/listHomeworkById") | 204 | @GET("api/v1/homework/listHomeworkById") |
205 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); | 205 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); |
206 | 206 | ||
207 | @POST("api/v1/homework/uploadHomeworkFeedback") | 207 | @POST("api/v1/homework/uploadHomeworkFeedback") |
208 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); | 208 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); |
209 | 209 | ||
210 | @POST("api/v1/homework/editHomeworkInfo") | 210 | @POST("api/v1/homework/editHomeworkInfo") |
211 | Single<ResponseResult<Boolean>> editHomework( | 211 | Single<ResponseResult<Boolean>> editHomework( |
212 | @Header("Authorization") String token, | 212 | @Header("Authorization") String token, |
213 | @Body Object body | 213 | @Body Object body |
214 | ); | 214 | ); |
215 | 215 | ||
216 | @GET("api/v1/homework/listHomeworkDetailByStuId") | 216 | @GET("api/v1/homework/listHomeworkDetailByStuId") |
217 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( | 217 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( |
218 | @Header("Authorization") String token, | 218 | @Header("Authorization") String token, |
219 | @Query("stuId") String stuId, | 219 | @Query("stuId") String stuId, |
220 | @Query("homeworkId") String homeworkId, | 220 | @Query("homeworkId") String homeworkId, |
221 | // type 固定传true | 221 | // type 固定传true |
222 | @Query("type") boolean type | 222 | @Query("type") boolean type |
223 | ); | 223 | ); |
224 | 224 | ||
225 | @GET("api/v1/homework/listHomeworkStatistics") | 225 | @GET("api/v1/homework/listHomeworkStatistics") |
226 | Single<ResponseResult<List<StDetail>>> getHuyouList( | 226 | Single<ResponseResult<List<StDetail>>> getHuyouList( |
227 | @Header("Authorization") String token, | 227 | @Header("Authorization") String token, |
228 | @Query("stuId") String stuId, | 228 | @Query("stuId") String stuId, |
229 | @Query("type") int type //0: 周报, 1:阶段总结 | 229 | @Query("type") int type //0: 周报, 1:阶段总结 |
230 | ); | 230 | ); |
231 | 231 | ||
232 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") | 232 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") |
233 | Single<ResponseResult<StDetail>> getHuyouDetail( | 233 | Single<ResponseResult<StDetail>> getHuyouDetail( |
234 | @Header("Authorization") String token, | 234 | @Header("Authorization") String token, |
235 | @Query("homeworkStatisticsId") String homeworkId | 235 | @Query("homeworkStatisticsId") String homeworkId |
236 | ); | 236 | ); |
237 | 237 | ||
238 | @GET("api/v1/demo/generalStatisticsHomework") | 238 | @GET("api/v1/demo/generalStatisticsHomework") |
239 | Single<ResponseResult<Object>> generalHuyou(); | 239 | Single<ResponseResult<Object>> generalHuyou(); |
240 | 240 | ||
241 | @POST("api/v1/homework/generalHomeworkStageStatistics") | 241 | @POST("api/v1/homework/generalHomeworkStageStatistics") |
242 | Single<ResponseResult<Boolean>> generalStageHuyou( | 242 | Single<ResponseResult<Boolean>> generalStageHuyou( |
243 | @Header("Authorization") String token, | 243 | @Header("Authorization") String token, |
244 | @Body Object body | 244 | @Body Object body |
245 | ); | 245 | ); |
246 | 246 | ||
247 | @GET("api/v1/homework/removeHomeworkStatistics") | 247 | @GET("api/v1/homework/removeHomeworkStatistics") |
248 | Single<ResponseResult<Boolean>> deleteHuyou( | 248 | Single<ResponseResult<Boolean>> deleteHuyou( |
249 | @Header("Authorization") String token, | 249 | @Header("Authorization") String token, |
250 | @Query("homeworkStatisticsId") String homeworkId | 250 | @Query("homeworkStatisticsId") String homeworkId |
251 | ); | 251 | ); |
252 | 252 | ||
253 | } | 253 | } |
254 | 254 | ||
255 | public static String getUserId() { | 255 | public static String getUserId() { |
256 | return (String) SharedPreferencesUtil.getData("userId", ""); | 256 | return (String) SharedPreferencesUtil.getData("userId", ""); |
257 | } | 257 | } |
258 | 258 | ||
259 | public static String getHeader() { | 259 | public static String getHeader() { |
260 | return (String) SharedPreferencesUtil.getData("token", ""); | 260 | return (String) SharedPreferencesUtil.getData("token", ""); |
261 | } | 261 | } |
262 | 262 | ||
263 | public static String getBaiduToken() { | 263 | public static String getBaiduToken() { |
264 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 264 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
265 | } | 265 | } |
266 | 266 | ||
267 | public static Single<BaiduInput> inputImage(String filePath, String id) { | 267 | public static Single<BaiduInput> inputImage(String filePath, String id) { |
268 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 268 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
269 | String base64 = BitmapUtils.fileToBase64(filePath); | 269 | String base64 = BitmapUtils.fileToBase64(filePath); |
270 | File file = new File(filePath); | 270 | File file = new File(filePath); |
271 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | 271 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); |
272 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | 272 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) |
273 | .flatMap(token -> { | 273 | .flatMap(token -> { |
274 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | 274 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); |
275 | }); | 275 | }); |
276 | } | 276 | } |
277 | 277 | ||
278 | public static Single<ResponseResult> uploadImage(String path, String id) { | 278 | public static Single<ResponseResult> uploadImage(String path, String id) { |
279 | File file = new File(path); | 279 | File file = new File(path); |
280 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 280 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
281 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 281 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
282 | return service_url.uploadImage(getHeader(), part, id); | 282 | return service_url.uploadImage(getHeader(), part, id); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 286 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
287 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 287 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
288 | } | 288 | } |
289 | 289 | ||
290 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 290 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
291 | File file = new File(path); | 291 | File file = new File(path); |
292 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 292 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
293 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 293 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
294 | Map<String, Object> map = new HashMap<>(); | 294 | Map<String, Object> map = new HashMap<>(); |
295 | map.put("condition", param); | 295 | map.put("condition", param); |
296 | setSubscribe(service_url.addError(part, map), observer); | 296 | setSubscribe(service_url.addError(part, map), observer); |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | public static void cut(String base64, Observer<CutPicBean> observer) { | 300 | public static void cut(String base64, Observer<CutPicBean> observer) { |
301 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 301 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
302 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 302 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
303 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 303 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
304 | } | 304 | } |
305 | 305 | ||
306 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 306 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
307 | setSubscribe(service_url.editError(getHeader(), map), observer); | 307 | setSubscribe(service_url.editError(getHeader(), map), observer); |
308 | } | 308 | } |
309 | 309 | ||
310 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 310 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
311 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 311 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
312 | } | 312 | } |
313 | 313 | ||
314 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 314 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
315 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 315 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
316 | } | 316 | } |
317 | 317 | ||
318 | public static void getBaiduToken(Observer<JsonObject> observer) { | 318 | public static void getBaiduToken(Observer<JsonObject> observer) { |
319 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); | 319 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); |
320 | } | 320 | } |
321 | 321 | ||
322 | public static Single<JsonObject> getBaiduTokenOcr() { | 322 | public static Single<JsonObject> getBaiduTokenOcr() { |
323 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); | 323 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); |
324 | } | 324 | } |
325 | 325 | ||
326 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 326 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
327 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 327 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
328 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 328 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
329 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 329 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
330 | } | 330 | } |
331 | 331 | ||
332 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 332 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
333 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 333 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
334 | } | 334 | } |
335 | 335 | ||
336 | public static void logout(Observer<ResponseBody> observer) { | 336 | public static void logout(Observer<ResponseBody> observer) { |
337 | setSubscribe(service_url.logout(), observer); | 337 | setSubscribe(service_url.logout(), observer); |
338 | } | 338 | } |
339 | 339 | ||
340 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 340 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
341 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 341 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
342 | } | 342 | } |
343 | 343 | ||
344 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 344 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
345 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 345 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
346 | } | 346 | } |
347 | 347 | ||
348 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 348 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
349 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 349 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
350 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 350 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
351 | Map<String, Object> map = new HashMap<>(); | 351 | Map<String, Object> map = new HashMap<>(); |
352 | map.put("stuId", stuId); | 352 | map.put("stuId", stuId); |
353 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 353 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
354 | } | 354 | } |
355 | 355 | ||
356 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 356 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
357 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 357 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
358 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 358 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
359 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 359 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
360 | } | 360 | } |
361 | 361 | ||
362 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 362 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
363 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 363 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
364 | } | 364 | } |
365 | 365 | ||
366 | 366 | ||
367 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 367 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
368 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 368 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
369 | } | 369 | } |
370 | 370 | ||
371 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 371 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
372 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 372 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
373 | } | 373 | } |
374 | 374 | ||
375 | 375 | ||
376 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 376 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
377 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 377 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 381 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
382 | setSubscribe(service_url.login(body), observer); | 382 | setSubscribe(service_url.login(body), observer); |
383 | } | 383 | } |
384 | 384 | ||
385 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 385 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
386 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 386 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
387 | } | 387 | } |
388 | 388 | ||
389 | 389 | ||
390 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 390 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
391 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 391 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
392 | } | 392 | } |
393 | 393 | ||
394 | public static void getChildrenList(Observer<ResponseBody> observer) { | 394 | public static void getChildrenList(Observer<ResponseBody> observer) { |
395 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 395 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 399 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
400 | setSubscribe(service_url.registerParent(body), observer); | 400 | setSubscribe(service_url.registerParent(body), observer); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | public static void listChildren(Observer<ResponseBody> observer) { | 404 | public static void listChildren(Observer<ResponseBody> observer) { |
405 | setSubscribe(service_url.listChildren(getHeader()), observer); | 405 | setSubscribe(service_url.listChildren(getHeader()), observer); |
406 | } | 406 | } |
407 | 407 | ||
408 | public static void listStudent(Observer<ResponseBody> observer) { | 408 | public static void listStudent(Observer<ResponseBody> observer) { |
409 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 409 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
410 | } | 410 | } |
411 | 411 | ||
412 | public static Single<ResponseResult<List<Student>>> listStudent() { | 412 | public static Single<ResponseResult<List<Student>>> listStudent() { |
413 | return service_url.getStudentList2(getHeader(), getUserId()); | 413 | return service_url.getStudentList2(getHeader(), getUserId()); |
414 | } | 414 | } |
415 | 415 | ||
416 | public static void listRecord(Observer<ResponseBody> observer) { | 416 | public static void listRecord(Observer<ResponseBody> observer) { |
417 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 417 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 421 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
422 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 422 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
423 | } | 423 | } |
424 | 424 | ||
425 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 425 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
426 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 426 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
427 | } | 427 | } |
428 | 428 | ||
429 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 429 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
430 | setSubscribe(service_url.getError(getHeader(), map), observer); | 430 | setSubscribe(service_url.getError(getHeader(), map), observer); |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | public static RequestBody getMapRequestBody(Map map) { | 434 | public static RequestBody getMapRequestBody(Map map) { |
435 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 435 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | public static RequestBody getArrayRequestBody(List list) { | 439 | public static RequestBody getArrayRequestBody(List list) { |
440 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 440 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
441 | } | 441 | } |
442 | 442 | ||
443 | public static RequestBody getFileRequestBody(File file) { | 443 | public static RequestBody getFileRequestBody(File file) { |
444 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 444 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
445 | } | 445 | } |
446 | 446 | ||
447 | public static RequestBody getFileRequestBody(byte[] bytes) { | 447 | public static RequestBody getFileRequestBody(byte[] bytes) { |
448 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 448 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
449 | } | 449 | } |
450 | 450 | ||
451 | public static RequestBody getObjectRequestBody(Object obj) { | 451 | public static RequestBody getObjectRequestBody(Object obj) { |
452 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 452 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
453 | } | 453 | } |
454 | 454 | ||
455 | public static RequestBody getStringRequestBody(String str) { | 455 | public static RequestBody getStringRequestBody(String str) { |
456 | return RequestBody.create(MediaType.parse("text/plain"), str); | 456 | return RequestBody.create(MediaType.parse("text/plain"), str); |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||
460 | /** | 460 | /** |
461 | * 插入观察者 | 461 | * 插入观察者 |
462 | * | 462 | * |
463 | * @param observable | 463 | * @param observable |
464 | * @param observer | 464 | * @param observer |
465 | * @param <T> | 465 | * @param <T> |
466 | */ | 466 | */ |
467 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 467 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
468 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 468 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
469 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 469 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
470 | .subscribe(observer); | 470 | .subscribe(observer); |
471 | } | 471 | } |
472 | 472 | ||
473 | } | 473 | } |
474 | 474 |
libs/common/src/main/java/com/prws/common/utils/LogcatHelper.java
1 | package com.prws.common.utils; | 1 | package com.prws.common.utils; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.os.Environment; | 4 | import android.os.Environment; |
5 | |||
6 | import java.io.BufferedReader; | ||
7 | import java.io.File; | ||
8 | import java.io.FileNotFoundException; | 5 | |
9 | import java.io.FileOutputStream; | 6 | import java.io.BufferedReader; |
10 | import java.io.IOException; | 7 | import java.io.File; |
11 | import java.io.InputStreamReader; | 8 | import java.io.FileNotFoundException; |
12 | import java.text.ParseException; | 9 | import java.io.FileOutputStream; |
13 | import java.text.SimpleDateFormat; | 10 | import java.io.IOException; |
14 | import java.util.Date; | 11 | import java.io.InputStreamReader; |
15 | |||
16 | public class LogcatHelper { | ||
17 | |||
18 | private static LogcatHelper INSTANCE = null; | 12 | import java.text.ParseException; |
19 | private static String PATH_LOGCAT; | 13 | import java.text.SimpleDateFormat; |
20 | private LogDumper mLogDumper = null; | ||
21 | private int mPId; | 14 | import java.util.Date; |
22 | 15 | ||
23 | /** | 16 | public class LogcatHelper { |
24 | * 初始化目录 | 17 | |
25 | */ | 18 | private static LogcatHelper INSTANCE = null; |
26 | public void init(Context context) { | 19 | private static String PATH_LOGCAT; |
27 | if (Environment.getExternalStorageState().equals( | 20 | private LogDumper mLogDumper = null; |
28 | Environment.MEDIA_MOUNTED)) {// 优先保存到SD卡中 | 21 | private int mPId; |
29 | PATH_LOGCAT = Environment.getExternalStorageDirectory() | 22 | |
30 | .getAbsolutePath() + File.separator + "aLog"; | 23 | /** |
31 | } else {// 如果SD卡不存在,就保存到本应用的目录下 | 24 | * 初始化目录 |
32 | PATH_LOGCAT = context.getFilesDir().getAbsolutePath() | 25 | */ |
33 | + File.separator + "aaLog"; | 26 | public void init(Context context) { |
34 | } | 27 | if (Environment.getExternalStorageState().equals( |
35 | File file = new File(PATH_LOGCAT); | 28 | Environment.MEDIA_MOUNTED)) {// 优先保存到SD卡中 |
36 | 29 | PATH_LOGCAT = Environment.getExternalStorageDirectory() | |
37 | 30 | .getAbsolutePath() + File.separator + "aLog"; | |
38 | LogUtil.i("LogcatHelper", "存储位置:" + PATH_LOGCAT); | 31 | } else {// 如果SD卡不存在,就保存到本应用的目录下 |
39 | if (!file.exists()) { | 32 | PATH_LOGCAT = context.getFilesDir().getAbsolutePath() |
40 | file.mkdirs(); | 33 | + File.separator + "aaLog"; |
41 | } | 34 | } |
42 | 35 | File file = new File(PATH_LOGCAT); | |
43 | if (file.isDirectory()) { | 36 | |
44 | File[] files = file.listFiles(); | 37 | |
45 | if (files.length > 3) { | 38 | LogUtil.i("LogcatHelper", "存储位置:" + PATH_LOGCAT); |
46 | //记录最小的创建时间文件 | 39 | if (!file.exists()) { |
47 | File minTimeFile = null; | 40 | file.mkdirs(); |
48 | for (File file1 : files) { | 41 | } |
49 | String fileName = file1.getName().substring(4, 14); | 42 | |
50 | LogUtil.e("LogcatHelper", "fileName:" + fileName); | 43 | if (file.isDirectory()) { |
51 | if (minTimeFile == null) { | 44 | File[] files = file.listFiles(); |
52 | minTimeFile = file1; | 45 | if (files.length > 3) { |
53 | continue; | 46 | //记录最小的创建时间文件 |
54 | } else { | 47 | File minTimeFile = null; |
55 | String minFileName = minTimeFile.getName().substring(4, 14); | 48 | for (File file1 : files) { |
56 | long minTime = getLongTime(minFileName); | 49 | String fileName = file1.getName().substring(4, 14); |
57 | long curTime = getLongTime(fileName); | 50 | LogUtil.e("LogcatHelper", "fileName:" + fileName); |
58 | LogUtil.e("LogcatHelper", "minFileName:" + minFileName + "--minTime:" + minTime + "--curTime:" + curTime); | 51 | if (minTimeFile == null) { |
59 | if (curTime < minTime) | 52 | minTimeFile = file1; |
60 | minTimeFile = file1; | 53 | continue; |
61 | } | 54 | } else { |
62 | } | 55 | String minFileName = minTimeFile.getName().substring(4, 14); |
63 | if (minTimeFile != null) { | 56 | long minTime = getLongTime(minFileName); |
64 | boolean isDelete = minTimeFile.delete(); | 57 | long curTime = getLongTime(fileName); |
65 | LogUtil.e("LogcatHelper", "isDelete:" + isDelete); | 58 | LogUtil.e("LogcatHelper", "minFileName:" + minFileName + "--minTime:" + minTime + "--curTime:" + curTime); |
66 | } | 59 | if (curTime < minTime) |
67 | } | 60 | minTimeFile = file1; |
68 | } | 61 | } |
69 | 62 | } | |
70 | LogUtil.i("LogcatHelper", "文件是否存在:" + new File(PATH_LOGCAT).exists()); | 63 | if (minTimeFile != null) { |
71 | } | 64 | boolean isDelete = minTimeFile.delete(); |
72 | 65 | LogUtil.e("LogcatHelper", "isDelete:" + isDelete); | |
73 | public static long getLongTime(String dateTime) { | 66 | } |
74 | try { | 67 | } |
75 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 68 | } |
76 | Date startDate = sdf.parse(dateTime); | 69 | |
77 | return startDate.getTime(); | 70 | LogUtil.i("LogcatHelper", "文件是否存在:" + new File(PATH_LOGCAT).exists()); |
78 | } catch (ParseException e) { | 71 | } |
79 | e.printStackTrace(); | 72 | |
80 | } | 73 | public static long getLongTime(String dateTime) { |
81 | return -1; | 74 | try { |
82 | } | 75 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
83 | 76 | Date startDate = sdf.parse(dateTime); | |
84 | 77 | return startDate.getTime(); | |
85 | public static LogcatHelper getInstance(Context context) { | 78 | } catch (ParseException e) { |
86 | if (INSTANCE == null) { | 79 | e.printStackTrace(); |
87 | INSTANCE = new LogcatHelper(context); | 80 | } |
88 | } | 81 | return -1; |
89 | return INSTANCE; | 82 | } |
90 | } | 83 | |
91 | 84 | ||
92 | private LogcatHelper(Context context) { | 85 | public static LogcatHelper getInstance(Context context) { |
93 | init(context); | 86 | if (INSTANCE == null) { |
94 | mPId = android.os.Process.myPid(); | 87 | INSTANCE = new LogcatHelper(context); |
95 | } | 88 | } |
96 | 89 | return INSTANCE; | |
97 | public void start() { | 90 | } |
98 | if (mLogDumper == null) | 91 | |
99 | mLogDumper = new LogDumper(String.valueOf(mPId), PATH_LOGCAT); | 92 | private LogcatHelper(Context context) { |
100 | mLogDumper.start(); | 93 | init(context); |
101 | } | 94 | mPId = android.os.Process.myPid(); |
102 | 95 | } | |
103 | public void stop() { | 96 | |
104 | if (mLogDumper != null) { | 97 | public void start() { |
105 | mLogDumper.stopLogs(); | 98 | if (mLogDumper == null) |
106 | mLogDumper = null; | 99 | mLogDumper = new LogDumper(String.valueOf(mPId), PATH_LOGCAT); |
107 | } | 100 | mLogDumper.start(); |
108 | } | 101 | } |
109 | 102 | ||
110 | private class LogDumper extends Thread { | 103 | public void stop() { |
111 | private Process logcatProc; | 104 | if (mLogDumper != null) { |
112 | private BufferedReader mReader = null; | 105 | mLogDumper.stopLogs(); |
113 | private boolean mRunning = true; | 106 | mLogDumper = null; |
114 | String cmds = null; | 107 | } |
115 | private String mPID; | 108 | } |
116 | private FileOutputStream out = null; | 109 | |
117 | 110 | private class LogDumper extends Thread { | |
118 | public LogDumper(String pid, String dir) { | 111 | private Process logcatProc; |
119 | mPID = pid; | 112 | private BufferedReader mReader = null; |
120 | try { | 113 | private boolean mRunning = true; |
121 | out = new FileOutputStream(new File(dir, "log-" | 114 | String cmds = null; |
122 | + getFileName() + ".log"),true); | 115 | private String mPID; |
123 | } catch (FileNotFoundException e) { | 116 | private FileOutputStream out = null; |
124 | // TODO Auto-generated catch block | 117 | |
125 | e.printStackTrace(); | 118 | public LogDumper(String pid, String dir) { |
126 | } | 119 | mPID = pid; |
127 | /** | 120 | try { |
128 | * | 121 | out = new FileOutputStream(new File(dir, "log-" |
129 | * 日志等级:*:v , *:d , *:w , *:e , *:f , *:s | 122 | + getFileName() + ".log"),true); |
130 | * | 123 | } catch (FileNotFoundException e) { |
131 | * 显示当前mPID程序的 E和W等级的日志. | 124 | // TODO Auto-generated catch block |
132 | * | 125 | e.printStackTrace(); |
133 | * */ | 126 | } |
134 | // cmds = "logcat *:e *:w | grep \"(" + mPID + ")\""; | 127 | /** |
135 | // cmds = "logcat | grep \"(" + mPID + ")\"";//打印所有日志信息 | 128 | * |
136 | // cmds = "logcat -s way";//打印标签过滤信息 | 129 | * 日志等级:*:v , *:d , *:w , *:e , *:f , *:s |
137 | // cmds = "logcat *:e *:i | grep \"(" + mPID + ")\""; | 130 | * |
138 | cmds = "logcat | grep \"(" + mPID + ")\""; | 131 | * 显示当前mPID程序的 E和W等级的日志. |
139 | 132 | * | |
140 | } | 133 | * */ |
141 | 134 | // cmds = "logcat *:e *:w | grep \"(" + mPID + ")\""; | |
142 | public void stopLogs() { | 135 | // cmds = "logcat | grep \"(" + mPID + ")\"";//打印所有日志信息 |
143 | mRunning = false; | 136 | // cmds = "logcat -s way";//打印标签过滤信息 |
144 | } | 137 | // cmds = "logcat *:e *:i | grep \"(" + mPID + ")\""; |
145 | 138 | cmds = "logcat | grep \"(" + mPID + ")\""; | |
146 | @Override | 139 | |
147 | public void run() { | 140 | } |
148 | try { | 141 | |
149 | logcatProc = Runtime.getRuntime().exec(cmds); | 142 | public void stopLogs() { |
150 | mReader = new BufferedReader(new InputStreamReader( | 143 | mRunning = false; |
151 | logcatProc.getInputStream()), 1024); | 144 | } |
152 | String line = null; | 145 | |
153 | while (mRunning && (line = mReader.readLine()) != null) { | 146 | @Override |
154 | if (!mRunning) { | 147 | public void run() { |
155 | break; | 148 | try { |
156 | } | 149 | logcatProc = Runtime.getRuntime().exec(cmds); |
157 | if (line.length() == 0) { | 150 | mReader = new BufferedReader(new InputStreamReader( |
158 | continue; | 151 | logcatProc.getInputStream()), 1024); |
159 | } | 152 | String line = null; |
160 | if (out != null && line.contains(mPID)) { | 153 | while (mRunning && (line = mReader.readLine()) != null) { |
161 | out.write((line + "\n").getBytes()); | 154 | if (!mRunning) { |
162 | } | 155 | break; |
163 | } | 156 | } |
164 | 157 | if (line.length() == 0) { | |
165 | } catch (IOException e) { | 158 | continue; |
166 | e.printStackTrace(); | 159 | } |
167 | } finally { | 160 | if (out != null && line.contains(mPID)) { |
168 | if (logcatProc != null) { | 161 | out.write((line + "\n").getBytes()); |
169 | logcatProc.destroy(); | 162 | } |
170 | logcatProc = null; | 163 | } |
171 | } | 164 | |
172 | if (mReader != null) { | 165 | } catch (IOException e) { |
173 | try { | 166 | e.printStackTrace(); |
174 | mReader.close(); | 167 | } finally { |
175 | mReader = null; | 168 | if (logcatProc != null) { |
176 | } catch (IOException e) { | 169 | logcatProc.destroy(); |
177 | e.printStackTrace(); | 170 | logcatProc = null; |
178 | } | 171 | } |
179 | } | 172 | if (mReader != null) { |
180 | if (out != null) { | 173 | try { |
181 | try { | 174 | mReader.close(); |
182 | out.close(); | 175 | mReader = null; |
183 | } catch (IOException e) { | 176 | } catch (IOException e) { |
184 | e.printStackTrace(); | 177 | e.printStackTrace(); |
185 | } | 178 | } |
186 | out = null; | 179 | } |
187 | } | 180 | if (out != null) { |
188 | } | 181 | try { |
189 | } | 182 | out.close(); |
190 | } | 183 | } catch (IOException e) { |
191 | 184 | e.printStackTrace(); | |
192 | public String getFileName() { | 185 | } |
193 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 186 | out = null; |
194 | String date = format.format(new Date(System.currentTimeMillis())); | 187 | } |
195 | return date; | 188 | } |
196 | } | 189 | } |
197 | } | 190 | } |