diff --git a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java index a9af179c2..a62f55728 100644 --- a/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/SearchResultsItemAdapter.java @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.yunbao.common.bean.SearchModel; import com.yunbao.main.R; import com.yunbao.main.views.AnchorSearchResultsItemViewHolder; +import com.yunbao.main.views.EmptySearchResultsItemViewHolder; import com.yunbao.main.views.UserSearchResultsItemViewHolder; import java.util.ArrayList; @@ -20,19 +21,22 @@ import java.util.List; */ public class SearchResultsItemAdapter extends RecyclerView.Adapter { private List> lists = new ArrayList<>(); - private final int ANCHOR = 2, USER = 3; + private final int ANCHOR = 2, USER = 3, EMPTY = 4; private int type = -1; //确定是不是全部展示列表 - private boolean isAll = true; + private boolean isAll = true, empty = false; private String searchKey = ""; @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { switch (viewType) { - case ANCHOR: + case ANCHOR:// View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_anchor_search_results_item_holder, parent, false); return new AnchorSearchResultsItemViewHolder(herdView); + case EMPTY: + View emptyView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_search_empty_item_holder, parent, false); + return new EmptySearchResultsItemViewHolder(emptyView); default: View bodyView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_user_search_results_item_holder, parent, false); return new UserSearchResultsItemViewHolder(bodyView); @@ -43,13 +47,13 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof AnchorSearchResultsItemViewHolder) { AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder; - itemViewHolder.showAnchors(lists.get(position), ANCHOR,searchKey); + itemViewHolder.showAnchors(lists.get(position), ANCHOR, searchKey); if (type != 1 && !isAll) { itemViewHolder.hideTypeTitle(); } } else { UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder; - viewHolder.showAnchors(lists.get(position), USER,searchKey); + viewHolder.showAnchors(lists.get(position), USER, searchKey); if (type != 1 && !isAll) { viewHolder.hideTypeTitle(); } @@ -63,6 +67,9 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { @Override public int getItemViewType(int position) { + if (empty) { + return EMPTY; + } if (type == 1 && lists.size() > 1) { if (position == 0) { return ANCHOR; @@ -70,6 +77,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { return USER; } } + return type; } @@ -79,7 +87,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { * @param mLists 數據源 * @param type */ - public void showData(List> mLists, int type,String searchKey) { + public void showData(List> mLists, int type, String searchKey) { + this.searchKey = searchKey; this.type = type; //展示全部列表在只展示用户或者主播的一个判断,服务器在查全部的时候会返回两个集合没数据也会展示一个空集合 @@ -91,8 +100,18 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { if (mLists.get(1).size() == 0) { this.type = USER; } + if (mLists.get(0).size() == 0 && mLists.get(1).size() == 0) { + empty = true; + } else { + empty = false; + } } else { isAll = false; + if (mLists.get(0).size() == 0) { + empty = true; + } else { + empty = false; + } } lists.clear(); for (List searchModels : mLists) { @@ -106,7 +125,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter { /** * 加载更多资源 */ - public void onLoadMoreData(List> mLists,String searchKey) { + public void onLoadMoreData(List> mLists, String searchKey) { this.searchKey = searchKey; lists.addAll(mLists); notifyDataSetChanged(); diff --git a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java index f08359fbe..23297c3e7 100644 --- a/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/SearchResultsItemFragment.java @@ -13,7 +13,6 @@ import com.yunbao.common.dialog.LoadingDialog; import com.yunbao.common.fragment.BaseFragment; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.main.MainNetManager; -import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.OnRecyclerViewScrollListener; import com.yunbao.main.R; import com.yunbao.main.adapter.SearchResultsItemAdapter; @@ -83,9 +82,9 @@ public class SearchResultsItemFragment extends BaseFragment { public void onSuccess(List> data) { fragment.dismiss(); if (page > 1) { - itemAdapter.onLoadMoreData(data,searchKey); + itemAdapter.onLoadMoreData(data, searchKey); } else { - itemAdapter.showData(data, type,searchKey); + itemAdapter.showData(data, type, searchKey); } } @@ -103,18 +102,16 @@ public class SearchResultsItemFragment extends BaseFragment { @Override public void onSuccess(List data) { fragment.dismiss(); - if (data.size() == 0) { + List> listList = new ArrayList<>(); + listList.add(data); + if (page > 1) { + itemAdapter.onLoadMoreData(listList, searchKey); } else { - List> listList = new ArrayList<>(); - listList.add(data); - if (page > 1) { - itemAdapter.onLoadMoreData(listList,searchKey); - } else { - itemAdapter.showData(listList, type,searchKey); - } + itemAdapter.showData(listList, type, searchKey); } + } @Override diff --git a/main/src/main/java/com/yunbao/main/views/EmptySearchResultsItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/EmptySearchResultsItemViewHolder.java new file mode 100644 index 000000000..ea3a29576 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/views/EmptySearchResultsItemViewHolder.java @@ -0,0 +1,12 @@ +package com.yunbao.main.views; + +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +public class EmptySearchResultsItemViewHolder extends RecyclerView.ViewHolder{ + public EmptySearchResultsItemViewHolder(@NonNull View itemView) { + super(itemView); + } +} diff --git a/main/src/main/res/layout/view_search_empty_item_holder.xml b/main/src/main/res/layout/view_search_empty_item_holder.xml new file mode 100644 index 000000000..290ded6e7 --- /dev/null +++ b/main/src/main/res/layout/view_search_empty_item_holder.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/mipmap-xxhdpi/img_search_empty.png b/main/src/main/res/mipmap-xxhdpi/img_search_empty.png new file mode 100644 index 000000000..f366bb41f Binary files /dev/null and b/main/src/main/res/mipmap-xxhdpi/img_search_empty.png differ