Search in sources :

Example 1 with SearchPresenter

use of cn.nicolite.palm300heroes.presenter.SearchPresenter in project Palm300Heroes by nicolite.

the class SearchActivity method doBusiness.

@Override
protected void doBusiness() {
    recyclerView.setLayoutManager(new GridLayoutManager(context, 3, OrientationHelper.VERTICAL, false));
    adapter = new SearchAdapter(context, searchHistoryList);
    recyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener(new SearchAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position, long itemId) {
            SearchHistory searchHistory = searchHistoryList.get(position);
            toolbarSearchEdit.setText(searchHistory.getHistory());
            startSearchResult();
        }
    });
    searchPresenter = new SearchPresenter(this, this);
    searchPresenter.showHistory(type);
    adapter.setOnItemLongClickListener(new SearchAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(View view, final int position, long itemId) {
            final CommonDialog commonDialog = new CommonDialog(context);
            commonDialog.setMessage("确定删除该条记录?").setPositiveButton("确认", new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    searchPresenter.deleteHistoryItem(searchHistoryList.get(position));
                    searchHistoryList.remove(position);
                    adapter.notifyItemRemoved(position);
                    commonDialog.dismiss();
                }
            }).setNegativeButton("取消", null).show();
            return true;
        }
    });
    toolbarSearchEdit.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (i == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_UP) {
                KeyBoardUtils.hideSoftInput(context, getWindow());
                searchPresenter.addHistory(type, toolbarSearchEdit.getText().toString());
                startSearchResult();
                return true;
            }
            return false;
        }
    });
}
Also used : SearchAdapter(cn.nicolite.palm300heroes.view.adapter.SearchAdapter) SearchPresenter(cn.nicolite.palm300heroes.presenter.SearchPresenter) CommonDialog(cn.nicolite.palm300heroes.view.customView.CommonDialog) ISearchView(cn.nicolite.palm300heroes.view.iview.ISearchView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) KeyEvent(android.view.KeyEvent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SearchHistory(cn.nicolite.palm300heroes.model.bean.SearchHistory)

Aggregations

GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 BindView (butterknife.BindView)1 SearchHistory (cn.nicolite.palm300heroes.model.bean.SearchHistory)1 SearchPresenter (cn.nicolite.palm300heroes.presenter.SearchPresenter)1 SearchAdapter (cn.nicolite.palm300heroes.view.adapter.SearchAdapter)1 CommonDialog (cn.nicolite.palm300heroes.view.customView.CommonDialog)1 ISearchView (cn.nicolite.palm300heroes.view.iview.ISearchView)1