package com.evan.demo.listener;

import android.support.v7.widget.SearchView;

import com.evan.demo.mvp.presenter.SearchPresenter;

/**
 * Created by yqman on 2016/5/22.
 */
public class OnSearchViewListener implements SearchView.OnQueryTextListener,SearchView.OnSuggestionListener, SearchView.OnCloseListener {
    private SearchView searchView;
    private SearchPresenter presenter;
    public OnSearchViewListener(SearchView searchView, SearchPresenter presenter) {
        this.searchView = searchView;
        this.presenter = presenter;
    }

    @Override
    public boolean onClose() {
        searchData("");
        return true;
    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        searchView.clearFocus();
        searchData(query);
        return true;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        searchData(newText);
        return true;
    }

    @Override
    public boolean onSuggestionSelect(int position) {
        return false;
    }

    @Override
    public boolean onSuggestionClick(int position) {
        return false;
    }

    private void searchData(String str){
        if(!str.equals("")) {
            presenter.getSearchResult(str);
        }
    }
}
