增加访客预约UI数据管理

0515
panqihua 5 years ago
parent db963809e2
commit 9c2d0ebc19
  1. 2
      app/src/main/assets/config.properties
  2. 57
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java
  3. 5
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java
  4. 20
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java
  5. 166
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java
  6. 7
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentViewModel.java
  7. 46
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java
  8. 45
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java
  9. 85
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java
  10. 10
      app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java
  11. 6
      app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java
  12. 8
      app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java
  13. 6
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java
  14. 4
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java
  15. 18
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java
  16. 10
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java
  17. 28
      app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java
  18. 14
      app/src/main/java/com/community/pocket/util/ValidUtil.java
  19. 35
      app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml
  20. 9
      app/src/main/res/values-en-rUS/strings.xml
  21. 9
      app/src/main/res/values-zh-rCN/strings.xml
  22. 9
      app/src/main/res/values/strings.xml
  23. 2
      build.gradle

@ -2,3 +2,5 @@
password.length=5 password.length=5
#注册账号大于长度 #注册账号大于长度
username.length=5 username.length=5
#多行文本最大长度
textMultiLine.length=200

@ -0,0 +1,57 @@
package com.community.pocket.data.main.visitor;
import com.community.pocket.R;
import com.community.pocket.ui.main.ui.visitor.VisitorResponse;
import com.community.pocket.util.Valid;
import java.util.ArrayList;
import java.util.List;
/**
* 访客接口
* TODO 完善接口逻辑
*/
public class VisitorRequest {
private static volatile VisitorRequest instance;
private VisitorRequest() {
}
public static VisitorRequest getInstance() {
if (instance == null) {
instance = new VisitorRequest();
}
return instance;
}
//访客预约
public Valid appointment(String appointment, String chooseTime, String notes) {
return Valid.ok;
}
//获取预约人
public VisitorResponse<List<String>> searchPeople(String name) {
return new VisitorResponse<List<String>>().setSuccess(R.string.visitor_appointment_people_ok).setBody(new ArrayList<String>() {
{
add("abc");
add("abcde");
add("aef2");
add("fff");
add("asdfa");
}
});
}
//选择预约人之后获取时间
public VisitorResponse<List<String>> searchTime(String name) {
return new VisitorResponse<List<String>>().setSuccess(R.string.visitor_appointment_time_ok).setBody(new ArrayList<String>() {
{
add("11:00");
add("12:00");
}
});
}
}

@ -10,6 +10,7 @@ import android.widget.TextView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.util.PropertiesUtil;
/** /**
* 提示正文输入字数 * 提示正文输入字数
@ -23,6 +24,8 @@ public class ShowWordCount {
private EditText postContent; private EditText postContent;
private static final int length = PropertiesUtil.getIntValue("textMultiLine.length");
public ShowWordCount(int[] ids, int contentId, View view) { public ShowWordCount(int[] ids, int contentId, View view) {
this.ids = ids; this.ids = ids;
this.view = view; this.view = view;
@ -33,7 +36,7 @@ public class ShowWordCount {
* 设置计数 * 设置计数
*/ */
private void setCount() { private void setCount() {
String text = view.getContext().getString(R.string.post_content_count, postContent.length(), view.getContext().getResources().getInteger(R.integer.post_content)); String text = view.getContext().getString(R.string.post_content_count, postContent.length(), length);
for (int id : ids) { for (int id : ids) {
TextView textView = view.findViewById(id); TextView textView = view.findViewById(id);

@ -0,0 +1,20 @@
package com.community.pocket.ui.main.ui.visitor;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.data.main.visitor.VisitorRequest;
public class VisitorAppointmentFactory implements ViewModelProvider.Factory {
@NonNull
@Override
@SuppressWarnings("unchecked")
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (modelClass.isAssignableFrom(VisitorViewModel.class)) {
return (T) new VisitorViewModel(VisitorRequest.getInstance());
} else {
throw new IllegalArgumentException("Unknown ViewModel class");
}
}
}

@ -2,11 +2,14 @@ package com.community.pocket.ui.main.ui.visitor;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -20,6 +23,7 @@ import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event; import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject; import org.xutils.view.annotation.ViewInject;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -32,9 +36,19 @@ public class VisitorAppointmentFragment extends BaseFragment {
@ViewInject(R.id.appointment) @ViewInject(R.id.appointment)
private AutoCompleteTextView appointment; private AutoCompleteTextView appointment;
//预约时间
@ViewInject(R.id.choose_time) @ViewInject(R.id.choose_time)
private Spinner spinner; private Spinner chooseTime;
//备注信息
@ViewInject(R.id.notes)
private EditText notes;
//提交按钮
@ViewInject(R.id.submit)
private Button submit;
private VisitorViewModel appointmentViewModel;
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override @Override
@ -42,8 +56,120 @@ public class VisitorAppointmentFragment extends BaseFragment {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_word_top, R.id.show_word_bottom}, R.id.notes, view); ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_word_top, R.id.show_word_bottom}, R.id.notes, view);
showWordCount.showCount(); showWordCount.showCount();
initSearch();
initChooseTime(); // appointmentViewModel=new ViewModelProvider(this,new VisitorAppointmentFactory()).get(VisitorViewModel.class);
// //监听访客预约表单校验状态
// appointmentViewModel.getVisitorFormState().observe(getViewLifecycleOwner(), new Observer<VisitorFormState>() {
// @Override
// public void onChanged(VisitorFormState visitorFormState) {
// if(visitorFormState==null){
// return;
// }
// submit.setEnabled(visitorFormState.isDataValid());
// if(visitorFormState.getAppointmentError()!=null){
// appointment.setError(getString(visitorFormState.getAppointmentError()));
// }
//
// if(visitorFormState.getChooseTimeError()!=null){
// Toast.makeText(getContext(),R.string.invalid_time,Toast.LENGTH_LONG).show();
// }
// if(visitorFormState.getNotesError()!=null){
// notes.setError(getString(visitorFormState.getNotesError()));
// }
// }
// });
//
// //监听预约请求结果
// appointmentViewModel.getVisitorResponse().observe(getViewLifecycleOwner(), new Observer<VisitorResponse>() {
// @Override
// public void onChanged(VisitorResponse visitorResponse) {
// if(visitorResponse==null){
// return;
// }
//
// if(visitorResponse.getSuccess()!=null){
// Toast.makeText(getContext(),visitorResponse.getSuccess(),Toast.LENGTH_LONG).show();
// NavHostFragment.findNavController(VisitorAppointmentFragment.this).navigate(R.id.visitorReservationFragment);
// }
// if(visitorResponse.getError()!=null){
// Toast.makeText(getContext(),visitorResponse.getError(),Toast.LENGTH_LONG).show();
// }
// }
// });
//
// //检索预约人请求结果
// appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer<VisitorResponse<List<String>>>() {
// @Override
// public void onChanged(VisitorResponse<List<String>> visitorResponse) {
// if(visitorResponse==null){
// return;
// }
//
// if(visitorResponse.getSuccess()!=null){
// initSearch(visitorResponse.getBody());
// }
//
// if(visitorResponse.getError()!=null){
// Toast.makeText(getContext(),visitorResponse.getError(),Toast.LENGTH_LONG).show();
// }
// }
// });
//
// //检索预约人可预约时间
// appointmentViewModel.getSearchTimeReq().observe(getViewLifecycleOwner(), new Observer<VisitorResponse<List<String>>>() {
// @Override
// public void onChanged(VisitorResponse<List<String>> listVisitorResponse) {
// if(listVisitorResponse==null){
// return;
// }
//
// if(listVisitorResponse.getSuccess()!=null){
// initChooseTime(listVisitorResponse.getBody());
// }
//
// if(listVisitorResponse.getError()!=null){
// Toast.makeText(getContext(),listVisitorResponse.getError(),Toast.LENGTH_LONG).show();
// }
// }
// });
//
//
// appointment.addTextChangedListener(new MyTextChange() {
// @Override
// public void afterTextChanged(Editable s) {
// if(s.toString().length()>0){
// appointmentViewModel.searchPeople(s.toString());
// }
// }
// });
//
// appointment.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// appointmentViewModel.appointmentDataChanged(appointment.getText().toString(),chooseTime.getSelectedItem().toString(),notes.getText().toString());
// appointmentViewModel.searchTime(appointment.getText().toString());
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> parent) {
//
// }
// });
//
// chooseTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// appointmentViewModel.appointmentDataChanged(appointment.getText().toString(),chooseTime.getSelectedItem().toString(),notes.getText().toString());
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> parent) {
//
// }
// });
// notes.addTextChangedListener(new MyTextChange(){});
} }
@ -51,10 +177,7 @@ public class VisitorAppointmentFragment extends BaseFragment {
* 搜索框 * 搜索框
*/ */
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initSearch() { private void initSearch(List<String> arrays) {
//TODO 设置数据源数组
String[] arrays = {"abc", "abcde", "aef2", "fff", "asdfa"};
// 设置适配器 // 设置适配器
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays);
// 将适配器与当前AutoCompleteTextView控件绑定 // 将适配器与当前AutoCompleteTextView控件绑定
@ -62,12 +185,10 @@ public class VisitorAppointmentFragment extends BaseFragment {
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initChooseTime() { private void initChooseTime(List<String> arrays) {
//TODO 设置数据源数组
String[] arrays = {"abc", "efg", "aef2", "fff", "asdfa"};
// 设置适配器 // 设置适配器
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays);
spinner.setAdapter(adapter); chooseTime.setAdapter(adapter);
} }
/** /**
@ -75,6 +196,25 @@ public class VisitorAppointmentFragment extends BaseFragment {
*/ */
@Event(value = R.id.submit) @Event(value = R.id.submit)
private void submit(View view) { private void submit(View view) {
Toast.makeText(view.getContext(), R.string.submit_appointment, Toast.LENGTH_SHORT).show(); appointmentViewModel.appointment(appointment.getText().toString(), chooseTime.getSelectedItem().toString(), notes.getText().toString());
}
abstract static class MyTextChange implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
} }
} }

@ -1,7 +0,0 @@
package com.community.pocket.ui.main.ui.visitor;
import androidx.lifecycle.ViewModel;
public class VisitorAppointmentViewModel extends ViewModel {
// TODO: Implement the ViewModel
}

@ -0,0 +1,46 @@
package com.community.pocket.ui.main.ui.visitor;
import androidx.annotation.Nullable;
/**
* 访客预约表单状态
*/
class VisitorFormState {
@Nullable
private Integer appointmentError;
@Nullable
private Integer chooseTimeError;
@Nullable
private Integer notesError;
private boolean isDataValid;
VisitorFormState(@Nullable Integer appointmentError, @Nullable Integer chooseTimeError, @Nullable Integer notesError) {
this.appointmentError = appointmentError;
this.chooseTimeError = chooseTimeError;
this.notesError = notesError;
}
VisitorFormState(boolean isDataValid) {
this.isDataValid = isDataValid;
}
@Nullable
Integer getAppointmentError() {
return appointmentError;
}
@Nullable
Integer getChooseTimeError() {
return chooseTimeError;
}
@Nullable
Integer getNotesError() {
return notesError;
}
boolean isDataValid() {
return isDataValid;
}
}

@ -0,0 +1,45 @@
package com.community.pocket.ui.main.ui.visitor;
import androidx.annotation.Nullable;
/**
* 访客接口请求结果
*/
public class VisitorResponse<T> {
@Nullable
private Integer success;
@Nullable
private Integer error;
@Nullable
private T body;
@Nullable
public Integer getSuccess() {
return success;
}
public VisitorResponse<T> setSuccess(@Nullable Integer success) {
this.success = success;
return this;
}
@Nullable
public Integer getError() {
return error;
}
public VisitorResponse<T> setError(@Nullable Integer error) {
this.error = error;
return this;
}
@Nullable
public T getBody() {
return body;
}
public VisitorResponse<T> setBody(@Nullable T body) {
this.body = body;
return this;
}
}

