修改测试问题,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.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<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 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<List<SearchModel>> mLists, int type,String searchKey) {
|
||||
public void showData(List<List<SearchModel>> 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<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;
|
||||
lists.addAll(mLists);
|
||||
notifyDataSetChanged();
|
||||
|
@ -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<List<SearchModel>> 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<SearchModel> data) {
|
||||
fragment.dismiss();
|
||||
if (data.size() == 0) {
|
||||
|
||||
} else {
|
||||
List<List<SearchModel>> listList = new ArrayList<>();
|
||||
listList.add(data);
|
||||
if (page > 1) {
|
||||
itemAdapter.onLoadMoreData(listList,searchKey);
|
||||
itemAdapter.onLoadMoreData(listList, searchKey);
|
||||
} else {
|
||||
itemAdapter.showData(listList, type,searchKey);
|
||||
}
|
||||
itemAdapter.showData(listList, type, searchKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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