Fix updating UI after saving map markers
This commit is contained in:
parent
f89c305d38
commit
fcdc4e5d5c
2 changed files with 37 additions and 18 deletions
|
@ -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<MapMarker> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue