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.
149 lines
4.8 KiB
149 lines
4.8 KiB
package com.community.pocket.ui.resetpwd;
|
|
|
|
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 androidx.navigation.fragment.NavHostFragment;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.ui.BaseFragment;
|
|
import com.community.pocket.ui.listener.MyTextChange;
|
|
import com.community.pocket.ui.main.ui.share.Response;
|
|
import com.community.pocket.util.Param;
|
|
|
|
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.step2)
|
|
public class ResetPwdStep2 extends BaseFragment {
|
|
|
|
@ViewInject(R.id.username)
|
|
private EditText username;
|
|
|
|
@ViewInject(R.id.email)
|
|
private EditText email;
|
|
|
|
//验证码
|
|
@ViewInject(R.id.code)
|
|
private EditText code;
|
|
|
|
//发送验证码按钮
|
|
@ViewInject(R.id.sendcode)
|
|
private Button sendCode;
|
|
|
|
//下一步按钮
|
|
@ViewInject(R.id.next)
|
|
private Button next;
|
|
|
|
private ResetPwdViewModel resetPwdViewModel;
|
|
|
|
/**
|
|
* 返回第一步输入账号邮箱
|
|
*/
|
|
@Event(value = R.id.back)
|
|
private void onClick(View view) {
|
|
NavHostFragment.findNavController(ResetPwdStep2.this)
|
|
.navigate(R.id.action_Second2Fragment_to_First2Fragment);
|
|
}
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
username.setText(Objects.requireNonNull(getArguments()).getString(Param.username.name()));
|
|
email.setText(Objects.requireNonNull(getArguments()).getString(Param.email.name()));
|
|
|
|
resetPwdViewModel = new ViewModelProvider(this, new ResetPwdViewModelFactory()).get(ResetPwdViewModel.class);
|
|
|
|
//监听表单数据校验状态
|
|
resetPwdViewModel.getResetPwdFormStep2().observe(getViewLifecycleOwner(), new Observer<ResetPwdFormState.Step2>() {
|
|
@Override
|
|
public void onChanged(ResetPwdFormState.Step2 step2) {
|
|
if (step2 == null) {
|
|
return;
|
|
}
|
|
|
|
next.setEnabled(step2.isDataValid());
|
|
|
|
if (step2.getCodeError() != null) {
|
|
code.setError(getString(step2.getCodeError()));
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
//监听输入框文本
|
|
TextWatcher afterTextChangedListener = new MyTextChange() {
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
resetPwdViewModel.resetpwdStep2Changed(code.getText().toString());
|
|
}
|
|
};
|
|
code.addTextChangedListener(afterTextChangedListener);
|
|
|
|
//监听发送验证码状态
|
|
resetPwdViewModel.getSendCodeResponse().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
|
|
@Override
|
|
public void onChanged(ResetPwdResponse resetPwdResponse) {
|
|
if (resetPwdResponse == null) {
|
|
return;
|
|
}
|
|
|
|
code.setEnabled(resetPwdResponse.getResult() == Response.Result.OK);
|
|
resetPwdResponse.toast(getContext());
|
|
}
|
|
});
|
|
|
|
//监听校验验证码状态
|
|
resetPwdViewModel.getCheckCodeResponse().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
|
|
@Override
|
|
public void onChanged(ResetPwdResponse resetPwdResponse) {
|
|
if (resetPwdResponse == null) {
|
|
return;
|
|
}
|
|
|
|
resetPwdResponse.toast(getContext());
|
|
if (resetPwdResponse.getResult() == Response.Result.OK) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString(Param.username.name(), username.getText().toString());
|
|
NavHostFragment.findNavController(ResetPwdStep2.this)
|
|
.navigate(R.id.action_Second2Fragment_to_threeFragment, bundle);
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 进入下一步重置密码
|
|
*/
|
|
@Event(value = R.id.next)
|
|
private void next(View view) {
|
|
resetPwdViewModel.checkCode(username.getText().toString(), code.getText().toString());
|
|
}
|
|
|
|
/**
|
|
* 发送验证码
|
|
*/
|
|
@Event(value = R.id.sendcode)
|
|
private void sendCode(View view) {
|
|
resetPwdViewModel.sendCode(username.getText().toString(), email.getText().toString());
|
|
}
|
|
}
|
|
|