quick action add dialog headers
This commit is contained in:
parent
efd2d53dc3
commit
0bb62d6b9c
6 changed files with 113 additions and 30 deletions
|
@ -14,17 +14,8 @@
|
||||||
android:layout_marginRight="24dp"
|
android:layout_marginRight="24dp"
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
android:textSize="@dimen/dialog_header_text_size"
|
||||||
android:textColor="?android:textColorPrimary"
|
android:textColor="?android:textColorPrimary"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="8dp"/>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/dialog_add_action_subhead"
|
|
||||||
android:layout_marginLeft="24dp"
|
|
||||||
android:layout_marginRight="24dp"
|
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
|
||||||
android:textColor="?android:textColorSecondary"
|
|
||||||
android:layout_marginBottom="16dp"/>
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/recycler_view"
|
android:id="@+id/recycler_view"
|
||||||
|
|
25
OsmAnd/res/layout/quick_action_add_dialog_header.xml
Normal file
25
OsmAnd/res/layout/quick_action_add_dialog_header.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="?attr/bg_color">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_sub_text_size"
|
||||||
|
android:layout_marginLeft="24dp"
|
||||||
|
android:layout_marginRight="24dp"
|
||||||
|
tools:text="Screen 1"/>
|
||||||
|
|
||||||
|
<View android:id="@+id/divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?attr/dashboard_divider"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -2473,7 +2473,6 @@ If you need help with OsmAnd application, please contact our support team: suppo
|
||||||
<string name="quick_action_edit_action">Edit action</string>
|
<string name="quick_action_edit_action">Edit action</string>
|
||||||
<string name="quick_action_add_favorite">Add favorite</string>
|
<string name="quick_action_add_favorite">Add favorite</string>
|
||||||
<string name="dialog_add_action_title">Add Action</string>
|
<string name="dialog_add_action_title">Add Action</string>
|
||||||
<string name="dialog_add_action_subhead">Create item</string>
|
|
||||||
<string name="quick_actions_delete">Delete Action</string>
|
<string name="quick_actions_delete">Delete Action</string>
|
||||||
<string name="quick_actions_delete_text">Are you sure you want to delete \"%s\" Action?</string>
|
<string name="quick_actions_delete_text">Are you sure you want to delete \"%s\" Action?</string>
|
||||||
<string name="btn_dismiss">Dismiss</string>
|
<string name="btn_dismiss">Dismiss</string>
|
||||||
|
@ -2494,4 +2493,7 @@ If you need help with OsmAnd application, please contact our support team: suppo
|
||||||
<string name="quic_action_showhide_favorites_title">Show/Hide Favorites</string>
|
<string name="quic_action_showhide_favorites_title">Show/Hide Favorites</string>
|
||||||
<string name="quic_action_showhide_poi_title">Show/Hide POI</string>
|
<string name="quic_action_showhide_poi_title">Show/Hide POI</string>
|
||||||
<string name="quick_action_add_category">Add category</string>
|
<string name="quick_action_add_category">Add category</string>
|
||||||
|
<string name="quick_action_add_create_items">Create items</string>
|
||||||
|
<string name="quick_action_add_configure_map">Configure map</string>
|
||||||
|
<string name="quick_action_add_navigation">Navigation</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
View root = inflater.inflate(R.layout.quick_action_add_dialog, container, false);
|
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);
|
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
|
||||||
Button btnDismiss = (Button) root.findViewById(R.id.btnDismiss);
|
Button btnDismiss = (Button) root.findViewById(R.id.btnDismiss);
|
||||||
|
@ -64,16 +64,19 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
|
public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private static final int HEADER = 1;
|
||||||
|
private static final int ITEM = 2;
|
||||||
|
|
||||||
private List<QuickAction> data;
|
private List<QuickAction> data;
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
public class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView title;
|
private TextView title;
|
||||||
private ImageView icon;
|
private ImageView icon;
|
||||||
|
|
||||||
public ViewHolder(View v) {
|
public ItemViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
||||||
title = (TextView) v.findViewById(R.id.title);
|
title = (TextView) v.findViewById(R.id.title);
|
||||||
|
@ -81,30 +84,60 @@ 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<QuickAction> data) {
|
public Adapter(List<QuickAction> data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
if (viewType == HEADER) {
|
||||||
.inflate(R.layout.quick_action_add_dialog_item, parent, false);
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||||
|
|
||||||
final QuickAction action = data.get(position);
|
final QuickAction action = data.get(position);
|
||||||
|
|
||||||
holder.title.setText(action.nameRes);
|
if (getItemViewType(position) == HEADER) {
|
||||||
holder.icon.setImageResource(action.iconRes);
|
|
||||||
|
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
|
||||||
|
|
||||||
|
headerHolder.header.setText(action.nameRes);
|
||||||
|
if (position == 0) headerHolder.divider.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
ItemViewHolder itemHolder = (ItemViewHolder) holder;
|
||||||
|
|
||||||
|
itemHolder.title.setText(action.nameRes);
|
||||||
|
itemHolder.icon.setImageResource(action.iconRes);
|
||||||
|
|
||||||
|
itemHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
@ -114,6 +147,8 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,5 +156,14 @@ public class AddQuickActionDialog extends DialogFragment {
|
||||||
return data.size();
|
return data.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
|
||||||
|
if (data.get(position).type == 0)
|
||||||
|
return HEADER;
|
||||||
|
|
||||||
|
return ITEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ public class QuickAction {
|
||||||
this.id = System.currentTimeMillis();
|
this.id = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected QuickAction(int type, int nameRes) {
|
||||||
|
this.id = System.currentTimeMillis();
|
||||||
|
this.nameRes = nameRes;
|
||||||
|
}
|
||||||
|
|
||||||
protected QuickAction(int type) {
|
protected QuickAction(int type) {
|
||||||
this.id = System.currentTimeMillis();
|
this.id = System.currentTimeMillis();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
|
@ -59,6 +59,22 @@ public class QuickActionFactory {
|
||||||
return quickActions;
|
return quickActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<QuickAction> produceTypeActionsListWithHeaders() {
|
||||||
|
|
||||||
|
ArrayList<QuickAction> 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) {
|
public static QuickAction newActionByType(int type) {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
Loading…
Reference in a new issue