diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c6d807..fa04f6c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -83,6 +83,9 @@ + onBackPressed()); btn_next.setOnClickListener(view -> { if (isName && isSex && isNian && isShen) { - addStudent(); + if (teacher != null) { + addStudent(); + } else { + showDialog("温馨提示", "您还未绑定老师,是否绑定?", "去绑定", "暂不绑定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialogInterface.dismiss(); + showDialog("温馨提示", "您暂未绑定老师,如需绑定老师\n" + "请联系400-800-3813", "确定", "", null, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + addStudent(); + } + }); + } + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Intent intent = new Intent(AddStudentActivity.this, AddTeacherActivity.class); + startActivityForResult(intent, BIND_TEACHER_CODE); + } + }); + } } else { Toast.makeText(this, "请完成设置后点击", Toast.LENGTH_SHORT).show(); } @@ -170,18 +207,17 @@ public class AddStudentActivity extends BaseActivity { String nian = (String) SharedPreferencesUtil.getData("setNian", ""); String shen = (String) SharedPreferencesUtil.getData("setShen", ""); String xueq = (String) SharedPreferencesUtil.getData("setXueq", ""); - - Map map = new HashMap(); map.put("nickName", name); map.put("gender", "男".equals(sex) ? 0 : 1); map.put("gradeId", SharedPreferencesUtil.getData("grade", 1)); map.put("parentIdentity", shen); map.put("term", xueq); + if (teacher != null) + map.put("userId", teacher.getId()); if (path != null) { map.put("photo", path); } - NetWorks.registerStudent(NetWorks.getMapRequestBody(map), new Observer() { @Override public void onSubscribe(Disposable d) { @@ -191,7 +227,6 @@ public class AddStudentActivity extends BaseActivity { @Override public void onNext(ResponseBody responseBody) { try { - String str = responseBody.string().toString(); LogUtil.e(TAG, "----" + str); JSONObject jo = new JSONObject(str); @@ -205,7 +240,6 @@ public class AddStudentActivity extends BaseActivity { e.printStackTrace(); Toast.makeText(AddStudentActivity.this, "服务繁忙,请重试", Toast.LENGTH_SHORT).show(); } - } @Override @@ -221,6 +255,7 @@ public class AddStudentActivity extends BaseActivity { }); } + @Override protected void initData() { @@ -335,7 +370,17 @@ public class AddStudentActivity extends BaseActivity { //也可以进行一些保存、压缩等操作后上传 File file = saveImage("head_output", image); uploadAvatar(file); - // Log.d("dsadsadsa",path); + } + } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) { + String t = intent.getStringExtra("teacher"); + teacher = new Gson().fromJson(t, Teacher.class); + rl_teacher.setVisibility(View.VISIBLE); + tv_bind.setText("重新绑定"); + tv_teacher.setText(teacher.getUserName()); + if (!TextUtils.isEmpty(teacher.getPhoto())) { + RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AddStudentActivity.this, 20)); + RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); + Glide.with(AddStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); } } } @@ -383,7 +428,6 @@ public class AddStudentActivity extends BaseActivity { fos.close(); return file; } catch (IOException e) { - Log.d("dsadsadsa", e.getLocalizedMessage()); e.printStackTrace(); } return null; @@ -415,4 +459,10 @@ public class AddStudentActivity extends BaseActivity { startActivityForResult(photoPickerIntent, ALBUM_REQUEST_CODE); } + + @OnClick(R.id.view_6) + public void toAddTeacher(View view) { + Intent intent = new Intent(AddStudentActivity.this, AddTeacherActivity.class); + startActivityForResult(intent, BIND_TEACHER_CODE); + } } diff --git a/app/src/main/java/com/hjx/parent/AddTeacherActivity.java b/app/src/main/java/com/hjx/parent/AddTeacherActivity.java new file mode 100644 index 0000000..546f8ac --- /dev/null +++ b/app/src/main/java/com/hjx/parent/AddTeacherActivity.java @@ -0,0 +1,157 @@ +package com.hjx.parent; + +import android.content.Intent; +import android.graphics.Color; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; +import com.bumptech.glide.request.RequestOptions; +import com.google.gson.Gson; +import com.prws.common.base.BaseActivity; +import com.prws.common.base.BasePresenter; +import com.prws.common.bean.ResponseResult; +import com.prws.common.bean.Teacher; +import com.prws.common.net.NetWorks; +import com.prws.common.utils.Common; +import com.prws.common.utils.ScreenUtils; + +import butterknife.BindView; +import butterknife.OnClick; +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; + +public class AddTeacherActivity extends BaseActivity { + @BindView(R.id.et_1) + EditText et_1; + @BindView(R.id.btn_next) + Button btn_next; + @BindView(R.id.rl_teacher) + RelativeLayout rl_teacher; + @BindView(R.id.iv_teacher) + ImageView iv_teacher; + @BindView(R.id.tv_teacher) + TextView tv_teacher; + Teacher teacher; + + @Override + protected int layoutResId() { + return R.layout.activity_add_teacher; + } + + @Override + public Object getContract() { + return null; + } + + @Override + public BasePresenter getPresenter() { + return null; + } + + @Override + protected void initView() { + et_1.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + if (editable.length() == 11) { + if (Common.isValidPhoneNumber(editable.toString())) { + searchTeacher(editable.toString()); + } else { + rl_teacher.setVisibility(View.GONE); + showToast("请输入正确的手机号码"); + btn_next.setTextColor(Color.parseColor("#999999")); + btn_next.setBackgroundResource(R.drawable.bg_solid_btn_grad); + btn_next.setEnabled(false); + } + } else { + rl_teacher.setVisibility(View.GONE); + btn_next.setBackgroundResource(R.drawable.bg_solid_btn_grad); + btn_next.setTextColor(Color.parseColor("#999999")); + btn_next.setEnabled(false); + } + } + }); + } + + + public void searchTeacher(String phone) { + NetWorks.searchTeacher(phone, new Observer>() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(ResponseResult result) { + if (result != null && result.getCode() == 200) { + teacher = result.getData(); + rl_teacher.setVisibility(View.VISIBLE); + if (!TextUtils.isEmpty(teacher.getPhoto())) { + RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(AddTeacherActivity.this, 20)); + RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); + Glide.with(AddTeacherActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); + } else { + iv_teacher.setImageResource(R.mipmap.ic_teacher_male); + } + tv_teacher.setText(teacher.getUserName()); + btn_next.setBackgroundResource(R.drawable.bg_solid_btn); + btn_next.setTextColor(Color.WHITE); + btn_next.setEnabled(true); + } + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + } + + @OnClick(R.id.btn_next) + public void confirm(View view) { + Intent intent = new Intent(); + intent.putExtra("teacher", new Gson().toJson(teacher)); + setResult(1000,intent); + finish(); + } + + @Override + protected void initListener() { + + } + + @Override + protected void initData() { + + } + + @Override + public void onNetChanged(int netWorkState) { + + } + +} diff --git a/app/src/main/java/com/hjx/parent/ChangePwdActivity.java b/app/src/main/java/com/hjx/parent/ChangePwdActivity.java index 15bc864..4c6d82d 100644 --- a/app/src/main/java/com/hjx/parent/ChangePwdActivity.java +++ b/app/src/main/java/com/hjx/parent/ChangePwdActivity.java @@ -87,8 +87,6 @@ public class ChangePwdActivity extends BaseActivity { try { String str = responseBody.string().toString(); - - LogUtil.e(TAG, "----" + str); JSONObject jo = new JSONObject(str); boolean isSucceed = jo.getBoolean("success"); diff --git a/app/src/main/java/com/hjx/parent/ChooseActivity.java b/app/src/main/java/com/hjx/parent/ChooseActivity.java index 646107b..217fe5b 100644 --- a/app/src/main/java/com/hjx/parent/ChooseActivity.java +++ b/app/src/main/java/com/hjx/parent/ChooseActivity.java @@ -92,10 +92,7 @@ public class ChooseActivity extends BaseActivity { @Override public void onNext(ResponseBody responseBody) { try { - String str = responseBody.string().toString(); - - LogUtil.e("TAG", "----" + str); JSONObject jo = new JSONObject(str); boolean isSucceed = jo.getBoolean("success"); diff --git a/app/src/main/java/com/hjx/parent/EditStudentActivity.java b/app/src/main/java/com/hjx/parent/EditStudentActivity.java index 130e570..b4b65bc 100644 --- a/app/src/main/java/com/hjx/parent/EditStudentActivity.java +++ b/app/src/main/java/com/hjx/parent/EditStudentActivity.java @@ -1,5 +1,6 @@ package com.hjx.parent; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Color; @@ -14,6 +15,8 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -31,6 +34,7 @@ import com.hjx.parent.bean.StudentBean; import com.prws.common.base.BaseActivity; import com.prws.common.base.BasePresenter; import com.prws.common.bean.ResponseResult; +import com.prws.common.bean.Teacher; import com.prws.common.net.NetWorks; import com.prws.common.utils.LogUtil; import com.prws.common.utils.ScreenUtils; @@ -63,12 +67,21 @@ public class EditStudentActivity extends BaseActivity { TextView tv_teacher; @BindView(R.id.iv_teacher) ImageView iv_teacher; + @BindView(R.id.rl_teacher) + RelativeLayout rl_teacher; + @BindView(R.id.tv_bind) + TextView tv_bind; + @BindView(R.id.view_6) + LinearLayout view_6; private static int CAMERA_REQUEST_CODE = 343; private static int ALBUM_REQUEST_CODE = 456; private static int CROP_REQUEST_CODE = 234; + + private static int BIND_TEACHER_CODE = 345; private File tempFile; private String path; StudentBean studentBean; + private Teacher teacher; @Override protected int layoutResId() { @@ -137,6 +150,8 @@ public class EditStudentActivity extends BaseActivity { iv_avatar.setImageResource(studentBean.getGender() == 0 ? R.mipmap.ic_avatar_male : R.mipmap.ic_avatar_female); } if (!"虚拟".equals(studentBean.getTeacherIdentity())) { + rl_teacher.setVisibility(View.VISIBLE); + tv_bind.setText("重新绑定"); tv_teacher.setText(studentBean.getTeacherName()); if (!TextUtils.isEmpty(studentBean.getTeacherAvatar())) { RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(this, 25)); @@ -146,7 +161,12 @@ public class EditStudentActivity extends BaseActivity { iv_teacher.setImageResource(studentBean.getSex() == 0 ? R.mipmap.ic_teacher_male : R.mipmap.ic_teacher_female); } } else { - iv_teacher.setVisibility(View.GONE); + rl_teacher.setVisibility(View.GONE); + if ((studentBean.getState() != null && studentBean.getState() == 0)) { + tv_bind.setText("待通过"); + tv_bind.setTextColor(Color.parseColor("#FF3737")); + view_6.setEnabled(false); + } } } @@ -159,10 +179,37 @@ public class EditStudentActivity extends BaseActivity { view_5.setOnClickListener(view -> startActivity(ShenActivity.class)); findViewById(R.id.tv_cancel).setOnClickListener(view -> onBackPressed()); btn_next.setOnClickListener(view -> { - editStudent(); + if (teacher != null || !"虚拟".equals(studentBean.getTeacherIdentity()) || (studentBean.getState() != null && studentBean.getState() == 0)) { + editStudent(); + } else { + showDialog("温馨提示", "您还未绑定老师,是否绑定?", "去绑定", "暂不绑定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialogInterface.dismiss(); + showDialog("温馨提示", "您暂未绑定老师,如需绑定老师\n" + "请联系400-800-3813", "确定", "", null, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + editStudent(); + } + }); + } + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); + startActivityForResult(intent, BIND_TEACHER_CODE); + } + }); + } }); } + @OnClick(R.id.view_6) + public void toAddTeacher(View view) { + Intent intent = new Intent(EditStudentActivity.this, AddTeacherActivity.class); + startActivityForResult(intent, BIND_TEACHER_CODE); + } + public void editStudent() { Map map = new HashMap(); map.put("nickName", studentBean.getNickName()); @@ -170,6 +217,9 @@ public class EditStudentActivity extends BaseActivity { map.put("gradeId", studentBean.getGradeId()); map.put("parentIdentity", studentBean.getParentIdentity()); map.put("term", studentBean.getTerm()); + if (teacher != null) { + map.put("teacherId", teacher.getId()); + } map.put("stuId", studentBean.getStuId()); NetWorks.editStudent(NetWorks.getMapRequestBody(map), new Observer() { @Override @@ -269,6 +319,17 @@ public class EditStudentActivity extends BaseActivity { uploadAvatar(file); // Log.d("dsadsadsa",path); } + } else if (requestCode == BIND_TEACHER_CODE && resultCode == 1000) { + String t = intent.getStringExtra("teacher"); + teacher = new Gson().fromJson(t, Teacher.class); + rl_teacher.setVisibility(View.VISIBLE); + tv_bind.setText("重新绑定"); + tv_teacher.setText(teacher.getUserName()); + if (!TextUtils.isEmpty(teacher.getPhoto())) { + RoundedCorners roundedCorners = new RoundedCorners(ScreenUtils.dpToPx(EditStudentActivity.this, 20)); + RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); + Glide.with(EditStudentActivity.this).load(teacher.getPhoto()).apply(options).into(iv_teacher); + } } } diff --git a/app/src/main/java/com/hjx/parent/bean/StudentBean.java b/app/src/main/java/com/hjx/parent/bean/StudentBean.java index 8466d05..b2455d2 100644 --- a/app/src/main/java/com/hjx/parent/bean/StudentBean.java +++ b/app/src/main/java/com/hjx/parent/bean/StudentBean.java @@ -22,7 +22,15 @@ public class StudentBean { String grade; String teacherIdentity; int sex; + Integer state; + public void setState(Integer state) { + this.state = state; + } + + public Integer getState() { + return state; + } @Override public String toString() { @@ -47,6 +55,7 @@ public class StudentBean { ", grade=" + grade + ", teacherIdentity=" + teacherIdentity + ", sex=" + sex + + ", state=" + state + '}'; } diff --git a/app/src/main/res/layout/activity_add_stu.xml b/app/src/main/res/layout/activity_add_stu.xml index 602919b..08cc5c3 100644 --- a/app/src/main/res/layout/activity_add_stu.xml +++ b/app/src/main/res/layout/activity_add_stu.xml @@ -158,9 +158,7 @@ android:background="@drawable/bg_solid_white_10" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintTop_toTopOf="parent" - - /> + app:layout_constraintTop_toTopOf="parent" /> - /> + - + + + + + + + + + + + + + + + + + -