You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.9 KiB
118 lines
3.9 KiB
package com.community.pocket.ui.resetpwd;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.text.Editable;
|
|
import android.text.TextWatcher;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.lifecycle.Observer;
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.ui.BaseFragment;
|
|
import com.community.pocket.ui.listener.MyTextChange;
|
|
import com.community.pocket.ui.login.LoginActivity;
|
|
import com.community.pocket.ui.main.ui.share.Response;
|
|
import com.community.pocket.util.Param;
|
|
import com.community.pocket.util.PropertiesUtil;
|
|
|
|
import org.xutils.view.annotation.ContentView;
|
|
import org.xutils.view.annotation.Event;
|
|
import org.xutils.view.annotation.ViewInject;
|
|
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 重置密码第三步,输入密码
|
|
*/
|
|
@ContentView(R.layout.step3)
|
|
public class ResetPwdStep3 extends BaseFragment {
|
|
|
|
|
|
//密码
|
|
@ViewInject(R.id.password)
|
|
private EditText password;
|
|
|
|
//确认密码
|
|
@ViewInject(R.id.confirmPwd)
|
|
private EditText confirmPassword;
|
|
|
|
//重置密码按钮
|
|
@ViewInject(R.id.reset_pwd)
|
|
private Button resetpwdButton;
|
|
|
|
private ResetPwdViewModel resetPwdViewModel;
|
|
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
resetPwdViewModel = new ViewModelProvider(this, new ResetPwdViewModelFactory()).get(ResetPwdViewModel.class);
|
|
|
|
//监听表单校验状态
|
|
resetPwdViewModel.getResetPwdFormStep3().observe(getViewLifecycleOwner(), new Observer<ResetPwdFormState.Step3>() {
|
|
@Override
|
|
public void onChanged(ResetPwdFormState.Step3 step3) {
|
|
if (step3 == null) {
|
|
return;
|
|
}
|
|
|
|
if (step3.getPasswordError() != null) {
|
|
password.setError(getString(step3.getPasswordError(), PropertiesUtil.getIntValue("password.length")));
|
|
}
|
|
|
|
if (step3.getConfirmPasswordError() != null) {
|
|
confirmPassword.setError(getString(step3.getConfirmPasswordError(), PropertiesUtil.getIntValue("password.length")));
|
|
}
|
|
|
|
resetpwdButton.setEnabled(step3.isDataValid());
|
|
}
|
|
});
|
|
|
|
TextWatcher textWatcher = new MyTextChange() {
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
resetPwdViewModel.resetpwdStep3Changed(password.getText().toString(), confirmPassword.getText().toString());
|
|
}
|
|
};
|
|
|
|
password.addTextChangedListener(textWatcher);
|
|
confirmPassword.addTextChangedListener(textWatcher);
|
|
|
|
resetPwdViewModel.getResetPwdResultStep3().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
|
|
@Override
|
|
public void onChanged(ResetPwdResponse resetPwdResponse) {
|
|
if (resetPwdResponse == null) {
|
|
return;
|
|
}
|
|
|
|
resetPwdResponse.toast(getContext());
|
|
|
|
if (resetPwdResponse.getResult() == Response.Result.OK) {
|
|
startActivity(new Intent(getContext(), LoginActivity.class));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Event(value = R.id.reset_pwd)
|
|
private void resetPwd(View v) {
|
|
resetPwdViewModel.resetPwd(Objects.requireNonNull(getArguments()).getString(Param.username.name()), password.getText().toString());
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Event(value = R.id.back)
|
|
private void back(View v) {
|
|
startActivity(new Intent(getContext(), LoginActivity.class));
|
|
Objects.requireNonNull(getActivity()).finish();
|
|
}
|
|
}
|
|
|