/*
* OpenERP, Open Source Management Solution
* Copyright (C) 2012-today OpenERP SA (<http://www.openerp.com>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
package com.openerp.support;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import android.widget.SearchView.OnQueryTextListener;
import com.openerp.orm.OEDatabase;
import com.openerp.support.fragment.FragmentHelper;
/**
* The Class BaseFragment.
*/
public abstract class BaseFragment extends Fragment implements FragmentHelper {
/** The scope. */
public AppScope scope;
private OEDatabase mDb = null;
/** The list search adapter. */
private ArrayAdapter<Object> listSearchAdapter;
/**
* Gets the query listener.
*
* @param listAdapter
* the list adapter
* @return the query listener
*/
public OnQueryTextListener getQueryListener(ArrayAdapter<Object> listAdapter) {
listSearchAdapter = listAdapter;
return queryListener;
}
/** The query listener. */
final public OnQueryTextListener queryListener = new OnQueryTextListener() {
private boolean isSearched = false;
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
newText = "";
if (isSearched && listSearchAdapter != null) {
listSearchAdapter.getFilter().filter(null);
}
} else {
isSearched = true;
listSearchAdapter.getFilter().filter(newText);
}
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
};
public OEDatabase db() {
mDb = (OEDatabase) databaseHelper(getActivity());
return mDb;
}
}