Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metric & Imperial #398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<item>12</item> <item>13</item> <item>14</item> <item>15</item>
</string-array>

<string-array name="p_units_ev">
<item>1</item> <item>2</item>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values "1" and "2" aren't useful. You can replace them with "metric" and "imperial" or completely remove the array and use getListItemIndex() to determine the configured value.

</string-array>
<string-array name="ages">
<item>@string/age_30</item>
<item>@string/age_2h</item>
Expand Down
7 changes: 7 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
<string name="p_ssid">SSID</string>
<string name="p_ssid_summary">Station type (1..15; 9=Mobile, 10=APRS-IS)</string>
<string name="p_ssid_entry">Enter the SSID for your station</string>
<string name="p_units_title">Distance Units</string>
<string name="p_units">Unit Preference</string>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This preference should go into the "Display and Notifications" section. It can be the first item in the category. Then it should be named "Distance Units" and the sub-string should be removed, as it will be replaced by the selected value anyway.

<string name="p_units_entry">Select Distance Unit</string>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've stopped adding distinct entry dialog titles, as every string needs to be translated into all languages, and the preference title ("Distance Units") can be re-used here.

<!-- array of station types (SSID) -->
<string-array name="p_ssid_e">
<item>(none) Primary Station</item>
Expand All @@ -172,6 +175,10 @@
<item>14: Freight vehicle</item>
<item>15: Generic additional station</item>
</string-array>
<string-array name="p_units_e">
<item>Metric</item>
<item>Imperial</item>
</string-array>
<string name="p_symbol">APRS symbol</string>
<string name="p_symbol_summary">Your symbol for map display</string>
<string name="p_symbol_overlay">Overlay:</string>
Expand Down
12 changes: 12 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
</PreferenceScreen>
</PreferenceCategory>

<PreferenceCategory
android:title="@string/p_units_title">

<de.duenndns.ListPreferenceWithValue
android:key="p.units"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key should be p_units for consistency with the other prefs in the main prefs screen.

android:title="@string/p_units"
android:entries="@array/p_units_e"
android:entryValues="@array/p_units_ev"
android:defaultValue="1"
android:dialogTitle="@string/p_units_entry" />

</PreferenceCategory>
<PreferenceCategory
android:title="@string/p__position">
<PreferenceScreen
Expand Down
4 changes: 4 additions & 0 deletions src/PrefsWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class PrefsWrapper(val context : Context) {
// wrap the "dumb" methods
def getString(key : String, defValue : String) = prefs.getString(key, defValue)
def getBoolean(key : String, defValue : Boolean) = prefs.getBoolean(key, defValue)

def isMetric(): Boolean = {
prefs.getString("p.units", "1") == "1" // "1" for metric, "2" for imperial
}

// safely read integers
def getStringInt(key : String, defValue : Int) = {
Expand Down
15 changes: 12 additions & 3 deletions src/StationListAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ class StationListAdapter(context : Context, prefs : PrefsWrapper,
val qrg_visible = if (qrg != null && qrg != "") View.VISIBLE else View.GONE
view.findViewById(R.id.station_qrg).asInstanceOf[View].setVisibility(qrg_visible)
val MCD = 1000000.0
android.location.Location.distanceBetween(my_lat/MCD, my_lon/MCD,
lat/MCD, lon/MCD, dist)
distage.setText("%1.1f km %s\n%s".format(dist(0)/1000.0, getBearing(dist(1)), age))
android.location.Location.distanceBetween(my_lat/MCD, my_lon/MCD, lat/MCD, lon/MCD, dist)

// Determine whether to use metric or imperial based on user preference
val isMetric = prefs.isMetric() // Assuming isMetric() returns true for metric, false for imperial
val distanceText: String = if (isMetric) {
val distanceInKm = dist(0) / 1000.0
"%1.1f km %s\n%s".format(distanceInKm, getBearing(dist(1)), age)
} else {
val distanceInMiles = dist(0) / 1000.0 * 0.621371
"%1.1f mi %s\n%s".format(distanceInMiles, getBearing(dist(1)), age)
}
distage.setText(distanceText)
view.findViewById(R.id.station_symbol).asInstanceOf[SymbolView].setSymbol(symbol)
super.bindView(view, context, cursor)
}
Expand Down