add listener for updating TrackPointFragment

This commit is contained in:
Chumva 2018-06-25 12:01:53 +03:00
parent fef53c2322
commit c8a76c3de2
3 changed files with 23 additions and 13 deletions

View file

@ -92,7 +92,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
public static final String ADDED_POINTS_NUMBER_KEY = "added_points_number_key"; public static final String ADDED_POINTS_NUMBER_KEY = "added_points_number_key";
private GPXUtilities.GPXFile newGpxFile; private GPXUtilities.GPXFile newGpxFile;
private OnMapMarkersSavedListener listener; private OnPointsSavedListener listener;
protected GPXUtilities.WptPt selectedWpt; protected GPXUtilities.WptPt selectedWpt;
private SavingTrackHelper savingTrackHelper; private SavingTrackHelper savingTrackHelper;
private GpxSelectionHelper selectedGpxHelper; private GpxSelectionHelper selectedGpxHelper;
@ -117,7 +117,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean compassUpdateAllowed = true; private boolean compassUpdateAllowed = true;
public void setListener(OnMapMarkersSavedListener listener) { public void setListener(OnPointsSavedListener listener) {
this.listener = listener; this.listener = listener;
} }
@ -189,7 +189,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
new SaveGpxAsyncTask(getMyApplication(), gpx,null, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new SaveGpxAsyncTask(getMyApplication(), gpx,null, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
syncGpx(gpx); syncGpx(gpx);
if (listener != null) { if (listener != null) {
listener.onMapMarkersSaved(); listener.onPointsSaved();
} }
dismiss(); dismiss();
} }
@ -1006,7 +1006,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
hasUnsavedChanges = false; hasUnsavedChanges = false;
app.getMapMarkersHelper().addOrEnableGroup(getGpx()); app.getMapMarkersHelper().addOrEnableGroup(getGpx());
if (listener != null) { if (listener != null) {
listener.onMapMarkersSaved(); listener.onPointsSaved();
} }
snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG) snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_show, new View.OnClickListener() { .setAction(R.string.shared_string_show, new View.OnClickListener() {
@ -1041,7 +1041,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
.setAction(R.string.shared_string_undo, new View.OnClickListener() { .setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
getGpx().addPoint(position, selectedWpt); getGpx().addPoint(position, wpt);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}); });
@ -1422,7 +1422,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
} }
interface OnMapMarkersSavedListener { public interface OnPointsSavedListener {
void onMapMarkersSaved(); void onPointsSaved();
} }
} }

View file

@ -33,7 +33,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnMapMarkersSavedListener; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnPointsSavedListener;
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener; import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
@ -141,7 +141,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
} }
Fragment coordinateInputDialog = fragmentManager.findFragmentByTag(CoordinateInputDialogFragment.TAG); Fragment coordinateInputDialog = fragmentManager.findFragmentByTag(CoordinateInputDialogFragment.TAG);
if (coordinateInputDialog != null) { if (coordinateInputDialog != null) {
((CoordinateInputDialogFragment) coordinateInputDialog).setListener(createOnMapMarkersSavedListener()); ((CoordinateInputDialogFragment) coordinateInputDialog).setListener(createOnPointsSavedListener());
} }
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
@ -293,10 +293,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private OnMapMarkersSavedListener createOnMapMarkersSavedListener() { private OnPointsSavedListener createOnPointsSavedListener() {
return new OnMapMarkersSavedListener() { return new OnPointsSavedListener() {
@Override @Override
public void onMapMarkersSaved() { public void onPointsSaved() {
updateAdapters(); updateAdapters();
} }
}; };
@ -392,7 +392,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
if (mapActivity != null) { if (mapActivity != null) {
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment(); CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.setListener(createOnMapMarkersSavedListener()); fragment.setListener(createOnPointsSavedListener());
fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG); fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG);
} }
} }

View file

@ -313,10 +313,20 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
if (fm != null) { if (fm != null) {
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment(); CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.setListener(createOnPointsSavedListener());
fragment.show(fm, CoordinateInputDialogFragment.TAG); fragment.show(fm, CoordinateInputDialogFragment.TAG);
} }
} }
private CoordinateInputDialogFragment.OnPointsSavedListener createOnPointsSavedListener() {
return new CoordinateInputDialogFragment.OnPointsSavedListener() {
@Override
public void onPointsSaved() {
setContent();
}
};
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); menu.clear();