Search in sources :

Example 1 with SearchEngine

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();
}
Also used : CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) AbstractPreferenceFragment(com.frostwire.android.gui.views.AbstractPreferenceFragment) R(com.frostwire.android.R) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) PreferenceGroupAdapter(android.support.v7.preference.PreferenceGroupAdapter) HashMap(java.util.HashMap) Preference(android.support.v7.preference.Preference) RecyclerView(android.support.v7.widget.RecyclerView) UIUtils(com.frostwire.android.gui.util.UIUtils) PreferenceGroup(android.support.v7.preference.PreferenceGroup) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Map(java.util.Map) SearchEngine(com.frostwire.android.gui.SearchEngine) SearchEngine(com.frostwire.android.gui.SearchEngine) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) HashMap(java.util.HashMap) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Preference(android.support.v7.preference.Preference)

Example 2 with SearchEngine

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);
            }
        }
    }
}
Also used : SearchEngine(com.frostwire.android.gui.SearchEngine) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Aggregations

CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)2 SearchEngine (com.frostwire.android.gui.SearchEngine)2 Preference (android.support.v7.preference.Preference)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 PreferenceGroupAdapter (android.support.v7.preference.PreferenceGroupAdapter)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 PreferenceViewHolder (android.support.v7.preference.PreferenceViewHolder)1 RecyclerView (android.support.v7.widget.RecyclerView)1 R (com.frostwire.android.R)1 UIUtils (com.frostwire.android.gui.util.UIUtils)1 AbstractPreferenceFragment (com.frostwire.android.gui.views.AbstractPreferenceFragment)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1