diff --git a/OsmAnd/res/layout/order_poi_list_item.xml b/OsmAnd/res/layout/order_poi_list_item.xml index a7e396c634..8b94a16e34 100644 --- a/OsmAnd/res/layout/order_poi_list_item.xml +++ b/OsmAnd/res/layout/order_poi_list_item.xml @@ -16,17 +16,16 @@ tools:background="?android:attr/selectableItemBackground"> + android:tint="?attr/secondary_icon_color" + osmand:srcCompat="@drawable/ic_action_item_move" /> + + + android:paddingEnd="@dimen/content_padding" + tools:src="@drawable/ic_action_remove" + tools:tint="@color/icon_color_default_light" /> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6362a76dc1..f50040ea20 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + %1$s deleted A toggle to show or hide the Mapillary layer on the map. Show Mapillary Hide Mapillary diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index ed1c11dfc2..4a7be56153 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -10,7 +10,6 @@ import net.osmand.PlatformUtil; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; -import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI; @@ -19,7 +18,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteStatement; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.wikipedia.WikipediaPoiMenu; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import org.json.JSONArray; @@ -39,7 +37,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import static net.osmand.osm.MapPoiTypes.WIKI_PLACE; import static net.osmand.plus.wikipedia.WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY; import static net.osmand.plus.wikipedia.WikipediaPoiMenu.GLOBAL_WIKI_POI_ENABLED_KEY; @@ -178,6 +175,12 @@ public class PoiFiltersHelper { helper.close(); } + public void updateCachedFilter(PoiUIFilter poiFilter) { + int i = cacheTopStandardFilters.indexOf(poiFilter); + if (i != -1) { + cacheTopStandardFilters.set(i, poiFilter); + } + } private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters) { for (PoiUIFilter pf : filters) { diff --git a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java index c6daaa6bc1..6fb1ffdedb 100644 --- a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java @@ -13,6 +13,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -27,6 +28,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.snackbar.Snackbar; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; @@ -47,6 +49,7 @@ import java.util.HashMap; import java.util.List; import static net.osmand.plus.poi.PoiUIFilter.CUSTOM_FILTER_ID; +import static net.osmand.plus.poi.PoiUIFilter.USER_PREFIX; import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.DESCRIPTION; import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.POI; import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.SPACE; @@ -67,6 +70,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec private boolean wasReset = false; private boolean isChanged = false; private ApplicationMode appMode; + private LinearLayout buttonsContainer; private HashMap poiFiltersOrders = new HashMap<>(); private List availableFiltersKeys = new ArrayList<>(); @@ -199,7 +203,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec } app.getPoiFilters().saveFiltersOrder(selectedAppMode, filterIds); } else if (wasReset) { - app.getPoiFilters().saveFiltersOrder(selectedAppMode,null); + app.getPoiFilters().saveFiltersOrder(selectedAppMode, null); } } if (resultCallback != null) { @@ -208,6 +212,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec dismiss(); } }); + buttonsContainer = mainView.findViewById(R.id.buttons_container); return mainView; } @@ -512,6 +517,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec private OsmandApplication app; private UiUtilities uiUtilities; + private PoiFiltersHelper poiHelper; private List items = new ArrayList<>(); private boolean nightMode; @@ -520,8 +526,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec public EditPoiFiltersAdapter(OsmandApplication app, boolean nightMode) { setHasStableIds(true); this.app = app; - this.uiUtilities = app.getUIUtilities(); this.nightMode = nightMode; + uiUtilities = app.getUIUtilities(); + poiHelper = app.getPoiFilters(); } @NonNull @@ -557,13 +564,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec @SuppressLint("ClickableViewAccessibility") @Override - public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, int position) { - ListItem item = items.get(position); - boolean nightMode = isNightMode(app, usedOnMap); + public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, final int position) { + final ListItem item = items.get(position); + final boolean nightMode = isNightMode(app, usedOnMap); int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; if (holder instanceof PoiViewHolder) { PoiViewHolder h = (PoiViewHolder) holder; - PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; + 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)); @@ -591,6 +598,47 @@ 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() { + @Override + public void onClick(View view) { + Snackbar snackbar = Snackbar.make(requireView(), + getString(R.string.item_deleted, poiInfo.name), Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + items.add(position, item); + notifyDataSetChanged(); + } + }) + .addCallback(new Snackbar.Callback() { + @Override + public void onShown(Snackbar sb) { + super.onShown(sb); + items.remove(item); + notifyDataSetChanged(); + } + + @Override + public void onDismissed(Snackbar transientBottomBar, int event) { + super.onDismissed(transientBottomBar, event); + if (DISMISS_EVENT_ACTION != event) { + PoiUIFilter filter = poiHelper.getFilterById(poiInfo.filterId); + if (filter != null && poiHelper.removePoiFilter(filter)) { + filter.setDeleted(true); + poiHelper.updateCachedFilter(filter); + app.getSearchUICore().refreshCustomPoiFilters(); + } + } + } + }); + snackbar.setAnchorView(buttonsContainer); + UiUtilities.setupSnackbar(snackbar, nightMode); + snackbar.show(); + } + }); } else if (holder instanceof SpaceViewHolder) { float space = (float) item.value; ((SpaceViewHolder) holder).setSpace((int) space); @@ -751,6 +799,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec private TextView description; private ImageView icon; private ImageView actionIcon; + private ImageView actionDelete; private ImageView moveIcon; private View itemsContainer; @@ -758,6 +807,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec super(itemView); title = itemView.findViewById(R.id.title); actionIcon = itemView.findViewById(R.id.action_icon); + actionDelete = itemView.findViewById(R.id.action_delete); icon = itemView.findViewById(R.id.icon); moveIcon = itemView.findViewById(R.id.move_icon); itemsContainer = itemView.findViewById(R.id.selectable_list_item);