增加我的访客、我的预约UI数据管理

0515
panqihua 5 years ago
parent 8bb27af826
commit d56e41699c
  1. 41
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java
  2. 2
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorRequest.java
  3. 41
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java
  4. 35
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyFragment.java
  5. 7
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyViewModel.java
  6. 22
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java
  7. 36
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationFragment.java
  8. 7
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorReservationViewModel.java
  9. 2
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFactory.java
  10. 3
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorAppointmentFragment.java
  11. 2
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorFormState.java
  12. 2
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorResponse.java
  13. 2
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/appointment/VisitorViewModel.java
  14. 60
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java
  15. 9
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java
  16. 32
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java
  17. 61
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java
  18. 9
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java
  19. 30
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java
  20. 2
      app/src/main/res/layout/main/layout/visitor/layout/visitor_appointment_fragment.xml
  21. 2
      app/src/main/res/layout/main/layout/visitor/layout/visitor_my_fragment.xml
  22. 6
      app/src/main/res/navigation/visitor_navigation.xml
  23. 4
      app/src/main/res/values-en-rUS/strings.xml
  24. 4
      app/src/main/res/values-zh-rCN/strings.xml
  25. 4
      app/src/main/res/values/strings.xml

@ -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<Visitor> 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;
}
}

@ -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;

@ -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<Visitor> 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;
}
}

@ -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();
}
}

@ -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
}

@ -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<Visitor> 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<Visitor> visitors) {
for (final Visitor visitor : visitors) {
createTextView(visitor.getName());
createTextView(DateFormat.format(getString(R.string.dateformat), visitor.getTime()));

@ -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();
}
}

@ -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
}

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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<VisitorMyResponse>() {
@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();
}
}

@ -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<List<Visitor>> {
}

@ -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<VisitorMyRequest> {
//我的访客数据请求状态
private MutableLiveData<VisitorMyResponse> visitorMyResponse = new MutableLiveData<>();
MutableLiveData<VisitorMyResponse> getVisitorMyResponse() {
return visitorMyResponse;
}
/**
* 加载我的访客
*/
void loadMy() {
VisitorMyResponse response = getRequest().loadMy();
visitorMyResponse.setValue(response);
}
@Override
protected VisitorMyRequest getRequest() {
return VisitorMyRequest.getInstance();
}
}

@ -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<VisitorReservationResponse>() {
@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();
}
}

@ -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<List<Visitor>> {
}

@ -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<VisitorReservationRequest> {
//我的预约请求状态
private MutableLiveData<VisitorReservationResponse> visitorReservationResponse = new MutableLiveData<>();
MutableLiveData<VisitorReservationResponse> getVisitorReservationResponse() {
return visitorReservationResponse;
}
void loadReservation() {
VisitorReservationResponse response = getRequest().loadReservation();
visitorReservationResponse.setValue(response);
}
@Override
protected VisitorReservationRequest getRequest() {
return VisitorReservationRequest.getInstance();
}
}

@ -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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

@ -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.VisitorMyFragment">
tools:context=".ui.main.ui.visitor.my.VisitorMyFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

@ -8,17 +8,17 @@
<fragment
android:id="@+id/visitorAppointmentFragment"
android:name="com.community.pocket.ui.main.ui.visitor.VisitorAppointmentFragment"
android:name="com.community.pocket.ui.main.ui.visitor.appointment.VisitorAppointmentFragment"
android:label="visitor_appointment_fragment"
tools:layout="@layout/visitor_appointment_fragment" />
<fragment
android:id="@+id/visitorReservationFragment"
android:name="com.community.pocket.ui.main.ui.visitor.VisitorReservationFragment"
android:name="com.community.pocket.ui.main.ui.visitor.reservation.VisitorReservationFragment"
android:label="visitor_reservation_fragment"
tools:layout="@layout/visitor_my_fragment" />
<fragment
android:id="@+id/visitorMyFragment"
android:name="com.community.pocket.ui.main.ui.visitor.VisitorMyFragment"
android:name="com.community.pocket.ui.main.ui.visitor.my.VisitorMyFragment"
android:label="visitor_my_fragment"
tools:layout="@layout/visitor_my_fragment" />
</navigation>

@ -147,4 +147,8 @@
<string name="load_forum_new_fail">load new fail</string>
<string name="load_forum_my_ok">load forum my success</string>
<string name="load_forum_my_fail">load my forum fail</string>
<string name="load_visitor_my_ok">load my visitor success</string>
<string name="load_visitor_my_fail">load my visitor fail</string>
<string name="load_visitor_reservation_ok">load reservation success</string>
<string name="load_visitor_reservation_fail">load reservation fail</string>
</resources>

@ -147,4 +147,8 @@
<string name="load_forum_new_fail">加载最新帖子失败</string>
<string name="load_forum_my_ok">加载我的帖子成功</string>
<string name="load_forum_my_fail">加载我的帖子失败</string>
<string name="load_visitor_my_ok">加载我的访客成功</string>
<string name="load_visitor_my_fail">加载我的访客失败</string>
<string name="load_visitor_reservation_ok">加载我的预约成功</string>
<string name="load_visitor_reservation_fail">加载我的预约失败</string>
</resources>

@ -148,6 +148,10 @@
<string name="load_forum_new_fail">load new fail</string>
<string name="load_forum_my_ok">load forum my success</string>
<string name="load_forum_my_fail">load my forum fail</string>
<string name="load_visitor_my_ok">load my visitor success</string>
<string name="load_visitor_my_fail">load my visitor fail</string>
<string name="load_visitor_reservation_ok">load reservation success</string>
<string name="load_visitor_reservation_fail">load reservation fail</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save