Combo: clean up SP access.
This commit is contained in:
parent
76568cac38
commit
84622a30a0
|
@ -242,8 +242,8 @@ public class ComboFragment extends DaggerFragment {
|
|||
tempBasalText.setText(tbrStr);
|
||||
|
||||
// stats
|
||||
bolusCount.setText(String.valueOf(sp.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L)));
|
||||
tbrCount.setText(String.valueOf(sp.getLong(ComboPlugin.COMBO_TBRS_SET, 0L)));
|
||||
bolusCount.setText(String.valueOf(comboPlugin.getBolusesDelivered()));
|
||||
tbrCount.setText(String.valueOf(comboPlugin.getTbrsSet()));
|
||||
serialNumber.setText(comboPlugin.serialNumber());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,11 +73,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
|||
*/
|
||||
@Singleton
|
||||
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
|
||||
private final ProfileFunction profileFunction;
|
||||
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
|
||||
String macAddress = ruffyScripter.getMacAddress();
|
||||
getAapsLogger().debug("Connected pump has MAC address: " + macAddress);
|
||||
if (macAddress != null) {
|
||||
String lastKnownSN = serialNumber();
|
||||
if (!lastKnownSN.equals(fakeSerialNumber()) && !lastKnownSN.equals(macAddress)) {
|
||||
getAapsLogger().info(LTag.PUMP, "Pump serial number changed " + lastKnownSN + " -> " + macAddress);
|
||||
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,
|
||||
|
@ -633,7 +629,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
|
|||
|
||||
private void incrementTbrCount() {
|
||||
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) {
|
||||
// ignore
|
||||
}
|
||||
|
@ -641,12 +637,20 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
|
|||
|
||||
private void incrementBolusCount() {
|
||||
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) {
|
||||
// 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.
|
||||
*/
|
||||
|
@ -1323,7 +1327,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
|
|||
|
||||
@NonNull @Override
|
||||
public String serialNumber() {
|
||||
return sp.getString(COMBO_PUMP_SERIAL, fakeSerialNumber());
|
||||
return sp.getString(R.string.combo_pump_serial, fakeSerialNumber());
|
||||
}
|
||||
|
||||
private String fakeSerialNumber() {
|
||||
|
|
|
@ -55,4 +55,7 @@
|
|||
<string name="bolusstopped">Bolus stopped</string>
|
||||
<string name="bolusstopping">Stopping bolus</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>
|
Loading…
Reference in a new issue