绑定手机
This commit is contained in:
@@ -466,6 +466,17 @@
|
||||
android:label="输入验证码界面"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.login.BindPhoneActivity"
|
||||
android:label="绑定手机号界面"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".ui.login.BindCodeActivity"
|
||||
android:label="绑定输入验证码界面"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".ui.login.QQLoginSelectMemberTypeActivity"
|
||||
android:label="QQ登录界面"
|
||||
|
@@ -49,6 +49,8 @@ import com.yizhuan.erban.common.widget.dialog.DialogUiHelper;
|
||||
import com.yizhuan.erban.common.widget.dialog.LoginPopupDialog;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.erban.ui.login.AddUserInfoActivity;
|
||||
import com.yizhuan.erban.ui.login.BindCodeActivity;
|
||||
import com.yizhuan.erban.ui.login.BindPhoneActivity;
|
||||
import com.yizhuan.erban.ui.login.ErbanQQMemberBindAndLoginActivity;
|
||||
import com.yizhuan.erban.ui.login.ForgetPswActivity;
|
||||
import com.yizhuan.erban.ui.login.LoginActivity;
|
||||
|
@@ -0,0 +1,262 @@
|
||||
package com.yizhuan.erban.ui.login;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.coorchice.library.utils.LogUtils;
|
||||
import com.trello.rxlifecycle2.android.ActivityEvent;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.base.BaseLoginAct;
|
||||
import com.yizhuan.erban.ui.login.ui.CodeEditText;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
|
||||
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
|
||||
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
|
||||
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
|
||||
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
|
||||
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
|
||||
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* @author zhouxiangfeng
|
||||
* @date 17/2/26
|
||||
*/
|
||||
public class BindCodeActivity extends BaseLoginAct {
|
||||
|
||||
private static final String TAG = "LoginVertificationActivity";
|
||||
|
||||
private CodeEditText codeEt;
|
||||
private TextView tvGetCode,tvDesc,tvSecond;
|
||||
private String mPhone;
|
||||
private boolean isSuperAdmin = false;
|
||||
private CodeDownDescTimer timer;
|
||||
private static final String TYPE_SMS = "1";
|
||||
|
||||
public static void start(Context context,String phone) {
|
||||
Intent intent = new Intent(context, BindCodeActivity.class);
|
||||
intent.putExtra("phone",phone);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void startForResult(Activity context,String phone, int requestCode) {
|
||||
Intent intent = new Intent(context, BindCodeActivity.class);
|
||||
intent.putExtra("phone",phone);
|
||||
context.startActivityForResult(intent, requestCode); // startActivityForResult会导致singletop,singletask失效
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login_code);
|
||||
initTitleBar("",true);
|
||||
onFindViews();
|
||||
initData();
|
||||
onSetListener();
|
||||
getSmsCode();
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void initData() {
|
||||
mPhone = getIntent().getStringExtra("phone");
|
||||
|
||||
codeEt.setFocusable(true);
|
||||
codeEt.setFocusableInTouchMode(true);
|
||||
codeEt.requestFocus();
|
||||
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setStatusBar() {
|
||||
StatusBarLightModes(true);
|
||||
}
|
||||
|
||||
private void onFindViews() {
|
||||
codeEt = findViewById(R.id.et_code);
|
||||
tvGetCode = findViewById(R.id.tv_get_code);
|
||||
tvDesc = findViewById(R.id.tv_desc);
|
||||
tvSecond = findViewById(R.id.tv_second);
|
||||
}
|
||||
|
||||
private void onSetListener() {
|
||||
codeEt.setOnTextFinishListener(new CodeEditText.OnTextFinishListener() {
|
||||
@Override
|
||||
public void onTextFinish(CharSequence text, int length) {
|
||||
bindPhone();
|
||||
}
|
||||
});
|
||||
|
||||
tvGetCode.setOnClickListener(v -> {
|
||||
getSmsCode();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needSteepStateBar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
codeEt = null;
|
||||
super.onDestroy();
|
||||
stopCountDownTimer();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
View view = getCurrentFocus();
|
||||
boolean isPressEdit = false;
|
||||
if (view instanceof EditText) {
|
||||
if (event.getRawX() >= view.getX() && event.getRawX() <= view.getX() + view.getWidth() && event.getRawY() >= view.getY() && event.getRawY() <= view.getY() + view.getHeight()) {
|
||||
isPressEdit = true;
|
||||
}
|
||||
}
|
||||
if (!isPressEdit) {
|
||||
hideIME();
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void getSmsCode() {
|
||||
if (mPhone.length() != 11){
|
||||
return;
|
||||
}
|
||||
AuthModel.get()
|
||||
.sendLoginCode(mPhone,TYPE_SMS)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe(new SingleObserver<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
tvDesc.setText(getString(R.string.str_send_code_success)+mPhone);
|
||||
startCountDownTimer();
|
||||
toast(s);
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
toast(e.getMessage());
|
||||
// finish();
|
||||
LogUtils.e( "获取短信失败!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void dealWithLoginError(Throwable e) {
|
||||
if (!(e instanceof IsSuperAdminException)) {
|
||||
String msg = e.getMessage();
|
||||
StringBuilder eventLabel = new StringBuilder("登录注册页-登录失败");
|
||||
if (!TextUtils.isEmpty(msg)) {
|
||||
eventLabel.append(msg);
|
||||
}
|
||||
// 2004可以完整写入
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.Event.EVENT_LOGIN_FAILED_CLICK, eventLabel.toString());
|
||||
}
|
||||
if (e instanceof BanAccountException) {
|
||||
isSuperAdmin = false;
|
||||
BanAccountException exception = (BanAccountException) e;
|
||||
String text = "您的账号因" + exception.getMessage() + "被封禁\n解封时间:";
|
||||
int start = text.length();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
|
||||
text += simpleDateFormat.format(new Date(exception.getDate()));
|
||||
SpannableString spannableString = new SpannableString(text);
|
||||
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(BindCodeActivity.this, R.color.appColor)),
|
||||
start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
getDialogManager().showOkCancelWithTitleDialog("您被封号了",
|
||||
spannableString, "确定", "取消", null);
|
||||
} else if (e instanceof ShowPhoneCodeException) {
|
||||
isSuperAdmin = false;
|
||||
ShowPhoneCodeException showPhoneCodeException = (ShowPhoneCodeException) e;
|
||||
toast(e.getMessage());
|
||||
} else {
|
||||
isSuperAdmin = false;
|
||||
toast(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void startCountDownTimer() {
|
||||
stopCountDownTimer();
|
||||
timer = new CodeDownDescTimer(tvSecond, tvGetCode,60000, 1000);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
private void stopCountDownTimer() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void bindPhone() {
|
||||
getDialogManager().showProgressDialog(BindCodeActivity.this, "正在绑定请稍后...");
|
||||
AuthModel.get().bindPhone(
|
||||
mPhone,
|
||||
codeEt.getText().toString()
|
||||
)
|
||||
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
||||
.subscribe(new SingleObserver<UserInfo>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(UserInfo s) {
|
||||
getDialogManager().dismissDialog();
|
||||
toast("绑定手机号成功");
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
getDialogManager().dismissDialog();
|
||||
toast(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,175 @@
|
||||
package com.yizhuan.erban.ui.login;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.base.BaseActivity;
|
||||
import com.yizhuan.erban.ui.login.helper.LogoutHelper;
|
||||
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
|
||||
import com.yizhuan.xchat_android_library.utils.NetworkUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.TextWatcherWrapper;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
/**
|
||||
* @author zhouxiangfeng
|
||||
* @date 17/2/26
|
||||
*/
|
||||
public class BindPhoneActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = "LoginPhoneActivity";
|
||||
|
||||
private EditText accountEt;
|
||||
private Button btnNext;
|
||||
private ImageView ivBack;
|
||||
public static final String KEY_BACK_LOGIN = "key_back_login";
|
||||
private int REQUEST_CODE = 100;
|
||||
|
||||
private AccountValidator accountValidator = new AccountValidator();
|
||||
private TextWatcher textWatcher = new TextWatcherWrapper() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
checkInput();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static void start(Context context) {
|
||||
Intent intent = new Intent(context, BindPhoneActivity.class);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void startForResult(Activity context, int requestCode) {
|
||||
Intent intent = new Intent(context, BindPhoneActivity.class);
|
||||
context.startActivityForResult(intent, requestCode); // startActivityForResult会导致singletop,singletask失效
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login_phone);
|
||||
onFindViews();
|
||||
onSetListener();
|
||||
|
||||
accountEt.setFocusable(true);
|
||||
accountEt.setFocusableInTouchMode(true);
|
||||
accountEt.requestFocus();
|
||||
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
// permission();
|
||||
// showLoginTip();
|
||||
// AuthModel.get().isFromLogin = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setStatusBar() {
|
||||
StatusBarLightModes(true);
|
||||
}
|
||||
|
||||
private void onFindViews() {
|
||||
accountEt = findViewById(R.id.et_account);
|
||||
btnNext = findViewById(R.id.btn_next);
|
||||
ivBack = findViewById(R.id.iv_back);
|
||||
}
|
||||
|
||||
private void onSetListener() {
|
||||
btnNext.setOnClickListener(this);
|
||||
btnNext.setEnabled(false);
|
||||
accountEt.addTextChangedListener(textWatcher);
|
||||
ivBack.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private void checkInput() {
|
||||
if (!TextUtils.isEmpty(accountEt.getText().toString()) && accountEt.getText().toString().length() >= 7) {
|
||||
btnNext.setEnabled(true);
|
||||
} else {
|
||||
btnNext.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btn_next:
|
||||
if (!NetworkUtils.isNetworkStrictlyAvailable(this)) {
|
||||
checkNetToast();
|
||||
return;
|
||||
}
|
||||
if (!accountValidator.isValid(accountEt.getText().toString())) {
|
||||
toast(accountValidator.getErrorMessage());
|
||||
return;
|
||||
}
|
||||
BindCodeActivity.startForResult(BindPhoneActivity.this,accountEt.getText().toString(),REQUEST_CODE);
|
||||
break;
|
||||
|
||||
case R.id.iv_back:
|
||||
handleFinish();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE &&resultCode == RESULT_OK){
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needSteepStateBar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
accountEt = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
View view = getCurrentFocus();
|
||||
boolean isPressEdit = false;
|
||||
if (view instanceof EditText) {
|
||||
if (event.getRawX() >= view.getX() && event.getRawX() <= view.getX() + view.getWidth() && event.getRawY() >= view.getY() && event.getRawY() <= view.getY() + view.getHeight()) {
|
||||
isPressEdit = true;
|
||||
}
|
||||
}
|
||||
if (!isPressEdit) {
|
||||
hideIME();
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
handleFinish();
|
||||
}
|
||||
|
||||
private void handleFinish() {
|
||||
LogoutHelper.logout();
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.yizhuan.xchat_android_core.auth.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录成功事件
|
||||
*/
|
||||
@Data
|
||||
public class BindPhoneEvent {
|
||||
|
||||
}
|
Reference in New Issue
Block a user