From 5b08660b5e9830e6d3914ecb4367ee975e90fb6f Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Tue, 9 Mar 2021 15:10:10 +0200 Subject: [PATCH] Fix after review part 2 --- .../main/java/net/osmand/util/Algorithms.java | 14 ++++---------- ...item_description_long_without_min_height.xml | 17 ----------------- OsmAnd/res/layout/track_split_interval.xml | 14 ++++++++++++++ OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 13 ++++++++----- .../src/net/osmand/plus/track/ColorsCard.java | 12 ++++-------- .../plus/track/SplitIntervalBottomSheet.java | 4 ---- 6 files changed, 30 insertions(+), 44 deletions(-) delete mode 100644 OsmAnd/res/layout/bottom_sheet_item_description_long_without_min_height.xml 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 3fd3bf6763..7aa4389f67 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -119,16 +119,6 @@ public class Algorithms { return def; } - 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) { if (input != null && input.length() > 0) { try { @@ -798,6 +788,10 @@ public class Algorithms { return false; } + public static boolean isInt(double d) { + return (d == Math.floor(d)) && !Double.isInfinite(d); + } + public static boolean isInt(String value) { int length = value.length(); for (int i = 0; i < length; i++) { diff --git a/OsmAnd/res/layout/bottom_sheet_item_description_long_without_min_height.xml b/OsmAnd/res/layout/bottom_sheet_item_description_long_without_min_height.xml deleted file mode 100644 index 9fe963d78f..0000000000 --- a/OsmAnd/res/layout/bottom_sheet_item_description_long_without_min_height.xml +++ /dev/null @@ -1,17 +0,0 @@ - - diff --git a/OsmAnd/res/layout/track_split_interval.xml b/OsmAnd/res/layout/track_split_interval.xml index 7751d35e0f..2fdcfc467c 100644 --- a/OsmAnd/res/layout/track_split_interval.xml +++ b/OsmAnd/res/layout/track_split_interval.xml @@ -5,6 +5,20 @@ android:layout_height="match_parent" android:orientation="vertical"> + + diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index ba821f411c..883cc908c5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -121,19 +121,22 @@ public class OsmAndFormatter { } public static String getFormattedTimeInterval(OsmandApplication app, double interval) { - String units; + String unitsStr; double intervalInUnits; if (interval < 60) { - units = app.getString(R.string.shared_string_sec); + unitsStr = app.getString(R.string.shared_string_sec); intervalInUnits = interval; } else if (interval % 60 == 0) { - units = app.getString(R.string.int_min); + unitsStr = app.getString(R.string.int_min); intervalInUnits = (interval / 60); } else { - units = app.getString(R.string.int_min); + unitsStr = app.getString(R.string.int_min); intervalInUnits = (interval / 60f); } - return Algorithms.formatDoubleWithoutExtraZeros(intervalInUnits) + " " + units; + String formattedInterval = Algorithms.isInt(intervalInUnits) ? + String.format(Locale.US, "%d", (long) intervalInUnits) : + String.format("%s", intervalInUnits); + return formattedInterval + " " + unitsStr; } public static String getFormattedDistanceInterval(OsmandApplication app, double interval) { diff --git a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java index 0ee0885f61..e6da7e736f 100644 --- a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java @@ -145,7 +145,10 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { Drawable transparencyIcon = getTransparencyIcon(app, color); Drawable colorIcon = app.getUIUtilities().getPaintedIcon(R.drawable.bg_point_circle, color); Drawable layeredIcon = UiUtilities.getLayeredIcon(transparencyIcon, colorIcon); - int listBgColor = ContextCompat.getColor(app, getListBackgroundColorId()); + int listBgColorId = nightMode ? + R.color.card_and_list_background_dark : + R.color.card_and_list_background_light; + int listBgColor = getResolvedColor(listBgColorId); double contrastRatio = ColorUtils.calculateContrast(color, listBgColor); if (contrastRatio < MINIMUM_CONTRAST_RATIO) { backgroundCircle.setBackgroundResource(nightMode ? R.drawable.circle_contour_bg_dark : R.drawable.circle_contour_bg_light); @@ -267,11 +270,4 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { colorsListPreference.setStringsListForProfile(appMode, colorNames); } } - - @ColorRes - private int getListBackgroundColorId() { - return nightMode ? - R.color.card_and_list_background_dark : - R.color.card_and_list_background_light; - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index 644df0db81..7d36e90b27 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -96,10 +96,6 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { @Override public void createMenuItems(Bundle savedInstanceState) { items.add(new TitleItem(getString(R.string.gpx_split_interval))); - 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);