From d56e41699cf34fd2c5e132ba4c4c4009834301ef Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sat, 4 Apr 2020 23:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=91=E7=9A=84=E8=AE=BF?= =?UTF-8?q?=E5=AE=A2=E3=80=81=E6=88=91=E7=9A=84=E9=A2=84=E7=BA=A6UI?= =?UTF-8?q?=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 --- .../data/main/visitor/VisitorMyRequest.java | 41 +++++++++++++ .../data/main/visitor/VisitorRequest.java | 2 +- .../visitor/VisitorReservationRequest.java | 41 +++++++++++++ .../ui/main/ui/visitor/VisitorMyFragment.java | 35 ----------- .../main/ui/visitor/VisitorMyViewModel.java | 7 --- .../ui/main/ui/visitor/VisitorMyVisitor.java | 22 ++----- .../visitor/VisitorReservationFragment.java | 36 ----------- .../visitor/VisitorReservationViewModel.java | 7 --- .../VisitorAppointmentFactory.java | 2 +- .../VisitorAppointmentFragment.java | 3 +- .../{ => appointment}/VisitorFormState.java | 2 +- .../{ => appointment}/VisitorResponse.java | 2 +- .../{ => appointment}/VisitorViewModel.java | 2 +- .../main/ui/visitor/my/VisitorMyFragment.java | 60 ++++++++++++++++++ .../main/ui/visitor/my/VisitorMyResponse.java | 9 +++ .../ui/visitor/my/VisitorMyViewModel.java | 32 ++++++++++ .../VisitorReservationFragment.java | 61 +++++++++++++++++++ .../VisitorReservationResponse.java | 9 +++ .../VisitorReservationViewModel.java | 30 +++++++++ .../layout/visitor_appointment_fragment.xml | 2 +- .../visitor/layout/visitor_my_fragment.xml | 2 +- .../res/navigation/visitor_navigation.xml | 6 +- app/src/main/res/values-en-rUS/strings.xml | 4 ++ app/src/main/res/values-zh-rCN/strings.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ 25 files changed, 311 insertions(+), 114 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java create mode 100644 app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyViewModel.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java delete mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationViewModel.java rename app/src/main/java/com/community/pocket/ui/main/ui/visitor/{ => appointment}/VisitorAppointmentFactory.java (91%) rename app/src/main/java/com/community/pocket/ui/main/ui/visitor/{ => appointment}/VisitorAppointmentFragment.java (98%) rename app/src/main/java/com/community/pocket/ui/main/ui/visitor/{ => appointment}/VisitorFormState.java (92%) rename app/src/main/java/com/community/pocket/ui/main/ui/visitor/{ => appointment}/VisitorResponse.java (93%) rename app/src/main/java/com/community/pocket/ui/main/ui/visitor/{ => appointment}/VisitorViewModel.java (97%) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java 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 new file mode 100644 index 0000000..bab15de --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java @@ -0,0 +1,41 @@ +package com.community.pocket.data.main.visitor; + +import com.community.pocket.R; +import com.community.pocket.data.model.Visitor; +import com.community.pocket.ui.main.ui.visitor.my.VisitorMyResponse; + +import java.util.ArrayList; +import java.util.List; + +/** + * 我的访客请求接口 + * TODO 完善逻辑 + */ +public class VisitorMyRequest { + private static volatile VisitorMyRequest instance; + + private VisitorMyRequest() { + } + + public static VisitorMyRequest getInstance() { + if (instance == null) { + instance = new VisitorMyRequest(); + } + return instance; + } + + /** + * 加载我的访客 + */ + public VisitorMyResponse loadMy() { + List visitors = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); + visitors.add(visitor); + } + VisitorMyResponse response = new VisitorMyResponse(); + response.setSuccess(R.string.load_visitor_my_ok); + response.setBody(visitors); + return response; + } +} 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 318234b..cad890b 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 @@ -1,7 +1,7 @@ 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.ui.main.ui.visitor.appointment.VisitorResponse; import com.community.pocket.util.Valid; import java.util.ArrayList; 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 new file mode 100644 index 0000000..72bd23d --- /dev/null +++ b/app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java @@ -0,0 +1,41 @@ +package com.community.pocket.data.main.visitor; + +import com.community.pocket.R; +import com.community.pocket.data.model.Visitor; +import com.community.pocket.ui.main.ui.visitor.reservation.VisitorReservationResponse; + +import java.util.ArrayList; +import java.util.List; + +/** + * 我的预约请求接口 + * TODO 完善逻辑 + */ +public class VisitorReservationRequest { + private static volatile VisitorReservationRequest instance; + + private VisitorReservationRequest() { + } + + public static VisitorReservationRequest getInstance() { + if (instance == null) { + instance = new VisitorReservationRequest(); + } + return instance; + } + + /** + * @return 我的预约 + */ + public VisitorReservationResponse loadReservation() { + List visitors = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); + visitors.add(visitor); + } + VisitorReservationResponse response = new VisitorReservationResponse(); + response.setSuccess(R.string.load_visitor_my_ok); + response.setBody(visitors); + return response; + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java deleted file mode 100644 index 5aa91fe..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.community.pocket.ui.main.ui.visitor; - -import android.os.Bundle; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.community.pocket.R; - -import org.xutils.view.annotation.ContentView; -import org.xutils.view.annotation.Event; - -/** - * 我的访客界面 - */ -@ContentView(R.layout.visitor_my_fragment) -public class VisitorMyFragment extends VisitorMyVisitor { - - @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); - } - - /** - * 查询访客数据 - */ - @Event(R.id.query) - private void query(View view) { - Toast.makeText(getContext(), "访客数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); - } -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyViewModel.java deleted file mode 100644 index 7f5a618..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyViewModel.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.community.pocket.ui.main.ui.visitor; - -import androidx.lifecycle.ViewModel; - -public class VisitorMyViewModel extends ViewModel { - // TODO: Implement the ViewModel -} 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 5cd4a99..0e56338 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,7 +1,6 @@ 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; @@ -9,8 +8,6 @@ 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.appcompat.app.AlertDialog; import androidx.gridlayout.widget.GridLayout; @@ -21,10 +18,12 @@ import com.community.pocket.ui.BaseFragment; import org.xutils.view.annotation.ViewInject; -import java.util.ArrayList; import java.util.List; import java.util.Objects; +/** + * 访客列表通用布局 + */ public abstract class VisitorMyVisitor extends BaseFragment { //表格布局 @ViewInject(R.id.table) @@ -50,24 +49,11 @@ public abstract class VisitorMyVisitor extends BaseFragment { */ private static final int maxLength = 5; - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - initDataList(); - } - - /** * 初始化数据 * TODO 测试数据 */ - private void initDataList() { - List visitors = new ArrayList<>(); - for (int i = 0; i < 30; i++) { - Visitor visitor = new Visitor("1231", System.currentTimeMillis(), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - visitors.add(visitor); - } - + protected void loadData(List visitors) { for (final Visitor visitor : visitors) { createTextView(visitor.getName()); createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime())); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java deleted file mode 100644 index 6761224..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.community.pocket.ui.main.ui.visitor; - -import android.os.Bundle; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.community.pocket.R; - -import org.xutils.view.annotation.ContentView; -import org.xutils.view.annotation.Event; - -/** - * 我的预约界面 - */ -@ContentView(R.layout.visitor_my_fragment) -public class VisitorReservationFragment extends VisitorMyVisitor { - - @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); - } - - - /** - * 查询预约数据 - */ - @Event(value = R.id.query) - private void query(View view) { - Toast.makeText(getContext(), "预约数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); - } -} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationViewModel.java deleted file mode 100644 index 0c337de..0000000 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationViewModel.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.community.pocket.ui.main.ui.visitor; - -import androidx.lifecycle.ViewModel; - -public class VisitorReservationViewModel extends ViewModel { - // TODO: Implement the ViewModel -} 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/appointment/VisitorAppointmentFactory.java similarity index 91% rename from app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFactory.java rename to app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFactory.java index 2a25069..bc882dc 100644 --- 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/appointment/VisitorAppointmentFactory.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.visitor; +package com.community.pocket.ui.main.ui.visitor.appointment; import androidx.annotation.NonNull; import androidx.lifecycle.ViewModel; 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/appointment/VisitorAppointmentFragment.java similarity index 98% rename from app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorAppointmentFragment.java rename to app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java index f608e47..d5845e4 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/appointment/VisitorAppointmentFragment.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.visitor; +package com.community.pocket.ui.main.ui.visitor.appointment; import android.annotation.SuppressLint; import android.os.Build; @@ -27,6 +27,7 @@ import com.community.pocket.data.adapter.VisitorAdpter; import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.listener.MyTextChange; import com.community.pocket.ui.main.ui.share.ShowWordCount; +import com.community.pocket.ui.main.ui.visitor.VisitorFragment; import com.community.pocket.util.PropertiesUtil; import org.jetbrains.annotations.NotNull; 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/appointment/VisitorFormState.java similarity index 92% rename from app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFormState.java rename to app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorFormState.java index 573404c..44f7faa 100644 --- 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/appointment/VisitorFormState.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.visitor; +package com.community.pocket.ui.main.ui.visitor.appointment; import androidx.annotation.Nullable; 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/appointment/VisitorResponse.java similarity index 93% rename from app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorResponse.java rename to app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java index a866606..6c7e791 100644 --- 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/appointment/VisitorResponse.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.visitor; +package com.community.pocket.ui.main.ui.visitor.appointment; import androidx.annotation.NonNull; import androidx.annotation.Nullable; 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/appointment/VisitorViewModel.java similarity index 97% rename from app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorViewModel.java rename to app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java index 947e938..82700a3 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/appointment/VisitorViewModel.java @@ -1,4 +1,4 @@ -package com.community.pocket.ui.main.ui.visitor; +package com.community.pocket.ui.main.ui.visitor.appointment; import android.text.Editable; 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 new file mode 100644 index 0000000..807f6fc --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java @@ -0,0 +1,60 @@ +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; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; + +/** + * 我的访客界面 + */ +@ContentView(R.layout.visitor_my_fragment) +public class VisitorMyFragment extends VisitorMyVisitor { + + @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.loadMy(); + + //监听我的访客请求状态 + viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(VisitorMyResponse visitorMyResponse) { + if (visitorMyResponse == null) { + return; + } + + if (visitorMyResponse.getSuccess() != null) { + loadData(visitorMyResponse.getBody()); + } + + if (visitorMyResponse.getError() != null) { + Toast.makeText(getContext(), visitorMyResponse.getError(), Toast.LENGTH_SHORT).show(); + } + } + }); + } + + /** + * 查询访客数据 + */ + @Event(R.id.query) + private void query(View view) { + Toast.makeText(getContext(), "访客数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java new file mode 100644 index 0000000..88da34e --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java @@ -0,0 +1,9 @@ +package com.community.pocket.ui.main.ui.visitor.my; + +import com.community.pocket.data.model.Visitor; +import com.community.pocket.ui.main.ui.share.Response; + +import java.util.List; + +public class VisitorMyResponse extends Response> { +} 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 new file mode 100644 index 0000000..03d38fa --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java @@ -0,0 +1,32 @@ +package com.community.pocket.ui.main.ui.visitor.my; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.data.main.visitor.VisitorMyRequest; +import com.community.pocket.ui.main.ui.share.BaseViewModel; + +/** + * 我的访客UI数据管理 + */ +public class VisitorMyViewModel extends BaseViewModel { + + //我的访客数据请求状态 + private MutableLiveData visitorMyResponse = new MutableLiveData<>(); + + MutableLiveData getVisitorMyResponse() { + return visitorMyResponse; + } + + /** + * 加载我的访客 + */ + void loadMy() { + VisitorMyResponse response = getRequest().loadMy(); + visitorMyResponse.setValue(response); + } + + @Override + protected VisitorMyRequest getRequest() { + return VisitorMyRequest.getInstance(); + } +} 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 new file mode 100644 index 0000000..09d026f --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java @@ -0,0 +1,61 @@ +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; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; + +import com.community.pocket.R; +import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; + +import org.xutils.view.annotation.ContentView; +import org.xutils.view.annotation.Event; + +/** + * 我的预约界面 + */ +@ContentView(R.layout.visitor_my_fragment) +public class VisitorReservationFragment extends VisitorMyVisitor { + + @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.loadReservation(); + + //监听我的预约请求状态 + viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(VisitorReservationResponse visitorReservationResponse) { + if (visitorReservationResponse == null) { + return; + } + + if (visitorReservationResponse.getSuccess() != null) { + loadData(visitorReservationResponse.getBody()); + } + + if (visitorReservationResponse.getError() != null) { + Toast.makeText(getContext(), visitorReservationResponse.getError(), Toast.LENGTH_SHORT).show(); + } + } + }); + } + + + /** + * 查询预约数据 + */ + @Event(value = R.id.query) + private void query(View view) { + Toast.makeText(getContext(), "预约数据查询" + startTime.getText() + "|" + endTime.getText(), Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java new file mode 100644 index 0000000..97b0b28 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java @@ -0,0 +1,9 @@ +package com.community.pocket.ui.main.ui.visitor.reservation; + +import com.community.pocket.data.model.Visitor; +import com.community.pocket.ui.main.ui.share.Response; + +import java.util.List; + +public class VisitorReservationResponse extends Response> { +} 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 new file mode 100644 index 0000000..a629185 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java @@ -0,0 +1,30 @@ +package com.community.pocket.ui.main.ui.visitor.reservation; + +import androidx.lifecycle.MutableLiveData; + +import com.community.pocket.data.main.visitor.VisitorReservationRequest; +import com.community.pocket.ui.main.ui.share.BaseViewModel; + +/** + * 我的预约UI数据管理 + */ +public class VisitorReservationViewModel extends BaseViewModel { + + //我的预约请求状态 + private MutableLiveData visitorReservationResponse = new MutableLiveData<>(); + + MutableLiveData getVisitorReservationResponse() { + return visitorReservationResponse; + } + + void loadReservation() { + VisitorReservationResponse response = getRequest().loadReservation(); + visitorReservationResponse.setValue(response); + } + + + @Override + protected VisitorReservationRequest getRequest() { + return VisitorReservationRequest.getInstance(); + } +} 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 f666b7f..e86117a 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 @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.main.ui.visitor.VisitorAppointmentFragment"> + tools:context=".ui.main.ui.visitor.appointment.VisitorAppointmentFragment"> + tools:context=".ui.main.ui.visitor.my.VisitorMyFragment"> \ No newline at end of file diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 14546e2..7bec9f6 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -147,4 +147,8 @@ load new fail load forum my success load my forum fail + load my visitor success + load my visitor fail + load reservation success + load reservation 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 16df921..7e4c702 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -147,4 +147,8 @@ 加载最新帖子失败 加载我的帖子成功 加载我的帖子失败 + 加载我的访客成功 + 加载我的访客失败 + 加载我的预约成功 + 加载我的预约失败 \ 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 8a1fa78..eff1f64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -148,6 +148,10 @@ load new fail load forum my success load my forum fail + load my visitor success + load my visitor fail + load reservation success + load reservation fail