From 04b9a02ccf06c9fdf73644664a54ccc0f5bb653b Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 23 Jun 2020 17:44:25 +0300 Subject: [PATCH 1/3] refactor RearrangePoiFiltersFragment --- .../plus/poi/RearrangePoiFiltersFragment.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java index e9077bb143..e495170e10 100644 --- a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java @@ -106,7 +106,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final OsmandApplication app = requireMyApplication(); - boolean nightMode = isNightMode(app, usedOnMap); + final boolean nightMode = isNightMode(app, usedOnMap); View mainView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false); createToolbar(mainView, nightMode); @@ -158,6 +158,38 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec updateItems(); } } + + @Override + public void onDeleteClicked(final int position) { + final ListItem item = items.get(position); + if (item.value instanceof PoiUIFilterDataObject) { + PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; + final PoiUIFilter filter = app.getPoiFilters().getFilterById(poiInfo.filterId); + if (filter != null && app.getPoiFilters().removePoiFilter(filter)) { + filter.setDeleted(true); + filterDeleted = true; + } + items.remove(item); + adapter.notifyDataSetChanged(); + 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); + adapter.notifyDataSetChanged(); + if (filter != null) { + filter.setDeleted(false); + app.getPoiFilters().createPoiFilter(filter, false); + } + } + }); + ViewCompat.setElevation(snackbar.getView(), 0f); + snackbar.setAnchorView(buttonsContainer); + UiUtilities.setupSnackbar(snackbar, nightMode); + snackbar.show(); + } + } }); recyclerView.setAdapter(adapter); @@ -577,13 +609,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec @SuppressLint("ClickableViewAccessibility") @Override - public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, final int position) { - final ListItem item = items.get(position); - final boolean nightMode = isNightMode(app, usedOnMap); + public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, int position) { + ListItem item = items.get(position); + 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; - final PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; + PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; int osmandOrangeColorResId = nightMode ? R.color.osmand_orange_dark : R.color.osmand_orange; h.title.setText(poiInfo.name); boolean userFilter = poiInfo.filterId.startsWith(USER_PREFIX); @@ -618,40 +650,10 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec 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)) { - availableFiltersKeys.remove(poiInfo.filterId); - filter.setDeleted(true); - filterDeleted = true; - } - } - } - }); - ViewCompat.setElevation(snackbar.getView(), 0f); - snackbar.setAnchorView(buttonsContainer); - UiUtilities.setupSnackbar(snackbar, nightMode); - snackbar.show(); + int pos = holder.getAdapterPosition(); + if (listener != null && pos != RecyclerView.NO_POSITION) { + listener.onDeleteClicked(pos); + } } }); } else if (holder instanceof SpaceViewHolder) { @@ -864,7 +866,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec void onDragOrSwipeEnded(RecyclerView.ViewHolder holder); - void onButtonClicked(int view); + void onButtonClicked(int position); + + void onDeleteClicked(int position); } public interface OnApplyPoiFiltersState { From 4a9c73a5e27dd57269541e9bf78680a025fb8cc5 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 26 Jun 2020 15:19:51 +0300 Subject: [PATCH 2/3] add padding to title on inActive poi --- .../net/osmand/plus/poi/RearrangePoiFiltersFragment.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java index e495170e10..0ad4b2ea05 100644 --- a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java @@ -617,11 +617,15 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec PoiViewHolder h = (PoiViewHolder) holder; PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value; int osmandOrangeColorResId = nightMode ? R.color.osmand_orange_dark : R.color.osmand_orange; + boolean isActive = poiInfo.isActive; h.title.setText(poiInfo.name); + int padding = (int) getResources().getDimension(R.dimen.content_padding); + int paddingSmall = (int) getResources().getDimension(R.dimen.content_padding_small); + h.title.setPadding(isActive ? 0 : padding, paddingSmall, paddingSmall, padding); 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.moveIcon.setVisibility(isActive ? View.VISIBLE : View.GONE); h.actionIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -631,7 +635,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec } } }); - if (poiInfo.isActive) { + if (isActive) { h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, R.color.color_osm_edit_delete)); h.moveIcon.setOnTouchListener(new View.OnTouchListener() { @Override From ef4bf971f0ac22686acc69622bcdc837b363d9d3 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 26 Jun 2020 16:40:58 +0300 Subject: [PATCH 3/3] set to snackbar fade animation --- OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java index 0ad4b2ea05..97ad08899d 100644 --- a/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java +++ b/OsmAnd/src/net/osmand/plus/poi/RearrangePoiFiltersFragment.java @@ -30,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import net.osmand.AndroidUtils; @@ -186,6 +187,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec }); ViewCompat.setElevation(snackbar.getView(), 0f); snackbar.setAnchorView(buttonsContainer); + snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE); UiUtilities.setupSnackbar(snackbar, nightMode); snackbar.show(); }