332 lines
11 KiB
Java
332 lines
11 KiB
Java
package com.xscm.modulelogin.activity;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.text.Editable;
|
|
import android.text.TextUtils;
|
|
import android.text.TextWatcher;
|
|
import android.text.method.PasswordTransformationMethod;
|
|
import android.view.View;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.alipay.sdk.app.AuthTask;
|
|
import com.blankj.utilcode.util.LogUtils;
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
import com.xscm.modulelogin.R;
|
|
import com.xscm.modulelogin.databinding.ActivityLoginBinding;
|
|
import com.xscm.modulelogin.even.LoginFinishEvent;
|
|
import com.xscm.modulelogin.present.LoginContacter;
|
|
import com.xscm.modulelogin.present.LoginPresenter;
|
|
import com.xscm.moduleutil.activity.BaseMvpActivity;
|
|
import com.xscm.moduleutil.bean.ThemeBean;
|
|
import com.xscm.moduleutil.bean.UserBean;
|
|
import com.xscm.moduleutil.utils.BarUtils;
|
|
import com.xscm.moduleutil.utils.PreferencesUtils;
|
|
import com.xscm.moduleutil.base.CommonAppContext;
|
|
import com.tencent.mm.opensdk.modelbase.BaseResp;
|
|
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
|
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* @author
|
|
* @data
|
|
* @description: 密码登录
|
|
*/
|
|
public class LoginActivity extends BaseMvpActivity<LoginPresenter, ActivityLoginBinding> implements LoginContacter.View, View.OnClickListener {
|
|
|
|
|
|
public String mobile;
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.activity_login;
|
|
}
|
|
|
|
@Override
|
|
protected void initData() {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
// EventBus.getDefault().register(this);
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
EventBus.getDefault().unregister(this);
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void finishEvent(LoginFinishEvent event) {
|
|
finish();
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void initView() {
|
|
super.initView();
|
|
BarUtils.setStatusBarAlpha(this, 0);
|
|
mBinding.edPhone.addTextChangedListener(new TextWatcher() {
|
|
@Override
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
setUpLoginBtn();
|
|
}
|
|
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
|
});
|
|
mBinding.edPhone.setOnFocusChangeListener(new View.
|
|
OnFocusChangeListener() {
|
|
@Override
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
|
if (mBinding.edPhone == null) {
|
|
return;
|
|
}
|
|
if (hasFocus) {
|
|
mBinding.relPhone.setSelected(true);
|
|
} else {
|
|
// 此处为失去焦点时的处理内容
|
|
mBinding.relPhone.setSelected(false);
|
|
}
|
|
}
|
|
});
|
|
mBinding.edPassword.setOnFocusChangeListener(new View.
|
|
OnFocusChangeListener() {
|
|
@Override
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
|
if (mBinding.relPhone == null) {
|
|
return;
|
|
}
|
|
if (hasFocus) {
|
|
// 此处为得到焦点时的处理内容
|
|
mBinding.rlCode.setSelected(true);
|
|
} else {
|
|
// 此处为失去焦点时的处理内容
|
|
mBinding.rlCode.setSelected(false);
|
|
}
|
|
}
|
|
});
|
|
mBinding.edPhone.setText(PreferencesUtils.getString(CommonAppContext.getInstance(), "mobile"));
|
|
if (!TextUtils.isEmpty(mobile)) {
|
|
mBinding.edPhone.setText(mobile);
|
|
}
|
|
mBinding.tvCodeText.setOnClickListener(this::onClick);
|
|
mBinding.flLogin.setOnClickListener(this::onClick);
|
|
mBinding.ivZfb.setOnClickListener(this::onClick);
|
|
mBinding.ivWeixin.setOnClickListener(this::onClick);
|
|
mBinding.tvYhxy.setOnClickListener(this::onClick);
|
|
mBinding.tvYsxy.setOnClickListener(this::onClick);
|
|
mBinding.ivEye.setOnClickListener(this::onClick);
|
|
mBinding.tvForgetPassword.setOnClickListener(this::onClick);
|
|
}
|
|
|
|
private void setUpLoginBtn() {
|
|
String text = mBinding.edPhone.getText().toString();
|
|
if (text.length() == 11) {
|
|
mBinding.flLogin.setEnabled(true);
|
|
mBinding.ivLoginBg.setAlpha(1f);
|
|
} else {
|
|
mBinding.ivLoginBg.setAlpha(0.3f);
|
|
mBinding.flLogin.setEnabled(false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected LoginPresenter bindPresenter() {
|
|
return new LoginPresenter(this, this);
|
|
}
|
|
|
|
@Override
|
|
public Activity getSelfActivity() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void showLoadings() {
|
|
showLoading();
|
|
}
|
|
|
|
@Override
|
|
public void showLoadings(String content) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void disLoadings() {
|
|
disLoading();
|
|
}
|
|
|
|
|
|
@Override
|
|
public void sendCodeSuccess1(String phoneNumber) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void loginSuccess(UserBean userBean) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void authorizationSuccess(String s) {
|
|
zfbLogin(s);
|
|
}
|
|
|
|
@Override
|
|
public void ysxlSuccess(String s) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void getThemeData(ThemeBean themeBean) {
|
|
|
|
}
|
|
|
|
boolean isPasswordVisible = false;
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.tv_code_text) {
|
|
// Intent intent = new Intent(this, PasswordLoginActivity.class);
|
|
// intent.putExtra("mobile", mBinding.edPhone.getText().toString());
|
|
// startActivity(intent);
|
|
// finish();
|
|
} else if (id == R.id.fl_login) {
|
|
if (!mBinding.cbPrivacy.isChecked()) {
|
|
com.hjq.toast.ToastUtils.show("请先勾选服务条款");
|
|
return;
|
|
}
|
|
String phoneNumber = mBinding.edPhone.getText().toString().trim();
|
|
String password = mBinding.edPassword.getText().toString().trim();
|
|
if (TextUtils.isEmpty(phoneNumber)) {
|
|
ToastUtils.showShort("请输入手机号");
|
|
return;
|
|
}
|
|
if (TextUtils.isEmpty(password)) {
|
|
ToastUtils.showShort("请输入登录密码");
|
|
return;
|
|
}
|
|
MvpPre.login(phoneNumber, password, "", 2);
|
|
// Intent intent = new Intent(this, MainActivity.class);
|
|
// startActivity(intent);
|
|
// finish();
|
|
} else if (id == R.id.iv_zfb) {
|
|
if (!mBinding.cbPrivacy.isChecked()) {
|
|
com.hjq.toast.ToastUtils.show("请先勾选服务条款");
|
|
return;
|
|
}
|
|
MvpPre.authorization("zfb");
|
|
// zfbLogin();
|
|
} else if (id == R.id.iv_weixin) {
|
|
|
|
if (!mBinding.cbPrivacy.isChecked()) {
|
|
com.hjq.toast.ToastUtils.show("请先勾选服务条款");
|
|
return;
|
|
}
|
|
wcLogin();
|
|
} else if (id == R.id.tv_yhxy) {
|
|
MvpPre.ysxl();
|
|
} else if (id == R.id.tv_ysxy) {
|
|
MvpPre.yhxy();
|
|
} else if (id == R.id.iv_eye) {
|
|
|
|
if (!isPasswordVisible) {
|
|
mBinding.edPassword.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
|
mBinding.ivEye.setImageResource(com.xscm.moduleutil.R.mipmap.eye_visible); // 设置按钮文本为隐藏密码
|
|
} else {
|
|
mBinding.edPassword.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
mBinding.edPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
mBinding.ivEye.setImageResource(com.xscm.moduleutil.R.mipmap.eye_close); // 设置按钮文本为显示密码
|
|
}
|
|
mBinding.edPassword.setSelection(mBinding.edPassword.getText().length()); // 将光标移动到文字末尾
|
|
isPasswordVisible = !isPasswordVisible; // 切换状态
|
|
} else if (id == R.id.tv_forget_password) {
|
|
Intent intent = new Intent(this, ForgetPasswordActivity.class);
|
|
startActivity(intent);
|
|
}
|
|
}
|
|
|
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
|
private void wcLogin() {
|
|
//发起登陆请求前先注册微信api
|
|
IWXAPI api = WXAPIFactory.createWXAPI(this, CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId(), true);
|
|
api.registerApp(CommonAppContext.getInstance().getCurrentEnvironment().getWxAppId());
|
|
if (!api.isWXAppInstalled()) {
|
|
//todo 提醒未安装微信
|
|
ToastUtils.showShort("请安装微信客户端");
|
|
return;
|
|
}
|
|
//开始发起登陆请求
|
|
final SendAuth.Req req = new SendAuth.Req();
|
|
req.scope = "snsapi_userinfo";
|
|
req.state = "wechat_sdk_demo_test";
|
|
api.sendReq(req);
|
|
}
|
|
|
|
private void zfbLogin(String s) {
|
|
LogUtils.e("@@@",s);
|
|
CommonAppContext.getInstance();
|
|
if (!CommonAppContext.isAlipayInstalled(this)){
|
|
ToastUtils.showShort("请安装支付宝客户端");
|
|
return;
|
|
}
|
|
String authInfo = s;
|
|
// String authInfo = "apiname=com.alipay.account.auth&app_id=2021005152631691&app_name=yusheng&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=2088170624624316&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=20141225xxxx&sign=fMcp4GtiM6rxSIeFnJCVePJKV43eXrUP86CQgiLhDHH2u%2FdN75eEvmywc2ulkm7qKRetkU9fbVZtJIqFdMJcJ9Yp%2BJI%2FF%2FpESafFR6rB2fRjiQQLGXvxmDGVMjPSxHxVtIqpZy5FDoKUSjQ2%2FILDKpu3%2F%2BtAtm2jRw1rUoMhgt0%3D";
|
|
Runnable authRunnable = new Runnable() {
|
|
|
|
@Override
|
|
public void run() {
|
|
// 构造AuthTask 对象
|
|
AuthTask authTask = new AuthTask(LoginActivity.this);
|
|
// 调用授权接口,获取授权结果
|
|
Map<String, String> result = authTask.authV2(authInfo, true);
|
|
LogUtils.e(result);
|
|
if (result.get("resultStatus").equals("9000")){
|
|
Pattern pattern = Pattern.compile("auth_code=([^&]*)");
|
|
Matcher matcher = pattern.matcher(result.get("result"));
|
|
|
|
if (matcher.find()) {
|
|
String authCode = matcher.group(1);
|
|
LogUtils.e("AuthCode", authCode);
|
|
MvpPre.oauthLogin(authCode,2);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
Thread authThread = new Thread(authRunnable);
|
|
authThread.start();
|
|
}
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void loginEvent(BaseResp event) {
|
|
if (event.errCode ==BaseResp.ErrCode.ERR_OK){
|
|
SendAuth.Resp authResp = (SendAuth.Resp)event;
|
|
LogUtils.e("@@@",authResp.code);
|
|
MvpPre.oauthLogin(authResp.code,1);
|
|
}
|
|
}
|
|
}
|