diff --git a/OsmAnd-telegram/res/drawable-hdpi/ic_action_ruler_unit.png b/OsmAnd-telegram/res/drawable-hdpi/ic_action_ruler_unit.png new file mode 100755 index 0000000000..4e6d0b951b Binary files /dev/null and b/OsmAnd-telegram/res/drawable-hdpi/ic_action_ruler_unit.png differ diff --git a/OsmAnd-telegram/res/drawable-hdpi/ic_action_speed.png b/OsmAnd-telegram/res/drawable-hdpi/ic_action_speed.png new file mode 100644 index 0000000000..3d5efa1f9f Binary files /dev/null and b/OsmAnd-telegram/res/drawable-hdpi/ic_action_speed.png differ diff --git a/OsmAnd-telegram/res/drawable-mdpi/ic_action_ruler_unit.png b/OsmAnd-telegram/res/drawable-mdpi/ic_action_ruler_unit.png new file mode 100755 index 0000000000..fe4ff58402 Binary files /dev/null and b/OsmAnd-telegram/res/drawable-mdpi/ic_action_ruler_unit.png differ diff --git a/OsmAnd-telegram/res/drawable-mdpi/ic_action_speed.png b/OsmAnd-telegram/res/drawable-mdpi/ic_action_speed.png new file mode 100644 index 0000000000..a6de19816e Binary files /dev/null and b/OsmAnd-telegram/res/drawable-mdpi/ic_action_speed.png differ diff --git a/OsmAnd-telegram/res/drawable-xhdpi/ic_action_ruler_unit.png b/OsmAnd-telegram/res/drawable-xhdpi/ic_action_ruler_unit.png new file mode 100755 index 0000000000..f719f6b7ce Binary files /dev/null and b/OsmAnd-telegram/res/drawable-xhdpi/ic_action_ruler_unit.png differ diff --git a/OsmAnd-telegram/res/drawable-xhdpi/ic_action_speed.png b/OsmAnd-telegram/res/drawable-xhdpi/ic_action_speed.png new file mode 100644 index 0000000000..aa69a709a5 Binary files /dev/null and b/OsmAnd-telegram/res/drawable-xhdpi/ic_action_speed.png differ diff --git a/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_ruler_unit.png b/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_ruler_unit.png new file mode 100755 index 0000000000..f7e4543506 Binary files /dev/null and b/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_ruler_unit.png differ diff --git a/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_speed.png b/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_speed.png new file mode 100644 index 0000000000..8231d72e64 Binary files /dev/null and b/OsmAnd-telegram/res/drawable-xxhdpi/ic_action_speed.png differ diff --git a/OsmAnd-telegram/res/drawable-xxxhdpi/ic_action_ruler_unit.png b/OsmAnd-telegram/res/drawable-xxxhdpi/ic_action_ruler_unit.png new file mode 100755 index 0000000000..2305e5f380 Binary files /dev/null and b/OsmAnd-telegram/res/drawable-xxxhdpi/ic_action_ruler_unit.png differ diff --git a/OsmAnd-telegram/res/layout/fragement_settings_dialog.xml b/OsmAnd-telegram/res/layout/fragement_settings_dialog.xml index 6b4af3e0e8..43c521ed2a 100644 --- a/OsmAnd-telegram/res/layout/fragement_settings_dialog.xml +++ b/OsmAnd-telegram/res/layout/fragement_settings_dialog.xml @@ -75,6 +75,35 @@ + + + + + + + + + + + Units & formats + Change what distance is measured in. + Units of length + Define unit of speed. + Unit of speed Saved messages End Start diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index ac68e16384..167564f20d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -142,6 +142,7 @@ class TelegramSettings(private val app: TelegramApplication) { val gpsAndLocPrefs = listOf(SendMyLocPref(), StaleLocPref(), LocHistoryPref(), ShareTypePref()) val gpxLoggingPrefs = listOf(MinLocationDistance(), MinLocationAccuracy(), MinLocationSpeed()) + val unitsAndFormatsPrefs = listOf(UnitsOfSpeed(), UnitsOfLength()) var batteryOptimisationAsked = false @@ -1054,6 +1055,36 @@ class TelegramSettings(private val app: TelegramApplication) { } } + inner class UnitsOfSpeed : NumericPref( + R.drawable.ic_action_speed, R.string.unit_of_speed_system, + R.string.unit_of_speed_system_descr, + emptyList() + ) { + + override fun getCurrentValue() = speedConstants.toShortString(app) + + override fun setCurrentValue(index: Int) { + speedConstants = SpeedConstants.values()[index] + } + + override fun getMenuItems() = SpeedConstants.values().map { it.toShortString(app) } + } + + inner class UnitsOfLength : NumericPref( + R.drawable.ic_action_ruler_unit, R.string.unit_of_length, + R.string.unit_of_length_descr, + emptyList() + ) { + + override fun getCurrentValue() = metricsConstants.toHumanString(app) + + override fun setCurrentValue(index: Int) { + metricsConstants = MetricsConstants.values()[index] + } + + override fun getMenuItems() = MetricsConstants.values().map { it.toHumanString(app) } + } + abstract inner class NumericPref( @DrawableRes val iconId: Int, @StringRes val titleId: Int, diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt index a20a5a14e2..1b7ffd2422 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/SettingsDialogFragment.kt @@ -66,6 +66,11 @@ class SettingsDialogFragment : BaseDialogFragment() { } } + container = mainView.findViewById(R.id.units_and_formats_container) + settings.unitsAndFormatsPrefs.forEach { + createNumericPref(inflater, container, it) + } + container = mainView.findViewById(R.id.gps_points_container) inflater.inflate(R.layout.item_with_descr_and_right_switch, container, false).apply { findViewById(R.id.icon).setImageDrawable(uiUtils.getThemedIcon(R.drawable.ic_action_connect)) @@ -291,7 +296,7 @@ class SettingsDialogFragment : BaseDialogFragment() { isModal = true anchorView = valueView setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList)) - height = if (menuList.size < 6) { + height = if (menuList.size <= 6) { ListPopupWindow.WRAP_CONTENT } else { AndroidUtils.getPopupMenuHeight(ctx)