Merge branch 'dev' into dev2

This commit is contained in:
Milos Kozak 2017-11-20 17:28:15 +01:00
commit 973b9d50c1
16 changed files with 99 additions and 33 deletions

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps; package info.nightscout.androidaps;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
@ -23,7 +22,6 @@ import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
@ -46,7 +44,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
myPreferenceFragment = new MyPreferenceFragment(); myPreferenceFragment = new MyPreferenceFragment();
myPreferenceFragment.setCaller(getIntent()); Bundle args = new Bundle();
args.putInt("id", getIntent().getIntExtra("id", -1));
myPreferenceFragment.setArguments(args);
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit(); getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
} }
@ -70,7 +70,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
private static void updatePrefSummary(Preference pref) { private static void updatePrefSummary(Preference pref) {
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) { if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref; ListPreference listPref = (ListPreference) pref;
pref.setSummary(listPref.getEntry()); pref.setSummary(listPref.getEntry());
} }
@ -83,14 +83,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) { } else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
pref.setSummary(editTextPref.getText()); pref.setSummary(editTextPref.getText());
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())) { } else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary)); pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
} }
} }
if (pref instanceof MultiSelectListPreference) {
EditTextPreference editTextPref = (EditTextPreference) pref;
pref.setSummary(editTextPref.getText());
}
} }
public static void initSummary(Preference p) { public static void initSummary(Preference p) {
@ -105,10 +101,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
public static class MyPreferenceFragment extends PreferenceFragment { public static class MyPreferenceFragment extends PreferenceFragment {
Intent caller; private Integer id;
public void setCaller(Intent i) { @Override
caller = i; public void setArguments(Bundle args) {
super.setArguments(args);
id = args.getInt("id");
} }
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) { void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
@ -120,10 +118,13 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Integer id = caller.getIntExtra("id", -1); if (savedInstanceState != null && savedInstanceState.containsKey("id")) {
id = savedInstanceState.getInt("id");
}
if (id != -1) { if (id != -1) {
addPreferencesFromResource(id); addPreferencesFromResource(id);
addPreferencesFromResource(R.xml.pref_advanced);
} else { } else {
if (!Config.NSCLIENT) { if (!Config.NSCLIENT) {
addPreferencesFromResource(R.xml.pref_password); addPreferencesFromResource(R.xml.pref_password);
@ -183,6 +184,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
initSummary(getPreferenceScreen()); initSummary(getPreferenceScreen());
} }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("id", id);
}
public Preference getPreference(String key) { public Preference getPreference(String key) {
return findPreference(key); return findPreference(key);
} }

View file

@ -72,7 +72,10 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U "; name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
} }
if (isCPP) { if (isCPP) {
name += "(" + percentage + "%," + timeshift + "h)"; name += "(" + percentage + "%";
if (timeshift != 0)
name += "," + timeshift + "h";
name += ")";
} }
return name; return name;
} }

View file

@ -270,6 +270,23 @@ public class ConfigBuilderFragment extends Fragment {
}, null); }, null);
} }
}); });
holder.name.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final PluginBase plugin = (PluginBase) v.getTag();
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
@Override
public void run() {
Intent i = new Intent(getContext(), PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
startActivity(i);
}
}, null);
return false;
}
});
} else { } else {
holder = (PluginViewHolder) view.getTag(); holder = (PluginViewHolder) view.getTag();
} }

View file

@ -409,9 +409,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(Profile profile) {
if (activePump != null) if (activePump != null) {
return activePump.isThisProfileSet(profile); boolean result = activePump.isThisProfileSet(profile);
else return true; if (result == false) {
log.debug("Current profile: " + getProfile().getData().toString());
log.debug("New profile: " + profile.getData().toString());
}
} else return true;
} }
@Override @Override
@ -564,7 +568,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: " + request.toString()); log.debug("applyAPSRequest: " + request.toString());
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < 0.05) { if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < getPumpDescription().basalStep) {
if (isTempBasalInProgress()) { if (isTempBasalInProgress()) {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: cancelTempBasal()"); log.debug("applyAPSRequest: cancelTempBasal()");

View file

@ -336,7 +336,9 @@ public class NSDeviceStatus {
try { try {
long clock = 0L; long clock = 0L;
if (object.has("created_at")) if (object.has("mills"))
clock = object.getLong("mills");
else if (object.has("created_at"))
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime(); clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
String device = getDevice(); String device = getDevice();
Integer battery = null; Integer battery = null;

View file

@ -553,7 +553,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
insulin = configBuilderPlugin.applyBolusConstraints(insulin); insulin = configBuilderPlugin.applyBolusConstraints(insulin);
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1)); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());

View file

@ -550,7 +550,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
insulin = configBuilderPlugin.applyBolusConstraints(insulin); insulin = configBuilderPlugin.applyBolusConstraints(insulin);
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1)); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());

View file

