refactor listener
This commit is contained in:
parent
52ac6ad4ba
commit
8232b0c9a5
2 changed files with 13 additions and 21 deletions
|
@ -570,11 +570,11 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
|
||||||
@NonNull PoiCategory poiCategory,
|
@NonNull PoiCategory poiCategory,
|
||||||
boolean selectAll) {
|
boolean selectAll) {
|
||||||
Set<String> acceptedCategories = filter.getAcceptedSubtypes(poiCategory);
|
Set<String> acceptedCategories = filter.getAcceptedSubtypes(poiCategory);
|
||||||
QuickSearchSubCategoriesFragment.showInstance(fm, this, poiCategory, acceptedCategories, selectAll, getFiltersSelectedListener());
|
QuickSearchSubCategoriesFragment.showInstance(fm, this, poiCategory, acceptedCategories, selectAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuickSearchSubCategoriesFragment.OnFiltersSelectedListener getFiltersSelectedListener() {
|
public OnFiltersSelectedListener getFiltersSelectedListener() {
|
||||||
return new QuickSearchSubCategoriesFragment.OnFiltersSelectedListener() {
|
return new OnFiltersSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet<String> filters) {
|
public void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet<String> filters) {
|
||||||
List<String> subCategories = new ArrayList<>();
|
List<String> subCategories = new ArrayList<>();
|
||||||
|
@ -598,4 +598,8 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnFiltersSelectedListener {
|
||||||
|
void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet<String> filters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||||
|
import net.osmand.plus.search.QuickSearchCustomPoiFragment.OnFiltersSelectedListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
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 CATEGORY_NAME_KEY = "category_key";
|
||||||
private static final String ALL_SELECTED_KEY = "all_selected";
|
private static final String ALL_SELECTED_KEY = "all_selected";
|
||||||
private static final String ACCEPTED_CATEGORIES_KEY = "accepted_categories";
|
private static final String ACCEPTED_CATEGORIES_KEY = "accepted_categories";
|
||||||
private OnFiltersSelectedListener listener;
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private UiUtilities uiUtilities;
|
private UiUtilities uiUtilities;
|
||||||
private PoiCategory poiCategory;
|
private PoiCategory poiCategory;
|
||||||
|
@ -66,13 +66,11 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
|
||||||
@Nullable Fragment targetFragment,
|
@Nullable Fragment targetFragment,
|
||||||
@NonNull PoiCategory poiCategory,
|
@NonNull PoiCategory poiCategory,
|
||||||
@Nullable Set<String> acceptedCategories,
|
@Nullable Set<String> acceptedCategories,
|
||||||
boolean selectAll,
|
boolean selectAll) {
|
||||||
@NonNull OnFiltersSelectedListener listener) {
|
|
||||||
QuickSearchSubCategoriesFragment fragment = new QuickSearchSubCategoriesFragment();
|
QuickSearchSubCategoriesFragment fragment = new QuickSearchSubCategoriesFragment();
|
||||||
fragment.setPoiCategory(poiCategory);
|
fragment.setPoiCategory(poiCategory);
|
||||||
fragment.setSelectAll(selectAll);
|
fragment.setSelectAll(selectAll);
|
||||||
fragment.setAcceptedCategories(acceptedCategories);
|
fragment.setAcceptedCategories(acceptedCategories);
|
||||||
fragment.setListener(listener);
|
|
||||||
fragment.setTargetFragment(targetFragment, 0);
|
fragment.setTargetFragment(targetFragment, 0);
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
|
@ -256,12 +254,10 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
|
||||||
for (PoiType poiType : adapter.getSelectedItems()) {
|
for (PoiType poiType : adapter.getSelectedItems()) {
|
||||||
list.add(poiType.getKeyName());
|
list.add(poiType.getKeyName());
|
||||||
}
|
}
|
||||||
if (listener != null) {
|
|
||||||
listener.onFiltersSelected(poiCategory, list);
|
|
||||||
} else {
|
|
||||||
Fragment fragment = getTargetFragment();
|
Fragment fragment = getTargetFragment();
|
||||||
if (fragment instanceof QuickSearchCustomPoiFragment) {
|
if (fragment instanceof QuickSearchCustomPoiFragment) {
|
||||||
listener = ((QuickSearchCustomPoiFragment) fragment).getFiltersSelectedListener();
|
OnFiltersSelectedListener listener = ((QuickSearchCustomPoiFragment) fragment).getFiltersSelectedListener();
|
||||||
|
if (listener instanceof OnFiltersSelectedListener) {
|
||||||
listener.onFiltersSelected(poiCategory, list);
|
listener.onFiltersSelected(poiCategory, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,15 +299,7 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
|
||||||
this.poiCategory = poiCategory;
|
this.poiCategory = poiCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(OnFiltersSelectedListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAcceptedCategories(Set<String> acceptedCategories) {
|
public void setAcceptedCategories(Set<String> acceptedCategories) {
|
||||||
this.acceptedCategories = acceptedCategories;
|
this.acceptedCategories = acceptedCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnFiltersSelectedListener {
|
|
||||||
void onFiltersSelected(PoiCategory poiCategory, LinkedHashSet<String> filters);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue