完善访客信息分页查询

0515
panqihua 5 years ago
parent 390b97b994
commit 01e74fcc55
  1. 3
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorMyRequest.java
  2. 3
      app/src/main/java/com/community/pocket/data/main/visitor/VisitorReservationRequest.java
  3. 34
      app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java
  4. 28
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java
  5. 29
      app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java
  6. 16
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java
  7. 5
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorLoad.java
  8. 60
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorMyVisitor.java
  9. 43
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyFragment.java
  10. 11
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyResponse.java
  11. 8
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/my/VisitorMyViewModel.java
  12. 43
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationFragment.java
  13. 11
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationResponse.java
  14. 15
      app/src/main/java/com/community/pocket/ui/main/ui/visitor/reservation/VisitorReservationViewModel.java
  15. 2
      app/src/main/res/values-en-rUS/strings.xml
  16. 2
      app/src/main/res/values-zh-rCN/strings.xml
  17. 2
      app/src/main/res/values/strings.xml

@ -30,7 +30,7 @@ public class VisitorMyRequest {
* 加载我的访客 * 加载我的访客
*/ */
@HttpRequest("/visitor/my") @HttpRequest("/visitor/my")
public void loadMy(MutableLiveData<VisitorMyResponse> liveData, String startDate, String endDate) { public void loadMy(MutableLiveData<VisitorMyResponse> liveData, String startDate, String endDate, Long page) {
FormBody.Builder builder = new FormBody.Builder() FormBody.Builder builder = new FormBody.Builder()
.add("username", LocalToken.getUsername()) .add("username", LocalToken.getUsername())
.add("token", LocalToken.getToken()); .add("token", LocalToken.getToken());
@ -40,6 +40,7 @@ public class VisitorMyRequest {
if (endDate != null && !endDate.isEmpty()) { if (endDate != null && !endDate.isEmpty()) {
builder.add("endDate", endDate); builder.add("endDate", endDate);
} }
builder.add("currentPage", String.valueOf(page));
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<VisitorMyResponse>(liveData).getInterface(VisitorMyResponse.class), builder.build()); new SimpleHttpParse<VisitorMyResponse>(liveData).getInterface(VisitorMyResponse.class), builder.build());
} }

@ -30,7 +30,7 @@ public class VisitorReservationRequest {
* 我的预约 * 我的预约
*/ */
@HttpRequest("/visitor/reservation") @HttpRequest("/visitor/reservation")
public void loadReservation(MutableLiveData<VisitorReservationResponse> liveData, String startDate, String endDate) { public void loadReservation(MutableLiveData<VisitorReservationResponse> liveData, String startDate, String endDate, Long currentPage) {
FormBody.Builder builder = new FormBody.Builder() FormBody.Builder builder = new FormBody.Builder()
.add("username", LocalToken.getUsername()) .add("username", LocalToken.getUsername())
.add("token", LocalToken.getToken()); .add("token", LocalToken.getToken());
@ -40,6 +40,7 @@ public class VisitorReservationRequest {
if (endDate != null && !endDate.isEmpty()) { if (endDate != null && !endDate.isEmpty()) {
builder.add("endDate", endDate); builder.add("endDate", endDate);
} }
builder.add("currentPage", String.valueOf(currentPage));
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<VisitorReservationResponse>(liveData).getInterface(VisitorReservationResponse.class), builder.build()); new SimpleHttpParse<VisitorReservationResponse>(liveData).getInterface(VisitorReservationResponse.class), builder.build());
} }

