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());
}
});
}
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;
}
});
}
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);
}
}
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);
}
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);
}
Aggregations