| | |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import com.tejia.lijin.app.presenter.SearchFgPresenter; |
| | | import com.tejia.lijin.app.util.FlowLayout; |
| | | import com.tejia.lijin.app.util.umengCustomEvent.SearchCustomEvent; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.wpc.library.util.common.StringUtils; |
| | | import com.wpc.library.widget.MyListView; |
| | |
| | | |
| | | private AutoCompleteTextView et_search; |
| | | private TextView tv_clear_history, tv_cancel; |
| | | private MyListView lv_search_history; |
| | | private HistoryAdapter adapter; |
| | | private List<String> mList = new ArrayList<>(); |
| | | private LinearLayout ll_no_data; |
| | | private TextView tv_no_data_hint; |
| | | private ImageView iv_no_data; |
| | | private FlowLayout fl_search_history; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | } else { |
| | | ll_no_data.setVisibility(View.GONE); |
| | | } |
| | | adapter = new HistoryAdapter(mList); |
| | | lv_search_history.setAdapter(adapter); |
| | | |
| | | } |
| | | |
| | | private void setSearchHistoryData() { |
| | | //设置历史搜索数据 |
| | | SearchFgPresenter.fillFlowData(getApplicationContext(), mList, fl_search_history, new SearchFgPresenter.ISearchItemClick() { |
| | | @Override |
| | | public void onClick(String text, int position) { |
| | | Intent intent = new Intent(OrderFormNumSearchActivity33.this, OrderSearchResultActivity.class); |
| | | intent.putExtra("orderNo", mList.get(position)); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void initView() { |
| | | et_search = findViewById(R.id.et_search); |
| | | tv_clear_history = findViewById(R.id.tv_clear_history); |
| | | tv_cancel = findViewById(R.id.tv_cancel); |
| | | lv_search_history = findViewById(R.id.lv_search_history); |
| | | fl_search_history = findViewById(R.id.fl_search_history); |
| | | ll_no_data = findViewById(R.id.ll_no_data); |
| | | tv_no_data_hint = findViewById(R.id.tv_no_data_hint); |
| | | iv_no_data = findViewById(R.id.iv_no_data); |
| | | iv_no_data.setImageResource(R.drawable.ic_order_search_null); |
| | | tv_no_data_hint.setText("暂无搜索记录~"); |
| | | } |
| | | |
| | | private void addListener() { |
| | |
| | | editor.clear(); |
| | | editor.commit(); |
| | | mList.clear(); |
| | | adapter.notifyDataSetChanged(); |
| | | setSearchHistoryData(); |
| | | if (mList.size() == 0) { |
| | | ll_no_data.setVisibility(View.VISIBLE); |
| | | } else { |
| | |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | MobclickAgent.onResume(this); |
| | | setSearchHistoryData(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | MobclickAgent.onPause(this); |
| | | } |
| | | |
| | | class HistoryAdapter extends BaseAdapter { |
| | | List<String> mList; |
| | | |
| | | public HistoryAdapter(List<String> list) { |
| | | mList = list; |
| | | } |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mList == null ? 0 : mList.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getItem(int position) { |
| | | return mList.get(position); |
| | | } |
| | | |
| | | @Override |
| | | public long getItemId(int position) { |
| | | return position; |
| | | } |
| | | |
| | | @Override |
| | | public View getView(final int position, View view, ViewGroup parent) { |
| | | view = LayoutInflater.from(OrderFormNumSearchActivity33.this) |
| | | .inflate(R.layout.item_search_history, null); |
| | | final TextView tv_content = view.findViewById(R.id.tv_search_content); |
| | | tv_content.setText(mList.get(position)); |
| | | ImageView iv_close = view.findViewById(R.id.iv_search_content_close); |
| | | tv_content.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | Intent intent = new Intent(OrderFormNumSearchActivity33.this, OrderSearchResultActivity.class); |
| | | intent.putExtra("orderNo", mList.get(position)); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | iv_close.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | mList.remove(position); |
| | | notifyDataSetChanged(); |
| | | |
| | | SharedPreferences sp = getSharedPreferences("orderFormNumHistory", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.clear(); |
| | | editor.putInt("formNums", mList.size()); |
| | | for (int i = 0; i < mList.size(); i++) { |
| | | editor.putString("item_" + (mList.size() - 1 - i), mList.get(mList.size() - 1 - i)); |
| | | } |
| | | editor.commit(); |
| | | if (mList.size() == 0) { |
| | | ll_no_data.setVisibility(View.VISIBLE); |
| | | } else { |
| | | ll_no_data.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | }); |
| | | return view; |
| | | } |
| | | } |
| | | } |