Show edit route screen

This commit is contained in:
Vitaliy 2020-08-07 20:30:37 +03:00
parent a719ce7912
commit a132201ab0
4 changed files with 84 additions and 30 deletions

View file

@ -460,7 +460,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
initMeasurementMode(newGpxData); initMeasurementMode(newGpxData);
if (planRouteMode && savedInstanceState == null) { if (editingCtx.isNewData() && planRouteMode && savedInstanceState == null) {
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createStartPlanRouteListener()); createStartPlanRouteListener());
} }
@ -1793,6 +1793,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return showFragment(fragment, fragmentManager); return showFragment(fragment, fragmentManager);
} }
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, boolean planRoute) {
MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setEditingCtx(editingCtx);
fragment.setPlanRouteMode(planRoute);
return showFragment(fragment, fragmentManager);
}
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) { public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) {
MeasurementToolFragment fragment = new MeasurementToolFragment(); MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setEditingCtx(editingCtx); fragment.setEditingCtx(editingCtx);

View file

@ -17,6 +17,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
@ -179,15 +180,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
importTrackCard.setListener(this); importTrackCard.setListener(this);
cardsContainer.addView(importTrackCard.build(mapActivity)); cardsContainer.addView(importTrackCard.build(mapActivity));
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); setupTracksCard();
List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackNames(app);
List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false);
if (list.size() > 0) {
String defaultCategory = app.getString(R.string.shared_string_all);
TracksToFollowCard tracksCard = new TracksToFollowCard(mapActivity, list, defaultCategory);
tracksCard.setListener(this);
cardsContainer.addView(tracksCard.build(mapActivity));
}
} else { } else {
File file = new File(gpxFile.path); File file = new File(gpxFile.path);
GPXInfo gpxInfo = new GPXInfo(gpxFile.path, file.lastModified(), file.length()); GPXInfo gpxInfo = new GPXInfo(gpxFile.path, file.lastModified(), file.length());
@ -214,8 +207,32 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
reverseTrackCard.setListener(this); reverseTrackCard.setListener(this);
cardsContainer.addView(reverseTrackCard.build(mapActivity)); cardsContainer.addView(reverseTrackCard.build(mapActivity));
} }
if (!rparams.isUseIntermediatePointsRTE()) { if (!rparams.isUseIntermediatePointsRTE()) {
setupNavigateOptionsCard(rparams);
}
}
}
}
}
private void setupTracksCard() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackNames(app);
List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false);
if (list.size() > 0) {
String defaultCategory = app.getString(R.string.shared_string_all);
TracksToFollowCard tracksCard = new TracksToFollowCard(mapActivity, list, defaultCategory);
tracksCard.setListener(FollowTrackFragment.this);
getCardsContainer().addView(tracksCard.build(mapActivity));
}
}
}
private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
int passRouteId = R.string.gpx_option_from_start_point; int passRouteId = R.string.gpx_option_from_start_point;
LocalRoutingParameter passWholeRoute = new OtherLocalRoutingParameter(passRouteId, LocalRoutingParameter passWholeRoute = new OtherLocalRoutingParameter(passRouteId,
app.getString(passRouteId), rparams.isPassWholeRoute()); app.getString(passRouteId), rparams.isPassWholeRoute());
@ -226,10 +243,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
NavigateTrackOptionsCard navigateTrackCard = new NavigateTrackOptionsCard(mapActivity, passWholeRoute, navigationType); NavigateTrackOptionsCard navigateTrackCard = new NavigateTrackOptionsCard(mapActivity, passWholeRoute, navigationType);
navigateTrackCard.setListener(this); navigateTrackCard.setListener(this);
cardsContainer.addView(navigateTrackCard.build(mapActivity)); getCardsContainer().addView(navigateTrackCard.build(mapActivity));
}
}
}
} }
} }
@ -326,7 +340,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
importTrack(); importTrack();
} else if (card instanceof TrackEditCard) { } else if (card instanceof TrackEditCard) {
editTrack(); editTrack();
dismiss(); close();
} else if (card instanceof SelectTrackCard) { } else if (card instanceof SelectTrackCard) {
updateSelectionMode(true); updateSelectionMode(true);
} else if (card instanceof ReverseTrackCard } else if (card instanceof ReverseTrackCard
@ -411,12 +425,15 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
importHelper.setGpxImportCompleteListener(new ImportHelper.OnGpxImportCompleteListener() { importHelper.setGpxImportCompleteListener(new ImportHelper.OnGpxImportCompleteListener() {
@Override @Override
public void onComplete(boolean success) { public void onComplete(boolean success) {
if (success) {
// setupTracksCard();
} else {
app.showShortToastMessage(app.getString(R.string.error_occurred_loading_gpx));
}
importHelper.setGpxImportCompleteListener(null); importHelper.setGpxImportCompleteListener(null);
} }
}); });
if (!importHelper.handleGpxImport(uri, false, false)) { importHelper.handleGpxImport(uri, true, false);
log.debug("import completed!");
}
} }
} else { } else {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
@ -433,7 +450,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
MeasurementEditingContext editingContext = new MeasurementEditingContext(); MeasurementEditingContext editingContext = new MeasurementEditingContext();
editingContext.setNewGpxData(newGpxData); editingContext.setNewGpxData(newGpxData);
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext); MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true);
} }
} }
@ -488,4 +505,16 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
} }
}); });
} }
private void close() {
try {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
fragmentManager.beginTransaction().remove(this).commitAllowingStateLoss();
}
} catch (Exception e) {
log.error(e);
}
}
} }

View file

@ -7,8 +7,8 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -32,8 +32,21 @@ public class TrackEditCard extends BaseCard {
return R.layout.gpx_track_item; return R.layout.gpx_track_item;
} }
private GpxDataItem getDataItem(GpxUiHelper.GPXInfo info) { private GpxDataItem getDataItem(final GPXInfo info) {
return app.getGpxDbHelper().getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName())); GpxDataItemCallback itemCallback = new GpxDataItemCallback() {
@Override
public boolean isCancelled() {
return false;
}
@Override
public void onGpxDataItemReady(GpxDataItem item) {
if (item != null) {
updateContent();
}
}
};
return app.getGpxDbHelper().getItem(new File(info.getFileName()), itemCallback);
} }
@Override @Override

View file

@ -33,6 +33,11 @@ public class TracksToFollowCard extends BaseCard {
gpxInfoCategories = getGpxInfoCategories(); gpxInfoCategories = getGpxInfoCategories();
} }
public void setGpxInfoList(List<GPXInfo> gpxInfoList) {
this.gpxInfoList = gpxInfoList;
gpxInfoCategories = getGpxInfoCategories();
}
public List<GPXInfo> getGpxInfoList() { public List<GPXInfo> getGpxInfoList() {
return gpxInfoList; return gpxInfoList;
} }