Settings: localize no heart rate sensor selected.

This commit is contained in:
Dennis Guse
2019-12-03 19:53:14 +01:00
parent e8c6801a32
commit 301a721329
3 changed files with 22 additions and 10 deletions
@@ -86,11 +86,11 @@ public class BluetoothRemoteSensorManager {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (bluetoothConnectionManager != null && PreferencesUtils.isKey(context, R.string.settings_sensor_bluetooth_heart_rate_key, key)) { if (bluetoothConnectionManager != null && PreferencesUtils.isKey(context, R.string.settings_sensor_bluetooth_heart_rate_key, key)) {
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context); if (PreferencesUtils.isBluetoothHeartRateSensorAddressDefault(context)) {
if (address.equals(PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT)) {
stop(); stop();
return; return;
} }
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context);
if (bluetoothConnectionManager.isSameBluetoothDevice(address)) { if (bluetoothConnectionManager.isSameBluetoothDevice(address)) {
return; return;
} }
@@ -145,12 +145,11 @@ public class BluetoothRemoteSensorManager {
return; return;
} }
// String address = PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT); if (PreferencesUtils.isBluetoothHeartRateSensorAddressDefault(context)) {
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context);
if (PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(address)) {
Log.w(TAG, "No bluetooth address."); Log.w(TAG, "No bluetooth address.");
return; return;
} }
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context);
Log.i(TAG, "Connecting to bluetooth address: " + address); Log.i(TAG, "Connecting to bluetooth address: " + address);
BluetoothDevice device; BluetoothDevice device;
@@ -24,6 +24,7 @@ import java.util.List;
import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.util.BluetoothUtils; import de.dennisguse.opentracks.util.BluetoothUtils;
import de.dennisguse.opentracks.util.PreferencesUtils;
/** /**
* Preference to select a discoverable Bluetooth LE device. * Preference to select a discoverable Bluetooth LE device.
@@ -33,6 +34,8 @@ public class BluetoothLePreference extends DialogPreference {
private final static String TAG = BluetoothLePreference.class.getSimpleName(); private final static String TAG = BluetoothLePreference.class.getSimpleName();
private final static int DEVICE_NONE_RESOURCEID = R.string.value_none;
public BluetoothLePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public BluetoothLePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
@@ -75,6 +78,10 @@ public class BluetoothLePreference extends DialogPreference {
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
if (getValue() == null || PreferencesUtils.isBluetoothHeartRateSensorAddressDefault(getContext(), getValue())) {
return getContext().getString(DEVICE_NONE_RESOURCEID);
}
return getValue(); return getValue();
} }
@@ -142,7 +149,7 @@ public class BluetoothLePreference extends DialogPreference {
} }
String deviceNone = getContext().getString(R.string.sensor_type_value_none); String deviceNone = getContext().getString(R.string.sensor_type_value_none);
listAdapter.add(getContext().getString(R.string.value_none), deviceNone); listAdapter.add(getContext().getString(DEVICE_NONE_RESOURCEID), deviceNone);
selectedEntryIndex = 0; selectedEntryIndex = 0;
BluetoothLePreference preference = (BluetoothLePreference) getPreference(); BluetoothLePreference preference = (BluetoothLePreference) getPreference();
@@ -32,8 +32,6 @@ import de.dennisguse.opentracks.R;
*/ */
public class PreferencesUtils { public class PreferencesUtils {
public static final String BLUETOOTH_SENSOR_DEFAULT = "";
private PreferencesUtils() { private PreferencesUtils() {
} }
@@ -251,12 +249,20 @@ public class PreferencesUtils {
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, RECORDING_TRACK_PAUSED); PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, RECORDING_TRACK_PAUSED);
} }
public static String getBluetoothHeartRateSensorAddressNone(Context context) {
return context.getString(R.string.sensor_type_value_none);
}
public static boolean isBluetoothHeartRateSensorAddressDefault(Context context) { public static boolean isBluetoothHeartRateSensorAddressDefault(Context context) {
return PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(getBluetoothHeartRateSensorAddress(context)); return getBluetoothHeartRateSensorAddressNone(context).equals(getBluetoothHeartRateSensorAddress(context));
}
public static boolean isBluetoothHeartRateSensorAddressDefault(Context context, String currentValue) {
return getBluetoothHeartRateSensorAddressNone(context).equals(currentValue);
} }
public static String getBluetoothHeartRateSensorAddress(Context context) { public static String getBluetoothHeartRateSensorAddress(Context context) {
return PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT); return PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, getBluetoothHeartRateSensorAddressNone(context));
} }
public static boolean shouldChartShowCadence(Context context) { public static boolean shouldChartShowCadence(Context context) {