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.
126 lines
4.3 KiB
126 lines
4.3 KiB
package com.community.pocket.ui.resetpwd;
|
|
|
|
import android.app.Activity;
|
|
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 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.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.step1)
|
|
public class ResetPwdStep1 extends BaseFragment {
|
|
|
|
@ViewInject(R.id.username)
|
|
private EditText username;
|
|
|
|
@ViewInject(R.id.email)
|
|
private EditText email;
|
|
|
|
private ResetPwdViewModel resetPwdViewModel;
|
|
|
|
@ViewInject(R.id.next)
|
|
private Button resetpwdButton;
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
resetPwdViewModel = new ViewModelProvider(this, new ResetPwdViewModelFactory()).get(ResetPwdViewModel.class);
|
|
//监听表单校验状态
|
|
resetPwdViewModel.getResetPwdFormStep1().observe(getViewLifecycleOwner(), new Observer<ResetPwdFormState.Step1>() {
|
|
@Override
|
|
public void onChanged(ResetPwdFormState.Step1 step1) {
|
|
if (step1 == null) {
|
|
return;
|
|
}
|
|
|
|
resetpwdButton.setEnabled(step1.isDataValid());
|
|
|
|
if (step1.getUsernameError() != null) {
|
|
username.setError(getString(step1.getUsernameError(), PropertiesUtil.getIntValue("username.length")));
|
|
}
|
|
if (step1.getEmailError() != null) {
|
|
email.setError(getString(step1.getEmailError(), PropertiesUtil.getIntValue("password.length")));
|
|
}
|
|
}
|
|
});
|
|
|
|
//监听输入框文本
|
|
TextWatcher afterTextChangedListener = new MyTextChange() {
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
resetPwdViewModel.resetpwdStep1Changed(username.getText().toString(), email.getText().toString());
|
|
}
|
|
};
|
|
|
|
username.addTextChangedListener(afterTextChangedListener);
|
|
email.addTextChangedListener(afterTextChangedListener);
|
|
|
|
//监听重置密码第一步请求
|
|
resetPwdViewModel.getResetPwdResultStep1().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Override
|
|
public void onChanged(ResetPwdResponse step1) {
|
|
if (step1 == null) {
|
|
return;
|
|
}
|
|
|
|
step1.toast(getContext());
|
|
|
|
if (step1.getResult() == Response.Result.OK) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString(Param.username.name(), username.getText().toString());
|
|
bundle.putString(Param.email.name(), email.getText().toString());
|
|
|
|
NavHostFragment.findNavController(ResetPwdStep1.this)
|
|
.navigate(R.id.action_First2Fragment_to_Second2Fragment, bundle);
|
|
}
|
|
|
|
|
|
Objects.requireNonNull(getActivity()).setResult(Activity.RESULT_OK);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
//进入下一步发送验证码
|
|
@Event(value = R.id.next)
|
|
private void onClick(View view) {
|
|
resetPwdViewModel.checkUser(username.getText().toString(), email.getText().toString());
|
|
}
|
|
|
|
//返回登陆
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
@Event(value = R.id.back)
|
|
private void back(View view) {
|
|
startActivity(new Intent(getContext(), LoginActivity.class));
|
|
Objects.requireNonNull(getActivity()).finish();
|
|
}
|
|
}
|
|
|