Fix track appearance for current recording track

This commit is contained in:
Vitaliy 2020-07-29 10:24:33 +03:00
parent 24f59ca8ab
commit b469563ea1
6 changed files with 81 additions and 37 deletions

View file

@ -175,7 +175,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
@ -1247,7 +1248,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
hideContextAndRouteInfoMenues();
Bundle args = new Bundle();
args.putString(TRACK_FILE_PATH, ((GPXFile) toShow).path);
args.putString(TRACK_FILE_NAME, ((GPXFile) toShow).path);
args.putBoolean(CURRENT_RECORDING, ((GPXFile) toShow).showCurrentTrack);
args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuController.MenuState.HALF_SCREEN);
TrackAppearanceFragment fragment = new TrackAppearanceFragment();

View file

@ -41,8 +41,13 @@ public class SelectedGpxMenuController extends MenuController {
@Override
public void buttonPressed() {
Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
intent.putExtra(TrackActivity.TRACK_FILE_NAME, selectedGpxPoint.getSelectedGpxFile().getGpxFile().path);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile();
if (selectedGpxFile.isShowCurrentTrack()) {
intent.putExtra(TrackActivity.CURRENT_RECORDING, true);
} else {
intent.putExtra(TrackActivity.TRACK_FILE_NAME, selectedGpxFile.getGpxFile().path);
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(intent);
}
};

View file

@ -34,7 +34,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH;
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
@ -75,7 +75,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
}
Bundle arguments = getArguments();
if (savedInstanceState != null) {
String gpxFilePath = savedInstanceState.getString(TRACK_FILE_PATH);
String gpxFilePath = savedInstanceState.getString(TRACK_FILE_NAME);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
prepareSplitIntervalOptions();
@ -83,7 +83,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
selectedDistanceSplitInterval = savedInstanceState.getInt(SELECTED_DISTANCE_SPLIT_INTERVAL);
selectedSplitType = GpxSplitType.valueOf(savedInstanceState.getString(SELECTED_TRACK_SPLIT_TYPE));
} else if (arguments != null) {
String gpxFilePath = arguments.getString(TRACK_FILE_PATH);
String gpxFilePath = arguments.getString(TRACK_FILE_NAME);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
prepareSplitIntervalOptions();
updateSelectedSplitParams();
@ -142,7 +142,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
outState.putInt(SELECTED_TIME_SPLIT_INTERVAL, selectedTimeSplitInterval);
outState.putInt(SELECTED_DISTANCE_SPLIT_INTERVAL, selectedDistanceSplitInterval);
outState.putString(SELECTED_TRACK_SPLIT_TYPE, selectedSplitType.name());
outState.putString(TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path);
outState.putString(TRACK_FILE_NAME, selectedGpxFile.getGpxFile().path);
}
private void updateSelectedSplitParams() {
@ -327,7 +327,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
try {
if (fragmentManager.findFragmentByTag(SplitIntervalBottomSheet.TAG) == null) {
Bundle args = new Bundle();
args.putString(TRACK_FILE_PATH, trackDrawInfo.getFilePath());
args.putString(TRACK_FILE_NAME, trackDrawInfo.getFilePath());
SplitIntervalBottomSheet splitIntervalBottomSheet = new SplitIntervalBottomSheet();
splitIntervalBottomSheet.setArguments(args);

View file

@ -59,10 +59,11 @@ import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.BACK_TO_LOC_HUD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_IN_HUD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_OUT_HUD_ID;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM;
import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH;
public class TrackAppearanceFragment extends ContextMenuFragment implements CardListener, ContextMenuFragmentListener {
@ -76,6 +77,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
private OsmandApplication app;
@Nullable
private GpxDataItem gpxDataItem;
private TrackDrawInfo trackDrawInfo;
private SelectedGpxFile selectedGpxFile;
@ -127,16 +129,28 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
Bundle arguments = getArguments();
if (savedInstanceState != null) {
trackDrawInfo = new TrackDrawInfo();
trackDrawInfo.readBundle(savedInstanceState);
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
trackDrawInfo = new TrackDrawInfo(savedInstanceState);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath());
if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
}
} else if (arguments != null) {
String gpxFilePath = arguments.getString(TRACK_FILE_PATH);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
File file = new File(selectedGpxFile.getGpxFile().path);
gpxDataItem = app.getGpxDbHelper().getItem(file);
trackDrawInfo = new TrackDrawInfo(gpxDataItem);
String gpxFilePath = arguments.getString(TRACK_FILE_NAME);
boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false);
if (gpxFilePath == null && !currentRecording) {
log.error("Required extra '" + TRACK_FILE_NAME + "' is missing");
dismiss();
return;
}
if (currentRecording) {
trackDrawInfo = new TrackDrawInfo(true);
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath));
trackDrawInfo = new TrackDrawInfo(gpxDataItem, false);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
}
updateTrackColor();
}
}
@ -486,7 +500,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
discardChanges();
discardSplitChanges();
FragmentActivity activity = getActivity();
if (activity != null) {
activity.onBackPressed();
@ -521,15 +535,21 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
gpxFile.setShowArrows(trackDrawInfo.isShowArrows());
gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish());
app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile);
gpxDataItem = new GpxDataItem(new File(gpxFile.path), gpxFile);
app.getGpxDbHelper().add(gpxDataItem);
saveGpx(gpxFile);
if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
} else {
if (gpxDataItem != null) {
gpxDataItem = new GpxDataItem(new File(gpxFile.path), gpxFile);
app.getGpxDbHelper().add(gpxDataItem);
}
app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile);
saveGpx(gpxFile);
}
}
private void discardChanges() {
if (gpxDataItem.getSplitType() != trackDrawInfo.getSplitType() || gpxDataItem.getSplitInterval() != trackDrawInfo.getSplitInterval()) {
private void discardSplitChanges() {
if (gpxDataItem != null && (gpxDataItem.getSplitType() != trackDrawInfo.getSplitType()
|| gpxDataItem.getSplitInterval() != trackDrawInfo.getSplitInterval())) {
int timeSplit = (int) gpxDataItem.getSplitInterval();
double distanceSplit = gpxDataItem.getSplitInterval();
@ -591,9 +611,11 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
ViewGroup cardsContainer = getCardsContainer();
cardsContainer.removeAllViews();
splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo);
splitIntervalCard.setListener(this);
cardsContainer.addView(splitIntervalCard.build(mapActivity));
if (!selectedGpxFile.isShowCurrentTrack()) {
splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo);
splitIntervalCard.setListener(this);
cardsContainer.addView(splitIntervalCard.build(mapActivity));
}
DirectionArrowsCard directionArrowsCard = new DirectionArrowsCard(mapActivity, trackDrawInfo);
directionArrowsCard.setListener(this);

View file

@ -7,9 +7,11 @@ import androidx.annotation.NonNull;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.util.Algorithms;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
public class TrackDrawInfo {
public static final String TRACK_FILE_PATH = "track_file_path";
private static final String TRACK_WIDTH = "track_width";
private static final String TRACK_GRADIENT_SCALE_TYPE = "track_gradient_scale_type";
private static final String TRACK_COLOR = "track_color";
@ -28,12 +30,17 @@ public class TrackDrawInfo {
private boolean joinSegments;
private boolean showArrows;
private boolean showStartFinish;
private boolean currentRecording;
public TrackDrawInfo() {
public TrackDrawInfo(boolean currentRecording) {
this.currentRecording = currentRecording;
}
public TrackDrawInfo(GpxDataItem gpxDataItem) {
public TrackDrawInfo(Bundle bundle) {
readBundle(bundle);
}
public TrackDrawInfo(GpxDataItem gpxDataItem, boolean currentRecording) {
filePath = gpxDataItem.getFile().getPath();
width = gpxDataItem.getWidth();
gradientScaleType = gpxDataItem.getGradientScaleType();
@ -43,6 +50,7 @@ public class TrackDrawInfo {
joinSegments = gpxDataItem.isJoinSegments();
showArrows = gpxDataItem.isShowArrows();
showStartFinish = gpxDataItem.isShowStartFinish();
this.currentRecording = currentRecording;
}
public String getFilePath() {
@ -105,8 +113,12 @@ public class TrackDrawInfo {
return showStartFinish;
}
protected void readBundle(@NonNull Bundle bundle) {
filePath = bundle.getString(TRACK_FILE_PATH);
public boolean isCurrentRecording() {
return currentRecording;
}
private void readBundle(@NonNull Bundle bundle) {
filePath = bundle.getString(TRACK_FILE_NAME);
width = bundle.getString(TRACK_WIDTH);
String gradientScaleTypeName = bundle.getString(TRACK_GRADIENT_SCALE_TYPE);
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
@ -118,10 +130,11 @@ public class TrackDrawInfo {
joinSegments = bundle.getBoolean(TRACK_JOIN_SEGMENTS);
showArrows = bundle.getBoolean(TRACK_SHOW_ARROWS);
showStartFinish = bundle.getBoolean(TRACK_SHOW_START_FINISH);
currentRecording = bundle.getBoolean(CURRENT_RECORDING);
}
protected void saveToBundle(@NonNull Bundle bundle) {
bundle.putString(TRACK_FILE_PATH, filePath);
bundle.putString(TRACK_FILE_NAME, filePath);
bundle.putString(TRACK_WIDTH, width);
bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType != null ? gradientScaleType.getTypeName() : "");
bundle.putInt(TRACK_COLOR, color);
@ -130,5 +143,6 @@ public class TrackDrawInfo {
bundle.putBoolean(TRACK_JOIN_SEGMENTS, joinSegments);
bundle.putBoolean(TRACK_SHOW_ARROWS, showArrows);
bundle.putBoolean(TRACK_SHOW_START_FINISH, showStartFinish);
bundle.putBoolean(CURRENT_RECORDING, currentRecording);
}
}

View file

@ -555,7 +555,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private boolean hasTrackDrawInfoForSelectedGpx(SelectedGpxFile selectedGpxFile) {
return trackDrawInfo != null && trackDrawInfo.getFilePath().equals(selectedGpxFile.getGpxFile().path);
return trackDrawInfo != null && (trackDrawInfo.isCurrentRecording() && selectedGpxFile.isShowCurrentTrack()
|| selectedGpxFile.getGpxFile().path.equals(trackDrawInfo.getFilePath()));
}
private void drawStartEndPoints(Canvas canvas, RotatedTileBox tileBox, WptPt start, WptPt end) {