use of com.frostwire.android.gui.SearchEngine in project frostwire by frostwire.
the class SearchEnginesPreferenceFragment method setupSearchEngines.
private void setupSearchEngines() {
final CheckBoxPreference selectAll = findPreference(PREF_KEY_SEARCH_SELECT_ALL);
Map<CheckBoxPreference, SearchEngine> inactiveSearchPreferences = new HashMap<>();
fillSearchEnginePreferences(activeSearchEnginePreferences, inactiveSearchPreferences);
// click listener for the search engines. Checks or unchecks the SelectAll checkbox
Preference.OnPreferenceClickListener searchEngineClickListener = preference -> {
CheckBoxPreference cb = (CheckBoxPreference) preference;
if (!cb.isChecked()) {
setChecked(selectAll, false, false);
if (areAllEnginesChecked(activeSearchEnginePreferences, false)) {
// always keep one checked
cb.setChecked(true);
UIUtils.showShortMessage(getView(), R.string.search_preferences_one_engine_checked_always);
}
selectAll.setTitle(R.string.select_all);
} else {
updateSelectAllCheckBox();
}
return true;
};
// hide inactive search engines and setup click listeners to interact with Select All.
for (CheckBoxPreference preference : inactiveSearchPreferences.keySet()) {
getPreferenceScreen().removePreference(preference);
}
for (CheckBoxPreference preference : activeSearchEnginePreferences.keySet()) {
preference.setOnPreferenceClickListener(searchEngineClickListener);
}
selectAll.setOnPreferenceClickListener(preference -> {
CheckBoxPreference selectAll1 = (CheckBoxPreference) preference;
checkAllEngines(selectAll1.isChecked());
selectAll1.setTitle(selectAll1.isChecked() ? R.string.deselect_all : R.string.select_all);
return true;
});
updateSelectAllCheckBox();
}
use of com.frostwire.android.gui.SearchEngine in project frostwire by frostwire.
the class SearchEnginesPreferenceFragment method fillSearchEnginePreferences.
private void fillSearchEnginePreferences(Map<CheckBoxPreference, SearchEngine> active, Map<CheckBoxPreference, SearchEngine> inactive) {
// make sure we start empty
inactive.clear();
active.clear();
for (SearchEngine engine : SearchEngine.getEngines()) {
CheckBoxPreference preference = findPreference(engine.getPreferenceKey());
if (preference != null) {
// it could already have been removed due to remote config value.
if (engine.isActive()) {
active.put(preference, engine);
} else {
inactive.put(preference, engine);
}
}
}
}
Aggregations