完善访客预约UI数据管理

0515
panqihua 5 years ago
parent 9c2d0ebc19
commit f91edffd33
  1. 39
      app/src/main/java/com/community/pocket/data/adapter/VisitorAdpter.java
  2. 36
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java
  3. 2
      app/src/main/java/com/community/pocket/ui/main/MainFragment.java
  4. 53
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostContent.java
  5. 22
      app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostFragment.java
  6. 299
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java
  7. 10
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java
  8. 1
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java
  9. 9
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java
  10. 35
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java
  11. 6
      app/src/main/java/com/community/pocket/util/ValidUtil.java
  12. 14
      app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml
  13. 2
      app/src/main/res/values-en-rUS/strings.xml
  14. 2
      app/src/main/res/values-zh-rCN/strings.xml
  15. 2
      app/src/main/res/values/strings.xml

@ -0,0 +1,39 @@
package com.community.pocket.data.adapter;
import android.content.Context;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class VisitorAdpter extends ArrayAdapter<String> {
private Map<String, List<String>> map;
private List<String> list;
public VisitorAdpter(Map<String, List<String>> map, Context context) {
super(context, android.R.layout.simple_list_item_1);
addAll(map);
}
public void addAll(Map<String, List<String>> map) {
this.map = map;
this.list = new ArrayList<>(this.map.keySet());
clear();
addAll(this.list);
}
public boolean containsKey(String name) {
return this.map.containsKey(name);
}
public List<String> getTime(String name) {
return map.get(name);
}
public List<String> getList() {
return list;
}
}

@ -5,7 +5,10 @@ import com.community.pocket.ui.main.ui.visitor.VisitorResponse;
import com.community.pocket.util.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
* 访客接口
@ -31,26 +34,23 @@ public class VisitorRequest {
}
//获取预约人
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>() {
{
public VisitorResponse<Map<String, List<String>>> searchPeople(String name) {
return new VisitorResponse<Map<String, List<String>>>().setSuccess(R.string.visitor_appointment_people_ok).setBody(new HashMap<String, List<String>>() {{
put("ac123" + new Random().nextInt(10), new ArrayList<String>() {{
add("11:00");
add("12:00");
}
});
}});
put("ab123" + new Random().nextInt(10), new ArrayList<String>() {{
add("11:00");
add("13:00");
}});
put("b123123", new ArrayList<String>() {{
add("11:00");
add("14:00");
}});
}});
}

@ -43,7 +43,7 @@ public abstract class MainFragment extends BaseFragment {
protected void changeColor(View view) {
int color = getResources().getColor(R.color.button_unchecked);
for (int id : button_ids()) {
View v = Objects.requireNonNull(getView()).findViewById(id);
View v = Objects.requireNonNull(getActivity()).findViewById(id);
v.setBackgroundColor(color);
}

@ -1,82 +1,29 @@
package com.community.pocket.ui.main.ui.forum.post;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import java.util.Objects;
/**
* 发送正文界面
*/
abstract class ForumPostContent extends BaseFragment {
/**
* 导航
*/
//TODO 临时方法,存在内存泄露
@SuppressLint("StaticFieldLeak")
private static NavController nav;
/**
* 选择帖子类型触发事件
*/
static Handler handler = new MyHandler();
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_count, R.id.show_count_top}, R.id.post_content, view);
showWordCount.showCount();
initPostCtrl();
}
/**
* 初始化路由控制器
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initPostCtrl() {
nav = Navigation.findNavController(Objects.requireNonNull(getView()));
}
/**
* 导航触发器
*/
private static class MyHandler extends Handler {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case 0:
nav.navigate(R.id.forumPostActiveFragment);
break;
case 1:
nav.navigate(R.id.forumPostTopicFragment);
break;
case 2:
nav.navigate(R.id.forumPostComplainFragment);
break;
}
}
}
}

