Commit 7243a5da592e2bb5e227a1299c780d7381db6f1f
1 parent
0ab1296a2e
Exists in
master
学生字段调整
Showing
7 changed files
with
66 additions
and
128 deletions
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/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; | 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.TextView; | 7 | import android.widget.TextView; |
| 8 | 8 | ||
| 9 | import androidx.annotation.NonNull; | 9 | import androidx.annotation.NonNull; |
| 10 | import androidx.constraintlayout.widget.Group; | 10 | import androidx.constraintlayout.widget.Group; |
| 11 | import androidx.recyclerview.widget.LinearLayoutManager; | 11 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 12 | import androidx.recyclerview.widget.RecyclerView; | 12 | import androidx.recyclerview.widget.RecyclerView; |
| 13 | 13 | ||
| 14 | import com.bumptech.glide.Glide; | 14 | import com.bumptech.glide.Glide; |
| 15 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; | 15 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| 16 | import com.bumptech.glide.request.RequestOptions; | 16 | import com.bumptech.glide.request.RequestOptions; |
| 17 | import com.chad.library.adapter.base.BaseQuickAdapter; | 17 | import com.chad.library.adapter.base.BaseQuickAdapter; |
| 18 | import com.chad.library.adapter.base.BaseViewHolder; | 18 | import com.chad.library.adapter.base.BaseViewHolder; |
| 19 | import com.google.gson.Gson; | 19 | import com.google.gson.Gson; |
| 20 | import com.hjx.parent.AccountActivity; | 20 | import com.hjx.parent.AccountActivity; |
| 21 | import com.hjx.parent.AddStudentActivity; | 21 | import com.hjx.parent.AddStudentActivity; |
| 22 | import com.hjx.parent.EditStudentActivity; | 22 | import com.hjx.parent.EditStudentActivity; |
| 23 | import com.hjx.parent.R; | 23 | import com.hjx.parent.R; |
| 24 | import com.hjx.parent.UserActivity; | 24 | import com.hjx.parent.UserActivity; |
| 25 | import com.hjx.parent.YinsiActivity; | 25 | import com.hjx.parent.YinsiActivity; |
| 26 | import com.hjx.parent.bean.StudentBean; | 26 | import com.hjx.parent.bean.StudentBean; |
| 27 | import com.prws.common.base.BaseFragment; | 27 | import com.prws.common.base.BaseFragment; |
| 28 | import com.prws.common.net.NetWorks; | 28 | import com.prws.common.net.NetWorks; |
| 29 | import com.prws.common.utils.LogUtil; | 29 | import com.prws.common.utils.LogUtil; |
| 30 | import com.prws.common.utils.ScreenUtils; | 30 | import com.prws.common.utils.ScreenUtils; |
| 31 | import com.prws.common.utils.SharedPreferencesUtil; | 31 | import com.prws.common.utils.SharedPreferencesUtil; |
| 32 | 32 | ||
| 33 | import org.json.JSONArray; | 33 | import org.json.JSONArray; |
| 34 | import org.json.JSONObject; | 34 | import org.json.JSONObject; |
| 35 | 35 | ||
| 36 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
| 37 | 37 | ||
| 38 | import io.reactivex.Observer; | 38 | import io.reactivex.Observer; |
| 39 | import io.reactivex.disposables.Disposable; | 39 | import io.reactivex.disposables.Disposable; |
| 40 | import okhttp3.ResponseBody; | 40 | import okhttp3.ResponseBody; |
| 41 | 41 | ||
| 42 | public class MeFragment extends BaseFragment { | 42 | public class MeFragment extends BaseFragment { |
| 43 | @Override | 43 | @Override |
| 44 | protected int getLayoutRes() { | 44 | protected int getLayoutRes() { |
| 45 | return R.layout.fragment_me; | 45 | return R.layout.fragment_me; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | Group group_1; | 48 | Group group_1; |
| 49 | TextView tv_name; | 49 | TextView tv_name; |
| 50 | TextView tv_phone; | 50 | TextView tv_phone; |
| 51 | ImageView iv_toux; | 51 | ImageView iv_toux; |
| 52 | RecyclerView recycle; | 52 | RecyclerView recycle; |
| 53 | 53 | ||
| 54 | @Override | 54 | @Override |
| 55 | protected void initDatas() { | 55 | protected void initDatas() { |
| 56 | super.initDatas(); | 56 | super.initDatas(); |
| 57 | recycle = mRootView.findViewById(R.id.recycle); | 57 | recycle = mRootView.findViewById(R.id.recycle); |
| 58 | group_1 = mRootView.findViewById(R.id.group_1); | 58 | group_1 = mRootView.findViewById(R.id.group_1); |
| 59 | String role = (String) SharedPreferencesUtil.getData("role", ""); | 59 | String role = (String) SharedPreferencesUtil.getData("role", ""); |
| 60 | String userId = (String) SharedPreferencesUtil.getData("userId", ""); | 60 | String userId = (String) SharedPreferencesUtil.getData("userId", ""); |
| 61 | String token = (String) SharedPreferencesUtil.getData("token", ""); | 61 | String token = (String) SharedPreferencesUtil.getData("token", ""); |
| 62 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); | 62 | String phone = (String) SharedPreferencesUtil.getData("phone", ""); |
| 63 | group_1.setVisibility(View.VISIBLE); | 63 | group_1.setVisibility(View.VISIBLE); |
| 64 | iv_toux = mRootView.findViewById(R.id.iv_toux); | 64 | iv_toux = mRootView.findViewById(R.id.iv_toux); |
| 65 | tv_name = mRootView.findViewById(R.id.tv_name); | 65 | tv_name = mRootView.findViewById(R.id.tv_name); |
| 66 | tv_phone = mRootView.findViewById(R.id.tv_phone); | 66 | tv_phone = mRootView.findViewById(R.id.tv_phone); |
| 67 | tv_phone.setVisibility(View.GONE); | 67 | tv_phone.setVisibility(View.GONE); |
| 68 | // tv_phone.setText(phone); | 68 | // tv_phone.setText(phone); |
| 69 | tv_name.setText(phone); | 69 | tv_name.setText(phone); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | @Override | 72 | @Override |
| 73 | public void onResume() { | 73 | public void onResume() { |
| 74 | super.onResume(); | 74 | super.onResume(); |
| 75 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); | 75 | String photo = (String) SharedPreferencesUtil.getData("photo", ""); |
| 76 | if (!TextUtils.isEmpty(photo)) { | 76 | if (!TextUtils.isEmpty(photo)) { |
| 77 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 77 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
| 78 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 78 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 79 | Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux); | 79 | Glide.with(getContext()).load(photo).error(R.mipmap.ic_parent_avatar).apply(options).into(iv_toux); |
| 80 | } | 80 | } |
| 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 | 96 | ||
| 97 | String str = responseBody.string().toString(); | 97 | String str = responseBody.string().toString(); |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | LogUtil.e("TAG", "----" + str); | 100 | LogUtil.e("TAG", "----" + str); |
| 101 | JSONObject jo = new JSONObject(str); | 101 | JSONObject jo = new JSONObject(str); |
| 102 | boolean isSucceed = jo.getBoolean("success"); | 102 | boolean isSucceed = jo.getBoolean("success"); |
| 103 | if (isSucceed) { | 103 | if (isSucceed) { |
| 104 | JSONArray jarr = jo.getJSONArray("data"); | 104 | JSONArray jarr = jo.getJSONArray("data"); |
| 105 | alist.clear(); | 105 | alist.clear(); |
| 106 | for (int i = 0; i < jarr.length(); i++) { | 106 | for (int i = 0; i < jarr.length(); i++) { |
| 107 | JSONObject jo2 = jarr.getJSONObject(i); | 107 | JSONObject jo2 = jarr.getJSONObject(i); |
| 108 | Gson gson = new Gson(); | 108 | Gson gson = new Gson(); |
| 109 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); | 109 | StudentBean sb = gson.fromJson(jo2.toString(), StudentBean.class); |
| 110 | alist.add(sb); | 110 | alist.add(sb); |
| 111 | } | 111 | } |
| 112 | if (alist.size() > 0) { | 112 | if (alist.size() > 0) { |
| 113 | loadList(); | 113 | loadList(); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | } else { | 116 | } else { |
| 117 | 117 | ||
| 118 | } | 118 | } |
| 119 | } catch (Exception e) { | 119 | } catch (Exception e) { |
| 120 | e.printStackTrace(); | 120 | e.printStackTrace(); |
| 121 | } | 121 | } |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | @Override | 124 | @Override |
| 125 | public void onError(Throwable e) { | 125 | public void onError(Throwable e) { |
| 126 | e.toString(); | 126 | e.toString(); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | @Override | 129 | @Override |
| 130 | public void onComplete() { | 130 | public void onComplete() { |
| 131 | 131 | ||
| 132 | } | 132 | } |
| 133 | }); | 133 | }); |
| 134 | mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class))); | 134 | mRootView.findViewById(R.id.view_4).setOnClickListener(view -> startActivity(new Intent(getActivity(), YinsiActivity.class))); |
| 135 | mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class))); | 135 | mRootView.findViewById(R.id.view_5).setOnClickListener(view -> startActivity(new Intent(getActivity(), UserActivity.class))); |
| 136 | mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003)); | 136 | mRootView.findViewById(R.id.view_3).setOnClickListener(view -> startActivityForResult(new Intent(getActivity(), AccountActivity.class), 1003)); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | // @Override | 139 | // @Override |
| 140 | // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 140 | // public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 141 | // super.onActivityResult(requestCode, resultCode, data); | 141 | // super.onActivityResult(requestCode, resultCode, data); |
| 142 | // Intent intent = new Intent(getActivity(), LoginActivity.class); | 142 | // Intent intent = new Intent(getActivity(), LoginActivity.class); |
| 143 | // startActivity(intent); | 143 | // startActivity(intent); |
| 144 | // getActivity().finish(); | 144 | // getActivity().finish(); |
| 145 | // } | 145 | // } |
| 146 | 146 | ||
| 147 | public void loadList() { | 147 | public void loadList() { |
| 148 | StudentBean sb = new StudentBean(); | 148 | StudentBean sb = new StudentBean(); |
| 149 | sb.setNickName("添加学生"); | 149 | sb.setNickName("添加学生"); |
| 150 | alist.add(0, sb); | 150 | alist.add(0, sb); |
| 151 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { | 151 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { |
| 152 | @Override | 152 | @Override |
| 153 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 153 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| 154 | 154 | ||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | @Override | 157 | @Override |
| 158 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 158 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
| 159 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 159 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
| 160 | item.setText(R.id.tv_name, studentBean.getNickName()); | 160 | item.setText(R.id.tv_name, studentBean.getNickName()); |
| 161 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 161 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
| 162 | item.setImageResource(R.id.iv_avatar, R.mipmap.tjxss); | 162 | item.setImageResource(R.id.iv_avatar, R.mipmap.tjxss); |
| 163 | item.setVisible(R.id.iv_vip, false); | 163 | item.setVisible(R.id.iv_vip, false); |
| 164 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 164 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
| 165 | @Override | 165 | @Override |
| 166 | public void onClick(View view) { | 166 | public void onClick(View view) { |
| 167 | startActivity(new Intent(getActivity(), AddStudentActivity.class)); | 167 | startActivity(new Intent(getActivity(), AddStudentActivity.class)); |
| 168 | } | 168 | } |
| 169 | }); | 169 | }); |
| 170 | } else { | 170 | } else { |
| 171 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 171 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
| 172 | item.setImageResource(R.id.iv_avatar, studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 172 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
| 173 | } else { | 173 | } else { |
| 174 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 174 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
| 175 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 175 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 176 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 176 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
| 177 | } | 177 | } |
| 178 | item.setVisible(R.id.iv_vip, !"虚拟".equals(studentBean.getTeacherIdentity())); | 178 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); |
| 179 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 179 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
| 180 | @Override | 180 | @Override |
| 181 | public void onClick(View view) { | 181 | public void onClick(View view) { |
| 182 | startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); | 182 | startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); |
| 183 | } | 183 | } |
| 184 | }); | 184 | }); |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| 187 | }; | 187 | }; |
| 188 | recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | 188 | recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); |
| 189 | recycle.setAdapter(adapter); | 189 | recycle.setAdapter(adapter); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | } | 192 | } |
| 193 | 193 |