diff --git a/OsmAnd/res/layout/order_poi_list_item.xml b/OsmAnd/res/layout/order_poi_list_item.xml index 643c5b2b6e..02271d0783 100644 --- a/OsmAnd/res/layout/order_poi_list_item.xml +++ b/OsmAnd/res/layout/order_poi_list_item.xml @@ -62,6 +62,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" + android:layout_marginStart="@dimen/list_content_padding_large" + android:layout_marginLeft="@dimen/list_content_padding_large" android:minHeight="@dimen/bottom_sheet_list_item_height" android:paddingStart="@dimen/content_padding_small" android:paddingLeft="@dimen/content_padding_small" diff --git a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java index 3e903b128c..e9077bb143 100644 --- a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java @@ -21,6 +21,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.core.view.MotionEventCompat; +import androidx.core.view.ViewCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -33,6 +34,7 @@ import com.google.android.material.snackbar.Snackbar; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; +import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -70,6 +72,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec private boolean activationModified; private boolean wasReset = false; private boolean isChanged = false; + private boolean filterDeleted = false; private ApplicationMode appMode; private LinearLayout buttonsContainer; @@ -220,7 +223,8 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec @Override public void onDismiss(@NonNull DialogInterface dialog) { - if (isChanged && !orderModified && !activationModified && resultCallback != null) { + if (filterDeleted && resultCallback != null) { + requireMyApplication().getPoiFilters().saveInactiveFilters(getSelectedAppMode(), availableFiltersKeys); resultCallback.onCustomFiltersDeleted(); } super.onDismiss(dialog); @@ -582,7 +586,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec final PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; int osmandOrangeColorResId = nightMode ? R.color.osmand_orange_dark : R.color.osmand_orange; h.title.setText(poiInfo.name); - h.icon.setImageDrawable(uiUtilities.getIcon(poiInfo.iconRes, osmandOrangeColorResId)); + boolean userFilter = poiInfo.filterId.startsWith(USER_PREFIX); + int iconRes = QuickSearchListItem.getCustomFilterIconRes(poiHelper.getFilterById(poiInfo.filterId)); + h.icon.setImageDrawable(uiUtilities.getIcon(userFilter ? iconRes : poiInfo.iconRes, osmandOrangeColorResId)); h.moveIcon.setVisibility(poiInfo.isActive ? View.VISIBLE : View.GONE); h.actionIcon.setOnClickListener(new View.OnClickListener() { @Override @@ -607,7 +613,6 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec } else { h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_add, R.color.color_osm_edit_create)); } - boolean userFilter = poiInfo.filterId.startsWith(USER_PREFIX); h.actionDelete.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_delete_item, R.color.color_osm_edit_delete)); h.actionDelete.setVisibility(userFilter ? View.VISIBLE : View.GONE); h.actionDelete.setOnClickListener(new View.OnClickListener() { @@ -636,12 +641,14 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec if (DISMISS_EVENT_ACTION != event) { PoiUIFilter filter = poiHelper.getFilterById(poiInfo.filterId); if (filter != null && poiHelper.removePoiFilter(filter)) { + availableFiltersKeys.remove(poiInfo.filterId); filter.setDeleted(true); - isChanged = true; + filterDeleted = true; } } } }); + ViewCompat.setElevation(snackbar.getView(), 0f); snackbar.setAnchorView(buttonsContainer); UiUtilities.setupSnackbar(snackbar, nightMode); snackbar.show(); diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java index 4f941b9b48..204c31de88 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.text.Spannable; +import androidx.annotation.DrawableRes; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; @@ -334,23 +335,8 @@ public class QuickSearchListItem { } else if (searchResult.object instanceof CustomSearchPoiFilter) { CustomSearchPoiFilter searchPoiFilter = (CustomSearchPoiFilter) searchResult.object; PoiUIFilter filter = app.getPoiFilters().getFilterById(searchPoiFilter.getFilterId()); - iconId = R.drawable.mx_special_custom_category; if (filter != null) { - Map> acceptedTypes = filter.getAcceptedTypes(); - List categories = new ArrayList<>(acceptedTypes.keySet()); - if (categories.size() == 1) { - String res = ""; - PoiCategory category = categories.get(0); - LinkedHashSet filters = acceptedTypes.get(category); - if (filters == null || filters.size() > 1) { - res = category.getIconKeyName(); - } else { - res = getPoiTypeIconName(category.getPoiTypeByKeyName(filters.iterator().next())); - } - if (res != null && RenderingIcons.containsBigIcon(res)) { - iconId = RenderingIcons.getBigIconResourceId(res); - } - } + iconId = getCustomFilterIconRes(filter); } } if (iconId > 0) { @@ -422,4 +408,27 @@ public class QuickSearchListItem { return app.getUIUtilities().getIcon(iconId, app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); } + + @DrawableRes + public static int getCustomFilterIconRes(PoiUIFilter filter) { + int iconId = 0; + if (filter != null) { + Map> acceptedTypes = filter.getAcceptedTypes(); + List categories = new ArrayList<>(acceptedTypes.keySet()); + if (categories.size() == 1) { + String res = ""; + PoiCategory category = categories.get(0); + LinkedHashSet filters = acceptedTypes.get(category); + if (filters == null || filters.size() > 1) { + res = category.getIconKeyName(); + } else { + res = getPoiTypeIconName(category.getPoiTypeByKeyName(filters.iterator().next())); + } + if (res != null && RenderingIcons.containsBigIcon(res)) { + iconId = RenderingIcons.getBigIconResourceId(res); + } + } + } + return iconId > 0 ? iconId : R.drawable.mx_special_custom_category; + } }