From b0e3306de7b78288eeaf6e9f6e9fc062b4fc7462 Mon Sep 17 00:00:00 2001 From: Rosty Date: Fri, 6 Jan 2017 13:22:47 +0200 Subject: [PATCH] quick actions show/hide poi (use icon of poi) fixed --- .../quickaction/CreateEditActionDialog.java | 2 +- .../osmand/plus/quickaction/QuickAction.java | 4 +++ .../plus/quickaction/QuickActionFactory.java | 30 ++++++++++++++++++- .../quickaction/QuickActionListFragment.java | 4 +-- .../plus/quickaction/QuickActionsWidget.java | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java index f898c3fc8a..539b8fc4a0 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java @@ -194,7 +194,7 @@ public class CreateEditActionDialog extends DialogFragment { if (savedInstanceState == null) name.setText(action.getName(getContext())); else action.setName(name.getText().toString()); - image.setImageResource(action.getIconRes()); + image.setImageResource(action.getIconRes(getApplication())); } private void setupFooter(final View root){ diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java index 103a5fe9b4..cbc794e94b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java @@ -68,6 +68,10 @@ public class QuickAction { return iconRes; } + public int getIconRes(Context context) { + return iconRes; + } + public long getId() { return id; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 877f82b142..45cd15d38a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -757,6 +757,35 @@ public class QuickActionFactory { this.title = title; } + @Override + public int getIconRes(Context context) { + + if (getParams().get(KEY_FILTERS) == null || getParams().get(KEY_FILTERS).isEmpty()) { + + return super.getIconRes(); + + } else { + + OsmandApplication app = (OsmandApplication) context.getApplicationContext(); + List filters = new ArrayList<>(); + + String filtersId = getParams().get(KEY_FILTERS); + Collections.addAll(filters, filtersId.split(",")); + + PoiUIFilter filter = app.getPoiFilters().getFilterById(filters.get(0)); + + Object res = filter.getIconResource(); + + if (filter == null) return super.getIconRes(); + + if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) { + + return RenderingIcons.getBigIconResourceId(res.toString()); + + } else return super.getIconRes(); + } + } + @Override public void execute(MapActivity activity) { @@ -1694,7 +1723,6 @@ public class QuickActionFactory { return filtered; } - @Override protected int getAddBtnText() { return R.string.quick_action_map_style_action; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 1de9d7cf37..7dcac96d3f 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -196,7 +196,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { int viewType = getItemViewType(position); - final QuickAction item = itemsList.get(position); + final QuickAction item = QuickActionFactory.produceAction(itemsList.get(position)); if (viewType == SCREEN_ITEM_TYPE) { final QuickActionItemVH itemVH = (QuickActionItemVH) holder; @@ -204,7 +204,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick itemVH.title.setText(item.getName(getContext())); itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position))); - itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getIconRes())); + itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getIconRes(getContext()))); itemVH.handleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java index 1030a6e0d2..fa7f6a258b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java @@ -209,7 +209,7 @@ public class QuickActionsWidget extends LinearLayout { actions.get(i + (position * ELEMENT_PER_PAGE))); ((ImageView) view.findViewById(R.id.imageView)) - .setImageResource(action.getIconRes()); + .setImageResource(action.getIconRes(getContext())); ((TextView) view.findViewById(R.id.title)) .setText(action.getActionText(application));