Move "move" button in layout; always show "delete" button

This commit is contained in:
Alexander Sytnyk 2018-01-25 13:22:55 +02:00
parent 78c482c3ae
commit e9d1efe10b
2 changed files with 33 additions and 108 deletions

View file

@ -9,6 +9,23 @@
android:descendantFocusability="blocksDescendants"
android:minHeight="50dp">
<ImageView
android:id="@+id/info_move"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:clickable="false"
android:contentDescription="@string/shared_string_more"
android:focusable="false"
android:paddingLeft="12dp"
android:paddingStart="12dp"
android:scaleType="center"
android:src="@drawable/ic_flat_list_dark"
android:visibility="gone"
tools:visibility="visible"/>
<ImageView
android:id="@+id/waypoint_icon"
android:layout_width="56dp"
@ -106,19 +123,4 @@
android:scaleType="center"
android:src="@drawable/ic_action_remove_dark"/>
<ImageView
android:id="@+id/info_move"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:clickable="false"
android:contentDescription="@string/shared_string_more"
android:focusable="false"
android:scaleType="center"
android:src="@drawable/ic_flat_list_dark"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout>

View file

@ -222,31 +222,20 @@ public class WaypointDialogHelper {
}
private List<Drawable> getCustomDividers(Context ctx, List<Object> points, boolean nightMode) {
int color;
int pointColor;
if (nightMode) {
color = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
pointColor = ContextCompat.getColor(ctx, R.color.dashboard_divider_dark);
} else {
color = ContextCompat.getColor(ctx, R.color.dashboard_divider_light);
pointColor = ContextCompat.getColor(ctx, R.color.ctx_menu_info_divider_light);
}
int color = ContextCompat.getColor(ctx, nightMode
? R.color.dashboard_divider_dark : R.color.dashboard_divider_light);
Shape fullDividerShape = new ListDividerShape(color, 0);
Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 56f));
Shape halfPointDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 56f),
pointColor, AndroidUtils.dpToPx(ctx, 1.5f), true);
Shape headerDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 16f));
final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
final ShapeDrawable halfPointDivider = new ShapeDrawable(halfPointDividerShape);
final ShapeDrawable headerDivider = new ShapeDrawable(headerDividerShape);
int divHeight = AndroidUtils.dpToPx(ctx, 1f);
fullDivider.setIntrinsicHeight(divHeight);
halfDivider.setIntrinsicHeight(divHeight);
halfPointDivider.setIntrinsicHeight(divHeight);
headerDivider.setIntrinsicHeight(divHeight);
List<Drawable> res = new ArrayList<>();
@ -267,16 +256,7 @@ public class WaypointDialogHelper {
Drawable d = null;
if (locationPointNext) {
if (locationPoint) {
LocationPointWrapper w = (LocationPointWrapper) obj;
if (w.type == WaypointHelper.TARGETS) {
d = halfPointDivider;
} else {
d = halfDivider;
}
} else {
d = fullDivider;
}
d = locationPoint ? halfDivider : fullDivider;
} else if (objNext instanceof RadiusItem && labelView) {
d = headerDivider;
} else if (locationPoint && !bottomDividerViewNext) {
@ -411,79 +391,22 @@ public class WaypointDialogHelper {
move.setVisibility(View.GONE);
more.setVisibility(View.GONE);
} else {
remove.setVisibility(View.GONE);
remove.setVisibility(View.VISIBLE);
move.setVisibility(View.VISIBLE);
more.setVisibility(View.GONE);
((ImageView) move).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_reorder, !nightMode));
if (app.accessibilityEnabled()) {
move.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((DragIcon) view.getTag()).onClick();
}
});
}
((ImageButton) remove).setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, !nightMode));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deletePoint(app, ctx, adapter, helper, point, deletedPoints, true);
}
});
((ImageView) move).setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_reorder, !nightMode));
move.setTag(new DragIcon() {
@Override
public void onClick() {
final PopupMenu optionsMenu = new PopupMenu(ctx, move);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
List<Object> activeObjects = ((StableArrayAdapter) adapter).getActiveObjects();
int count = activeObjects.size();
int t = -1;
for (int i = 0; i < activeObjects.size(); i++) {
Object o = activeObjects.get(i);
if (point == o) {
t = i;
break;
}
}
final int index = t;
MenuItem item;
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
final TargetPoint start = targetPointsHelper.getPointToStart();
if (count > 1 && (index > 0 || start != null)) {
item = optionsMenu.getMenu().add(R.string.shared_string_move_up)
.setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_drop_up));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (index == 0) {
switchStartAndFirstIntermediate(targetPointsHelper, ctx, start, helper);
} else if (helper != null && helper.helperCallbacks != null) {
helper.helperCallbacks.exchangeWaypoints(index, index - 1);
}
updateRouteInfoMenu(ctx);
return true;
}
});
}
if (index < count - 1 && count > 1) {
item = optionsMenu.getMenu().add(R.string.shared_string_move_down)
.setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_drop_down));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (helper != null && helper.helperCallbacks != null) {
helper.helperCallbacks.exchangeWaypoints(index, index + 1);
}
updateRouteInfoMenu(ctx);
return true;
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_remove)
.setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
deletePoint(app, ctx, adapter, helper, point, deletedPoints, true);
return true;
}
});
optionsMenu.show();
// do nothing
}
});
}
@ -491,8 +414,8 @@ public class WaypointDialogHelper {
remove.setVisibility(View.VISIBLE);
move.setVisibility(View.GONE);
more.setVisibility(View.GONE);
((ImageButton) remove).setImageDrawable(app.getIconsCache().getIcon(
R.drawable.ic_action_remove_dark, !nightMode));
((ImageButton) remove).setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, !nightMode));
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {