From 9c2d0ebc1967e3760d0840b19eca719bde460f6b Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 3 Apr 2020 02:47:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E5=AE=A2=E9=A2=84?= =?UTF-8?q?=E7=BA=A6UI=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/config.properties | 4 +- .../data/main/visitor/VisitorRequest.java | 57 ++++++ .../ui/main/ui/forum/ShowWordCount.java | 5 +- .../ui/visitor/VisitorAppointmentFactory.java | 20 +++ .../visitor/VisitorAppointmentFragment.java | 166 ++++++++++++++++-- .../visitor/VisitorAppointmentViewModel.java | 7 - .../ui/main/ui/visitor/VisitorFormState.java | 46 +++++ .../ui/main/ui/visitor/VisitorResponse.java | 45 +++++ .../ui/main/ui/visitor/VisitorViewModel.java | 87 ++++++++- .../pocket/ui/register/RegisterActivity.java | 10 +- ...isterResult.java => RegisterResponse.java} | 6 +- .../pocket/ui/register/RegisterViewModel.java | 8 +- ...etPwdResult.java => ResetPwdResponse.java} | 6 +- .../pocket/ui/resetpwd/ResetPwdStep1.java | 4 +- .../pocket/ui/resetpwd/ResetPwdStep2.java | 18 +- .../pocket/ui/resetpwd/ResetPwdStep3.java | 10 +- .../pocket/ui/resetpwd/ResetPwdViewModel.java | 28 +-- .../com/community/pocket/util/ValidUtil.java | 14 ++ .../layout/visitor_appointment_fragment.xml | 37 +++- app/src/main/res/values-en-rUS/strings.xml | 9 + app/src/main/res/values-zh-rCN/strings.xml | 9 + app/src/main/res/values/strings.xml | 9 + build.gradle | 2 +- 23 files changed, 524 insertions(+), 83 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java rename app/src/main/java/com/community/pocket/ui/register/{RegisterResult.java => RegisterResponse.java} (75%) rename app/src/main/java/com/community/pocket/ui/resetpwd/{ResetPwdResult.java => ResetPwdResponse.java} (76%) diff --git a/app/src/main/assets/config.properties b/app/src/main/assets/config.properties index 8624297..7a15d63 100644 --- a/app/src/main/assets/config.properties +++ b/app/src/main/assets/config.properties @@ -1,4 +1,6 @@ #注册密码大于长度 password.length=5 #注册账号大于长度 -username.length=5 \ No newline at end of file +username.length=5 +#多行文本最大长度 +textMultiLine.length=200 \ No newline at end of file diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java new file mode 100644 index 0000000..a636bd8 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java @@ -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> searchPeople(String name) { + return new VisitorResponse>().setSuccess(R.string.visitor_appointment_people_ok).setBody(new ArrayList() { + { + add("abc"); + add("abcde"); + add("aef2"); + add("fff"); + add("asdfa"); + } + }); + } + + //选择预约人之后获取时间 + public VisitorResponse> searchTime(String name) { + return new VisitorResponse>().setSuccess(R.string.visitor_appointment_time_ok).setBody(new ArrayList() { + { + add("11:00"); + add("12:00"); + } + }); + } + + +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java index 5c8f5f7..9494ac6 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ShowWordCount.java @@ -10,6 +10,7 @@ import android.widget.TextView; import androidx.annotation.IdRes; import com.community.pocket.R; +import com.community.pocket.util.PropertiesUtil; /** * 提示正文输入字数 @@ -23,6 +24,8 @@ public class ShowWordCount { private EditText postContent; + private static final int length = PropertiesUtil.getIntValue("textMultiLine.length"); + public ShowWordCount(int[] ids, int contentId, View view) { this.ids = ids; this.view = view; @@ -33,7 +36,7 @@ public class ShowWordCount { * 设置计数 */ 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) { TextView textView = view.findViewById(id); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java new file mode 100644 index 0000000..2a25069 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java @@ -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 create(@NonNull Class modelClass) { + if (modelClass.isAssignableFrom(VisitorViewModel.class)) { + return (T) new VisitorViewModel(VisitorRequest.getInstance()); + } else { + throw new IllegalArgumentException("Unknown ViewModel class"); + } + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java index 40f310c..19bd796 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java @@ -2,11 +2,14 @@ package com.community.pocket.ui.main.ui.visitor; import android.os.Build; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.View; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.EditText; import android.widget.Spinner; -import android.widget.Toast; import androidx.annotation.NonNull; 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.ViewInject; +import java.util.List; import java.util.Objects; /** @@ -32,9 +36,19 @@ public class VisitorAppointmentFragment extends BaseFragment { @ViewInject(R.id.appointment) private AutoCompleteTextView appointment; + //预约时间 @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) @Override @@ -42,8 +56,120 @@ public class VisitorAppointmentFragment extends BaseFragment { 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.showCount(); - initSearch(); - initChooseTime(); + +// appointmentViewModel=new ViewModelProvider(this,new VisitorAppointmentFactory()).get(VisitorViewModel.class); + +// //监听访客预约表单校验状态 +// appointmentViewModel.getVisitorFormState().observe(getViewLifecycleOwner(), new Observer() { +// @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() { +// @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>>() { +// @Override +// public void onChanged(VisitorResponse> 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>>() { +// @Override +// public void onChanged(VisitorResponse> 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) - private void initSearch() { - //TODO 设置数据源数组 - String[] arrays = {"abc", "abcde", "aef2", "fff", "asdfa"}; - + private void initSearch(List arrays) { // 设置适配器 ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays); // 将适配器与当前AutoCompleteTextView控件绑定 @@ -62,12 +185,10 @@ public class VisitorAppointmentFragment extends BaseFragment { } @RequiresApi(api = Build.VERSION_CODES.KITKAT) - private void initChooseTime() { - //TODO 设置数据源数组 - String[] arrays = {"abc", "efg", "aef2", "fff", "asdfa"}; + private void initChooseTime(List arrays) { // 设置适配器 ArrayAdapter 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) 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) { + + } } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentViewModel.java deleted file mode 100644 index 7115ab3..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentViewModel.java +++ /dev/null @@ -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 -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java new file mode 100644 index 0000000..63583df --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java @@ -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; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java new file mode 100644 index 0000000..641da56 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java @@ -0,0 +1,45 @@ +package com.community.pocket.ui.main.ui.visitor; + +import androidx.annotation.Nullable; + +/** + * 访客接口请求结果 + */ +public class VisitorResponse { + @Nullable + private Integer success; + @Nullable + private Integer error; + @Nullable + private T body; + + @Nullable + public Integer getSuccess() { + return success; + } + + public VisitorResponse setSuccess(@Nullable Integer success) { + this.success = success; + return this; + } + + @Nullable + public Integer getError() { + return error; + } + + public VisitorResponse setError(@Nullable Integer error) { + this.error = error; + return this; + } + + @Nullable + public T getBody() { + return body; + } + + public VisitorResponse setBody(@Nullable T body) { + this.body = body; + return this; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java index f6de588..7fda092 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java @@ -1,19 +1,88 @@ package com.community.pocket.ui.main.ui.visitor; -import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; 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 mText; +import java.util.List; - public VisitorViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is dashboard fragment"); +/** + * 管理访客UI数据 + */ +class VisitorViewModel extends ViewModel { + + //访客预约表单校验信息 + private MutableLiveData visitorFormState = new MutableLiveData<>(); + + //访客预约请求结果 + private MutableLiveData visitorResponse = new MutableLiveData<>(); + + //检索预约人 + private MutableLiveData>> searchPeopleReq = new MutableLiveData<>(); + + //检索预约人可预约时间 + private MutableLiveData>> searchTimeReq = new MutableLiveData<>(); + + //访客请求 + private VisitorRequest visitorRequest; + + VisitorViewModel(VisitorRequest visitorRequest) { + this.visitorRequest = visitorRequest; } - LiveData getText() { - return mText; + MutableLiveData getVisitorFormState() { + return visitorFormState; + } + + MutableLiveData getVisitorResponse() { + return visitorResponse; + } + + MutableLiveData>> getSearchPeopleReq() { + return searchPeopleReq; + } + + MutableLiveData>> getSearchTimeReq() { + 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> result = visitorRequest.searchPeople(name); + searchPeopleReq.setValue(result); + } + + //检索预约人时间 + void searchTime(String name) { + VisitorResponse> 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)); + } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java b/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java index 559eb6a..fb9a1a2 100644 --- a/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java +++ b/app/src/main/java/com/community/pocket/ui/register/RegisterActivity.java @@ -116,17 +116,17 @@ public class RegisterActivity extends BaseActivity { email.addTextChangedListener(afterTextChangedListener); //监听注册请求结果 - registerViewModel.getRegisterResult().observe(this, new Observer() { + registerViewModel.getRegisterResult().observe(this, new Observer() { @Override - public void onChanged(RegisterResult registerResult) { - if (registerResult == null) { + public void onChanged(RegisterResponse registerResponse) { + if (registerResponse == null) { return; } - if (registerResult.getError() != null) { + if (registerResponse.getError() != null) { 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(); startActivity(new Intent(getApplicationContext(), LoginActivity.class)); //Complete and destroy login activity once successful diff --git a/app/src/main/java/com/community/pocket/ui/register/RegisterResult.java b/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java similarity index 75% rename from app/src/main/java/com/community/pocket/ui/register/RegisterResult.java rename to app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java index 6b7b195..62a4dd5 100644 --- a/app/src/main/java/com/community/pocket/ui/register/RegisterResult.java +++ b/app/src/main/java/com/community/pocket/ui/register/RegisterResponse.java @@ -5,7 +5,7 @@ import androidx.annotation.Nullable; /** * 注册结果 */ -class RegisterResult { +class RegisterResponse { @Nullable private Integer success; @Nullable @@ -16,7 +16,7 @@ class RegisterResult { return success; } - RegisterResult setSuccess(@Nullable Integer success) { + RegisterResponse setSuccess(@Nullable Integer success) { this.success = success; return this; } @@ -26,7 +26,7 @@ class RegisterResult { return error; } - RegisterResult setError(@Nullable Integer error) { + RegisterResponse setError(@Nullable Integer error) { this.error = error; return this; } diff --git a/app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java b/app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java index 4992328..2bc63ec 100644 --- a/app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/register/RegisterViewModel.java @@ -16,7 +16,7 @@ class RegisterViewModel extends ViewModel { //注册表单校验信息 private MutableLiveData registerFormState = new MutableLiveData<>(); //注册结果 - private MutableLiveData registerResult = new MutableLiveData<>(); + private MutableLiveData registerResult = new MutableLiveData<>(); //注册请求 private RegisterRequest registerRequest; @@ -29,7 +29,7 @@ class RegisterViewModel extends ViewModel { return registerFormState; } - MutableLiveData getRegisterResult() { + MutableLiveData getRegisterResult() { return registerResult; } @@ -37,9 +37,9 @@ 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 RegisterResult().setSuccess(R.string.register_ok)); + registerResult.setValue(new RegisterResponse().setSuccess(R.string.register_ok)); } else { - registerResult.setValue(new RegisterResult().setError(R.string.register_fail)); + registerResult.setValue(new RegisterResponse().setError(R.string.register_fail)); } } diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResult.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java similarity index 76% rename from app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResult.java rename to app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java index 7d5fd0c..7b75cd7 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResult.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdResponse.java @@ -5,7 +5,7 @@ import androidx.annotation.Nullable; /** * 重置密码结果 */ -class ResetPwdResult { +class ResetPwdResponse { @Nullable private Integer success; @Nullable @@ -16,7 +16,7 @@ class ResetPwdResult { return success; } - ResetPwdResult setSuccess(@Nullable Integer success) { + ResetPwdResponse setSuccess(@Nullable Integer success) { this.success = success; return this; } @@ -26,7 +26,7 @@ class ResetPwdResult { return error; } - ResetPwdResult setError(@Nullable Integer error) { + ResetPwdResponse setError(@Nullable Integer error) { this.error = error; return this; } diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java index 0415a13..64da799 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep1.java @@ -93,10 +93,10 @@ public class ResetPwdStep1 extends BaseFragment { email.addTextChangedListener(afterTextChangedListener); //监听重置密码第一步请求 - resetPwdViewModel.getResetPwdResultStep1().observe(getViewLifecycleOwner(), new Observer() { + resetPwdViewModel.getResetPwdResultStep1().observe(getViewLifecycleOwner(), new Observer() { @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override - public void onChanged(ResetPwdResult step1) { + public void onChanged(ResetPwdResponse step1) { if (step1 == null) { return; } diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java index d6e62a3..b1572ef 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep2.java @@ -107,16 +107,16 @@ public class ResetPwdStep2 extends BaseFragment { }; code.addTextChangedListener(afterTextChangedListener); - resetPwdViewModel.getResetPwdResultStep2().observe(getViewLifecycleOwner(), new Observer() { + resetPwdViewModel.getResetPwdResultStep2().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(ResetPwdResult resetPwdResult) { - if (resetPwdResult == null) { + public void onChanged(ResetPwdResponse resetPwdResponse) { + if (resetPwdResponse == null) { return; } - if (resetPwdResult.getSuccess() != null) { - Toast.makeText(getContext(), resetPwdResult.getSuccess(), Toast.LENGTH_LONG).show(); - if (resetPwdResult.getSuccess() == R.string.resetpwd_step2_ok) { + 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(); @@ -126,9 +126,9 @@ public class ResetPwdStep2 extends BaseFragment { } } - if (resetPwdResult.getError() != null) { - Toast.makeText(getContext(), resetPwdResult.getError(), Toast.LENGTH_LONG).show(); - if (resetPwdResult.getError() == R.string.resetpwd_step2_fail) { + if (resetPwdResponse.getError() != null) { + Toast.makeText(getContext(), resetPwdResponse.getError(), Toast.LENGTH_LONG).show(); + if (resetPwdResponse.getError() == R.string.resetpwd_step2_fail) { code.setEnabled(false); } } diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java index bc7b84b..049faa9 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdStep3.java @@ -96,19 +96,19 @@ public class ResetPwdStep3 extends BaseFragment { password.addTextChangedListener(textWatcher); confirmPassword.addTextChangedListener(textWatcher); - resetPwdViewModel.getResetPwdResultStep3().observe(getViewLifecycleOwner(), new Observer() { + resetPwdViewModel.getResetPwdResultStep3().observe(getViewLifecycleOwner(), new Observer() { @Override - public void onChanged(ResetPwdResult resetPwdResult) { - if (resetPwdResult == null) { + public void onChanged(ResetPwdResponse resetPwdResponse) { + if (resetPwdResponse == null) { return; } - if (resetPwdResult.getSuccess() != null) { + if (resetPwdResponse.getSuccess() != null) { Toast.makeText(getContext(), getString(R.string.resetpwd_step3_ok), Toast.LENGTH_LONG).show(); 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(); } } diff --git a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java index 0545ddd..f3312c4 100644 --- a/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/resetpwd/ResetPwdViewModel.java @@ -17,15 +17,15 @@ class ResetPwdViewModel extends ViewModel { //重置密码第一步校验状态 private MutableLiveData resetPwdFormStep1 = new MutableLiveData<>(); //重置密码第一步验证结果 - private MutableLiveData resetPwdResultStep1 = new MutableLiveData<>(); + private MutableLiveData resetPwdResultStep1 = new MutableLiveData<>(); //重置密码第二步校验状态 private MutableLiveData resetPwdFormStep2 = new MutableLiveData<>(); //重置密码第二步发送验证码结果 - private MutableLiveData resetPwdResultStep2 = new MutableLiveData<>(); + private MutableLiveData resetPwdResultStep2 = new MutableLiveData<>(); //重置密码第三步校验状态 private MutableLiveData resetPwdFormStep3 = new MutableLiveData<>(); //重置密码第三部重置结果 - private MutableLiveData resetPwdResultStep3 = new MutableLiveData<>(); + private MutableLiveData resetPwdResultStep3 = new MutableLiveData<>(); //重置密码请求 private ResetPwdRequest resetPwdRequest; @@ -38,7 +38,7 @@ class ResetPwdViewModel extends ViewModel { return resetPwdFormStep1; } - MutableLiveData getResetPwdResultStep1() { + MutableLiveData getResetPwdResultStep1() { return resetPwdResultStep1; } @@ -46,7 +46,7 @@ class ResetPwdViewModel extends ViewModel { return resetPwdFormStep2; } - MutableLiveData getResetPwdResultStep2() { + MutableLiveData getResetPwdResultStep2() { return resetPwdResultStep2; } @@ -54,7 +54,7 @@ class ResetPwdViewModel extends ViewModel { return resetPwdFormStep3; } - MutableLiveData getResetPwdResultStep3() { + MutableLiveData getResetPwdResultStep3() { return resetPwdResultStep3; } @@ -62,9 +62,9 @@ class ResetPwdViewModel extends ViewModel { void checkUser(String username, String email) { Result result = resetPwdRequest.checkUser(username, email); 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 { - 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) { Result result = resetPwdRequest.sendCode(username, email); 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(); } 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) { Result result = resetPwdRequest.checkCode(username, email, code); 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 { - 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) { Result result = resetPwdRequest.resetPwd(username, password); 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 { - resetPwdResultStep3.setValue(new ResetPwdResult().setError(R.string.resetpwd_step3_fail)); + resetPwdResultStep3.setValue(new ResetPwdResponse().setError(R.string.resetpwd_step3_fail)); } } diff --git a/app/src/main/java/com/community/pocket/util/ValidUtil.java b/app/src/main/java/com/community/pocket/util/ValidUtil.java index 7e8c12b..1ed1b9e 100644 --- a/app/src/main/java/com/community/pocket/util/ValidUtil.java +++ b/app/src/main/java/com/community/pocket/util/ValidUtil.java @@ -43,4 +43,18 @@ public class ValidUtil { public static boolean CAPTCHAValid(String code) { 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"); + } } diff --git a/app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml b/app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml index 4e26a31..87f9326 100644 --- a/app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml +++ b/app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml @@ -11,6 +11,15 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical"> + + - + app:layout_constraintTop_toBottomOf="@id/appointment"> + + + + + + + app:layout_constraintTop_toBottomOf="@id/choose_time_layout" /> diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index d72761e..83cb8c1 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -107,4 +107,13 @@ try again after %1d seconds reset password success reset password error + appointment OK + appointment fail + invalid time + invalid notes + please choose people before time + search people success + search people fail + search time OK + search time fail \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a493745..bf19caa 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -107,4 +107,13 @@ %1d秒后再试 重置密码成功 重置密码失败 + 访客预约成功 + 访客预约失败 + 预约时间不合法 + 备注信息不合法 + 请先选择预约人 + 预约人检索成功 + 预约人检索失败 + 预约时间检索成功 + 预约时间检索失败 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1258d6f..fb0d1cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -108,6 +108,15 @@ try again after %1d seconds reset password success reset password error + appointment OK + appointment fail + invalid time + invalid notes + please choose people before time + search people success + search people fail + search time OK + search time fail diff --git a/build.gradle b/build.gradle index d9e3148..b76d777 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } 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' // NOTE: Do not place your application dependencies here; they belong