Search in sources :

Example 1 with SearchHistory

use of cn.nicolite.palm300heroes.model.bean.SearchHistory in project Palm300Heroes by nicolite.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SearchViewHolder holder, int position) {
    SearchHistory searchHistory = searchHistoryList.get(position);
    holder.text.setText(searchHistory.getHistory());
    holder.text.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(view, holder.getAdapterPosition(), holder.getItemId());
            }
        }
    });
    holder.text.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            return onItemLongClickListener != null && onItemLongClickListener.onItemLongClick(view, holder.getAdapterPosition(), holder.getItemId());
        }
    });
}
Also used : SearchHistory(cn.nicolite.palm300heroes.model.bean.SearchHistory) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) BindView(butterknife.BindView)

Example 2 with SearchHistory

use of cn.nicolite.palm300heroes.model.bean.SearchHistory 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)

Example 3 with SearchHistory

use of cn.nicolite.palm300heroes.model.bean.SearchHistory in project Palm300Heroes by nicolite.

the class SearchPresenter method showHistory.

public void showHistory(int type) {
    SearchHistoryDao searchHistoryDao = daoSession.getSearchHistoryDao();
    List<SearchHistory> list = searchHistoryDao.queryBuilder().where(SearchHistoryDao.Properties.Type.eq(type)).orderDesc(SearchHistoryDao.Properties.Id).list();
    if (getView() != null) {
        getView().showHistory(list);
    }
}
Also used : SearchHistoryDao(cn.nicolite.palm300heroes.db.dao.SearchHistoryDao) SearchHistory(cn.nicolite.palm300heroes.model.bean.SearchHistory)

Example 4 with SearchHistory

use of cn.nicolite.palm300heroes.model.bean.SearchHistory in project Palm300Heroes by nicolite.

the class SearchPresenter method addHistory.

public void addHistory(int type, String history) {
    if (TextUtils.isEmpty(history)) {
        if (getView() != null) {
            getView().showMessage("你还没有输入搜索内容!");
        }
        return;
    }
    SearchHistoryDao searchHistoryDao = daoSession.getSearchHistoryDao();
    List<SearchHistory> list = searchHistoryDao.queryBuilder().where(SearchHistoryDao.Properties.Type.eq(type), SearchHistoryDao.Properties.History.eq(history)).list();
    if (!ListUtils.isEmpty(list)) {
        for (SearchHistory searchHistory : list) {
            searchHistoryDao.delete(searchHistory);
        }
    }
    SearchHistory searchHistory = new SearchHistory();
    searchHistory.setType(type);
    searchHistory.setHistory(history);
    searchHistoryDao.insert(searchHistory);
    showHistory(type);
}
Also used : SearchHistoryDao(cn.nicolite.palm300heroes.db.dao.SearchHistoryDao) SearchHistory(cn.nicolite.palm300heroes.model.bean.SearchHistory)

Example 5 with SearchHistory

use of cn.nicolite.palm300heroes.model.bean.SearchHistory in project Palm300Heroes by nicolite.

the class SearchPresenter method deleteHistory.

public void deleteHistory(int type) {
    SearchHistoryDao searchHistoryDao = daoSession.getSearchHistoryDao();
    List<SearchHistory> list = searchHistoryDao.queryBuilder().where(SearchHistoryDao.Properties.Type.eq(type)).list();
    if (!ListUtils.isEmpty(list)) {
        for (SearchHistory searchHistory : list) {
            searchHistoryDao.delete(searchHistory);
        }
    }
    showHistory(type);
}
Also used : SearchHistoryDao(cn.nicolite.palm300heroes.db.dao.SearchHistoryDao) SearchHistory(cn.nicolite.palm300heroes.model.bean.SearchHistory)

Aggregations

SearchHistory (cn.nicolite.palm300heroes.model.bean.SearchHistory)5 SearchHistoryDao (cn.nicolite.palm300heroes.db.dao.SearchHistoryDao)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 BindView (butterknife.BindView)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 KeyEvent (android.view.KeyEvent)1 TextView (android.widget.TextView)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