Skip to content

Commit 01cbb17

Browse files
committed
fix: preferences that are enums can be set either by integer or case-insensitive string
fixes #1874
1 parent 5925ce3 commit 01cbb17

File tree

34 files changed

+134
-123
lines changed

34 files changed

+134
-123
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
- Try to not block the main thread when generating an Status Message, which causes an ANR
1515
- Messages that fail to send because the endpoint isn't ready now retry every 10 seconds, not every second
1616
- Import config screen displays JSON config LTR under RTL locales
17+
- setting / importing configuration options that are enums are now case-insensitive
18+
- Fix regression where setting the locatorPriority preference using a number wasn't working (#1874)
1719

1820
## Version 2.5.3
1921

project/app/src/androidTest/java/org/owntracks/android/mqtt/MQTTMessagePublishTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class MQTTMessagePublishTests :
196196
private fun setupTestActivity() {
197197
PreferenceManager.getDefaultSharedPreferences(app)
198198
.edit()
199-
.putInt(Preferences::monitoring.name, MonitoringMode.QUIET.value)
199+
.putInt(Preferences::monitoring.name, MonitoringMode.Quiet.value)
200200
.putString(Preferences::reverseGeocodeProvider.name, "None")
201201
.apply()
202202
setNotFirstStartPreferences()

project/app/src/androidTest/java/org/owntracks/android/ui/ClickOnPreference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
99
import com.adevinta.android.barista.interaction.BaristaSleepInteractions.sleep
1010
import org.hamcrest.Matchers.allOf
1111

12-
private const val SLEEP_MILLIS = 100L
12+
private const val SLEEP_MILLIS = 10L
1313

1414
fun clickOnDrawerAndWait(text: Int) {
1515
Espresso.onView(

project/app/src/androidTest/java/org/owntracks/android/ui/ContactsActivityTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ContactsActivityTests :
4343
setNotFirstStartPreferences()
4444
getPreferences()
4545
.edit()
46-
.putInt(Preferences::monitoring.name, MonitoringMode.QUIET.value)
46+
.putInt(Preferences::monitoring.name, MonitoringMode.Quiet.value)
4747
.putString(Preferences::reverseGeocodeProvider.name, "None")
4848
.apply()
4949
launchActivity()

project/app/src/androidTest/java/org/owntracks/android/ui/PreferencesActivityTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class PreferencesActivityTests :
190190
val expected =
191191
baristaRule.activityTestRule.activity.resources.run {
192192
getStringArray(R.array.geocoders)[
193-
getStringArray(R.array.geocoderValues).indexOfFirst { it == defaultGeocoder.value }]
193+
getStringArray(R.array.geocoderValues).indexOfFirst { it == defaultGeocoder.name }]
194194
}
195195
assertContains(android.R.id.summary, expected)
196196
}

project/app/src/gms/java/org/owntracks/android/preferences/DefaultsProviderImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DefaultsProviderImpl : DefaultsProvider {
99
override fun <T> getDefaultValue(preferences: Preferences, property: KProperty<*>): T {
1010
return when (property) {
1111
Preferences::mapLayerStyle -> MapLayerStyle.GoogleMapDefault
12-
Preferences::reverseGeocodeProvider -> ReverseGeocodeProvider.DEVICE
12+
Preferences::reverseGeocodeProvider -> ReverseGeocodeProvider.Device
1313
else -> super.getDefaultValue<T>(preferences, property)
1414
}
1515
as T

project/app/src/gms/java/org/owntracks/android/ui/map/MapLayerStyle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum class MapLayerStyle {
3434
@JvmStatic
3535
@FromConfiguration
3636
fun getByValue(value: String): MapLayerStyle =
37-
entries.firstOrNull { it.name == value } ?: GoogleMapDefault
37+
entries.firstOrNull { it.name.equals(value, true) } ?: GoogleMapDefault
3838
}
3939
}
4040

project/app/src/main/java/org/owntracks/android/App.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ class App :
193193
@MainThread
194194
private fun setThemeFromPreferences() {
195195
when (preferences.theme) {
196-
AppTheme.AUTO -> AppCompatDelegate.setDefaultNightMode(Preferences.SYSTEM_NIGHT_AUTO_MODE)
197-
AppTheme.DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
198-
AppTheme.LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
196+
AppTheme.Auto -> AppCompatDelegate.setDefaultNightMode(Preferences.SYSTEM_NIGHT_AUTO_MODE)
197+
AppTheme.Dark -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
198+
AppTheme.Light -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
199199
}
200200
}
201201

project/app/src/main/java/org/owntracks/android/geocoding/GeocoderProvider.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ constructor(
5151
withContext(ioDispatcher) {
5252
geocoder =
5353
when (preferences.reverseGeocodeProvider) {
54-
ReverseGeocodeProvider.OPENCAGE ->
54+
ReverseGeocodeProvider.OpenCage ->
5555
OpenCageGeocoder(preferences.opencageApiKey, httpClient)
56-
ReverseGeocodeProvider.DEVICE -> DeviceGeocoder(context)
57-
ReverseGeocodeProvider.NONE -> GeocoderNone()
56+
ReverseGeocodeProvider.Device -> DeviceGeocoder(context)
57+
ReverseGeocodeProvider.None -> GeocoderNone()
5858
}
5959
}
6060
}

project/app/src/main/java/org/owntracks/android/location/LocatorPriority.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@ package org.owntracks.android.location
22

33
import org.owntracks.android.preferences.types.FromConfiguration
44

5-
enum class LocatorPriority {
6-
HighAccuracy,
7-
BalancedPowerAccuracy,
8-
LowPower,
9-
NoPower;
5+
enum class LocatorPriority(private val value: Int) {
6+
HighAccuracy(3),
7+
BalancedPowerAccuracy(2),
8+
LowPower(1),
9+
NoPower(0);
1010

1111
companion object {
1212
@JvmStatic
1313
@FromConfiguration
14-
fun getByValue(value: String?): LocatorPriority? =
15-
LocatorPriority.entries.firstOrNull { it.name == value }
14+
fun getByValue(value: Int): LocatorPriority =
15+
LocatorPriority.entries.firstOrNull { it.value == value } ?: BalancedPowerAccuracy
16+
17+
@JvmStatic
18+
@FromConfiguration
19+
fun getByValue(value: String): LocatorPriority =
20+
value.toIntOrNull()?.run(::getByValue)
21+
?: entries.firstOrNull { it.name.equals(value, true) }
22+
?: BalancedPowerAccuracy
1623
}
1724
}

0 commit comments

Comments
 (0)