From 8232b0c9a53f6e6c2e37e14305bd68ad5e385e6d Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 21 May 2020 16:47:07 +0300 Subject: [PATCH] refactor listener --- .../search/QuickSearchCustomPoiFragment.java | 10 +++++--- .../QuickSearchSubCategoriesFragment.java | 24 +++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java index 156a65a292..6a1dbefe7e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java @@ -570,11 +570,11 @@ public class QuickSearchCustomPoiFragment extends DialogFragment { @NonNull PoiCategory poiCategory, boolean selectAll) { Set acceptedCategories = filter.getAcceptedSubtypes(poiCategory); - QuickSearchSubCategoriesFragment.showInstance(fm, this, poiCategory, acceptedCategories, selectAll, getFiltersSelectedListener()); + QuickSearchSubCategoriesFragment.showInstance(fm, this, poiCategory, acceptedCategories, selectAll); } - public QuickSearchSubCategoriesFragment.OnFiltersSelectedListener getFiltersSelectedListener() { - return new QuickSearchSubCategoriesFragment.OnFiltersSelectedListener() { + public OnFiltersSelectedListener getFiltersSelectedListener() { + return new OnFiltersSelectedListener() { @Override public void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet filters) { List subCategories = new ArrayList<>(); @@ -598,4 +598,8 @@ public class QuickSearchCustomPoiFragment extends DialogFragment { } }; } + + public interface OnFiltersSelectedListener { + void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet filters); + } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java index bc54825680..9e88025f8d 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java @@ -30,6 +30,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndDialogFragment; +import net.osmand.plus.search.QuickSearchCustomPoiFragment.OnFiltersSelectedListener; import java.util.ArrayList; import java.util.Collections; @@ -45,7 +46,6 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { private static final String CATEGORY_NAME_KEY = "category_key"; private static final String ALL_SELECTED_KEY = "all_selected"; private static final String ACCEPTED_CATEGORIES_KEY = "accepted_categories"; - private OnFiltersSelectedListener listener; private OsmandApplication app; private UiUtilities uiUtilities; private PoiCategory poiCategory; @@ -66,13 +66,11 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { @Nullable Fragment targetFragment, @NonNull PoiCategory poiCategory, @Nullable Set acceptedCategories, - boolean selectAll, - @NonNull OnFiltersSelectedListener listener) { + boolean selectAll) { QuickSearchSubCategoriesFragment fragment = new QuickSearchSubCategoriesFragment(); fragment.setPoiCategory(poiCategory); fragment.setSelectAll(selectAll); fragment.setAcceptedCategories(acceptedCategories); - fragment.setListener(listener); fragment.setTargetFragment(targetFragment, 0); fragment.show(fm, TAG); } @@ -256,12 +254,10 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { for (PoiType poiType : adapter.getSelectedItems()) { list.add(poiType.getKeyName()); } - if (listener != null) { - listener.onFiltersSelected(poiCategory, list); - } else { - Fragment fragment = getTargetFragment(); - if (fragment instanceof QuickSearchCustomPoiFragment) { - listener = ((QuickSearchCustomPoiFragment) fragment).getFiltersSelectedListener(); + Fragment fragment = getTargetFragment(); + if (fragment instanceof QuickSearchCustomPoiFragment) { + OnFiltersSelectedListener listener = ((QuickSearchCustomPoiFragment) fragment).getFiltersSelectedListener(); + if (listener instanceof OnFiltersSelectedListener) { listener.onFiltersSelected(poiCategory, list); } } @@ -303,15 +299,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { this.poiCategory = poiCategory; } - public void setListener(OnFiltersSelectedListener listener) { - this.listener = listener; - } - public void setAcceptedCategories(Set acceptedCategories) { this.acceptedCategories = acceptedCategories; } - - public interface OnFiltersSelectedListener { - void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet filters); - } }