@ -2,12 +2,14 @@ package com.community.pocket.ui.main.ui.forum;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.core.widget.NestedScrollView; import androidx.core.widget.NestedScrollView;
@ -33,12 +35,17 @@ public abstract class ForumPost extends BaseFragment {
@ViewInject(R.id.post_layout) @ViewInject(R.id.post_layout)
private LinearLayout layout; private LinearLayout layout;
@ViewInject(R.id.search)
private SearchView searchView;
/** /**
* 加载帖子数据 * 加载帖子数据
*/ */
protected void loadPost(Page<Forum> forumList) { protected void loadPost(Page<Forum> forumList) {
if (forumList.getCurrentPage() == 1) { if (forumList.getCurrentPage() == 1 && !forumList.getList().isEmpty()) {
layout.removeAllViews(); layout.removeAllViews();
} }
for (int i = 0; i < forumList.getList().size(); i++) { for (int i = 0; i < forumList.getList().size(); i++) {
@ -93,10 +100,31 @@ public abstract class ForumPost extends BaseFragment {
protected abstract Long getCurrentPage(); protected abstract Long getCurrentPage();
protected abstract SearchView searchView(); @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!query.isEmpty()) {
load(1L);
return true;
} else {
return false;
}
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
protected void load(Long page) { protected void load(Long page) {
getViewModel().loadForumNew(page, searchView().getQuery().toString()); getViewModel().loadForumNew(page, searchView.getQuery().toString());
} }
//滚动加载更多帖子 //滚动加载更多帖子

@ -6,7 +6,6 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SearchView;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
@ -15,7 +14,6 @@ import com.community.pocket.ui.main.ui.forum.ForumPost;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
/** /**
* 我的帖子 * 我的帖子
@ -25,9 +23,6 @@ public class ForumMyFragment extends ForumPost {
private ForumMyViewModel viewModel; private ForumMyViewModel viewModel;
@ViewInject(R.id.search)
private SearchView searchView;
private Long currentPage = 1L; private Long currentPage = 1L;
@Override @Override
@ -38,24 +33,6 @@ public class ForumMyFragment extends ForumPost {
load(1L); load(1L);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!query.isEmpty()) {
load(1L);
return true;
} else {
return false;
}
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
//监听我的帖子加载状态 //监听我的帖子加载状态
viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), forumMyResponse -> { viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), forumMyResponse -> {
if (forumMyResponse == null) { if (forumMyResponse == null) {
@ -91,11 +68,6 @@ public class ForumMyFragment extends ForumPost {
return currentPage; return currentPage;
} }
@Override
protected SearchView searchView() {
return searchView;
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

@ -7,7 +7,6 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SearchView;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
@ -16,7 +15,6 @@ import com.community.pocket.ui.main.ui.forum.ForumPost;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
/** /**
* 最新帖子 * 最新帖子
@ -26,9 +24,6 @@ public class ForumNewFragment extends ForumPost {
private ForumNewViewModel viewModel; private ForumNewViewModel viewModel;
@ViewInject(R.id.search)
private SearchView searchView;
private Long currentPage = 1L; private Long currentPage = 1L;
@Override @Override
@ -39,25 +34,6 @@ public class ForumNewFragment extends ForumPost {
load(1L); load(1L);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!query.isEmpty()) {
load(1L);
return true;
} else {
return false;
}
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
//监听最新帖子请求状态 //监听最新帖子请求状态
viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), forumNewResponse -> { viewModel.getForumNewResponse().observe(getViewLifecycleOwner(), forumNewResponse -> {
if (forumNewResponse == null) { if (forumNewResponse == null) {
@ -98,11 +74,6 @@ public class ForumNewFragment extends ForumPost {
return currentPage; return currentPage;
} }
@Override
protected SearchView searchView() {
return searchView;
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

@ -8,6 +8,7 @@ import android.widget.Button;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.widget.NestedScrollView;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.main.MainFragment; import com.community.pocket.ui.main.MainFragment;
@ -26,17 +27,18 @@ public class VisitorFragment extends MainFragment {
@ViewInject(R.id.visitor_reservation) @ViewInject(R.id.visitor_reservation)
private Button myBtn; private Button myBtn;
@ViewInject(R.id.scroll_body)
private NestedScrollView scrollView;
NestedScrollView getScrollView() {
return scrollView;
}
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
myBtn.setOnClickListener(new View.OnClickListener() { myBtn.setOnClickListener(this::reservation);
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onClick(View v) {
reservation(v);
}
});
} }
//跳转到访客预约界面 //跳转到访客预约界面

@ -0,0 +1,5 @@
package com.community.pocket.ui.main.ui.visitor;
public interface VisitorLoad {
void loadMy(String startDate, String endDate, Long page);
}

@ -3,6 +3,7 @@ package com.community.pocket.ui.main.ui.visitor;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -14,16 +15,18 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.widget.NestedScrollView;
import androidx.gridlayout.widget.GridLayout; import androidx.gridlayout.widget.GridLayout;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Page;
import com.community.pocket.data.model.Visitor; import com.community.pocket.data.model.Visitor;
import com.community.pocket.ui.BaseFragment; import com.community.pocket.ui.BaseFragment;
import com.community.pocket.util.PropertiesUtil; import com.community.pocket.util.PropertiesUtil;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject; import org.xutils.view.annotation.ViewInject;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -61,16 +64,19 @@ public abstract class VisitorMyVisitor extends BaseFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
this.initTip(); this.initTip();
this.loadMore();
} }
/** /**
* 初始化数据 * 初始化数据
*/ */
protected <T extends Visitor> void loadData(List<T> visitors) { protected <T extends Visitor> void loadData(Page<T> visitors) {
gridLayout.removeAllViews(); if (visitors.getCurrentPage() == 1 && !visitors.isEmpty()) {
for (final Visitor visitor : visitors) { gridLayout.removeViews(4, gridLayout.getChildCount() - 4);
}
for (final Visitor visitor : visitors.getList()) {
createTextView(visitor.getName()); createTextView(visitor.getName());
createTextView(formatUnix(visitor.getTime())); createTextView(DateFormat.format(getString(R.string.dateformat_visitor), visitor.getTime()));
createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength)); createTextView(visitor.getNotes().length() <= maxLength ? visitor.getNotes() : visitor.getNotes().substring(0, maxLength));
switch (visitor.getStatus()) { switch (visitor.getStatus()) {
@ -80,13 +86,7 @@ public abstract class VisitorMyVisitor extends BaseFragment {
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
button.setLayoutParams(layoutParams); button.setLayoutParams(layoutParams);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(v -> createAlertNotes(visitor));
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onClick(View v) {
createAlertNotes(visitor);
}
});
gridLayout.addView(button); gridLayout.addView(button);
break; break;
case uncheck: case uncheck:
@ -102,6 +102,25 @@ public abstract class VisitorMyVisitor extends BaseFragment {
} }
/**
* 加载更多数据
*/
protected abstract Long getCurrentPage();
protected abstract VisitorLoad getViewModel();
protected void load(Long page) {
getViewModel().loadMy(startTime.getText().toString(), endTime.getText().toString(), page);
}
private void loadMore() {
VisitorFragment visitorFragment = getParentFragment(VisitorFragment.class);
visitorFragment.getScrollView().setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
load(this.getCurrentPage() + 1);
}
});
}
/** /**
* 创建单元格 * 创建单元格
@ -124,6 +143,7 @@ public abstract class VisitorMyVisitor extends BaseFragment {
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(); GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
textView.setLayoutParams(layoutParams); textView.setLayoutParams(layoutParams);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
gridLayout.addView(textView); gridLayout.addView(textView);
} }
@ -144,12 +164,7 @@ public abstract class VisitorMyVisitor extends BaseFragment {
Button button = view.findViewById(R.id.close); Button button = view.findViewById(R.id.close);
AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create();
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(v -> alertDialog.dismiss());
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show(); alertDialog.show();
} }
@ -158,4 +173,13 @@ public abstract class VisitorMyVisitor extends BaseFragment {
String format = PropertiesUtil.getValue("date.pattern"); String format = PropertiesUtil.getValue("date.pattern");
tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis()))); tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis())));
} }
/**
* 查询访客数据
*/
@Event(R.id.query)
private void query(View view) {
load(1L);
}
} }

@ -5,15 +5,14 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.ui.main.ui.visitor.VisitorLoad;
import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
/** /**
* 我的访客界面 * 我的访客界面
@ -23,6 +22,8 @@ public class VisitorMyFragment extends VisitorMyVisitor {
private VisitorMyViewModel viewModel; private VisitorMyViewModel viewModel;
private Long currentPage;
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
@ -31,30 +32,30 @@ public class VisitorMyFragment extends VisitorMyVisitor {
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorMyViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorMyViewModel.class);
viewModel.loadMy(null, null); load(1L);
//监听我的访客请求状态 //监听我的访客请求状态
viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), new Observer<VisitorMyResponse>() { viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), visitorMyResponse -> {
@Override if (visitorMyResponse == null) {
public void onChanged(VisitorMyResponse visitorMyResponse) { return;
if (visitorMyResponse == null) { }
return;
} visitorMyResponse.toast(getContext());
visitorMyResponse.toast(getContext()); if (visitorMyResponse.getResult() == Response.Result.OK) {
this.currentPage = visitorMyResponse.getVisitorList().getCurrentPage();
if (visitorMyResponse.getResult() == Response.Result.OK) { loadData(visitorMyResponse.getVisitorList());
loadData(visitorMyResponse.getVisitorList());
}
} }
}); });
} }
/** @Override
* 查询访客数据 protected Long getCurrentPage() {
*/ return currentPage;
@Event(R.id.query) }
private void query(View view) {
viewModel.loadMy(startTime.getText().toString(), endTime.getText().toString()); @Override
protected VisitorLoad getViewModel() {
return viewModel;
} }
} }

