Combo: clean up SP access.

This commit is contained in:
Johannes Mockenhaupt 2021-04-29 21:22:36 +02:00
parent 76568cac38
commit 84622a30a0
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 18 additions and 11 deletions

View file

@ -242,8 +242,8 @@ public class ComboFragment extends DaggerFragment {
tempBasalText.setText(tbrStr); tempBasalText.setText(tbrStr);
// stats // stats
bolusCount.setText(String.valueOf(sp.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L))); bolusCount.setText(String.valueOf(comboPlugin.getBolusesDelivered()));
tbrCount.setText(String.valueOf(sp.getLong(ComboPlugin.COMBO_TBRS_SET, 0L))); tbrCount.setText(String.valueOf(comboPlugin.getTbrsSet()));
serialNumber.setText(comboPlugin.serialNumber()); serialNumber.setText(comboPlugin.serialNumber());
} }
} }

View file

@ -73,11 +73,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/ */
@Singleton @Singleton
public class ComboPlugin extends PumpPluginBase implements Pump, Constraints { public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
// TODO clean up?
static final String COMBO_PUMP_SERIAL = "combo_pump_serial";
static final String COMBO_TBRS_SET = "combo_tbrs_set";
static final String COMBO_BOLUSES_DELIVERED = "combo_boluses_delivered";
// collaborators // collaborators
private final ProfileFunction profileFunction; private final ProfileFunction profileFunction;
private final SP sp; private final SP sp;
@ -408,13 +403,14 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
// read pump BT mac address and use it as the pump's serial // read pump BT mac address and use it as the pump's serial
String macAddress = ruffyScripter.getMacAddress(); String macAddress = ruffyScripter.getMacAddress();
getAapsLogger().debug("Connected pump has MAC address: " + macAddress);
if (macAddress != null) { if (macAddress != null) {
String lastKnownSN = serialNumber(); String lastKnownSN = serialNumber();
if (!lastKnownSN.equals(fakeSerialNumber()) && !lastKnownSN.equals(macAddress)) { if (!lastKnownSN.equals(fakeSerialNumber()) && !lastKnownSN.equals(macAddress)) {
getAapsLogger().info(LTag.PUMP, "Pump serial number changed " + lastKnownSN + " -> " + macAddress); getAapsLogger().info(LTag.PUMP, "Pump serial number changed " + lastKnownSN + " -> " + macAddress);
pumpSync.connectNewPump(); pumpSync.connectNewPump();
} }
sp.putString(COMBO_PUMP_SERIAL, macAddress); sp.putString(R.string.combo_pump_serial, macAddress);
} }
// ComboFragment updates state fully only after the pump has initialized, // ComboFragment updates state fully only after the pump has initialized,
@ -633,7 +629,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
private void incrementTbrCount() { private void incrementTbrCount() {
try { try {
sp.putLong(COMBO_TBRS_SET, sp.getLong(COMBO_TBRS_SET, 0L) + 1); sp.putLong(R.string.combo_tbrs_set, sp.getLong(R.string.combo_tbrs_set, 0L) + 1);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
@ -641,12 +637,20 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
private void incrementBolusCount() { private void incrementBolusCount() {
try { try {
sp.putLong(COMBO_BOLUSES_DELIVERED, sp.getLong(COMBO_BOLUSES_DELIVERED, 0L) + 1); sp.putLong(R.string.combo_boluses_delivered, sp.getLong(R.string.combo_boluses_delivered, 0L) + 1);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
} }
public Long getTbrsSet() {
return sp.getLong(R.string.combo_tbrs_set, 0L);
}
public Long getBolusesDelivered() {
return sp.getLong(R.string.combo_boluses_delivered, 0L);
}
/** /**
* Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. * Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus.
*/ */
@ -1323,7 +1327,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
@NonNull @Override @NonNull @Override
public String serialNumber() { public String serialNumber() {
return sp.getString(COMBO_PUMP_SERIAL, fakeSerialNumber()); return sp.getString(R.string.combo_pump_serial, fakeSerialNumber());
} }
private String fakeSerialNumber() { private String fakeSerialNumber() {

View file

@ -55,4 +55,7 @@
<string name="bolusstopped">Bolus stopped</string> <string name="bolusstopped">Bolus stopped</string>
<string name="bolusstopping">Stopping bolus</string> <string name="bolusstopping">Stopping bolus</string>
<string name="combo_serial_number">Pump identifier</string> <string name="combo_serial_number">Pump identifier</string>
<string name="combo_pump_serial" translatable="false">combo_pump_serial</string>
<string name="combo_tbrs_set" translatable="false">combo_tbrs_set</string>
<string name="combo_boluses_delivered" translatable="false">combo_boluses_delivered</string>
</resources> </resources>