用户登录、注册、重置密码接口逻辑完善

封装自定义响应提示逻辑
0515
panqihua 5 years ago
parent c6b093e822
commit 9183754134
  1. 24
      app/src/main/java/com/community/pocket/data/login/LoginRequest.java
  2. 2
      app/src/main/java/com/community/pocket/data/main/garbage/GarbageSortingRequest.java
  3. 21
      app/src/main/java/com/community/pocket/data/register/RegisterRequest.java
  4. 48
      app/src/main/java/com/community/pocket/data/resetpwd/ResetPwdRequest.java
  5. 18
      app/src/main/java/com/community/pocket/ui/login/LoginActivity.java
  6. 40
      app/src/main/java/com/community/pocket/ui/login/LoginResponse.java
  7. 3
      app/src/main/java/com/community/pocket/ui/login/LoginViewModel.java
  8. 3
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingFragment.java
  9. 13
      app/src/main/java/com/community/pocket/ui/main/ui/garbage/waste/GarbageWasteFragment.java
  10. 50
      app/src/main/java/com/community/pocket/ui/main/ui/share/Response.java
  11. 24
      app/src/main/java/com/community/pocket/ui/main/ui/share/ToastResponse.java
  12. 13
      app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java
  13. 52
      app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java
  14. 10
      app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java
  15. 53
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java
  16. 10
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java
  17. 36
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java
  18. 11
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java
  19. 27
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java
  20. 14
      app/src/main/java/com/community/pocket/util/CustomMessage.java
  21. 16
      app/src/main/java/com/community/pocket/util/SimpleHttpParse.java
  22. 4
      app/src/main/res/layout/activity_login.xml
  23. 10
      app/src/main/res/layout/activity_register.xml
  24. 4
      app/src/main/res/layout/resetpwd/layout/step1.xml
  25. 8
      app/src/main/res/layout/resetpwd/layout/step2.xml
  26. 4
      app/src/main/res/layout/resetpwd/layout/step3.xml
  27. 7
      app/src/main/res/values-en-rUS/strings.xml
  28. 7
      app/src/main/res/values-zh-rCN/strings.xml
  29. 7
      app/src/main/res/values/strings.xml

@ -1,13 +1,18 @@
package com.community.pocket.data.login;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.R;
import com.community.pocket.data.model.Token;
import com.community.pocket.ui.login.LoginResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import okhttp3.FormBody;
/**
* 登陆请求接口
* TODO 完善逻辑
*/
public class LoginRequest {
private static volatile LoginRequest instance;
@ -22,14 +27,13 @@ public class LoginRequest {
return instance;
}
public LoginResponse login(String username, String password) {
Token token = new Token();
token.setTime(System.currentTimeMillis());
token.setToken("123");
@HttpRequest("/login")
public void login(MutableLiveData<LoginResponse> liveData, String username, String password) {
LoginResponse loginResponse = new LoginResponse();
loginResponse.setSuccess(R.string.login_ok, username);
loginResponse.setBody(token);
return loginResponse;
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<LoginResponse>(liveData, R.string.register_ok, null).getInterface(LoginResponse.class),
new FormBody.Builder()
.add("username", username)
.add("password", password)
.build());
}
}

@ -31,7 +31,7 @@ public class GarbageSortingRequest {
@HttpRequest("/garbage/sorting")
public void search(MutableLiveData<GarbageSortingResponse> liveData, String name) {
HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<GarbageSortingResponse>(liveData, R.string.garbage_search_ok, R.string.garbage_search_ok).getInterface(GarbageSortingResponse.class),
new SimpleHttpParse<GarbageSortingResponse>(liveData, R.string.garbage_search_ok, null).getInterface(GarbageSortingResponse.class),
new FormBody.Builder().add("name", name).build());
}
}

