Merge pull request #4709 from osmandapp/fix_marker_menu

Fix marker menu
This commit is contained in:
Alexey 2017-11-07 18:35:44 +03:00 committed by GitHub
commit 5654b3c3d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 81 deletions

View file

@ -122,39 +122,4 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/> android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout> </LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/bottom_sheet_divider_margin_bottom"
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginStart="@dimen/bottom_sheet_divider_margin_start"
android:layout_marginTop="@dimen/bottom_sheet_divider_margin_top"
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/delete_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical">
<ImageView
android:id="@+id/delete_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
android:layout_marginStart="@dimen/content_padding"
tools:src="@drawable/ic_action_delete_dark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/shared_string_delete"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="rename_marker">Rename marker</string>
<string name="tap_on_map_to_hide_interface_descr">A tap on the map toggles the control buttons and widgets.</string> <string name="tap_on_map_to_hide_interface_descr">A tap on the map toggles the control buttons and widgets.</string>
<string name="tap_on_map_to_hide_interface">Full screen mode</string> <string name="tap_on_map_to_hide_interface">Full screen mode</string>
<string name="show_on_top_bar">Show on Top Bar</string> <string name="show_on_top_bar">Show on Top Bar</string>

View file

@ -44,6 +44,7 @@ import net.osmand.plus.mapcontextmenu.editors.WptPtEditor;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.RenameMarkerBottomSheetDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer;
@ -87,6 +88,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
private boolean autoHide; private boolean autoHide;
private int favActionIconId; private int favActionIconId;
private int waypointActionIconId;
private MenuAction searchDoneAction; private MenuAction searchDoneAction;
@ -704,12 +706,27 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return R.string.shared_string_add_to_favorites; return R.string.shared_string_add_to_favorites;
} }
public int getWaypointActionIconId() {
return waypointActionIconId;
}
public int getWaypointActionStringId() {
if (menuController != null) {
return menuController.getWaypointActionStringId();
}
return settings.USE_MAP_MARKERS.get()
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
}
protected void acquireIcons() { protected void acquireIcons() {
super.acquireIcons(); super.acquireIcons();
if (menuController != null) { if (menuController != null) {
favActionIconId = menuController.getFavActionIconId(); favActionIconId = menuController.getFavActionIconId();
waypointActionIconId = menuController.getWaypointActionIconId();
} else { } else {
favActionIconId = R.drawable.map_action_fav_dark; favActionIconId = R.drawable.map_action_fav_dark;
waypointActionIconId = settings.USE_MAP_MARKERS.get()
? R.drawable.map_action_flag_dark : R.drawable.map_action_waypoint;
} }
} }
@ -745,20 +762,25 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
public void buttonWaypointPressed() { public void buttonWaypointPressed() {
if (pointDescription.isDestination()) { if (object != null && object instanceof MapMarker) {
mapActivity.getMapActions().editWaypoints(); RenameMarkerBottomSheetDialogFragment
} else if (settings.USE_MAP_MARKERS.get()) { .showInstance(mapActivity.getSupportFragmentManager(), (MapMarker) object);
if (pointDescription.isMapMarker()) {
hide();
MapActivity.clearPrevActivityIntent();
MapMarkersDialogFragment.showInstance(mapActivity);
} else {
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForMarker());
}
} else { } else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(), if (pointDescription.isDestination()) {
getPointDescriptionForTarget()); mapActivity.getMapActions().editWaypoints();
} else if (settings.USE_MAP_MARKERS.get()) {
if (pointDescription.isMapMarker()) {
hide();
MapActivity.clearPrevActivityIntent();
MapMarkersDialogFragment.showInstance(mapActivity);
} else {
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForMarker());
}
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForTarget());
}
} }
close(); close();
} }

View file

@ -455,15 +455,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}); });
final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button); final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button);
if (getMyApplication().getSettings().USE_MAP_MARKERS.get()) { buttonWaypoint.setImageDrawable(getIcon(menu.getWaypointActionIconId(),
buttonWaypoint.setImageDrawable(getIcon(R.drawable.map_action_flag_dark, !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId()));
buttonWaypoint.setContentDescription(getString(R.string.shared_string_add_to_map_markers));
} else {
buttonWaypoint.setImageDrawable(getIcon(R.drawable.map_action_waypoint,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonWaypoint.setContentDescription(getString(R.string.context_menu_item_destination_point));
}
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode); AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode);
buttonWaypoint.setOnClickListener(new View.OnClickListener() { buttonWaypoint.setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -411,6 +411,16 @@ public abstract class MenuController extends BaseMenuController {
return R.string.shared_string_add_to_favorites; return R.string.shared_string_add_to_favorites;
} }
public int getWaypointActionIconId() {
return getMapActivity().getMyApplication().getSettings().USE_MAP_MARKERS.get()
? R.drawable.map_action_flag_dark : R.drawable.map_action_waypoint;
}
public int getWaypointActionStringId() {
return getMapActivity().getMyApplication().getSettings().USE_MAP_MARKERS.get()
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
}
public String getTypeStr() { public String getTypeStr() {
return ""; return "";
} }

View file

@ -94,4 +94,14 @@ public class MapMarkerMenuController extends MenuController {
public boolean needStreetName() { public boolean needStreetName() {
return !needTypeStr(); return !needTypeStr();
} }
@Override
public int getWaypointActionIconId() {
return R.drawable.map_action_edit_dark;
}
@Override
public int getWaypointActionStringId() {
return R.string.rename_marker;
}
} }

View file

@ -82,7 +82,6 @@ public class MarkerMenuOnMapFragment extends BaseOsmAndFragment implements OsmAn
((ImageView) mainView.findViewById(R.id.marker_icon)) ((ImageView) mainView.findViewById(R.id.marker_icon))
.setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex))); .setImageDrawable(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex)));
((ImageView) mainView.findViewById(R.id.rename_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); ((ImageView) mainView.findViewById(R.id.rename_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark));
((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark));
((TextView) mainView.findViewById(R.id.marker_title)).setText(marker.getName(getActivity())); ((TextView) mainView.findViewById(R.id.marker_title)).setText(marker.getName(getActivity()));
@ -135,33 +134,11 @@ public class MarkerMenuOnMapFragment extends BaseOsmAndFragment implements OsmAn
public void onClick(View view) { public void onClick(View view) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
RenameMarkerBottomSheetDialogFragment fragment = new RenameMarkerBottomSheetDialogFragment(); RenameMarkerBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), marker);
fragment.setMarker(marker);
fragment.setRetainInstance(true);
fragment.show(mapActivity.getSupportFragmentManager(), RenameMarkerBottomSheetDialogFragment.TAG);
} }
} }
}); });
mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
app.getMapMarkersHelper().removeMarker(marker);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), R.string.item_removed, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
app.getMapMarkersHelper().addMarker(marker);
}
})
.show();
}
dismiss();
}
});
mainView.findViewById(R.id.back_row).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.back_row).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {

View file

@ -162,4 +162,16 @@ public class RenameMarkerBottomSheetDialogFragment extends BottomSheetDialogFrag
} }
super.onDestroyView(); super.onDestroyView();
} }
public static boolean showInstance(FragmentManager fm, MapMarker marker) {
try {
RenameMarkerBottomSheetDialogFragment fragment = new RenameMarkerBottomSheetDialogFragment();
fragment.setMarker(marker);
fragment.setRetainInstance(true);
fragment.show(fm, RenameMarkerBottomSheetDialogFragment.TAG);
return true;
} catch (Exception e) {
return false;
}
}
} }