@ -1,19 +1,88 @@
package com.community.pocket.ui.main.ui.visitor; package com.community.pocket.ui.main.ui.visitor;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class VisitorViewModel extends ViewModel { import com.community.pocket.R;
import com.community.pocket.data.main.visitor.VisitorRequest;
import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
private MutableLiveData<String> mText; import java.util.List;
public VisitorViewModel() { /**
mText = new MutableLiveData<>(); * 管理访客UI数据
mText.setValue("This is dashboard fragment"); */
class VisitorViewModel extends ViewModel {
//访客预约表单校验信息
private MutableLiveData<VisitorFormState> visitorFormState = new MutableLiveData<>();
//访客预约请求结果
private MutableLiveData<VisitorResponse> visitorResponse = new MutableLiveData<>();
//检索预约人
private MutableLiveData<VisitorResponse<List<String>>> searchPeopleReq = new MutableLiveData<>();
//检索预约人可预约时间
private MutableLiveData<VisitorResponse<List<String>>> searchTimeReq = new MutableLiveData<>();
//访客请求
private VisitorRequest visitorRequest;
VisitorViewModel(VisitorRequest visitorRequest) {
this.visitorRequest = visitorRequest;
}
MutableLiveData<VisitorFormState> getVisitorFormState() {
return visitorFormState;
}
MutableLiveData<VisitorResponse> getVisitorResponse() {
return visitorResponse;
}
MutableLiveData<VisitorResponse<List<String>>> getSearchPeopleReq() {
return searchPeopleReq;
} }
LiveData<String> getText() { MutableLiveData<VisitorResponse<List<String>>> getSearchTimeReq() {
return mText; return searchTimeReq;
}
//访客预约
void appointment(String appointment, String chooseTime, String notes) {
Valid valid = visitorRequest.appointment(appointment, chooseTime, notes);
if (valid == Valid.ok) {
visitorResponse.setValue(new VisitorResponse().setSuccess(R.string.visitor_appointment_ok));
} else {
visitorResponse.setValue(new VisitorResponse().setError(R.string.visitor_appointment_fail));
}
}
//检索预约人
void searchPeople(String name) {
VisitorResponse<List<String>> result = visitorRequest.searchPeople(name);
searchPeopleReq.setValue(result);
}
//检索预约人时间
void searchTime(String name) {
VisitorResponse<List<String>> result = visitorRequest.searchTime(name);
searchTimeReq.setValue(result);
}
//校验访客预约表单
void appointmentDataChanged(String appointment, String chooseTime, String notes) {
if (!ValidUtil.usernamevalid(appointment)) {
visitorFormState.setValue(new VisitorFormState(R.string.invalid_username, null, null));
} else if (!ValidUtil.timeValid(chooseTime)) {
visitorFormState.setValue(new VisitorFormState(null, R.string.invalid_time, null));
} else if (!ValidUtil.notesValid(notes)) {
visitorFormState.setValue(new VisitorFormState(null, null, R.string.notes));
} else {
visitorFormState.setValue(new VisitorFormState(true));
}
} }
} }

