Move two methods to OsmAndFormatter

This commit is contained in:
Vitaliy 2020-07-27 12:09:21 +03:00
parent 0ad4528041
commit 787fddb714
4 changed files with 22 additions and 24 deletions

View file

@ -119,6 +119,21 @@ public class OsmAndFormatter {
return DateUtils.formatDateTime(context, milliseconds, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
}
public static String getFormattedTimeInterval(OsmandApplication app, double interval) {
if (interval < 60) {
return interval + " " + app.getString(R.string.int_seconds);
} else if (interval % 60 == 0) {
return (interval / 60) + " " + app.getString(R.string.int_min);
} else {
return (interval / 60f) + " " + app.getString(R.string.int_min);
}
}
public static String getFormattedDistanceInterval(OsmandApplication app, double interval) {
double roundedDist = OsmAndFormatter.calculateRoundedDist(interval, app);
return OsmAndFormatter.getFormattedDistance((float) roundedDist, app);
}
public static double calculateRoundedDist(double distInMeters, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();

View file

@ -59,7 +59,6 @@ import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.SplitIntervalCard;
import net.osmand.plus.track.SplitTrackAsyncTask;
import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
@ -830,14 +829,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
if (model.size() > 0) {
if (distance) {
double dvalue = OsmAndFormatter.calculateRoundedDist(value, app);
options.add(SplitIntervalCard.getFormattedDistanceInterval(app, value));
options.add(OsmAndFormatter.getFormattedDistanceInterval(app, value));
distanceSplit.add(dvalue);
timeSplit.add(-1);
if (Math.abs(model.get(0).getSplitDistance() - dvalue) < 1) {
selectedSplitInterval = distanceSplit.size() - 1;
}
} else {
options.add(SplitIntervalCard.getFormattedTimeInterval(app, value));
options.add(OsmAndFormatter.getFormattedTimeInterval(app, value));
distanceSplit.add(-1d);
timeSplit.add(value);
if (model.get(0).getSplitTime() == value) {

View file

@ -188,7 +188,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
private void addDistanceOptionSplit(int value, @NonNull List<GpxDisplayGroup> displayGroups) {
if (displayGroups.size() > 0) {
double dvalue = OsmAndFormatter.calculateRoundedDist(value, app);
String formattedDist = SplitIntervalCard.getFormattedDistanceInterval(app, value);
String formattedDist = OsmAndFormatter.getFormattedDistanceInterval(app, value);
distanceSplitOptions.put(formattedDist, dvalue);
if (Math.abs(displayGroups.get(0).getSplitDistance() - dvalue) < 1) {
selectedDistanceSplitInterval = distanceSplitOptions.size() - 1;
@ -198,7 +198,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment {
private void addTimeOptionSplit(int value, @NonNull List<GpxDisplayGroup> model) {
if (model.size() > 0) {
String time = SplitIntervalCard.getFormattedTimeInterval(app, value);
String time = OsmAndFormatter.getFormattedTimeInterval(app, value);
timeSplitOptions.put(time, value);
if (model.get(0).getSplitTime() == value) {
selectedTimeSplitInterval = timeSplitOptions.size() - 1;

View file

@ -11,7 +11,6 @@ import androidx.annotation.NonNull;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -68,25 +67,10 @@ public class SplitIntervalCard extends BaseCard {
if (splitInterval == 0) {
intervalStr = GpxSplitType.NO_SPLIT.getHumanString(app);
} else if (trackDrawInfo.getSplitType() == GpxSplitType.DISTANCE.getType()) {
intervalStr = getFormattedDistanceInterval(app, trackDrawInfo.getSplitInterval());
intervalStr = OsmAndFormatter.getFormattedDistanceInterval(app, trackDrawInfo.getSplitInterval());
} else if (trackDrawInfo.getSplitType() == GpxSplitType.TIME.getType()) {
intervalStr = getFormattedTimeInterval(app, splitInterval);
intervalStr = OsmAndFormatter.getFormattedTimeInterval(app, splitInterval);
}
return intervalStr;
}
public static String getFormattedTimeInterval(OsmandApplication app, double interval) {
if (interval < 60) {
return interval + " " + app.getString(R.string.int_seconds);
} else if (interval % 60 == 0) {
return (interval / 60) + " " + app.getString(R.string.int_min);
} else {
return (interval / 60f) + " " + app.getString(R.string.int_min);
}
}
public static String getFormattedDistanceInterval(OsmandApplication app, double interval) {
double roundedDist = OsmAndFormatter.calculateRoundedDist(interval, app);
return OsmAndFormatter.getFormattedDistance((float) roundedDist, app);
}
}