UI-搜索框带俩页签

搜索框带俩页签

效果图

搜索带两页签.gif

代码

  1. Activity内有个FrameLayout布局,FrameLayout布局动态替换历史记录和搜索结果
  2. 历史记录存储于本地,点击某一搜索历史可以调用搜索
  3. 调用搜索直接切换到搜索结果
  4. 搜索结果页面布局 tabLayout+NoScrollViewPager,点击切换or滑动切换子Fragment

contract

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:56
* email :shenbh@qq.com
* desc : 平台页搜索
* </pre>
*/
public interface GoodsStoreSearchContract {
interface SearchView extends MvpView {
void __getDataSuccess(boolean pIsLoadByRefresh, SearchRecordBean pGoodsStoreSearch);
void __getDataFail();
void __clearHistorySuccess();
}

interface SearchResultView extends MvpView{
//帖子
void __getTopicListSuccess(boolean pIsLoadByRefresh, SearchResultGoodsBean pGoodsStoreSearchResultBean);
//社群分类
void __getCircleListSuccess(boolean pIsLoadByRefresh, SearchResultStoresBean GoodsStoreSearchResultClassBean);
void __getDataFail();
void saveTopicLoves(int position, String result);
}
}

入口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package xxx.xxx.view.found.search;

import android.graphics.Color;
import android.support.annotation.LayoutRes;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.u1city.androidframe.common.cache.PreferencesUtils;
import com.u1city.androidframe.common.system.KeyBoardUtils;
import com.u1city.androidframe.common.text.StringUtils;
import com.u1city.androidframe.customView.ClearEditText;

import xxx.xxx.R;
import xxx.xxx.base.LdyBaseActivity;
import xxx.xxx.center.StringConstantUtils;
import xxx.xxx.core.App;
import xxx.xxx.core.Constants;
import xxx.xxx.core.SqliteUtils;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:56
* email :shenbh@qq.com
* desc : 平台页搜索入口页面
* </pre>
*/
public class GoodsStoreSearchActivity extends LdyBaseActivity {
@LayoutRes
private static final int PAGE_LAYOUT_RES_ID = R.layout.activity_platform_search;

@Bind(R.id.title_search_focus_cet)
ClearEditText mTitleSearchFocusCet;
@Bind(R.id.title_search_cet)
ClearEditText mTitleSearchCet;
@Bind(R.id.title_ll)
LinearLayout mTitleLl;

@Bind(R.id.community_space_fl)
FrameLayout mCommunitySpaceFl;

private FragmentManager mFragmentManager;


@Override
protected void onDestroy() {
super.onDestroy();
ButterKnife.unbind(this);
}

@Override
protected int setLayoutResId() {
return PAGE_LAYOUT_RES_ID;
}

@Override
protected void onCreate() {
setImmersion();
initView();
setListener();

mFragmentManager = getSupportFragmentManager();
showSearchResult(false);
}

@Override
public void setImmersion() {
getImmersion().statusBarDarkFont(true);
getImmersion().keyboardEnable();
}

private void initView() {
LinearLayout.LayoutParams lp = (LayoutParams) mTitleLl.getLayoutParams();
lp.setMargins(0, BarUtils.getStatusBarHeight(), 0, 0);
mTitleLl.setLayoutParams(lp);
}


private void setListener() {
// TODO:sbh 2019/5/22 如果搜索内容清空了,是否要切换回搜索热词页面
mTitleSearchCet.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
startSearch(mTitleSearchCet.getText().toString());
KeyBoardUtils.closeKeybord(mTitleSearchCet, GoodsStoreSearchActivity.this);
}
return false;
}
});

mTitleSearchCet.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateKeyWord();
}

@Override
public void afterTextChanged(Editable s) {

}
});
}

