From aa20cb47d51887c6f4122d705f04720552d1c299 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 17 Apr 2020 18:53:21 +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/VisitorMyRequest.java | 17 ++++++++++------ .../visitor/VisitorReservationRequest.java | 18 ++++++++++------- .../ui/main/ui/visitor/VisitorMyVisitor.java | 20 +++++++++++++++++++ .../VisitorAppointmentFragment.java | 10 ---------- .../main/ui/visitor/my/VisitorMyFragment.java | 9 +++++---- .../ui/visitor/my/VisitorMyViewModel.java | 4 ++-- .../VisitorReservationFragment.java | 9 +++++---- .../VisitorReservationViewModel.java | 5 +++-- .../visitor/layout/visitor_my_fragment.xml | 20 ++++++++++++++----- 9 files changed, 72 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java index 39e6da4..ca53a87 100644 --- a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java @@ -30,12 +30,17 @@ public class VisitorMyRequest { * 加载我的访客 */ @HttpRequest("/visitor/my") - public void loadMy(MutableLiveData liveData) { + public void loadMy(MutableLiveData liveData, String startDate, String endDate) { + FormBody.Builder builder = new FormBody.Builder() + .add("username", LocalToken.getUsername()) + .add("token", LocalToken.getToken()); + if (startDate != null && !startDate.isEmpty()) { + builder.add("startDate", startDate); + } + if (endDate != null && !endDate.isEmpty()) { + builder.add("endDate", endDate); + } HttpUtil.getRequest(HttpUtil.Method.GET, - new SimpleHttpParse(liveData).getInterface(VisitorMyResponse.class), - new FormBody.Builder() - .add("username", LocalToken.getUsername()) - .add("token", LocalToken.getToken()) - .build()); + new SimpleHttpParse(liveData).getInterface(VisitorMyResponse.class), builder.build()); } } diff --git a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java index 9faa73c..7670cda 100644 --- a/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java @@ -30,13 +30,17 @@ public class VisitorReservationRequest { * 我的预约 */ @HttpRequest("/visitor/reservation") - public void loadReservation(MutableLiveData liveData) { + public void loadReservation(MutableLiveData liveData, String startDate, String endDate) { + FormBody.Builder builder = new FormBody.Builder() + .add("username", LocalToken.getUsername()) + .add("token", LocalToken.getToken()); + if (startDate != null && !startDate.isEmpty()) { + builder.add("startDate", startDate); + } + if (endDate != null && !endDate.isEmpty()) { + builder.add("endDate", endDate); + } HttpUtil.getRequest(HttpUtil.Method.GET, - new SimpleHttpParse(liveData).getInterface(VisitorReservationResponse.class), - new FormBody.Builder() - .add("username", LocalToken.getUsername()) - .add("token", LocalToken.getToken()) - .build()); - + new SimpleHttpParse(liveData).getInterface(VisitorReservationResponse.class), builder.build()); } } 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 b289309..7da9a63 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 @@ -1,6 +1,7 @@ package com.community.pocket.ui.main.ui.visitor; import android.os.Build; +import android.os.Bundle; import android.text.format.DateFormat; import android.view.Gravity; import android.view.View; @@ -8,6 +9,8 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; @@ -16,6 +19,7 @@ import androidx.gridlayout.widget.GridLayout; import com.community.pocket.R; import com.community.pocket.data.model.Visitor; import com.community.pocket.ui.BaseFragment; +import com.community.pocket.util.PropertiesUtil; import org.xutils.view.annotation.ViewInject; @@ -45,15 +49,25 @@ public abstract class VisitorMyVisitor extends BaseFragment { @ViewInject(R.id.time) protected TextView time; + @ViewInject(R.id.tip) + private TextView tip; + /** * 显示备注最大长度 */ private static final int maxLength = 5; + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + this.initTip(); + } + /** * 初始化数据 */ protected void loadData(List visitors) { + gridLayout.removeAllViews(); for (final Visitor visitor : visitors) { createTextView(visitor.getName()); createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime())); @@ -138,4 +152,10 @@ public abstract class VisitorMyVisitor extends BaseFragment { }); alertDialog.show(); } + + //初始化日期提示 + private void initTip() { + String format = PropertiesUtil.getValue("date.pattern"); + tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis()))); + } } 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 379da54..527b3f7 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 @@ -193,16 +193,6 @@ 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{ -// -// } -// } /** * 搜索框 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java index db73e33..2b47e15 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java @@ -2,7 +2,6 @@ package com.community.pocket.ui.main.ui.visitor.my; import android.os.Bundle; import android.view.View; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -22,15 +21,17 @@ import org.xutils.view.annotation.Event; @ContentView(R.layout.visitor_my_fragment) public class VisitorMyFragment extends VisitorMyVisitor { + private VisitorMyViewModel viewModel; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); name.setText(R.string.visitor_name); time.setText(R.string.visitor_time); - final VisitorMyViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorMyViewModel.class); + viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorMyViewModel.class); - viewModel.loadMy(); + viewModel.loadMy(null, null); //监听我的访客请求状态 viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), new Observer() { @@ -54,6 +55,6 @@ public class VisitorMyFragment extends VisitorMyVisitor { */ @Event(R.id.query) private void query(View view) { - Toast.makeText(getContext(), "访客数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); + viewModel.loadMy(startTime.getText().toString(), endTime.getText().toString()); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java index 6fdfc2d..16a4575 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java @@ -20,8 +20,8 @@ public class VisitorMyViewModel extends BaseViewModel { /** * 加载我的访客 */ - void loadMy() { - getRequest().loadMy(visitorMyResponse); + void loadMy(String startDate, String endDate) { + getRequest().loadMy(visitorMyResponse, startDate, endDate); } @Override diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java index 1240a04..6cd316c 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java @@ -2,7 +2,6 @@ package com.community.pocket.ui.main.ui.visitor.reservation; import android.os.Bundle; import android.view.View; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -22,15 +21,17 @@ import org.xutils.view.annotation.Event; @ContentView(R.layout.visitor_my_fragment) public class VisitorReservationFragment extends VisitorMyVisitor { + private VisitorReservationViewModel viewModel; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); name.setText(R.string.appointment_name); time.setText(R.string.appointment_time); - VisitorReservationViewModel viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorReservationViewModel.class); + viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorReservationViewModel.class); - viewModel.loadReservation(); + viewModel.loadReservation(null, null); //监听我的预约请求状态 viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), new Observer() { @@ -55,6 +56,6 @@ public class VisitorReservationFragment extends VisitorMyVisitor { */ @Event(value = R.id.query) private void query(View view) { - Toast.makeText(getContext(), "预约数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); + viewModel.loadReservation(startTime.getText().toString(), endTime.getText().toString()); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java index a440f85..7748782 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java @@ -17,8 +17,9 @@ public class VisitorReservationViewModel extends BaseViewModel + + + app:layout_constraintTop_toBottomOf="@id/tip"> + android:importantForAutofill="no" + android:inputType="date" /> + android:importantForAutofill="no" + android:inputType="date" />