登录注册

登录布局




    

        

        

    

    

        

            

            

        

        

            

            
        

        

activity

public class LoginActivity extends BaseActivity implements ILoginView {

    @BindView(R.id.finish)
    ImageView finish;
    @BindView(R.id.login_title_relative)
    RelativeLayout loginTitleRelative;
    @BindView(R.id.edit_phone)
    EditText editPhone;
    @BindView(R.id.edit_pwd)
    EditText editPwd;
    @BindView(R.id.btnLogin)
    Button btnLogin;
    @BindView(R.id.text_regist)
    TextView textRegist;

    @Override
    protected LoginPresenter ProvidePresenter() {
        presenter = new LoginPresenter(this);
        return presenter;
    }

    //设置监听
    @Override
    protected void initListener() {

    }

    //初始化数据
    @Override
    protected void initData() {

    }


    //设置布局ID
    @Override
    protected int provideLayoutId() {
        return R.layout.activity_login;
    }


    @Override
    public Context context() {
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
    }

    @OnClick({R.id.finish, R.id.btnLogin, R.id.text_regist})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.finish:
                finish();
                break;
            case R.id.btnLogin:
                String mobile = editPhone.getText().toString();
                String password = editPwd.getText().toString();
                presenter.getLogin(mobile,password);
                break;
            case R.id.text_regist:
                Intent intent = new Intent(this, RegisterActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void Show(LoginBean loginBean) {
        int uid = loginBean.getData().getUid();
        String username = loginBean.getData().getUsername();
        String token = loginBean.getData().getToken();
        SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("name",username);
        editor.putInt("uid",uid);
        editor.putString("token",token);
        editor.commit();
        if (loginBean.getCode().equals("0")){
            Intent intent = new Intent();
            intent.putExtra("uid",uid+"");
            intent.putExtra("token",token);
            setResult(2,intent);
            finish();
        }
        Toast.makeText(this,loginBean.getMsg(),Toast.LENGTH_LONG).show();
    }

    @Override
    public void ShowRegister(RegisterBean registerBean) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
    public void Event(RegistInfoBean registInfoBean){
        String mobile = registInfoBean.getMobile();
        String password = registInfoBean.getPassword();
        editPhone.setText(mobile);
        editPwd.setText(password);
    }

}

注册布局




    

        

        

    

    

        

            

            

        

        

            

            
        

        

activity

public class RegisterActivity extends BaseActivity implements ILoginView {
    @BindView(R.id.finish)
    ImageView finish;
    @BindView(R.id.login_title_relative)
    RelativeLayout loginTitleRelative;
    @BindView(R.id.reg_edit_phone)
    EditText regEditPhone;
    @BindView(R.id.reg_edit_pwd)
    EditText regEditPwd;
    @BindView(R.id.btn_register)
    Button btnRegister;
    private String mobile;
    private String password;

    @Override
    public Context context() {
        return this;
    }

    @Override
    public void Show(LoginBean loginBean) {

    }

    @Override
    public void ShowRegister(RegisterBean registerBean) {
        String msg = registerBean.getMsg();
        String code = registerBean.getCode();
        if (code.equals("0")&&msg.equals("注册成功")){
            EventBus.getDefault().postSticky(new RegistInfoBean(mobile, password));
            finish();
        }else if(code.equals("1")&&msg.equals("天呢!用户已注册")) {
            finish();
        }
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected LoginPresenter ProvidePresenter() {
        presenter = new LoginPresenter(this);
        return presenter;
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected int provideLayoutId() {
        return R.layout.activity_regist;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.finish, R.id.btn_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.finish:
                finish();
                break;
            case R.id.btn_register:
                mobile = regEditPhone.getText().toString().trim();
                password = regEditPwd.getText().toString().trim();
                presenter.getReg(mobile, password);
                break;
        }
    }
}

 

你可能感兴趣的:(电商项目实战)