| | |
| | | import androidx.annotation.Nullable; |
| | | import androidx.annotation.StringRes; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProvider; |
| | | |
| | | import com.duqing.missions.R; |
| | | import com.duqing.missions.base.activities.BaseTitleBarActivity; |
| | |
| | | @Override |
| | | public void initViews() { |
| | | |
| | | |
| | | final EditText phoneEdit = binding.editPhone; |
| | | final EditText passwordEditText = binding.editPassword; |
| | | final Button loginButton = binding.login; |
| | | |
| | | |
| | | viewModel.getLoginFormState().observe(this, new Observer<LoginFormState>() { |
| | | @Override |
| | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | viewModel.getLoginResult().observe(this, new Observer<LoginResult>() { |
| | | @Override |
| | | public void onChanged(@Nullable LoginResult loginResult) { |
| | |
| | | finish(); |
| | | } |
| | | }); |
| | | |
| | | binding.txtPasswordTitle.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | unCheckStyle(binding.txtVerifyTitle); |
| | | } |
| | | }); |
| | | |
| | | binding.txtVerifyTitle.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | unCheckStyle(binding.txtPasswordTitle); |
| | | } |
| | | }); |
| | | |
| | | TextWatcher afterTextChangedListener = new TextWatcher() { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| | |
| | | phoneEdit.addTextChangedListener(afterTextChangedListener); |
| | | passwordEditText.addTextChangedListener(afterTextChangedListener); |
| | | passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { |
| | | |
| | | @Override |
| | | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
| | | if (actionId == EditorInfo.IME_ACTION_DONE) { |
| | |
| | | return false; |
| | | } |
| | | }); |
| | | |
| | | loginButton.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | passwordEditText.getText().toString()); |
| | | } |
| | | }); |
| | | |
| | | viewModel.getCountDown().observe(this, new Observer<Long>() { |
| | | @Override |
| | | public void onChanged(Long l) { |
| | | if(l>0){ |
| | | binding.textVerify.setTextColor(getResources().getColor(R.color.gray)); |
| | | binding.textVerify.setEnabled(false); |
| | | binding.textVerify.setText("重新发送("+l+"s)"); |
| | | }else{ |
| | | binding.textVerify.setEnabled(true); |
| | | binding.textVerify.setTextColor(getResources().getColor(R.color.sky)); |
| | | binding.textVerify.setText("获取验证码"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | binding.textVerify.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | viewModel.startCountDown(0); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ViewModelProvider.Factory getViewModelFactory() { |
| | | return new LoginViewModelFactory(); |
| | | } |
| | | |
| | | public void checkedStyle(TextView textView){ |