/**
* 根据关键词进行搜索
* @param word 关键词
*/
public void startSearch(String word) {
if (StringUtils.isEmpty(word)){
return;
}

mTitleSearchCet.setText(word);
mTitleSearchFocusCet.requestFocus();
KeyBoardUtils.closeKeybord(mTitleSearchCet, this);
showSearchResult(true);

if (Constants.cust != null) {
//保存到数据库
SqliteUtils.getInstance().saveGoodsStoreSearchHistroy(word, Constants.getCustomerId());
}
}

private void showSearchResult(boolean show) {
updateKeyWord();
if (show) {//显示搜索结果
// toolbarTitle.setText("搜索结果");
changeToResultPage();
hideSoftKeyBoard();
} else {//显示搜索热词页面
changeToSearchPage();
}
}

/**
* 切换到搜索关键词页面
*/
private void changeToSearchPage(){
mFragmentManager.beginTransaction().replace(R.id.community_space_fl,
GoodsStoreSearchRecordFragment.newInstance(null)).commit();
}

/**
* 切换到搜索结果页面
*/
private void changeToResultPage(){
mFragmentManager.beginTransaction().replace(R.id.community_space_fl,
GoodsStoreSearchResultFragment.newInstance(null)).commit();
}

private void updateKeyWord(){
PreferencesUtils.putStringPreferences(App.getContext(), StringConstantUtils.KEY_KEYWORD,
mTitleSearchCet.getText().toString());
}

@OnClick({R.id.title_search_cancel_tv})
public void click(View view) {
switch(view.getId()){
case R.id.title_search_cancel_tv://取消
// showSearchResult(false);
finishAnimation();
break;
default:
break;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//activity_platform_search.xml
<?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:background="@color/white"
android:orientation="vertical">

<include
android:id="@+id/title_ll"
layout="@layout/platform_search_title"
android:layout_width="match_parent"
android:layout_marginTop="34dp"
android:layout_height="wrap_content"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/community_space_fl"/>
</LinearLayout>

历史记录和结果

历史记录Fragment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//GoodsStoreSearchRecordFragment.java


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.u1city.androidframe.common.display.DimensUtil;
import com.u1city.androidframe.common.network.NetUtil;
import com.u1city.androidframe.common.toast.ToastUtil;

import java.util.List;
import java.util.Map;

import xxx.xxx.R;
import xxx.xxx.base.LdyBaseFragment;
import xxx.xxx.base.LdyBaseMvpFragment;
import xxx.xxx.center.ShapeUtil;
import xxx.xxx.core.Constants;
import xxx.xxx.core.SqliteUtils;
import xxx.xxx.view.found.search.bean.SearchRecordBean;
import xxx.xxx.view.found.search.bean.SearchRecordChildBean;
import xxx.xxx.view.productList.FlowLayout;
import xxx.xxx.view.productList.TagAdapter;
import xxx.xxx.view.productList.TagFlowLayout;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:56
* email :shenbh@qq.com
* desc : 平台页搜索-历史记录页面
* </pre>
*/
public class GoodsStoreSearchRecordFragment extends LdyBaseFragment {

@LayoutRes
private static final int PAGE_LAYOUT_RES_ID = R.layout.fragment_goods_stores_search_record;


@Bind(R.id.history_tv)
TextView mHistoryTv;
@Bind(R.id.history_delete_iv)
ImageView mHistoryDeleteIv;
@Bind(R.id.history_rl)
RelativeLayout mHistoryRl;
@Bind(R.id.history_search_tfl)
TagFlowLayout mHistorySearchTfl;
@Bind(R.id.empty_tv)
TextView emptyTv;

public static GoodsStoreSearchRecordFragment newInstance(Map<String, Object> map) {
GoodsStoreSearchRecordFragment fragment = new GoodsStoreSearchRecordFragment();
return fragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}


/**
* 更新历史搜索数据
*/
private void updateHistorySearchData(){
if (Constants.cust != null) {
List<SearchRecordChildBean> searcHistoryList = SqliteUtils.getInstance().getGoodsStoreSearchHistory(Constants.getCustomerId());
setHistorySearchView(searcHistoryList);
}
}

private void initView() {

}

/**
* 初始化一些基本的参数
*/
private void initParams() {

}

@Override
protected int setLayoutResId() {
return PAGE_LAYOUT_RES_ID;
}

@Override
protected void lazyLoadData() {
// 这里不用smartRefreshLayout的进度圈是因为显示的时机有点滞后

updateHistorySearchData();
}


/**
* 设置 TagFlowLayout 的数据(热门搜索和历史搜索)
* @param titleList 关键词集合
* @param tfl TagFlowLayout
*/
private void setTagFlowLayoutData(final List<SearchRecordChildBean> titleList, final TagFlowLayout tfl){
final int width = (DimensUtil.getDisplayWidth(mContext) - 30) / DimensUtil.dpToPixels(mContext, 13);
if (titleList.size() > 0){
tfl.setAdapter(new TagAdapter<SearchRecordChildBean>(titleList) {
@Override
public View getView(TagFlowLayout parent, int position, Object s) {
String title = ((SearchRecordChildBean)s).getKeyword();
if (title.length() >= width) {
title = title.substring(0, width - 1) + "...";
}
TextView tv = (TextView) getLayoutInflater().inflate(R.layout.item_flow_layout, tfl, false);
ShapeUtil.getInstance().setInnerTextColorStroke(tv);
tv.setPadding(14, 10, 14, 10);
tv.setText(title);
return tv;
}
});

tfl.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
@Override
public boolean onTagClick(View view, int position, FlowLayout parent) {
String word = titleList.get(position).getKeyword();
if (getActivity() != null) {
((GoodsStoreSearchActivity)getActivity()).startSearch(word);
}
return true;
}
});
}
}

/**
* 设置历史搜索列表数据 的布局
*
* @param historySearchDatas 历史搜索词语的集合
*/
private void setHistorySearchView(final List<SearchRecordChildBean> historySearchDatas) {
if (historySearchDatas == null || historySearchDatas.size() == 0) {
mHistoryRl.setVisibility(View.VISIBLE);
mHistorySearchTfl.setVisibility(View.GONE);
emptyTv.setVisibility(View.VISIBLE);
return;
}
mHistoryRl.setVisibility(View.VISIBLE);
mHistorySearchTfl.setVisibility(View.VISIBLE);
emptyTv.setVisibility(View.GONE);

setTagFlowLayoutData(historySearchDatas, mHistorySearchTfl);
}

private Context mContext;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
}