@ -1,6 +1,13 @@
package com.community.pocket.data.register;
import com.community.pocket.util.Valid;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.ui.register.RegisterResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import okhttp3.FormBody;
/**
* 该类请求注册接口完成注册操作
@ -18,8 +25,14 @@ public class RegisterRequest {
return instance;
}
//TODO 接口请求逻辑
public Valid register(String username, String password, String confirmPassword, String mobilePhone, String email) {
return Valid.ok;
@HttpRequest("/register")
public void register(MutableLiveData<RegisterResponse> liveData, String username, String password, String mobilePhone, String email) {
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<RegisterResponse>(liveData).getInterface(RegisterResponse.class),
new FormBody.Builder()
.add("username", username)
.add("password", password)
.add("mobilePhone", mobilePhone)
.add("email", email)
.build());
}
}

@ -1,10 +1,16 @@
package com.community.pocket.data.resetpwd;
import androidx.lifecycle.MutableLiveData;
import com.community.pocket.ui.resetpwd.ResetPwdResponse;
import com.community.pocket.util.HttpRequest;
import com.community.pocket.util.HttpUtil;
import com.community.pocket.util.SimpleHttpParse;
import okhttp3.FormBody;
/**
* 重置密码请求
* TODO 接口请求逻辑完善
*/
public class ResetPwdRequest {
private static volatile ResetPwdRequest instance;
@ -21,34 +27,50 @@ public class ResetPwdRequest {
/**
* 检查用户邮箱
* TODO R.string.resetpwd_step1_ok
*/
public ResetPwdResponse checkUser(String username, String email) {
return new ResetPwdResponse();
@HttpRequest("/resetpwd/checkUser")
public void checkUser(MutableLiveData<ResetPwdResponse> liveData, String username, String email) {
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<ResetPwdResponse>(liveData).getInterface(ResetPwdResponse.class),
new FormBody.Builder()
.add("username", username)
.add("email", email)
.build());
}
/**
* 发送验证码
* TODO R.string.resetpwd_step2_ok
*/
public ResetPwdResponse sendCode(String username, String email) {
return new ResetPwdResponse();
@HttpRequest("/resetpwd/sendCode")
public void sendCode(MutableLiveData<ResetPwdResponse> liveData, String username, String email) {
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<ResetPwdResponse>(liveData).getInterface(ResetPwdResponse.class),
new FormBody.Builder()
.add("username", username)
.add("email", email)
.build());
}
/**
* 检查验证码
* TODO R.string.resetpwd_step2_valid_ok
*/
public ResetPwdResponse checkCode(String username, String email, String code) {
return new ResetPwdResponse();
@HttpRequest("/resetpwd/checkCode")
public void checkCode(MutableLiveData<ResetPwdResponse> liveData, String username, String code) {
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<ResetPwdResponse>(liveData).getInterface(ResetPwdResponse.class),
new FormBody.Builder()
.add("username", username)
.add("code", code)
.build());
}
/**
* 重置密码
* TODO R.string.resetpwd_step3_ok
*/
public ResetPwdResponse resetPwd(String username, String password) {
return new ResetPwdResponse();
@HttpRequest("/resetpwd/resetPwd")
public void resetPwd(MutableLiveData<ResetPwdResponse> liveData, String username, String password) {
HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse<ResetPwdResponse>(liveData).getInterface(ResetPwdResponse.class),
new FormBody.Builder()
.add("username", username)
.add("password", password)
.build());
}
}

@ -10,7 +10,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
@ -21,6 +20,7 @@ import com.community.pocket.R;
import com.community.pocket.ui.BaseActivity;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.MainMenu;
import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.ui.register.RegisterActivity;
import com.community.pocket.ui.resetpwd.ResetPwdActivity;
import com.community.pocket.util.PropertiesUtil;
@ -85,18 +85,14 @@ public class LoginActivity extends BaseActivity {
return;
}
loadingProgressBar.setVisibility(View.GONE);
if (loginResponse.getError() != null) {
Toast.makeText(getApplicationContext(), loginResponse.fail(getApplicationContext()), Toast.LENGTH_SHORT).show();
}
if (loginResponse.getSuccess() != null) {
Toast.makeText(getApplicationContext(), loginResponse.ok(getApplicationContext()), Toast.LENGTH_SHORT).show();
}
setResult(Activity.RESULT_OK);
startActivity(new Intent(getApplicationContext(), MainMenu.class));
//Complete and destroy login activity once successful
finish();
loginResponse.toast(getBaseContext());
if (loginResponse.getResult() == Response.Result.OK) {
startActivity(new Intent(getBaseContext(), MainMenu.class));
//Complete and destroy login activity once successful
finish();
}
}
});

@ -1,11 +1,47 @@
package com.community.pocket.ui.login;
import androidx.annotation.StringRes;
import com.community.pocket.R;
import com.community.pocket.data.model.Token;
import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.ui.main.ui.share.ToastResponse;
import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull;
/**
* 登陆响应结果
*/
public class LoginResponse extends Response<Token> {
public class LoginResponse extends ToastResponse<LoginResponse.Msg> {
private Token token;
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
enum Msg implements CustomMessage {
ok(R.string.login_ok),
fail(R.string.login_fail);
private Integer msg;
Msg(@StringRes Integer msg) {
this.msg = msg;
}
@NotNull
@Override
public Integer getMsg() {
return msg;
}
public void setMsg(Integer msg) {
this.msg = msg;
}
}
}

@ -28,8 +28,7 @@ public class LoginViewModel extends BaseViewModel<LoginRequest> {
//登陆
public void login(String username, String password) {
LoginResponse response = getRequest().login(username, password);
loginResult.setValue(response);
getRequest().login(loginResult, username, password);
}
//登陆表单数据变化触发数据校验

@ -6,7 +6,6 @@ import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -68,7 +67,7 @@ public class GarbageSortingFragment extends BaseFragment {
}
if (garbageSortingResponse.getError() != null) {
Toast.makeText(getContext(), garbageSortingResponse.ok(getContext()), Toast.LENGTH_SHORT).show();
garbageSortingResponse.fail(getContext());
}
}
});

@ -7,7 +7,6 @@ import android.view.Gravity;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -23,6 +22,7 @@ import com.community.pocket.data.model.GarbageWastePrice;
import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.listener.MyTextChange;
import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView;
import com.community.pocket.ui.main.ui.share.Response;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
@ -73,7 +73,7 @@ public class GarbageWasteFragment extends BaseFragment {
}
if (garbageWasteResponse.getError() != null) {
Toast.makeText(getContext(), garbageWasteResponse.fail(getContext()), Toast.LENGTH_SHORT).show();
garbageWasteResponse.fail(getContext());
}
}
});
@ -86,12 +86,11 @@ public class GarbageWasteFragment extends BaseFragment {
return;
}
if (garbageWasteResponse.getSuccess() != null) {
initSearch(garbageWasteResponse.getBody());
}
if (garbageWasteResponse.getError() != null) {
Toast.makeText(getContext(), garbageWasteResponse.fail(getContext()), Toast.LENGTH_SHORT).show();
if (garbageWasteResponse.getResult() == Response.Result.OK) {
initSearch(garbageWasteResponse.getBody());
} else {
garbageWasteResponse.fail(getContext());
}
}
});

@ -1,10 +1,13 @@
package com.community.pocket.ui.main.ui.share;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.community.pocket.R;
import com.google.gson.Gson;
/**
@ -15,11 +18,13 @@ import com.google.gson.Gson;
public abstract class Response<T> {
//成功描述
@Nullable
@Deprecated
private Integer success;
//失败描述
@Nullable
@Deprecated
private Integer error;
//描述参数
private Object[] args;
//响应体
private T body;
@ -46,23 +51,29 @@ public abstract class Response<T> {
}
@Nullable
@Deprecated
// TODO 废弃
public Integer getSuccess() {
return success;
}
public void setSuccess(@Nullable Integer success, Object... args) {
@Deprecated
// TODO 废弃
public void setSuccess(@Nullable @StringRes Integer success) {
this.success = success;
this.args = args;
}
@Nullable
@Deprecated
// TODO 废弃
public Integer getError() {
return error;
}
public void setError(@Nullable Integer error, Object... args) {
@Deprecated
// TODO 废弃
public void setError(@Nullable @StringRes Integer error) {
this.error = error;
this.args = args;
}
public T getBody() {
@ -73,21 +84,7 @@ public abstract class Response<T> {
this.body = body;
}
public String ok(Context context) {
if (success != null) {
return context.getString(success, args);
}
return null;
}
public String fail(Context context) {
if (error != null) {
return context.getString(error, args);
}
return null;
}
public Object[] getArgs() {
Object[] getArgs() {
return args;
}
@ -95,6 +92,19 @@ public abstract class Response<T> {
this.args = args;
}
public void ok(Context context) {
if (success != null) {
Toast.makeText(context, context.getString(success, args), Toast.LENGTH_SHORT).show();
}
}
public void fail(Context context) {
if (error != null) {
Toast.makeText(context, context.getString(error, args), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, context.getString(R.string.unknow_error), Toast.LENGTH_LONG).show();
}
}
public enum Result {
OK,

@ -0,0 +1,24 @@
package com.community.pocket.ui.main.ui.share;
import android.content.Context;
import android.widget.Toast;
import com.community.pocket.R;
import com.community.pocket.util.CustomMessage;
/**
* 弹窗响应
*
* @param <T>
*/
public abstract class ToastResponse<T extends CustomMessage> extends Response<T> {
public void toast(Context context) {
if (getBody() != null) {
Toast.makeText(context, context.getString(getBody().getMsg(), getArgs()), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, R.string.unknow_error, Toast.LENGTH_LONG).show();
}
}
}