@ -675,7 +675,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
insulin = configBuilderPlugin.applyBolusConstraints(insulin); insulin = configBuilderPlugin.applyBolusConstraints(insulin);
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1)); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {

View file

@ -33,14 +33,14 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
dataSize = 2; dataSize = 2;
pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d; pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
Date lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today pump.lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 1; dataSize = 1;
lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize))); pump.lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 1; dataSize = 1;
lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize))); pump.lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
dataIndex += dataSize; dataIndex += dataSize;
dataSize = 2; dataSize = 2;
@ -58,7 +58,7 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
log.debug("Result: " + error); log.debug("Result: " + error);
log.debug("BolusType: " + bolusType); log.debug("BolusType: " + bolusType);
log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U"); log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U");
log.debug("Last bolus time: " + lastBolusTime.toLocaleString()); log.debug("Last bolus time: " + pump.lastBolusTime.toLocaleString());
log.debug("Last bolus amount: " + pump.lastBolusAmount); log.debug("Last bolus amount: " + pump.lastBolusAmount);
log.debug("Max bolus: " + pump.maxBolus + " U"); log.debug("Max bolus: " + pump.maxBolus + " U");
log.debug("Bolus step: " + pump.bolusStep + " U"); log.debug("Bolus step: " + pump.bolusStep + " U");

View file

@ -42,7 +42,7 @@ public class DanaRS_Packet_Bolus_Set_Extended_Bolus extends DanaRS_Packet {
public void handleMessage(byte[] data) { public void handleMessage(byte[] data) {
int result = intFromBuff(data, 0, 1); int result = intFromBuff(data, 0, 1);
if (Config.logDanaMessageDetail) { if (Config.logDanaMessageDetail) {
if (result == 0) if (result != 0)
log.debug("Result OK"); log.debug("Result OK");
else else
log.error("Result Error: " + result); log.error("Result Error: " + result);

View file

@ -130,7 +130,7 @@ public class DanaRSService extends Service {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State()); bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus, bolusStep, maxBolus
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingtempbasalstatus))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingtempbasalstatus)));
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State()); bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
@ -141,7 +141,6 @@ public class DanaRSService extends Service {
bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number()); bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number());
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // bolusStep, maxBolus
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array()); bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array());

View file

@ -513,7 +513,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
insulin = configBuilderPlugin.applyBolusConstraints(insulin); insulin = configBuilderPlugin.applyBolusConstraints(insulin);
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1)); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {

View file

@ -27,8 +27,8 @@ public class DateUtil {
/** /**
* The date format in iso. * The date format in iso.
*/ */
private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ";
private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
/** /**
* Takes in an ISO date string of the following format: * Takes in an ISO date string of the following format:

View file

@ -663,4 +663,13 @@
<string name="bloodsugarmeasurementalert">Výstraha měření glykémie</string> <string name="bloodsugarmeasurementalert">Výstraha měření glykémie</string>
<string name="connectiontimedout">Vypršel čas připojování</string> <string name="connectiontimedout">Vypršel čas připojování</string>
<string name="treatments_wizard_tt_label">DC</string> <string name="treatments_wizard_tt_label">DC</string>
<string name="free_peak_oref">Volitelný vrchol - Oref</string>
<string name="nsclientinternal_secret_dialogtitle">NS heslo</string>
<string name="nsclientinternal_secret_title">NS heslo (API secret)</string>
<string name="processinghistory">Zpracovávám</string>
<string name="rapid_acting_oref">Rychle působící - Oref</string>
<string name="startingbolus">Spouštím bolus</string>
<string name="ultrafastactinginsulincomment">Fiasp</string>
<string name="ultrarapid_oref">Ultra rychlý - Oref</string>
<string name="waitingforestimatedbolusend" formatted="false">Čekání na konec bolusu. Zbývá %d sek.</string>
</resources> </resources>

View file

@ -754,7 +754,7 @@
<string name="shortprotein">Pr</string> <string name="shortprotein">Pr</string>
<string name="shortfat">Fat</string> <string name="shortfat">Fat</string>
<string name="active"><![CDATA[<Active>]]></string> <string name="active"><![CDATA[<Active>]]></string>
<string name="waitingforestimatedbolusend" formatted="false">Waiting for estimated bolus end. Remaining %d sec.</string> <string name="waitingforestimatedbolusend" formatted="false">Waiting for bolus end. Remaining %d sec.</string>
<string name="processinghistory">Processing event</string> <string name="processinghistory">Processing event</string>
<string name="startingbolus">Starting bolus delivery</string> <string name="startingbolus">Starting bolus delivery</string>
</resources> </resources>

View file

@ -0,0 +1,25 @@
package info.nightscout.utils;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by mike on 20.11.2017.
*/
public class DateUtilTest {
public DateUtilTest() {
super();
}
@Test
public void fromISODateStringTest() throws Exception {
assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
assertEquals( 1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime());
}
}