<commit_before>package cgeo.geocaching.maps;

import cgeo.geocaching.R;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.Dialogs;
import cgeo.geocaching.utils.functions.Action1;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

public class MapSettingsUtils {

    private MapSettingsUtils() {
        // utility class
    }

    public static void showSettingsPopup(final Activity activity, final Runnable onMapSettingsPopupFinished) {
        final ArrayList<SettingsElementModel> settingsElements = new ArrayList<>();
        settingsElements.add(new SettingsElementModel(R.string.map_mycaches_hide , R.drawable.ic_menu_myplaces, Settings.isExcludeMyCaches(), Settings::setExcludeMine));
        settingsElements.add(new SettingsElementModel(R.string.map_disabled_hide , R.drawable.ic_menu_disabled, Settings.isExcludeDisabledCaches(), Settings::setExcludeDisabled));
        settingsElements.add(new SettingsElementModel(R.string.map_archived_hide , R.drawable.ic_menu_archived, Settings.isExcludeArchivedCaches(), Settings::setExcludeArchived));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_original , R.drawable.ic_menu_waypoint, Settings.isExcludeWpOriginal(), Settings::setExcludeWpOriginal));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_parking , R.drawable.ic_menu_parking, Settings.isExcludeWpParking(), Settings::setExcludeWpParking));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_visited , R.drawable.ic_menu_visited, Settings.isExcludeWpVisited(), Settings::setExcludeWpVisited));
        if (StringUtils.isNotBlank(Settings.getTrackFile())) {
            settingsElements.add(new SettingsElementModel(R.string.map_hide_track, R.drawable.ic_menu_hidetrack, Settings.isHideTrack(), Settings::setHideTrack));
        }

        final View dialogView = activity.getLayoutInflater().inflate(R.layout.map_settings_dialog, null);
        ((ListView) dialogView.findViewById(R.id.map_settings_listview)).setAdapter(new MapSettingsAdapter(activity, settingsElements));

        Dialogs.newBuilder(activity)
            .setView(dialogView)
            .setTitle(R.string.quick_settings)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                for (SettingsElementModel item : settingsElements) {
                    item.setValue.call(item.currentValue);
                }
                onMapSettingsPopupFinished.run();
            })
            .setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
            .create()
            .show();
    }

    private static class SettingsElementModel {
        public final int resTitle;
        public final int resIcon;
        public boolean currentValue;
        public final Action1<Boolean> setValue;

        SettingsElementModel(@StringRes final int resTitle, @DrawableRes final int resIcon, final boolean currentValue, final Action1<Boolean> setValue) {
            this.resTitle = resTitle;
            this.resIcon = resIcon;
            this.currentValue = currentValue;
            this.setValue = setValue;
        }
    }

    private static class MapSettingsAdapter extends ArrayAdapter<SettingsElementModel> {
<commit_msg>apply map popup changes also when clicking outside (rel. to #8138)<commit_after>package cgeo.geocaching.maps;

import cgeo.geocaching.R;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.dialog.Dialogs;
import cgeo.geocaching.utils.functions.Action1;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import java.util.ArrayList;

import org.apache.commons.lang3.StringUtils;

public class MapSettingsUtils {

    private MapSettingsUtils() {
        // utility class
    }

    public static void showSettingsPopup(final Activity activity, final Runnable onMapSettingsPopupFinished) {
        final ArrayList<SettingsElementModel> settingsElements = new ArrayList<>();
        settingsElements.add(new SettingsElementModel(R.string.map_mycaches_hide , R.drawable.ic_menu_myplaces, Settings.isExcludeMyCaches(), Settings::setExcludeMine));
        settingsElements.add(new SettingsElementModel(R.string.map_disabled_hide , R.drawable.ic_menu_disabled, Settings.isExcludeDisabledCaches(), Settings::setExcludeDisabled));
        settingsElements.add(new SettingsElementModel(R.string.map_archived_hide , R.drawable.ic_menu_archived, Settings.isExcludeArchivedCaches(), Settings::setExcludeArchived));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_original , R.drawable.ic_menu_waypoint, Settings.isExcludeWpOriginal(), Settings::setExcludeWpOriginal));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_parking , R.drawable.ic_menu_parking, Settings.isExcludeWpParking(), Settings::setExcludeWpParking));
        settingsElements.add(new SettingsElementModel(R.string.map_hidewp_visited , R.drawable.ic_menu_visited, Settings.isExcludeWpVisited(), Settings::setExcludeWpVisited));
        if (StringUtils.isNotBlank(Settings.getTrackFile())) {
            settingsElements.add(new SettingsElementModel(R.string.map_hide_track, R.drawable.ic_menu_hidetrack, Settings.isHideTrack(), Settings::setHideTrack));
        }

        final View dialogView = activity.getLayoutInflater().inflate(R.layout.map_settings_dialog, null);
        ((ListView) dialogView.findViewById(R.id.map_settings_listview)).setAdapter(new MapSettingsAdapter(activity, settingsElements));

        Dialogs.newBuilder(activity)
            .setView(dialogView)
            .setTitle(R.string.quick_settings)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss())
            .setOnDismissListener(dialog -> {
                for (SettingsElementModel item : settingsElements) {
                    item.setValue.call(item.currentValue);
                }
                onMapSettingsPopupFinished.run();
            })
            .create()
            .show();
    }

    private static class SettingsElementModel {
        public final int resTitle;
        public final int resIcon;
        public boolean currentValue;
        public final Action1<Boolean> setValue;

        SettingsElementModel(@StringRes final int resTitle, @DrawableRes final int resIcon, final boolean currentValue, final Action1<Boolean> setValue) {
            this.resTitle = resTitle;
            this.resIcon = resIcon;
            this.currentValue = currentValue;
            this.setValue = setValue;
        }
    }

    private static class MapSettingsAdapter extends ArrayAdapter<SettingsElementModel> {

{'fraction_non_alphanumeric': 0.09279851734180566, 'fraction_numerical': 0.0015885623510722795, 'mean_word_length': 4.080699394754539, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266034', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2040, 'n_words': 356}