修改测试问题,shouye ytuijian

This commit is contained in:
18401019693 2022-08-10 14:10:49 +08:00
parent e96d0e7bf4
commit 28cd3e5798
5 changed files with 98 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SearchModel;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.views.AnchorSearchResultsItemViewHolder; import com.yunbao.main.views.AnchorSearchResultsItemViewHolder;
import com.yunbao.main.views.EmptySearchResultsItemViewHolder;
import com.yunbao.main.views.UserSearchResultsItemViewHolder; import com.yunbao.main.views.UserSearchResultsItemViewHolder;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,19 +21,22 @@ import java.util.List;
*/ */
public class SearchResultsItemAdapter extends RecyclerView.Adapter { 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, EMPTY = 4;
private int type = -1; private int type = -1;
//确定是不是全部展示列表 //确定是不是全部展示列表
private boolean isAll = true; private boolean isAll = true, empty = false;
private String searchKey = ""; private String searchKey = "";
@NonNull @NonNull
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) { switch (viewType) {
case ANCHOR: case ANCHOR://
View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_anchor_search_results_item_holder, parent, false); View herdView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_anchor_search_results_item_holder, parent, false);
return new AnchorSearchResultsItemViewHolder(herdView); 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: default:
View bodyView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_user_search_results_item_holder, parent, false); View bodyView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_user_search_results_item_holder, parent, false);
return new UserSearchResultsItemViewHolder(bodyView); return new UserSearchResultsItemViewHolder(bodyView);
@ -63,6 +67,9 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (empty) {
return EMPTY;
}
if (type == 1 && lists.size() > 1) { if (type == 1 && lists.size() > 1) {
if (position == 0) { if (position == 0) {
return ANCHOR; return ANCHOR;
@ -70,6 +77,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
return USER; return USER;
} }
} }
return type; return type;
} }
@ -80,6 +88,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
* @param type * @param type
*/ */
public void showData(List<List<SearchModel>> mLists, int type, String searchKey) { public void showData(List<List<SearchModel>> mLists, int type, String searchKey) {
this.searchKey = searchKey; this.searchKey = searchKey;
this.type = type; this.type = type;
//展示全部列表在只展示用户或者主播的一个判断服务器在查全部的时候会返回两个集合没数据也会展示一个空集合 //展示全部列表在只展示用户或者主播的一个判断服务器在查全部的时候会返回两个集合没数据也会展示一个空集合
@ -91,8 +100,18 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
if (mLists.get(1).size() == 0) { if (mLists.get(1).size() == 0) {
this.type = USER; this.type = USER;
} }
if (mLists.get(0).size() == 0 && mLists.get(1).size() == 0) {
empty = true;
} else {
empty = false;
}
} else { } else {
isAll = false; isAll = false;
if (mLists.get(0).size() == 0) {
empty = true;
} else {
empty = false;
}
} }
lists.clear(); lists.clear();
for (List<SearchModel> searchModels : mLists) { for (List<SearchModel> searchModels : mLists) {

View File

@ -13,7 +13,6 @@ import com.yunbao.common.dialog.LoadingDialog;
import com.yunbao.common.fragment.BaseFragment; import com.yunbao.common.fragment.BaseFragment;
import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.main.MainNetManager; import com.yunbao.common.http.main.MainNetManager;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.OnRecyclerViewScrollListener; import com.yunbao.common.views.weight.OnRecyclerViewScrollListener;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.adapter.SearchResultsItemAdapter; import com.yunbao.main.adapter.SearchResultsItemAdapter;
@ -103,9 +102,7 @@ public class SearchResultsItemFragment extends BaseFragment {
@Override @Override
public void onSuccess(List<SearchModel> data) { public void onSuccess(List<SearchModel> data) {
fragment.dismiss(); fragment.dismiss();
if (data.size() == 0) {
} else {
List<List<SearchModel>> listList = new ArrayList<>(); List<List<SearchModel>> listList = new ArrayList<>();
listList.add(data); listList.add(data);
if (page > 1) { if (page > 1) {
@ -113,7 +110,7 @@ public class SearchResultsItemFragment extends BaseFragment {
} else { } else {
itemAdapter.showData(listList, type, searchKey); itemAdapter.showData(listList, type, searchKey);
} }
}
} }

View File

@ -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);
}
}

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="160dp"
android:layout_height="141.67dp"
android:src="@mipmap/img_search_empty" />
<FrameLayout
android:id="@+id/type_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<ImageView
android:id="@+id/change_batch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:background="@mipmap/icon_cange" />
<TextView
android:id="@+id/anchor_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:drawablePadding="5dp"
android:text="@string/you_may_also_like"
android:textColor="#FF000000"
android:textSize="16sp" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:focusable="true"
android:focusableInTouchMode="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/live_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fadingEdge="none" />
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB