Explorar el Código

添加确认密码和用户协议到注册界面

zengjiebin hace 7 años
padre
commit
3beaba0a9b

+ 0 - 1
app/src/main/java/com/sheep/gamegroup/module/login/LoginAct.java

@@ -11,7 +11,6 @@ import android.view.Menu;
 import com.sheep.gamegroup.absBase.BaseUMActivity;
 import com.sheep.gamegroup.greendao.DDProviderHelper;
 import com.sheep.gamegroup.model.entity.LoginEntity;
-import com.sheep.gamegroup.model.util.EntityUtils;
 import com.sheep.gamegroup.module.login.controller.LoginController;
 import com.sheep.gamegroup.module.login.fragments.EditUserInfoFgt;
 import com.sheep.gamegroup.module.login.fragments.FindAccountFgt;

+ 47 - 1
app/src/main/java/com/sheep/gamegroup/module/login/fragments/SignUpFgt.java

@@ -6,6 +6,7 @@ import android.text.TextUtils;
 import android.text.method.HideReturnsTransformationMethod;
 import android.text.method.PasswordTransformationMethod;
 import android.view.View;
+import android.widget.CheckBox;
 import android.widget.EditText;
 import android.widget.ImageView;
 
@@ -16,6 +17,7 @@ import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.login.controller.LoginController;
 import com.sheep.gamegroup.util.ChannelContent;
 import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.PreferenceUtils;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.UMConfigUtils;
@@ -43,6 +45,14 @@ public class SignUpFgt extends BaseFragment {
     EditText passwordBox;
     @BindView(R.id.show_hide_pwd_btn)
     ImageView showHidePwdBtn;
+    @BindView(R.id.password_box2)
+    EditText passwordBox2;
+    @BindView(R.id.show_hide_pwd_btn2)
+    ImageView showHidePwdBtn2;
+
+    //用户协议
+    @BindView(R.id.tel_agreement_cb)
+    CheckBox tel_agreement_cb;
 
     public SignUpFgt() {
         // Required empty public constructor
@@ -77,9 +87,23 @@ public class SignUpFgt extends BaseFragment {
         }
         passwordBox.setSelection(passwordBox.getText().toString().length());
     }
+    @OnClick(R.id.show_hide_pwd_btn2)
+    public void doShowHidePwd2(View v) {
+        showHidePwdBtn2.setSelected(!showHidePwdBtn2.isSelected());
+        showHidePwdBtn2.setImageResource(showHidePwdBtn2.isSelected() ? R.mipmap.pwd_show : R.mipmap.pwd_hide);
+        if (showHidePwdBtn2.isSelected()) {
+            //如果选中,显示密码
+            passwordBox2.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
+        } else {
+            //否则隐藏密码
+            passwordBox2.setTransformationMethod(PasswordTransformationMethod.getInstance());
+        }
+        passwordBox2.setSelection(passwordBox2.getText().toString().length());
+    }
 
     @OnClick(R.id.register_btn)
     public void doRegister(View v) {
+        if(checkAgreement()) return;
         if (!validate()) return;
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("user_name", userNameBox.getText().toString().trim());
@@ -109,7 +133,7 @@ public class SignUpFgt extends BaseFragment {
                             e.printStackTrace();
                         }
                         if (loginEty != null) {
-                            SpUtils.saveToken(getActivity(), loginEty.getToken());
+                            SpUtils.saveToken(SheepApp.getInstance(), loginEty.getToken());
                             DataUtil.getInstance().initUserEntity(loginEty.getUser());
                             mController.whenLoginSuccess(LoginController.PLATFORM_ACCOUNT, loginEty);
                         }
@@ -120,6 +144,7 @@ public class SignUpFgt extends BaseFragment {
     private boolean validate() {
         String username = userNameBox.getText().toString().trim();
         String password = passwordBox.getText().toString().trim();
+        String password2 = passwordBox2.getText().toString().trim();
         if (TextUtils.isEmpty(username)) {
             G.shortToast("请输入用户名");
             return false;
@@ -128,6 +153,10 @@ public class SignUpFgt extends BaseFragment {
             G.shortToast("请输入密码");
             return false;
         }
+        if (TextUtils.isEmpty(password2)) {
+            G.shortToast("请确认密码");
+            return false;
+        }
         if (!StringUtils.isUserName(username)) {
             G.shortToast("用户名只能包含英文、数字、._-@符号,长度4-20");
             return false;
@@ -136,7 +165,24 @@ public class SignUpFgt extends BaseFragment {
             G.shortToast("密码只能包含英文、数字、_.-@$!*%符号,长度6-16");
             return false;
         }
+        if (!TextUtils.equals(password, password2)) {
+            G.shortToast("两次输入的密码不相同");
+            return false;
+        }
         return true;
     }
 
+    @OnClick(R.id.tel_agreement_tv)
+    public void showAgreement(View v) {
+        Jump2View.getInstance().tryShowAgreement(SheepApp.getInstance().getCurrentActivity(), G::showToast);
+    }
+
+    //检查是否同意用户协议
+    protected boolean checkAgreement() {
+        if(tel_agreement_cb.isChecked()){
+            return false;
+        }
+        G.showToast("温馨提示:您必须同意用户协议才能继续体验小绵羊APP!");
+        return true;
+    }
 }

+ 3 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/G.java

@@ -69,6 +69,9 @@ public class G {
      * @param duration 显示的时长
      */
     public static void showToast(String msg, int duration) {
+        if(TextUtils.isEmpty(msg)){
+            return;
+        }
         Toast.makeText(SheepApp.getInstance(), msg, duration).show();
 //        if (mToast == null) {
 //            mToast = Toast.makeText(SheepApp.getInstance(), msg, duration);

+ 45 - 2
app/src/main/res/layout/fragment_sign_up.xml

@@ -1,5 +1,4 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
@@ -28,7 +27,6 @@
                 android:id="@+id/password_box"
                 android:layout_weight="1"
                 style="@style/login_edit_style"
-                android:layout_below="@+id/user_name_box"
                 android:hint="输入密码(6-16位)"
                 android:inputType="textPassword"
                 android:lines="1"
@@ -44,6 +42,30 @@
         </LinearLayout>
 
         <View style="@style/login_separetor_line_style" />
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <EditText
+                android:id="@+id/password_box2"
+                android:layout_weight="1"
+                style="@style/login_edit_style"
+                android:hint="确认密码"
+                android:inputType="textPassword"
+                android:lines="1"
+                android:maxLength="16" />
+            <ImageView
+                android:id="@+id/show_hide_pwd_btn2"
+                android:src="@mipmap/pwd_hide"
+                android:layout_marginTop="26dp"
+                android:tint="@color/bg_line"
+                android:padding="7dp"
+                android:layout_width="30dp"
+                android:layout_height="30dp" />
+        </LinearLayout>
+
+        <View style="@style/login_separetor_line_style" />
     </LinearLayout>
 
     <Button
@@ -52,4 +74,25 @@
         android:layout_marginTop="50dp"
         android:text="注册" />
 
+    <LinearLayout
+        android:id="@+id/tel_agreement_ll"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:layout_marginTop="40dp"
+        android:gravity="center">
+        <android.support.v7.widget.AppCompatCheckBox
+            android:id="@+id/tel_agreement_cb"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:button="@drawable/drawable_selector_check"/>
+        <TextView
+            android:id="@+id/tel_agreement_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="5dp"
+            android:text="我已阅读并同意《小绵羊平台用户协议》"
+            android:textColor="@color/G"
+            android:textSize="12sp"/>
+    </LinearLayout>
 </LinearLayout>

BIN
app/src/main/res/mipmap-xxhdpi/icon_select.png


BIN
app/src/main/res/mipmap-xxhdpi/icon_select.webp


BIN
app/src/main/res/mipmap-xxhdpi/icon_select_nor.png


BIN
app/src/main/res/mipmap-xxhdpi/icon_select_nor.webp