Commit 0471108b6ad5a6516cc9e0edfe54f563ab9e410b
1 parent
68453f091e
Exists in
master
去掉添加学生功能
Showing
6 changed files
with
14 additions
and
22 deletions
Show diff stats
.idea/gradle.xml
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <project version="4"> | 2 | <project version="4"> |
| 3 | <component name="GradleMigrationSettings" migrationVersion="1" /> | 3 | <component name="GradleMigrationSettings" migrationVersion="1" /> |
| 4 | <component name="GradleSettings"> | 4 | <component name="GradleSettings"> |
| 5 | <option name="linkedExternalProjectsSettings"> | 5 | <option name="linkedExternalProjectsSettings"> |
| 6 | <GradleProjectSettings> | 6 | <GradleProjectSettings> |
| 7 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> | 7 | <option name="externalProjectPath" value="$PROJECT_DIR$" /> |
| 8 | <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> | 8 | <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" /> |
| 9 | <option name="modules"> | 9 | <option name="modules"> |
| 10 | <set> | 10 | <set> |
| 11 | <option value="$PROJECT_DIR$" /> | 11 | <option value="$PROJECT_DIR$" /> |
| 12 | <option value="$PROJECT_DIR$/app" /> | 12 | <option value="$PROJECT_DIR$/app" /> |
| 13 | <option value="$PROJECT_DIR$/libs" /> | 13 | <option value="$PROJECT_DIR$/libs" /> |
| 14 | <option value="$PROJECT_DIR$/libs/common" /> | 14 | <option value="$PROJECT_DIR$/libs/common" /> |
| 15 | </set> | 15 | </set> |
| 16 | </option> | 16 | </option> |
| 17 | <option name="resolveExternalAnnotations" value="false" /> | 17 | <option name="resolveExternalAnnotations" value="false" /> |
| 18 | </GradleProjectSettings> | 18 | </GradleProjectSettings> |
| 19 | </option> | 19 | </option> |
| 20 | <option name="offlineMode" value="true" /> | ||
| 20 | </component> | 21 | </component> |
| 21 | </project> | 22 | </project> |
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(); | ||
| 132 | sb.setNickName("添加学生"); | ||
| 133 | alist.add(sb); | ||
| 134 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 131 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 135 | try { | 132 | try { |
| 136 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 133 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
| 137 | for (int i = 0; i < alist.size(); i++) { | 134 | for (int i = 0; i < alist.size(); i++) { |
| 138 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { | 135 | if (studentBean.getStuId().equals(alist.get(i).getStuId())) { |
| 139 | select = i; | 136 | select = i; |
| 140 | break; | 137 | break; |
| 141 | } | 138 | } |
| 142 | } | 139 | } |
| 143 | } catch (Exception e) { | 140 | } catch (Exception e) { |
| 144 | 141 | ||
| 145 | } | 142 | } |
| 146 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { | 143 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child_choose, alist) { |
| 147 | @Override | 144 | @Override |
| 148 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 145 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| 149 | 146 | ||
| 150 | } | 147 | } |
| 151 | 148 | ||
| 152 | @Override | 149 | @Override |
| 153 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 150 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
| 154 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 151 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
| 155 | item.setText(R.id.tv_name, studentBean.getNickName()); | 152 | item.setText(R.id.tv_name, studentBean.getNickName()); |
| 156 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 153 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
| 157 | item.setVisible(R.id.rl_add, true); | 154 | // do nothing |
| 158 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | ||
| 159 | @Override | ||
| 160 | public void onClick(View view) { | ||
| 161 | startActivity(new Intent(ChooseActivity.this, AddStudentActivity.class)); | ||
| 162 | } | ||
| 163 | }); | ||
| 164 | } else { | 155 | } else { |
| 165 | item.setBackgroundRes(R.id.rl_child, select == item.getAdapterPosition() ? R.drawable.bg_solid_white_10_or : R.drawable.bg_solid_white_10); | 156 | 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); | 157 | item.setImageResource(R.id.iv_select, select == item.getAdapterPosition() ? R.mipmap.gx : R.mipmap.wsyq); |
| 167 | item.setVisible(R.id.rl_add, false); | 158 | item.setVisible(R.id.rl_add, false); |
| 168 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 159 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
| 169 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 160 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
| 170 | } else { | 161 | } else { |
| 171 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); | 162 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(ChooseActivity.this, 45)); |
| 172 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 163 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 173 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 164 | Glide.with(ChooseActivity.this).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
| 174 | } | 165 | } |
| 175 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); | 166 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); |
| 176 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 167 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
| 177 | @Override | 168 | @Override |
| 178 | public void onClick(View view) { | 169 | public void onClick(View view) { |
| 179 | select = item.getAdapterPosition(); | 170 | select = item.getAdapterPosition(); |
| 180 | notifyDataSetChanged(); | 171 | notifyDataSetChanged(); |
| 181 | } | 172 | } |
| 182 | }); | 173 | }); |
| 183 | } | 174 | } |
| 184 | } | 175 | } |
| 185 | }; | 176 | }; |
| 186 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); | 177 | recycle.setLayoutManager(new LinearLayoutManager(ChooseActivity.this, LinearLayoutManager.VERTICAL, false)); |
| 187 | recycle.setAdapter(adapter); | 178 | recycle.setAdapter(adapter); |
| 188 | } | 179 | } |
| 189 | 180 | ||
| 190 | @OnClick(R.id.tv_confirm) | 181 | @OnClick(R.id.tv_confirm) |
| 191 | public void confirm(View view) { | 182 | public void confirm(View view) { |
| 192 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { | 183 | if (alist.size() > 0 && alist.size() - 1 >= select && alist.get(select) != null) { |
| 193 | StudentBean studentBean = alist.get(select); | 184 | StudentBean studentBean = alist.get(select); |
| 194 | if (studentBean.getStuId() != null) { | 185 | if (studentBean.getStuId() != null) { |
| 195 | if (getIntent().getBooleanExtra("needBack", false)) { | 186 | if (getIntent().getBooleanExtra("needBack", false)) { |
| 196 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 187 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
| 197 | } else { | 188 | } else { |
| 198 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); | 189 | Intent intent = new Intent(ChooseActivity.this, MainActivity.class); |
| 199 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); | 190 | SharedPreferencesUtil.putData("student", new Gson().toJson(studentBean)); |
| 200 | startActivity(intent); | 191 | startActivity(intent); |
| 201 | } | 192 | } |
| 202 | finish(); | 193 | finish(); |
| 203 | } | 194 | } |
| 204 | } | 195 | } |
| 205 | } | 196 | } |
| 206 | } | 197 | } |
| 207 | 198 |
app/src/main/java/com/hjx/parent/SmsLoginActivity.java
| 1 | package com.hjx.parent; | 1 | package com.hjx.parent; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | import android.telephony.PhoneNumberUtils; | 6 | import android.telephony.PhoneNumberUtils; |
| 7 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
| 8 | import android.view.View; | 8 | import android.view.View; |
| 9 | import android.widget.Toast; | 9 | import android.widget.Toast; |
| 10 | 10 | ||
| 11 | import com.hjx.parent.databinding.ActivitySmsLoginBinding; | 11 | import com.hjx.parent.databinding.ActivitySmsLoginBinding; |
| 12 | import com.hjx.parent.rx.BaseRxActivity; | 12 | import com.hjx.parent.rx.BaseRxActivity; |
| 13 | import com.prws.common.bean.Student; | ||
| 13 | import com.prws.common.net.NetWorks; | 14 | import com.prws.common.net.NetWorks; |
| 14 | import com.prws.common.utils.LogUtil; | 15 | import com.prws.common.utils.LogUtil; |
| 15 | import com.prws.common.utils.SharedPreferencesUtil; | 16 | import com.prws.common.utils.SharedPreferencesUtil; |
| 16 | 17 | ||
| 17 | import java.util.HashMap; | 18 | import java.util.HashMap; |
| 19 | import java.util.List; | ||
| 18 | import java.util.Map; | 20 | import java.util.Map; |
| 19 | import java.util.concurrent.TimeUnit; | 21 | import java.util.concurrent.TimeUnit; |
| 20 | 22 | ||
| 21 | import io.reactivex.Observable; | 23 | import io.reactivex.Observable; |
| 22 | import io.reactivex.android.schedulers.AndroidSchedulers; | 24 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 23 | import io.reactivex.disposables.Disposable; | 25 | import io.reactivex.disposables.Disposable; |
| 24 | 26 | ||
| 25 | public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> { | 27 | public class SmsLoginActivity extends BaseRxActivity<ActivitySmsLoginBinding> { |
| 26 | private final NetWorks.NetService api = NetWorks.service_url; | 28 | private final NetWorks.NetService api = NetWorks.service_url; |
| 27 | @Override | 29 | @Override |
| 28 | public void initView(Bundle savedInstanceState) { | 30 | public void initView(Bundle savedInstanceState) { |
| 29 | getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); | 31 | getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
| 30 | 32 | ||
| 31 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 33 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 32 | 34 | ||
| 33 | if (!TextUtils.isEmpty(student)) { | 35 | if (!TextUtils.isEmpty(student)) { |
| 34 | if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { | 36 | if ((SharedPreferencesUtil.getData("role", "")).equals("parent")) { |
| 35 | Intent intent = new Intent(this, MainActivity.class); | 37 | Intent intent = new Intent(this, MainActivity.class); |
| 36 | startActivity(intent); | 38 | startActivity(intent); |
| 37 | finish(); | 39 | finish(); |
| 38 | } else { | 40 | } else { |
| 39 | Intent intent = new Intent(this, TeacherMainActivity.class); | 41 | Intent intent = new Intent(this, TeacherMainActivity.class); |
| 40 | startActivity(intent); | 42 | startActivity(intent); |
| 41 | finish(); | 43 | finish(); |
| 42 | } | 44 | } |
| 43 | return; | 45 | return; |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | binding.tvEntrance.setOnClickListener(v -> { | 48 | binding.tvEntrance.setOnClickListener(v -> { |
| 47 | startActivity(new Intent(this, LoginActivity.class)); | 49 | startActivity(new Intent(this, LoginActivity.class)); |
| 48 | finish(); | 50 | finish(); |
| 49 | }); | 51 | }); |
| 50 | binding.btnGetCode.setOnClickListener(v -> { | 52 | binding.btnGetCode.setOnClickListener(v -> { |
| 51 | String phone = binding.etPhone.getText().toString().trim(); | 53 | String phone = binding.etPhone.getText().toString().trim(); |
| 52 | if (phone.isEmpty()) { | 54 | if (phone.isEmpty()) { |
| 53 | showToast("请输入手机号"); | 55 | showToast("请输入手机号"); |
| 54 | return; | 56 | return; |
| 55 | } | 57 | } |
| 56 | sendCode(phone); | 58 | sendCode(phone); |
| 57 | }); | 59 | }); |
| 58 | binding.btnLogin.setOnClickListener(v -> { | 60 | binding.btnLogin.setOnClickListener(v -> { |
| 59 | 61 | ||
| 60 | String phone = binding.etPhone.getText().toString().trim(); | 62 | String phone = binding.etPhone.getText().toString().trim(); |
| 61 | String code = binding.etCode.getText().toString().trim(); | 63 | String code = binding.etCode.getText().toString().trim(); |
| 62 | if (phone.isEmpty() || code.isEmpty()) { | 64 | if (phone.isEmpty() || code.isEmpty()) { |
| 63 | Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show(); | 65 | Toast.makeText(this, "手机号以及验证码不能为空", Toast.LENGTH_SHORT).show(); |
| 64 | return; | 66 | return; |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | if (!binding.chkPermission.isChecked()) { | 69 | if (!binding.chkPermission.isChecked()) { |
| 68 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); | 70 | Toast.makeText(this, "请勾选协议", Toast.LENGTH_SHORT).show(); |
| 69 | return; | 71 | return; |
| 70 | } | 72 | } |
| 71 | login(phone, code); | 73 | login(phone, code); |
| 72 | }); | 74 | }); |
| 73 | 75 | ||
| 74 | binding.tv6.setOnClickListener(view -> { | 76 | binding.tv6.setOnClickListener(view -> { |
| 75 | startActivity(new Intent(this, YinsiActivity.class)); | 77 | startActivity(new Intent(this, YinsiActivity.class)); |
| 76 | }); | 78 | }); |
| 77 | binding.tv4.setOnClickListener(view -> { | 79 | binding.tv4.setOnClickListener(view -> { |
| 78 | startActivity(new Intent(this, UserAgreementActivity.class)); | 80 | startActivity(new Intent(this, UserAgreementActivity.class)); |
| 79 | }); | 81 | }); |
| 80 | } | 82 | } |
| 81 | 83 | ||
| 82 | @SuppressLint("CheckResult") | 84 | @SuppressLint("CheckResult") |
| 83 | private void login(String phone, String code) { | 85 | private void login(String phone, String code) { |
| 84 | binding.btnLogin.setEnabled(false); | 86 | binding.btnLogin.setEnabled(false); |
| 85 | Map<String, String> body = new HashMap<>(); | 87 | Map<String, String> body = new HashMap<>(); |
| 86 | body.put("phone", phone); | 88 | body.put("phone", phone); |
| 87 | body.put("code", code); | 89 | body.put("code", code); |
| 88 | api.smsLogin(body) | 90 | api.smsLogin(body) |
| 89 | .compose(transformSingle()) | 91 | .compose(transformSingle()) |
| 90 | .subscribe((response, th) -> { | 92 | .subscribe((response, th) -> { |
| 91 | binding.btnLogin.setEnabled(true); | 93 | binding.btnLogin.setEnabled(true); |
| 92 | if (handleResponseData(response, th)) { | 94 | if (handleResponseData(response, th)) { |
| 95 | List<Student> list = response.getData().parentInfoList; | ||
| 96 | if (list == null || list.isEmpty()) { | ||
| 97 | showToast("未注册学生, 无法登录"); | ||
| 98 | return; | ||
| 99 | } | ||
| 93 | SharedPreferencesUtil.putData("phone", phone); | 100 | SharedPreferencesUtil.putData("phone", phone); |
| 94 | SharedPreferencesUtil.putData("role", "parent"); | 101 | SharedPreferencesUtil.putData("role", "parent"); |
| 95 | SharedPreferencesUtil.putData("userId", response.getData().id); | 102 | SharedPreferencesUtil.putData("userId", response.getData().id); |
| 96 | SharedPreferencesUtil.putData("token", response.getData().token); | 103 | SharedPreferencesUtil.putData("token", response.getData().token); |
| 97 | SharedPreferencesUtil.putData("name", response.getData().username); | 104 | SharedPreferencesUtil.putData("name", response.getData().username); |
| 98 | startActivity(new Intent(this, ChooseActivity.class)); | 105 | startActivity(new Intent(this, ChooseActivity.class)); |
| 99 | finish(); | 106 | finish(); |
| 100 | } | 107 | } |
| 101 | }); | 108 | }); |
| 102 | } | 109 | } |
| 103 | 110 | ||
| 104 | @SuppressLint({"SetTextI18n", "CheckResult"}) | 111 | @SuppressLint({"SetTextI18n", "CheckResult"}) |
| 105 | private void sendCode(String phone) { | 112 | private void sendCode(String phone) { |
| 106 | binding.btnGetCode.setEnabled(false); | 113 | binding.btnGetCode.setEnabled(false); |
| 107 | api.smsCode(phone) | 114 | api.smsCode(phone) |
| 108 | .compose(transformSingle()) | 115 | .compose(transformSingle()) |
| 109 | .subscribe((response, th) -> { | 116 | .subscribe((response, th) -> { |
| 110 | if (handleResponse(response, th)) { | 117 | if (handleResponse(response, th)) { |
| 111 | showToast("验证码已发送"); | 118 | showToast("验证码已发送"); |
| 112 | timeDown(); | 119 | timeDown(); |
| 113 | } else { | 120 | } else { |
| 114 | if (disposable != null) disposable.dispose(); | 121 | if (disposable != null) disposable.dispose(); |
| 115 | binding.btnGetCode.setText("获取验证码"); | 122 | binding.btnGetCode.setText("获取验证码"); |
| 116 | binding.btnGetCode.setEnabled(true); | 123 | binding.btnGetCode.setEnabled(true); |
| 117 | } | 124 | } |
| 118 | }); | 125 | }); |
| 119 | } | 126 | } |
| 120 | 127 | ||
| 121 | private int timeDown = 0; | 128 | private int timeDown = 0; |
| 122 | private Disposable disposable; | 129 | private Disposable disposable; |
| 123 | @SuppressLint("SetTextI18n") | 130 | @SuppressLint("SetTextI18n") |
| 124 | private void timeDown() { | 131 | private void timeDown() { |
| 125 | timeDown = 60; | 132 | timeDown = 60; |
| 126 | disposable = Observable | 133 | disposable = Observable |
| 127 | .interval(0, 1, TimeUnit.SECONDS) | 134 | .interval(0, 1, TimeUnit.SECONDS) |
| 128 | .observeOn(AndroidSchedulers.mainThread()) | 135 | .observeOn(AndroidSchedulers.mainThread()) |
| 129 | .subscribe(l -> { | 136 | .subscribe(l -> { |
| 130 | if (--timeDown <= 0) { | 137 | if (--timeDown <= 0) { |
| 131 | if (disposable != null) disposable.dispose(); | 138 | if (disposable != null) disposable.dispose(); |
| 132 | binding.btnGetCode.setText("获取验证码"); | 139 | binding.btnGetCode.setText("获取验证码"); |
| 133 | binding.btnGetCode.setEnabled(true); | 140 | binding.btnGetCode.setEnabled(true); |
| 134 | } else { | 141 | } else { |
| 135 | binding.btnGetCode.setText("获取验证码(" + timeDown + "s)"); | 142 | binding.btnGetCode.setText("获取验证码(" + timeDown + "s)"); |
| 136 | binding.btnGetCode.setEnabled(false); | 143 | binding.btnGetCode.setEnabled(false); |
| 137 | } | 144 | } |
| 138 | }, Throwable::printStackTrace); | 145 | }, Throwable::printStackTrace); |
| 139 | } | 146 | } |
| 140 | 147 | ||
| 141 | @Override | 148 | @Override |
| 142 | protected void onDestroy() { | 149 | protected void onDestroy() { |
| 143 | super.onDestroy(); | 150 | super.onDestroy(); |
| 144 | if (disposable != null) disposable.dispose(); | 151 | if (disposable != null) disposable.dispose(); |
| 145 | } | 152 | } |
| 146 | 153 | ||
| 147 | @Override | 154 | @Override |
| 148 | protected ActivitySmsLoginBinding getViewBinding() { | 155 | protected ActivitySmsLoginBinding getViewBinding() { |
| 149 | return ActivitySmsLoginBinding.inflate(getLayoutInflater()); | 156 | return ActivitySmsLoginBinding.inflate(getLayoutInflater()); |
| 150 | } | 157 | } |
| 151 | } | 158 | } |
| 152 | 159 |
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(); | ||
| 149 | sb.setNickName("添加学生"); | ||
| 150 | alist.add(0, sb); | ||
| 151 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { | 148 | BaseQuickAdapter adapter = new BaseQuickAdapter(R.layout.item_child, alist) { |
| 152 | @Override | 149 | @Override |
| 153 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { | 150 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
| 154 | 151 | ||
| 155 | } | 152 | } |
| 156 | 153 | ||
| 157 | @Override | 154 | @Override |
| 158 | protected void convert(@NonNull BaseViewHolder item, Object o) { | 155 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
| 159 | StudentBean studentBean = alist.get(item.getAdapterPosition()); | 156 | StudentBean studentBean = alist.get(item.getAdapterPosition()); |
| 160 | item.setText(R.id.tv_name, studentBean.getNickName()); | 157 | item.setText(R.id.tv_name, studentBean.getNickName()); |
| 161 | if (TextUtils.isEmpty(studentBean.getStuId())) { | 158 | if (TextUtils.isEmpty(studentBean.getStuId())) { |
| 162 | item.setImageResource(R.id.iv_avatar, R.mipmap.tjxss); | 159 | // do nothing |
| 163 | item.setVisible(R.id.iv_vip, false); | ||
| 164 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | ||
| 165 | @Override | ||
| 166 | public void onClick(View view) { | ||
| 167 | startActivity(new Intent(getActivity(), AddStudentActivity.class)); | ||
| 168 | } | ||
| 169 | }); | ||
| 170 | } else { | 160 | } else { |
| 171 | if (TextUtils.isEmpty(studentBean.getPhoto())) { | 161 | if (TextUtils.isEmpty(studentBean.getPhoto())) { |
| 172 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); | 162 | item.setImageResource(R.id.iv_avatar, "男".equals(studentBean.getGender()) ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); |
| 173 | } else { | 163 | } else { |
| 174 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); | 164 | RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(getContext(), 45)); |
| 175 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); | 165 | RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); |
| 176 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); | 166 | Glide.with(getActivity()).load(studentBean.getPhoto()).apply(options).into((ImageView) item.getView(R.id.iv_avatar)); |
| 177 | } | 167 | } |
| 178 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); | 168 | item.setVisible(R.id.iv_vip, studentBean.getIsIntention() == 1); |
| 179 | item.getConvertView().setOnClickListener(new View.OnClickListener() { | 169 | item.getConvertView().setOnClickListener(new View.OnClickListener() { |
| 180 | @Override | 170 | @Override |
| 181 | public void onClick(View view) { | 171 | public void onClick(View view) { |
| 182 | startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); | 172 | startActivity(new Intent(getActivity(), EditStudentActivity.class).putExtra("student", new Gson().toJson(studentBean))); |
| 183 | } | 173 | } |
| 184 | }); | 174 | }); |
| 185 | } | 175 | } |
| 186 | } | 176 | } |
| 187 | }; | 177 | }; |
| 188 | recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); | 178 | recycle.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); |
| 189 | recycle.setAdapter(adapter); | 179 | recycle.setAdapter(adapter); |
| 190 | } | 180 | } |
| 191 | 181 | ||
| 192 | } | 182 | } |
| 193 | 183 |
libs/common/src/main/java/com/prws/common/bean/User.java
| 1 | package com.prws.common.bean; | 1 | package com.prws.common.bean; |
| 2 | 2 | ||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 3 | public class User { | 5 | public class User { |
| 4 | 6 | ||
| 5 | public String id; | 7 | public String id; |
| 6 | public String phone; | 8 | public String phone; |
| 7 | public String account; | 9 | public String account; |
| 8 | public String password; | 10 | public String password; |
| 9 | public String username; | 11 | public String username; |
| 10 | public String identity; //用户身份(NORMAL,ADMIN,EMPLOYEE) | 12 | public String identity; //用户身份(NORMAL,ADMIN,EMPLOYEE) |
| 11 | public String identityName; //用户身份(普通用户、管理员、内部员工) | 13 | public String identityName; //用户身份(普通用户、管理员、内部员工) |
| 12 | public String gender; //性别 | 14 | public String gender; //性别 |
| 13 | public String registration; //注册方式(用户创建、员工创建) | 15 | public String registration; //注册方式(用户创建、员工创建) |
| 16 | public ArrayList<Student> parentInfoList; | ||
| 14 | public String token; | 17 | public String token; |
| 15 | } | 18 | } |
| 16 | 19 |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| 1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
| 5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
| 7 | import com.prws.common.bean.CutPicBean; | 7 | import com.prws.common.bean.CutPicBean; |
| 8 | import com.prws.common.bean.GradeAndSubject; | 8 | import com.prws.common.bean.GradeAndSubject; |
| 9 | import com.prws.common.bean.PageInfo; | 9 | import com.prws.common.bean.PageInfo; |
| 10 | import com.prws.common.bean.ResponseResult; | 10 | import com.prws.common.bean.ResponseResult; |
| 11 | import com.prws.common.bean.ScheduleBean; | 11 | import com.prws.common.bean.ScheduleBean; |
| 12 | import com.prws.common.bean.Student; | 12 | import com.prws.common.bean.Student; |
| 13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
| 14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
| 15 | import com.prws.common.bean.UpdateBean; | 15 | import com.prws.common.bean.UpdateBean; |
| 16 | import com.prws.common.bean.User; | 16 | import com.prws.common.bean.User; |
| 17 | import com.prws.common.bean.baidu.BaiduInput; | 17 | import com.prws.common.bean.baidu.BaiduInput; |
| 18 | import com.prws.common.bean.homework.HomeWork; | 18 | import com.prws.common.bean.homework.HomeWork; |
| 19 | import com.prws.common.bean.homework.HomeworkDetail; | 19 | import com.prws.common.bean.homework.HomeworkDetail; |
| 20 | import com.prws.common.bean.homework.HomeworkList; | 20 | import com.prws.common.bean.homework.HomeworkList; |
| 21 | import com.prws.common.bean.homework.StDetail; | 21 | import com.prws.common.bean.homework.StDetail; |
| 22 | import com.prws.common.utils.BitmapUtils; | 22 | import com.prws.common.utils.BitmapUtils; |
| 23 | import com.prws.common.utils.SharedPreferencesUtil; | 23 | import com.prws.common.utils.SharedPreferencesUtil; |
| 24 | 24 | ||
| 25 | import java.io.File; | 25 | import java.io.File; |
| 26 | import java.util.HashMap; | 26 | import java.util.HashMap; |
| 27 | import java.util.List; | 27 | import java.util.List; |
| 28 | import java.util.Map; | 28 | import java.util.Map; |
| 29 | 29 | ||
| 30 | import io.reactivex.Observable; | 30 | import io.reactivex.Observable; |
| 31 | import io.reactivex.Observer; | 31 | import io.reactivex.Observer; |
| 32 | import io.reactivex.Single; | 32 | import io.reactivex.Single; |
| 33 | import io.reactivex.android.schedulers.AndroidSchedulers; | 33 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 34 | import io.reactivex.schedulers.Schedulers; | 34 | import io.reactivex.schedulers.Schedulers; |
| 35 | import okhttp3.MediaType; | 35 | import okhttp3.MediaType; |
| 36 | import okhttp3.MultipartBody; | 36 | import okhttp3.MultipartBody; |
| 37 | import okhttp3.RequestBody; | 37 | import okhttp3.RequestBody; |
| 38 | import okhttp3.ResponseBody; | 38 | import okhttp3.ResponseBody; |
| 39 | import retrofit2.Call; | 39 | import retrofit2.Call; |
| 40 | import retrofit2.Callback; | 40 | import retrofit2.Callback; |
| 41 | import retrofit2.http.Body; | 41 | import retrofit2.http.Body; |
| 42 | import retrofit2.http.GET; | 42 | import retrofit2.http.GET; |
| 43 | import retrofit2.http.Header; | 43 | import retrofit2.http.Header; |
| 44 | import retrofit2.http.Headers; | 44 | import retrofit2.http.Headers; |
| 45 | import retrofit2.http.Multipart; | 45 | import retrofit2.http.Multipart; |
| 46 | import retrofit2.http.POST; | 46 | import retrofit2.http.POST; |
| 47 | import retrofit2.http.PUT; | 47 | import retrofit2.http.PUT; |
| 48 | import retrofit2.http.Part; | 48 | import retrofit2.http.Part; |
| 49 | import retrofit2.http.PartMap; | 49 | import retrofit2.http.PartMap; |
| 50 | import retrofit2.http.Query; | 50 | import retrofit2.http.Query; |
| 51 | import retrofit2.http.Url; | 51 | import retrofit2.http.Url; |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 54 | * 类名称:NetWorks | 54 | * 类名称:NetWorks |
| 55 | * 创建人: | 55 | * 创建人: |
| 56 | * <p> | 56 | * <p> |
| 57 | * 类描述:网络请求的操作类 | 57 | * 类描述:网络请求的操作类 |
| 58 | */ | 58 | */ |
| 59 | public class NetWorks extends RetrofitUtils { | 59 | public class NetWorks extends RetrofitUtils { |
| 60 | //服务器路径 | 60 | //服务器路径 |
| 61 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 61 | public static final NetService service_url = getMachineRetrofit("https://mgr.hjx.com").create(NetService.class); |
| 62 | 62 | ||
| 63 | //设缓存有效期为1天 | 63 | //设缓存有效期为1天 |
| 64 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 64 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
| 65 | //查询缓存的Cache-Control设置,使用缓存 | 65 | //查询缓存的Cache-Control设置,使用缓存 |
| 66 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 66 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
| 67 | //查询网络的Cache-Control设置。不使用缓存 | 67 | //查询网络的Cache-Control设置。不使用缓存 |
| 68 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 68 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | public interface NetService { | 71 | public interface NetService { |
| 72 | 72 | ||
| 73 | 73 | ||
| 74 | @GET("/api/v1/user/logout") | 74 | @GET("/api/v1/user/logout") |
| 75 | Observable<ResponseBody> logout(); | 75 | Observable<ResponseBody> logout(); |
| 76 | 76 | ||
| 77 | @Multipart | 77 | @Multipart |
| 78 | @POST("/api/v1/user/upLoadAvatar") | 78 | @POST("/api/v1/user/upLoadAvatar") |
| 79 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 79 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | @Headers("Content-Type: application/json") | 82 | @Headers("Content-Type: application/json") |
| 83 | @POST("/api/v1/user/editUser") | 83 | @POST("/api/v1/user/editUser") |
| 84 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 84 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
| 85 | 85 | ||
| 86 | @Headers("Content-Type: application/json") | 86 | @Headers("Content-Type: application/json") |
| 87 | @POST("/api/v1/user/changePassword") | 87 | @POST("/api/v1/user/changePassword") |
| 88 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 88 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | @GET("/api/v1/user/searchById") | 91 | @GET("/api/v1/user/searchById") |
| 92 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 92 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | @Headers("Content-Type: application/json") | 95 | @Headers("Content-Type: application/json") |
| 96 | @POST("/api/v1/login/userLogin") | 96 | @POST("/api/v1/login/userLogin") |
| 97 | Observable<ResponseBody> login(@Body RequestBody body); | 97 | Observable<ResponseBody> login(@Body RequestBody body); |
| 98 | 98 | ||
| 99 | @GET("/api/v1/resource/listGradeAndSubject") | 99 | @GET("/api/v1/resource/listGradeAndSubject") |
| 100 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 100 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | @GET("/api/v1/manager/generalQrCode") | 103 | @GET("/api/v1/manager/generalQrCode") |
| 104 | Observable<ResponseBody> generalQrCode(); | 104 | Observable<ResponseBody> generalQrCode(); |
| 105 | 105 | ||
| 106 | @GET("/api/v1/parent/scanAndLogin") | 106 | @GET("/api/v1/parent/scanAndLogin") |
| 107 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); | 107 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
| 108 | 108 | ||
| 109 | @GET("/api/v1/parent/getChildrenList") | 109 | @GET("/api/v1/parent/getChildrenList") |
| 110 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 110 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | @Headers("Content-Type: application/json") | 113 | @Headers("Content-Type: application/json") |
| 114 | @POST("/api/v1/parent/registerParent") | 114 | @POST("/api/v1/parent/registerParent") |
| 115 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 115 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
| 116 | 116 | ||
| 117 | 117 | ||
| 118 | @GET("/api/v1/parent/listChildren") | 118 | @GET("/api/v1/parent/listChildren") |
| 119 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 119 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | @Headers("Content-Type: application/json") | 122 | @Headers("Content-Type: application/json") |
| 123 | @POST("/api/v1/parent/registerStudent") | 123 | @POST("/api/v1/parent/registerStudent") |
| 124 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 124 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 125 | 125 | ||
| 126 | @Headers("Content-Type: application/json") | 126 | @Headers("Content-Type: application/json") |
| 127 | @POST("/api/v1/parent/bindTeacher") | 127 | @POST("/api/v1/parent/bindTeacher") |
| 128 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 128 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
| 129 | 129 | ||
| 130 | @Multipart | 130 | @Multipart |
| 131 | @POST("/api/v1/user/upLoadAvatar") | 131 | @POST("/api/v1/user/upLoadAvatar") |
| 132 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 132 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | @Multipart | 135 | @Multipart |
| 136 | @POST("/api/v1/student/editStudentAvatar") | 136 | @POST("/api/v1/student/editStudentAvatar") |
| 137 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 137 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 138 | 138 | ||
| 139 | @Headers("Content-Type: application/json") | 139 | @Headers("Content-Type: application/json") |
| 140 | @POST("/api/v1/parent/editChild") | 140 | @POST("/api/v1/parent/editChild") |
| 141 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 141 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 142 | 142 | ||
| 143 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 143 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
| 144 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 144 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 145 | 145 | ||
| 146 | @GET("api/v1/parent/searchTeacher") | 146 | @GET("api/v1/parent/searchTeacher") |
| 147 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 147 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
| 148 | 148 | ||
| 149 | @POST("api/v1/question/listErrorBook") | 149 | @POST("api/v1/question/listErrorBook") |
| 150 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 150 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
| 151 | 151 | ||
| 152 | @POST | 152 | @POST |
| 153 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 153 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
| 154 | 154 | ||
| 155 | @POST | 155 | @POST |
| 156 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 156 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
| 157 | 157 | ||
| 158 | @POST | 158 | @POST |
| 159 | Observable<JsonObject> getBaiduToken(@Url String url); | 159 | Observable<JsonObject> getBaiduToken(@Url String url); |
| 160 | 160 | ||
| 161 | @Multipart | 161 | @Multipart |
| 162 | @POST("api/v1/pad/addErrorBook") | 162 | @POST("api/v1/pad/addErrorBook") |
| 163 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 163 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 164 | 164 | ||
| 165 | @POST("api/v1/pad/deleteStuErrorBook") | 165 | @POST("api/v1/pad/deleteStuErrorBook") |
| 166 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 166 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
| 167 | 167 | ||
| 168 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 168 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
| 169 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 169 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
| 170 | 170 | ||
| 171 | @POST("api/v1/question/editErrorBook") | 171 | @POST("api/v1/question/editErrorBook") |
| 172 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 172 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
| 173 | 173 | ||
| 174 | @GET("api/v1/resource/checkUpdate") | 174 | @GET("api/v1/resource/checkUpdate") |
| 175 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 175 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
| 176 | 176 | ||
| 177 | @GET("api/v1/teacher/getStudentList") | 177 | @GET("api/v1/teacher/getStudentList") |
| 178 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 178 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
| 179 | 179 | ||
| 180 | @GET("api/v1/teacher/getStudentList") | 180 | @GET("api/v1/teacher/getStudentList") |
| 181 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | 181 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); |
| 182 | 182 | ||
| 183 | @GET("api/v1/answer/listRecordForTeacher") | 183 | @GET("api/v1/answer/listRecordForTeacher") |
| 184 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 184 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
| 185 | 185 | ||
| 186 | @GET("api/v1/homework/listHomeworkByStuId") | 186 | @GET("api/v1/homework/listHomeworkByStuId") |
| 187 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); | 187 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 188 | 188 | ||
| 189 | @POST | 189 | @POST |
| 190 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); | 190 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); |
| 191 | 191 | ||
| 192 | @Multipart | 192 | @Multipart |
| 193 | @POST("api/v1/homework/uploadHomework") | 193 | @POST("api/v1/homework/uploadHomework") |
| 194 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); | 194 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); |
| 195 | 195 | ||
| 196 | @POST("api/v1/homework/uploadHomeworkAction") | 196 | @POST("api/v1/homework/uploadHomeworkAction") |
| 197 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); | 197 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); |
| 198 | 198 | ||
| 199 | @GET("api/v1/homework/removeHomework") | 199 | @GET("api/v1/homework/removeHomework") |
| 200 | Single<ResponseResult<Boolean>> deleteHomework( | 200 | Single<ResponseResult<Boolean>> deleteHomework( |
| 201 | @Header("Authorization") String token, | 201 | @Header("Authorization") String token, |
| 202 | @Query("homeworkId") String homeworkId | 202 | @Query("homeworkId") String homeworkId |
| 203 | ); | 203 | ); |
| 204 | 204 | ||
| 205 | @GET("api/v1/homework/listHomeworkById") | 205 | @GET("api/v1/homework/listHomeworkById") |
| 206 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); | 206 | Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId); |
| 207 | 207 | ||
| 208 | @POST("api/v1/homework/uploadHomeworkFeedback") | 208 | @POST("api/v1/homework/uploadHomeworkFeedback") |
| 209 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); | 209 | Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map); |
| 210 | 210 | ||
| 211 | @POST("api/v1/homework/editHomeworkInfo") | 211 | @POST("api/v1/homework/editHomeworkInfo") |
| 212 | Single<ResponseResult<Boolean>> editHomework( | 212 | Single<ResponseResult<Boolean>> editHomework( |
| 213 | @Header("Authorization") String token, | 213 | @Header("Authorization") String token, |
| 214 | @Body Object body | 214 | @Body Object body |
| 215 | ); | 215 | ); |
| 216 | 216 | ||
| 217 | @GET("api/v1/homework/listHomeworkDetailByStuId") | 217 | @GET("api/v1/homework/listHomeworkDetailByStuId") |
| 218 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( | 218 | Single<ResponseResult<HomeworkDetail>> getHomeworkCompleteDetail( |
| 219 | @Header("Authorization") String token, | 219 | @Header("Authorization") String token, |
| 220 | @Query("stuId") String stuId, | 220 | @Query("stuId") String stuId, |
| 221 | @Query("homeworkId") String homeworkId, | 221 | @Query("homeworkId") String homeworkId, |
| 222 | // type 固定传true | 222 | // type 固定传true |
| 223 | @Query("type") boolean type | 223 | @Query("type") boolean type |
| 224 | ); | 224 | ); |
| 225 | 225 | ||
| 226 | @GET("api/v1/homework/listHomeworkStatistics") | 226 | @GET("api/v1/homework/listHomeworkStatistics") |
| 227 | Single<ResponseResult<List<StDetail>>> getHuyouList( | 227 | Single<ResponseResult<List<StDetail>>> getHuyouList( |
| 228 | @Header("Authorization") String token, | 228 | @Header("Authorization") String token, |
| 229 | @Query("stuId") String stuId, | 229 | @Query("stuId") String stuId, |
| 230 | @Query("type") int type //0: 周报, 1:阶段总结 | 230 | @Query("type") int type //0: 周报, 1:阶段总结 |
| 231 | ); | 231 | ); |
| 232 | 232 | ||
| 233 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") | 233 | @GET("api/v1/homework/listHomeworkStatisticsDetailForStudent") |
| 234 | Single<ResponseResult<StDetail>> getHuyouDetail( | 234 | Single<ResponseResult<StDetail>> getHuyouDetail( |
| 235 | @Header("Authorization") String token, | 235 | @Header("Authorization") String token, |
| 236 | @Query("homeworkStatisticsId") String homeworkId | 236 | @Query("homeworkStatisticsId") String homeworkId |
| 237 | ); | 237 | ); |
| 238 | 238 | ||
| 239 | @GET("api/v1/demo/generalStatisticsHomework") | 239 | @GET("api/v1/demo/generalStatisticsHomework") |
| 240 | Single<ResponseResult<Object>> generalHuyou(); | 240 | Single<ResponseResult<Object>> generalHuyou(); |
| 241 | 241 | ||
| 242 | @POST("api/v1/homework/generalHomeworkStageStatistics") | 242 | @POST("api/v1/homework/generalHomeworkStageStatistics") |
| 243 | Single<ResponseResult<Boolean>> generalStageHuyou( | 243 | Single<ResponseResult<Boolean>> generalStageHuyou( |
| 244 | @Header("Authorization") String token, | 244 | @Header("Authorization") String token, |
| 245 | @Body Object body | 245 | @Body Object body |
| 246 | ); | 246 | ); |
| 247 | 247 | ||
| 248 | @GET("api/v1/homework/removeHomeworkStatistics") | 248 | @GET("api/v1/homework/removeHomeworkStatistics") |
| 249 | Single<ResponseResult<Boolean>> deleteHuyou( | 249 | Single<ResponseResult<Boolean>> deleteHuyou( |
| 250 | @Header("Authorization") String token, | 250 | @Header("Authorization") String token, |
| 251 | @Query("homeworkStatisticsId") String homeworkId | 251 | @Query("homeworkStatisticsId") String homeworkId |
| 252 | ); | 252 | ); |
| 253 | 253 | ||
| 254 | @GET("api/v1/login/smsCode") | 254 | @GET("api/v1/login/smsCode") |
| 255 | Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile); | 255 | Single<ResponseResult<String>> smsCode(@Query("mobile") String mobile); |
| 256 | 256 | ||
| 257 | @POST("api/v1/login/smsLogin") | 257 | @POST("api/v1/login/smsLogin") |
| 258 | Single<ResponseResult<User>> smsLogin(@Body Object body); | 258 | Single<ResponseResult<User>> smsLogin(@Body Object body); |
| 259 | 259 | ||
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | public static String getUserId() { | 262 | public static String getUserId() { |
| 263 | return (String) SharedPreferencesUtil.getData("userId", ""); | 263 | return (String) SharedPreferencesUtil.getData("userId", ""); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | public static String getHeader() { | 266 | public static String getHeader() { |
| 267 | return (String) SharedPreferencesUtil.getData("token", ""); | 267 | return (String) SharedPreferencesUtil.getData("token", ""); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | public static String getBaiduToken() { | 270 | public static String getBaiduToken() { |
| 271 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 271 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | public static Single<BaiduInput> inputImage(String filePath, String id) { | 274 | public static Single<BaiduInput> inputImage(String filePath, String id) { |
| 275 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 275 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 276 | String base64 = BitmapUtils.fileToBase64(filePath); | 276 | String base64 = BitmapUtils.fileToBase64(filePath); |
| 277 | File file = new File(filePath); | 277 | File file = new File(filePath); |
| 278 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | 278 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); |
| 279 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | 279 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) |
| 280 | .flatMap(token -> { | 280 | .flatMap(token -> { |
| 281 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | 281 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); |
| 282 | }); | 282 | }); |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | public static Single<ResponseResult> uploadImage(String path, String id) { | 285 | public static Single<ResponseResult> uploadImage(String path, String id) { |
| 286 | File file = new File(path); | 286 | File file = new File(path); |
| 287 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 287 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 288 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 288 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 289 | return service_url.uploadImage(getHeader(), part, id); | 289 | return service_url.uploadImage(getHeader(), part, id); |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | 292 | ||
| 293 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 293 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
| 294 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 294 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 297 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 298 | File file = new File(path); | 298 | File file = new File(path); |
| 299 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 299 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 300 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 300 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 301 | Map<String, Object> map = new HashMap<>(); | 301 | Map<String, Object> map = new HashMap<>(); |
| 302 | map.put("condition", param); | 302 | map.put("condition", param); |
| 303 | setSubscribe(service_url.addError(part, map), observer); | 303 | setSubscribe(service_url.addError(part, map), observer); |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | 306 | ||
| 307 | public static void cut(String base64, Observer<CutPicBean> observer) { | 307 | public static void cut(String base64, Observer<CutPicBean> observer) { |
| 308 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 308 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 309 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 309 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
| 310 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 310 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 313 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
| 314 | setSubscribe(service_url.editError(getHeader(), map), observer); | 314 | setSubscribe(service_url.editError(getHeader(), map), observer); |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 317 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
| 318 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 318 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 321 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
| 322 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 322 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | public static void getBaiduToken(Observer<JsonObject> observer) { | 325 | public static void getBaiduToken(Observer<JsonObject> observer) { |
| 326 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); | 326 | setSubscribe(service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey + "&client_secret=" + BuildConfig.SecretKey), observer); |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | public static Single<JsonObject> getBaiduTokenOcr() { | 329 | public static Single<JsonObject> getBaiduTokenOcr() { |
| 330 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); | 330 | return service_url.getBaiduToken("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + BuildConfig.APIKey1 + "&client_secret=" + BuildConfig.SecretKey1).firstOrError(); |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 333 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
| 334 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 334 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 335 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 335 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
| 336 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 336 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 339 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
| 340 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 340 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | public static void logout(Observer<ResponseBody> observer) { | 343 | public static void logout(Observer<ResponseBody> observer) { |
| 344 | setSubscribe(service_url.logout(), observer); | 344 | setSubscribe(service_url.logout(), observer); |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 347 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
| 348 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 348 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 351 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
| 352 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 352 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 355 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
| 356 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 356 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 357 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 357 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 358 | Map<String, Object> map = new HashMap<>(); | 358 | Map<String, Object> map = new HashMap<>(); |
| 359 | map.put("stuId", stuId); | 359 | map.put("stuId", stuId); |
| 360 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 360 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 363 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
| 364 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 364 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 365 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 365 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 366 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 366 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 369 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
| 370 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 370 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | 373 | ||
| 374 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 374 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
| 375 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 375 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 378 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
| 379 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 379 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 383 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
| 384 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 384 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | 387 | ||
| 388 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 388 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
| 389 | setSubscribe(service_url.login(body), observer); | 389 | setSubscribe(service_url.login(body), observer); |
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 392 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
| 393 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 393 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | 396 | ||
| 397 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 397 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
| 398 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 398 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
| 399 | } | 399 | } |
| 400 | 400 | ||
| 401 | public static void getChildrenList(Observer<ResponseBody> observer) { | 401 | public static void getChildrenList(Observer<ResponseBody> observer) { |
| 402 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 402 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
| 403 | } | 403 | } |
| 404 | 404 | ||
| 405 | 405 | ||
| 406 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 406 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
| 407 | setSubscribe(service_url.registerParent(body), observer); | 407 | setSubscribe(service_url.registerParent(body), observer); |
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | 410 | ||
| 411 | public static void listChildren(Observer<ResponseBody> observer) { | 411 | public static void listChildren(Observer<ResponseBody> observer) { |
| 412 | setSubscribe(service_url.listChildren(getHeader()), observer); | 412 | setSubscribe(service_url.listChildren(getHeader()), observer); |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | public static void listStudent(Observer<ResponseBody> observer) { | 415 | public static void listStudent(Observer<ResponseBody> observer) { |
| 416 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 416 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | public static Single<ResponseResult<List<Student>>> listStudent() { | 419 | public static Single<ResponseResult<List<Student>>> listStudent() { |
| 420 | return service_url.getStudentList2(getHeader(), getUserId()); | 420 | return service_url.getStudentList2(getHeader(), getUserId()); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | public static void listRecord(Observer<ResponseBody> observer) { | 423 | public static void listRecord(Observer<ResponseBody> observer) { |
| 424 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 424 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | 427 | ||
| 428 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 428 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
| 429 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 429 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 432 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
| 433 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 433 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 436 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
| 437 | setSubscribe(service_url.getError(getHeader(), map), observer); | 437 | setSubscribe(service_url.getError(getHeader(), map), observer); |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | 440 | ||
| 441 | public static RequestBody getMapRequestBody(Map map) { | 441 | public static RequestBody getMapRequestBody(Map map) { |
| 442 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 442 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | 445 | ||
| 446 | public static RequestBody getArrayRequestBody(List list) { | 446 | public static RequestBody getArrayRequestBody(List list) { |
| 447 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 447 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
| 448 | } | 448 | } |
| 449 | 449 | ||
| 450 | public static RequestBody getFileRequestBody(File file) { | 450 | public static RequestBody getFileRequestBody(File file) { |
| 451 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 451 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | public static RequestBody getFileRequestBody(byte[] bytes) { | 454 | public static RequestBody getFileRequestBody(byte[] bytes) { |
| 455 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 455 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | public static RequestBody getObjectRequestBody(Object obj) { | 458 | public static RequestBody getObjectRequestBody(Object obj) { |
| 459 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 459 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | public static RequestBody getStringRequestBody(String str) { | 462 | public static RequestBody getStringRequestBody(String str) { |
| 463 | return RequestBody.create(MediaType.parse("text/plain"), str); | 463 | return RequestBody.create(MediaType.parse("text/plain"), str); |
| 464 | } | 464 | } |
| 465 | 465 | ||
| 466 | 466 | ||
| 467 | /** | 467 | /** |
| 468 | * 插入观察者 | 468 | * 插入观察者 |
| 469 | * | 469 | * |
| 470 | * @param observable | 470 | * @param observable |
| 471 | * @param observer | 471 | * @param observer |
| 472 | * @param <T> | 472 | * @param <T> |
| 473 | */ | 473 | */ |
| 474 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 474 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
| 475 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 475 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
| 476 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 476 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
| 477 | .subscribe(observer); | 477 | .subscribe(observer); |
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | } | 480 | } |
| 481 | 481 |