admin
2022-04-18 34f0d1927d662956202620b8036384a026ceca29
BuWanVideo/src/com/weikou/beibeivideo/ui/login/PhoneLoginActivity.java
@@ -1,6 +1,8 @@
package com.weikou.beibeivideo.ui.login;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
@@ -45,7 +47,7 @@
    private PhoneNumberAuthHelper mPhoneNumberAuthHelper;
    private TextView tv_login_onekey, tv_obtain_verfication_code, tv_title;
    private TextView tv_login_onekey, tv_obtain_verfication_code, tv_title, tv_confirm;
    private EditText et_phone, et_verfication_code;
@@ -65,13 +67,15 @@
        cb_user_agreement = findViewById(R.id.cb_user_agreement);
        et_verfication_code = findViewById(R.id.et_verfication_code);
        tv_title = findViewById(R.id.tv_title);
        tv_confirm = findViewById(R.id.tv_confirm);
        tv_login_onekey.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        tv_login_onekey.getPaint().setAntiAlias(true);//抗锯齿
        tv_obtain_verfication_code.setOnClickListener(this);
        tv_login_onekey.setOnClickListener(this);
        findViewById(R.id.tv_confirm).setOnClickListener(this);
        tv_confirm.setOnClickListener(this);
        findViewById(R.id.tv_back).setOnClickListener(this);
        findViewById(R.id.tv_user_agreement).setOnClickListener(this);
        findViewById(R.id.tv_privacy_policy).setOnClickListener(this);
@@ -92,10 +96,15 @@
        initView();
        login = getIntent().getBooleanExtra("login", false);
        tv_title.setText(login ? "登录" : "绑定手机号");
        tv_confirm.setText(login ? "登录" : "绑定");
        if (login) {
            tv_login_onekey.setVisibility(View.GONE);
        }
        openOneKeyLogin(false);
        if (!login) {
            openOneKeyLogin(false);
        }
    }
@@ -223,7 +232,11 @@
                    break;
                }
                tv_obtain_verfication_code.setEnabled(false);
                sendBindVerifyCode(phone);
                if (login) {
                    sendLoginVerifyCode(phone);
                } else {
                    sendBindVerifyCode(phone);
                }
                break;
@@ -243,7 +256,11 @@
                    SingleToast.showToast(this, "验证码不能为空");
                    return;
                }
                bindPhone(null);
                if (login) {
                    phoneLogin();
                } else {
                    bindPhone(null);
                }
                break;
            case R.id.tv_login_onekey:
@@ -366,6 +383,29 @@
        });
    }
    private void sendLoginVerifyCode(String phone) {
        timer = new Timer();
        timer.schedule(new PhoneLoginActivity.MyTask(), 1000, 1000);
        String loginUid = UserUtil.getLoginUid(this);
        BeibeiVideoAPI.sendLoginVerifyCode(PhoneLoginActivity.this, phone, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optBoolean("IsPost")) {
                    SingleToast.showToast(PhoneLoginActivity.this, "验证码发送成功,请注意查收");
                } else {
                    SingleToast.showToast(PhoneLoginActivity.this, "获取验证码失败,请重新获取!");
                    handler.sendEmptyMessage(1);
                }
            }
            @Override
            public void onFinish() {
                super.onFinish();
                tv_obtain_verfication_code.setEnabled(true);
            }
        });
    }
    private void bindPhone(String accessToken) {
        String loginUid = UserUtil.getLoginUid(this);
@@ -394,7 +434,52 @@
            public void onFinish() {
                super.onFinish();
                DialogUtil.dismiss(loadingDialog);
                mPhoneNumberAuthHelper.quitLoginPage();
                if (mPhoneNumberAuthHelper != null) {
                    mPhoneNumberAuthHelper.quitLoginPage();
                }
            }
        });
    }
    private void phoneLogin() {
        String phone = (et_phone.getText() + "").trim();
        String code = (et_verfication_code.getText() + "").trim();
        BeibeiVideoAPI.phoneLogin(this, phone, code, new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                DialogUtil.show(loadingDialog);
            }
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optBoolean("IsPost")) {
                    JSONObject user = jsonObject.optJSONObject("Data");
                    SharedPreferences.Editor edit = getSharedPreferences("user",
                            Context.MODE_PRIVATE).edit();
                    edit.putString("portrait", user.optString("Portrait"));
                    edit.putString("LoginUid",
                            user.optString("Id"));
                    edit.putString("name",
                            user.optString("Nickname"));
                    edit.commit();
                    //绑定成功
                    Toast.makeText(PhoneLoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    PhoneLoginActivity.this.finish();
                } else {
                    Toast.makeText(PhoneLoginActivity.this, jsonObject.optString("Error"), Toast.LENGTH_SHORT).show();
                }
            }
            @Override
            public void onFinish() {
                super.onFinish();
                DialogUtil.dismiss(loadingDialog);
            }
        });