Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #208 from rilling/187-update-default-units-in-sett…
Browse files Browse the repository at this point in the history
…ings_Group_8_C2

187 update default units in settings group 8 c2
  • Loading branch information
VarunAggarwal1998 authored Nov 17, 2023
2 parents 59abe98 + e33bec8 commit d8d4f9c
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ public static void applyDefaultUnit() {
}
}

public static WeightUnit getWeightUnit() {
final String WEIGHT_UNIT_DEFAULT = resources.getString(R.string.weight_unit_default);

final String VALUE = getString(R.string.weight_unit_key, WEIGHT_UNIT_DEFAULT);
return Arrays.stream(WeightUnit.values())
.filter(d -> VALUE.equals(resources.getString(d.getPreferenceId(), WEIGHT_UNIT_DEFAULT)))
.findFirst()
.orElse(WeightUnit.defaultWeightUnit());
}

public static void setWeightUnit(WeightUnit weightUnit) {
setString(R.string.weight_unit_key, weightUnit.getPreferenceId());
}

public static TemperatureUnit getTemperatureUnit() {
final String TEMPERATURE_UNIT_DEFAULT = resources.getString(R.string.temperature_unit_default);

final String VALUE = getString(R.string.temperature_unit_key, TEMPERATURE_UNIT_DEFAULT);
return Arrays.stream(TemperatureUnit.values())
.filter(d -> VALUE.equals(resources.getString(d.getPreferenceId(), TEMPERATURE_UNIT_DEFAULT)))
.findFirst()
.orElse(TemperatureUnit.defaultTemperatureUnit());
}

public static void setTemperatureUnit(TemperatureUnit temperatureUnit) {
setString(R.string.temperature_unit_key, temperatureUnit.getPreferenceId());
}
public static boolean isReportSpeed(String activityTypeLocalized) {
final String STATS_RATE_DEFAULT = resources.getString(R.string.stats_rate_default);
String currentStatsRate = getString(R.string.stats_rate_key, STATS_RATE_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.dennisguse.opentracks.settings;

import de.dennisguse.opentracks.R;

public enum TemperatureUnit {
CELSIUS(R.string.unit_celsius),
FAHRENHEIT(R.string.unit_fahrenheit);

private final int preferenceIdentifier;

TemperatureUnit(int preferenceIdentifier) {
this.preferenceIdentifier = preferenceIdentifier;
}

public int getPreferenceId() {
return preferenceIdentifier;
}

// If you need a default value, you can define it here
public static TemperatureUnit defaultTemperatureUnit() {
return CELSIUS;
}
}
23 changes: 23 additions & 0 deletions src/main/java/de/dennisguse/opentracks/settings/WeightUnit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.dennisguse.opentracks.settings;

import de.dennisguse.opentracks.R;

public enum WeightUnit {
POUND(R.string.unit_pound),
KILOGRAM(R.string.unit_kilogram);

private final int preferenceIdentifier;

WeightUnit(int preferenceIdentifier) {
this.preferenceIdentifier = preferenceIdentifier;
}

public int getPreferenceId() {
return preferenceIdentifier;
}

// If you need a default value, you can define it here
public static WeightUnit defaultWeightUnit() {
return KILOGRAM;
}
}
29 changes: 29 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,35 @@
<item>@string/settings_stats_units_nautical</item>
</string-array>

<!-- Weight Preference -->
<string name="weight_unit_key" translatable="false">weightUnit</string>
<string name="weight_unit_default" translatable="false">@string/unit_kilogram</string>
<string-array name="weight_unit_values">
<item>@string/unit_kilogram</item>
<item>@string/unit_pound</item>

</string-array>
<string-array name="weight_unit_options">
<item>@string/unit_kilogram</item>
<item>@string/unit_pound</item>

</string-array>

<!-- Temperature Preference -->
<string name="temperature_unit_key" translatable="false">temperatureUnit</string>
<string name="temperature_unit_default" translatable="false">@string/unit_celsius</string>
<string-array name="temperature_unit_values">
<item>@string/unit_celsius</item>
<item>@string/unit_fahrenheit</item>


</string-array>
<string-array name="temperature_unit_options">
<item>@string/unit_celsius</item>
<item>@string/unit_fahrenheit</item>


</string-array>
<string name="track_name_key" translatable="false">trackName</string>
<string name="track_name_default" translatable="false">@string/settings_recording_track_name_date_iso_8601_value</string>
<string name="settings_recording_track_name_date_iso_8601_value" translatable="false">DATE_ISO_8601</string>
Expand Down
9 changes: 9 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ limitations under the License.
<string name="unit_minute_per_kilometer">min/km</string>
<string name="unit_minute_per_mile">min/mi</string>
<string name="unit_minute_per_nautical_mile">min/NM</string>

<!-- Weight and Temperature Units -->
<string name="settings_weight_title">Preferred weight</string>
<string name="settings_temperature_title">Preferred Temperature</string>
<string name="unit_pound">Pound (lb)</string>
<string name="unit_kilogram">Kilogram (kg)</string>
<string name="unit_celsius">Celsius (°C)</string>
<string name="unit_fahrenheit">Fahrenheit (°F)</string>

<!-- Location Coordinates -->
<string name="location_coordinate">%1$s°</string>
<string name="location_latitude_longitude">%1$s, %2$s</string>
Expand Down
14 changes: 14 additions & 0 deletions src/main/res/xml/settings_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
android:key="@string/stats_rate_key"
android:title="@string/settings_stats_rate_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="@string/weight_unit_default"
android:entries="@array/weight_unit_options"
android:entryValues="@array/weight_unit_values"
android:key="@string/weight_unit_key"
android:title="@string/settings_weight_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="@string/temperature_unit_default"
android:entries="@array/temperature_unit_options"
android:entryValues="@array/temperature_unit_values"
android:key="@string/temperature_unit_key"
android:title="@string/settings_temperature_title"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_activity_defaults_category">
Expand Down

0 comments on commit d8d4f9c

Please sign in to comment.