From 01e74fcc55e887130dd07810378a20b91270b444 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Tue, 21 Apr 2020 15:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AE=BF=E5=AE=A2=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/visitor/VisitorMyRequest.java | 3 +- .../visitor/VisitorReservationRequest.java | 3 +- .../pocket/ui/main/ui/forum/ForumPost.java | 34 ++++++++++- .../ui/main/ui/forum/my/ForumMyFragment.java | 28 --------- .../main/ui/forum/news/ForumNewFragment.java | 29 --------- .../ui/main/ui/visitor/VisitorFragment.java | 16 ++--- .../ui/main/ui/visitor/VisitorLoad.java | 5 ++ .../ui/main/ui/visitor/VisitorMyVisitor.java | 60 +++++++++++++------ .../main/ui/visitor/my/VisitorMyFragment.java | 43 ++++++------- .../main/ui/visitor/my/VisitorMyResponse.java | 11 ++-- .../ui/visitor/my/VisitorMyViewModel.java | 8 ++- .../VisitorReservationFragment.java | 43 ++++++------- .../VisitorReservationResponse.java | 11 ++-- .../VisitorReservationViewModel.java | 15 ++--- app/src/main/res/values-en-rUS/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 17 files changed, 166 insertions(+), 149 deletions(-) create mode 100644 app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorLoad.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 index ca53a87..f87bc12 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,7 +30,7 @@ public class VisitorMyRequest { * 加载我的访客 */ @HttpRequest("/visitor/my") - public void loadMy(MutableLiveData liveData, String startDate, String endDate) { + public void loadMy(MutableLiveData liveData, String startDate, String endDate, Long page) { FormBody.Builder builder = new FormBody.Builder() .add("username", LocalToken.getUsername()) .add("token", LocalToken.getToken()); @@ -40,6 +40,7 @@ public class VisitorMyRequest { if (endDate != null && !endDate.isEmpty()) { builder.add("endDate", endDate); } + builder.add("currentPage", String.valueOf(page)); HttpUtil.getRequest(HttpUtil.Method.GET, 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 7670cda..5af3dc3 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,7 +30,7 @@ public class VisitorReservationRequest { * 我的预约 */ @HttpRequest("/visitor/reservation") - public void loadReservation(MutableLiveData liveData, String startDate, String endDate) { + public void loadReservation(MutableLiveData liveData, String startDate, String endDate, Long currentPage) { FormBody.Builder builder = new FormBody.Builder() .add("username", LocalToken.getUsername()) .add("token", LocalToken.getToken()); @@ -40,6 +40,7 @@ public class VisitorReservationRequest { if (endDate != null && !endDate.isEmpty()) { builder.add("endDate", endDate); } + builder.add("currentPage", String.valueOf(currentPage)); HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(VisitorReservationResponse.class), builder.build()); } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java index 3c6c4f6..2b2a106 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/ForumPost.java @@ -2,12 +2,14 @@ package com.community.pocket.ui.main.ui.forum; import android.content.Intent; import android.os.Build; +import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.appcompat.widget.SearchView; import androidx.core.widget.NestedScrollView; @@ -33,12 +35,17 @@ public abstract class ForumPost extends BaseFragment { @ViewInject(R.id.post_layout) private LinearLayout layout; + + @ViewInject(R.id.search) + private SearchView searchView; + + /** * 加载帖子数据 */ protected void loadPost(Page forumList) { - if (forumList.getCurrentPage() == 1) { + if (forumList.getCurrentPage() == 1 && !forumList.getList().isEmpty()) { layout.removeAllViews(); } 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 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) { - getViewModel().loadForumNew(page, searchView().getQuery().toString()); + getViewModel().loadForumNew(page, searchView.getQuery().toString()); } //滚动加载更多帖子 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java index 69748b1..001a17f 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java @@ -6,7 +6,6 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.SearchView; import androidx.lifecycle.ViewModelProvider; 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 org.xutils.view.annotation.ContentView; -import org.xutils.view.annotation.ViewInject; /** * 我的帖子 @@ -25,9 +23,6 @@ public class ForumMyFragment extends ForumPost { private ForumMyViewModel viewModel; - @ViewInject(R.id.search) - private SearchView searchView; - private Long currentPage = 1L; @Override @@ -38,24 +33,6 @@ public class ForumMyFragment extends ForumPost { 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 -> { if (forumMyResponse == null) { @@ -91,11 +68,6 @@ public class ForumMyFragment extends ForumPost { return currentPage; } - @Override - protected SearchView searchView() { - return searchView; - } - @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java index 3fa2fac..622c462 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/news/ForumNewFragment.java @@ -7,7 +7,6 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.SearchView; import androidx.lifecycle.ViewModelProvider; 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 org.xutils.view.annotation.ContentView; -import org.xutils.view.annotation.ViewInject; /** * 最新帖子 @@ -26,9 +24,6 @@ public class ForumNewFragment extends ForumPost { private ForumNewViewModel viewModel; - @ViewInject(R.id.search) - private SearchView searchView; - private Long currentPage = 1L; @Override @@ -39,25 +34,6 @@ public class ForumNewFragment extends ForumPost { 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 -> { if (forumNewResponse == null) { @@ -98,11 +74,6 @@ public class ForumNewFragment extends ForumPost { return currentPage; } - @Override - protected SearchView searchView() { - return searchView; - } - @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java index a8337ec..01772d2 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorFragment.java @@ -8,6 +8,7 @@ import android.widget.Button; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.core.widget.NestedScrollView; import com.community.pocket.R; import com.community.pocket.ui.main.MainFragment; @@ -26,17 +27,18 @@ public class VisitorFragment extends MainFragment { @ViewInject(R.id.visitor_reservation) private Button myBtn; + @ViewInject(R.id.scroll_body) + private NestedScrollView scrollView; + + NestedScrollView getScrollView() { + return scrollView; + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - myBtn.setOnClickListener(new View.OnClickListener() { - @RequiresApi(api = Build.VERSION_CODES.KITKAT) - @Override - public void onClick(View v) { - reservation(v); - } - }); + myBtn.setOnClickListener(this::reservation); } //跳转到访客预约界面 diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorLoad.java b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorLoad.java new file mode 100644 index 0000000..6866a87 --- /dev/null +++ b/app/src/main/java/com/community/pocket/ui/main/ui/visitor/VisitorLoad.java @@ -0,0 +1,5 @@ +package com.community.pocket.ui.main.ui.visitor; + +public interface VisitorLoad { + void loadMy(String startDate, String endDate, Long page); +} 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 942c169..5e65266 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 @@ -3,6 +3,7 @@ package com.community.pocket.ui.main.ui.visitor; import android.os.Build; import android.os.Bundle; import android.text.format.DateFormat; +import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.widget.Button; @@ -14,16 +15,18 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; +import androidx.core.widget.NestedScrollView; import androidx.gridlayout.widget.GridLayout; import com.community.pocket.R; +import com.community.pocket.data.model.Page; import com.community.pocket.data.model.Visitor; import com.community.pocket.ui.BaseFragment; import com.community.pocket.util.PropertiesUtil; +import org.xutils.view.annotation.Event; import org.xutils.view.annotation.ViewInject; -import java.util.List; import java.util.Objects; /** @@ -61,16 +64,19 @@ public abstract class VisitorMyVisitor extends BaseFragment { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); this.initTip(); + this.loadMore(); } /** * 初始化数据 */ - protected void loadData(List visitors) { - gridLayout.removeAllViews(); - for (final Visitor visitor : visitors) { + protected void loadData(Page visitors) { + if (visitors.getCurrentPage() == 1 && !visitors.isEmpty()) { + gridLayout.removeViews(4, gridLayout.getChildCount() - 4); + } + for (final Visitor visitor : visitors.getList()) { 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)); switch (visitor.getStatus()) { @@ -80,13 +86,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { 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); - } - }); + button.setOnClickListener(v -> createAlertNotes(visitor)); gridLayout.addView(button); break; 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(); layoutParams.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f); textView.setLayoutParams(layoutParams); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); gridLayout.addView(textView); } @@ -144,12 +164,7 @@ public abstract class VisitorMyVisitor extends BaseFragment { Button button = view.findViewById(R.id.close); AlertDialog.Builder alert = new AlertDialog.Builder(Objects.requireNonNull(getContext())); final AlertDialog alertDialog = alert.setTitle(R.string.visitor_traffic_permit).setView(view).create(); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - alertDialog.dismiss(); - } - }); + button.setOnClickListener(v -> alertDialog.dismiss()); alertDialog.show(); } @@ -158,4 +173,13 @@ public abstract class VisitorMyVisitor extends BaseFragment { String format = PropertiesUtil.getValue("date.pattern"); tip.setText(getString(R.string.dateformat_tip, format, DateFormat.format(format, System.currentTimeMillis()))); } + + + /** + * 查询访客数据 + */ + @Event(R.id.query) + private void query(View view) { + load(1L); + } } 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 2b47e15..dc39d2e 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 @@ -5,15 +5,14 @@ import android.view.View; 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.share.Response; +import com.community.pocket.ui.main.ui.visitor.VisitorLoad; import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; 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 Long currentPage; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle 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.loadMy(null, null); + load(1L); //监听我的访客请求状态 - viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(VisitorMyResponse visitorMyResponse) { - if (visitorMyResponse == null) { - return; - } - - visitorMyResponse.toast(getContext()); - - if (visitorMyResponse.getResult() == Response.Result.OK) { - loadData(visitorMyResponse.getVisitorList()); - } + viewModel.getVisitorMyResponse().observe(getViewLifecycleOwner(), visitorMyResponse -> { + if (visitorMyResponse == null) { + return; + } + + visitorMyResponse.toast(getContext()); + + if (visitorMyResponse.getResult() == Response.Result.OK) { + this.currentPage = visitorMyResponse.getVisitorList().getCurrentPage(); + loadData(visitorMyResponse.getVisitorList()); } }); } - /** - * 查询访客数据 - */ - @Event(R.id.query) - private void query(View view) { - viewModel.loadMy(startTime.getText().toString(), endTime.getText().toString()); + @Override + protected Long getCurrentPage() { + return currentPage; + } + + @Override + protected VisitorLoad getViewModel() { + return viewModel; } } 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 index 1f382af..beeb4ff 100644 --- 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 @@ -4,26 +4,27 @@ import androidx.annotation.StringRes; import com.community.pocket.R; 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.util.CustomMessage; import org.jetbrains.annotations.NotNull; -import java.util.List; - public class VisitorMyResponse extends Response { - private List visitorList; + private Page visitorList; - List getVisitorList() { + Page getVisitorList() { return visitorList; } - public void setVisitorList(List visitorList) { + public void setVisitorList(Page visitorList) { this.visitorList = visitorList; } enum Msg implements CustomMessage { 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), token(R.string.invalid_token); 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 16a4575..055325e 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 @@ -4,11 +4,12 @@ import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.main.visitor.VisitorMyRequest; import com.community.pocket.ui.main.ui.share.BaseViewModel; +import com.community.pocket.ui.main.ui.visitor.VisitorLoad; /** * 我的访客UI数据管理 */ -public class VisitorMyViewModel extends BaseViewModel { +public class VisitorMyViewModel extends BaseViewModel implements VisitorLoad { //我的访客数据请求状态 private MutableLiveData visitorMyResponse = new MutableLiveData<>(); @@ -20,8 +21,9 @@ public class VisitorMyViewModel extends BaseViewModel { /** * 加载我的访客 */ - void loadMy(String startDate, String endDate) { - getRequest().loadMy(visitorMyResponse, startDate, endDate); + @Override + public void loadMy(String startDate, String endDate, Long page) { + getRequest().loadMy(visitorMyResponse, startDate, endDate, page); } @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 6cd316c..b192c7b 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 @@ -5,15 +5,14 @@ import android.view.View; 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.share.Response; +import com.community.pocket.ui.main.ui.visitor.VisitorLoad; import com.community.pocket.ui.main.ui.visitor.VisitorMyVisitor; 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 Long currentPage; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle 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.loadReservation(null, null); + load(1L); //监听我的预约请求状态 - viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(VisitorReservationResponse visitorReservationResponse) { - if (visitorReservationResponse == null) { - return; - } - - visitorReservationResponse.toast(getContext()); - - if (visitorReservationResponse.getResult() == Response.Result.OK) { - loadData(visitorReservationResponse.getVisitorList()); - } + viewModel.getVisitorReservationResponse().observe(getViewLifecycleOwner(), visitorReservationResponse -> { + if (visitorReservationResponse == null) { + return; + } + + visitorReservationResponse.toast(getContext()); + + if (visitorReservationResponse.getResult() == Response.Result.OK) { + this.currentPage = visitorReservationResponse.getVisitorList().getCurrentPage(); + loadData(visitorReservationResponse.getVisitorList()); } }); } + @Override + protected Long getCurrentPage() { + return currentPage; + } - /** - * 查询预约数据 - */ - @Event(value = R.id.query) - private void query(View view) { - viewModel.loadReservation(startTime.getText().toString(), endTime.getText().toString()); + @Override + protected VisitorLoad getViewModel() { + return viewModel; } + } 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 index b5578b8..ae26fc9 100644 --- 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 @@ -3,30 +3,31 @@ package com.community.pocket.ui.main.ui.visitor.reservation; import androidx.annotation.StringRes; import com.community.pocket.R; +import com.community.pocket.data.model.Page; import com.community.pocket.data.model.VisitorReservation; import com.community.pocket.ui.main.ui.share.Response; import com.community.pocket.util.CustomMessage; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * 我的预约信息 */ public class VisitorReservationResponse extends Response { - private List visitorList; + private Page visitorList; - List getVisitorList() { + Page getVisitorList() { return visitorList; } - public void setVisitorList(List visitorList) { + public void setVisitorList(Page visitorList) { this.visitorList = visitorList; } enum Msg implements CustomMessage { 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), token(R.string.invalid_token); 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 7748782..1df02e0 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 @@ -4,11 +4,12 @@ import androidx.lifecycle.MutableLiveData; import com.community.pocket.data.main.visitor.VisitorReservationRequest; import com.community.pocket.ui.main.ui.share.BaseViewModel; +import com.community.pocket.ui.main.ui.visitor.VisitorLoad; /** * 我的预约UI数据管理 */ -public class VisitorReservationViewModel extends BaseViewModel { +public class VisitorReservationViewModel extends BaseViewModel implements VisitorLoad { //我的预约请求状态 private MutableLiveData visitorReservationResponse = new MutableLiveData<>(); @@ -17,14 +18,14 @@ public class VisitorReservationViewModel extends BaseViewModel服务端地址应该以http开头 恭喜你发现了新的错误,请联系管理员解决问题 load more forum OK + no more data + load more data OK \ 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 bb3efc6..822d8f6 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -228,4 +228,6 @@ 服务端地址应该以http开头 恭喜你发现了新的错误,请联系管理员解决问题 成功加载更多帖子 + 没有更多数据 + 成功加载更多数据 \ 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 8186377..7bf1072 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,6 +229,8 @@ 服务端地址应该以http开头 恭喜你发现了新的错误,请联系管理员解决问题 load more forum OK + no more data + load more data OK