|
|
|
@ -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<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) |
|
|
|
|
private void initSearch() { |
|
|
|
|
//TODO 设置数据源数组
|
|
|
|
|
String[] arrays = {"abc", "abcde", "aef2", "fff", "asdfa"}; |
|
|
|
|
|
|
|
|
|
private void initSearch(List<String> arrays) { |
|
|
|
|
// 设置适配器
|
|
|
|
|
ArrayAdapter<String> 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<String> 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) |
|
|
|
|
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) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|