Commit dbb1f52deb0bffb5d6b85123e68d0c1fff2e6f50
1 parent
8f79866a79
Exists in
master
录入作业
Showing
6 changed files
with
199 additions
and
7 deletions
Show diff stats
app/src/main/java/com/hjx/parent/ImageActivity.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.app.Dialog; | 4 | import android.app.Dialog; |
| 5 | import android.content.Intent; | 5 | import android.content.Intent; |
| 6 | import android.graphics.Bitmap; | 6 | import android.graphics.Bitmap; |
| 7 | import android.graphics.BitmapFactory; | 7 | import android.graphics.BitmapFactory; |
| 8 | import android.graphics.Rect; | 8 | import android.graphics.Rect; |
| 9 | import android.net.Uri; | 9 | import android.net.Uri; |
| 10 | import android.os.Bundle; | 10 | import android.os.Bundle; |
| 11 | import android.os.Handler; | 11 | import android.os.Handler; |
| 12 | import android.provider.MediaStore; | 12 | import android.provider.MediaStore; |
| 13 | import android.text.TextUtils; | 13 | import android.text.TextUtils; |
| 14 | import android.util.Log; | 14 | import android.util.Log; |
| 15 | import android.view.KeyEvent; | 15 | import android.view.KeyEvent; |
| 16 | import android.view.View; | 16 | import android.view.View; |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | import androidx.annotation.Nullable; | 19 | import androidx.annotation.Nullable; |
| 20 | import androidx.core.content.FileProvider; | 20 | import androidx.core.content.FileProvider; |
| 21 | import androidx.viewpager2.widget.ViewPager2; | 21 | import androidx.viewpager2.widget.ViewPager2; |
| 22 | 22 | ||
| 23 | import com.google.gson.Gson; | 23 | import com.google.gson.Gson; |
| 24 | import com.google.gson.JsonObject; | 24 | import com.google.gson.JsonObject; |
| 25 | import com.hjx.parent.adapter.ImageAdapter; | 25 | import com.hjx.parent.adapter.ImageAdapter; |
| 26 | import com.hjx.parent.databinding.ActivityImageBinding; | 26 | import com.hjx.parent.databinding.ActivityImageBinding; |
| 27 | import com.hjx.parent.dialog.AddHomeworkDialog; | 27 | import com.hjx.parent.dialog.AddHomeworkDialog; |
| 28 | import com.hjx.parent.dialog.ErrorInputDialog; | 28 | import com.hjx.parent.dialog.ErrorInputDialog; |
| 29 | import com.hjx.parent.dialog.TipDialog; | 29 | import com.hjx.parent.dialog.TipDialog; |
| 30 | import com.hjx.parent.rx.BaseRxActivity; | 30 | import com.hjx.parent.rx.BaseRxActivity; |
| 31 | import com.prws.common.bean.CutPicBean; | 31 | import com.prws.common.bean.CutPicBean; |
| 32 | import com.prws.common.bean.ImageBean; | 32 | import com.prws.common.bean.ImageBean; |
| 33 | import com.prws.common.bean.TopicBean; | 33 | import com.prws.common.bean.TopicBean; |
| 34 | import com.prws.common.net.NetWorks; | 34 | import com.prws.common.net.NetWorks; |
| 35 | import com.prws.common.utils.BitmapUtils; | 35 | import com.prws.common.utils.BitmapUtils; |
| 36 | import com.prws.common.utils.CommonUtil; | 36 | import com.prws.common.utils.CommonUtil; |
| 37 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; | 37 | import com.xiasuhuei321.loadingdialog.view.LoadingDialog; |
| 38 | 38 | ||
| 39 | import java.io.File; | 39 | import java.io.File; |
| 40 | import java.util.ArrayList; | 40 | import java.util.ArrayList; |
| 41 | import java.util.List; | 41 | import java.util.List; |
| 42 | 42 | ||
| 43 | import io.reactivex.Observer; | 43 | import io.reactivex.Observer; |
| 44 | import io.reactivex.disposables.Disposable; | 44 | import io.reactivex.disposables.Disposable; |
| 45 | import retrofit2.Call; | 45 | import retrofit2.Call; |
| 46 | import retrofit2.Callback; | 46 | import retrofit2.Callback; |
| 47 | import retrofit2.Response; | 47 | import retrofit2.Response; |
| 48 | 48 | ||
| 49 | public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implements View.OnClickListener { | 49 | public class ImageActivity extends BaseRxActivity<ActivityImageBinding> implements View.OnClickListener { |
| 50 | 50 | ||
| 51 | private List<String> images = new ArrayList<>(); | 51 | private List<String> images = new ArrayList<>(); |
| 52 | private ImageAdapter imageAdapter; | 52 | private ImageAdapter imageAdapter; |
| 53 | private List<ImageBean> list = new ArrayList<>(); | 53 | private List<ImageBean> list = new ArrayList<>(); |
| 54 | private String filePath; | 54 | private String filePath; |
| 55 | 55 | ||
| 56 | private int type = 0; | 56 | private int type = 0; |
| 57 | private AddHomeworkDialog addHomeworkDialog; | 57 | private AddHomeworkDialog addHomeworkDialog; |
| 58 | 58 | ||
| 59 | @Override | 59 | @Override |
| 60 | public void initView(Bundle savedInstanceState) { | 60 | public void initView(Bundle savedInstanceState) { |
| 61 | type = getIntent().getIntExtra("type", 0); | 61 | type = getIntent().getIntExtra("type", 0); |
| 62 | binding.tvSave.setText(type == 0 ? "保存错题" : "录入题目"); | 62 | binding.tvSave.setText(type == 0 ? "保存错题" : "录入题目"); |
| 63 | 63 | ||
| 64 | images = getIntent().getStringArrayListExtra("images"); | 64 | images = getIntent().getStringArrayListExtra("images"); |
| 65 | for (String s : images) { | 65 | for (String s : images) { |
| 66 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; | 66 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + System.currentTimeMillis() + CommonUtil.getStr() + ".jpg"; |
| 67 | ImageBean imageBean = new ImageBean(); | 67 | ImageBean imageBean = new ImageBean(); |
| 68 | Bitmap bitmap = BitmapUtils.getimage(s); | 68 | Bitmap bitmap = BitmapUtils.getimage(s); |
| 69 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 69 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 70 | imageBean.setPath(filepath); | 70 | imageBean.setPath(filepath); |
| 71 | list.add(imageBean); | 71 | list.add(imageBean); |
| 72 | } | 72 | } |
| 73 | imageAdapter = new ImageAdapter(this, list); | 73 | imageAdapter = new ImageAdapter(this, list); |
| 74 | binding.viewPager.setAdapter(imageAdapter); | 74 | binding.viewPager.setAdapter(imageAdapter); |
| 75 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { | 75 | binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { |
| 76 | @Override | 76 | @Override |
| 77 | public void onPageSelected(int position) { | 77 | public void onPageSelected(int position) { |
| 78 | if (list.get(position).getCuts() == null) { | 78 | if (list.get(position).getCuts() == null) { |
| 79 | // binding.ivPrevious.setEnabled(false); | 79 | // binding.ivPrevious.setEnabled(false); |
| 80 | // binding.ivNext.setEnabled(false); | 80 | // binding.ivNext.setEnabled(false); |
| 81 | clearText(); | 81 | clearText(); |
| 82 | } | 82 | } |
| 83 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 83 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 84 | if (position == 0) { | 84 | if (position == 0) { |
| 85 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); | 85 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous_gray); |
| 86 | // binding.ivPrevious.setEnabled(true); | 86 | // binding.ivPrevious.setEnabled(true); |
| 87 | } else { | 87 | } else { |
| 88 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); | 88 | binding.ivPrevious.setImageResource(R.mipmap.ic_previous); |
| 89 | // binding.ivPrevious.setEnabled(false); | 89 | // binding.ivPrevious.setEnabled(false); |
| 90 | } | 90 | } |
| 91 | if (position == list.size() - 1) { | 91 | if (position == list.size() - 1) { |
| 92 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); | 92 | binding.ivNext.setImageResource(R.mipmap.ic_next_gray); |
| 93 | // binding.ivNext.setEnabled(true); | 93 | // binding.ivNext.setEnabled(true); |
| 94 | } else { | 94 | } else { |
| 95 | binding.ivNext.setImageResource(R.mipmap.ic_next); | 95 | binding.ivNext.setImageResource(R.mipmap.ic_next); |
| 96 | // binding.ivNext.setEnabled(false); | 96 | // binding.ivNext.setEnabled(false); |
| 97 | } | 97 | } |
| 98 | super.onPageSelected(position); | 98 | super.onPageSelected(position); |
| 99 | } | 99 | } |
| 100 | }); | 100 | }); |
| 101 | binding.ivNext.setOnClickListener(this); | 101 | binding.ivNext.setOnClickListener(this); |
| 102 | binding.ivPrevious.setOnClickListener(this); | 102 | binding.ivPrevious.setOnClickListener(this); |
| 103 | binding.ivBack.setOnClickListener(this); | 103 | binding.ivBack.setOnClickListener(this); |
| 104 | binding.tvPhoto.setOnClickListener(this); | 104 | binding.tvPhoto.setOnClickListener(this); |
| 105 | binding.tvAdd.setOnClickListener(this); | 105 | binding.tvAdd.setOnClickListener(this); |
| 106 | binding.llEdit.setOnClickListener(this); | 106 | binding.llEdit.setOnClickListener(this); |
| 107 | binding.tvSave.setOnClickListener(this); | 107 | binding.tvSave.setOnClickListener(this); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | public void clearText() { | 110 | public void clearText() { |
| 111 | int index = binding.viewPager.getCurrentItem(); | 111 | int index = binding.viewPager.getCurrentItem(); |
| 112 | showLoadingDialog(getString(R.string.loading_text), new LoadingDialog.DismissListener() { | 112 | showLoadingDialog(getString(R.string.loading_text), new LoadingDialog.DismissListener() { |
| 113 | @Override | 113 | @Override |
| 114 | public void dimiss() { | 114 | public void dimiss() { |
| 115 | // binding.ivPrevious.setEnabled(index != 0); | 115 | // binding.ivPrevious.setEnabled(index != 0); |
| 116 | // binding.ivNext.setEnabled(index != list.size() - 1); | 116 | // binding.ivNext.setEnabled(index != list.size() - 1); |
| 117 | } | 117 | } |
| 118 | }); | 118 | }); |
| 119 | Log.i("clearText", list.get(index).getPath()); | 119 | Log.i("clearText", list.get(index).getPath()); |
| 120 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath()); | 120 | String base64 = BitmapUtils.imageToBase64(list.get(index).getPath()); |
| 121 | NetWorks.removeWriting(base64, new Observer<JsonObject>() { | 121 | NetWorks.removeWriting(base64, new Observer<JsonObject>() { |
| 122 | @Override | 122 | @Override |
| 123 | public void onSubscribe(Disposable d) { | 123 | public void onSubscribe(Disposable d) { |
| 124 | 124 | ||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | @Override | 127 | @Override |
| 128 | public void onNext(JsonObject jsonObject) { | 128 | public void onNext(JsonObject jsonObject) { |
| 129 | if (jsonObject != null && jsonObject.get("image_processed") != null) { | 129 | if (jsonObject != null && jsonObject.get("image_processed") != null) { |
| 130 | String image = jsonObject.get("image_processed").getAsString(); | 130 | String image = jsonObject.get("image_processed").getAsString(); |
| 131 | if (image != null) { | 131 | if (image != null) { |
| 132 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 132 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 133 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); | 133 | CommonUtil.saveBitmapToUri(BitmapUtils.stringToBitmap(image), filepath); |
| 134 | list.get(index).setPath(filepath); | 134 | list.get(index).setPath(filepath); |
| 135 | imageAdapter.notifyItemChanged(index); | 135 | imageAdapter.notifyItemChanged(index); |
| 136 | cut(filepath); | 136 | cut(filepath); |
| 137 | } else { | 137 | } else { |
| 138 | loadFail("去除字迹失败"); | 138 | loadFail("去除字迹失败"); |
| 139 | } | 139 | } |
| 140 | } else { | 140 | } else { |
| 141 | loadFail("去除字迹失败"); | 141 | loadFail("去除字迹失败"); |
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | @Override | 145 | @Override |
| 146 | public void onError(Throwable e) { | 146 | public void onError(Throwable e) { |
| 147 | loadFail("去除字迹失败"); | 147 | loadFail("去除字迹失败"); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | @Override | 150 | @Override |
| 151 | public void onComplete() { | 151 | public void onComplete() { |
| 152 | 152 | ||
| 153 | } | 153 | } |
| 154 | }); | 154 | }); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | public void cut(String path) { | 157 | public void cut(String path) { |
| 158 | String base64 = BitmapUtils.imageToBase64(path); | 158 | String base64 = BitmapUtils.imageToBase64(path); |
| 159 | Log.i("figLoaction", path); | 159 | Log.i("figLoaction", path); |
| 160 | NetWorks.cut(base64, new Observer<CutPicBean>() { | 160 | NetWorks.cut(base64, new Observer<CutPicBean>() { |
| 161 | @Override | 161 | @Override |
| 162 | public void onSubscribe(Disposable d) { | 162 | public void onSubscribe(Disposable d) { |
| 163 | 163 | ||
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | @Override | 166 | @Override |
| 167 | public void onNext(CutPicBean cutPicBean) { | 167 | public void onNext(CutPicBean cutPicBean) { |
| 168 | if (cutPicBean != null) { | 168 | if (cutPicBean != null) { |
| 169 | if (cutPicBean.getDirection() != 0) { | 169 | if (cutPicBean.getDirection() != 0) { |
| 170 | rotatingImage(cutPicBean); | 170 | rotatingImage(cutPicBean); |
| 171 | } else { | 171 | } else { |
| 172 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 172 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 173 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 173 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 174 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 174 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 175 | figLoactions.add(cutLocation.getFig_location()); | 175 | figLoactions.add(cutLocation.getFig_location()); |
| 176 | } | 176 | } |
| 177 | new Handler().postDelayed(new Runnable() { | 177 | new Handler().postDelayed(new Runnable() { |
| 178 | @Override | 178 | @Override |
| 179 | public void run() { | 179 | public void run() { |
| 180 | getRects(figLoactions); | 180 | getRects(figLoactions); |
| 181 | } | 181 | } |
| 182 | }, 1000); | 182 | }, 1000); |
| 183 | } else { | 183 | } else { |
| 184 | cancelLoadingDialog(); | 184 | cancelLoadingDialog(); |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| 187 | } else { | 187 | } else { |
| 188 | loadFail("自动切题失败"); | 188 | loadFail("自动切题失败"); |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | @Override | 192 | @Override |
| 193 | public void onError(Throwable e) { | 193 | public void onError(Throwable e) { |
| 194 | loadFail("自动切题失败"); | 194 | loadFail("自动切题失败"); |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | @Override | 197 | @Override |
| 198 | public void onComplete() { | 198 | public void onComplete() { |
| 199 | 199 | ||
| 200 | } | 200 | } |
| 201 | }); | 201 | }); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { | 204 | private void getRects(List<CutPicBean.FigLoaction> figLoactions) { |
| 205 | Log.i("figLoaction", new Gson().toJson(figLoactions)); | 205 | Log.i("figLoaction", new Gson().toJson(figLoactions)); |
| 206 | int index = binding.viewPager.getCurrentItem(); | 206 | int index = binding.viewPager.getCurrentItem(); |
| 207 | List<ImageBean.Cut> cuts = new ArrayList<>(); | 207 | List<ImageBean.Cut> cuts = new ArrayList<>(); |
| 208 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { | 208 | for (CutPicBean.FigLoaction figLoaction : figLoactions) { |
| 209 | ImageBean.Cut cut = new ImageBean.Cut(); | 209 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 210 | cut.setRect(figLoaction); | 210 | cut.setRect(figLoaction); |
| 211 | cut.setSelect(false); | 211 | cut.setSelect(false); |
| 212 | cuts.add(cut); | 212 | cuts.add(cut); |
| 213 | } | 213 | } |
| 214 | list.get(index).setCuts(cuts); | 214 | list.get(index).setCuts(cuts); |
| 215 | imageAdapter.notifyItemChanged(index); | 215 | imageAdapter.notifyItemChanged(index); |
| 216 | cancelLoadingDialog(); | 216 | cancelLoadingDialog(); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | private void rotatingImage(CutPicBean cutPicBean) { | 219 | private void rotatingImage(CutPicBean cutPicBean) { |
| 220 | int index = binding.viewPager.getCurrentItem(); | 220 | int index = binding.viewPager.getCurrentItem(); |
| 221 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); | 221 | Bitmap bitmap = BitmapFactory.decodeFile(list.get(index).getPath()); |
| 222 | int angle = 0; | 222 | int angle = 0; |
| 223 | switch (cutPicBean.getDirection()) { | 223 | switch (cutPicBean.getDirection()) { |
| 224 | case 1: | 224 | case 1: |
| 225 | angle = 90; | 225 | angle = 90; |
| 226 | break; | 226 | break; |
| 227 | case 2: | 227 | case 2: |
| 228 | angle = 180; | 228 | angle = 180; |
| 229 | break; | 229 | break; |
| 230 | case 3: | 230 | case 3: |
| 231 | angle = 270; | 231 | angle = 270; |
| 232 | break; | 232 | break; |
| 233 | } | 233 | } |
| 234 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { | 234 | if (cutPicBean.getQus_figure() != null && cutPicBean.getQus_figure().size() > 0) { |
| 235 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); | 235 | List<CutPicBean.FigLoaction> figLoactions = new ArrayList<>(); |
| 236 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { | 236 | for (CutPicBean.CutLocation cutLocation : cutPicBean.getQus_figure()) { |
| 237 | figLoactions.add(cutLocation.getFig_location()); | 237 | figLoactions.add(cutLocation.getFig_location()); |
| 238 | } | 238 | } |
| 239 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); | 239 | figLoactions = CommonUtil.rotaingLocation(angle, figLoactions, bitmap.getWidth(), bitmap.getHeight()); |
| 240 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); | 240 | bitmap = CommonUtil.rotaingImageView(angle, bitmap); |
| 241 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 241 | String filepath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 242 | CommonUtil.saveBitmapToUri(bitmap, filepath); | 242 | CommonUtil.saveBitmapToUri(bitmap, filepath); |
| 243 | list.get(index).setPath(filepath); | 243 | list.get(index).setPath(filepath); |
| 244 | imageAdapter.notifyItemChanged(index); | 244 | imageAdapter.notifyItemChanged(index); |
| 245 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; | 245 | List<CutPicBean.FigLoaction> finalFigLoactions = figLoactions; |
| 246 | new Handler().postDelayed(new Runnable() { | 246 | new Handler().postDelayed(new Runnable() { |
| 247 | @Override | 247 | @Override |
| 248 | public void run() { | 248 | public void run() { |
| 249 | getRects(finalFigLoactions); | 249 | getRects(finalFigLoactions); |
| 250 | } | 250 | } |
| 251 | }, 500); | 251 | }, 500); |
| 252 | } else { | 252 | } else { |
| 253 | cancelLoadingDialog(); | 253 | cancelLoadingDialog(); |
| 254 | } | 254 | } |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | @Override | 257 | @Override |
| 258 | protected ActivityImageBinding getViewBinding() { | 258 | protected ActivityImageBinding getViewBinding() { |
| 259 | return ActivityImageBinding.inflate(getLayoutInflater()); | 259 | return ActivityImageBinding.inflate(getLayoutInflater()); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | @SuppressLint("SetTextI18n") | 262 | @SuppressLint("SetTextI18n") |
| 263 | public void refreshNum() { | 263 | public void refreshNum() { |
| 264 | int num = 0; | 264 | int num = 0; |
| 265 | for (ImageBean imageBean : list) { | 265 | for (ImageBean imageBean : list) { |
| 266 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 266 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 267 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 267 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 268 | if (cut.isSelect()) { | 268 | if (cut.isSelect()) { |
| 269 | num++; | 269 | num++; |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | } | 272 | } |
| 273 | } | 273 | } |
| 274 | String btnText = type == 0 ? "保存错题" : "录入题目"; | 274 | String btnText = type == 0 ? "保存错题" : "录入题目"; |
| 275 | if (num > 0) { | 275 | if (num > 0) { |
| 276 | binding.tvSave.setEnabled(true); | 276 | binding.tvSave.setEnabled(true); |
| 277 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); | 277 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_5); |
| 278 | binding.tvSave.setText(btnText + "(" + num + ")"); | 278 | binding.tvSave.setText(btnText + "(" + num + ")"); |
| 279 | } else { | 279 | } else { |
| 280 | binding.tvSave.setEnabled(false); | 280 | binding.tvSave.setEnabled(false); |
| 281 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); | 281 | binding.tvSave.setBackgroundResource(R.drawable.bg_soild_blue_light_5); |
| 282 | binding.tvSave.setText(btnText); | 282 | binding.tvSave.setText(btnText); |
| 283 | } | 283 | } |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | @Override | 286 | @Override |
| 287 | public void onClick(View v) { | 287 | public void onClick(View v) { |
| 288 | switch (v.getId()) { | 288 | switch (v.getId()) { |
| 289 | case R.id.iv_back: | 289 | case R.id.iv_back: |
| 290 | back(); | 290 | back(); |
| 291 | break; | 291 | break; |
| 292 | case R.id.iv_next: | 292 | case R.id.iv_next: |
| 293 | if (binding.viewPager.getCurrentItem() + 1 < list.size()) { | 293 | if (binding.viewPager.getCurrentItem() + 1 < list.size()) { |
| 294 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); | 294 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() + 1); |
| 295 | } | 295 | } |
| 296 | break; | 296 | break; |
| 297 | case R.id.iv_previous: | 297 | case R.id.iv_previous: |
| 298 | if (binding.viewPager.getCurrentItem() != 0) { | 298 | if (binding.viewPager.getCurrentItem() != 0) { |
| 299 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); | 299 | binding.viewPager.setCurrentItem(binding.viewPager.getCurrentItem() - 1); |
| 300 | } | 300 | } |
| 301 | break; | 301 | break; |
| 302 | case R.id.ll_edit: | 302 | case R.id.ll_edit: |
| 303 | Intent intent = new Intent(context, ImageEditActivity.class); | 303 | Intent intent = new Intent(context, ImageEditActivity.class); |
| 304 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 304 | intent.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 305 | startActivityForResult(intent, 1001); | 305 | startActivityForResult(intent, 1001); |
| 306 | break; | 306 | break; |
| 307 | case R.id.tv_photo: | 307 | case R.id.tv_photo: |
| 308 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | 308 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 309 | //确保有相机来处理Intent | 309 | //确保有相机来处理Intent |
| 310 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 310 | filePath = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 311 | File photoFile = new File(filePath); | 311 | File photoFile = new File(filePath); |
| 312 | if (photoFile != null) { | 312 | if (photoFile != null) { |
| 313 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri | 313 | //适配Android 7.0文件权限,通过FileProvider创建一个content类型的Uri |
| 314 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); | 314 | Uri photoUri = FileProvider.getUriForFile(activity, "com.hjx.parent.fileprovider", photoFile); |
| 315 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); | 315 | takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 316 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); | 316 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); |
| 317 | activity.startActivityForResult(takePictureIntent, 1002); | 317 | activity.startActivityForResult(takePictureIntent, 1002); |
| 318 | } | 318 | } |
| 319 | break; | 319 | break; |
| 320 | case R.id.tv_add: | 320 | case R.id.tv_add: |
| 321 | Intent intent1 = new Intent(context, ImageSelectActivity.class); | 321 | Intent intent1 = new Intent(context, ImageSelectActivity.class); |
| 322 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); | 322 | intent1.putExtra("path", list.get(binding.viewPager.getCurrentItem()).getPath()); |
| 323 | startActivityForResult(intent1, 1001); | 323 | startActivityForResult(intent1, 1001); |
| 324 | break; | 324 | break; |
| 325 | case R.id.tv_save: | 325 | case R.id.tv_save: |
| 326 | List<TopicBean> topicBeans = new ArrayList<>(); | 326 | List<TopicBean> topicBeans = new ArrayList<>(); |
| 327 | for (ImageBean imageBean : list) { | 327 | for (ImageBean imageBean : list) { |
| 328 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { | 328 | if (imageBean.getCuts() != null && imageBean.getCuts().size() > 0) { |
| 329 | for (ImageBean.Cut cut : imageBean.getCuts()) { | 329 | for (ImageBean.Cut cut : imageBean.getCuts()) { |
| 330 | if (cut.isSelect()) { | 330 | if (cut.isSelect()) { |
| 331 | TopicBean bean = new TopicBean(); | 331 | TopicBean bean = new TopicBean(); |
| 332 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 332 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 333 | BitmapUtils.saveBitmap(cut.getBitmap(), path); | 333 | BitmapUtils.saveBitmap(cut.getBitmap(), path); |
| 334 | bean.setPath(path); | 334 | bean.setPath(path); |
| 335 | topicBeans.add(bean); | 335 | topicBeans.add(bean); |
| 336 | } | 336 | } |
| 337 | } | 337 | } |
| 338 | } | 338 | } |
| 339 | } | 339 | } |
| 340 | save(topicBeans); | 340 | save(topicBeans); |
| 341 | break; | 341 | break; |
| 342 | } | 342 | } |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | private void save(List<TopicBean> topicBeans) { | 345 | private void save(List<TopicBean> topicBeans) { |
| 346 | if (type == 0) { | 346 | if (type == 0) { |
| 347 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); | 347 | ErrorInputDialog dialog = new ErrorInputDialog(this, topicBeans); |
| 348 | dialog.show(); | 348 | dialog.show(); |
| 349 | } else { | 349 | } else { |
| 350 | List<String> paths = new ArrayList<>(); | ||
| 351 | for (TopicBean it: topicBeans) { | ||
| 352 | paths.add(it.getPath()); | ||
| 353 | } | ||
| 350 | if (addHomeworkDialog == null) { | 354 | if (addHomeworkDialog == null) { |
| 351 | addHomeworkDialog = new AddHomeworkDialog(this); | 355 | addHomeworkDialog = new AddHomeworkDialog(this); |
| 352 | } | 356 | } |
| 353 | addHomeworkDialog.show(); | 357 | addHomeworkDialog.show(paths, () -> { |
| 358 | // TODO | ||
| 359 | }); | ||
| 354 | } | 360 | } |
| 355 | } | 361 | } |
| 356 | 362 | ||
| 357 | @Override | 363 | @Override |
| 358 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | 364 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 359 | super.onActivityResult(requestCode, resultCode, data); | 365 | super.onActivityResult(requestCode, resultCode, data); |
| 360 | if (requestCode == 1001) { | 366 | if (requestCode == 1001) { |
| 361 | if (resultCode == 1002) { | 367 | if (resultCode == 1002) { |
| 362 | if (list.size() > 1) { | 368 | if (list.size() > 1) { |
| 363 | list.remove(binding.viewPager.getCurrentItem()); | 369 | list.remove(binding.viewPager.getCurrentItem()); |
| 364 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); | 370 | imageAdapter.notifyItemRemoved(binding.viewPager.getCurrentItem()); |
| 365 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); | 371 | binding.tvTitle.setText((binding.viewPager.getCurrentItem() + 1) + "/" + list.size()); |
| 366 | refreshNum(); | 372 | refreshNum(); |
| 367 | } else { | 373 | } else { |
| 368 | finish(); | 374 | finish(); |
| 369 | } | 375 | } |
| 370 | } else if (resultCode == 1003) { | 376 | } else if (resultCode == 1003) { |
| 371 | int position = binding.viewPager.getCurrentItem(); | 377 | int position = binding.viewPager.getCurrentItem(); |
| 372 | list.remove(position); | 378 | list.remove(position); |
| 373 | String path = data.getStringExtra("path"); | 379 | String path = data.getStringExtra("path"); |
| 374 | ImageBean imageBean = new ImageBean(); | 380 | ImageBean imageBean = new ImageBean(); |
| 375 | imageBean.setPath(path); | 381 | imageBean.setPath(path); |
| 376 | list.add(position, imageBean); | 382 | list.add(position, imageBean); |
| 377 | imageAdapter.notifyItemChanged(position); | 383 | imageAdapter.notifyItemChanged(position); |
| 378 | clearText(); | 384 | clearText(); |
| 379 | refreshNum(); | 385 | refreshNum(); |
| 380 | } else if (resultCode == 1004) { | 386 | } else if (resultCode == 1004) { |
| 381 | Rect rect = data.getParcelableExtra("cut"); | 387 | Rect rect = data.getParcelableExtra("cut"); |
| 382 | if (rect != null) { | 388 | if (rect != null) { |
| 383 | int position = binding.viewPager.getCurrentItem(); | 389 | int position = binding.viewPager.getCurrentItem(); |
| 384 | ImageBean.Cut cut = new ImageBean.Cut(); | 390 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 385 | cut.setRect1(rect); | 391 | cut.setRect1(rect); |
| 386 | cut.setSelect(false); | 392 | cut.setSelect(false); |
| 387 | if (list.get(position).getCuts() != null) { | 393 | if (list.get(position).getCuts() != null) { |
| 388 | list.get(position).getCuts().add(cut); | 394 | list.get(position).getCuts().add(cut); |
| 389 | } else { | 395 | } else { |
| 390 | List<ImageBean.Cut> cuts =new ArrayList<>(); | 396 | List<ImageBean.Cut> cuts =new ArrayList<>(); |
| 391 | cuts.add(cut); | 397 | cuts.add(cut); |
| 392 | list.get(position).setCuts(cuts); | 398 | list.get(position).setCuts(cuts); |
| 393 | } | 399 | } |
| 394 | imageAdapter.notifyItemChanged(position); | 400 | imageAdapter.notifyItemChanged(position); |
| 395 | refreshNum(); | 401 | refreshNum(); |
| 396 | } | 402 | } |
| 397 | } else if (resultCode == 1005) { | 403 | } else if (resultCode == 1005) { |
| 398 | int i = data.getIntExtra("position", 0); | 404 | int i = data.getIntExtra("position", 0); |
| 399 | int position = binding.viewPager.getCurrentItem(); | 405 | int position = binding.viewPager.getCurrentItem(); |
| 400 | Rect rect = data.getParcelableExtra("cut"); | 406 | Rect rect = data.getParcelableExtra("cut"); |
| 401 | if (rect != null) { | 407 | if (rect != null) { |
| 402 | ImageBean.Cut cut = new ImageBean.Cut(); | 408 | ImageBean.Cut cut = new ImageBean.Cut(); |
| 403 | cut.setRect1(rect); | 409 | cut.setRect1(rect); |
| 404 | cut.setSelect(false); | 410 | cut.setSelect(false); |
| 405 | list.get(position).getCuts().remove(i); | 411 | list.get(position).getCuts().remove(i); |
| 406 | list.get(position).getCuts().add(i, cut); | 412 | list.get(position).getCuts().add(i, cut); |
| 407 | imageAdapter.notifyItemChanged(position); | 413 | imageAdapter.notifyItemChanged(position); |
| 408 | refreshNum(); | 414 | refreshNum(); |
| 409 | } else { | 415 | } else { |
| 410 | list.get(position).getCuts().remove(i); | 416 | list.get(position).getCuts().remove(i); |
| 411 | imageAdapter.notifyItemChanged(position); | 417 | imageAdapter.notifyItemChanged(position); |
| 412 | refreshNum(); | 418 | refreshNum(); |
| 413 | } | 419 | } |
| 414 | } | 420 | } |
| 415 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { | 421 | } else if (requestCode == 1002 && resultCode == RESULT_OK && !TextUtils.isEmpty(filePath)) { |
| 416 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); | 422 | Bitmap b = BitmapUtils.compress(BitmapFactory.decodeFile(filePath)); |
| 417 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; | 423 | String path = context.getExternalFilesDir("images").getPath() + "/" + String.valueOf(System.currentTimeMillis()) + CommonUtil.getStr() + ".jpg"; |
| 418 | CommonUtil.saveBitmapToUri(b, path); | 424 | CommonUtil.saveBitmapToUri(b, path); |
| 419 | int position = binding.viewPager.getCurrentItem(); | 425 | int position = binding.viewPager.getCurrentItem(); |
| 420 | list.remove(position); | 426 | list.remove(position); |
| 421 | ImageBean imageBean = new ImageBean(); | 427 | ImageBean imageBean = new ImageBean(); |
| 422 | imageBean.setPath(path); | 428 | imageBean.setPath(path); |
| 423 | list.add(position, imageBean); | 429 | list.add(position, imageBean); |
| 424 | imageAdapter.notifyItemChanged(position); | 430 | imageAdapter.notifyItemChanged(position); |
| 425 | clearText(); | 431 | clearText(); |
| 426 | refreshNum(); | 432 | refreshNum(); |
| 427 | } | 433 | } |
| 428 | } | 434 | } |
| 429 | 435 | ||
| 430 | private void back() { | 436 | private void back() { |
| 431 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { | 437 | showTipDialog("温馨提示", "是否确认退出?", "取消", "确定", new TipDialog.TipDialogInterface() { |
| 432 | @Override | 438 | @Override |
| 433 | public void onConfirm(Dialog dialog) { | 439 | public void onConfirm(Dialog dialog) { |
| 434 | dialog.dismiss(); | 440 | dialog.dismiss(); |
| 435 | finish(); | 441 | finish(); |
| 436 | } | 442 | } |
| 437 | 443 | ||
| 438 | @Override | 444 | @Override |
| 439 | public void onCancel(Dialog dialog) { | 445 | public void onCancel(Dialog dialog) { |
| 440 | dialog.dismiss(); | 446 | dialog.dismiss(); |
| 441 | } | 447 | } |
| 442 | }); | 448 | }); |
| 443 | } | 449 | } |
| 444 | 450 | ||
| 445 | @Override | 451 | @Override |
| 446 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 452 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 447 | if (keyCode == KeyEvent.KEYCODE_BACK) { | 453 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 448 | back(); | 454 | back(); |
| 449 | return true; | 455 | return true; |
| 450 | } | 456 | } |
| 451 | return super.onKeyDown(keyCode, event); | 457 | return super.onKeyDown(keyCode, event); |
| 452 | } | 458 | } |
| 453 | } | 459 | } |
| 454 | 460 |
app/src/main/java/com/hjx/parent/dialog/AddHomeworkDialog.java
| 1 | package com.hjx.parent.dialog; | 1 | package com.hjx.parent.dialog; |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Context; | 4 | import android.content.Context; |
| 5 | import android.util.Pair; | ||
| 5 | import android.view.View; | 6 | import android.view.View; |
| 6 | import android.widget.AdapterView; | 7 | import android.widget.AdapterView; |
| 7 | import android.widget.ArrayAdapter; | 8 | import android.widget.ArrayAdapter; |
| 9 | import android.widget.Toast; | ||
| 8 | 10 | ||
| 9 | import androidx.annotation.NonNull; | 11 | import androidx.annotation.NonNull; |
| 10 | 12 | ||
| 11 | import com.bigkoo.pickerview.builder.TimePickerBuilder; | 13 | import com.bigkoo.pickerview.builder.TimePickerBuilder; |
| 12 | import com.bigkoo.pickerview.listener.OnTimeSelectListener; | ||
| 13 | import com.bigkoo.pickerview.view.TimePickerView; | ||
| 14 | import com.google.gson.Gson; | 14 | import com.google.gson.Gson; |
| 15 | import com.hjx.parent.R; | 15 | import com.hjx.parent.R; |
| 16 | import com.hjx.parent.bean.StudentBean; | 16 | import com.hjx.parent.bean.StudentBean; |
| 17 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; | 17 | import com.hjx.parent.databinding.DialogAddHomeworkBinding; |
| 18 | import com.hjx.parent.rx.ILifecycleActivity; | 18 | import com.hjx.parent.function.Function0; |
| 19 | import com.hjx.parent.rx.BaseRxActivity; | ||
| 19 | import com.prws.common.bean.GradeAndSubject; | 20 | import com.prws.common.bean.GradeAndSubject; |
| 20 | import com.prws.common.bean.ResponseResult; | 21 | import com.prws.common.bean.ResponseResult; |
| 21 | import com.prws.common.bean.Student; | 22 | import com.prws.common.bean.Student; |
| 22 | import com.prws.common.bean.Subject; | 23 | import com.prws.common.bean.Subject; |
| 24 | import com.prws.common.bean.baidu.BaiduInput; | ||
| 23 | import com.prws.common.net.NetWorks; | 25 | import com.prws.common.net.NetWorks; |
| 24 | import com.prws.common.utils.SharedPreferencesUtil; | 26 | import com.prws.common.utils.SharedPreferencesUtil; |
| 25 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; | 27 | import com.trello.rxlifecycle2.android.RxLifecycleAndroid; |
| 26 | 28 | ||
| 29 | import java.io.File; | ||
| 27 | import java.text.SimpleDateFormat; | 30 | import java.text.SimpleDateFormat; |
| 28 | import java.util.ArrayList; | 31 | import java.util.ArrayList; |
| 29 | import java.util.Date; | 32 | import java.util.Date; |
| 33 | import java.util.HashMap; | ||
| 30 | import java.util.List; | 34 | import java.util.List; |
| 31 | import java.util.Locale; | 35 | import java.util.Locale; |
| 36 | import java.util.Map; | ||
| 32 | 37 | ||
| 38 | import io.reactivex.Observable; | ||
| 33 | import io.reactivex.android.schedulers.AndroidSchedulers; | 39 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 34 | import io.reactivex.schedulers.Schedulers; | 40 | import io.reactivex.schedulers.Schedulers; |
| 35 | 41 | ||
| 36 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ | 42 | public class AddHomeworkDialog extends BaseDialog<DialogAddHomeworkBinding>{ |
| 37 | private final ILifecycleActivity activity; | 43 | private final BaseRxActivity<?> activity; |
| 44 | |||
| 45 | private Function0 callback; | ||
| 38 | 46 | ||
| 39 | String stuId; | 47 | String stuId; |
| 40 | 48 | ||
| 41 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); | 49 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA); |
| 42 | List<Student> studentList; | 50 | List<Student> studentList; |
| 43 | List<GradeAndSubject> gradeAndSubjectList; | 51 | List<GradeAndSubject> gradeAndSubjectList; |
| 44 | 52 | ||
| 53 | List<String> images; | ||
| 54 | |||
| 45 | Student student; | 55 | Student student; |
| 46 | String grade; | 56 | String grade; |
| 47 | String term; | 57 | String term; |
| 48 | String subject; | 58 | String subject; |
| 49 | Date uploadTime = new Date(); | 59 | Date uploadTime = new Date(); |
| 50 | 60 | ||
| 51 | public AddHomeworkDialog(ILifecycleActivity context) { | 61 | public AddHomeworkDialog(BaseRxActivity<?> context) { |
| 52 | super((Context) context); | 62 | super((Context) context); |
| 53 | activity = context; | 63 | activity = context; |
| 54 | } | 64 | } |
| 55 | 65 | ||
| 66 | public void show(List<String> paths, Function0 callback) { | ||
| 67 | images = paths; | ||
| 68 | this.callback = callback; | ||
| 69 | super.show(); | ||
| 70 | } | ||
| 71 | |||
| 56 | @SuppressLint("SetTextI18n") | 72 | @SuppressLint("SetTextI18n") |
| 57 | @Override | 73 | @Override |
| 58 | public void initView() { | 74 | public void initView() { |
| 59 | binding.btnClose.setOnClickListener(v -> dismiss()); | 75 | binding.btnClose.setOnClickListener(v -> dismiss()); |
| 60 | stuId = getCurrentStuId(); | 76 | stuId = getCurrentStuId(); |
| 61 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 77 | binding.spStudent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 62 | @Override | 78 | @Override |
| 63 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 79 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 64 | student = studentList.get(position); | 80 | student = studentList.get(position); |
| 65 | if (gradeAndSubjectList == null) return; | 81 | if (gradeAndSubjectList == null) return; |
| 66 | int p = 0; | 82 | int p = 0; |
| 67 | for (GradeAndSubject it: gradeAndSubjectList) { | 83 | for (GradeAndSubject it: gradeAndSubjectList) { |
| 68 | if (it.getGrade().getGrade().equals(student.grade)) { | 84 | if (it.getGrade().getGrade().equals(student.grade)) { |
| 69 | p = gradeAndSubjectList.indexOf(it); | 85 | p = gradeAndSubjectList.indexOf(it); |
| 70 | break; | 86 | break; |
| 71 | } | 87 | } |
| 72 | } | 88 | } |
| 73 | binding.spGrade.setSelection(p); | 89 | binding.spGrade.setSelection(p); |
| 74 | } | 90 | } |
| 75 | 91 | ||
| 76 | @Override | 92 | @Override |
| 77 | public void onNothingSelected(AdapterView<?> parent) { | 93 | public void onNothingSelected(AdapterView<?> parent) { |
| 78 | } | 94 | } |
| 79 | }); | 95 | }); |
| 80 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 96 | binding.spTerm.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 81 | @Override | 97 | @Override |
| 82 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 98 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 83 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; | 99 | term = getContext().getResources().getStringArray(R.array.grade_array)[position]; |
| 84 | } | 100 | } |
| 85 | @Override | 101 | @Override |
| 86 | public void onNothingSelected(AdapterView<?> parent) { | 102 | public void onNothingSelected(AdapterView<?> parent) { |
| 87 | } | 103 | } |
| 88 | }); | 104 | }); |
| 89 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 105 | binding.spGrade.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 90 | @Override | 106 | @Override |
| 91 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 107 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 92 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); | 108 | grade = gradeAndSubjectList.get(position).getGrade().getGrade(); |
| 93 | refreshSubjects(position); | 109 | refreshSubjects(position); |
| 94 | } | 110 | } |
| 95 | 111 | ||
| 96 | @Override | 112 | @Override |
| 97 | public void onNothingSelected(AdapterView<?> parent) { | 113 | public void onNothingSelected(AdapterView<?> parent) { |
| 98 | } | 114 | } |
| 99 | }); | 115 | }); |
| 100 | 116 | ||
| 101 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 117 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
| 102 | binding.tvDate.setOnClickListener(v -> { | 118 | binding.tvDate.setOnClickListener(v -> { |
| 103 | new TimePickerBuilder(getContext(), (date, v1) -> { | 119 | new TimePickerBuilder(getContext(), (date, v1) -> { |
| 104 | uploadTime = date; | 120 | uploadTime = date; |
| 105 | binding.tvDate.setText(dateFormat.format(uploadTime)); | 121 | binding.tvDate.setText(dateFormat.format(uploadTime)); |
| 106 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 122 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
| 107 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); | 123 | }).setType(new boolean[]{true, true, true, false, false, false}).isDialog(true).build().show(); |
| 108 | }); | 124 | }); |
| 109 | 125 | ||
| 126 | binding.btnConfirm.setOnClickListener(v -> { | ||
| 127 | String name = binding.etName.getText().toString().trim(); | ||
| 128 | if (name.isEmpty()) { | ||
| 129 | Toast.makeText(getContext(), "请输入作业名称", Toast.LENGTH_SHORT).show(); | ||
| 130 | return; | ||
| 131 | } | ||
| 132 | uploadImage(name); | ||
| 133 | }); | ||
| 134 | |||
| 110 | getGrade(); | 135 | getGrade(); |
| 111 | } | 136 | } |
| 112 | 137 | ||
| 113 | private String getCurrentStuId() { | 138 | private String getCurrentStuId() { |
| 114 | String student = (String) SharedPreferencesUtil.getData("student", ""); | 139 | String student = (String) SharedPreferencesUtil.getData("student", ""); |
| 115 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); | 140 | StudentBean studentBean = new Gson().fromJson(student, StudentBean.class); |
| 116 | return studentBean.getStuId(); | 141 | return studentBean.getStuId(); |
| 117 | } | 142 | } |
| 118 | 143 | ||
| 119 | @SuppressLint("CheckResult") | 144 | @SuppressLint("CheckResult") |
| 120 | private void getStudents() { | 145 | private void getStudents() { |
| 121 | NetWorks.listStudent() | 146 | NetWorks.listStudent() |
| 122 | .subscribeOn(Schedulers.io()) | 147 | .subscribeOn(Schedulers.io()) |
| 123 | .observeOn(AndroidSchedulers.mainThread()) | 148 | .observeOn(AndroidSchedulers.mainThread()) |
| 124 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 149 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
| 125 | .map(ResponseResult::getData) | 150 | .map(ResponseResult::getData) |
| 126 | .subscribe((data, th) -> { | 151 | .subscribe((data, th) -> { |
| 127 | if (th != null) th.printStackTrace(); | 152 | if (th != null) th.printStackTrace(); |
| 128 | if (data != null && data.size() > 0) { | 153 | if (data != null && data.size() > 0) { |
| 129 | studentList = data; | 154 | studentList = data; |
| 130 | int position = 0; | 155 | int position = 0; |
| 131 | for (int i = 0; i < data.size(); i++) { | 156 | for (int i = 0; i < data.size(); i++) { |
| 132 | if (data.get(i).stuId.equals(stuId)) { | 157 | if (data.get(i).stuId.equals(stuId)) { |
| 133 | position = i; | 158 | position = i; |
| 134 | break; | 159 | break; |
| 135 | } | 160 | } |
| 136 | } | 161 | } |
| 137 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); | 162 | binding.spStudent.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, data)); |
| 138 | binding.spStudent.setSelection(position); | 163 | binding.spStudent.setSelection(position); |
| 139 | } | 164 | } |
| 140 | }); | 165 | }); |
| 141 | } | 166 | } |
| 142 | 167 | ||
| 143 | @SuppressLint("CheckResult") | 168 | @SuppressLint("CheckResult") |
| 144 | private void getGrade() { | 169 | private void getGrade() { |
| 145 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) | 170 | NetWorks.service_url.listGradeAndSubject(NetWorks.getHeader()) |
| 146 | .subscribeOn(Schedulers.io()) | 171 | .subscribeOn(Schedulers.io()) |
| 147 | .observeOn(AndroidSchedulers.mainThread()) | 172 | .observeOn(AndroidSchedulers.mainThread()) |
| 148 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | 173 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) |
| 149 | .map(ResponseResult::getData) | 174 | .map(ResponseResult::getData) |
| 150 | .firstOrError() | 175 | .firstOrError() |
| 151 | .subscribe((data, th) -> { | 176 | .subscribe((data, th) -> { |
| 152 | if (th != null) th.printStackTrace(); | 177 | if (th != null) th.printStackTrace(); |
| 153 | if (data != null && data.size() > 0) { | 178 | if (data != null && data.size() > 0) { |
| 154 | gradeAndSubjectList = data; | 179 | gradeAndSubjectList = data; |
| 155 | List<String> grades = new ArrayList<>(); | 180 | List<String> grades = new ArrayList<>(); |
| 156 | for (GradeAndSubject it: data) { | 181 | for (GradeAndSubject it: data) { |
| 157 | grades.add(it.getGrade().getGrade()); | 182 | grades.add(it.getGrade().getGrade()); |
| 158 | } | 183 | } |
| 159 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); | 184 | binding.spGrade.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, grades)); |
| 160 | } | 185 | } |
| 161 | getStudents(); | 186 | getStudents(); |
| 162 | }); | 187 | }); |
| 163 | } | 188 | } |
| 164 | 189 | ||
| 165 | private void refreshSubjects(int gradePosition) { | 190 | private void refreshSubjects(int gradePosition) { |
| 166 | if (gradeAndSubjectList == null) return; | 191 | if (gradeAndSubjectList == null) return; |
| 167 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); | 192 | List<Subject> subjectList = gradeAndSubjectList.get(gradePosition).getSubjects(); |
| 168 | List<String> subjects = new ArrayList<>(); | 193 | List<String> subjects = new ArrayList<>(); |
| 169 | for (Subject s: subjectList) { | 194 | for (Subject s: subjectList) { |
| 170 | subjects.add(s.getSubject()); | 195 | subjects.add(s.getSubject()); |
| 171 | } | 196 | } |
| 172 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 197 | binding.spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
| 173 | @SuppressLint("SetTextI18n") | 198 | @SuppressLint("SetTextI18n") |
| 174 | @Override | 199 | @Override |
| 175 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | 200 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 176 | subject = subjects.get(position); | 201 | subject = subjects.get(position); |
| 177 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); | 202 | binding.etName.setText(dateFormat.format(uploadTime) + subject + "作业"); |
| 178 | } | 203 | } |
| 179 | @Override | 204 | @Override |
| 180 | public void onNothingSelected(AdapterView<?> parent) { | 205 | public void onNothingSelected(AdapterView<?> parent) { |
| 181 | } | 206 | } |
| 182 | }); | 207 | }); |
| 183 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); | 208 | binding.spSubject.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_spinner, subjects)); |
| 184 | } | 209 | } |
| 185 | 210 | ||
| 211 | @SuppressLint("CheckResult") | ||
| 212 | public void uploadImage(String name) { | ||
| 213 | activity.showLoadingDialog("上传作业中..."); | ||
| 214 | Observable.fromIterable(images) | ||
| 215 | .map(path -> { | ||
| 216 | int index = images.indexOf(path); | ||
| 217 | return new Pair<>(index, path); | ||
| 218 | }) | ||
| 219 | .subscribeOn(Schedulers.io()) | ||
| 220 | .flatMap(pair -> { | ||
| 221 | int index = pair.first; | ||
| 222 | String path = pair.second; | ||
| 223 | File file = new File(path); | ||
| 224 | String id = file.getName().substring(0, file.getName().lastIndexOf(".")); | ||
| 225 | return Observable.just(file) | ||
| 226 | .map(var -> { | ||
| 227 | BaiduInput baiduInput = NetWorks.inputImage(path, id).blockingGet(); | ||
| 228 | if (baiduInput.getError_code() != null) { | ||
| 229 | throw new RuntimeException("图片入库失败"); | ||
| 230 | } else { | ||
| 231 | return baiduInput; | ||
| 232 | } | ||
| 233 | }) | ||
| 234 | .map(var -> NetWorks.uploadImage(path, id).blockingGet()) | ||
| 235 | .map(var -> { | ||
| 236 | Map<String, Object> map = new HashMap<>(); | ||
| 237 | map.put("brief", id); | ||
| 238 | map.put("sort", index); | ||
| 239 | return map; | ||
| 240 | }); | ||
| 241 | }, 2) | ||
| 242 | .toList() | ||
| 243 | .map(list -> { | ||
| 244 | List<String> stuIds = new ArrayList<>(); | ||
| 245 | stuIds.add(student.stuId); | ||
| 246 | String userId = NetWorks.getUserId(); | ||
| 247 | |||
| 248 | Map<String, Object> map = new HashMap<>(); | ||
| 249 | map.put("name", name); | ||
| 250 | map.put("grade", grade); | ||
| 251 | map.put("term", term); | ||
| 252 | map.put("subject", subject); | ||
| 253 | map.put("userId", userId); | ||
| 254 | map.put("stuIds", stuIds); | ||
| 255 | map.put("briefList", list); | ||
| 256 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); | ||
| 257 | map.put("uploadTime", format.format(uploadTime)); | ||
| 258 | return map; | ||
| 259 | }) | ||
| 260 | .flatMap(body -> { | ||
| 261 | return NetWorks.service_url.uploadHomework(NetWorks.getHeader(), body); | ||
| 262 | }) | ||
| 263 | .observeOn(AndroidSchedulers.mainThread()) | ||
| 264 | .compose(RxLifecycleAndroid.bindActivity(activity.getRxLifecycle())) | ||
| 265 | .subscribe((response, th) -> { | ||
| 266 | if (th != null) th.printStackTrace(); | ||
| 267 | if (response != null && response.getSuccess()) { | ||
| 268 | activity.cancelLoadingDialog(); | ||
| 269 | dismiss(); | ||
| 270 | if (callback != null) callback.invoke(); | ||
| 271 | } else { | ||
| 272 | activity.loadFail("上传作业失败"); | ||
| 273 | } | ||
| 274 | }) | ||
| 275 | ; | ||
| 276 | } | ||
| 277 | |||
| 186 | @NonNull | 278 | @NonNull |
| 187 | @Override | 279 | @Override |
| 188 | public DialogAddHomeworkBinding getBinding() { | 280 | public DialogAddHomeworkBinding getBinding() { |
| 189 | return DialogAddHomeworkBinding.inflate(getLayoutInflater()); | 281 | return DialogAddHomeworkBinding.inflate(getLayoutInflater()); |
| 190 | } | 282 | } |
app/src/main/res/layout/dialog_add_homework.xml
| 1 | <FrameLayout | 1 | <FrameLayout |
| 2 | xmlns:android="http://schemas.android.com/apk/res/android" | 2 | xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | xmlns:app="http://schemas.android.com/apk/res-auto" | 3 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 4 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
| 5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
| 6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
| 7 | tools:ignore="HardcodedText,ContentDescription,UselessParent" > | 7 | tools:ignore="HardcodedText,ContentDescription,UselessParent" > |
| 8 | 8 | ||
| 9 | <LinearLayout | 9 | <LinearLayout |
| 10 | android:orientation="vertical" | 10 | android:orientation="vertical" |
| 11 | android:background="@drawable/shape_radius_top_10" | 11 | android:background="@drawable/shape_radius_top_10" |
| 12 | android:layout_marginTop="80dp" | 12 | android:layout_marginTop="80dp" |
| 13 | android:layout_width="match_parent" | 13 | android:layout_width="match_parent" |
| 14 | android:layout_height="match_parent"> | 14 | android:layout_height="match_parent"> |
| 15 | 15 | ||
| 16 | <FrameLayout | 16 | <FrameLayout |
| 17 | android:layout_marginVertical="8dp" | 17 | android:layout_marginVertical="8dp" |
| 18 | android:layout_width="match_parent" | 18 | android:layout_width="match_parent" |
| 19 | android:layout_height="wrap_content"> | 19 | android:layout_height="wrap_content"> |
| 20 | 20 | ||
| 21 | <TextView | 21 | <TextView |
| 22 | android:text="录入作业" | 22 | android:text="录入作业" |
| 23 | android:textSize="17sp" | 23 | android:textSize="17sp" |
| 24 | android:textStyle="bold" | 24 | android:textStyle="bold" |
| 25 | android:layout_gravity="center" | 25 | android:layout_gravity="center" |
| 26 | android:textColor="@color/text_title" | 26 | android:textColor="@color/text_title" |
| 27 | android:layout_width="wrap_content" | 27 | android:layout_width="wrap_content" |
| 28 | android:layout_height="wrap_content" /> | 28 | android:layout_height="wrap_content" /> |
| 29 | 29 | ||
| 30 | <ImageView | 30 | <ImageView |
| 31 | android:id="@+id/btnClose" | 31 | android:id="@+id/btnClose" |
| 32 | android:padding="12dp" | 32 | android:padding="12dp" |
| 33 | android:src="@mipmap/ic_close" | 33 | android:src="@mipmap/ic_close" |
| 34 | android:layout_gravity="end|center_vertical" | 34 | android:layout_gravity="end|center_vertical" |
| 35 | android:layout_width="35dp" | 35 | android:layout_width="35dp" |
| 36 | android:layout_height="35dp" /> | 36 | android:layout_height="35dp" /> |
| 37 | </FrameLayout> | 37 | </FrameLayout> |
| 38 | 38 | ||
| 39 | <TextView | 39 | <TextView |
| 40 | android:layout_width="wrap_content" | 40 | android:layout_width="wrap_content" |
| 41 | android:layout_height="wrap_content" | 41 | android:layout_height="wrap_content" |
| 42 | android:layout_marginHorizontal="15dp" | 42 | android:layout_marginHorizontal="15dp" |
| 43 | android:text="学生" | 43 | android:text="学生" |
| 44 | android:textColor="@color/text_title" | 44 | android:textColor="@color/text_title" |
| 45 | android:textSize="14sp" | 45 | android:textSize="14sp" |
| 46 | android:textStyle="bold" /> | 46 | android:textStyle="bold" /> |
| 47 | 47 | ||
| 48 | <androidx.appcompat.widget.AppCompatSpinner | 48 | <androidx.appcompat.widget.AppCompatSpinner |
| 49 | android:id="@+id/spStudent" | 49 | android:id="@+id/spStudent" |
| 50 | style="@style/customSpinnerStyle" | 50 | style="@style/customSpinnerStyle" |
| 51 | android:layout_width="match_parent" | 51 | android:layout_width="match_parent" |
| 52 | android:layout_height="40dp" | 52 | android:layout_height="40dp" |
| 53 | android:layout_marginTop="10dp" | 53 | android:layout_marginTop="10dp" |
| 54 | android:layout_marginHorizontal="15dp" | 54 | android:layout_marginHorizontal="15dp" |
| 55 | android:background="@drawable/selector_for_input_spinner" | 55 | android:background="@drawable/selector_for_input_spinner" |
| 56 | android:popupBackground="@drawable/shape_for_input_spinner" | 56 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 57 | android:scrollbars="none" /> | 57 | android:scrollbars="none" /> |
| 58 | 58 | ||
| 59 | <TextView | 59 | <TextView |
| 60 | android:layout_width="wrap_content" | 60 | android:layout_width="wrap_content" |
| 61 | android:layout_height="wrap_content" | 61 | android:layout_height="wrap_content" |
| 62 | android:layout_marginHorizontal="15dp" | 62 | android:layout_marginHorizontal="15dp" |
| 63 | android:layout_marginTop="20dp" | 63 | android:layout_marginTop="20dp" |
| 64 | android:text="年级" | 64 | android:text="年级" |
| 65 | android:textColor="@color/text_title" | 65 | android:textColor="@color/text_title" |
| 66 | android:textSize="14sp" | 66 | android:textSize="14sp" |
| 67 | android:textStyle="bold" /> | 67 | android:textStyle="bold" /> |
| 68 | 68 | ||
| 69 | <androidx.appcompat.widget.AppCompatSpinner | 69 | <androidx.appcompat.widget.AppCompatSpinner |
| 70 | android:id="@+id/spGrade" | 70 | android:id="@+id/spGrade" |
| 71 | style="@style/customSpinnerStyle" | 71 | style="@style/customSpinnerStyle" |
| 72 | android:layout_width="match_parent" | 72 | android:layout_width="match_parent" |
| 73 | android:layout_height="40dp" | 73 | android:layout_height="40dp" |
| 74 | android:layout_marginTop="10dp" | 74 | android:layout_marginTop="10dp" |
| 75 | android:layout_marginHorizontal="15dp" | 75 | android:layout_marginHorizontal="15dp" |
| 76 | android:background="@drawable/selector_for_input_spinner" | 76 | android:background="@drawable/selector_for_input_spinner" |
| 77 | android:popupBackground="@drawable/shape_for_input_spinner" | 77 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 78 | android:scrollbars="none" /> | 78 | android:scrollbars="none" /> |
| 79 | 79 | ||
| 80 | <TextView | 80 | <TextView |
| 81 | android:layout_width="wrap_content" | 81 | android:layout_width="wrap_content" |
| 82 | android:layout_height="wrap_content" | 82 | android:layout_height="wrap_content" |
| 83 | android:layout_marginHorizontal="15dp" | 83 | android:layout_marginHorizontal="15dp" |
| 84 | android:layout_marginTop="20dp" | 84 | android:layout_marginTop="20dp" |
| 85 | android:text="学期" | 85 | android:text="学期" |
| 86 | android:textColor="@color/text_title" | 86 | android:textColor="@color/text_title" |
| 87 | android:textSize="14sp" | 87 | android:textSize="14sp" |
| 88 | android:textStyle="bold" /> | 88 | android:textStyle="bold" /> |
| 89 | 89 | ||
| 90 | <androidx.appcompat.widget.AppCompatSpinner | 90 | <androidx.appcompat.widget.AppCompatSpinner |
| 91 | android:id="@+id/spTerm" | 91 | android:id="@+id/spTerm" |
| 92 | style="@style/customSpinnerStyle" | 92 | style="@style/customSpinnerStyle" |
| 93 | android:layout_width="match_parent" | 93 | android:layout_width="match_parent" |
| 94 | android:layout_height="40dp" | 94 | android:layout_height="40dp" |
| 95 | android:layout_marginTop="10dp" | 95 | android:layout_marginTop="10dp" |
| 96 | android:layout_marginHorizontal="15dp" | 96 | android:layout_marginHorizontal="15dp" |
| 97 | android:background="@drawable/selector_for_input_spinner" | 97 | android:background="@drawable/selector_for_input_spinner" |
| 98 | android:entries="@array/grade_array" | 98 | android:entries="@array/grade_array" |
| 99 | android:popupBackground="@drawable/shape_for_input_spinner" | 99 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 100 | android:scrollbars="none" /> | 100 | android:scrollbars="none" /> |
| 101 | 101 | ||
| 102 | <TextView | 102 | <TextView |
| 103 | android:layout_width="wrap_content" | 103 | android:layout_width="wrap_content" |
| 104 | android:layout_height="wrap_content" | 104 | android:layout_height="wrap_content" |
| 105 | android:layout_marginHorizontal="15dp" | 105 | android:layout_marginHorizontal="15dp" |
| 106 | android:layout_marginTop="20dp" | 106 | android:layout_marginTop="20dp" |
| 107 | android:text="科目" | 107 | android:text="科目" |
| 108 | android:textColor="@color/text_title" | 108 | android:textColor="@color/text_title" |
| 109 | android:textSize="14sp" | 109 | android:textSize="14sp" |
| 110 | android:textStyle="bold" /> | 110 | android:textStyle="bold" /> |
| 111 | 111 | ||
| 112 | <androidx.appcompat.widget.AppCompatSpinner | 112 | <androidx.appcompat.widget.AppCompatSpinner |
| 113 | android:id="@+id/spSubject" | 113 | android:id="@+id/spSubject" |
| 114 | style="@style/customSpinnerStyle" | 114 | style="@style/customSpinnerStyle" |
| 115 | android:layout_width="match_parent" | 115 | android:layout_width="match_parent" |
| 116 | android:layout_height="40dp" | 116 | android:layout_height="40dp" |
| 117 | android:layout_marginTop="10dp" | 117 | android:layout_marginTop="10dp" |
| 118 | android:layout_marginHorizontal="15dp" | 118 | android:layout_marginHorizontal="15dp" |
| 119 | android:background="@drawable/selector_for_input_spinner" | 119 | android:background="@drawable/selector_for_input_spinner" |
| 120 | android:popupBackground="@drawable/shape_for_input_spinner" | 120 | android:popupBackground="@drawable/shape_for_input_spinner" |
| 121 | android:scrollbars="none" /> | 121 | android:scrollbars="none" /> |
| 122 | 122 | ||
| 123 | <TextView | 123 | <TextView |
| 124 | android:layout_width="wrap_content" | 124 | android:layout_width="wrap_content" |
| 125 | android:layout_height="wrap_content" | 125 | android:layout_height="wrap_content" |
| 126 | android:layout_marginHorizontal="15dp" | 126 | android:layout_marginHorizontal="15dp" |
| 127 | android:layout_marginTop="20dp" | 127 | android:layout_marginTop="20dp" |
| 128 | android:text="日期" | 128 | android:text="日期" |
| 129 | android:textColor="@color/text_title" | 129 | android:textColor="@color/text_title" |
| 130 | android:textSize="14sp" | 130 | android:textSize="14sp" |
| 131 | android:textStyle="bold" /> | 131 | android:textStyle="bold" /> |
| 132 | 132 | ||
| 133 | <TextView | 133 | <TextView |
| 134 | android:id="@+id/tvDate" | 134 | android:id="@+id/tvDate" |
| 135 | tools:text="2024-09-18" | 135 | tools:text="2024-09-18" |
| 136 | android:textSize="16sp" | 136 | android:textSize="16sp" |
| 137 | android:textColor="#333" | 137 | android:textColor="#333" |
| 138 | android:gravity="center_vertical" | 138 | android:gravity="center_vertical" |
| 139 | android:paddingHorizontal="16dp" | 139 | android:paddingHorizontal="16dp" |
| 140 | android:layout_width="match_parent" | 140 | android:layout_width="match_parent" |
| 141 | android:layout_height="40dp" | 141 | android:layout_height="40dp" |
| 142 | android:layout_marginTop="10dp" | 142 | android:layout_marginTop="10dp" |
| 143 | android:layout_marginHorizontal="15dp" | 143 | android:layout_marginHorizontal="15dp" |
| 144 | android:background="@drawable/selector_for_input_spinner" /> | 144 | android:background="@drawable/selector_for_input_spinner" /> |
| 145 | 145 | ||
| 146 | <TextView | 146 | <TextView |
| 147 | android:layout_width="wrap_content" | 147 | android:layout_width="wrap_content" |
| 148 | android:layout_height="wrap_content" | 148 | android:layout_height="wrap_content" |
| 149 | android:layout_marginHorizontal="15dp" | 149 | android:layout_marginHorizontal="15dp" |
| 150 | android:layout_marginTop="20dp" | 150 | android:layout_marginTop="20dp" |
| 151 | android:text="作业名称" | 151 | android:text="作业名称" |
| 152 | android:textColor="@color/text_title" | 152 | android:textColor="@color/text_title" |
| 153 | android:textSize="14sp" | 153 | android:textSize="14sp" |
| 154 | android:textStyle="bold" /> | 154 | android:textStyle="bold" /> |
| 155 | 155 | ||
| 156 | <EditText | 156 | <EditText |
| 157 | android:id="@+id/etName" | 157 | android:id="@+id/etName" |
| 158 | android:layout_width="match_parent" | 158 | android:layout_width="match_parent" |
| 159 | android:layout_height="40dp" | 159 | android:layout_height="40dp" |
| 160 | android:layout_marginTop="10dp" | 160 | android:layout_marginTop="10dp" |
| 161 | android:layout_marginHorizontal="15dp" | 161 | android:layout_marginHorizontal="15dp" |
| 162 | android:background="@drawable/shape_for_input_spinner" | 162 | android:background="@drawable/shape_for_input_spinner" |
| 163 | android:fillViewport="true" | 163 | android:fillViewport="true" |
| 164 | android:gravity="center_vertical" | 164 | android:gravity="center_vertical" |
| 165 | android:maxLength="50" | 165 | android:maxLength="50" |
| 166 | android:paddingHorizontal="16dp" | 166 | android:paddingHorizontal="16dp" |
| 167 | android:textColor="@color/text_title" | 167 | android:textColor="@color/text_title" |
| 168 | android:textSize="18sp" | 168 | android:textSize="13sp" |
| 169 | android:inputType="text" | 169 | android:inputType="text" |
| 170 | tools:ignore="Autofill,LabelFor" /> | 170 | tools:ignore="Autofill,LabelFor" /> |
| 171 | 171 | ||
| 172 | <Space style="@style/empty_space"/> | 172 | <Space style="@style/empty_space"/> |
| 173 | <TextView | 173 | <TextView |
| 174 | android:id="@+id/btnConfirm" | ||
| 174 | android:text="确认录入" | 175 | android:text="确认录入" |
| 175 | android:gravity="center" | 176 | android:gravity="center" |
| 176 | android:textSize="16sp" | 177 | android:textSize="16sp" |
| 177 | android:textColor="@color/white" | 178 | android:textColor="@color/white" |
| 178 | android:background="@drawable/shape_radius_5" | 179 | android:background="@drawable/shape_radius_5" |
| 179 | android:backgroundTint="#1C90F3" | 180 | android:backgroundTint="#1C90F3" |
| 180 | android:layout_gravity="center_horizontal" | 181 | android:layout_gravity="center_horizontal" |
| 181 | android:layout_marginBottom="16dp" | 182 | android:layout_marginBottom="16dp" |
| 182 | android:layout_width="224dp" | 183 | android:layout_width="224dp" |
| 183 | android:layout_height="36dp"/> | 184 | android:layout_height="36dp"/> |
| 184 | </LinearLayout> | 185 | </LinearLayout> |
| 185 | </FrameLayout> | 186 | </FrameLayout> |
libs/common/build.gradle
| 1 | apply plugin: 'com.android.library' | 1 | apply plugin: 'com.android.library' |
| 2 | apply from: '../../config.gradle' | 2 | apply from: '../../config.gradle' |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | def androidId = rootProject.ext.androidId | 5 | def androidId = rootProject.ext.androidId |
| 6 | def support = rootProject.ext.dependencies | 6 | def support = rootProject.ext.dependencies |
| 7 | def url = rootProject.ext.url | 7 | def url = rootProject.ext.url |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | android { | 10 | android { |
| 11 | compileSdkVersion androidId.compileSdkVersion | 11 | compileSdkVersion androidId.compileSdkVersion |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | defaultConfig { | 14 | defaultConfig { |
| 15 | minSdkVersion androidId.minSdkVersion | 15 | minSdkVersion androidId.minSdkVersion |
| 16 | targetSdkVersion androidId.targetSdkVersion | 16 | targetSdkVersion androidId.targetSdkVersion |
| 17 | versionCode androidId.versionCode | 17 | versionCode androidId.versionCode |
| 18 | versionName androidId.versionName | 18 | versionName androidId.versionName |
| 19 | 19 | ||
| 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 21 | 21 | ||
| 22 | buildConfigField("String", "APIKey1", "\"eCa3YzEjTBBiNjlXcNnjnldP\"") | ||
| 23 | buildConfigField("String", "SecretKey1", "\"KnZPmjF0ZzmxWV964mzmm6yuDljnETLt\"") | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | buildTypes { | 26 | buildTypes { |
| 25 | debug { | 27 | debug { |
| 26 | minifyEnabled false | 28 | minifyEnabled false |
| 27 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") | 29 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") |
| 28 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | 30 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") |
| 29 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | 31 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") |
| 30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 32 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 31 | } | 33 | } |
| 32 | release { | 34 | release { |
| 33 | minifyEnabled false | 35 | minifyEnabled false |
| 34 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") | 36 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") |
| 35 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | 37 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") |
| 36 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | 38 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") |
| 37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 38 | } | 40 | } |
| 39 | } | 41 | } |
| 40 | 42 | ||
| 41 | compileOptions { | 43 | compileOptions { |
| 42 | sourceCompatibility JavaVersion.VERSION_1_8 | 44 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 43 | targetCompatibility JavaVersion.VERSION_1_8 | 45 | targetCompatibility JavaVersion.VERSION_1_8 |
| 44 | } | 46 | } |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 47 | dependencies { | 49 | dependencies { |
| 48 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 50 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
| 49 | 51 | ||
| 50 | 52 | ||
| 51 | support.each { k, v -> implementation v } | 53 | support.each { k, v -> implementation v } |
| 52 | 54 | ||
| 53 | // 抓包, OkHttp拦截 | 55 | // 抓包, OkHttp拦截 |
| 54 | def chuckerVersion = "3.5.2" | 56 | def chuckerVersion = "3.5.2" |
| 55 | debugImplementation("com.github.chuckerteam.chucker:library:$chuckerVersion") { | 57 | debugImplementation("com.github.chuckerteam.chucker:library:$chuckerVersion") { |
| 56 | exclude module: 'lifecycle-viewmodel-ktx' | 58 | exclude module: 'lifecycle-viewmodel-ktx' |
| 57 | } | 59 | } |
| 58 | releaseImplementation("com.github.chuckerteam.chucker:library-no-op:$chuckerVersion") { | 60 | releaseImplementation("com.github.chuckerteam.chucker:library-no-op:$chuckerVersion") { |
| 59 | exclude module: 'lifecycle-viewmodel-ktx' | 61 | exclude module: 'lifecycle-viewmodel-ktx' |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | } | 64 | } |
libs/common/src/main/java/com/prws/common/bean/baidu/BaiduInput.java
| File was created | 1 | package com.prws.common.bean.baidu; | |
| 2 | |||
| 3 | public class BaiduInput { | ||
| 4 | String brief; | ||
| 5 | String error_code; | ||
| 6 | String cont_sign; | ||
| 7 | String log_id; | ||
| 8 | |||
| 9 | public void setBrief(String brief) { | ||
| 10 | this.brief = brief; | ||
| 11 | } | ||
| 12 | |||
| 13 | public void setError_code(String error_code) { | ||
| 14 | this.error_code = error_code; | ||
| 15 | } | ||
| 16 | |||
| 17 | public void setCont_sign(String cont_sign) { | ||
| 18 | this.cont_sign = cont_sign; | ||
| 19 | } | ||
| 20 | |||
| 21 | public void setLog_id(String log_id) { | ||
| 22 | this.log_id = log_id; | ||
| 23 | } | ||
| 24 | |||
| 25 | public String getBrief() { | ||
| 26 | return brief; | ||
| 27 | } | ||
| 28 | |||
| 29 | public String getError_code() { | ||
| 30 | return error_code; | ||
| 31 | } | ||
| 32 | |||
| 33 | public String getCont_sign() { | ||
| 34 | return cont_sign; | ||
| 35 | } | ||
| 36 | |||
| 37 | public String getLog_id() { | ||
| 38 | return log_id; | ||
| 39 | } | ||
| 40 | |||
| 41 | public class Brief { | ||
| 42 | String name; | ||
| 43 | String id; | ||
| 44 | |||
| 45 | public void setName(String name) { | ||
| 46 | this.name = name; | ||
| 47 | } | ||
| 48 | |||
| 49 | public String getName() { | ||
| 50 | return name; | ||
| 51 | } | ||
| 52 | |||
| 53 | public String getId() { | ||
| 54 | return id; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| 1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
| 5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 6 | import com.prws.common.BuildConfig; | 6 | import com.prws.common.BuildConfig; |
| 7 | import com.prws.common.bean.CutPicBean; | 7 | import com.prws.common.bean.CutPicBean; |
| 8 | import com.prws.common.bean.GradeAndSubject; | 8 | import com.prws.common.bean.GradeAndSubject; |
| 9 | import com.prws.common.bean.PageInfo; | 9 | import com.prws.common.bean.PageInfo; |
| 10 | import com.prws.common.bean.ResponseResult; | 10 | import com.prws.common.bean.ResponseResult; |
| 11 | import com.prws.common.bean.ScheduleBean; | 11 | import com.prws.common.bean.ScheduleBean; |
| 12 | import com.prws.common.bean.Student; | 12 | import com.prws.common.bean.Student; |
| 13 | import com.prws.common.bean.Teacher; | 13 | import com.prws.common.bean.Teacher; |
| 14 | import com.prws.common.bean.TopicBean; | 14 | import com.prws.common.bean.TopicBean; |
| 15 | import com.prws.common.bean.UpdateBean; | 15 | import com.prws.common.bean.UpdateBean; |
| 16 | import com.prws.common.bean.baidu.BaiduInput; | ||
| 16 | import com.prws.common.bean.homework.HomeworkList; | 17 | import com.prws.common.bean.homework.HomeworkList; |
| 18 | import com.prws.common.utils.BitmapUtils; | ||
| 17 | import com.prws.common.utils.SharedPreferencesUtil; | 19 | import com.prws.common.utils.SharedPreferencesUtil; |
| 18 | 20 | ||
| 19 | import java.io.File; | 21 | import java.io.File; |
| 20 | import java.util.HashMap; | 22 | import java.util.HashMap; |
| 21 | import java.util.List; | 23 | import java.util.List; |
| 22 | import java.util.Map; | 24 | import java.util.Map; |
| 23 | 25 | ||
| 24 | import io.reactivex.Observable; | 26 | import io.reactivex.Observable; |
| 25 | import io.reactivex.Observer; | 27 | import io.reactivex.Observer; |
| 26 | import io.reactivex.Single; | 28 | import io.reactivex.Single; |
| 27 | import io.reactivex.android.schedulers.AndroidSchedulers; | 29 | import io.reactivex.android.schedulers.AndroidSchedulers; |
| 28 | import io.reactivex.schedulers.Schedulers; | 30 | import io.reactivex.schedulers.Schedulers; |
| 29 | import okhttp3.MediaType; | 31 | import okhttp3.MediaType; |
| 30 | import okhttp3.MultipartBody; | 32 | import okhttp3.MultipartBody; |
| 31 | import okhttp3.RequestBody; | 33 | import okhttp3.RequestBody; |
| 32 | import okhttp3.ResponseBody; | 34 | import okhttp3.ResponseBody; |
| 33 | import retrofit2.Call; | 35 | import retrofit2.Call; |
| 34 | import retrofit2.Callback; | 36 | import retrofit2.Callback; |
| 35 | import retrofit2.http.Body; | 37 | import retrofit2.http.Body; |
| 36 | import retrofit2.http.GET; | 38 | import retrofit2.http.GET; |
| 37 | import retrofit2.http.Header; | 39 | import retrofit2.http.Header; |
| 38 | import retrofit2.http.Headers; | 40 | import retrofit2.http.Headers; |
| 39 | import retrofit2.http.Multipart; | 41 | import retrofit2.http.Multipart; |
| 40 | import retrofit2.http.POST; | 42 | import retrofit2.http.POST; |
| 41 | import retrofit2.http.PUT; | 43 | import retrofit2.http.PUT; |
| 42 | import retrofit2.http.Part; | 44 | import retrofit2.http.Part; |
| 43 | import retrofit2.http.PartMap; | 45 | import retrofit2.http.PartMap; |
| 44 | import retrofit2.http.Query; | 46 | import retrofit2.http.Query; |
| 45 | import retrofit2.http.Url; | 47 | import retrofit2.http.Url; |
| 46 | 48 | ||
| 47 | /** | 49 | /** |
| 48 | * 类名称:NetWorks | 50 | * 类名称:NetWorks |
| 49 | * 创建人: | 51 | * 创建人: |
| 50 | * <p> | 52 | * <p> |
| 51 | * 类描述:网络请求的操作类 | 53 | * 类描述:网络请求的操作类 |
| 52 | */ | 54 | */ |
| 53 | public class NetWorks extends RetrofitUtils { | 55 | public class NetWorks extends RetrofitUtils { |
| 54 | //服务器路径 | 56 | //服务器路径 |
| 55 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); | 57 | public static final NetService service_url = getMachineRetrofit(BuildConfig.SERVER_URL).create(NetService.class); |
| 56 | 58 | ||
| 57 | //设缓存有效期为1天 | 59 | //设缓存有效期为1天 |
| 58 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; | 60 | protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1; |
| 59 | //查询缓存的Cache-Control设置,使用缓存 | 61 | //查询缓存的Cache-Control设置,使用缓存 |
| 60 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; | 62 | protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC; |
| 61 | //查询网络的Cache-Control设置。不使用缓存 | 63 | //查询网络的Cache-Control设置。不使用缓存 |
| 62 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; | 64 | protected static final String CACHE_CONTROL_NETWORK = "max-age=0"; |
| 63 | 65 | ||
| 64 | 66 | ||
| 65 | public interface NetService { | 67 | public interface NetService { |
| 66 | 68 | ||
| 67 | 69 | ||
| 68 | @GET("/api/v1/user/logout") | 70 | @GET("/api/v1/user/logout") |
| 69 | Observable<ResponseBody> logout(); | 71 | Observable<ResponseBody> logout(); |
| 70 | 72 | ||
| 71 | @Multipart | 73 | @Multipart |
| 72 | @POST("/api/v1/user/upLoadAvatar") | 74 | @POST("/api/v1/user/upLoadAvatar") |
| 73 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); | 75 | Observable<ResponseBody> upLoadAvatar(@Header("Authorization") String token, @Part List<MultipartBody.Part> partLis); |
| 74 | 76 | ||
| 75 | 77 | ||
| 76 | @Headers("Content-Type: application/json") | 78 | @Headers("Content-Type: application/json") |
| 77 | @POST("/api/v1/user/editUser") | 79 | @POST("/api/v1/user/editUser") |
| 78 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); | 80 | Observable<ResponseBody> editUser(@Header("Authorization") String token, @Body RequestBody body); |
| 79 | 81 | ||
| 80 | @Headers("Content-Type: application/json") | 82 | @Headers("Content-Type: application/json") |
| 81 | @POST("/api/v1/user/changePassword") | 83 | @POST("/api/v1/user/changePassword") |
| 82 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); | 84 | Observable<ResponseBody> changePassword(@Header("Authorization") String token, @Body RequestBody body); |
| 83 | 85 | ||
| 84 | 86 | ||
| 85 | @GET("/api/v1/user/searchById") | 87 | @GET("/api/v1/user/searchById") |
| 86 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); | 88 | Observable<ResponseBody> searchById(@Header("Authorization") String token, @Query("userId") String userId); |
| 87 | 89 | ||
| 88 | 90 | ||
| 89 | @Headers("Content-Type: application/json") | 91 | @Headers("Content-Type: application/json") |
| 90 | @POST("/api/v1/auth/login") | 92 | @POST("/api/v1/auth/login") |
| 91 | Observable<ResponseBody> login(@Body RequestBody body); | 93 | Observable<ResponseBody> login(@Body RequestBody body); |
| 92 | 94 | ||
| 93 | @GET("/api/v1/resource/listGradeAndSubject") | 95 | @GET("/api/v1/resource/listGradeAndSubject") |
| 94 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); | 96 | Observable<ResponseResult<List<GradeAndSubject>>> listGradeAndSubject(@Header("Authorization") String token); |
| 95 | 97 | ||
| 96 | 98 | ||
| 97 | @GET("/api/v1/manager/generalQrCode") | 99 | @GET("/api/v1/manager/generalQrCode") |
| 98 | Observable<ResponseBody> generalQrCode(); | 100 | Observable<ResponseBody> generalQrCode(); |
| 99 | 101 | ||
| 100 | @GET("/api/v1/parent/scanAndLogin?") | 102 | @GET("/api/v1/parent/scanAndLogin?") |
| 101 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); | 103 | Observable<ResponseBody> scanAndLogin(@Header("Authorization") String token, @Query("code") String code, @Query("stuId") String stuId); |
| 102 | 104 | ||
| 103 | @GET("/api/v1/parent/getChildrenList") | 105 | @GET("/api/v1/parent/getChildrenList") |
| 104 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); | 106 | Observable<ResponseBody> getChildrenList(@Header("Authorization") String token); |
| 105 | 107 | ||
| 106 | 108 | ||
| 107 | @Headers("Content-Type: application/json") | 109 | @Headers("Content-Type: application/json") |
| 108 | @POST("/api/v1/parent/registerParent") | 110 | @POST("/api/v1/parent/registerParent") |
| 109 | Observable<ResponseBody> registerParent(@Body RequestBody body); | 111 | Observable<ResponseBody> registerParent(@Body RequestBody body); |
| 110 | 112 | ||
| 111 | 113 | ||
| 112 | @GET("/api/v1/parent/listChildren") | 114 | @GET("/api/v1/parent/listChildren") |
| 113 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); | 115 | Observable<ResponseBody> listChildren(@Header("Authorization") String token); |
| 114 | 116 | ||
| 115 | 117 | ||
| 116 | @Headers("Content-Type: application/json") | 118 | @Headers("Content-Type: application/json") |
| 117 | @POST("/api/v1/parent/registerStudent") | 119 | @POST("/api/v1/parent/registerStudent") |
| 118 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); | 120 | Observable<ResponseBody> registerStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 119 | 121 | ||
| 120 | @Headers("Content-Type: application/json") | 122 | @Headers("Content-Type: application/json") |
| 121 | @POST("/api/v1/parent/bindTeacher") | 123 | @POST("/api/v1/parent/bindTeacher") |
| 122 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); | 124 | Observable<ResponseBody> bindTeacher(@Header("Authorization") String token, @Body RequestBody body); |
| 123 | 125 | ||
| 124 | @Multipart | 126 | @Multipart |
| 125 | @POST("/api/v1/user/upLoadAvatar") | 127 | @POST("/api/v1/user/upLoadAvatar") |
| 126 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); | 128 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file); |
| 127 | 129 | ||
| 128 | 130 | ||
| 129 | @Multipart | 131 | @Multipart |
| 130 | @POST("/api/v1/student/editStudentAvatar") | 132 | @POST("/api/v1/student/editStudentAvatar") |
| 131 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 133 | Observable<ResponseResult<Map<String, String>>> uploadAvatar(@Header("Authorization") String token, @Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 132 | 134 | ||
| 133 | @Headers("Content-Type: application/json") | 135 | @Headers("Content-Type: application/json") |
| 134 | @POST("/api/v1/parent/editChild") | 136 | @POST("/api/v1/parent/editChild") |
| 135 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); | 137 | Observable<ResponseResult> editStudent(@Header("Authorization") String token, @Body RequestBody body); |
| 136 | 138 | ||
| 137 | @GET("/api/v1/student/getStudyPlanForThisWeek") | 139 | @GET("/api/v1/student/getStudyPlanForThisWeek") |
| 138 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); | 140 | Observable<ResponseResult<ScheduleBean>> getWeekPlan(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 139 | 141 | ||
| 140 | @GET("api/v1/parent/searchTeacher") | 142 | @GET("api/v1/parent/searchTeacher") |
| 141 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); | 143 | Observable<ResponseResult<Teacher>> searchTeacher(@Header("Authorization") String token, @Query("phone") String phone); |
| 142 | 144 | ||
| 143 | @POST("api/v1/question/listErrorBook") | 145 | @POST("api/v1/question/listErrorBook") |
| 144 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); | 146 | Observable<ResponseResult<PageInfo<TopicBean>>> getError(@Header("Authorization") String token, @Body Map<String, Object> body); |
| 145 | 147 | ||
| 146 | @POST | 148 | @POST |
| 147 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); | 149 | Observable<JsonObject> removeWriting(@Url String url, @Body RequestBody body); |
| 148 | 150 | ||
| 149 | @POST | 151 | @POST |
| 150 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); | 152 | Observable<CutPicBean> cut(@Url String url, @Body RequestBody body); |
| 151 | 153 | ||
| 152 | @POST | 154 | @POST |
| 153 | Observable<JsonObject> getBaiduToken(@Url String url); | 155 | Observable<JsonObject> getBaiduToken(@Url String url); |
| 154 | 156 | ||
| 155 | @Multipart | 157 | @Multipart |
| 156 | @POST("api/v1/pad/addErrorBook") | 158 | @POST("api/v1/pad/addErrorBook") |
| 157 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); | 159 | Observable<ResponseResult> addError(@Part() MultipartBody.Part file, @PartMap Map<String, Object> map); |
| 158 | 160 | ||
| 159 | @POST("api/v1/pad/deleteStuErrorBook") | 161 | @POST("api/v1/pad/deleteStuErrorBook") |
| 160 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); | 162 | Observable<ResponseResult> deleteError(@Header("Authorization") String token, @Body List<String> map); |
| 161 | 163 | ||
| 162 | @PUT("api/v1/pad/updateStuErrorBookInfo") | 164 | @PUT("api/v1/pad/updateStuErrorBookInfo") |
| 163 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); | 165 | Observable<ResponseResult> updateError(@Header("Authorization") String token, @Body List<HashMap<String, Object>> map); |
| 164 | 166 | ||
| 165 | @POST("api/v1/question/editErrorBook") | 167 | @POST("api/v1/question/editErrorBook") |
| 166 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); | 168 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
| 167 | 169 | ||
| 168 | @GET("api/v1/resource/checkUpdate") | 170 | @GET("api/v1/resource/checkUpdate") |
| 169 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | 171 | Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); |
| 170 | 172 | ||
| 171 | @GET("api/v1/teacher/getStudentList") | 173 | @GET("api/v1/teacher/getStudentList") |
| 172 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); | 174 | Observable<ResponseBody> getStudentList(@Header("Authorization") String token, @Query("userId") String id); |
| 173 | 175 | ||
| 174 | @GET("api/v1/teacher/getStudentList") | 176 | @GET("api/v1/teacher/getStudentList") |
| 175 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); | 177 | Single<ResponseResult<List<Student>>> getStudentList2(@Header("Authorization") String token, @Query("userId") String id); |
| 176 | 178 | ||
| 177 | @GET("api/v1/answer/listRecordForTeacher") | 179 | @GET("api/v1/answer/listRecordForTeacher") |
| 178 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); | 180 | Observable<ResponseBody> getRecordList(@Header("Authorization") String token, @Query("userId") String id); |
| 179 | 181 | ||
| 180 | @GET("api/v1/homework/listHomeworkByStuId") | 182 | @GET("api/v1/homework/listHomeworkByStuId") |
| 181 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); | 183 | Single<ResponseResult<List<HomeworkList>>> getStudentHomework(@Header("Authorization") String token, @Query("stuId") String stuId); |
| 182 | 184 | ||
| 185 | @POST | ||
| 186 | Single<BaiduInput> inputImage(@Url String url, @Body RequestBody body); | ||
| 187 | |||
| 188 | @Multipart | ||
| 189 | @POST("api/v1/homework/uploadHomework") | ||
| 190 | Single<ResponseResult> uploadImage(@Header("Authorization") String token, @Part() MultipartBody.Part file, @Query("brief") String id); | ||
| 191 | |||
| 192 | @POST("api/v1/homework/uploadHomeworkAction") | ||
| 193 | Single<ResponseResult> uploadHomework(@Header("Authorization") String token, @Body Object map); | ||
| 194 | |||
| 183 | } | 195 | } |
| 184 | 196 | ||
| 185 | public static String getUserId() { | 197 | public static String getUserId() { |
| 186 | return (String) SharedPreferencesUtil.getData("userId", ""); | 198 | return (String) SharedPreferencesUtil.getData("userId", ""); |
| 187 | } | 199 | } |
| 188 | 200 | ||
| 189 | public static String getHeader() { | 201 | public static String getHeader() { |
| 190 | return (String) SharedPreferencesUtil.getData("token", ""); | 202 | return (String) SharedPreferencesUtil.getData("token", ""); |
| 191 | } | 203 | } |
| 192 | 204 | ||
| 193 | public static String getBaiduToken() { | 205 | public static String getBaiduToken() { |
| 194 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); | 206 | return (String) SharedPreferencesUtil.getData("baiduToken", ""); |
| 195 | } | 207 | } |
| 196 | 208 | ||
| 209 | public static Single<BaiduInput> inputImage(String filePath, String id) { | ||
| 210 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | ||
| 211 | String base64 = BitmapUtils.fileToBase64(filePath); | ||
| 212 | File file = new File(filePath); | ||
| 213 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&brief={\"name\":\"" + file.getName() + "\", \"id\":\"" + id + "\"}"); | ||
| 214 | return getBaiduTokenOcr().map(jsonObject -> jsonObject.get("access_token").getAsString()) | ||
| 215 | .flatMap(token -> { | ||
| 216 | return service_url.inputImage("https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add?access_token=" + token, body); | ||
| 217 | }); | ||
| 218 | } | ||
| 219 | |||
| 220 | public static Single<ResponseResult> uploadImage(String path, String id) { | ||
| 221 | File file = new File(path); | ||
| 222 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | ||
| 223 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | ||
| 224 | return service_url.uploadImage(getHeader(), part, id); | ||
| 225 | } | ||
| 226 | |||
| 197 | 227 | ||
| 198 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | 228 | public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { |
| 199 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); | 229 | service_url.checkUpdate(code, packageName, 0).enqueue(callback); |
| 200 | } | 230 | } |
| 201 | 231 | ||
| 202 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { | 232 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 203 | File file = new File(path); | 233 | File file = new File(path); |
| 204 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | 234 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); |
| 205 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 235 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 206 | Map<String, Object> map = new HashMap<>(); | 236 | Map<String, Object> map = new HashMap<>(); |
| 207 | map.put("condition", param); | 237 | map.put("condition", param); |
| 208 | setSubscribe(service_url.addError(part, map), observer); | 238 | setSubscribe(service_url.addError(part, map), observer); |
| 209 | } | 239 | } |
| 210 | 240 | ||
| 211 | 241 | ||
| 212 | public static void cut(String base64, Observer<CutPicBean> observer) { | 242 | public static void cut(String base64, Observer<CutPicBean> observer) { |
| 213 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 243 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 214 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); | 244 | RequestBody body = RequestBody.create(mediaType, "image=" + base64 + "&detect_direction=true"); |
| 215 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); | 245 | setSubscribe(service_url.cut("https://aip.baidubce.com/rest/2.0/ocr/v1/paper_cut_edu?access_token=" + getBaiduToken(), body), observer); |
| 216 | } | 246 | } |
| 217 | 247 | ||
| 218 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { | 248 | public static void editError(Map<String, Object> map, Observer<ResponseResult> observer) { |
| 219 | setSubscribe(service_url.editError(getHeader(), map), observer); | 249 | setSubscribe(service_url.editError(getHeader(), map), observer); |
| 220 | } | 250 | } |
| 221 | 251 | ||
| 222 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { | 252 | public static void editError(List<HashMap<String, Object>> map, Observer<ResponseResult> observer) { |
| 223 | setSubscribe(service_url.updateError(getHeader(), map), observer); | 253 | setSubscribe(service_url.updateError(getHeader(), map), observer); |
| 224 | } | 254 | } |
| 225 | 255 | ||
| 226 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { | 256 | public static void deleteError(List<String> map, Observer<ResponseResult> observer) { |
| 227 | setSubscribe(service_url.deleteError(getHeader(), map), observer); | 257 | setSubscribe(service_url.deleteError(getHeader(), map), observer); |
| 228 | } | 258 | } |
| 229 | 259 | ||
| 230 | public static void getBaiduToken(Observer<JsonObject> observer) { | 260 | public static void getBaiduToken(Observer<JsonObject> observer) { |
| 231 | 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); | 261 | 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); |
| 232 | } | 262 | } |
| 233 | 263 | ||
| 264 | public static Single<JsonObject> getBaiduTokenOcr() { | ||
| 265 | 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(); | ||
| 266 | } | ||
| 267 | |||
| 234 | public static void removeWriting(String base64, Observer<JsonObject> observer) { | 268 | public static void removeWriting(String base64, Observer<JsonObject> observer) { |
| 235 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); | 269 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); |
| 236 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); | 270 | RequestBody body = RequestBody.create(mediaType, "image=" + base64); |
| 237 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); | 271 | setSubscribe(service_url.removeWriting(("https://aip.baidubce.com/rest/2.0/ocr/v1/remove_handwriting?access_token=" + getBaiduToken()), body), observer); |
| 238 | } | 272 | } |
| 239 | 273 | ||
| 240 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { | 274 | public static void searchTeacher(String phone, Observer<ResponseResult<Teacher>> observer) { |
| 241 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); | 275 | setSubscribe(service_url.searchTeacher(getHeader(), phone), observer); |
| 242 | } | 276 | } |
| 243 | 277 | ||
| 244 | public static void logout(Observer<ResponseBody> observer) { | 278 | public static void logout(Observer<ResponseBody> observer) { |
| 245 | setSubscribe(service_url.logout(), observer); | 279 | setSubscribe(service_url.logout(), observer); |
| 246 | } | 280 | } |
| 247 | 281 | ||
| 248 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { | 282 | public static void editStudent(RequestBody body, Observer<ResponseResult> observable) { |
| 249 | setSubscribe(service_url.editStudent(getHeader(), body), observable); | 283 | setSubscribe(service_url.editStudent(getHeader(), body), observable); |
| 250 | } | 284 | } |
| 251 | 285 | ||
| 252 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { | 286 | public static void getWeekPlan(String id, Observer<ResponseResult<ScheduleBean>> observer) { |
| 253 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); | 287 | setSubscribe(service_url.getWeekPlan(getHeader(), id), observer); |
| 254 | } | 288 | } |
| 255 | 289 | ||
| 256 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { | 290 | public static void uploadStudentAvatar(File file, String stuId, Observer<ResponseResult<Map<String, String>>> observer) { |
| 257 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 291 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 258 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 292 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 259 | Map<String, Object> map = new HashMap<>(); | 293 | Map<String, Object> map = new HashMap<>(); |
| 260 | map.put("stuId", stuId); | 294 | map.put("stuId", stuId); |
| 261 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); | 295 | setSubscribe(service_url.uploadAvatar(getHeader(), part, map), observer); |
| 262 | } | 296 | } |
| 263 | 297 | ||
| 264 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { | 298 | public static void uploadAvatar(File file, Observer<ResponseResult<Map<String, String>>> observer) { |
| 265 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); | 299 | RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); |
| 266 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); | 300 | MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody); |
| 267 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); | 301 | setSubscribe(service_url.uploadAvatar(getHeader(), part), observer); |
| 268 | } | 302 | } |
| 269 | 303 | ||
| 270 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { | 304 | public static void upLoadAvatar(List<MultipartBody.Part> partLis, Observer<ResponseBody> observer) { |
| 271 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); | 305 | setSubscribe(service_url.upLoadAvatar(getHeader(), partLis), observer); |
| 272 | } | 306 | } |
| 273 | 307 | ||
| 274 | 308 | ||
| 275 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { | 309 | public static void editUser(RequestBody body, Observer<ResponseBody> observer) { |
| 276 | setSubscribe(service_url.editUser(getHeader(), body), observer); | 310 | setSubscribe(service_url.editUser(getHeader(), body), observer); |
| 277 | } | 311 | } |
| 278 | 312 | ||
| 279 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { | 313 | public static void changePassword(RequestBody body, Observer<ResponseBody> observer) { |
| 280 | setSubscribe(service_url.changePassword(getHeader(), body), observer); | 314 | setSubscribe(service_url.changePassword(getHeader(), body), observer); |
| 281 | } | 315 | } |
| 282 | 316 | ||
| 283 | 317 | ||
| 284 | public static void searchById(String userId, Observer<ResponseBody> observer) { | 318 | public static void searchById(String userId, Observer<ResponseBody> observer) { |
| 285 | setSubscribe(service_url.searchById(getHeader(), userId), observer); | 319 | setSubscribe(service_url.searchById(getHeader(), userId), observer); |
| 286 | } | 320 | } |
| 287 | 321 | ||
| 288 | 322 | ||
| 289 | public static void login(RequestBody body, Observer<ResponseBody> observer) { | 323 | public static void login(RequestBody body, Observer<ResponseBody> observer) { |
| 290 | setSubscribe(service_url.login(body), observer); | 324 | setSubscribe(service_url.login(body), observer); |
| 291 | } | 325 | } |
| 292 | 326 | ||
| 293 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { | 327 | public static void listGradeAndSubject(Observer<ResponseResult<List<GradeAndSubject>>> observer) { |
| 294 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); | 328 | setSubscribe(service_url.listGradeAndSubject(getHeader()), observer); |
| 295 | } | 329 | } |
| 296 | 330 | ||
| 297 | 331 | ||
| 298 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { | 332 | public static void scanAndLogin(String code, String stuId, Observer<ResponseBody> observer) { |
| 299 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); | 333 | setSubscribe(service_url.scanAndLogin(getHeader(), code, stuId), observer); |
| 300 | } | 334 | } |
| 301 | 335 | ||
| 302 | public static void getChildrenList(Observer<ResponseBody> observer) { | 336 | public static void getChildrenList(Observer<ResponseBody> observer) { |
| 303 | setSubscribe(service_url.getChildrenList(getHeader()), observer); | 337 | setSubscribe(service_url.getChildrenList(getHeader()), observer); |
| 304 | } | 338 | } |
| 305 | 339 | ||
| 306 | 340 | ||
| 307 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { | 341 | public static void registerParent(RequestBody body, Observer<ResponseBody> observer) { |
| 308 | setSubscribe(service_url.registerParent(body), observer); | 342 | setSubscribe(service_url.registerParent(body), observer); |
| 309 | } | 343 | } |
| 310 | 344 | ||
| 311 | 345 | ||
| 312 | public static void listChildren(Observer<ResponseBody> observer) { | 346 | public static void listChildren(Observer<ResponseBody> observer) { |
| 313 | setSubscribe(service_url.listChildren(getHeader()), observer); | 347 | setSubscribe(service_url.listChildren(getHeader()), observer); |
| 314 | } | 348 | } |
| 315 | 349 | ||
| 316 | public static void listStudent(Observer<ResponseBody> observer) { | 350 | public static void listStudent(Observer<ResponseBody> observer) { |
| 317 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 351 | setSubscribe(service_url.getStudentList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 318 | } | 352 | } |
| 319 | 353 | ||
| 320 | public static Single<ResponseResult<List<Student>>> listStudent() { | 354 | public static Single<ResponseResult<List<Student>>> listStudent() { |
| 321 | return service_url.getStudentList2(getHeader(), getUserId()); | 355 | return service_url.getStudentList2(getHeader(), getUserId()); |
| 322 | } | 356 | } |
| 323 | 357 | ||
| 324 | public static void listRecord(Observer<ResponseBody> observer) { | 358 | public static void listRecord(Observer<ResponseBody> observer) { |
| 325 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); | 359 | setSubscribe(service_url.getRecordList(getHeader(), (String) SharedPreferencesUtil.getData("userId", "")), observer); |
| 326 | } | 360 | } |
| 327 | 361 | ||
| 328 | 362 | ||
| 329 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { | 363 | public static void registerStudent(RequestBody body, Observer<ResponseBody> observer) { |
| 330 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); | 364 | setSubscribe(service_url.registerStudent(getHeader(), body), observer); |
| 331 | } | 365 | } |
| 332 | 366 | ||
| 333 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { | 367 | public static void bindTeacher(RequestBody body, Observer<ResponseBody> observer) { |
| 334 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); | 368 | setSubscribe(service_url.bindTeacher(getHeader(), body), observer); |
| 335 | } | 369 | } |
| 336 | 370 | ||
| 337 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { | 371 | public static void getError(Map map, Observer<ResponseResult<PageInfo<TopicBean>>> observer) { |
| 338 | setSubscribe(service_url.getError(getHeader(), map), observer); | 372 | setSubscribe(service_url.getError(getHeader(), map), observer); |
| 339 | } | 373 | } |
| 340 | 374 | ||
| 341 | 375 | ||
| 342 | public static RequestBody getMapRequestBody(Map map) { | 376 | public static RequestBody getMapRequestBody(Map map) { |
| 343 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); | 377 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(map)); |
| 344 | } | 378 | } |
| 345 | 379 | ||
| 346 | 380 | ||
| 347 | public static RequestBody getArrayRequestBody(List list) { | 381 | public static RequestBody getArrayRequestBody(List list) { |
| 348 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); | 382 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list)); |
| 349 | } | 383 | } |
| 350 | 384 | ||
| 351 | public static RequestBody getFileRequestBody(File file) { | 385 | public static RequestBody getFileRequestBody(File file) { |
| 352 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); | 386 | return RequestBody.create(MediaType.parse("application/octet-stream"), file); |
| 353 | } | 387 | } |
| 354 | 388 | ||
| 355 | public static RequestBody getFileRequestBody(byte[] bytes) { | 389 | public static RequestBody getFileRequestBody(byte[] bytes) { |
| 356 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); | 390 | return RequestBody.create(MediaType.parse("multipart/form-data"), bytes); |
| 357 | } | 391 | } |
| 358 | 392 | ||
| 359 | public static RequestBody getObjectRequestBody(Object obj) { | 393 | public static RequestBody getObjectRequestBody(Object obj) { |
| 360 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); | 394 | return RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(obj)); |
| 361 | } | 395 | } |
| 362 | 396 | ||
| 363 | public static RequestBody getStringRequestBody(String str) { | 397 | public static RequestBody getStringRequestBody(String str) { |
| 364 | return RequestBody.create(MediaType.parse("text/plain"), str); | 398 | return RequestBody.create(MediaType.parse("text/plain"), str); |
| 365 | } | 399 | } |
| 366 | 400 | ||
| 367 | 401 | ||
| 368 | /** | 402 | /** |
| 369 | * 插入观察者 | 403 | * 插入观察者 |
| 370 | * | 404 | * |
| 371 | * @param observable | 405 | * @param observable |
| 372 | * @param observer | 406 | * @param observer |
| 373 | * @param <T> | 407 | * @param <T> |
| 374 | */ | 408 | */ |
| 375 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { | 409 | public static <T> void setSubscribe(Observable<T> observable, Observer<T> observer) { |
| 376 | observable.subscribeOn(Schedulers.io())//子线程访问网络 | 410 | observable.subscribeOn(Schedulers.io())//子线程访问网络 |
| 377 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 | 411 | .observeOn(AndroidSchedulers.mainThread())//回调到主线程 |
| 378 | .subscribe(observer); | 412 | .subscribe(observer); |
| 379 | } | 413 | } |
| 380 | 414 | ||
| 381 | } | 415 | } |
| 382 | 416 |