全部检索界面优化

This commit is contained in:
18401019693 2022-08-06 15:46:11 +08:00
parent fadf7c5655
commit c15a420307

View File

@ -22,6 +22,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
private List<List<SearchModel>> lists = new ArrayList<>(); private List<List<SearchModel>> lists = new ArrayList<>();
private final int ANCHOR = 2, USER = 3; private final int ANCHOR = 2, USER = 3;
private int type = -1; private int type = -1;
//确定是不是全部展示列表
private boolean isAll = true;
@NonNull @NonNull
@Override @Override
@ -41,13 +43,13 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
if (holder instanceof AnchorSearchResultsItemViewHolder) { if (holder instanceof AnchorSearchResultsItemViewHolder) {
AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder; AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder;
itemViewHolder.showAnchors(lists.get(position), ANCHOR); itemViewHolder.showAnchors(lists.get(position), ANCHOR);
if (type != 1) { if (type != 1 && !isAll) {
itemViewHolder.hideTypeTitle(); itemViewHolder.hideTypeTitle();
} }
} else { } else {
UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder; UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder;
viewHolder.showAnchors(lists.get(position), USER); viewHolder.showAnchors(lists.get(position), USER);
if (type != 1) { if (type != 1 && !isAll) {
viewHolder.hideTypeTitle(); viewHolder.hideTypeTitle();
} }
} }
@ -60,7 +62,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (type == 1) { if (type == 1 && lists.size() > 1) {
if (position == (lists.size() - 1)) { if (position == (lists.size() - 1)) {
return ANCHOR; return ANCHOR;
} else { } else {
@ -71,15 +73,31 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
} }
/** /**
* 設置數據源 * 設置數據源(处理数据源)
* *
* @param mLists 數據源 * @param mLists 數據源
* @param type * @param type
*/ */
public void showData(List<List<SearchModel>> mLists, int type) { public void showData(List<List<SearchModel>> mLists, int type) {
this.type = type; this.type = type;
//展示全部列表在只展示用户或者主播的一个判断服务器在查全部的时候会返回两个集合没数据也会展示一个空集合
if (mLists.size() > 1) {
isAll = true;
if (mLists.get(0).size() == 0) {
this.type = ANCHOR;
}
if (mLists.get(1).size() == 0) {
this.type = USER;
}
} else {
isAll = false;
}
lists.clear(); lists.clear();
lists.addAll(mLists); for (List<SearchModel> searchModels : mLists) {
if (searchModels.size() > 0) {
lists.add(searchModels);
}
}
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }