From b4a74fb6efa1bdf607f7483382cfe26533293e79 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Sun, 19 Apr 2020 20:28:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E6=A3=80=E7=B4=A2=E5=B8=96=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/main/forum/ForumMyRequest.java | 3 ++- .../ui/main/ui/forum/my/ForumMyFragment.java | 27 +++++++++++++++++-- .../ui/main/ui/forum/my/ForumMyViewModel.java | 4 +-- .../layout/forum/layout/forum_my_fragment.xml | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java index 2e067bd..49a3400 100644 --- a/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java +++ b/app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java @@ -31,12 +31,13 @@ public class ForumMyRequest { * 加载我的帖子 */ @HttpRequest("/forum/my") - public void loadForumMy(MutableLiveData liveData, int page) { + public void loadForumMy(MutableLiveData liveData, int page, String title) { HttpUtil.getRequest(HttpUtil.Method.GET, new SimpleHttpParse(liveData).getInterface(ForumMyResponse.class), new FormBody.Builder() .add("currentPage", String.valueOf(page)) .add("username", LocalToken.getUsername()) + .add("title", title) .build()); } } 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 925605f..1915a6b 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,6 +6,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.SearchView; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; @@ -14,6 +15,7 @@ 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; /** * 我的帖子 @@ -23,13 +25,34 @@ public class ForumMyFragment extends ForumPost { private ForumMyViewModel viewModel; + @ViewInject(R.id.search) + private SearchView searchView; + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); - viewModel.loadForumMy(1); + viewModel.loadForumMy(1, ""); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + if (!query.isEmpty()) { + viewModel.loadForumMy(1, searchView.getQuery().toString()); + return true; + } else { + return false; + } + + } + + @Override + public boolean onQueryTextChange(String newText) { + return false; + } + }); //监听我的帖子加载状态 viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer() { @@ -62,6 +85,6 @@ public class ForumMyFragment extends ForumPost { public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - viewModel.loadForumMy(1); + viewModel.loadForumMy(1, ""); } } diff --git a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java index 19c59f3..a16fe2d 100644 --- a/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java +++ b/app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java @@ -15,8 +15,8 @@ public class ForumMyViewModel extends BaseViewModel { return forumMyResponse; } - void loadForumMy(int page) { - getRequest().loadForumMy(forumMyResponse, page); + void loadForumMy(int page, String title) { + getRequest().loadForumMy(forumMyResponse, page, title); } @Override diff --git a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml index ef2aac2..c2d90b0 100644 --- a/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml +++ b/app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml @@ -16,7 +16,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> -