<NME> FilterUtils.java
<BEF> ADDFILE
<MSG> open filter-selection with long click (fix #11202) (#11297)

* open filter-selection with long click on menu-item and filter-bar
option to clear the current filter

* improve refresh of map
rename method to retrieve name(s) of active filter

* incorporate review comments
<DFF> @@ -0,0 +1,97 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.activity.FilteredActivity;
+import cgeo.geocaching.filters.core.GeocacheFilter;
+import cgeo.geocaching.filters.core.GeocacheFilterContext;
+import cgeo.geocaching.filters.gui.GeocacheFilterActivity;
+import cgeo.geocaching.models.Geocache;
+import cgeo.geocaching.ui.TextParam;
+import cgeo.geocaching.ui.dialog.SimpleDialog;
+
+import android.app.Activity;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class FilterUtils {
+
+    private FilterUtils() {
+        // should not be instantiated
+    }
+
+    public static void openFilterActivity(final Activity activity, final GeocacheFilterContext filterContext, final Collection<Geocache> filteredList) {
+
+        GeocacheFilterActivity.selectFilter(
+            activity,
+            filterContext,
+            filteredList, true);
+    }
+
+    public static <T extends Activity & FilteredActivity> boolean openFilterList(final T filteredActivity, final GeocacheFilterContext filterContext) {
+        final List<GeocacheFilter> filters = new ArrayList<>(GeocacheFilter.Storage.getStoredFilters());
+
+        if (filters.isEmpty()) {
+            return false;
+        } else {
+            final boolean isFilterActive = filterContext.get().isFiltering();
+            if (isFilterActive) {
+                SimpleDialog.of(filteredActivity).setTitle(R.string.cache_filter_storage_select_clear_title)
+                    .setButtons(0, 0, R.string.cache_filter_storage_clear_button)
+                    .setSelectionForNeutral(false)
+                    .selectSingle(filters, (f, pos) -> TextParam.text(f.getName()), -1, false,
+                        (f, pos) -> filteredActivity.refreshWithFilter(f),
+                        (f, pos) -> {
+                        },
+                        (f, pos) -> filteredActivity.refreshWithFilter(GeocacheFilter.createEmpty())
+                    );
+            } else {
+                SimpleDialog.of(filteredActivity).setTitle(R.string.cache_filter_storage_select_title)
+                    .selectSingle(filters, (f, pos) -> TextParam.text(f.getName()), -1, false,
+                        (f, pos) -> filteredActivity.refreshWithFilter(f),
+                        (f, pos) -> {
+                        }
+                    );
+            }
+        }
+        return true;
+    }
+
+    public static void updateFilterBar(final Activity activity, final Collection<String> filterNames) {
+        final View filterView = activity.findViewById(R.id.filter_bar);
+        if (filterNames.isEmpty()) {
+            filterView.setVisibility(View.GONE);
+        } else {
+            final TextView filterTextView = activity.findViewById(R.id.filter_text);
+            filterTextView.setText(TextUtils.join(", ", filterNames));
+            filterView.setVisibility(View.VISIBLE);
+        }
+    }
+
+    /** filterView must exist */
+    public static void initializeFilterBar(@NonNull final Activity activity, @NonNull final FilteredActivity filteredActivity) {
+        final View filterView = activity.findViewById(R.id.filter_bar);
+        filterView.setOnLongClickListener(v -> filteredActivity.showFilterList(null));
+    }
+
+    public static void initializeFilterMenu(@NonNull final Activity activity, @NonNull final FilteredActivity filteredActivity) {
+
+        new Handler().post(new Runnable() {
+            @Override
+            public void run() {
+                final View filterView = activity.findViewById(R.id.menu_filter);
+                if (filterView != null) {
+                    filterView.setOnLongClickListener(v -> filteredActivity.showFilterList(null));
+                }
+            }
+        });
+    }
+
+}

open filter-selection with long click (fix #11202) (#11297)