@ -4,26 +4,27 @@ import androidx.annotation.StringRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.MyVisitor; import com.community.pocket.data.model.MyVisitor;
import com.community.pocket.data.model.Page;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.CustomMessage; import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
public class VisitorMyResponse extends Response<VisitorMyResponse.Msg> { public class VisitorMyResponse extends Response<VisitorMyResponse.Msg> {
private List<MyVisitor> visitorList; private Page<MyVisitor> visitorList;
List<MyVisitor> getVisitorList() { Page<MyVisitor> getVisitorList() {
return visitorList; return visitorList;
} }
public void setVisitorList(List<MyVisitor> visitorList) { public void setVisitorList(Page<MyVisitor> visitorList) {
this.visitorList = visitorList; this.visitorList = visitorList;
} }
enum Msg implements CustomMessage { enum Msg implements CustomMessage {
ok(R.string.load_visitor_my_ok), ok(R.string.load_visitor_my_ok),
ok_empty(R.string.no_more_data),
ok_more(R.string.load_more_data_ok),
fail(R.string.load_visitor_my_fail), fail(R.string.load_visitor_my_fail),
token(R.string.invalid_token); token(R.string.invalid_token);

@ -4,11 +4,12 @@ import androidx.lifecycle.MutableLiveData;
import com.community.pocket.data.main.visitor.VisitorMyRequest; import com.community.pocket.data.main.visitor.VisitorMyRequest;
import com.community.pocket.ui.main.ui.share.BaseViewModel; import com.community.pocket.ui.main.ui.share.BaseViewModel;
import com.community.pocket.ui.main.ui.visitor.VisitorLoad;
/** /**
* 我的访客UI数据管理 * 我的访客UI数据管理
*/ */
public class VisitorMyViewModel extends BaseViewModel<VisitorMyRequest> { public class VisitorMyViewModel extends BaseViewModel<VisitorMyRequest> implements VisitorLoad {
//我的访客数据请求状态 //我的访客数据请求状态
private MutableLiveData<VisitorMyResponse> visitorMyResponse = new MutableLiveData<>(); private MutableLiveData<VisitorMyResponse> visitorMyResponse = new MutableLiveData<>();
@ -20,8 +21,9 @@ public class VisitorMyViewModel extends BaseViewModel<VisitorMyRequest> {
/** /**
* 加载我的访客 * 加载我的访客
*/ */
void loadMy(String startDate, String endDate) { @Override
getRequest().loadMy(visitorMyResponse, startDate, endDate); public void loadMy(String startDate, String endDate, Long page) {
getRequest().loadMy(visitorMyResponse, startDate, endDate, page);
} }
@Override @Override

@ -5,15 +5,14 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.ui.main.ui.visitor.VisitorLoad;
import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor;
import org.xutils.view.annotation.ContentView; import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
/** /**
* 我的预约界面 * 我的预约界面
@ -23,6 +22,8 @@ public class VisitorReservationFragment extends VisitorMyVisitor {
private VisitorReservationViewModel viewModel; private VisitorReservationViewModel viewModel;
private Long currentPage;
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
@ -31,31 +32,31 @@ public class VisitorReservationFragment extends VisitorMyVisitor {
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorReservationViewModel.class); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(VisitorReservationViewModel.class);
viewModel.loadReservation(null, null); load(1L);
//监听我的预约请求状态 //监听我的预约请求状态
viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), new Observer<VisitorReservationResponse>() { viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), visitorReservationResponse -> {
@Override if (visitorReservationResponse == null) {
public void onChanged(VisitorReservationResponse visitorReservationResponse) { return;
if (visitorReservationResponse == null) { }
return;
} visitorReservationResponse.toast(getContext());
visitorReservationResponse.toast(getContext()); if (visitorReservationResponse.getResult() == Response.Result.OK) {
this.currentPage = visitorReservationResponse.getVisitorList().getCurrentPage();
if (visitorReservationResponse.getResult() == Response.Result.OK) { loadData(visitorReservationResponse.getVisitorList());
loadData(visitorReservationResponse.getVisitorList());
}
} }
}); });
} }
@Override
protected Long getCurrentPage() {
return currentPage;
}
/** @Override
* 查询预约数据 protected VisitorLoad getViewModel() {
*/ return viewModel;
@Event(value = R.id.query)
private void query(View view) {
viewModel.loadReservation(startTime.getText().toString(), endTime.getText().toString());
} }
} }

@ -3,30 +3,31 @@ package com.community.pocket.ui.main.ui.visitor.reservation;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import com.community.pocket.R; import com.community.pocket.R;
import com.community.pocket.data.model.Page;
import com.community.pocket.data.model.VisitorReservation; import com.community.pocket.data.model.VisitorReservation;
import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.ui.main.ui.share.Response;
import com.community.pocket.util.CustomMessage; import com.community.pocket.util.CustomMessage;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
/** /**
* 我的预约信息 * 我的预约信息
*/ */
public class VisitorReservationResponse extends Response<VisitorReservationResponse.Msg> { public class VisitorReservationResponse extends Response<VisitorReservationResponse.Msg> {
private List<VisitorReservation> visitorList; private Page<VisitorReservation> visitorList;
List<VisitorReservation> getVisitorList() { Page<VisitorReservation> getVisitorList() {
return visitorList; return visitorList;
} }
public void setVisitorList(List<VisitorReservation> visitorList) { public void setVisitorList(Page<VisitorReservation> visitorList) {
this.visitorList = visitorList; this.visitorList = visitorList;
} }
enum Msg implements CustomMessage { enum Msg implements CustomMessage {
ok(R.string.load_visitor_reservation_ok), ok(R.string.load_visitor_reservation_ok),
ok_empty(R.string.no_more_data),
ok_more(R.string.load_more_data_ok),
fail(R.string.load_visitor_reservation_fail), fail(R.string.load_visitor_reservation_fail),
token(R.string.invalid_token); token(R.string.invalid_token);

@ -4,11 +4,12 @@ import androidx.lifecycle.MutableLiveData;
import com.community.pocket.data.main.visitor.VisitorReservationRequest; import com.community.pocket.data.main.visitor.VisitorReservationRequest;
import com.community.pocket.ui.main.ui.share.BaseViewModel; import com.community.pocket.ui.main.ui.share.BaseViewModel;
import com.community.pocket.ui.main.ui.visitor.VisitorLoad;
/** /**
* 我的预约UI数据管理 * 我的预约UI数据管理
*/ */
public class VisitorReservationViewModel extends BaseViewModel<VisitorReservationRequest> { public class VisitorReservationViewModel extends BaseViewModel<VisitorReservationRequest> implements VisitorLoad {
//我的预约请求状态 //我的预约请求状态
private MutableLiveData<VisitorReservationResponse> visitorReservationResponse = new MutableLiveData<>(); private MutableLiveData<VisitorReservationResponse> visitorReservationResponse = new MutableLiveData<>();
@ -17,14 +18,14 @@ public class VisitorReservationViewModel extends BaseViewModel<VisitorReservatio
return visitorReservationResponse; return visitorReservationResponse;
} }
//我的预约
void loadReservation(String startDate, String endDate) {
getRequest().loadReservation(visitorReservationResponse, startDate, endDate);
}
@Override @Override
protected VisitorReservationRequest getRequest() { protected VisitorReservationRequest getRequest() {
return VisitorReservationRequest.getInstance(); return VisitorReservationRequest.getInstance();
} }
//我的预约
@Override
public void loadMy(String startDate, String endDate, Long currentPage) {
getRequest().loadReservation(visitorReservationResponse, startDate, endDate, currentPage);
}
} }

@ -228,4 +228,6 @@
<string name="server_address_error_3">服务端地址应该以http开头</string> <string name="server_address_error_3">服务端地址应该以http开头</string>
<string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string> <string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string>
<string name="load_more_forum_ok">load more forum OK</string> <string name="load_more_forum_ok">load more forum OK</string>
<string name="no_more_data">no more data</string>
<string name="load_more_data_ok">load more data OK</string>
</resources> </resources>

@ -228,4 +228,6 @@
<string name="server_address_error_3">服务端地址应该以http开头</string> <string name="server_address_error_3">服务端地址应该以http开头</string>
<string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string> <string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string>
<string name="load_more_forum_ok">成功加载更多帖子</string> <string name="load_more_forum_ok">成功加载更多帖子</string>
<string name="no_more_data">没有更多数据</string>
<string name="load_more_data_ok">成功加载更多数据</string>
</resources> </resources>

@ -229,6 +229,8 @@
<string name="server_address_error_3">服务端地址应该以http开头</string> <string name="server_address_error_3">服务端地址应该以http开头</string>
<string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string> <string name="server_address_error_4">恭喜你发现了新的错误,请联系管理员解决问题</string>
<string name="load_more_forum_ok">load more forum OK</string> <string name="load_more_forum_ok">load more forum OK</string>
<string name="no_more_data">no more data</string>
<string name="load_more_data_ok">load more data OK</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save