Merge pull request #6131 from osmandapp/edit_map_marker
Replace map marker edition screen with new one
This commit is contained in:
commit
6af95064d8
8 changed files with 197 additions and 194 deletions
|
@ -105,6 +105,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/category_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/category_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||
Thx - Hardy
|
||||
-->
|
||||
|
||||
<string name="markers_remove_dialog_msg">Delete Map marker \'%s\'?</string>
|
||||
<string name="edit_map_marker">Edit map marker</string>
|
||||
<string name="third_party_application">Third-party application</string>
|
||||
<string name="search_street">Search street</string>
|
||||
<string name="start_search_from_city">Start search from city</string>
|
||||
|
|
|
@ -39,13 +39,12 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
|
|||
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.MapMarkerEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.RtePtEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor;
|
||||
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.RenameMarkerBottomSheetDialogFragment;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.transport.TransportStopRoute;
|
||||
|
@ -70,6 +69,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
private FavoritePointEditor favoritePointEditor;
|
||||
private WptPtEditor wptPtEditor;
|
||||
private RtePtEditor rtePtEditor;
|
||||
private MapMarkerEditor mapMarkerEditor;
|
||||
|
||||
private boolean active;
|
||||
private LatLon latLon;
|
||||
|
@ -165,6 +165,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (rtePtEditor != null) {
|
||||
rtePtEditor.setMapActivity(mapActivity);
|
||||
}
|
||||
if (mapMarkerEditor != null) {
|
||||
mapMarkerEditor.setMapActivity(mapActivity);
|
||||
}
|
||||
|
||||
if (active && mapActivity != null) {
|
||||
acquireMenuController(false);
|
||||
|
@ -221,6 +224,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
return rtePtEditor;
|
||||
}
|
||||
|
||||
public MapMarkerEditor getMapMarkerEditor() {
|
||||
if (mapMarkerEditor == null) {
|
||||
mapMarkerEditor = new MapMarkerEditor(mapActivity);
|
||||
}
|
||||
return mapMarkerEditor;
|
||||
}
|
||||
|
||||
public PointEditor getPointEditor(String tag) {
|
||||
if (favoritePointEditor != null && favoritePointEditor.getFragmentTag().equals(tag)) {
|
||||
return favoritePointEditor;
|
||||
|
@ -228,6 +238,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
return wptPtEditor;
|
||||
} else if (rtePtEditor != null && rtePtEditor.getFragmentTag().equals(tag)) {
|
||||
return rtePtEditor;
|
||||
} else if (mapMarkerEditor != null && mapMarkerEditor.getFragmentTag().equals(tag)) {
|
||||
return mapMarkerEditor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -869,12 +881,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (mapActivity != null) {
|
||||
MapMarker marker = getMapMarker();
|
||||
if (marker != null) {
|
||||
RenameMarkerBottomSheetDialogFragment
|
||||
.showInstance(mapActivity.getSupportFragmentManager(), marker);
|
||||
} else if (pointDescription.isMapMarker()) {
|
||||
hide();
|
||||
MapActivity.clearPrevActivityIntent();
|
||||
MapMarkersDialogFragment.showInstance(mapActivity);
|
||||
getMapMarkerEditor().edit(marker);
|
||||
} else {
|
||||
String mapObjectName = null;
|
||||
if (object instanceof Amenity) {
|
||||
|
@ -883,8 +890,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
|
||||
getPointDescriptionForMarker(), mapObjectName);
|
||||
close();
|
||||
}
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
public class MapMarkerEditor extends PointEditor {
|
||||
|
||||
private MapMarker marker;
|
||||
|
||||
public MapMarkerEditor(MapActivity mapActivity) {
|
||||
super(mapActivity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentTag() {
|
||||
return MapMarkerEditorFragment.class.getSimpleName();
|
||||
}
|
||||
|
||||
public MapMarker getMarker() {
|
||||
return marker;
|
||||
}
|
||||
|
||||
public void edit(@NonNull MapMarker marker) {
|
||||
this.marker = marker;
|
||||
isNew = false;
|
||||
if (mapActivity != null) {
|
||||
MapMarkerEditorFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
public class MapMarkerEditorFragment extends PointEditorFragment {
|
||||
|
||||
private MapMarkerEditor editor;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
editor = getMapActivity().getContextMenu().getMapMarkerEditor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View mainView = super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (mainView != null) {
|
||||
mainView.findViewById(R.id.category_row).setVisibility(View.GONE);
|
||||
mainView.findViewById(R.id.description_info_view).setVisibility(View.GONE);
|
||||
}
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean wasSaved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void save(boolean needDismiss) {
|
||||
EditText nameEt = getNameEdit();
|
||||
String name = nameEt.getText().toString().trim();
|
||||
if (name.replaceAll("\\s", "").length() > 0) {
|
||||
MapMarker marker = editor.getMarker();
|
||||
marker.setOriginalPointDescription(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name));
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
app.getMapMarkersHelper().updateMapMarker(marker, true);
|
||||
}
|
||||
if (needDismiss) {
|
||||
dismiss(true);
|
||||
}
|
||||
} else {
|
||||
nameEt.setError(getString(R.string.wrong_input));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(final boolean needDismiss) {
|
||||
Context ctx = getContext();
|
||||
final MapMarker marker = editor.getMarker();
|
||||
new AlertDialog.Builder(ctx)
|
||||
.setMessage(getString(R.string.markers_remove_dialog_msg, marker.getName(ctx)))
|
||||
.setNegativeButton(R.string.shared_string_no, null)
|
||||
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
app.getMapMarkersHelper().removeMarker(marker);
|
||||
}
|
||||
if (needDismiss) {
|
||||
dismiss(true);
|
||||
}
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointEditor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolbarTitle() {
|
||||
return getString(R.string.edit_map_marker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeaderCaption() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInitValue() {
|
||||
return editor.getMarker().getName(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategoryInitValue() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescriptionInitValue() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getNameIcon() {
|
||||
return requireMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_flag_dark, getPointColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getCategoryIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPointColor() {
|
||||
return MapMarker.getColorId(editor.getMarker().colorIndex);
|
||||
}
|
||||
|
||||
public static void showInstance(MapActivity mapActivity) {
|
||||
MapMarkerEditor editor = mapActivity.getContextMenu().getMapMarkerEditor();
|
||||
MapMarkerEditorFragment fragment = new MapMarkerEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
|
@ -154,6 +154,10 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
protected EditText getNameEdit() {
|
||||
return nameEdit;
|
||||
}
|
||||
|
||||
protected DialogFragment createSelectCategoryDialog() {
|
||||
return SelectCategoryDialogFragment.createInstance(getEditor().getFragmentTag());
|
||||
}
|
||||
|
|
|
@ -1,184 +0,0 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||
|
||||
public class RenameMarkerBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public final static String TAG = "RenameMarkerBottomSheetDialogFragment";
|
||||
|
||||
private MapMarker marker;
|
||||
|
||||
public void setMarker(MapMarker marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_rename_marker_bottom_sheet_dialog, container);
|
||||
|
||||
LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
|
||||
int layoutRes = Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH
|
||||
? R.layout.markers_track_name_text_field_box
|
||||
: R.layout.markers_track_name_edit_text;
|
||||
contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 1);
|
||||
View textBox = mainView.findViewById(R.id.name_text_box);
|
||||
if (portrait) {
|
||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||
}
|
||||
|
||||
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
|
||||
if (nightMode) {
|
||||
nameEditText.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
|
||||
if (textBox instanceof TextInputLayout) {
|
||||
((TextInputLayout) textBox).setHintTextAppearance(R.style.TextAppearance_App_DarkTextInputLayout);
|
||||
} else if (textBox instanceof OsmandTextFieldBoxes) {
|
||||
((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(mapActivity,R.color.color_dialog_buttons_dark));
|
||||
}
|
||||
}
|
||||
nameEditText.setText(marker.getName(mapActivity));
|
||||
nameEditText.requestFocus();
|
||||
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||
|
||||
if (textBox instanceof OsmandTextFieldBoxes) {
|
||||
((OsmandTextFieldBoxes) textBox).activate(true);
|
||||
}
|
||||
|
||||
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String name = nameEditText.getText().toString();
|
||||
if (name.replaceAll("\\s", "").length() > 0) {
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
|
||||
marker.setOriginalPointDescription(pd);
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().updateMapMarker(marker, true);
|
||||
dismiss();
|
||||
} else {
|
||||
nameEditText.setError(getString(R.string.wrong_input));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mainView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
|
||||
final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
|
||||
final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity());
|
||||
|
||||
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
boolean dimensSet;
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (!dimensSet) {
|
||||
final View scrollView = mainView.findViewById(R.id.rename_marker_scroll_view);
|
||||
int scrollViewHeight = scrollView.getHeight();
|
||||
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
||||
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
|
||||
int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight;
|
||||
if (scrollViewHeight > spaceForScrollView) {
|
||||
scrollView.getLayoutParams().height = spaceForScrollView;
|
||||
scrollView.requestLayout();
|
||||
}
|
||||
|
||||
if (!portrait) {
|
||||
if (screenHeight - statusBarHeight - mainView.getHeight()
|
||||
>= AndroidUtils.dpToPx(getActivity(), 8)) {
|
||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode,
|
||||
R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
|
||||
} else {
|
||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode,
|
||||
R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark);
|
||||
}
|
||||
}
|
||||
dimensSet = true;
|
||||
}
|
||||
|
||||
final Window window = getDialog().getWindow();
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
params.gravity = Gravity.BOTTOM;
|
||||
window.setAttributes(params);
|
||||
}
|
||||
});
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
|
||||
final Window window = getDialog().getWindow();
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
Dialog dialog = getDialog();
|
||||
if (dialog != null && getRetainInstance()) {
|
||||
dialog.setDismissMessage(null);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue