|
|
@@ -1,6 +1,7 @@
|
|
|
package com.sheep.gamegroup.module.login.fragments;
|
|
|
|
|
|
|
|
|
+import android.support.design.widget.Snackbar;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.method.HideReturnsTransformationMethod;
|
|
|
@@ -9,6 +10,7 @@ import android.view.View;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
@@ -26,6 +28,7 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
|
@@ -39,6 +42,14 @@ public class SignUpFgt extends BaseFragment {
|
|
|
|
|
|
private LoginController mController;
|
|
|
|
|
|
+ @BindView(R.id.for_phone_container)
|
|
|
+ View forPhoneContainer;
|
|
|
+ @BindView(R.id.for_account_container)
|
|
|
+ View forAccountContainer;
|
|
|
+ @BindView(R.id.phone_number_box)
|
|
|
+ EditText phoneNumberBox;
|
|
|
+ @BindView(R.id.captcha_box)
|
|
|
+ EditText captchaBox;
|
|
|
@BindView(R.id.user_name_box)
|
|
|
EditText userNameBox;
|
|
|
@BindView(R.id.password_box)
|
|
|
@@ -49,11 +60,17 @@ public class SignUpFgt extends BaseFragment {
|
|
|
EditText passwordBox2;
|
|
|
@BindView(R.id.show_hide_pwd_btn2)
|
|
|
ImageView showHidePwdBtn2;
|
|
|
+ @BindView(R.id.register_type_toggle_icon)
|
|
|
+ ImageView registerToggleIcon;
|
|
|
+ @BindView(R.id.register_type_toggle_text)
|
|
|
+ TextView registerToggleText;
|
|
|
|
|
|
//用户协议
|
|
|
@BindView(R.id.tel_agreement_cb)
|
|
|
CheckBox tel_agreement_cb;
|
|
|
|
|
|
+ private int registerType = LoginController.PLATFORM_PHONE;
|
|
|
+
|
|
|
public SignUpFgt() {
|
|
|
// Required empty public constructor
|
|
|
}
|
|
|
@@ -71,7 +88,19 @@ public class SignUpFgt extends BaseFragment {
|
|
|
|
|
|
@Override
|
|
|
public void onViewCreated() {
|
|
|
-
|
|
|
+ if (registerType == LoginController.PLATFORM_ACCOUNT) {
|
|
|
+ TitleBarUtils.getInstance().setTitle(getActivity(), "账号注册");
|
|
|
+ forAccountContainer.setVisibility(View.VISIBLE);
|
|
|
+ forPhoneContainer.setVisibility(View.GONE);
|
|
|
+ registerToggleText.setText("手机注册");
|
|
|
+ registerToggleIcon.setImageResource(R.mipmap.login_phone);
|
|
|
+ } else {
|
|
|
+ TitleBarUtils.getInstance().setTitle(getActivity(), "手机注册");
|
|
|
+ forAccountContainer.setVisibility(View.GONE);
|
|
|
+ forPhoneContainer.setVisibility(View.VISIBLE);
|
|
|
+ registerToggleText.setText("账号注册");
|
|
|
+ registerToggleIcon.setImageResource(R.mipmap.login_account);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@OnClick(R.id.show_hide_pwd_btn)
|
|
|
@@ -87,6 +116,7 @@ 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());
|
|
|
@@ -101,10 +131,106 @@ public class SignUpFgt extends BaseFragment {
|
|
|
passwordBox2.setSelection(passwordBox2.getText().toString().length());
|
|
|
}
|
|
|
|
|
|
+ @OnClick(R.id.send_captcha_btn)
|
|
|
+ public void doSendCaptcha(View v) {
|
|
|
+ String phoneNum = phoneNumberBox.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(phoneNum)) {
|
|
|
+ G.shortToast("请输入手机号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!StringUtils.isMobile(phoneNum)) {
|
|
|
+ G.shortToast("手机号有误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("account", phoneNum);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().getCaptcha(jsonObject)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ Snackbar.make(v, "验证码已发送", Snackbar.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ Snackbar.make(v, "发生错误", Snackbar.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick(R.id.register_type_toggle)
|
|
|
+ public void doToggleLoginType(View view) {
|
|
|
+ registerType = registerType == LoginController.PLATFORM_ACCOUNT ? LoginController.PLATFORM_PHONE : LoginController.PLATFORM_ACCOUNT;
|
|
|
+ onViewCreated();
|
|
|
+ }
|
|
|
+
|
|
|
@OnClick(R.id.register_btn)
|
|
|
public void doRegister(View v) {
|
|
|
- if(checkAgreement()) return;
|
|
|
- if (!validate()) return;
|
|
|
+ if (registerType == LoginController.PLATFORM_ACCOUNT) {
|
|
|
+ registerAccount();
|
|
|
+ } else if (registerType == LoginController.PLATFORM_ACCOUNT) {
|
|
|
+ registerPhone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void registerPhone() {
|
|
|
+ if (checkAgreement()) return;
|
|
|
+ if (!validatePhone()) return;
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("account", phoneNumberBox.getText().toString().trim());
|
|
|
+ jsonObject.put("sec_code", captchaBox.getText().toString().trim());
|
|
|
+ jsonObject.put("invitation_code", ChannelContent.getInstance().getChannel_name());
|
|
|
+ PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE, UMConfigUtils.Source.SHEEP);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().loginByCaptcha(jsonObject)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ G.shortToast(baseMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ if (baseMessage == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LoginEntity loginEty = null;
|
|
|
+ try {
|
|
|
+ loginEty = JSONObject.parseObject(JSONObject.toJSONString(baseMessage.getData()), LoginEntity.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (loginEty != null) {
|
|
|
+ SpUtils.saveToken(getActivity(), loginEty.getToken());
|
|
|
+ DataUtil.getInstance().initUserEntity(loginEty.getUser());
|
|
|
+ mController.whenLoginSuccess(LoginController.PLATFORM_PHONE, loginEty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validatePhone() {
|
|
|
+ String etCode = captchaBox.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(etCode)) {
|
|
|
+ G.shortToast(getString(R.string.input_your_captcha));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (etCode.length() != 6) {
|
|
|
+ G.shortToast(getString(R.string.toast_warning_phone_captcha_image_code_size));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void registerAccount() {
|
|
|
+ if (checkAgreement()) return;
|
|
|
+ if (!validateAccount()) return;
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("user_name", userNameBox.getText().toString().trim());
|
|
|
jsonObject.put("password", passwordBox.getText().toString().trim());
|
|
|
@@ -141,7 +267,7 @@ public class SignUpFgt extends BaseFragment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private boolean validate() {
|
|
|
+ private boolean validateAccount() {
|
|
|
String username = userNameBox.getText().toString().trim();
|
|
|
String password = passwordBox.getText().toString().trim();
|
|
|
String password2 = passwordBox2.getText().toString().trim();
|
|
|
@@ -158,7 +284,11 @@ public class SignUpFgt extends BaseFragment {
|
|
|
return false;
|
|
|
}
|
|
|
if (!StringUtils.isUserName(username)) {
|
|
|
- G.shortToast("用户名只能包含英文、数字、._-@符号,长度4-20");
|
|
|
+ G.shortToast("用户名只能包含英文、数字、._-@符号,且至少包含一个字母,长度4-20");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!StringUtils.containLetter(username)) {
|
|
|
+ G.shortToast("用户名至少包含一个字母");
|
|
|
return false;
|
|
|
}
|
|
|
if (!StringUtils.isPassword(password)) {
|
|
|
@@ -179,7 +309,7 @@ public class SignUpFgt extends BaseFragment {
|
|
|
|
|
|
//检查是否同意用户协议
|
|
|
protected boolean checkAgreement() {
|
|
|
- if(tel_agreement_cb.isChecked()){
|
|
|
+ if (tel_agreement_cb.isChecked()) {
|
|
|
return false;
|
|
|
}
|
|
|
G.showToast("温馨提示:您必须同意用户协议才能继续体验小绵羊APP!");
|