完善搜索功能模块
This commit is contained in:
@@ -100,4 +100,12 @@ public class SearchResultsItemAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多资源
|
||||
*/
|
||||
public void onLoadMoreData(List<List<SearchModel>> mLists) {
|
||||
lists.addAll(mLists);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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;
|
||||
import com.yunbao.main.utils.WordsTypeUtil;
|
||||
@@ -27,6 +28,7 @@ import java.util.List;
|
||||
public class SearchResultsItemFragment extends BaseFragment {
|
||||
private String searchKey = "";
|
||||
private int page = 1;
|
||||
private int type = 1;
|
||||
private RecyclerView searchList;
|
||||
private SearchResultsItemAdapter itemAdapter;
|
||||
|
||||
@@ -46,6 +48,13 @@ public class SearchResultsItemFragment extends BaseFragment {
|
||||
itemAdapter = new SearchResultsItemAdapter();
|
||||
searchList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
|
||||
searchList.setAdapter(itemAdapter);
|
||||
searchList.addOnScrollListener(new OnRecyclerViewScrollListener() {
|
||||
@Override
|
||||
public void onBottom() {
|
||||
page = page + 1;
|
||||
setSearchKey(searchKey, type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +73,7 @@ public class SearchResultsItemFragment extends BaseFragment {
|
||||
LoadingDialog fragment = new LoadingDialog();
|
||||
fragment.show(getChildFragmentManager(), "LoadingDialog");
|
||||
this.searchKey = searchKey;
|
||||
this.type = type;
|
||||
if (type == 1) {
|
||||
MainNetManager.get(getActivity())
|
||||
.search(WordsTypeUtil.changeSimplified(searchKey),
|
||||
@@ -71,7 +81,11 @@ public class SearchResultsItemFragment extends BaseFragment {
|
||||
type, page, new HttpCallback<List<List<SearchModel>>>() {
|
||||
@Override
|
||||
public void onSuccess(List<List<SearchModel>> data) {
|
||||
itemAdapter.showData(data, type);
|
||||
if (page > 1) {
|
||||
itemAdapter.onLoadMoreData(data);
|
||||
} else {
|
||||
itemAdapter.showData(data, type);
|
||||
}
|
||||
fragment.dismiss();
|
||||
}
|
||||
|
||||
@@ -88,9 +102,18 @@ public class SearchResultsItemFragment extends BaseFragment {
|
||||
type, page, new HttpCallback<List<SearchModel>>() {
|
||||
@Override
|
||||
public void onSuccess(List<SearchModel> data) {
|
||||
List<List<SearchModel>> listList = new ArrayList<>();
|
||||
listList.add(data);
|
||||
itemAdapter.showData(listList, type);
|
||||
if (data.size() == 0) {
|
||||
ToastUtil.show(R.string.refresh_footer_nothing);
|
||||
} else {
|
||||
List<List<SearchModel>> listList = new ArrayList<>();
|
||||
listList.add(data);
|
||||
if (page > 1) {
|
||||
itemAdapter.onLoadMoreData(listList);
|
||||
} else {
|
||||
itemAdapter.showData(listList, type);
|
||||
}
|
||||
}
|
||||
|
||||
fragment.dismiss();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user