Browse Source

忘记密码

詹子聪 5 years ago
parent
commit
35f623197f

+ 130 - 0
app/src/main/java/com/miekir/ym/ui/home/more/forget/ForgetActivity.java

@@ -0,0 +1,130 @@
+package com.miekir.ym.ui.home.more.forget;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.View;
+
+import com.google.android.material.textfield.TextInputEditText;
+import com.miekir.common.utils.ToastTool;
+import com.miekir.common.utils.ViewTool;
+import com.miekir.mvp.presenter.InjectPresenter;
+import com.miekir.ym.R;
+import com.miekir.ym.base.YangActivity;
+import com.miekir.ym.bean.BeiUser;
+import com.miekir.ym.manager.UserInfoManager;
+import com.miekir.ym.tool.StringTool;
+import com.miekir.ym.ui.home.more.register.CodePresenter;
+import com.miekir.ym.ui.home.more.register.ICodeView;
+
+/**
+ * @author Miekir
+ * @date 2020/6/18 16:48
+ * Description: 登录界面
+ */
+public class ForgetActivity extends YangActivity implements View.OnClickListener, ICodeView, IForgetView {
+    private TextInputEditText et_email;
+    private TextInputEditText et_code;
+    private TextInputEditText et_new_password;
+
+    private String email;
+    private String code;
+    private String password;
+
+    @InjectPresenter
+    private CodePresenter mCodePresenter;
+
+    @InjectPresenter
+    private ForgetPresenter mForgetPresenter;
+
+    @Override
+    public int getLayoutId() {
+        return R.layout.activity_forget;
+    }
+
+    @Override
+    public void initViews(Bundle savedInstanceState) {
+        setTitle("重置密码");
+
+        et_email = findViewById(R.id.et_email);
+        et_code = findViewById(R.id.et_code);
+        et_new_password = findViewById(R.id.et_new_password);
+        ViewTool.setOnClickListener(this, this,
+                new int[]{R.id.btn_get_code, R.id.btn_reset_password});
+    }
+
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.btn_get_code:
+                // 获取验证码
+                email = et_email.getEditableText().toString();
+                if (TextUtils.isEmpty(email)) {
+                    ToastTool.showShort("邮箱不能为空");
+                    return;
+                }
+
+                showLoading();
+                mCodePresenter.getCode(email);
+                break;
+            case R.id.btn_reset_password:
+                email = et_email.getEditableText().toString();
+                if (TextUtils.isEmpty(email)) {
+                    ToastTool.showShort("邮箱不能为空");
+                    return;
+                }
+
+                if (!email.contains("@")) {
+                    ToastTool.showShort("请输入合法的邮箱");
+                    return;
+                }
+
+                // 重设密码
+                code = et_code.getEditableText().toString();
+                if (TextUtils.isEmpty(code)) {
+                    ToastTool.showShort("验证码不能为空");
+                    return;
+                }
+
+                password = et_new_password.getEditableText().toString();
+                if (TextUtils.isEmpty(password)) {
+                    ToastTool.showShort("新密码不能为空");
+                    return;
+                }
+
+                String encodePassword = StringTool.getEncodeString(password);
+                if (TextUtils.isEmpty(encodePassword)) {
+                    ToastTool.showShort("该手机不支持加密算法");
+                    return;
+                }
+                showLoading();
+                mForgetPresenter.submitReset(email, code, encodePassword);
+                break;
+            default:
+                break;
+        }
+    }
+
+    @Override
+    public void onGetCode(boolean isSuccess, String message) {
+        hideLoading();
+        if (isSuccess) {
+            ToastTool.showShort("验证码发送成功");
+        } else {
+            ToastTool.showShort(message);
+        }
+    }
+
+    @Override
+    public void onForgetResult(BeiUser user, String message) {
+        hideLoading();
+        if (user != null) {
+            UserInfoManager.getInstance().setBeiUser(user);
+            ToastTool.showShort("重设密码成功");
+            setResult(RESULT_OK);
+            finish();
+        } else {
+            ToastTool.showShort(message);
+        }
+    }
+}

+ 55 - 0
app/src/main/java/com/miekir/ym/ui/home/more/forget/ForgetPresenter.java

@@ -0,0 +1,55 @@
+package com.miekir.ym.ui.home.more.forget;
+
+import android.text.TextUtils;
+
+import com.miekir.mvp.presenter.BasePresenter;
+import com.miekir.network.RetrofitHelper;
+import com.miekir.network.widget.observe.NetMvpObserver;
+import com.miekir.ym.base.ApiService;
+import com.miekir.ym.bean.BeiUser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+
+/**
+ * @author Miekir
+ * @date 2020/7/9 20:54
+ * Description: 商品的相关数据接口处理
+ */
+public class ForgetPresenter extends BasePresenter<IForgetView> {
+
+    public void submitReset(String email, String code, String password) {
+        NetMvpObserver<BeiUser> observer = new NetMvpObserver<BeiUser>() {
+            @Override
+            public void onSuccess(int code, BeiUser result) {
+                post(view -> view.onForgetResult(result, null));
+            }
+
+            @Override
+            public void onFailure(int code, Throwable e, String errMsg) {
+                post(view -> view.onForgetResult(null, TextUtils.isEmpty(errMsg) ? "密码重设失败" : errMsg));
+            }
+        };
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("email", email);
+        map.put("code", code);
+        map.put("password", password);
+        RetrofitHelper.getInstance()
+                .getRequestApi(ApiService.class)
+                .resetPassword(map)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(observer);
+
+        mProgressDisposableList.add(observer);
+    }
+
+    @Override
+    public void onInit() {
+
+    }
+}

+ 16 - 0
app/src/main/java/com/miekir/ym/ui/home/more/forget/IForgetView.java

@@ -0,0 +1,16 @@
+package com.miekir.ym.ui.home.more.forget;
+
+import com.miekir.mvp.view.IView;
+import com.miekir.ym.bean.BeiUser;
+
+/**
+ * Copyright (C), 2019-2020, Miekir
+ *
+ * @author Miekir
+ * @date 2020/8/2 10:29
+ * Description: 忘记密码的回调
+ */
+public interface IForgetView extends IView {
+
+    void onForgetResult(BeiUser user, String message);
+}

+ 143 - 0
app/src/main/res/layout/activity_forget.xml

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/colorPrimary"
+    android:fitsSystemWindows="true"
+    android:focusable="true"
+    android:focusableInTouchMode="true"
+    android:orientation="vertical">
+    <!--启用深色模式之后,需要使用fitsSystemWindows来不让布局上滑-->
+
+    <include layout="@layout/view_toolbar" />
+    <!--阴影效果android:background="?android:attr/listDivider"-->
+
+
+    <com.google.android.material.textfield.TextInputLayout
+        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/margin_default"
+        android:layout_marginTop="@dimen/margin_default"
+        android:layout_marginEnd="@dimen/margin_default"
+        android:hint="请输入邮箱"
+        app:boxBackgroundMode="outline"
+        app:boxCornerRadiusBottomEnd="4dp"
+        app:boxCornerRadiusBottomStart="4dp"
+        app:boxCornerRadiusTopEnd="4dp"
+        app:boxCornerRadiusTopStart="4dp"
+        app:boxStrokeWidth="@dimen/width_stroke"
+        app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:id="@+id/et_email"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:inputType="textEmailAddress"
+            android:maxLength="50"
+            android:paddingEnd="90dp"
+            android:textSize="@dimen/text_normal_s" />
+    </com.google.android.material.textfield.TextInputLayout>
+
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/margin_default"
+        android:layout_marginTop="@dimen/margin_default"
+        android:layout_marginEnd="@dimen/margin_default">
+
+        <com.google.android.material.textfield.TextInputLayout
+            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="邮箱验证码"
+            android:orientation="horizontal"
+            app:boxBackgroundMode="outline"
+            app:boxCornerRadiusBottomEnd="4dp"
+            app:boxCornerRadiusBottomStart="4dp"
+            app:boxCornerRadiusTopEnd="4dp"
+            app:boxCornerRadiusTopStart="4dp"
+            app:boxStrokeWidth="@dimen/width_stroke"
+            app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+            <com.google.android.material.textfield.TextInputEditText
+                android:id="@+id/et_code"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:digits="0123456789"
+                android:inputType="number"
+                android:maxLength="6"
+                android:textSize="@dimen/text_normal_s" />
+
+        </com.google.android.material.textfield.TextInputLayout>
+
+        <!--去除按钮阴影style="?android:attr/borderlessButtonStyle"-->
+        <!--用android.widget.Button代替Button就不会有Material风格了,当前style下Button的background无效-->
+        <android.widget.Button
+            android:id="@+id/btn_get_code"
+            style="?android:attr/borderlessButtonStyle"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|end"
+            android:elevation="0dp"
+            android:layout_marginTop="@dimen/margin_sss"
+            android:layout_marginEnd="@dimen/margin_ss"
+            android:minWidth="0dp"
+            android:minHeight="0dp"
+            android:paddingStart="@dimen/margin_s"
+            android:paddingTop="@dimen/margin_ss"
+            android:paddingEnd="@dimen/margin_s"
+            android:paddingBottom="@dimen/margin_ss"
+            android:text="获取验证码"
+            android:textColor="@color/green_logo"
+            android:textSize="@dimen/text_s"
+            android:textStyle="bold"
+            android:background="?selectableItemBackground" />
+    </FrameLayout>
+
+
+    <com.google.android.material.textfield.TextInputLayout
+        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/margin_default"
+        android:layout_marginTop="@dimen/margin_default"
+        android:layout_marginEnd="@dimen/margin_default"
+        android:hint="请输入新密码"
+        app:boxBackgroundMode="outline"
+        app:boxCornerRadiusBottomEnd="4dp"
+        app:boxCornerRadiusBottomStart="4dp"
+        app:boxCornerRadiusTopEnd="4dp"
+        app:boxCornerRadiusTopStart="4dp"
+        app:boxStrokeWidth="@dimen/width_stroke"
+        app:boxStrokeWidthFocused="@dimen/width_stroke">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:id="@+id/et_new_password"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:inputType="textPassword"
+            android:maxLength="20"
+            android:textSize="@dimen/text_normal_s" />
+
+    </com.google.android.material.textfield.TextInputLayout>
+
+
+    <android.widget.Button
+        android:id="@+id/btn_reset_password"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:minHeight="0dp"
+        android:layout_marginTop="@dimen/margin_default"
+        android:layout_marginStart="@dimen/margin_default"
+        android:layout_marginEnd="@dimen/margin_default"
+        android:paddingTop="@dimen/padding_full_width"
+        android:paddingBottom="@dimen/padding_full_width"
+        android:text="立即重设密码"
+        android:textColor="@color/white"
+        android:textStyle="bold"
+        android:background="@drawable/selector_btn"
+        style="?android:attr/borderlessButtonStyle"/>
+</LinearLayout>