@Override
public void onDetach() {
super.onDetach();
mContext = null;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO: inflate a fragment view
View rootView = super.onCreateView(inflater, container, savedInstanceState);
ButterKnife.bind(this, rootView);
return rootView;
}

@Override
protected void onViewCreated() {
initParams();
initView();
}

@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}

@OnClick(R.id.history_delete_iv)
public void onViewClicked() {
if (Constants.cust != null) {
SqliteUtils.getInstance().clearGoodsStoreSearchHistroy(Constants.getCustomerId());
}

updateHistorySearchData();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//fragment_goods_stores_search_record.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:zhy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
tools:visibility="visible">

<ScrollView
android:id="@+id/search_scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:scrollbars="none">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<RelativeLayout
android:id="@+id/history_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:layout_below="@+id/hot_search_tfl"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingTop="10dp">

<TextView
android:id="@+id/history_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:text="历史搜索"
android:textColor="@color/light_text_color"
android:textSize="12sp" />

<ImageView
android:id="@+id/history_delete_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_delete" />
</RelativeLayout>

<xxx.xxx.view.productList.TagFlowLayout
android:id="@+id/history_search_tfl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingLeft="15dp"
android:layout_below="@+id/history_rl"
android:visibility="gone"
tools:visibility="visible"
zhy:max_select="-1" />

<TextView
android:layout_below="@+id/history_rl"
android:id="@+id/empty_tv"
android:paddingLeft="15dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="无搜索历史"/>
</RelativeLayout>
</ScrollView>
</LinearLayout>

搜索结果Frament

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//GoodsStoreSearchResultFragment.java

/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:57
* email :shenbh@qq.com
* desc : 平台页搜索-搜索结果页面
* </pre>
*/
public class GoodsStoreSearchResultFragment extends LdyBaseFragment {

@LayoutRes
private static final int PAGE_LAYOUT_RES_ID = R.layout.fragment_community_space_search_result;

@Bind(R.id.community_search_result_main_tl)
TabLayout communitySearchResultMainTl;
@Bind(R.id.community_search_result_main_vp)
NoScrollViewPager communitySearchResultMainVp;

private String[] tabNames = new String[]{"商品", "门店"};

private GoodsStoreSearchResultFragmentPagerAdapter pagerAdapter;

public static GoodsStoreSearchResultFragment newInstance(Map<String, Object> map) {
GoodsStoreSearchResultFragment fragment = new GoodsStoreSearchResultFragment();
if (map != null) {
Bundle args = new Bundle();
args.putString("keyWord", (String) map.get("keyWord"));
fragment.setArguments(args);
}
return fragment;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ButterKnife.bind(this, super.onCreateView(inflater, container, savedInstanceState));
return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
protected void onViewCreated() {
initParams();
initView();
}

/**
* 初始化一些基本的参数
*/
private void initParams() {

}

private void initView() {
initTab();
}

@Override
protected int setLayoutResId() {
return PAGE_LAYOUT_RES_ID;
}

@Override
protected void lazyLoadData() {

}

private void initTab() {
pagerAdapter = new GoodsStoreSearchResultFragmentPagerAdapter(getChildFragmentManager());
communitySearchResultMainVp.setAdapter(pagerAdapter);
communitySearchResultMainVp.setCanScroll(true);

ArrayList<TabListBean> tabs = new ArrayList<>();
for (int i = 0, size = tabNames.length; i < size; i++) {
WeakReference<TabListBean> wf = new WeakReference<>(new TabListBean());
wf.get().setTabName(tabNames[i]);
tabs.add(wf.get());
}

if (pagerAdapter != null) {
pagerAdapter.setData(tabs);
}

communitySearchResultMainTl.setupWithViewPager(communitySearchResultMainVp);
}

@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}

class GoodsStoreSearchResultFragmentPagerAdapter extends FragmentStatePagerAdapter {

private List<TabListBean> mTabListBeans = new ArrayList<>();
private List<RxFragment> mRxFragments = new ArrayList<>();
private FragmentManager mFragmentManager;

public void setData(@NonNull List<TabListBean> data) {
mTabListBeans = data;
FragmentTransaction ft = mFragmentManager.beginTransaction();//获得FragmentTransaction 事务
for (RxFragment fragment : mRxFragments) {
ft.remove(fragment);
}
ft.commitAllowingStateLoss();
ft = null;
mFragmentManager.executePendingTransactions();//提交事务
mRxFragments.clear();
// for (int i = 0; i < mTabListBeans.size(); i++) {
// mRxFragments.add(pageType == 0 ?
// GoodsStoreSearchResultPostFragment.newInstance(null) :
// PageFragment.newInstance(mTabListBeans.get(i).getTemplateId()));
// }

// 子Fragment,用来切换搜索结果
mRxFragments.add(GoodsStoreSearchResultGoodsFragment.newInstance(null));
mRxFragments.add(GoodsStoreSearchResultStoresFragment.newInstance(null));

notifyDataSetChanged();
}

public List<TabListBean> getList() {
return mTabListBeans;
}

public GoodsStoreSearchResultFragmentPagerAdapter(FragmentManager fm) {
super(fm);
mFragmentManager = fm;
}

@Override
public Fragment getItem(int position) {
return mRxFragments.get(position);
}

@Override
public int getCount() {
return ListUtils.isEmpty(mTabListBeans) ? 0 : mTabListBeans.size();
}

@Override
public CharSequence getPageTitle(int position) {
return mTabListBeans.get(position).getTabName();
}

@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
}

public void releaseFragment(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
}
}

布局文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//fragment_community_space_search_result
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.TabLayout
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
android:id="@+id/community_search_result_main_tl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="@android:color/white"
app:tabIndicatorColor="@color/main_color"
app:tabSelectedTextColor="@color/main_color"
app:tabTextColor="@color/dark_text_color" />

<View style="@style/ViewBoldSolidLine"/>

<com.u1city.androidframe.customView.NoScrollViewPager
android:id="@+id/community_search_result_main_vp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

数据请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
public class GoodsStoreSearchResultPresenter extends MvpBasePresenter<GoodsStoreSearchContract.SearchResultView> {

public GoodsStoreSearchResultPresenter(Context context) {
super(context);
}

public void getPlatformSearchProductListByKeyword(final boolean pIsLoadByRefresh,
final String keyWord, final int pageIndex, final int pageSize){
RxRequest.rxRequest(mContext, new Observable.OnSubscribe<BaseAnalysis>() {
@Override
public void call(final Subscriber<? super BaseAnalysis> subscriber) {
RequestApi.getInstance().getPlatformSearchProductListByKeyword(keyWord, pageIndex, pageSize,new StandardCallback(mContext, true, true) {
@Override
public void onResult(BaseAnalysis analysis) throws Exception {
subscriber.onNext(analysis);
subscriber.onCompleted();
}

@Override
public void onError(int type) {}

@Override
public void onError(BaseAnalysis baseAnalysis) {
super.onError(baseAnalysis);
subscriber.onError(new Throwable(baseAnalysis.msg()));
}
});
}
}).compose(RxSchedulers.<BaseAnalysis>request((RxAppCompatActivity) mContext, getView()))
.subscribe(new RxSubscriber<BaseAnalysis>(getView()) {
@Override
public void _onNext(BaseAnalysis analysis) {
if (analysis.success()) {
SearchResultGoodsBean bean = new FastJsonFactory().getJson()
.fromJson(analysis.getResult(), SearchResultGoodsBean.class);
getView().__getTopicListSuccess(pIsLoadByRefresh, bean);
addPage();
}
}

@Override
public void _onError(Throwable error) {
getView().__getDataFail();
}
});

}

public void getPlatformAllStoreList(final boolean pIsLoadByRefresh, final String keyWord,
final int pageIndex, final int pageSize, final String longitude, final String latitude){
RxRequest.rxRequest(mContext, new Observable.OnSubscribe<BaseAnalysis>() {
@Override
public void call(final Subscriber<? super BaseAnalysis> subscriber) {
RequestApi.getInstance().getPlatformAllStoreList( keyWord, pageIndex, pageSize, longitude, latitude,new StandardCallback(mContext, true, true) {
@Override
public void onResult(BaseAnalysis analysis) throws Exception {
subscriber.onNext(analysis);
subscriber.onCompleted();
}

@Override
public void onError(int type) {
}

@Override
public void onError(BaseAnalysis baseAnalysis) {
super.onError(baseAnalysis);
subscriber.onError(new Throwable(baseAnalysis.msg()));
}
});
}
}).compose(RxSchedulers.<BaseAnalysis>request((RxAppCompatActivity) mContext, getView()))
.subscribe(new RxSubscriber<BaseAnalysis>(getView()) {
@Override
public void _onNext(BaseAnalysis analysis) {
if (analysis.success()) {
SearchResultStoresBean bean =
new FastJsonFactory().getJson().fromJson(analysis.getResult(), SearchResultStoresBean.class);
getView().__getCircleListSuccess(pIsLoadByRefresh, bean);
addPage();
}
}

@Override
public void _onError(Throwable error) {
getView().__getDataFail();
}
});

}

public void saveTopicLove(final int position,final long TopicId,final String LoveOperate){
Observable.create(new Observable.OnSubscribe<BaseAnalysis>() {
@Override
public void call(final Subscriber<? super BaseAnalysis> subscriber) {
RequestApi.getInstance().saveTopicLoves(TopicId, LoveOperate,new StandardCallback(mContext, true, true) {
@Override
public void onResult(BaseAnalysis analysis) throws Exception {
subscriber.onNext(analysis);
subscriber.onCompleted();
}

@Override
public void onError(int type) {

}

@Override
public void onError(BaseAnalysis baseAnalysis) {
super.onError(baseAnalysis);
// getView().getCommunityTopicListError();
}
});
}
}).compose(RxSchedulers.<BaseAnalysis>request((RxAppCompatActivity) mContext))
.subscribe(new Action1<BaseAnalysis>() {
@Override
public void call(BaseAnalysis analysis) {
try {
String result = analysis.getIntFromResult("topicLoveNumber") + "";
if(!TextUtils.isEmpty(result)){
getView().saveTopicLoves(position,result);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}

@Override
public void destroy() {

}
}

子Fragment

GoodsStoreSearchResultGoodsFragment.java

GoodsStoreSearchResultStoresFragment.java

bean

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:59
* email :shenbh@qq.com
* desc : 平台页搜索-历史记录
* </pre>
*/
@Keep
public class SearchRecordBean {
private String total;
private List<SearchRecordChildBean> hotSearchKeyword;
private List<SearchRecordChildBean> historySearchKeyword;

public void setTotal(String total) {
this.total = total;
}

public String getTotal() {
return total;
}

public List<SearchRecordChildBean> getHotSearchKeyword() {
return hotSearchKeyword;
}

public void setHotSearchKeyword(List<SearchRecordChildBean> hotSearchKeyword) {
this.hotSearchKeyword = hotSearchKeyword;
}

public List<SearchRecordChildBean> getHistorySearchKeyword() {
return historySearchKeyword;
}

public void setHistorySearchKeyword(List<SearchRecordChildBean> historySearchKeyword) {
this.historySearchKeyword = historySearchKeyword;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:59
* email :shenbh@qq.com
* desc : 平台页搜索-历史记录
* </pre>
*/
@Keep
public class SearchRecordChildBean extends DataSupport {
private String customerId;
private String keyword;//关键词
private String times;//搜索次数

public String getCustomerId() {
return customerId;
}

public void setCustomerId(String customerId) {
this.customerId = customerId;
}

public String getKeyword() {
return keyword;
}

public void setKeyword(String keyword) {
this.keyword = keyword;
}

public int getTimes() {
return BaseParser.parseInt(times);
}

public void setTimes(String times) {
this.times = times;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import android.support.annotation.Keep;
import java.util.List;

/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:59
* email :shenbh@qq.com
* desc : 平台页搜索-搜索结果-商品
* </pre>
*/
@Keep
public class SearchResultGoodsBean {
private String total;
private List<PostBean> rows;

public String getTotal() {
return total;
}

public void setTotal(String total) {
this.total = total;
}

public List<PostBean> getRows() {
return rows;
}

public void setRows(List<PostBean> rows) {
this.rows = rows;
}

/**
* 帖子
*/
public static class PostBean {
private String topicId;//帖子主键id
private String publishEasyAgentId;//发帖子id
private String publishNickName;//发帖人昵称
private String publishVipLevelName;//发帖人会员等级
private String publishAvatarUrl;//发帖人头像
private String circleInfoId;//归属的圈子id
private String circleInfoName;//归属的圈子名称
private String title;//标题
private String firstImageUrl;//帖子首图地址
private String createTime;//发帖时间
private String content;//发帖内容
private String comments;//帖子评论量
private String loves;//帖子点赞量
private String views;//帖子浏览量
private String retransmission;//帖子转发量
private String isTop;//是否置顶;0否;1是
private String isEssence;//是否精华帖;0否;1是
private String status;//0:编辑中;1:审核中;2:正常;3:驳回;4:删除
private String isLoves;//是否已经点赞0-否,1-是

public String getTopicId() {
return topicId;
}

public void setTopicId(String topicId) {
this.topicId = topicId;
}

public String getPublishEasyAgentId() {
return publishEasyAgentId;
}

public void setPublishEasyAgentId(String publishEasyAgentId) {
this.publishEasyAgentId = publishEasyAgentId;
}

public String getPublishNickName() {
return publishNickName;
}

public void setPublishNickName(String publishNickName) {
this.publishNickName = publishNickName;
}

public String getPublishVipLevelName() {
return publishVipLevelName;
}

public void setPublishVipLevelName(String publishVipLevelName) {
this.publishVipLevelName = publishVipLevelName;
}

public String getPublishAvatarUrl() {
return publishAvatarUrl;
}

public void setPublishAvatarUrl(String publishAvatarUrl) {
this.publishAvatarUrl = publishAvatarUrl;
}

public String getCircleInfoId() {
return circleInfoId;
}

public void setCircleInfoId(String circleInfoId) {
this.circleInfoId = circleInfoId;
}

public String getCircleInfoName() {
return circleInfoName;
}

public void setCircleInfoName(String circleInfoName) {
this.circleInfoName = circleInfoName;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getFirstImageUrl() {
return firstImageUrl;
}

public void setFirstImageUrl(String firstImageUrl) {
this.firstImageUrl = firstImageUrl;
}

public String getCreateTime() {
return createTime;
}

public void setCreateTime(String createTime) {
this.createTime = createTime;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}

public String getLoves() {
return loves;
}

public void setLoves(String loves) {
this.loves = loves;
}

public String getViews() {
return views;
}

public void setViews(String views) {
this.views = views;
}

public String getRetransmission() {
return retransmission;
}

public void setRetransmission(String retransmission) {
this.retransmission = retransmission;
}

public String getIsTop() {
return isTop;
}

public void setIsTop(String isTop) {
this.isTop = isTop;
}

public String getIsEssence() {
return isEssence;
}

public void setIsEssence(String isEssence) {
this.isEssence = isEssence;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public boolean getIsLoves() {
//是否已经点赞0-否,1-是
return "1".equals(isLoves);
}

public void setIsLoves(String isLoves) {
//是否已经点赞0-否,1-是
this.isLoves = isLoves;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* <pre>
* @author : shenbh
* time : 2020/6/29 15:58
* email :shenbh@qq.com
* desc : 平台页搜索-搜索结果-门店
* </pre>
*/
@Keep
public class SearchResultStoresBean {
private String total;
private List<ClassBean> rows;

public String getTotal() {
return total;
}

public void setTotal(String total) {
this.total = total;
}

public List<ClassBean> getRows() {
return rows;
}

public void setRows(List<ClassBean> rows) {
this.rows = rows;
}

public static class ClassBean {
private String socialCircleInfoId;//圈子主键
private String iconUrl;//圈子图标
private String circleDescription;//圈子简介
private String name;//圈子名称
private String comment;//圈子里所有帖子的评论数和评论的评论
private String view;//圈子里所有帖子的阅读数
private String attention;//关注该圈子的会员数量
private String topic;//圈子内帖子数量
private String isAttention;//是否关注:0-否 1-是

public String getSocialCircleInfoId() {
return socialCircleInfoId;
}

public void setSocialCircleInfoId(String socialCircleInfoId) {
this.socialCircleInfoId = socialCircleInfoId;
}

public String getIconUrl() {
return iconUrl;
}

public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}

public String getCircleDescription() {
return circleDescription;
}

public void setCircleDescription(String circleDescription) {
this.circleDescription = circleDescription;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public String getView() {
return view;
}

public void setView(String view) {
this.view = view;
}

public String getAttention() {
return attention;
}

public void setAttention(String attention) {
this.attention = attention;
}

public String getTopic() {
return topic;
}

public void setTopic(String topic) {
this.topic = topic;
}

public String getIsAttention() {
return isAttention;
}

public void setIsAttention(String isAttention) {
this.isAttention = isAttention;
}
}
}