@ -116,17 +116,17 @@ public class RegisterActivity extends BaseActivity {
email.addTextChangedListener(afterTextChangedListener); email.addTextChangedListener(afterTextChangedListener);
//监听注册请求结果 //监听注册请求结果
registerViewModel.getRegisterResult().observe(this, new Observer<RegisterResult>() { registerViewModel.getRegisterResult().observe(this, new Observer<RegisterResponse>() {
@Override @Override
public void onChanged(RegisterResult registerResult) { public void onChanged(RegisterResponse registerResponse) {
if (registerResult == null) { if (registerResponse == null) {
return; return;
} }
if (registerResult.getError() != null) { if (registerResponse.getError() != null) {
Toast.makeText(getApplicationContext(), R.string.register_fail, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), R.string.register_fail, Toast.LENGTH_SHORT).show();
} }
if (registerResult.getSuccess() != null) { if (registerResponse.getSuccess() != null) {
Toast.makeText(getApplicationContext(), R.string.register_ok, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), R.string.register_ok, Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), LoginActivity.class)); startActivity(new Intent(getApplicationContext(), LoginActivity.class));
//Complete and destroy login activity once successful //Complete and destroy login activity once successful

@ -5,7 +5,7 @@ import androidx.annotation.Nullable;
/** /**
* 注册结果 * 注册结果
*/ */
class RegisterResult { class RegisterResponse {
@Nullable @Nullable
private Integer success; private Integer success;
@Nullable @Nullable
@ -16,7 +16,7 @@ class RegisterResult {
return success; return success;
} }
RegisterResult setSuccess(@Nullable Integer success) { RegisterResponse setSuccess(@Nullable Integer success) {
this.success = success; this.success = success;
return this; return this;
} }
@ -26,7 +26,7 @@ class RegisterResult {
return error; return error;
} }
RegisterResult setError(@Nullable Integer error) { RegisterResponse setError(@Nullable Integer error) {
this.error = error; this.error = error;
return this; return this;
} }

@ -16,7 +16,7 @@ class RegisterViewModel extends ViewModel {
//注册表单校验信息 //注册表单校验信息
private MutableLiveData<RegisterFormState> registerFormState = new MutableLiveData<>(); private MutableLiveData<RegisterFormState> registerFormState = new MutableLiveData<>();
//注册结果 //注册结果
private MutableLiveData<RegisterResult> registerResult = new MutableLiveData<>(); private MutableLiveData<RegisterResponse> registerResult = new MutableLiveData<>();
//注册请求 //注册请求
private RegisterRequest registerRequest; private RegisterRequest registerRequest;
@ -29,7 +29,7 @@ class RegisterViewModel extends ViewModel {
return registerFormState; return registerFormState;
} }
MutableLiveData<RegisterResult> getRegisterResult() { MutableLiveData<RegisterResponse> getRegisterResult() {
return registerResult; return registerResult;
} }
@ -37,9 +37,9 @@ class RegisterViewModel extends ViewModel {
void register(String username, String password, String confirmPassword, String mobilePhone, String email) { void register(String username, String password, String confirmPassword, String mobilePhone, String email) {
Valid valid = registerRequest.register(username, password, confirmPassword, mobilePhone, email); Valid valid = registerRequest.register(username, password, confirmPassword, mobilePhone, email);
if (Valid.ok == valid) { if (Valid.ok == valid) {
registerResult.setValue(new RegisterResult().setSuccess(R.string.register_ok)); registerResult.setValue(new RegisterResponse().setSuccess(R.string.register_ok));
} else { } else {
registerResult.setValue(new RegisterResult().setError(R.string.register_fail)); registerResult.setValue(new RegisterResponse().setError(R.string.register_fail));
} }
} }

@ -5,7 +5,7 @@ import androidx.annotation.Nullable;
/** /**
* 重置密码结果 * 重置密码结果
*/ */
class ResetPwdResult { class ResetPwdResponse {
@Nullable @Nullable
private Integer success; private Integer success;
@Nullable @Nullable
@ -16,7 +16,7 @@ class ResetPwdResult {
return success; return success;
} }
ResetPwdResult setSuccess(@Nullable Integer success) { ResetPwdResponse setSuccess(@Nullable Integer success) {
this.success = success; this.success = success;
return this; return this;
} }
@ -26,7 +26,7 @@ class ResetPwdResult {
return error; return error;
} }
ResetPwdResult setError(@Nullable Integer error) { ResetPwdResponse setError(@Nullable Integer error) {
this.error = error; this.error = error;
return this; return this;
} }

@ -93,10 +93,10 @@ public class ResetPwdStep1 extends BaseFragment {
email.addTextChangedListener(afterTextChangedListener); email.addTextChangedListener(afterTextChangedListener);
//监听重置密码第一步请求 //监听重置密码第一步请求
resetPwdViewModel.getResetPwdResultStep1().observe(getViewLifecycleOwner(), new Observer<ResetPwdResult>() { resetPwdViewModel.getResetPwdResultStep1().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override @Override
public void onChanged(ResetPwdResult step1) { public void onChanged(ResetPwdResponse step1) {
if (step1 == null) { if (step1 == null) {
return; return;
} }

@ -107,16 +107,16 @@ public class ResetPwdStep2 extends BaseFragment {
}; };
code.addTextChangedListener(afterTextChangedListener); code.addTextChangedListener(afterTextChangedListener);
resetPwdViewModel.getResetPwdResultStep2().observe(getViewLifecycleOwner(), new Observer<ResetPwdResult>() { resetPwdViewModel.getResetPwdResultStep2().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
@Override @Override
public void onChanged(ResetPwdResult resetPwdResult) { public void onChanged(ResetPwdResponse resetPwdResponse) {
if (resetPwdResult == null) { if (resetPwdResponse == null) {
return; return;
} }
if (resetPwdResult.getSuccess() != null) { if (resetPwdResponse.getSuccess() != null) {
Toast.makeText(getContext(), resetPwdResult.getSuccess(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), resetPwdResponse.getSuccess(), Toast.LENGTH_LONG).show();
if (resetPwdResult.getSuccess() == R.string.resetpwd_step2_ok) { if (resetPwdResponse.getSuccess() == R.string.resetpwd_step2_ok) {
code.setEnabled(true); code.setEnabled(true);
} else { } else {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -126,9 +126,9 @@ public class ResetPwdStep2 extends BaseFragment {
} }
} }
if (resetPwdResult.getError() != null) { if (resetPwdResponse.getError() != null) {
Toast.makeText(getContext(), resetPwdResult.getError(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), resetPwdResponse.getError(), Toast.LENGTH_LONG).show();
if (resetPwdResult.getError() == R.string.resetpwd_step2_fail) { if (resetPwdResponse.getError() == R.string.resetpwd_step2_fail) {
code.setEnabled(false); code.setEnabled(false);
} }
} }

@ -96,19 +96,19 @@ public class ResetPwdStep3 extends BaseFragment {
password.addTextChangedListener(textWatcher); password.addTextChangedListener(textWatcher);
confirmPassword.addTextChangedListener(textWatcher); confirmPassword.addTextChangedListener(textWatcher);
resetPwdViewModel.getResetPwdResultStep3().observe(getViewLifecycleOwner(), new Observer<ResetPwdResult>() { resetPwdViewModel.getResetPwdResultStep3().observe(getViewLifecycleOwner(), new Observer<ResetPwdResponse>() {
@Override @Override
public void onChanged(ResetPwdResult resetPwdResult) { public void onChanged(ResetPwdResponse resetPwdResponse) {
if (resetPwdResult == null) { if (resetPwdResponse == null) {
return; return;
} }
if (resetPwdResult.getSuccess() != null) { if (resetPwdResponse.getSuccess() != null) {
Toast.makeText(getContext(), getString(R.string.resetpwd_step3_ok), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), getString(R.string.resetpwd_step3_ok), Toast.LENGTH_LONG).show();
startActivity(new Intent(getContext(), LoginActivity.class)); startActivity(new Intent(getContext(), LoginActivity.class));
} }
if (resetPwdResult.getError() != null) { if (resetPwdResponse.getError() != null) {
Toast.makeText(getContext(), getString(R.string.resetpwd_step3_fail), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), getString(R.string.resetpwd_step3_fail), Toast.LENGTH_LONG).show();
} }
} }

@ -17,15 +17,15 @@ class ResetPwdViewModel extends ViewModel {
//重置密码第一步校验状态 //重置密码第一步校验状态
private MutableLiveData<ResetPwdFormState.Step1> resetPwdFormStep1 = new MutableLiveData<>(); private MutableLiveData<ResetPwdFormState.Step1> resetPwdFormStep1 = new MutableLiveData<>();
//重置密码第一步验证结果 //重置密码第一步验证结果
private MutableLiveData<ResetPwdResult> resetPwdResultStep1 = new MutableLiveData<>(); private MutableLiveData<ResetPwdResponse> resetPwdResultStep1 = new MutableLiveData<>();
//重置密码第二步校验状态 //重置密码第二步校验状态
private MutableLiveData<ResetPwdFormState.Step2> resetPwdFormStep2 = new MutableLiveData<>(); private MutableLiveData<ResetPwdFormState.Step2> resetPwdFormStep2 = new MutableLiveData<>();
//重置密码第二步发送验证码结果 //重置密码第二步发送验证码结果
private MutableLiveData<ResetPwdResult> resetPwdResultStep2 = new MutableLiveData<>(); private MutableLiveData<ResetPwdResponse> resetPwdResultStep2 = new MutableLiveData<>();
//重置密码第三步校验状态 //重置密码第三步校验状态
private MutableLiveData<ResetPwdFormState.Step3> resetPwdFormStep3 = new MutableLiveData<>(); private MutableLiveData<ResetPwdFormState.Step3> resetPwdFormStep3 = new MutableLiveData<>();
//重置密码第三部重置结果 //重置密码第三部重置结果
private MutableLiveData<ResetPwdResult> resetPwdResultStep3 = new MutableLiveData<>(); private MutableLiveData<ResetPwdResponse> resetPwdResultStep3 = new MutableLiveData<>();
//重置密码请求 //重置密码请求
private ResetPwdRequest resetPwdRequest; private ResetPwdRequest resetPwdRequest;
@ -38,7 +38,7 @@ class ResetPwdViewModel extends ViewModel {
return resetPwdFormStep1; return resetPwdFormStep1;
} }
MutableLiveData<ResetPwdResult> getResetPwdResultStep1() { MutableLiveData<ResetPwdResponse> getResetPwdResultStep1() {
return resetPwdResultStep1; return resetPwdResultStep1;
} }
@ -46,7 +46,7 @@ class ResetPwdViewModel extends ViewModel {
return resetPwdFormStep2; return resetPwdFormStep2;
} }
MutableLiveData<ResetPwdResult> getResetPwdResultStep2() { MutableLiveData<ResetPwdResponse> getResetPwdResultStep2() {
return resetPwdResultStep2; return resetPwdResultStep2;
} }
@ -54,7 +54,7 @@ class ResetPwdViewModel extends ViewModel {
return resetPwdFormStep3; return resetPwdFormStep3;
} }
MutableLiveData<ResetPwdResult> getResetPwdResultStep3() { MutableLiveData<ResetPwdResponse> getResetPwdResultStep3() {
return resetPwdResultStep3; return resetPwdResultStep3;
} }
@ -62,9 +62,9 @@ class ResetPwdViewModel extends ViewModel {
void checkUser(String username, String email) { void checkUser(String username, String email) {
Result<String> result = resetPwdRequest.checkUser(username, email); Result<String> result = resetPwdRequest.checkUser(username, email);
if (result.getValid() == Valid.ok) { if (result.getValid() == Valid.ok) {
resetPwdResultStep1.setValue(new ResetPwdResult().setSuccess(R.string.resetpwd_step1_ok)); resetPwdResultStep1.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step1_ok));
} else { } else {
resetPwdResultStep1.setValue(new ResetPwdResult().setError(R.string.resetpwd_step1_fail)); resetPwdResultStep1.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step1_fail));
} }
} }
@ -72,10 +72,10 @@ class ResetPwdViewModel extends ViewModel {
void sendCode(String username, String email) { void sendCode(String username, String email) {
Result<String> result = resetPwdRequest.sendCode(username, email); Result<String> result = resetPwdRequest.sendCode(username, email);
if (result.getValid() == Valid.ok) { if (result.getValid() == Valid.ok) {
resetPwdResultStep2.setValue(new ResetPwdResult().setSuccess(R.string.resetpwd_step2_ok)); resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_ok));
resetpwdStep2Changed(); resetpwdStep2Changed();
} else { } else {
resetPwdResultStep2.setValue(new ResetPwdResult().setError(R.string.resetpwd_step2_fail)); resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_fail));
} }
} }
@ -83,9 +83,9 @@ class ResetPwdViewModel extends ViewModel {
void checkCode(String username, String email, String code) { void checkCode(String username, String email, String code) {
Result<String> result = resetPwdRequest.checkCode(username, email, code); Result<String> result = resetPwdRequest.checkCode(username, email, code);
if (result.getValid() == Valid.ok) { if (result.getValid() == Valid.ok) {
resetPwdResultStep2.setValue(new ResetPwdResult().setSuccess(R.string.resetpwd_step2_valid_ok)); resetPwdResultStep2.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step2_valid_ok));
} else { } else {
resetPwdResultStep2.setValue(new ResetPwdResult().setError(R.string.resetpwd_step2_valid_fail)); resetPwdResultStep2.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step2_valid_fail));
} }
} }
@ -93,9 +93,9 @@ class ResetPwdViewModel extends ViewModel {
void resetPwd(String username, String password) { void resetPwd(String username, String password) {
Result<String> result = resetPwdRequest.resetPwd(username, password); Result<String> result = resetPwdRequest.resetPwd(username, password);
if (result.getValid() == Valid.ok) { if (result.getValid() == Valid.ok) {
resetPwdResultStep3.setValue(new ResetPwdResult().setSuccess(R.string.resetpwd_step3_ok)); resetPwdResultStep3.setValue(new ResetPwdResponse().setSuccess(R.string.resetpwd_step3_ok));
} else { } else {
resetPwdResultStep3.setValue(new ResetPwdResult().setError(R.string.resetpwd_step3_fail)); resetPwdResultStep3.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step3_fail));
} }
} }

@ -43,4 +43,18 @@ public class ValidUtil {
public static boolean CAPTCHAValid(String code) { public static boolean CAPTCHAValid(String code) {
return Pattern.compile("^\\d{6}$").matcher(code).matches(); return Pattern.compile("^\\d{6}$").matcher(code).matches();
} }
/**
* 校验预约时间
*/
public static boolean timeValid(String time) {
return Pattern.compile("^\\d{2}:\\d{2}$").matcher(time).matches();
}
/**
* 校验备注信息
*/
public static boolean notesValid(String notes) {
return notes != null && notes.length() <= PropertiesUtil.getIntValue("textMultiLine.length");
}
} }

@ -11,6 +11,15 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11121212121"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<AutoCompleteTextView <AutoCompleteTextView
android:id="@+id/appointment" android:id="@+id/appointment"
android:layout_width="0dp" android:layout_width="0dp"
@ -18,18 +27,33 @@
android:completionThreshold="1" android:completionThreshold="1"
android:gravity="center" android:gravity="center"
android:hint="@string/prompt_appointment" android:hint="@string/prompt_appointment"
app:layout_constraintBottom_toTopOf="@+id/choose_time"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/choose_time_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appointment">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/prompt_choose_time" />
<Spinner <Spinner
android:id="@+id/choose_time" android:id="@+id/choose_time"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_weight="1" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appointment" /> </LinearLayout>
<TextView <TextView
android:id="@+id/show_word_top" android:id="@+id/show_word_top"
@ -38,7 +62,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/choose_time" /> app:layout_constraintTop_toBottomOf="@id/choose_time_layout" />
<EditText <EditText
android:id="@+id/notes" android:id="@+id/notes"
@ -70,6 +94,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/submit_appointment" android:text="@string/submit_appointment"
android:enabled="false"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/show_word_bottom" /> app:layout_constraintTop_toBottomOf="@id/show_word_bottom" />

@ -107,4 +107,13 @@
<string name="invalid_send_CAPTCHA">try again after %1d seconds</string> <string name="invalid_send_CAPTCHA">try again after %1d seconds</string>
<string name="resetpwd_step3_ok">reset password success</string> <string name="resetpwd_step3_ok">reset password success</string>
<string name="resetpwd_step3_fail">reset password error</string> <string name="resetpwd_step3_fail">reset password error</string>
<string name="visitor_appointment_ok">appointment OK</string>
<string name="visitor_appointment_fail">appointment fail</string>
<string name="invalid_time">invalid time</string>
<string name="invalid_notes">invalid notes</string>
<string name="choose_time_error">please choose people before time</string>
<string name="visitor_appointment_people_ok">search people success</string>
<string name="visitor_appointment_people_fail">search people fail</string>
<string name="visitor_appointment_time_ok">search time OK</string>
<string name="visitor_appointment_time_fail">search time fail</string>
</resources> </resources>

@ -107,4 +107,13 @@
<string name="invalid_send_CAPTCHA">%1d秒后再试</string> <string name="invalid_send_CAPTCHA">%1d秒后再试</string>
<string name="resetpwd_step3_ok">重置密码成功</string> <string name="resetpwd_step3_ok">重置密码成功</string>
<string name="resetpwd_step3_fail">重置密码失败</string> <string name="resetpwd_step3_fail">重置密码失败</string>
<string name="visitor_appointment_ok">访客预约成功</string>
<string name="visitor_appointment_fail">访客预约失败</string>
<string name="invalid_time">预约时间不合法</string>
<string name="invalid_notes">备注信息不合法</string>
<string name="choose_time_error">请先选择预约人</string>
<string name="visitor_appointment_people_ok">预约人检索成功</string>
<string name="visitor_appointment_people_fail">预约人检索失败</string>
<string name="visitor_appointment_time_ok">预约时间检索成功</string>
<string name="visitor_appointment_time_fail">预约时间检索失败</string>
</resources> </resources>

@ -108,6 +108,15 @@
<string name="invalid_send_CAPTCHA">try again after %1d seconds</string> <string name="invalid_send_CAPTCHA">try again after %1d seconds</string>
<string name="resetpwd_step3_ok">reset password success</string> <string name="resetpwd_step3_ok">reset password success</string>
<string name="resetpwd_step3_fail">reset password error</string> <string name="resetpwd_step3_fail">reset password error</string>
<string name="visitor_appointment_ok">appointment OK</string>
<string name="visitor_appointment_fail">appointment fail</string>
<string name="invalid_time">invalid time</string>
<string name="invalid_notes">invalid notes</string>
<string name="choose_time_error">please choose people before time</string>
<string name="visitor_appointment_people_ok">search people success</string>
<string name="visitor_appointment_people_fail">search people fail</string>
<string name="visitor_appointment_time_ok">search time OK</string>
<string name="visitor_appointment_time_fail">search time fail</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->

@ -8,7 +8,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.6.1' classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.github.jokar:multi-languages.plugin:0.0.8' classpath 'com.github.jokar:multi-languages.plugin:0.0.8'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

Loading…
Cancel
Save