From 819b010f4c9c4eaf34b17a5cc9c3de7168857c59 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 17 Apr 2020 17:53:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AE=BF=E5=AE=A2=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/visitor/VisitorRequest.java | 6 +- .../community/pocket/data/model/Visitor.java | 28 +++++++- .../pocket/data/model/VisitorStatus.java | 7 ++ .../post/ForumPostComplainViewModel.java | 4 +- .../sorting/GarbageSortingViewModel.java | 4 +- .../garbage/waste/GarbageWasteViewModel.java | 4 +- .../main/ui/share/MyAutoCompleteTextView.java | 17 ++++- .../ui/main/ui/share/SearchViewModel.java | 4 +- .../ui/main/ui/visitor/VisitorMyVisitor.java | 68 ++++++++++++------ .../VisitorAppointmentFragment.java | 29 ++++++-- .../visitor/appointment/VisitorViewModel.java | 14 ++-- .../java/com/community/pocket/util/Param.java | 3 +- .../layout/main/layout/activity_main_menu.xml | 2 + .../layout/visitor_appointment_fragment.xml | 69 ++++++++++++------- .../layout/visitor/layout/visitor_info.xml | 48 ++++++++++--- app/src/main/res/values-en-rUS/strings.xml | 11 +++ app/src/main/res/values-zh-rCN/strings.xml | 19 +++-- app/src/main/res/values/strings.xml | 11 +++ 18 files changed, 264 insertions(+), 84 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/data/model/VisitorStatus.java 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 index b8e357c..a06be32 100644 --- 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 @@ -30,7 +30,7 @@ public class VisitorRequest { //访客预约 @HttpRequest("/visitor/visitor") - public void appointment(MutableLiveData liveData, String appointment, String chooseDate, String chooseTime, String notes) { + public void appointment(MutableLiveData liveData, String appointment, String chooseDate, String chooseTime, String notes, boolean checked) { HttpUtil.getRequest(HttpUtil.Method.POST, new SimpleHttpParse(liveData).getInterface(VisitorResponse.class), new FormBody.Builder() @@ -38,6 +38,7 @@ public class VisitorRequest { .add("chooseDate", chooseDate) .add("chooseTime", chooseTime) .add("notes", notes) + .add("isOutPeople", String.valueOf(checked)) .add("token", LocalToken.getToken()) .add("username", LocalToken.getUsername()) .build()); @@ -45,11 +46,12 @@ public class VisitorRequest { //获取预约人 @HttpRequest("/visitor/people") - public void searchPeople(MutableLiveData liveData, String name) { + public void searchPeople(MutableLiveData liveData, String name, Boolean isOutPeople) { HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(VisitorPeopleResponse.class), new FormBody.Builder() .add("name", name) + .add("outPeople", String.valueOf(isOutPeople)) .add("username", LocalToken.getUsername()) .build()); } diff --git a/app/src/main/java/com/community/pocket/data/model/Visitor.java b/app/src/main/java/com/community/pocket/data/model/Visitor.java index 497f29a..8043f18 100644 --- a/app/src/main/java/com/community/pocket/data/model/Visitor.java +++ b/app/src/main/java/com/community/pocket/data/model/Visitor.java @@ -4,10 +4,16 @@ package com.community.pocket.data.model; * 访客信息 */ public abstract class Visitor { - private long time; + //预约时间 + private Long time; + //预约目的 private String notes; + //审核状态 + private VisitorStatus status; + //审核管理员 + private String managerName; - public void setTime(long time) { + public void setTime(Long time) { this.time = time; } @@ -15,7 +21,7 @@ public abstract class Visitor { this.notes = notes; } - public long getTime() { + public Long getTime() { return time; } @@ -24,4 +30,20 @@ public abstract class Visitor { } public abstract String getName(); + + public VisitorStatus getStatus() { + return status; + } + + public void setStatus(VisitorStatus status) { + this.status = status; + } + + public String getManagerName() { + return managerName; + } + + public void setManagerName(String managerName) { + this.managerName = managerName; + } } diff --git a/app/src/main/java/com/community/pocket/data/model/VisitorStatus.java b/app/src/main/java/com/community/pocket/data/model/VisitorStatus.java new file mode 100644 index 0000000..f3fd038 --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/model/VisitorStatus.java @@ -0,0 +1,7 @@ +package com.community.pocket.data.model; + +public enum VisitorStatus { + uncheck, + ok, + fail +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java index 27c54b8..04f87ac 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/post/ForumPostComplainViewModel.java @@ -1,5 +1,7 @@ package com.community.pocket.ui.main.ui.forum.post; +import android.os.Bundle; + import androidx.lifecycle.MutableLiveData; import com.community.pocket.R; @@ -61,7 +63,7 @@ public class ForumPostComplainViewModel extends ForumPostViewModel implements Se } @Override - public void search(String content) { + public void search(String content, Bundle data) { searchPeople(content); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java index cb5a053..73ebe22 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/garbage/sorting/GarbageSortingViewModel.java @@ -1,5 +1,7 @@ package com.community.pocket.ui.main.ui.garbage.sorting; +import android.os.Bundle; + import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.main.garbage.GarbageSortingRequest; @@ -24,7 +26,7 @@ public class GarbageSortingViewModel extends BaseViewModel im //检索废品请求状态 @Override - public void search(String content) { + public void search(String content, Bundle data) { getRequest().search(searchList, content); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java index c6cdb91..018174a 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/MyAutoCompleteTextView.java @@ -1,6 +1,7 @@ package com.community.pocket.ui.main.ui.share; import android.annotation.SuppressLint; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -32,7 +33,7 @@ public class MyAutoCompleteTextView { //延时搜索的handler private Handler searchHandler = new Handler(Looper.getMainLooper()) { public void handleMessage(@NotNull Message msg) { - dealSearchHint(); + dealSearchHint(msg.getData()); } }; @@ -40,13 +41,13 @@ public class MyAutoCompleteTextView { /** * 根据用户输入的字符去调用接口查询 */ - private void dealSearchHint() { + private void dealSearchHint(Bundle data) { String searchContent = view.getText().toString(); if (searchContent.isEmpty()) { return; } // appointmentViewModel.searchPeople(searchContent); - searchViewModel.search(searchContent); + searchViewModel.search(searchContent, data); } @SuppressLint("SoonBlockedPrivateApi") @@ -76,4 +77,14 @@ public class MyAutoCompleteTextView { searchHandler.sendEmptyMessageDelayed(1, 600); view.setTag(time); } + + public void searchHandler(Message message) { + long time = System.currentTimeMillis(); + //输入的字符间隔时间 小于700毫秒 移除以前的handler 延时600毫秒执行 + if (view.getTag() != null && time - (Long) view.getTag() < 700) { + searchHandler.removeMessages(1); + } + searchHandler.sendMessageDelayed(message, 600); + view.setTag(time); + } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/share/SearchViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/share/SearchViewModel.java index 84612f7..f5fd9dc 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/share/SearchViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/share/SearchViewModel.java @@ -1,9 +1,11 @@ package com.community.pocket.ui.main.ui.share; +import android.os.Bundle; + /** * 搜索框请求数据源 */ public interface SearchViewModel { //请求方法 - void search(String content); + void search(String content, Bundle data); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java index 6a6f2fe..b289309 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java @@ -9,6 +9,7 @@ import android.widget.EditText; import android.widget.TextView; import androidx.annotation.RequiresApi; +import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; import androidx.gridlayout.widget.GridLayout; @@ -58,50 +59,77 @@ public abstract class VisitorMyVisitor extends BaseFragment { createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime())); createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); - Button button = new Button(getContext()); - button.setText(getString(R.string.show_notes)); - GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); - layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); - button.setLayoutParams(layoutParams); - button.setOnClickListener(new View.OnClickListener() { - @RequiresApi(api = Build.VERSION_CODES.KITKAT) - @Override - public void onClick(View v) { - createAlertNotes(visitor.getNotes()); - } - }); - gridLayout.addView(button); + switch (visitor.getStatus()) { + case ok: + Button button = new Button(getContext()); + button.setText(R.string.show_notes); + GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); + layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); + button.setLayoutParams(layoutParams); + button.setOnClickListener(new View.OnClickListener() { + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public void onClick(View v) { + createAlertNotes(visitor); + } + }); + gridLayout.addView(button); + break; + case uncheck: + createTextView(R.string.visitor_uncheck); + break; + case fail: + createTextView(R.string.visitor_check_fail); + break; + + } + } } + /** * 创建单元格 */ private void createTextView(CharSequence text) { TextView textView = new TextView(getContext()); - textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); textView.setText(text); + createTextView(textView); + } + + private void createTextView(@StringRes int resId) { + TextView textView = new TextView(getContext()); + textView.setText(resId); + createTextView(textView); + } + + private void createTextView(TextView textView) { + textView.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); textView.setBackground(getResources().getDrawable(R.drawable.border)); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); textView.setLayoutParams(layoutParams); gridLayout.addView(textView); - } /** * 创建显示备注信息弹窗 */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) - private void createAlertNotes(String text) { + private void createAlertNotes(Visitor visitor) { View view = View.inflate(getContext(), R.layout.visitor_info, null); - TextView textView = view.findViewById(R.id.content); - textView.setText(text); - textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); + TextView name = view.findViewById(R.id.name); + name.setText(getString(R.string.visitor_show_name, visitor.getName())); + TextView time = view.findViewById(R.id.time); + time.setText(getString(R.string.visitor_show_time, DateFormat.format(getString(R.string.dateformat), visitor.getTime()))); + TextView notes = view.findViewById(R.id.notes); + notes.setText(getString(R.string.visitor_show_notes, visitor.getNotes())); + TextView admin = view.findViewById(R.id.admin); + admin.setText(getString(R.string.visitor_show_admin, visitor.getManagerName())); Button button = view.findViewById(R.id.close); AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); - final AlertDialog alertDialog = alert.setTitle(R.string.notes).setView(view).create(); + final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java index dce2deb..379da54 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java @@ -2,6 +2,7 @@ package com.community.pocket.ui.main.ui.visitor.appointment; import android.os.Build; import android.os.Bundle; +import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateFormat; @@ -10,6 +11,7 @@ import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; +import android.widget.RadioButton; import android.widget.Spinner; import android.widget.TextView; @@ -26,8 +28,8 @@ import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.main.ui.share.MyAutoCompleteTextView; import com.community.pocket.ui.main.ui.share.Response; -import com.community.pocket.ui.main.ui.share.ShowWordCount; import com.community.pocket.ui.main.ui.visitor.VisitorFragment; +import com.community.pocket.util.Param; import com.community.pocket.util.PropertiesUtil; import org.xutils.view.annotation.ContentView; @@ -78,13 +80,14 @@ public class VisitorAppointmentFragment extends BaseFragment { //预约时间数据 private ArrayAdapter timeAdpter; + //是否外来人口预约 + @ViewInject(R.id.is_outpeople) + private RadioButton radioButton; + @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_word_top, R.id.show_word_bottom}, R.id.notes, view); - showWordCount.showCount(); - appointmentViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorViewModel.class); @@ -168,7 +171,11 @@ public class VisitorAppointmentFragment extends BaseFragment { } appointment.setTag(R.string.visitor_tag, s.toString()); - myAutoCompleteTextView.searchHandler(); + Message message = new Message(); + Bundle bundle = new Bundle(); + bundle.putBoolean(Param.isOutPeople.name(), radioButton.isChecked()); + message.setData(bundle); + myAutoCompleteTextView.searchHandler(message); } }); @@ -186,6 +193,16 @@ public class VisitorAppointmentFragment extends BaseFragment { initTip(); } +// +// //是否外来人口 +// @Event(value = R.id.button_group,type = RadioGroup.OnCheckedChangeListener.class) +// private void checkOutPeople(RadioGroup group, @IdRes int checkedId){ +// if(R.id.is_outpeople==checkedId){ +// +// }else{ +// +// } +// } /** * 搜索框 @@ -219,7 +236,7 @@ public class VisitorAppointmentFragment extends BaseFragment { */ @Event(value = R.id.submit) private void submit(View view) { - appointmentViewModel.appointment(appointment.getText().toString(), chooseDate.getText().toString(), chooseTime.getSelectedItem().toString(), notes.getText().toString()); + appointmentViewModel.appointment(appointment.getText().toString(), chooseDate.getText().toString(), chooseTime.getSelectedItem().toString(), notes.getText().toString(), radioButton.isChecked()); } //初始化日期提示 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java index f39695f..a8bb9e6 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java @@ -1,5 +1,6 @@ package com.community.pocket.ui.main.ui.visitor.appointment; +import android.os.Bundle; import android.text.Editable; import androidx.lifecycle.MutableLiveData; @@ -8,6 +9,7 @@ import com.community.pocket.R; import com.community.pocket.data.main.visitor.VisitorRequest; import com.community.pocket.ui.main.ui.share.BaseViewModel; import com.community.pocket.ui.main.ui.share.SearchViewModel; +import com.community.pocket.util.Param; import com.community.pocket.util.ValidUtil; /** @@ -38,13 +40,13 @@ public class VisitorViewModel extends BaseViewModel implements S } //访客预约 - void appointment(String appointment, String chooseDate, String chooseTime, String notes) { - getRequest().appointment(visitorResponse, appointment, chooseDate, chooseTime, notes); + void appointment(String appointment, String chooseDate, String chooseTime, String notes, boolean checked) { + getRequest().appointment(visitorResponse, appointment, chooseDate, chooseTime, notes, checked); } //检索预约人 - private void searchPeople(String name) { - getRequest().searchPeople(searchPeopleReq, name); + private void searchPeople(String name, Boolean isOutPeople) { + getRequest().searchPeople(searchPeopleReq, name, isOutPeople); } //校验访客预约表单 @@ -63,8 +65,8 @@ public class VisitorViewModel extends BaseViewModel implements S } @Override - public void search(String content) { - searchPeople(content); + public void search(String content, Bundle data) { + searchPeople(content, data.getBoolean(Param.isOutPeople.name())); } @Override diff --git a/app/src/main/java/com/community/pocket/util/Param.java b/app/src/main/java/com/community/pocket/util/Param.java index 9f8c41f..1ea7718 100644 --- a/app/src/main/java/com/community/pocket/util/Param.java +++ b/app/src/main/java/com/community/pocket/util/Param.java @@ -6,5 +6,6 @@ package com.community.pocket.util; public enum Param { username, email, - forumId + forumId, + isOutPeople } diff --git a/app/src/main/res/layout/main/layout/activity_main_menu.xml b/app/src/main/res/layout/main/layout/activity_main_menu.xml index 49ba468..5dfb2ba 100644 --- a/app/src/main/res/layout/main/layout/activity_main_menu.xml +++ b/app/src/main/res/layout/main/layout/activity_main_menu.xml @@ -35,6 +35,8 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:background="?android:attr/windowBackground" + android:textAlignment="gravity" + app:itemTextColor="@color/colorAccent" app:labelVisibilityMode="labeled" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" 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 0d567e7..e813796 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 @@ -30,7 +30,7 @@ android:hint="@string/prompt_appointment" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/button_group_layout" /> - - + app:layout_constraintTop_toBottomOf="@id/choose_time_layout" /> - + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + +