From 6d5529918c6dac93e1bd47ea1848aeb0d25b8e74 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Tue, 9 Mar 2021 11:45:40 +0200 Subject: [PATCH] Fix after review --- .../src/main/java/net/osmand/util/Algorithms.java | 13 ++++++++----- OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 2 +- .../LongDescriptionStandardHeightItem.java | 12 ------------ .../osmand/plus/track/SplitIntervalBottomSheet.java | 7 +++++-- .../src/net/osmand/plus/track/TrackWidthCard.java | 4 +++- 5 files changed, 17 insertions(+), 21 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/LongDescriptionStandardHeightItem.java diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index 05da55a753..48adfce30f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -118,11 +118,14 @@ public class Algorithms { return def; } - public static String formatDoubleWithoutAdditionalZeros(double d) { - if(d == (long) d) - return String.format(Locale.US, "%d",(long)d); - else - return String.format("%s",d); + public static String formatDoubleWithoutExtraZeros(double d) { + return isInt(d) ? + String.format(Locale.US, "%d", (long) d) : + String.format("%s", d); + } + + public static boolean isInt(double d) { + return (d == Math.floor(d)) && !Double.isInfinite(d); } public static int parseIntSilently(String input, int def) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index d18309730e..ba821f411c 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -133,7 +133,7 @@ public class OsmAndFormatter { units = app.getString(R.string.int_min); intervalInUnits = (interval / 60f); } - return Algorithms.formatDoubleWithoutAdditionalZeros(intervalInUnits) + " " + units; + return Algorithms.formatDoubleWithoutExtraZeros(intervalInUnits) + " " + units; } public static String getFormattedDistanceInterval(OsmandApplication app, double interval) { diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/LongDescriptionStandardHeightItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/LongDescriptionStandardHeightItem.java deleted file mode 100644 index fa2b9808b9..0000000000 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/LongDescriptionStandardHeightItem.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.osmand.plus.base.bottomsheetmenu.simpleitems; - -import net.osmand.plus.R; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; - -public class LongDescriptionStandardHeightItem extends BottomSheetItemWithDescription { - - public LongDescriptionStandardHeightItem(CharSequence description) { - this.description = description; - this.layoutId =R.layout.bottom_sheet_item_description_long_without_min_height; - } -} diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index 57d38e2040..644df0db81 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -22,7 +22,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionStandardHeightItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.widgets.MultiStateToggleButton; @@ -96,7 +96,10 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.gpx_split_interval))); - items.add(new LongDescriptionStandardHeightItem(getString(R.string.gpx_split_interval_descr))); + items.add(new LongDescriptionItem.Builder() + .setDescription(getString(R.string.gpx_split_interval_descr)) + .setLayoutId(R.layout.bottom_sheet_item_description_long_without_min_height) + .create()); LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); View view = themedInflater.inflate(R.layout.track_split_interval, null); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java index a6bc058b6d..9e98414d34 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java @@ -179,7 +179,9 @@ public class TrackWidthCard extends BaseCard { private void scrollMenuToSelectedItem() { int position = widthAdapter.getItemPosition(selectedItem); - groupRecyclerView.scrollToPosition(position); + if (position != -1) { + groupRecyclerView.scrollToPosition(position); + } } private class GpxWidthAdapter extends RecyclerView.Adapter {