|
|
@@ -33,6 +33,8 @@ import com.sheep.gamegroup.view.adapter.AdpTitleInfoList;
|
|
|
import com.sheep.gamegroup.view.fragment.FgtSearchAppOrTask;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+import com.umeng.socialize.utils.Log;
|
|
|
|
|
|
import org.afinal.simplecache.ApiKey;
|
|
|
|
|
|
@@ -50,14 +52,10 @@ import io.reactivex.schedulers.Schedulers;
|
|
|
* realicing@sina.com
|
|
|
*/
|
|
|
public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
- @BindView(R.id.title_search_input)
|
|
|
- AppCompatAutoCompleteTextView title_search_input;
|
|
|
@BindView(R.id.search_app_list)
|
|
|
RecyclerView recyclerView;
|
|
|
@BindView(R.id.frame_container)
|
|
|
View frame_container;
|
|
|
- @BindView(R.id.title_search_commit)
|
|
|
- TextView title_search_commit;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -74,49 +72,39 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setShowOrHide(this, true)
|
|
|
+ .setSearchBox(this, "搜索任务名称/游戏名称",
|
|
|
+ (v, actionId, event) -> {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
+ toSearchApp();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ (text) -> {
|
|
|
+ frame_container.removeCallbacks(autoSearchRunnable);
|
|
|
+ if (text.isEmpty() && !isTitleInfoListEmpty()) {//输入框内容为空且有搜索记录时显示搜索记录
|
|
|
+ recyclerView.setVisibility(View.VISIBLE);
|
|
|
+ frame_container.setVisibility(View.INVISIBLE);
|
|
|
+ } else {
|
|
|
+ frame_container.postDelayed(autoSearchRunnable, 1000L);//1秒后自动搜索
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setRightBtn(this, "搜索", 0,
|
|
|
+ v -> toSearchApp())
|
|
|
+ .setShowOrHide(this, true);
|
|
|
+
|
|
|
recyclerView.setHasFixedSize(true);
|
|
|
recyclerView.setNestedScrollingEnabled(false);
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance()));
|
|
|
AdpTitleInfoList adpTitleInfoList = new AdpTitleInfoList(titleInfoListList);
|
|
|
adpTitleInfoList.bindToRecyclerView(recyclerView);
|
|
|
- title_search_input.setHint("搜索任务名称/游戏名称");
|
|
|
- title_search_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
- @Override
|
|
|
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
- if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
- title_search_commit.performClick();
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- title_search_input.addTextChangedListener(new TextWatcher() {
|
|
|
- @Override
|
|
|
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void afterTextChanged(Editable editable) {
|
|
|
- title_search_input.removeCallbacks(autoSearchRunnable);
|
|
|
- if (editable.toString().isEmpty() && !isTitleInfoListEmpty()) {//输入框内容为空且有搜索记录时显示搜索记录
|
|
|
- recyclerView.setVisibility(View.VISIBLE);
|
|
|
- frame_container.setVisibility(View.INVISIBLE);
|
|
|
- } else {
|
|
|
- title_search_input.postDelayed(autoSearchRunnable, 1000L);//1秒后自动搜索
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
private Runnable autoSearchRunnable = new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if (title_search_commit != null)
|
|
|
- title_search_commit.performClick();
|
|
|
+ toSearchApp();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -124,6 +112,7 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
public static final int SORT_TOP_SEARCH = 1;//热门推荐 的排序
|
|
|
public static final int SORT_SEARCH_RECORD = 2;//搜索历史 的排序
|
|
|
List<ISearchRecord> topSearchStatisticsList = new ArrayList<>();
|
|
|
+
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
//尝试获取缓存数据
|
|
|
@@ -141,34 +130,35 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
}
|
|
|
notifyDataSetChangedTitleInfoList();
|
|
|
SheepApp.getInstance().getNetComponent().getApiService().getTopSearchStatistics()
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
- @Override
|
|
|
- public void onNext(BaseMessage baseMessage) {
|
|
|
- boolean isNewData = DataUtil.getInstance().isNewData(ApiKey.top_search_statistics);
|
|
|
- if (isNewData) {
|
|
|
- List<TopSearchStatistics> newList = baseMessage.getDatas(TopSearchStatistics.class);
|
|
|
- topSearchStatisticsList.clear();
|
|
|
- topSearchStatisticsList.addAll(newList);
|
|
|
- if(ListUtil.getItem(titleInfoListList, new ListUtil.CallBack<TitleInfoList, Boolean>() {
|
|
|
- @Override
|
|
|
- public Boolean call(TitleInfoList titleInfoList) {
|
|
|
- return titleInfoList.getSort() == SORT_TOP_SEARCH;
|
|
|
- }
|
|
|
- }) == null){
|
|
|
- addListData("热门推荐", topSearchStatisticsList, SORT_TOP_SEARCH);
|
|
|
- }
|
|
|
- notifyDataSetChangedTitleInfoList();
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ boolean isNewData = DataUtil.getInstance().isNewData(ApiKey.top_search_statistics);
|
|
|
+ if (isNewData) {
|
|
|
+ List<TopSearchStatistics> newList = baseMessage.getDatas(TopSearchStatistics.class);
|
|
|
+ topSearchStatisticsList.clear();
|
|
|
+ topSearchStatisticsList.addAll(newList);
|
|
|
+ if (ListUtil.getItem(titleInfoListList, new ListUtil.CallBack<TitleInfoList, Boolean>() {
|
|
|
+ @Override
|
|
|
+ public Boolean call(TitleInfoList titleInfoList) {
|
|
|
+ return titleInfoList.getSort() == SORT_TOP_SEARCH;
|
|
|
}
|
|
|
+ }) == null) {
|
|
|
+ addListData("热门推荐", topSearchStatisticsList, SORT_TOP_SEARCH);
|
|
|
}
|
|
|
+ notifyDataSetChangedTitleInfoList();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onError(BaseMessage baseMessage) {
|
|
|
- }
|
|
|
- });
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
+
|
|
|
//排序与刷新
|
|
|
private void notifyDataSetChangedTitleInfoList() {
|
|
|
//排序
|
|
|
@@ -193,7 +183,7 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
TextView item_search_record_name = view.findViewById(R.id.item_search_record_name);
|
|
|
ImageView item_search_record_x = view.findViewById(R.id.item_search_record_x);
|
|
|
ViewUtil.setText(item_search_record_name, item.getInput());
|
|
|
- if(item instanceof SearchRecord) {
|
|
|
+ if (item instanceof SearchRecord) {
|
|
|
//点击一条搜索历史后面的xx
|
|
|
item_search_record_x.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
@@ -214,9 +204,8 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
view.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- title_search_input.setText(item.getInput());
|
|
|
- title_search_input.setSelection(item.getInput().length());
|
|
|
- if(item instanceof IHomePageSearch)
|
|
|
+ TitleBarUtils.getInstance().setSearchText(ActSearchAppOrTask.this, item.getInput());
|
|
|
+ if (item instanceof IHomePageSearch)
|
|
|
ApiUtil.postTopSearchStatisticsClickTopSearch((IHomePageSearch) item);
|
|
|
}
|
|
|
});
|
|
|
@@ -226,19 +215,7 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
|
|
|
//搜索历史中没有数据且没有获取到服务器的热门搜索列表
|
|
|
private boolean isTitleInfoListEmpty() {
|
|
|
- return searchRecordList.isEmpty() && topSearchStatisticsList.isEmpty() ;
|
|
|
- }
|
|
|
-
|
|
|
- @OnClick({R.id.title_search_commit, R.id.title_img_back})
|
|
|
- public void onViewClicked(View view) {
|
|
|
- switch (view.getId()) {
|
|
|
- case R.id.title_search_commit:
|
|
|
- toSearchApp();
|
|
|
- break;
|
|
|
- case R.id.title_img_back:
|
|
|
- finish();
|
|
|
- break;
|
|
|
- }
|
|
|
+ return searchRecordList.isEmpty() && topSearchStatisticsList.isEmpty();
|
|
|
}
|
|
|
|
|
|
List<ISearchRecord> searchRecordList = new ArrayList<>();
|
|
|
@@ -247,10 +224,10 @@ public class ActSearchAppOrTask extends BaseContainerActivity {
|
|
|
private void toSearchApp() {
|
|
|
recyclerView.setVisibility(View.INVISIBLE);
|
|
|
frame_container.setVisibility(View.VISIBLE);
|
|
|
- String inputText = title_search_input.getText().toString();
|
|
|
+ String inputText = TitleBarUtils.getInstance().getSearchText(this);
|
|
|
if (!TextUtils.isEmpty(inputText)) {
|
|
|
//保存搜索到数据库
|
|
|
- SearchRecord searchRecord = new SearchRecord();
|
|
|
+ SearchRecord searchRecord = new SearchRecord();
|
|
|
searchRecord.setInput(inputText);
|
|
|
searchRecord.setLast_time(System.currentTimeMillis());
|
|
|
searchRecord.setCount(1);
|