diff --git a/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java index 228cf584be..59c48ff48e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java @@ -1,7 +1,5 @@ package net.osmand.plus.osmedit; -import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH; - import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -10,8 +8,6 @@ import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.InputFilter; -import android.text.InputFilter.LengthFilter; -import android.text.Spanned; import android.text.TextUtils; import android.text.TextWatcher; import android.util.TypedValue; @@ -41,6 +37,8 @@ import java.util.Map; import gnu.trove.list.array.TIntArrayList; +import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH; + public class BasicEditPoiFragment extends BaseOsmAndFragment implements EditPoiDialogFragment.OnFragmentActivatedListener { private static final Log LOG = PlatformUtil.getLog(BasicEditPoiFragment.class); @@ -167,6 +165,19 @@ public class BasicEditPoiFragment extends BaseOsmAndFragment mOpeningHoursAdapter.setOpeningHoursRule(item, position); } + public void removeUnsavedOpeningHours() { + EditPoiData data = getData(); + if (data != null) { + OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHoursHandleErrors(data.getTagValues() + .get(OSMSettings.OSMTagKey.OPENING_HOURS.getValue())); + if (openingHours == null) { + openingHours = new OpeningHoursParser.OpeningHours(); + } + mOpeningHoursAdapter.replaceOpeningHours(openingHours); + mOpeningHoursAdapter.updateViews(); + } + } + private EditPoiData getData() { Fragment parent = getParentFragment(); if (parent != null && parent instanceof EditPoiDialogFragment) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java index bdbb0e49c9..08fb4c61d7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java @@ -83,7 +83,15 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment { } } }) - .setNegativeButton(R.string.shared_string_cancel, null); + .setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + BasicEditPoiFragment editPoiFragment = ((BasicEditPoiFragment) getParentFragment()); + if (editPoiFragment != null) { + editPoiFragment.removeUnsavedOpeningHours(); + } + } + }); int paddingInDp = 18; float density = getActivity().getResources().getDisplayMetrics().density;