diff --git a/OsmAnd/res/layout/quick_action_add_dialog.xml b/OsmAnd/res/layout/quick_action_add_dialog.xml index f70186f23c..34aae941b8 100644 --- a/OsmAnd/res/layout/quick_action_add_dialog.xml +++ b/OsmAnd/res/layout/quick_action_add_dialog.xml @@ -14,17 +14,8 @@ android:layout_marginRight="24dp" android:textSize="@dimen/dialog_header_text_size" android:textColor="?android:textColorPrimary" - android:layout_marginBottom="16dp"/> + android:layout_marginBottom="8dp"/> - + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4bdebfce49..2fa6d0a0cb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2473,7 +2473,6 @@ If you need help with OsmAnd application, please contact our support team: suppo Edit action Add favorite Add Action - Create item Delete Action Are you sure you want to delete \"%s\" Action? Dismiss @@ -2494,4 +2493,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Show/Hide Favorites Show/Hide POI Add category + Create items + Configure map + Navigation diff --git a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java index cb66a00af0..b26da6ee40 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java @@ -42,7 +42,7 @@ public class AddQuickActionDialog extends DialogFragment { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View root = inflater.inflate(R.layout.quick_action_add_dialog, container, false); - Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsList()); + Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders()); RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view); Button btnDismiss = (Button) root.findViewById(R.id.btnDismiss); @@ -64,16 +64,19 @@ public class AddQuickActionDialog extends DialogFragment { super.onViewCreated(view, savedInstanceState); } - public class Adapter extends RecyclerView.Adapter { + public class Adapter extends RecyclerView.Adapter { + + private static final int HEADER = 1; + private static final int ITEM = 2; private List data; - public class ViewHolder extends RecyclerView.ViewHolder { + public class ItemViewHolder extends RecyclerView.ViewHolder { private TextView title; private ImageView icon; - public ViewHolder(View v) { + public ItemViewHolder(View v) { super(v); title = (TextView) v.findViewById(R.id.title); @@ -81,39 +84,71 @@ public class AddQuickActionDialog extends DialogFragment { } } + public class HeaderViewHolder extends RecyclerView.ViewHolder { + + private TextView header; + private View divider; + + public HeaderViewHolder(View v) { + super(v); + + header = (TextView) v.findViewById(R.id.header); + divider = v.findViewById(R.id.divider); + } + } + public Adapter(List data) { this.data = data; } @Override - public Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.quick_action_add_dialog_item, parent, false); + if (viewType == HEADER) { - return new ViewHolder(v); + return new HeaderViewHolder(LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_add_dialog_header, parent, false)); + + } else { + + return new ItemViewHolder(LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_add_dialog_item, parent, false)); + } } @Override - public void onBindViewHolder(ViewHolder holder, int position) { + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { final QuickAction action = data.get(position); - holder.title.setText(action.nameRes); - holder.icon.setImageResource(action.iconRes); + if (getItemViewType(position) == HEADER) { - holder.itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + HeaderViewHolder headerHolder = (HeaderViewHolder) holder; - CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type); - dialog.show(getFragmentManager(), AddQuickActionDialog.TAG); + headerHolder.header.setText(action.nameRes); + if (position == 0) headerHolder.divider.setVisibility(View.GONE); - dismiss(); - } - }); + } else { + + ItemViewHolder itemHolder = (ItemViewHolder) holder; + + itemHolder.title.setText(action.nameRes); + itemHolder.icon.setImageResource(action.iconRes); + + itemHolder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type); + dialog.show(getFragmentManager(), AddQuickActionDialog.TAG); + + dismiss(); + } + }); + + } } @Override @@ -121,5 +156,14 @@ public class AddQuickActionDialog extends DialogFragment { return data.size(); } + + @Override + public int getItemViewType(int position) { + + if (data.get(position).type == 0) + return HEADER; + + return ITEM; + } } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java index f9b089a934..71addb600e 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java @@ -38,6 +38,11 @@ public class QuickAction { this.id = System.currentTimeMillis(); } + protected QuickAction(int type, int nameRes) { + this.id = System.currentTimeMillis(); + this.nameRes = nameRes; + } + protected QuickAction(int type) { this.id = System.currentTimeMillis(); this.type = type; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 4aaf0a76dd..d6b42f200f 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -59,6 +59,22 @@ public class QuickActionFactory { return quickActions; } + public static List produceTypeActionsListWithHeaders() { + + ArrayList quickActions = new ArrayList<>(); + + quickActions.add(new QuickAction(0, R.string.quick_action_add_create_items)); + quickActions.add(new MarkerAction()); + quickActions.add(new FavoriteAction()); + quickActions.add(new GPXAction()); + + quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map)); + quickActions.add(new ShowHideFavoritesAction()); + quickActions.add(new ShowHidePoiAction()); + + return quickActions; + } + public static QuickAction newActionByType(int type) { switch (type) {