|
|
@@ -17,7 +17,9 @@ import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
+import com.sheep.gamegroup.absBase.IHomePageSearch;
|
|
|
import com.sheep.gamegroup.model.entity.SearchAppRecord;
|
|
|
+import com.sheep.gamegroup.util.ApiUtil;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
@@ -26,6 +28,7 @@ import com.sheep.gamegroup.view.adapter.ArrayAdapter;
|
|
|
import com.sheep.gamegroup.view.fragment.FgtSearchApp;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
@@ -35,21 +38,20 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
-import butterknife.OnClick;
|
|
|
|
|
|
/**
|
|
|
* Created by realicing on 2018/9/13.
|
|
|
* realicing@sina.com
|
|
|
*/
|
|
|
public class ActSearchApp extends BaseActivity {
|
|
|
- @BindView(R.id.title_search_input)
|
|
|
- AppCompatAutoCompleteTextView title_search_input;
|
|
|
+ // @BindView(R.id.title_search_input)
|
|
|
+// AppCompatAutoCompleteTextView title_search_input;
|
|
|
@BindView(R.id.search_app_list)
|
|
|
ListView search_app_list;
|
|
|
@BindView(R.id.frame_container)
|
|
|
View frame_container;
|
|
|
- @BindView(R.id.title_search_commit)
|
|
|
- TextView title_search_commit;
|
|
|
+// @BindView(R.id.title_search_commit)
|
|
|
+// TextView title_search_commit;
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
@@ -75,11 +77,11 @@ public class ActSearchApp extends BaseActivity {
|
|
|
}
|
|
|
if (fgtSearchApp == null && fragment instanceof FgtSearchApp)
|
|
|
fgtSearchApp = (FgtSearchApp) fragment;
|
|
|
- inputAdapter = new ArrayAdapter<SearchAppRecord>(SheepApp.getInstance(), R.layout.item_serach_record, searchRecordList){
|
|
|
+ inputAdapter = new ArrayAdapter<SearchAppRecord>(SheepApp.getInstance(), R.layout.item_serach_record, searchRecordList) {
|
|
|
@Override
|
|
|
public boolean convert(int position, View view, ViewGroup parent, final SearchAppRecord item) {
|
|
|
- TextView item_search_record_name = (TextView)view.findViewById(R.id.item_search_record_name);
|
|
|
- ImageView item_search_record_x = (ImageView)view.findViewById(R.id.item_search_record_x);
|
|
|
+ TextView item_search_record_name = (TextView) view.findViewById(R.id.item_search_record_name);
|
|
|
+ ImageView item_search_record_x = (ImageView) view.findViewById(R.id.item_search_record_x);
|
|
|
ViewUtil.setText(item_search_record_name, item.getInput());
|
|
|
item_search_record_x.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
@@ -90,7 +92,7 @@ public class ActSearchApp extends BaseActivity {
|
|
|
ListUtil.addAll(searchRecordList, allSearchRecordList, 10);
|
|
|
inputAdapter.notifyDataSetChanged();
|
|
|
MyDbManager.getInstance().hideSearchApp(item);
|
|
|
- if(searchRecordList.isEmpty()){
|
|
|
+ if (searchRecordList.isEmpty()) {
|
|
|
frame_container.setVisibility(View.VISIBLE);
|
|
|
search_app_list.setVisibility(View.INVISIBLE);
|
|
|
}
|
|
|
@@ -106,73 +108,52 @@ public class ActSearchApp extends BaseActivity {
|
|
|
|
|
|
@Override
|
|
|
public void initListener() {
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setShowOrHide(this, true)
|
|
|
+ .setTitleFinish(this)
|
|
|
+ .setSearchBox(this, "搜索任务名称/游戏名称",
|
|
|
+ (v, actionId, event) -> {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
+ toSearchApp();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ (text) -> {
|
|
|
+ if (text.isEmpty() && !searchRecordList.isEmpty()) {//输入框内容为空且有搜索记录时显示搜索记录
|
|
|
+ search_app_list.setVisibility(View.VISIBLE);
|
|
|
+ frame_container.setVisibility(View.INVISIBLE);
|
|
|
+ } else {
|
|
|
+ frame_container.postDelayed(() -> toSearchApp(), 1000L);//1秒后自动搜索
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setRightBtn(this, "搜索", 0,
|
|
|
+ v -> toSearchApp())
|
|
|
+ .setShowOrHide(this, true);
|
|
|
search_app_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
|
|
SearchAppRecord item = ListUtil.getItem(searchRecordList, position);
|
|
|
- if(item != null){
|
|
|
- title_search_input.setText(item.getInput());
|
|
|
- title_search_input.setSelection(item.getInput().length());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- 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() && !searchRecordList.isEmpty()){//输入框内容为空且有搜索记录时显示搜索记录
|
|
|
- search_app_list.setVisibility(View.VISIBLE);
|
|
|
- frame_container.setVisibility(View.INVISIBLE);
|
|
|
- } else {
|
|
|
- title_search_input.postDelayed(autoSearchRunnable, 1000L);//1秒后自动搜索
|
|
|
+ if (item != null) {
|
|
|
+ TitleBarUtils.getInstance().setSearchText(ActSearchApp.this, item.getInput());
|
|
|
+ if (item instanceof IHomePageSearch)
|
|
|
+ ApiUtil.postTopSearchStatisticsClickTopSearch((IHomePageSearch) item);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private Runnable autoSearchRunnable = new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if(title_search_commit != null)
|
|
|
- title_search_commit.performClick();
|
|
|
- }
|
|
|
- };
|
|
|
- private Comparator<SearchAppRecord> comparator = new Comparator<SearchAppRecord>() {
|
|
|
- @Override
|
|
|
- public int compare(SearchAppRecord item1, SearchAppRecord item2) {
|
|
|
- return item2.getCount() - item1.getCount();
|
|
|
- }
|
|
|
- };
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
//初始化搜索历史
|
|
|
List<SearchAppRecord> newSgrList = MyDbManager.getInstance().getAllSearchAppRecord();
|
|
|
ListUtil.addAll(allSearchRecordList, newSgrList);
|
|
|
- Collections.sort(allSearchRecordList, comparator);
|
|
|
+ Collections.sort(allSearchRecordList, (item1,item2) -> item2.getCount() - item1.getCount());
|
|
|
ListUtil.addAll(searchRecordList, allSearchRecordList, 10);
|
|
|
for (SearchAppRecord item : allSearchRecordList) {
|
|
|
searchRecordMap.put(item.getInput(), item);
|
|
|
}
|
|
|
inputAdapter.notifyDataSetChanged();
|
|
|
- if(searchRecordList.isEmpty()) {
|
|
|
+ if (searchRecordList.isEmpty()) {
|
|
|
frame_container.setVisibility(View.VISIBLE);
|
|
|
search_app_list.setVisibility(View.INVISIBLE);
|
|
|
} else {
|
|
|
@@ -181,18 +162,6 @@ public class ActSearchApp extends BaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @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;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
List<SearchAppRecord> searchRecordList = new ArrayList<>();
|
|
|
List<SearchAppRecord> allSearchRecordList = new ArrayList<>();
|
|
|
Map<String, SearchAppRecord> searchRecordMap = new HashMap<>();
|
|
|
@@ -201,11 +170,11 @@ public class ActSearchApp extends BaseActivity {
|
|
|
private void toSearchApp() {
|
|
|
search_app_list.setVisibility(View.INVISIBLE);
|
|
|
frame_container.setVisibility(View.VISIBLE);
|
|
|
- String inputText = title_search_input.getText().toString();
|
|
|
+ String inputText = TitleBarUtils.getInstance().getSearchText(this).toString();
|
|
|
if (!TextUtils.isEmpty(inputText)) {
|
|
|
//保存搜索到数据库
|
|
|
SearchAppRecord searchRecord = searchRecordMap.get(inputText);
|
|
|
- if(searchRecord == null) {
|
|
|
+ if (searchRecord == null) {
|
|
|
searchRecord = new SearchAppRecord();
|
|
|
searchRecord.setInput(inputText);
|
|
|
searchRecordList.add(searchRecord);
|