@ -10,6 +10,8 @@ import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import com.community.pocket.R;
import com.community.pocket.ui.BaseFragment;
@ -17,6 +19,8 @@ import com.community.pocket.ui.BaseFragment;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import java.util.Objects;
/**
* 发送帖子
*/
@ -35,6 +39,7 @@ public class ForumPostFragment extends BaseFragment {
@ViewInject(R.id.post_type)
private Spinner postType;
private NavController nav;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
@ -52,8 +57,23 @@ public class ForumPostFragment extends BaseFragment {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
ForumPostContent.handler.sendEmptyMessage(position);
if (nav == null) {
nav = Navigation.findNavController(Objects.requireNonNull(getView()).findViewById(R.id.post_type_fragment));
} else {
switch (position) {
case 0:
nav.navigate(R.id.forumPostActiveFragment);
break;
case 1:
nav.navigate(R.id.forumPostTopicFragment);
break;
case 2:
nav.navigate(R.id.forumPostComplainFragment);
break;
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {

@ -1,29 +1,43 @@
package com.community.pocket.ui.main.ui.visitor;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
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;
import androidx.annotation.RequiresApi;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R;
import com.community.pocket.data.adapter.VisitorAdpter;
import com.community.pocket.ui.BaseFragment;
import com.community.pocket.ui.main.ui.forum.ShowWordCount;
import com.community.pocket.util.PropertiesUtil;
import org.jetbrains.annotations.NotNull;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
@ -50,6 +64,16 @@ public class VisitorAppointmentFragment extends BaseFragment {
private VisitorViewModel appointmentViewModel;
//AutoCompleteTextView的doBeforeTextChanged方法
private Method doBeforeTextChanged;
//AutoCompleteTextView的doAfterTextChanged方法
private Method doAfterTextChanged;
//预约人数据呀
private VisitorAdpter visitorAdpter;
//预约时间数据
private ArrayAdapter<String> timeAdpter;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
@ -57,138 +81,175 @@ public class VisitorAppointmentFragment extends BaseFragment {
ShowWordCount showWordCount = new ShowWordCount(new int[]{R.id.show_word_top, R.id.show_word_bottom}, R.id.notes, view);
showWordCount.showCount();
// 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(){});
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(), PropertiesUtil.getIntValue("username.length")));
}
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();
VisitorFragment visitorFragment = ((VisitorFragment) Objects.requireNonNull(getParentFragment()).getParentFragment());
Button button = Objects.requireNonNull(Objects.requireNonNull(visitorFragment).getView()).findViewById(R.id.visitor_reservation);
try {
Method method = VisitorFragment.class.getDeclaredMethod("my", View.class);
method.setAccessible(true);
method.invoke(visitorFragment, button);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
if (visitorResponse.getError() != null) {
Toast.makeText(getContext(), visitorResponse.getError(), Toast.LENGTH_LONG).show();
}
}
});
//检索预约人请求结果
appointmentViewModel.getSearchPeopleReq().observe(getViewLifecycleOwner(), new Observer<VisitorResponse<Map<String, List<String>>>>() {
@Override
public void onChanged(VisitorResponse<Map<String, 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();
}
}
});
appointment.addTextChangedListener(new MyTextChange() {
@Override
public void afterTextChanged(Editable s) {
if (timeAdpter != null) {
timeAdpter.clear();
}
if (s.toString().equals(appointment.getTag(R.string.visitor_tag))) {
return;
}
if (visitorAdpter != null && visitorAdpter.containsKey(s.toString())) {
appointmentViewModel.appointmentDataChanged(appointment.getText(), notes.getText());
initTime(s);
}
appointment.setTag(R.string.visitor_tag, s.toString());
long time = System.currentTimeMillis();
//输入的字符间隔时间 小于700毫秒 移除以前的handler 延时600毫秒执行
if (appointment.getTag() != null && time - (Long) appointment.getTag() < 700) {
searchHandler.removeMessages(1);
}
searchHandler.sendEmptyMessageDelayed(1, 600);
appointment.setTag(time);
}
});
notes.addTextChangedListener(new MyTextChange() {
@Override
public void afterTextChanged(Editable s) {
appointmentViewModel.appointmentDataChanged(appointment.getText(), notes.getText());
}
});
}
//延时搜索的handler
private Handler searchHandler = new Handler(Looper.getMainLooper()) {
public void handleMessage(@NotNull Message msg) {
dealSearchHint();
}
};
/**
* 根据用户输入的字符去调用接口查询预约人
*/
private void dealSearchHint() {
String searchContent = appointment.getText().toString();
if (searchContent.isEmpty()) {
return;
}
appointmentViewModel.searchPeople(searchContent);
}
@SuppressLint("SoonBlockedPrivateApi")
private void refreshDropList() {
try {
if (doAfterTextChanged == null) {
Class<AutoCompleteTextView> autoCompleteTextView = AutoCompleteTextView.class;
doBeforeTextChanged = autoCompleteTextView.getDeclaredMethod("doBeforeTextChanged");
doBeforeTextChanged.setAccessible(true);
doAfterTextChanged = autoCompleteTextView.getDeclaredMethod("doAfterTextChanged");
doAfterTextChanged.setAccessible(true);
}
// doBeforeTextChanged.invoke(appointment);
doAfterTextChanged.invoke(appointment);
} catch (Exception e) {
Log.e("", e.toString());
Toast.makeText(getContext(), R.string.load_data_err, Toast.LENGTH_LONG).show();
}
}
/**
* 搜索框
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initSearch(List<String> arrays) {
private void initSearch(Map<String, List<String>> arrays) {
// 设置适配器
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays);
if (visitorAdpter == null) {
visitorAdpter = new VisitorAdpter(arrays, getContext());
// 将适配器与当前AutoCompleteTextView控件绑定
appointment.setAdapter(adapter);
appointment.setAdapter(visitorAdpter);
} else {
visitorAdpter.addAll(arrays);
}
refreshDropList();
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void initChooseTime(List<String> arrays) {
// 设置适配器
ArrayAdapter<String> adapter = new ArrayAdapter<>(Objects.requireNonNull(this.getContext()), android.R.layout.simple_list_item_1, arrays);
chooseTime.setAdapter(adapter);
private void initTime(Editable e) {
if (timeAdpter == null) {
timeAdpter = new ArrayAdapter<>(Objects.requireNonNull(getContext()), android.R.layout.simple_list_item_1, visitorAdpter.getTime(e.toString()));
chooseTime.setAdapter(timeAdpter);
} else {
timeAdpter.clear();
timeAdpter.addAll(visitorAdpter.getTime(e.toString()));
}
}
/**

@ -9,15 +9,12 @@ 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) {
VisitorFormState(@Nullable Integer appointmentError, @Nullable Integer notesError) {
this.appointmentError = appointmentError;
this.chooseTimeError = chooseTimeError;
this.notesError = notesError;
}
@ -30,11 +27,6 @@ class VisitorFormState {
return appointmentError;
}
@Nullable
Integer getChooseTimeError() {
return chooseTimeError;
}
@Nullable
Integer getNotesError() {
return notesError;

@ -17,6 +17,7 @@ import org.xutils.view.annotation.Event;
@ContentView(R.layout.visitor)
public class VisitorFragment extends MainFragment {
//跳转到访客预约界面
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Event(value = R.id.visitor_appointment)

@ -1,5 +1,6 @@
package com.community.pocket.ui.main.ui.visitor;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
@ -10,7 +11,7 @@ public class VisitorResponse<T> {
private Integer success;
@Nullable
private Integer error;
@Nullable
private T body;
@Nullable
@ -33,12 +34,12 @@ public class VisitorResponse<T> {
return this;
}
@Nullable
public T getBody() {
@NonNull
T getBody() {
return body;
}
public VisitorResponse<T> setBody(@Nullable T body) {
public VisitorResponse<T> setBody(@NonNull T body) {
this.body = body;
return this;
}

@ -1,5 +1,7 @@
package com.community.pocket.ui.main.ui.visitor;
import android.text.Editable;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
@ -9,6 +11,7 @@ import com.community.pocket.util.Valid;
import com.community.pocket.util.ValidUtil;
import java.util.List;
import java.util.Map;
/**
* 管理访客UI数据
@ -22,10 +25,7 @@ class VisitorViewModel extends ViewModel {
private MutableLiveData<VisitorResponse> visitorResponse = new MutableLiveData<>();
//检索预约人
private MutableLiveData<VisitorResponse<List<String>>> searchPeopleReq = new MutableLiveData<>();
//检索预约人可预约时间
private MutableLiveData<VisitorResponse<List<String>>> searchTimeReq = new MutableLiveData<>();
private MutableLiveData<VisitorResponse<Map<String, List<String>>>> searchPeopleReq = new MutableLiveData<>();
//访客请求
private VisitorRequest visitorRequest;
@ -42,14 +42,10 @@ class VisitorViewModel extends ViewModel {
return visitorResponse;
}
MutableLiveData<VisitorResponse<List<String>>> getSearchPeopleReq() {
MutableLiveData<VisitorResponse<Map<String, List<String>>>> getSearchPeopleReq() {
return searchPeopleReq;
}
MutableLiveData<VisitorResponse<List<String>>> getSearchTimeReq() {
return searchTimeReq;
}
//访客预约
void appointment(String appointment, String chooseTime, String notes) {
Valid valid = visitorRequest.appointment(appointment, chooseTime, notes);
@ -62,25 +58,16 @@ class VisitorViewModel extends ViewModel {
//检索预约人
void searchPeople(String name) {
VisitorResponse<List<String>> result = visitorRequest.searchPeople(name);
VisitorResponse<Map<String, 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));
void appointmentDataChanged(Editable appointment, Editable notes) {
if (!ValidUtil.usernamevalid(appointment.toString())) {
visitorFormState.setValue(new VisitorFormState(R.string.invalid_username, null));
} else if (!ValidUtil.notesValid(notes.toString())) {
visitorFormState.setValue(new VisitorFormState(null, R.string.invalid_notes));
} else {
visitorFormState.setValue(new VisitorFormState(true));
}

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

@ -11,15 +11,6 @@
android:layout_height="wrap_content"
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
android:id="@+id/appointment"
android:layout_width="0dp"
@ -33,10 +24,11 @@
<LinearLayout
android:id="@+id/choose_time_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appointment">

@ -116,4 +116,6 @@
<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>
<string name="load_data_err">load data error</string>
<string name="visitor_tag">visitor_tag</string>
</resources>

@ -116,4 +116,6 @@
<string name="visitor_appointment_people_fail">预约人检索失败</string>
<string name="visitor_appointment_time_ok">预约时间检索成功</string>
<string name="visitor_appointment_time_fail">预约时间检索失败</string>
<string name="load_data_err">数据加载失败!!!</string>
<string name="visitor_tag">visitor_tag</string>
</resources>

@ -117,6 +117,8 @@
<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>
<string name="load_data_err">load data error</string>
<string name="visitor_tag">visitor_tag</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save