增加按标题检索帖子

0515
panqihua 5 years ago
parent 0d4e25ee02
commit b4a74fb6ef
  1. 3
      app/src/main/java/com/community/pocket/data/main/forum/ForumMyRequest.java
  2. 27
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyFragment.java
  3. 4
      app/src/main/java/com/community/pocket/ui/main/ui/forum/my/ForumMyViewModel.java
  4. 2
      app/src/main/res/layout/main/layout/forum/layout/forum_my_fragment.xml

@ -31,12 +31,13 @@ public class ForumMyRequest {
* 加载我的帖子 * 加载我的帖子
*/ */
@HttpRequest("/forum/my") @HttpRequest("/forum/my")
public void loadForumMy(MutableLiveData<ForumMyResponse> liveData, int page) { public void loadForumMy(MutableLiveData<ForumMyResponse> liveData, int page, String title) {
HttpUtil.getRequest(HttpUtil.Method.GET, HttpUtil.getRequest(HttpUtil.Method.GET,
new SimpleHttpParse<ForumMyResponse>(liveData).getInterface(ForumMyResponse.class), new SimpleHttpParse<ForumMyResponse>(liveData).getInterface(ForumMyResponse.class),
new FormBody.Builder() new FormBody.Builder()
.add("currentPage", String.valueOf(page)) .add("currentPage", String.valueOf(page))
.add("username", LocalToken.getUsername()) .add("username", LocalToken.getUsername())
.add("title", title)
.build()); .build());
} }
} }

@ -6,6 +6,7 @@ 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.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; 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 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;
/** /**
* 我的帖子 * 我的帖子
@ -23,13 +25,34 @@ public class ForumMyFragment extends ForumPost {
private ForumMyViewModel viewModel; private ForumMyViewModel viewModel;
@ViewInject(R.id.search)
private SearchView searchView;
@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);
viewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(ForumMyViewModel.class); 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<ForumMyResponse>() { viewModel.getForumMyResponse().observe(getViewLifecycleOwner(), new Observer<ForumMyResponse>() {
@ -62,6 +85,6 @@ public class ForumMyFragment extends ForumPost {
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);
viewModel.loadForumMy(1); viewModel.loadForumMy(1, "");
} }
} }

@ -15,8 +15,8 @@ public class ForumMyViewModel extends BaseViewModel<ForumMyRequest> {
return forumMyResponse; return forumMyResponse;
} }
void loadForumMy(int page) { void loadForumMy(int page, String title) {
getRequest().loadForumMy(forumMyResponse, page); getRequest().loadForumMy(forumMyResponse, page, title);
} }
@Override @Override

@ -16,7 +16,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<SearchView <androidx.appcompat.widget.SearchView
android:id="@+id/search" android:id="@+id/search"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

Loading…
Cancel
Save