@ -8,7 +8,6 @@ import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
@ -114,16 +113,14 @@ public class RegisterActivity extends BaseActivity {
return;
}
if (registerResponse.getError() != null) {
Toast.makeText(getApplicationContext(), R.string.register_fail, Toast.LENGTH_SHORT).show();
}
if (registerResponse.getSuccess() != null) {
Toast.makeText(getApplicationContext(), R.string.register_ok, Toast.LENGTH_SHORT).show();
registerResponse.toast(getBaseContext());
if (registerResponse.getBody() == RegisterResponse.Msg.ok) {
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
//Complete and destroy login activity once successful
finish();
}
}
setResult(Activity.RESULT_OK);
}
@ -133,7 +130,7 @@ public class RegisterActivity extends BaseActivity {
@Event(value = R.id.register)
private void register(View v) {
registerViewModel.register(username.getText().toString(), password.getText().toString(), confirmPassword.getText().toString(), mobiePhone.getText().toString(), email.getText().toString());
registerViewModel.register(username.getText().toString(), password.getText().toString(), mobiePhone.getText().toString(), email.getText().toString());
}
@Event(value = R.id.back)

@ -1,33 +1,41 @@
package com.community.pocket.ui.register;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.community.pocket.R;
import com.community.pocket.ui.main.ui.share.ToastResponse;
import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull;
/**
* 注册结果
*/
class RegisterResponse {
@Nullable
private Integer success;
@Nullable
private Integer error;
@Nullable
Integer getSuccess() {
return success;
}
public class RegisterResponse extends ToastResponse<RegisterResponse.Msg> {
RegisterResponse setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
/**
* 响应类型
*/
enum Msg implements CustomMessage {
ok(R.string.register_ok),
name(R.string.register_fail_name_repeat),
mobie(R.string.register_fail_mobie_repeat),
email(R.string.register_fail_email_repeat);
@Nullable
Integer getError() {
return error;
}
private Integer msg;
Msg(@StringRes Integer msg) {
this.msg = msg;
}
@NotNull
public @StringRes
Integer getMsg() {
return msg;
}
RegisterResponse setError(@Nullable Integer error) {
this.error = error;
return this;
public void setMsg(Integer msg) {
this.msg = msg;
}
}
}

@ -5,7 +5,6 @@ import androidx.lifecycle.ViewModel;
import com.community.pocket.R;
import com.community.pocket.data.register.RegisterRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
/**
@ -34,13 +33,8 @@ class RegisterViewModel extends ViewModel {
}
//注册
void register(String username, String password, String confirmPassword, String mobilePhone, String email) {
Valid valid = registerRequest.register(username, password, confirmPassword, mobilePhone, email);
if (Valid.ok == valid) {
registerResult.setValue(new RegisterResponse().setSuccess(R.string.register_ok));
} else {
registerResult.setValue(new RegisterResponse().setError(R.string.register_fail));
}
void register(String username, String password, String mobilePhone, String email) {
registerRequest.register(registerResult, username, password, mobilePhone, email);
}
//监听注册表单数据变化触发数据校验

@ -1,33 +1,42 @@
package com.community.pocket.ui.resetpwd;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.community.pocket.R;
import com.community.pocket.ui.main.ui.share.ToastResponse;
import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull;
/**
* 重置密码结果
*/
public class ResetPwdResponse {
@Nullable
private Integer success;
@Nullable
private Integer error;
@Nullable
Integer getSuccess() {
return success;
}
public class ResetPwdResponse extends ToastResponse<ResetPwdResponse.Msg> {
ResetPwdResponse setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
enum Msg implements CustomMessage {
step1_ok(R.string.resetpwd_step1_ok),
step1_fail(R.string.resetpwd_step1_fail),
step2_ok(R.string.resetpwd_step2_ok),
step2_fail(R.string.resetpwd_step2_fail),
step2_valid_ok(R.string.resetpwd_step2_valid_ok),
step2_valid_fail(R.string.resetpwd_step2_valid_fail),
step3_ok(R.string.resetpwd_step3_ok),
step3_fail(R.string.resetpwd_step3_fail);
@Nullable
Integer getError() {
return error;
}
private Integer msg;
Msg(@StringRes Integer msg) {
this.msg = msg;
}
public void setMsg(Integer msg) {
this.msg = msg;
}
ResetPwdResponse setError(@Nullable Integer error) {
this.error = error;
return this;
@NotNull
@Override
public Integer getMsg() {
return msg;
}
}
}

@ -9,7 +9,6 @@ import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -22,6 +21,7 @@ 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;
@ -92,13 +92,9 @@ public class ResetPwdStep1 extends BaseFragment {
return;
}
if (step1.getError() != null) {
Toast.makeText(getContext(), step1.getError(), Toast.LENGTH_LONG).show();
}
if (step1.getSuccess() != null) {
Toast.makeText(getContext(), step1.getSuccess(), Toast.LENGTH_LONG).show();
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());

@ -7,7 +7,6 @@ import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -19,6 +18,7 @@ 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;
@ -98,31 +98,35 @@ public class ResetPwdStep2 extends BaseFragment {
};
code.addTextChangedListener(afterTextChangedListener);
resetPwdViewModel.getResetPwdResultStep2().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
//监听发送验证码状态
resetPwdViewModel.getSendCodeResponse().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
@Override
public void onChanged(ResetPwdResponse resetPwdResponse) {
if (resetPwdResponse == null) {
return;
}
if (resetPwdResponse.getSuccess() != null) {
Toast.makeText(getContext(), resetPwdResponse.getSuccess(), Toast.LENGTH_LONG).show();
if (resetPwdResponse.getSuccess() == R.string.resetpwd_step2_ok) {
code.setEnabled(true);
} else {
Bundle bundle = new Bundle();
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);
}
}
if (resetPwdResponse.getError() != null) {
Toast.makeText(getContext(), resetPwdResponse.getError(), Toast.LENGTH_LONG).show();
if (resetPwdResponse.getError() == R.string.resetpwd_step2_fail) {
code.setEnabled(false);
}
}
}
});
}
@ -132,7 +136,7 @@ public class ResetPwdStep2 extends BaseFragment {
*/
@Event(value = R.id.next)
private void next(View view) {
resetPwdViewModel.checkCode(username.getText().toString(), email.getText().toString(), code.getText().toString());
resetPwdViewModel.checkCode(username.getText().toString(), code.getText().toString());
}
/**

@ -8,7 +8,6 @@ import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -20,6 +19,7 @@ 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;
@ -94,13 +94,10 @@ public class ResetPwdStep3 extends BaseFragment {
return;
}
if (resetPwdResponse.getSuccess() != null) {
Toast.makeText(getContext(), getString(R.string.resetpwd_step3_ok), Toast.LENGTH_LONG).show();
startActivity(new Intent(getContext(), LoginActivity.class));
resetPwdResponse.toast(getContext());
}
if (resetPwdResponse.getError() != null) {
Toast.makeText(getContext(), getString(R.string.resetpwd_step3_fail), Toast.LENGTH_LONG).show();
if (resetPwdResponse.getResult() == Response.Result.OK) {
startActivity(new Intent(getContext(), LoginActivity.class));
}
}
});

@ -19,7 +19,10 @@ class ResetPwdViewModel extends ViewModel {
//重置密码第二步校验状态
private MutableLiveData<ResetPwdFormState.Step2> resetPwdFormStep2 = new MutableLiveData<>();
//重置密码第二步发送验证码结果
private MutableLiveData<ResetPwdResponse> resetPwdResultStep2 = new MutableLiveData<>();
private MutableLiveData<ResetPwdResponse> sendCodeResponse = new MutableLiveData<>();
//重置密码验证码校验结果
private MutableLiveData<ResetPwdResponse> checkCodeResponse = new MutableLiveData<>();
//重置密码第三步校验状态
private MutableLiveData<ResetPwdFormState.Step3> resetPwdFormStep3 = new MutableLiveData<>();
//重置密码第三部重置结果
@ -44,8 +47,12 @@ class ResetPwdViewModel extends ViewModel {
return resetPwdFormStep2;
}
MutableLiveData<ResetPwdResponse> getResetPwdResultStep2() {
return resetPwdResultStep2;
MutableLiveData<ResetPwdResponse> getSendCodeResponse() {
return sendCodeResponse;
}
MutableLiveData<ResetPwdResponse> getCheckCodeResponse() {
return checkCodeResponse;
}
MutableLiveData<ResetPwdFormState.Step3> getResetPwdFormStep3() {
@ -58,26 +65,22 @@ class ResetPwdViewModel extends ViewModel {
//重置密码第一步
void checkUser(String username, String email) {
ResetPwdResponse response = resetPwdRequest.checkUser(username, email);
resetPwdResultStep1.setValue(response);
resetPwdRequest.checkUser(resetPwdResultStep1, username, email);
}
//重置密码第二步
void sendCode(String username, String email) {
ResetPwdResponse response = resetPwdRequest.sendCode(username, email);
resetPwdResultStep2.setValue(response);
resetPwdRequest.sendCode(sendCodeResponse, username, email);
}
//重置密码第二步
void checkCode(String username, String email, String code) {
ResetPwdResponse response = resetPwdRequest.checkCode(username, email, code);
resetPwdResultStep2.setValue(response);
void checkCode(String username, String code) {
resetPwdRequest.checkCode(checkCodeResponse, username, code);
}
//重置密码第三步
void resetPwd(String username, String password) {
ResetPwdResponse response = resetPwdRequest.resetPwd(username, password);
resetPwdResultStep3.setValue(response);
resetPwdRequest.resetPwd(resetPwdResultStep3, username, password);
}
//监听重置密码第一步表单触发校验

@ -0,0 +1,14 @@
package com.community.pocket.util;
import androidx.annotation.StringRes;
import org.jetbrains.annotations.NotNull;
/**
* 自定义响应信息
*/
public interface CustomMessage {
@StringRes
@NotNull
Integer getMsg();
}

@ -8,20 +8,36 @@ import org.jetbrains.annotations.NotNull;
import okhttp3.Call;
import okhttp3.Response;
/**
* HTTP响应实体
*
* @param <T>
*/
public class SimpleHttpParse<T extends com.community.pocket.ui.main.ui.share.Response> implements HttpParse<T> {
private MutableLiveData liveData;
//TODO 废弃
@Deprecated
private Integer success;
//TODO 废弃
@Deprecated
private Integer error;
//TODO 废弃
@Deprecated
public SimpleHttpParse(MutableLiveData liveData, @StringRes Integer success, @StringRes Integer error) {
this.liveData = liveData;
this.success = success;
this.error = error;
}
public SimpleHttpParse(MutableLiveData liveData) {
this.liveData = liveData;
}
public HttpResponse<T> getInterface(Class<T> tClass) {
return new HttpResponse<>(tClass, this);
}

@ -28,7 +28,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_user"
android:inputType="text"
android:selectAllOnFocus="true"
@ -43,7 +43,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_PASSWORD"
android:importantForAutofill="no"
android:hint="@string/prompt_password"
android:imeActionLabel="@string/action_sign_in_short"
android:inputType="textPassword"

@ -27,7 +27,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_user"
android:inputType="text"
android:selectAllOnFocus="true"
@ -41,7 +41,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_password"
android:inputType="text|textPassword"
android:selectAllOnFocus="true"
@ -55,7 +55,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_confirm_password"
android:inputType="text|textPassword"
android:selectAllOnFocus="true"
@ -69,7 +69,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_phone"
android:inputType="text|phone"
android:selectAllOnFocus="true"
@ -83,7 +83,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_email"
android:inputType="none|textEmailAddress"
android:selectAllOnFocus="true"

@ -11,7 +11,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_user"
android:inputType="text"
android:selectAllOnFocus="true"
@ -25,7 +25,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_email"
android:inputType="text|textEmailAddress"
android:selectAllOnFocus="true"

@ -11,14 +11,14 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:enabled="false"
android:hint="@string/prompt_user"
android:selectAllOnFocus="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TextFields" />
tools:ignore="TextFields"
android:importantForAutofill="no" />
<EditText
android:id="@+id/email"
@ -26,7 +26,6 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:enabled="false"
android:hint="@string/prompt_email"
android:selectAllOnFocus="true"
@ -34,7 +33,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username"
tools:layout_constraintTop_toBottomOf="@id/username"
tools:ignore="TextFields" />
tools:ignore="TextFields"
android:importantForAutofill="no" />
<EditText
android:id="@+id/code"

@ -9,7 +9,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_password"
android:inputType="text|textPassword"
android:selectAllOnFocus="true"
@ -23,7 +23,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:autofillHints="@string/AUTOFILL_HINT_USERNAME"
android:importantForAutofill="no"
android:hint="@string/prompt_confirm_password"
android:inputType="text|textPassword"
android:selectAllOnFocus="true"

@ -8,7 +8,6 @@
<string name="welcome">"Welcome !"</string>
<string name="invalid_username">Username must be >%1$s characters</string>
<string name="invalid_password">Password must be >%1$s characters</string>
<string name="login_failed">"Login failed"</string>
<string name="language_auto">system language</string>
<string name="language_chs">chs</string>
<string name="language_en">en</string>
@ -95,7 +94,6 @@
<string name="invalid_mobiephone">Cell phone Numbers are illegal</string>
<string name="invalid_email">Invalid mailbox</string>
<string name="register_ok">register OK</string>
<string name="register_fail">register fail</string>
<string name="resetpwd_step1_fail">username or email error</string>
<string name="resetpwd_step1_ok">Check success</string>
<string name="prompt_code">please input code</string>
@ -163,4 +161,9 @@
<string name="garbage_waste_search_ok">search success</string>
<string name="garbage_table_name">name</string>
<string name="garbage_table_price">price</string>
<string name="register_fail_name_repeat">username repeat</string>
<string name="register_fail_mobie_repeat">mobie repeat</string>
<string name="register_fail_email_repeat">email repeat</string>
<string name="unknow_error">unknow error</string>
<string name="login_fail">login fail</string>
</resources>

@ -7,7 +7,6 @@
<string name="action_sign_in_short">登陆</string>
<string name="welcome">"欢迎 !"</string>
<string name="invalid_password">密码必须大于%1$s个字符</string>
<string name="login_failed">"登陆失败"</string>
<string name="language_auto">系统语言</string>
<string name="language_chs">简体中文</string>
<string name="language_en">英文</string>
@ -94,7 +93,6 @@
<string name="invalid_mobiephone">手机号码不合法</string>
<string name="invalid_email">邮箱不合法</string>
<string name="register_ok">注册成功</string>
<string name="register_fail">注册失败</string>
<string name="invalid_username">用户名必须大于%1$s个字符</string>
<string name="resetpwd_step1_fail">用户名或邮箱错误</string>
<string name="resetpwd_step1_ok">校验成功</string>
@ -163,4 +161,9 @@
<string name="garbage_waste_search_ok">检索废品成功</string>
<string name="garbage_table_name">废品</string>
<string name="garbage_table_price">价格</string>
<string name="register_fail_name_repeat">用户名%1s已注册</string>
<string name="register_fail_mobie_repeat">手机号%1s已绑定</string>
<string name="register_fail_email_repeat">邮箱%1s已绑定</string>
<string name="unknow_error">未知错误,请联系管理员</string>
<string name="login_fail">登陆失败,账号或密码错误</string>
</resources>

@ -8,7 +8,6 @@
<string name="welcome">"Welcome !"</string>
<string name="invalid_username">Username must be >%1$s characters</string>
<string name="invalid_password">Password must be >%1$s characters</string>
<string name="login_failed">"Login failed"</string>
<string name="language_auto">system language</string>
<string name="language_chs">chs</string>
<string name="language_en">en</string>
@ -96,7 +95,6 @@
<string name="invalid_mobiephone">Cell phone Numbers are illegal</string>
<string name="invalid_email">Invalid mailbox</string>
<string name="register_ok">register OK</string>
<string name="register_fail">register fail</string>
<string name="resetpwd_step1_fail">username or email error</string>
<string name="resetpwd_step1_ok">Check success</string>
<string name="prompt_code">please input code</string>
@ -164,6 +162,11 @@
<string name="garbage_waste_search_ok">search success</string>
<string name="garbage_table_name">name</string>
<string name="garbage_table_price">price</string>
<string name="register_fail_name_repeat">username repeat</string>
<string name="register_fail_mobie_repeat">mobie repeat</string>
<string name="register_fail_email_repeat">email repeat</string>
<string name="unknow_error">unknow error</string>
<string name="login_fail">login fail</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save