Add units and formats preferences to ui

This commit is contained in:
Chumva 2019-12-05 18:55:34 +02:00
parent d6b8bf666c
commit c54dc6c526
13 changed files with 71 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

View file

@ -75,6 +75,35 @@
<include layout="@layout/list_item_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_bg_color"
android:orientation="vertical">
<net.osmand.telegram.ui.views.TextViewEx
android:layout_width="match_parent"
android:layout_height="@dimen/list_header_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
android:text="@string/units_and_formats"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/list_item_title_text_size"
app:typeface="@string/font_roboto_medium"/>
<LinearLayout
android:id="@+id/units_and_formats_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
<include layout="@layout/list_item_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="units_and_formats">Units &amp; formats</string>
<string name="unit_of_length_descr">Change what distance is measured in.</string>
<string name="unit_of_length">Units of length</string>
<string name="unit_of_speed_system_descr">Define unit of speed.</string>
<string name="unit_of_speed_system">Unit of speed</string>
<string name="saved_messages">Saved messages</string>
<string name="shared_string_end">End</string>
<string name="shared_string_start">Start</string>

View file

@ -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,

View file

@ -66,6 +66,11 @@ class SettingsDialogFragment : BaseDialogFragment() {
}
}
container = mainView.findViewById<ViewGroup>(R.id.units_and_formats_container)
settings.unitsAndFormatsPrefs.forEach {
createNumericPref(inflater, container, it)
}
container = mainView.findViewById<ViewGroup>(R.id.gps_points_container)
inflater.inflate(R.layout.item_with_descr_and_right_switch, container, false).apply {
findViewById<ImageView>(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)