修改测试问题,shouye ytuijian
This commit is contained in:
parent
e96d0e7bf4
commit
28cd3e5798
@ -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);
|
||||||
@ -43,13 +47,13 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
|
|||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
if (holder instanceof AnchorSearchResultsItemViewHolder) {
|
if (holder instanceof AnchorSearchResultsItemViewHolder) {
|
||||||
AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder;
|
AnchorSearchResultsItemViewHolder itemViewHolder = (AnchorSearchResultsItemViewHolder) holder;
|
||||||
itemViewHolder.showAnchors(lists.get(position), ANCHOR,searchKey);
|
itemViewHolder.showAnchors(lists.get(position), ANCHOR, searchKey);
|
||||||
if (type != 1 && !isAll) {
|
if (type != 1 && !isAll) {
|
||||||
itemViewHolder.hideTypeTitle();
|
itemViewHolder.hideTypeTitle();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder;
|
UserSearchResultsItemViewHolder viewHolder = (UserSearchResultsItemViewHolder) holder;
|
||||||
viewHolder.showAnchors(lists.get(position), USER,searchKey);
|
viewHolder.showAnchors(lists.get(position), USER, searchKey);
|
||||||
if (type != 1 && !isAll) {
|
if (type != 1 && !isAll) {
|
||||||
viewHolder.hideTypeTitle();
|
viewHolder.hideTypeTitle();
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +87,8 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
|
|||||||
* @param mLists 數據源
|
* @param mLists 數據源
|
||||||
* @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) {
|
||||||
@ -106,7 +125,7 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
|
|||||||
/**
|
/**
|
||||||
* 加载更多资源
|
* 加载更多资源
|
||||||
*/
|
*/
|
||||||
public void onLoadMoreData(List<List<SearchModel>> mLists,String searchKey) {
|
public void onLoadMoreData(List<List<SearchModel>> mLists, String searchKey) {
|
||||||
this.searchKey = searchKey;
|
this.searchKey = searchKey;
|
||||||
lists.addAll(mLists);
|
lists.addAll(mLists);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
@ -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;
|
||||||
@ -83,9 +82,9 @@ public class SearchResultsItemFragment extends BaseFragment {
|
|||||||
public void onSuccess(List<List<SearchModel>> data) {
|
public void onSuccess(List<List<SearchModel>> data) {
|
||||||
fragment.dismiss();
|
fragment.dismiss();
|
||||||
if (page > 1) {
|
if (page > 1) {
|
||||||
itemAdapter.onLoadMoreData(data,searchKey);
|
itemAdapter.onLoadMoreData(data, searchKey);
|
||||||
} else {
|
} else {
|
||||||
itemAdapter.showData(data, type,searchKey);
|
itemAdapter.showData(data, type, searchKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,18 +102,16 @@ 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) {
|
||||||
itemAdapter.onLoadMoreData(listList,searchKey);
|
itemAdapter.onLoadMoreData(listList, searchKey);
|
||||||
} else {
|
} else {
|
||||||
itemAdapter.showData(listList, type,searchKey);
|
itemAdapter.showData(listList, type, searchKey);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
52
main/src/main/res/layout/view_search_empty_item_holder.xml
Normal file
52
main/src/main/res/layout/view_search_empty_item_holder.xml
Normal 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>
|
BIN
main/src/main/res/mipmap-xxhdpi/img_search_empty.png
Normal file
BIN
main/src/main/res/mipmap-xxhdpi/img_search_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 309 KiB |
Loading…
Reference in New Issue
Block a user