EspressoCategoryUnitTest needs to set metricUnits.

This commit is contained in:
Dennis Guse
2021-06-16 07:32:04 +02:00
parent 71c385a1a9
commit e655762c72
4 changed files with 60 additions and 3 deletions
@@ -30,8 +30,7 @@ public class Startup extends Application {
// Set default values of preferences on first start.
SharedPreferences sharedPreferences = PreferencesUtils.resetPreferences(this, false);
if (PreferencesUtils.getString(sharedPreferences, this, R.string.stats_units_key, "").equals("")) {
String statsUnits = getString(Locale.US.equals(Locale.getDefault()) ? R.string.stats_units_imperial : R.string.stats_units_metric);
PreferencesUtils.setString(sharedPreferences, this, R.string.stats_units_key, statsUnits);
PreferencesUtils.setMetricUnits(sharedPreferences, this, !Locale.US.equals(Locale.getDefault()));
}
ActivityUtils.applyNightMode(sharedPreferences, this);
@@ -112,6 +112,16 @@ public class PreferencesUtils {
return STATS_UNIT.equals(getString(sharedPreferences, context, R.string.stats_units_key, STATS_UNIT));
}
public static void setMetricUnits(SharedPreferences sharedPreferences, Context context, boolean metricUnits) {
String unit;
if (metricUnits) {
unit = context.getString(R.string.stats_units_metric);
} else {
unit = context.getString(R.string.stats_units_imperial);
}
setString(sharedPreferences, context, R.string.stats_units_key, unit);
}
public static boolean isReportSpeed(SharedPreferences sharedPreferences, Context context, String category) {
final String STATS_RATE_DEFAULT = context.getString(R.string.stats_rate_default);
String currentStatsRate = getString(sharedPreferences, context, R.string.stats_rate_key, STATS_RATE_DEFAULT);