From fcdc4e5d5c6677c307ed623dee6d3fc1c1de1520 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 26 Oct 2017 09:13:01 +0300 Subject: [PATCH] Fix updating UI after saving map markers --- .../CoordinateInputDialogFragment.java | 26 ++++++++--------- .../mapmarkers/MapMarkersDialogFragment.java | 29 ++++++++++++++++--- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 56cf783828..da7c02899f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -79,6 +79,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private static final String LONGITUDE_LABEL = "longitude"; private static final String NAME_LABEL = "name"; + private OnMapMarkersSavedListener listener; private List mapMarkers = new ArrayList<>(); private CoordinateInputAdapter adapter; private boolean lightTheme; @@ -94,6 +95,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean compassUpdateAllowed = true; private MapMarkersHelper mapMarkersHelper; + public void setListener(OnMapMarkersSavedListener listener) { + this.listener = listener; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -301,6 +306,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private void saveMarkers() { mapMarkersHelper.addMarkers(mapMarkers); + if (listener != null) { + listener.onMapMarkersSaved(); + } } private void registerTextFieldBoxes() { @@ -583,20 +591,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm return (OsmandApplication) getActivity().getApplication(); } - public static boolean showInstance(@NonNull MapActivity mapActivity) { - try { - if (mapActivity.isActivityDestroyed()) { - return false; - } - CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment(); - fragment.setRetainInstance(true); - fragment.show(mapActivity.getSupportFragmentManager(), TAG); - return true; - } catch (RuntimeException e) { - return false; - } - } - @Override public void updateLocation(Location location) { boolean newLocation = this.location == null && location != null; @@ -693,4 +687,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } } + public interface OnMapMarkersSavedListener { + void onMapMarkersSaved(); + } + } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index a1eba79338..c67db62314 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -26,6 +26,7 @@ import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; +import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnMapMarkersSavedListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener; @@ -110,6 +111,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm if (saveAsTrackFragment != null) { ((SaveAsTrackBottomSheetDialogFragment) saveAsTrackFragment).setListener(createSaveAsTrackFragmentListener()); } + Fragment coordinateInputDialog = fragmentManager.findFragmentByTag(CoordinateInputDialogFragment.TAG); + if (coordinateInputDialog != null) { + ((CoordinateInputDialogFragment) coordinateInputDialog).setListener(createOnMapMarkersSavedListener()); + } View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); @@ -202,10 +207,25 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm return mainView; } + private void updateAdapters() { + activeFragment.updateAdapter(); + groupsFragment.updateAdapter(); + historyFragment.updateAdapter(); + } + private OsmandApplication getMyApplication() { return (OsmandApplication) getActivity().getApplication(); } + private OnMapMarkersSavedListener createOnMapMarkersSavedListener() { + return new OnMapMarkersSavedListener() { + @Override + public void onMapMarkersSaved() { + updateAdapters(); + } + }; + } + private MarkerOptionsFragmentListener createOptionsFragmentListener() { return new MarkerOptionsFragmentListener() { @@ -232,7 +252,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void coordinateInputOnClick() { if (mapActivity != null) { - CoordinateInputDialogFragment.showInstance(mapActivity); + CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment(); + fragment.setRetainInstance(true); + fragment.setListener(createOnMapMarkersSavedListener()); + fragment.show(mapActivity.getSupportFragmentManager(), CoordinateInputDialogFragment.TAG); } } @@ -302,9 +325,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public void onMapMarkersModeChanged(boolean showDirectionEnabled) { mapActivity.getMapLayers().getMapWidgetRegistry().updateMapMarkersMode(mapActivity); activeFragment.setShowDirectionEnabled(showDirectionEnabled); - activeFragment.updateAdapter(); - groupsFragment.updateAdapter(); - historyFragment.updateAdapter(); + updateAdapters(); } }; }