Merge pull request #2225 from MilosKozak/localprofile
Localprofile improvement, global units
This commit is contained in:
commit
a15f985794
|
@ -249,37 +249,20 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
private void doMigrations() {
|
private void doMigrations() {
|
||||||
|
|
||||||
checkUpgradeToProfileTarget();
|
|
||||||
|
|
||||||
// guarantee that the unreachable threshold is at least 30 and of type String
|
// guarantee that the unreachable threshold is at least 30 and of type String
|
||||||
// Added in 1.57 at 21.01.2018
|
// Added in 1.57 at 21.01.2018
|
||||||
int unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30);
|
int unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30);
|
||||||
SP.remove(R.string.key_pump_unreachable_threshold);
|
SP.remove(R.string.key_pump_unreachable_threshold);
|
||||||
if (unreachable_threshold < 30) unreachable_threshold = 30;
|
if (unreachable_threshold < 30) unreachable_threshold = 30;
|
||||||
SP.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold));
|
SP.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold));
|
||||||
|
|
||||||
|
if (!SP.contains(R.string.key_units)) {
|
||||||
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkUpgradeToProfileTarget() { // TODO: can be removed in the future
|
|
||||||
boolean oldKeyExists = SP.contains("openapsma_min_bg");
|
|
||||||
if (oldKeyExists) {
|
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
String oldRange = SP.getDouble("openapsma_min_bg", 0d) + " - " + SP.getDouble("openapsma_max_bg", 0d);
|
|
||||||
String newRange = "";
|
|
||||||
if (profile != null) {
|
|
||||||
newRange = profile.getTargetLow() + " - " + profile.getTargetHigh();
|
|
||||||
}
|
|
||||||
String message = "Target range is changed in current version.\n\nIt's not taken from preferences but from profile.\n\n!!! REVIEW YOUR SETTINGS !!!";
|
|
||||||
message += "\n\nOld settings: " + oldRange;
|
|
||||||
message += "\nProfile settings: " + newRange;
|
|
||||||
OKDialog.show(this, "Target range change", message, () -> {
|
|
||||||
SP.remove("openapsma_min_bg");
|
|
||||||
SP.remove("openapsma_max_bg");
|
|
||||||
SP.remove("openapsma_target_bg");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
|
@ -59,7 +59,6 @@ import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlu
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
|
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
|
||||||
|
@ -195,8 +194,7 @@ public class MainApp extends Application {
|
||||||
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||||
pluginsList.add(NSProfilePlugin.getPlugin());
|
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.INSTANCE);
|
||||||
if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.getPlugin());
|
|
||||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin());
|
if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE);
|
if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE);
|
||||||
|
|
|
@ -231,9 +231,8 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
noProfile.setVisibility(View.GONE);
|
noProfile.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String units = profile.getUnits();
|
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
|
||||||
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
final double highLine = OverviewPlugin.INSTANCE.determineHighLine();
|
||||||
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
|
||||||
|
|
||||||
buttonDate.setText(DateUtil.dateAndTimeString(start));
|
buttonDate.setText(DateUtil.dateAndTimeString(start));
|
||||||
buttonZoom.setText(String.valueOf(rangeToDisplay));
|
buttonZoom.setText(String.valueOf(rangeToDisplay));
|
||||||
|
|
|
@ -10,9 +10,12 @@ import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRebuildTabs;
|
import info.nightscout.androidaps.events.EventRebuildTabs;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -46,6 +49,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAverage
|
||||||
import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin;
|
import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin;
|
||||||
import info.nightscout.androidaps.utils.OKDialog;
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
|
|
||||||
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
MyPreferenceFragment myPreferenceFragment;
|
MyPreferenceFragment myPreferenceFragment;
|
||||||
|
@ -65,20 +69,41 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
||||||
if (key.equals("language")) {
|
if (key.equals(MainApp.gs(R.string.key_language))) {
|
||||||
RxBus.INSTANCE.send(new EventRebuildTabs(true));
|
RxBus.INSTANCE.send(new EventRebuildTabs(true));
|
||||||
//recreate() does not update language so better close settings
|
//recreate() does not update language so better close settings
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
if (key.equals("short_tabtitles")) {
|
if (key.equals(MainApp.gs(R.string.key_short_tabtitles))) {
|
||||||
RxBus.INSTANCE.send(new EventRebuildTabs());
|
RxBus.INSTANCE.send(new EventRebuildTabs());
|
||||||
}
|
}
|
||||||
|
if (key.equals(MainApp.gs(R.string.key_units))) {
|
||||||
|
recreate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
||||||
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
|
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
|
||||||
}
|
}
|
||||||
updatePrefSummary(myPreferenceFragment.findPreference(key));
|
updatePrefSummary(myPreferenceFragment.findPreference(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void adjustUnitDependentPrefs(Preference pref) {
|
||||||
|
// convert preferences values to current units
|
||||||
|
String[] unitDependent = new String[]{
|
||||||
|
MainApp.gs(R.string.key_hypo_target),
|
||||||
|
MainApp.gs(R.string.key_activity_target),
|
||||||
|
MainApp.gs(R.string.key_eatingsoon_target),
|
||||||
|
MainApp.gs(R.string.key_high_mark),
|
||||||
|
MainApp.gs(R.string.key_low_mark)
|
||||||
|
};
|
||||||
|
if (Arrays.asList(unitDependent).contains(pref.getKey())) {
|
||||||
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
||||||
|
String converted = Profile.toCurrentUnitsString(SafeParse.stringToDouble(editTextPref.getText()));
|
||||||
|
editTextPref.setSummary(converted);
|
||||||
|
editTextPref.setText(converted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void updatePrefSummary(Preference pref) {
|
private static void updatePrefSummary(Preference pref) {
|
||||||
if (pref instanceof ListPreference) {
|
if (pref instanceof ListPreference) {
|
||||||
ListPreference listPref = (ListPreference) pref;
|
ListPreference listPref = (ListPreference) pref;
|
||||||
|
@ -97,6 +122,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
adjustUnitDependentPrefs(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initSummary(Preference p) {
|
public static void initSummary(Preference p) {
|
||||||
|
@ -139,8 +165,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
if (!Config.NSCLIENT) {
|
if (!Config.NSCLIENT) {
|
||||||
addPreferencesFromResource(R.xml.pref_password);
|
addPreferencesFromResource(R.xml.pref_password);
|
||||||
}
|
}
|
||||||
|
addPreferencesFromResource(R.xml.pref_general);
|
||||||
addPreferencesFromResource(R.xml.pref_age);
|
addPreferencesFromResource(R.xml.pref_age);
|
||||||
addPreferencesFromResource(R.xml.pref_language);
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.pref_overview);
|
addPreferencesFromResource(R.xml.pref_overview);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
@ -75,6 +76,11 @@ public class Profile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constructor from profileStore JSON
|
||||||
|
public Profile(JSONObject json) {
|
||||||
|
init(json, 100, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public Profile(JSONObject json, int percentage, int timeshift) {
|
public Profile(JSONObject json, int percentage, int timeshift) {
|
||||||
init(json, percentage, timeshift);
|
init(json, percentage, timeshift);
|
||||||
}
|
}
|
||||||
|
@ -100,8 +106,6 @@ public class Profile {
|
||||||
units = json.getString("units").toLowerCase();
|
units = json.getString("units").toLowerCase();
|
||||||
if (json.has("dia"))
|
if (json.has("dia"))
|
||||||
dia = json.getDouble("dia");
|
dia = json.getDouble("dia");
|
||||||
if (json.has("dia"))
|
|
||||||
dia = json.getDouble("dia");
|
|
||||||
if (json.has("timezone"))
|
if (json.has("timezone"))
|
||||||
timeZone = TimeZone.getTimeZone(json.getString("timezone"));
|
timeZone = TimeZone.getTimeZone(json.getString("timezone"));
|
||||||
isf = json.getJSONArray("sens");
|
isf = json.getJSONArray("sens");
|
||||||
|
@ -149,7 +153,7 @@ public class Profile {
|
||||||
return units;
|
return units;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeZone getTimeZone() {
|
TimeZone getTimeZone() {
|
||||||
return timeZone;
|
return timeZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +166,7 @@ public class Profile {
|
||||||
double multiplier = getMultiplier(array);
|
double multiplier = getMultiplier(array);
|
||||||
|
|
||||||
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
||||||
for (Integer index = 0; index < array.length(); index++) {
|
for (int index = 0; index < array.length(); index++) {
|
||||||
try {
|
try {
|
||||||
final JSONObject o = array.getJSONObject(index);
|
final JSONObject o = array.getJSONObject(index);
|
||||||
long tas = 0;
|
long tas = 0;
|
||||||
|
@ -385,12 +389,12 @@ public class Profile {
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getIsf() {
|
public double getIsfMgdl() {
|
||||||
return getIsfTimeFromMidnight(secondsFromMidnight());
|
return toMgdl(getIsfTimeFromMidnight(secondsFromMidnight()), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getIsf(long time) {
|
public double getIsfMgdl(long time) {
|
||||||
return getIsfTimeFromMidnight(secondsFromMidnight(time));
|
return toMgdl(getIsfTimeFromMidnight(secondsFromMidnight(time)), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getIsfTimeFromMidnight(int timeAsSeconds) {
|
double getIsfTimeFromMidnight(int timeAsSeconds) {
|
||||||
|
@ -405,15 +409,15 @@ public class Profile {
|
||||||
return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + MainApp.gs(R.string.profile_per_unit));
|
return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + MainApp.gs(R.string.profile_per_unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileValue[] getIsfs() {
|
public ProfileValue[] getIsfsMgdl() {
|
||||||
if (isf_v == null)
|
if (isf_v == null)
|
||||||
isf_v = convertToSparseArray(ic);
|
isf_v = convertToSparseArray(ic);
|
||||||
ProfileValue[] ret = new ProfileValue[isf_v.size()];
|
ProfileValue[] ret = new ProfileValue[isf_v.size()];
|
||||||
|
|
||||||
for (Integer index = 0; index < isf_v.size(); index++) {
|
for (int index = 0; index < isf_v.size(); index++) {
|
||||||
Integer tas = (int) isf_v.keyAt(index);
|
int tas = (int) isf_v.keyAt(index);
|
||||||
double value = isf_v.valueAt(index);
|
double value = isf_v.valueAt(index);
|
||||||
ret[index] = new ProfileValue(tas, value);
|
ret[index] = new ProfileValue(tas, toMgdl(value, units));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -495,44 +499,44 @@ public class Profile {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTarget() {
|
public double getTargetMgdl() {
|
||||||
return getTarget(secondsFromMidnight());
|
return getTargetMgdl(secondsFromMidnight());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected double getTarget(int timeAsSeconds) {
|
public double getTargetMgdl(int timeAsSeconds) {
|
||||||
return (getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2;
|
return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetLow() {
|
public double getTargetLowMgdl() {
|
||||||
return getTargetLowTimeFromMidnight(secondsFromMidnight());
|
return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetLow(long time) {
|
public double getTargetLowMgdl(long time) {
|
||||||
return getTargetLowTimeFromMidnight(secondsFromMidnight(time));
|
return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight(time)), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetLowTimeFromMidnight(int timeAsSeconds) {
|
double getTargetLowTimeFromMidnight(int timeAsSeconds) {
|
||||||
if (targetLow_v == null)
|
if (targetLow_v == null)
|
||||||
targetLow_v = convertToSparseArray(targetLow);
|
targetLow_v = convertToSparseArray(targetLow);
|
||||||
return getValueToTime(targetLow_v, timeAsSeconds);
|
return getValueToTime(targetLow_v, timeAsSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetHigh() {
|
public double getTargetHighMgdl() {
|
||||||
return getTargetHighTimeFromMidnight(secondsFromMidnight());
|
return toMgdl(getTargetHighTimeFromMidnight(secondsFromMidnight()), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetHigh(long time) {
|
public double getTargetHighMgdl(long time) {
|
||||||
return getTargetHighTimeFromMidnight(secondsFromMidnight(time));
|
return toMgdl(getTargetHighTimeFromMidnight(secondsFromMidnight(time)), units);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getTargetHighTimeFromMidnight(int timeAsSeconds) {
|
double getTargetHighTimeFromMidnight(int timeAsSeconds) {
|
||||||
if (targetHigh_v == null)
|
if (targetHigh_v == null)
|
||||||
targetHigh_v = convertToSparseArray(targetHigh);
|
targetHigh_v = convertToSparseArray(targetHigh);
|
||||||
return getValueToTime(targetHigh_v, timeAsSeconds);
|
return getValueToTime(targetHigh_v, timeAsSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TargetValue {
|
public class TargetValue {
|
||||||
public TargetValue(int timeAsSeconds, double low, double high) {
|
TargetValue(int timeAsSeconds, double low, double high) {
|
||||||
this.timeAsSeconds = timeAsSeconds;
|
this.timeAsSeconds = timeAsSeconds;
|
||||||
this.low = low;
|
this.low = low;
|
||||||
this.high = high;
|
this.high = high;
|
||||||
|
@ -559,17 +563,17 @@ public class Profile {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileValue[] getSingleTargets() {
|
public ProfileValue[] getSingleTargetsMgdl() {
|
||||||
if (targetLow_v == null)
|
if (targetLow_v == null)
|
||||||
targetLow_v = convertToSparseArray(targetLow);
|
targetLow_v = convertToSparseArray(targetLow);
|
||||||
if (targetHigh_v == null)
|
if (targetHigh_v == null)
|
||||||
targetHigh_v = convertToSparseArray(targetHigh);
|
targetHigh_v = convertToSparseArray(targetHigh);
|
||||||
ProfileValue[] ret = new ProfileValue[targetLow_v.size()];
|
ProfileValue[] ret = new ProfileValue[targetLow_v.size()];
|
||||||
|
|
||||||
for (Integer index = 0; index < targetLow_v.size(); index++) {
|
for (int index = 0; index < targetLow_v.size(); index++) {
|
||||||
Integer tas = (int) targetLow_v.keyAt(index);
|
int tas = (int) targetLow_v.keyAt(index);
|
||||||
double target = (targetLow_v.valueAt(index) + targetHigh_v.valueAt(index)) / 2;
|
double target = (targetLow_v.valueAt(index) + targetHigh_v.valueAt(index)) / 2;
|
||||||
ret[index] = new ProfileValue(tas, target);
|
ret[index] = new ProfileValue(tas, toMgdl(target, units));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -617,22 +621,39 @@ public class Profile {
|
||||||
else return value * Constants.MGDL_TO_MMOLL;
|
else return value * Constants.MGDL_TO_MMOLL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double toUnits(Double valueInMgdl, Double valueInMmol, String units) {
|
public static double fromMmolToUnits(double value, String units) {
|
||||||
|
if (units.equals(Constants.MMOL)) return value;
|
||||||
|
else return value * Constants.MMOLL_TO_MGDL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double toUnits(double valueInMgdl, double valueInMmol, String units) {
|
||||||
if (units.equals(Constants.MGDL)) return valueInMgdl;
|
if (units.equals(Constants.MGDL)) return valueInMgdl;
|
||||||
else return valueInMmol;
|
else return valueInMmol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toUnitsString(Double valueInMgdl, Double valueInMmol, String units) {
|
public static String toUnitsString(double valueInMgdl, double valueInMmol, String units) {
|
||||||
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(valueInMgdl);
|
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(valueInMgdl);
|
||||||
else return DecimalFormatter.to1Decimal(valueInMmol);
|
else return DecimalFormatter.to1Decimal(valueInMmol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toSignedUnitsString(Double valueInMgdl, Double valueInMmol, String units) {
|
public static String toSignedUnitsString(double valueInMgdl, double valueInMmol, String units) {
|
||||||
if (units.equals(Constants.MGDL))
|
if (units.equals(Constants.MGDL))
|
||||||
return (valueInMgdl > 0 ? "+" : "") + DecimalFormatter.to0Decimal(valueInMgdl);
|
return (valueInMgdl > 0 ? "+" : "") + DecimalFormatter.to0Decimal(valueInMgdl);
|
||||||
else return (valueInMmol > 0 ? "+" : "") + DecimalFormatter.to1Decimal(valueInMmol);
|
else return (valueInMmol > 0 ? "+" : "") + DecimalFormatter.to1Decimal(valueInMmol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double toCurrentUnits(double anyBg) {
|
||||||
|
if (anyBg < 32) return fromMmolToUnits(anyBg, ProfileFunctions.getSystemUnits());
|
||||||
|
else return fromMgdlToUnits(anyBg, ProfileFunctions.getSystemUnits());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toCurrentUnitsString(double anyBg) {
|
||||||
|
if (anyBg < 32)
|
||||||
|
return toUnitsString(anyBg * Constants.MMOLL_TO_MGDL, anyBg, ProfileFunctions.getSystemUnits());
|
||||||
|
else
|
||||||
|
return toUnitsString(anyBg, anyBg * Constants.MGDL_TO_MMOLL, ProfileFunctions.getSystemUnits());
|
||||||
|
}
|
||||||
|
|
||||||
// targets are stored in mg/dl but profile vary
|
// targets are stored in mg/dl but profile vary
|
||||||
public static String toTargetRangeString(double low, double high, String sourceUnits, String units) {
|
public static String toTargetRangeString(double low, double high, String sourceUnits, String units) {
|
||||||
double lowMgdl = toMgdl(low, sourceUnits);
|
double lowMgdl = toMgdl(low, sourceUnits);
|
||||||
|
@ -670,4 +691,112 @@ public class Profile {
|
||||||
public int getTimeshift() {
|
public int getTimeshift() {
|
||||||
return timeshift;
|
return timeshift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Profile convertToNonCustomizedProfile() {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
try {
|
||||||
|
o.put("units", units);
|
||||||
|
o.put("dia", dia);
|
||||||
|
o.put("timezone", timeZone.getID());
|
||||||
|
// SENS
|
||||||
|
JSONArray sens = new JSONArray();
|
||||||
|
double lastValue = -1d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
int timeAsSeconds = i * 60 * 60;
|
||||||
|
double value = getIsfTimeFromMidnight(timeAsSeconds);
|
||||||
|
if (value != lastValue) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
String time;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(i) + ":00";
|
||||||
|
item.put("time", time);
|
||||||
|
item.put("timeAsSeconds", timeAsSeconds);
|
||||||
|
item.put("value", value);
|
||||||
|
lastValue = value;
|
||||||
|
sens.put(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("sens", sens);
|
||||||
|
// CARBRATIO
|
||||||
|
JSONArray carbratio = new JSONArray();
|
||||||
|
lastValue = -1d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
int timeAsSeconds = i * 60 * 60;
|
||||||
|
double value = getIcTimeFromMidnight(timeAsSeconds);
|
||||||
|
if (value != lastValue) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
String time;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(i) + ":00";
|
||||||
|
item.put("time", time);
|
||||||
|
item.put("timeAsSeconds", timeAsSeconds);
|
||||||
|
item.put("value", value);
|
||||||
|
lastValue = value;
|
||||||
|
carbratio.put(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("carbratio", carbratio);
|
||||||
|
// BASAL
|
||||||
|
JSONArray basal = new JSONArray();
|
||||||
|
lastValue = -1d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
int timeAsSeconds = i * 60 * 60;
|
||||||
|
double value = getBasalTimeFromMidnight(timeAsSeconds);
|
||||||
|
if (value != lastValue) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
String time;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(i) + ":00";
|
||||||
|
item.put("time", time);
|
||||||
|
item.put("timeAsSeconds", timeAsSeconds);
|
||||||
|
item.put("value", value);
|
||||||
|
lastValue = value;
|
||||||
|
basal.put(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("basal", basal);
|
||||||
|
// TARGET_LOW
|
||||||
|
JSONArray target_low = new JSONArray();
|
||||||
|
lastValue = -1d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
int timeAsSeconds = i * 60 * 60;
|
||||||
|
double value = getTargetLowTimeFromMidnight(timeAsSeconds);
|
||||||
|
if (value != lastValue) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
String time;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(i) + ":00";
|
||||||
|
item.put("time", time);
|
||||||
|
item.put("timeAsSeconds", timeAsSeconds);
|
||||||
|
item.put("value", value);
|
||||||
|
lastValue = value;
|
||||||
|
target_low.put(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("target_low", target_low);
|
||||||
|
// TARGET_HIGH
|
||||||
|
JSONArray target_high = new JSONArray();
|
||||||
|
lastValue = -1d;
|
||||||
|
for (int i = 0; i < 24; i++) {
|
||||||
|
int timeAsSeconds = i * 60 * 60;
|
||||||
|
double value = getTargetHighTimeFromMidnight(timeAsSeconds);
|
||||||
|
if (value != lastValue) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
String time;
|
||||||
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
|
time = df.format(i) + ":00";
|
||||||
|
item.put("time", time);
|
||||||
|
item.put("timeAsSeconds", timeAsSeconds);
|
||||||
|
item.put("value", value);
|
||||||
|
lastValue = value;
|
||||||
|
target_high.put(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.put("target_high", target_high);
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Unhandled exception" + e);
|
||||||
|
}
|
||||||
|
return new Profile(o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,118 +0,0 @@
|
||||||
package info.nightscout.androidaps.data;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.collection.ArrayMap;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 01.06.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ProfileStore {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(ProfileStore.class);
|
|
||||||
private JSONObject json = null;
|
|
||||||
private String units = Constants.MGDL;
|
|
||||||
|
|
||||||
ArrayMap<String, Profile> cachedObjects = new ArrayMap<>();
|
|
||||||
|
|
||||||
public ProfileStore(JSONObject json) {
|
|
||||||
this.json = json;
|
|
||||||
getDefaultProfile(); // initialize units
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject getData() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Profile getDefaultProfile() {
|
|
||||||
Profile profile = null;
|
|
||||||
try {
|
|
||||||
String defaultProfileName = json.getString("defaultProfile");
|
|
||||||
JSONObject store = json.getJSONObject("store");
|
|
||||||
if (store.has(defaultProfileName)) {
|
|
||||||
profile = cachedObjects.get(defaultProfileName);
|
|
||||||
if (profile == null) {
|
|
||||||
if (store.has("units"))
|
|
||||||
units = store.getString("units");
|
|
||||||
profile = new Profile(store.getJSONObject(defaultProfileName), units);
|
|
||||||
units = profile.getUnits();
|
|
||||||
cachedObjects.put(defaultProfileName, profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getDefaultProfileName() {
|
|
||||||
String defaultProfileName = null;
|
|
||||||
try {
|
|
||||||
defaultProfileName = json.getString("defaultProfile");
|
|
||||||
JSONObject store = json.getJSONObject("store");
|
|
||||||
if (store.has(defaultProfileName)) {
|
|
||||||
return defaultProfileName;
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return defaultProfileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUnits() {
|
|
||||||
return units;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Profile getSpecificProfile(String profileName) {
|
|
||||||
Profile profile = null;
|
|
||||||
try {
|
|
||||||
JSONObject store = json.getJSONObject("store");
|
|
||||||
if (store.has(profileName)) {
|
|
||||||
profile = cachedObjects.get(profileName);
|
|
||||||
if (profile == null) {
|
|
||||||
if (store.has("units"))
|
|
||||||
units = store.getString("units");
|
|
||||||
profile = new Profile(store.getJSONObject(profileName), units);
|
|
||||||
units = profile.getUnits();
|
|
||||||
cachedObjects.put(profileName, profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<CharSequence> getProfileList() {
|
|
||||||
ArrayList<CharSequence> ret = new ArrayList<CharSequence>();
|
|
||||||
|
|
||||||
JSONObject store;
|
|
||||||
try {
|
|
||||||
store = json.getJSONObject("store");
|
|
||||||
Iterator<?> keys = store.keys();
|
|
||||||
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
String profileName = (String) keys.next();
|
|
||||||
ret.add(profileName);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package info.nightscout.androidaps.data
|
||||||
|
|
||||||
|
import androidx.collection.ArrayMap
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ProfileStore(val data: JSONObject) {
|
||||||
|
private val log = LoggerFactory.getLogger(ProfileStore::class.java)
|
||||||
|
|
||||||
|
private val cachedObjects = ArrayMap<String, Profile>()
|
||||||
|
|
||||||
|
private fun getStore(): JSONObject? {
|
||||||
|
try {
|
||||||
|
if (data.has("store")) return data.getJSONObject("store")
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
log.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getDefaultProfile(): Profile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
|
||||||
|
|
||||||
|
fun getDefaultProfileName(): String? {
|
||||||
|
val defaultProfileName = data.getString("defaultProfile")
|
||||||
|
return getStore()?.has(defaultProfileName)?.let { defaultProfileName }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getProfileList(): ArrayList<CharSequence> {
|
||||||
|
val ret = ArrayList<CharSequence>()
|
||||||
|
getStore()?.keys()?.let { keys ->
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
val profileName = keys.next() as String
|
||||||
|
ret.add(profileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSpecificProfile(profileName: String): Profile? {
|
||||||
|
var profile: Profile? = null
|
||||||
|
try {
|
||||||
|
getStore()?.let { store ->
|
||||||
|
if (store.has(profileName)) {
|
||||||
|
profile = cachedObjects[profileName]
|
||||||
|
if (profile == null) {
|
||||||
|
val profileObject = store.getJSONObject(profileName)
|
||||||
|
if (profileObject != null && profileObject.has("units")) {
|
||||||
|
profile = Profile(profileObject, profileObject.getString("units"))
|
||||||
|
cachedObjects[profileName] = profile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
log.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
return profile
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
|
@ -74,7 +75,7 @@ public class QuickWizardEntry {
|
||||||
//BG
|
//BG
|
||||||
double bg = 0;
|
double bg = 0;
|
||||||
if (lastBG != null && useBG() == YES) {
|
if (lastBG != null && useBG() == YES) {
|
||||||
bg = lastBG.valueToUnits(profile.getUnits());
|
bg = lastBG.valueToUnits(ProfileFunctions.getSystemUnits());
|
||||||
}
|
}
|
||||||
|
|
||||||
// COB
|
// COB
|
||||||
|
|
|
@ -181,8 +181,7 @@ public class BgReading implements DataPointWithLabelInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getY() {
|
public double getY() {
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
return valueToUnits(ProfileFunctions.getSystemUnits());
|
||||||
return valueToUnits(units);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -215,9 +214,9 @@ public class BgReading implements DataPointWithLabelInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColor() {
|
public int getColor() {
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
Double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
|
||||||
Double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
Double highLine = OverviewPlugin.INSTANCE.determineHighLine();
|
||||||
int color = MainApp.gc(R.color.inrange);
|
int color = MainApp.gc(R.color.inrange);
|
||||||
if (isPrediction())
|
if (isPrediction())
|
||||||
return getPredectionColor();
|
return getPredectionColor();
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getY() {
|
public double getY() {
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
if (eventType.equals(MBG)) {
|
if (eventType.equals(MBG)) {
|
||||||
double mbg = 0d;
|
double mbg = 0d;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -259,11 +259,11 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
|
||||||
double sensitivityRatio = lastAutosensResult.ratio;
|
double sensitivityRatio = lastAutosensResult.ratio;
|
||||||
double normalTarget = 100;
|
double normalTarget = 100;
|
||||||
|
|
||||||
if (exercise_mode && isTempTarget && profile.getTarget() >= normalTarget + 5) {
|
if (exercise_mode && isTempTarget && profile.getTargetMgdl() >= normalTarget + 5) {
|
||||||
// w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44
|
// w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44
|
||||||
// e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6
|
// e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6
|
||||||
double c = half_basal_exercise_target - normalTarget;
|
double c = half_basal_exercise_target - normalTarget;
|
||||||
sensitivityRatio = c / (c + profile.getTarget() - normalTarget);
|
sensitivityRatio = c / (c + profile.getTargetMgdl() - normalTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realDuration > 0) {
|
if (realDuration > 0) {
|
||||||
|
|
|
@ -299,11 +299,11 @@ public class TemporaryBasal implements Interval, DbObjectBase {
|
||||||
double sensitivityRatio = lastAutosensResult.ratio;
|
double sensitivityRatio = lastAutosensResult.ratio;
|
||||||
double normalTarget = 100;
|
double normalTarget = 100;
|
||||||
|
|
||||||
if (exercise_mode && isTempTarget && profile.getTarget() >= normalTarget + 5) {
|
if (exercise_mode && isTempTarget && profile.getTargetMgdl() >= normalTarget + 5) {
|
||||||
// w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44
|
// w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44
|
||||||
// e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6
|
// e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6
|
||||||
double c = half_basal_exercise_target - normalTarget;
|
double c = half_basal_exercise_target - normalTarget;
|
||||||
sensitivityRatio = c / (c + profile.getTarget() - normalTarget);
|
sensitivityRatio = c / (c + profile.getTargetMgdl() - normalTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realDuration > 0) {
|
if (realDuration > 0) {
|
||||||
|
|
|
@ -10,6 +10,5 @@ import info.nightscout.androidaps.data.ProfileStore;
|
||||||
public interface ProfileInterface {
|
public interface ProfileInterface {
|
||||||
@Nullable
|
@Nullable
|
||||||
ProfileStore getProfile();
|
ProfileStore getProfile();
|
||||||
String getUnits();
|
|
||||||
String getProfileName();
|
String getProfileName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import javax.annotation.Nullable;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
@ -194,8 +195,6 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
double autosensDataRatio,
|
double autosensDataRatio,
|
||||||
boolean tempTargetSet) throws JSONException {
|
boolean tempTargetSet) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
mProfile = new JSONObject();
|
mProfile = new JSONObject();
|
||||||
mProfile.put("max_iob", maxIob);
|
mProfile.put("max_iob", maxIob);
|
||||||
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
||||||
|
@ -206,7 +205,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mProfile.put("max_bg", maxBg);
|
mProfile.put("max_bg", maxBg);
|
||||||
mProfile.put("target_bg", targetBg);
|
mProfile.put("target_bg", targetBg);
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units));
|
mProfile.put("sens", profile.getIsfMgdl());
|
||||||
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
|
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
|
||||||
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
|
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
|
||||||
mProfile.put("skip_neutral_temps", true);
|
mProfile.put("skip_neutral_temps", true);
|
||||||
|
@ -220,7 +219,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
|
mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
|
||||||
mProfile.put("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pump == null) {
|
||||||
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||||
|
if (L.isEnabled(L.APS))
|
||||||
|
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
|
@ -121,12 +128,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
||||||
double minBg = Profile.toMgdl(profile.getTargetLow(), units);
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = Profile.toMgdl(profile.getTargetHigh(), units);
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
double targetBg = Profile.toMgdl(profile.getTarget(), units);
|
double targetBg = profile.getTargetMgdl();
|
||||||
|
|
||||||
minBg = Round.roundTo(minBg, 0.1d);
|
minBg = Round.roundTo(minBg, 0.1d);
|
||||||
maxBg = Round.roundTo(maxBg, 0.1d);
|
maxBg = Round.roundTo(maxBg, 0.1d);
|
||||||
|
@ -162,7 +167,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
if (!HardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
if (!HardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||||
return;
|
return;
|
||||||
if (!HardLimits.checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
if (!HardLimits.checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
||||||
return;
|
return;
|
||||||
if (!HardLimits.checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
if (!HardLimits.checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
@ -160,8 +161,6 @@ public class DetermineBasalAdapterMAJS {
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData) throws JSONException {
|
MealData mealData) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
mProfile = new JSONObject();
|
mProfile = new JSONObject();
|
||||||
mProfile.put("max_iob", maxIob);
|
mProfile.put("max_iob", maxIob);
|
||||||
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
||||||
|
@ -172,11 +171,11 @@ public class DetermineBasalAdapterMAJS {
|
||||||
mProfile.put("max_bg", maxBg);
|
mProfile.put("max_bg", maxBg);
|
||||||
mProfile.put("target_bg", targetBg);
|
mProfile.put("target_bg", targetBg);
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units));
|
mProfile.put("sens", profile.getIsfMgdl());
|
||||||
|
|
||||||
mProfile.put("current_basal", basalRate);
|
mProfile.put("current_basal", basalRate);
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
|
||||||
mProfile.put("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,13 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pump == null) {
|
||||||
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||||
|
if (L.isEnabled(L.APS))
|
||||||
|
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
|
@ -120,13 +127,11 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
||||||
|
|
||||||
double minBg = Profile.toMgdl(profile.getTargetLow(), units);
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = Profile.toMgdl(profile.getTargetHigh(), units);
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
double targetBg = Profile.toMgdl(profile.getTarget(), units);
|
double targetBg = profile.getTargetMgdl();
|
||||||
|
|
||||||
minBg = Round.roundTo(minBg, 0.1d);
|
minBg = Round.roundTo(minBg, 0.1d);
|
||||||
maxBg = Round.roundTo(maxBg, 0.1d);
|
maxBg = Round.roundTo(maxBg, 0.1d);
|
||||||
|
@ -160,7 +165,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
if (!checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import javax.annotation.Nullable;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
@ -219,8 +220,6 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
boolean advancedFiltering
|
boolean advancedFiltering
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
mProfile = new JSONObject();
|
mProfile = new JSONObject();
|
||||||
|
|
||||||
mProfile.put("max_iob", maxIob);
|
mProfile.put("max_iob", maxIob);
|
||||||
|
@ -232,7 +231,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mProfile.put("max_bg", maxBg);
|
mProfile.put("max_bg", maxBg);
|
||||||
mProfile.put("target_bg", targetBg);
|
mProfile.put("target_bg", targetBg);
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units));
|
mProfile.put("sens", profile.getIsfMgdl());
|
||||||
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
|
mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3));
|
||||||
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
|
mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d));
|
||||||
|
|
||||||
|
@ -273,7 +272,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mProfile.put("temptargetSet", tempTargetSet);
|
mProfile.put("temptargetSet", tempTargetSet);
|
||||||
mProfile.put("autosens_max", SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
|
mProfile.put("autosens_max", SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
|
||||||
mProfile.put("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pump == null) {
|
||||||
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||||
|
if (L.isEnabled(L.APS))
|
||||||
|
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
|
@ -125,16 +132,14 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String units = profile.getUnits();
|
|
||||||
|
|
||||||
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
||||||
|
|
||||||
Constraint<Double> maxBasalConstraint = MainApp.getConstraintChecker().getMaxBasalAllowed(profile);
|
Constraint<Double> maxBasalConstraint = MainApp.getConstraintChecker().getMaxBasalAllowed(profile);
|
||||||
inputConstraints.copyReasons(maxBasalConstraint);
|
inputConstraints.copyReasons(maxBasalConstraint);
|
||||||
double maxBasal = maxBasalConstraint.value();
|
double maxBasal = maxBasalConstraint.value();
|
||||||
double minBg = Profile.toMgdl(profile.getTargetLow(), units);
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = Profile.toMgdl(profile.getTargetHigh(), units);
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
double targetBg = Profile.toMgdl(profile.getTarget(), units);
|
double targetBg = profile.getTargetMgdl();
|
||||||
|
|
||||||
minBg = Round.roundTo(minBg, 0.1d);
|
minBg = Round.roundTo(minBg, 0.1d);
|
||||||
maxBg = Round.roundTo(maxBg, 0.1d);
|
maxBg = Round.roundTo(maxBg, 0.1d);
|
||||||
|
@ -168,7 +173,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
if (!checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal()))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -124,9 +124,8 @@ public class ProfileFunctions {
|
||||||
return getProfile(System.currentTimeMillis());
|
return getProfile(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileUnits() {
|
public static String getSystemUnits() {
|
||||||
Profile profile = getProfile();
|
return SP.getString(R.string.key_units, Constants.MGDL);
|
||||||
return profile != null ? profile.getUnits() : Constants.MGDL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class InputBg extends Element {
|
||||||
|
|
||||||
public InputBg() {
|
public InputBg() {
|
||||||
super();
|
super();
|
||||||
setUnits(ProfileFunctions.getInstance().getProfileUnits());
|
setUnits(ProfileFunctions.getSystemUnits());
|
||||||
if (getUnits().equals(Constants.MMOL))
|
if (getUnits().equals(Constants.MMOL))
|
||||||
value = MMOL_MIN;
|
value = MMOL_MIN;
|
||||||
else
|
else
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class InputTempTarget extends Element {
|
||||||
|
|
||||||
public InputTempTarget() {
|
public InputTempTarget() {
|
||||||
super();
|
super();
|
||||||
setUnits(ProfileFunctions.getInstance().getProfileUnits());
|
setUnits(ProfileFunctions.getSystemUnits());
|
||||||
if (getUnits().equals(Constants.MMOL))
|
if (getUnits().equals(Constants.MMOL))
|
||||||
value = 6;
|
value = 6;
|
||||||
else
|
else
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TriggerDelta extends Trigger {
|
||||||
|
|
||||||
public TriggerDelta() {
|
public TriggerDelta() {
|
||||||
super();
|
super();
|
||||||
this.units = ProfileFunctions.getInstance().getProfileUnits();
|
this.units = ProfileFunctions.getSystemUnits();
|
||||||
initializer();
|
initializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
|
|
||||||
Profile profile;
|
Profile profile;
|
||||||
public ProfileStore profileStore;
|
public ProfileStore profileStore;
|
||||||
String units = Constants.MGDL;
|
|
||||||
|
|
||||||
TextView eventTypeText;
|
TextView eventTypeText;
|
||||||
LinearLayout layoutPercent;
|
LinearLayout layoutPercent;
|
||||||
|
@ -179,7 +178,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ArrayList<CharSequence> profileList;
|
ArrayList<CharSequence> profileList;
|
||||||
units = profile != null ? profile.getUnits() : Constants.MGDL;
|
|
||||||
profileList = profileStore.getProfileList();
|
profileList = profileStore.getProfileList();
|
||||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(),
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(),
|
||||||
R.layout.spinner_centered, profileList);
|
R.layout.spinner_centered, profileList);
|
||||||
|
@ -190,7 +188,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
profileSpinner.setSelection(p);
|
profileSpinner.setSelection(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
|
final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, ProfileFunctions.getSystemUnits());
|
||||||
|
|
||||||
// temp target
|
// temp target
|
||||||
final List<String> reasonList = Lists.newArrayList(
|
final List<String> reasonList = Lists.newArrayList(
|
||||||
|
@ -205,8 +203,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
double defaultDuration;
|
double defaultDuration;
|
||||||
double defaultTarget = 0;
|
double defaultTarget;
|
||||||
if (profile != null && editTemptarget.getValue() == bg) {
|
if (profile != null && editTemptarget.getValue().equals(bg)) {
|
||||||
defaultTarget = bg;
|
defaultTarget = bg;
|
||||||
} else {
|
} else {
|
||||||
//prevent changes on screen rotate
|
//prevent changes on screen rotate
|
||||||
|
@ -214,17 +212,17 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
boolean erase = false;
|
boolean erase = false;
|
||||||
|
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
DefaultValueHelper helper = new DefaultValueHelper();
|
DefaultValueHelper helper = new DefaultValueHelper();
|
||||||
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
|
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
|
||||||
defaultDuration = helper.determineEatingSoonTTDuration();
|
defaultDuration = helper.determineEatingSoonTTDuration();
|
||||||
defaultTarget = helper.determineEatingSoonTT(units);
|
defaultTarget = helper.determineEatingSoonTT();
|
||||||
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
|
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
|
||||||
defaultDuration = helper.determineActivityTTDuration();
|
defaultDuration = helper.determineActivityTTDuration();
|
||||||
defaultTarget = helper.determineActivityTT(units);
|
defaultTarget = helper.determineActivityTT();
|
||||||
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
|
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
|
||||||
defaultDuration = helper.determineHypoTTDuration();
|
defaultDuration = helper.determineHypoTTDuration();
|
||||||
defaultTarget = helper.determineHypoTT(units);
|
defaultTarget = helper.determineHypoTT();
|
||||||
} else if (editDuration.getValue() != 0) {
|
} else if (editDuration.getValue() != 0) {
|
||||||
defaultDuration = editDuration.getValue();
|
defaultDuration = editDuration.getValue();
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,7 +247,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
});
|
});
|
||||||
|
|
||||||
// bg
|
// bg
|
||||||
bgUnitsView.setText(units);
|
bgUnitsView.setText(ProfileFunctions.getSystemUnits());
|
||||||
|
|
||||||
TextWatcher bgTextWatcher = new TextWatcher() {
|
TextWatcher bgTextWatcher = new TextWatcher() {
|
||||||
|
|
||||||
|
@ -268,7 +266,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), bgTextWatcher);
|
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), bgTextWatcher);
|
||||||
editTemptarget.setParams(Constants.MIN_TT_MGDL, Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
|
editTemptarget.setParams(Constants.MIN_TT_MGDL, Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
|
||||||
} else if (units.equals(Constants.MMOL)) {
|
} else if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
|
||||||
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok), bgTextWatcher);
|
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok), bgTextWatcher);
|
||||||
editTemptarget.setParams(Constants.MIN_TT_MMOL, Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
|
editTemptarget.setParams(Constants.MIN_TT_MMOL, Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok));
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,7 +275,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
|
Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, ProfileFunctions.getSystemUnits());
|
||||||
if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) {
|
if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) {
|
||||||
editBg.setValue(savedInstanceState.getDouble("editBg"));
|
editBg.setValue(savedInstanceState.getDouble("editBg"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -286,16 +284,16 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
});
|
});
|
||||||
|
|
||||||
Integer maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value();
|
Integer maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value();
|
||||||
editCarbs = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbsinput);
|
editCarbs = view.findViewById(R.id.careportal_newnstreatment_carbsinput);
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value();
|
Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value();
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_insulininput);
|
editInsulin = view.findViewById(R.id.careportal_newnstreatment_insulininput);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false, view.findViewById(R.id.ok));
|
editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
editSplit = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_splitinput);
|
editSplit = view.findViewById(R.id.careportal_newnstreatment_splitinput);
|
||||||
editSplit.setParams(100d, 0d, 100d, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok));
|
editSplit.setParams(100d, 0d, 100d, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok));
|
||||||
editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput);
|
editDuration = view.findViewById(R.id.careportal_newnstreatment_durationinput);
|
||||||
editDuration.setParams(0d, 0d, Constants.MAX_PROFILE_SWITCH_DURATION, 10d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editDuration.setParams(0d, 0d, Constants.MAX_PROFILE_SWITCH_DURATION, 10d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
TextWatcher percentTextWatcher = new TextWatcher() {
|
TextWatcher percentTextWatcher = new TextWatcher() {
|
||||||
|
@ -319,7 +317,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
Integer maxPercent = 200;
|
Integer maxPercent = 200;
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
maxPercent = MainApp.getConstraintChecker().getMaxBasalPercentAllowed(profile).value();
|
maxPercent = MainApp.getConstraintChecker().getMaxBasalPercentAllowed(profile).value();
|
||||||
editPercent = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
editPercent = view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
||||||
editPercent.setParams(0d, -100d, (double) maxPercent, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok), percentTextWatcher);
|
editPercent.setParams(0d, -100d, (double) maxPercent, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok), percentTextWatcher);
|
||||||
|
|
||||||
TextWatcher absoluteTextWatcher = new TextWatcher() {
|
TextWatcher absoluteTextWatcher = new TextWatcher() {
|
||||||
|
@ -343,16 +341,16 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
Double maxAbsolute = HardLimits.maxBasal();
|
Double maxAbsolute = HardLimits.maxBasal();
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
maxAbsolute = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
maxAbsolute = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
||||||
editAbsolute = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
editAbsolute = view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
||||||
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, view.findViewById(R.id.ok), absoluteTextWatcher);
|
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, view.findViewById(R.id.ok), absoluteTextWatcher);
|
||||||
|
|
||||||
editCarbTime = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput);
|
editCarbTime = view.findViewById(R.id.careportal_newnstreatment_carbtimeinput);
|
||||||
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
editPercentage = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentage);
|
editPercentage = view.findViewById(R.id.careportal_newnstreatment_percentage);
|
||||||
editPercentage.setParams(100d, (double) Constants.CPP_MIN_PERCENTAGE, (double) Constants.CPP_MAX_PERCENTAGE, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editPercentage.setParams(100d, (double) Constants.CPP_MIN_PERCENTAGE, (double) Constants.CPP_MAX_PERCENTAGE, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
editTimeshift = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_timeshift);
|
editTimeshift = view.findViewById(R.id.careportal_newnstreatment_timeshift);
|
||||||
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
ProfileSwitch ps = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now());
|
ProfileSwitch ps = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now());
|
||||||
|
@ -369,21 +367,21 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
options.duration = false;
|
options.duration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_eventtime_layout), options.date);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_eventtime_layout), options.date);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bg_layout), options.bg);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_bg_layout), options.bg);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout), options.bg);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_bgsource_layout), options.bg);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_insulin_layout), options.insulin);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_insulin_layout), options.insulin);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbs_layout), options.carbs);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_carbs_layout), options.carbs);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_split_layout), options.split);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_split_layout), options.split);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_duration_layout), options.duration);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_duration_layout), options.duration);
|
||||||
showOrHide(layoutPercent, options.percent);
|
showOrHide(layoutPercent, options.percent);
|
||||||
showOrHide(layoutAbsolute, options.absolute);
|
showOrHide(layoutAbsolute, options.absolute);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout), options.prebolus);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_carbtime_layout), options.prebolus);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
showOrHide(view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
||||||
|
|
||||||
setCancelable(true);
|
setCancelable(true);
|
||||||
getDialog().setCanceledOnTouchOutside(false);
|
getDialog().setCanceledOnTouchOutside(false);
|
||||||
|
@ -457,7 +455,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
if ((data.size() > 0) &&
|
if ((data.size() > 0) &&
|
||||||
(data.get(0).date > millis - 7 * 60 * 1000L) &&
|
(data.get(0).date > millis - 7 * 60 * 1000L) &&
|
||||||
(data.get(0).date < millis + 7 * 60 * 1000L)) {
|
(data.get(0).date < millis + 7 * 60 * 1000L)) {
|
||||||
editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, units));
|
editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, ProfileFunctions.getSystemUnits()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,7 +583,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText()));
|
data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText()));
|
||||||
if (!notesEdit.getText().toString().equals(""))
|
if (!notesEdit.getText().toString().equals(""))
|
||||||
data.put("notes", notesEdit.getText().toString());
|
data.put("notes", notesEdit.getText().toString());
|
||||||
data.put("units", units);
|
data.put("units", ProfileFunctions.getSystemUnits());
|
||||||
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
|
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
|
||||||
if (options.eventType == R.id.careportal_combobolus) {
|
if (options.eventType == R.id.careportal_combobolus) {
|
||||||
Double enteredInsulin = SafeParse.stringToDouble(editInsulin.getText());
|
Double enteredInsulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||||
|
@ -611,7 +609,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
ret += MainApp.gs(R.string.treatments_wizard_bg_label);
|
ret += MainApp.gs(R.string.treatments_wizard_bg_label);
|
||||||
ret += ": ";
|
ret += ": ";
|
||||||
ret += JsonHelper.safeGetObject(data, "glucose", "");
|
ret += JsonHelper.safeGetObject(data, "glucose", "");
|
||||||
ret += " " + units + "\n";
|
ret += " " + ProfileFunctions.getSystemUnits() + "\n";
|
||||||
}
|
}
|
||||||
if (data.has("glucoseType")) {
|
if (data.has("glucoseType")) {
|
||||||
ret += MainApp.gs(R.string.careportal_newnstreatment_glucosetype);
|
ret += MainApp.gs(R.string.careportal_newnstreatment_glucosetype);
|
||||||
|
@ -734,8 +732,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
.reason(reason)
|
.reason(reason)
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
if (tempTarget.durationInMinutes != 0) {
|
if (tempTarget.durationInMinutes != 0) {
|
||||||
tempTarget.low(Profile.toMgdl(targetBottom, units))
|
tempTarget.low(Profile.toMgdl(targetBottom, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(targetTop, units));
|
.high(Profile.toMgdl(targetTop, ProfileFunctions.getSystemUnits()));
|
||||||
} else {
|
} else {
|
||||||
tempTarget.low(0).high(0);
|
tempTarget.low(0).high(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,21 +312,14 @@ public class NSUpload {
|
||||||
|
|
||||||
public static void uploadTempTarget(TempTarget tempTarget) {
|
public static void uploadTempTarget(TempTarget tempTarget) {
|
||||||
try {
|
try {
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
|
|
||||||
if (profile == null) {
|
|
||||||
log.error("Profile is null. Skipping upload");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("eventType", CareportalEvent.TEMPORARYTARGET);
|
data.put("eventType", CareportalEvent.TEMPORARYTARGET);
|
||||||
data.put("duration", tempTarget.durationInMinutes);
|
data.put("duration", tempTarget.durationInMinutes);
|
||||||
data.put("reason", tempTarget.reason);
|
data.put("reason", tempTarget.reason);
|
||||||
data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()));
|
data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits()));
|
||||||
data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, profile.getUnits()));
|
data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits()));
|
||||||
data.put("created_at", DateUtil.toISOString(tempTarget.date));
|
data.put("created_at", DateUtil.toISOString(tempTarget.date));
|
||||||
data.put("units", profile.getUnits());
|
data.put("units", ProfileFunctions.getSystemUnits());
|
||||||
data.put("enteredBy", MainApp.gs(R.string.app_name));
|
data.put("enteredBy", MainApp.gs(R.string.app_name));
|
||||||
uploadCareportalEntryToNS(data);
|
uploadCareportalEntryToNS(data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -517,6 +510,21 @@ public class NSUpload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void uploadProfileStore(JSONObject profileStore) {
|
||||||
|
if (SP.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
|
||||||
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("action", "dbAdd");
|
||||||
|
bundle.putString("collection", "profile");
|
||||||
|
bundle.putString("data", String.valueOf(profileStore));
|
||||||
|
Intent intent = new Intent(Intents.ACTION_DATABASE);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
|
DbLogger.dbAdd(intent, String.valueOf(profileStore));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) {
|
public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
|
@ -760,36 +760,36 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
pvd.show(manager, "ProfileViewDialog");
|
pvd.show(manager, "ProfileViewDialog");
|
||||||
} else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) {
|
} else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) {
|
||||||
DefaultValueHelper defHelper = new DefaultValueHelper();
|
DefaultValueHelper defHelper = new DefaultValueHelper();
|
||||||
double target = defHelper.determineEatingSoonTT(profile.getUnits());
|
double target = Profile.toMgdl(defHelper.determineEatingSoonTT(), ProfileFunctions.getSystemUnits());
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(defHelper.determineEatingSoonTTDuration())
|
.duration(defHelper.determineEatingSoonTTDuration())
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(MainApp.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(target, profile.getUnits()))
|
.low(target)
|
||||||
.high(Profile.toMgdl(target, profile.getUnits()));
|
.high(target);
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (item.getTitle().equals(MainApp.gs(R.string.activity))) {
|
} else if (item.getTitle().equals(MainApp.gs(R.string.activity))) {
|
||||||
DefaultValueHelper defHelper = new DefaultValueHelper();
|
DefaultValueHelper defHelper = new DefaultValueHelper();
|
||||||
double target = defHelper.determineActivityTT(profile.getUnits());
|
double target = Profile.toMgdl(defHelper.determineActivityTT(), ProfileFunctions.getSystemUnits());
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(now())
|
.date(now())
|
||||||
.duration(defHelper.determineActivityTTDuration())
|
.duration(defHelper.determineActivityTTDuration())
|
||||||
.reason(MainApp.gs(R.string.activity))
|
.reason(MainApp.gs(R.string.activity))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(target, profile.getUnits()))
|
.low(target)
|
||||||
.high(Profile.toMgdl(target, profile.getUnits()));
|
.high(target);
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) {
|
} else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) {
|
||||||
DefaultValueHelper defHelper = new DefaultValueHelper();
|
DefaultValueHelper defHelper = new DefaultValueHelper();
|
||||||
double target = defHelper.determineHypoTT(profile.getUnits());
|
double target = Profile.toMgdl(defHelper.determineHypoTT(), ProfileFunctions.getSystemUnits());
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(now())
|
.date(now())
|
||||||
.duration(defHelper.determineHypoTTDuration())
|
.duration(defHelper.determineHypoTTDuration())
|
||||||
.reason(MainApp.gs(R.string.hypo))
|
.reason(MainApp.gs(R.string.hypo))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(target, profile.getUnits()))
|
.low(target)
|
||||||
.high(Profile.toMgdl(target, profile.getUnits()));
|
.high(target);
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (item.getTitle().equals(MainApp.gs(R.string.custom))) {
|
} else if (item.getTitle().equals(MainApp.gs(R.string.custom))) {
|
||||||
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
|
||||||
|
@ -814,7 +814,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE);
|
boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE);
|
||||||
boolean dexcom = SourceDexcomPlugin.INSTANCE.isEnabled(PluginType.BGSOURCE);
|
boolean dexcom = SourceDexcomPlugin.INSTANCE.isEnabled(PluginType.BGSOURCE);
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
|
||||||
|
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
// try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days
|
// try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days
|
||||||
|
@ -1041,9 +1040,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||||
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
||||||
|
|
||||||
final String units = profile.getUnits();
|
final String units = ProfileFunctions.getSystemUnits();
|
||||||
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
|
||||||
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
final double highLine = OverviewPlugin.INSTANCE.determineHighLine();
|
||||||
|
|
||||||
//Start with updating the BG as it is unaffected by loop.
|
//Start with updating the BG as it is unaffected by loop.
|
||||||
// **** BG value ****
|
// **** BG value ****
|
||||||
|
@ -1126,7 +1125,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else {
|
} else {
|
||||||
tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
|
tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));
|
||||||
tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
|
tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
|
||||||
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
|
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), Constants.MGDL, units));
|
||||||
tempTargetView.setVisibility(View.VISIBLE);
|
tempTargetView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.general.overview
|
package info.nightscout.androidaps.plugins.general.overview
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||||
|
@ -9,7 +8,6 @@ import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.L
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
|
||||||
|
@ -65,22 +63,17 @@ object OverviewPlugin : PluginBase(PluginDescription()
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun determineHighLine(units: String): Double {
|
fun determineHighLine(): Double {
|
||||||
var highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(bgTargetHigh, units))!!
|
var highLineSetting = SP.getDouble(R.string.key_high_mark, bgTargetHigh)
|
||||||
if (highLineSetting < 1)
|
if (highLineSetting < 1) highLineSetting = 180.0
|
||||||
highLineSetting = Profile.fromMgdlToUnits(180.0, units)
|
highLineSetting = Profile.toCurrentUnits(highLineSetting)
|
||||||
return highLineSetting
|
return highLineSetting
|
||||||
}
|
}
|
||||||
|
|
||||||
fun determineLowLine(): Double {
|
fun determineLowLine(): Double {
|
||||||
val profile = ProfileFunctions.getInstance().profile ?: return bgTargetLow
|
var lowLineSetting = SP.getDouble(R.string.key_low_mark, bgTargetLow)
|
||||||
return determineLowLine(profile.units)
|
if (lowLineSetting < 1) lowLineSetting = 76.0
|
||||||
}
|
lowLineSetting = Profile.toCurrentUnits(lowLineSetting)
|
||||||
|
|
||||||
fun determineLowLine(units: String): Double {
|
|
||||||
var lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(bgTargetLow, units))!!
|
|
||||||
if (lowLineSetting < 1)
|
|
||||||
lowLineSetting = Profile.fromMgdlToUnits(76.0, units)
|
|
||||||
return lowLineSetting
|
return lowLineSetting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis
|
||||||
view.findViewById(R.id.ok).setOnClickListener(this);
|
view.findViewById(R.id.ok).setOnClickListener(this);
|
||||||
view.findViewById(R.id.cancel).setOnClickListener(this);
|
view.findViewById(R.id.cancel).setOnClickListener(this);
|
||||||
|
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
|
Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
|
||||||
|
|
||||||
bgNumber = (NumberPicker) view.findViewById(R.id.overview_calibration_bg);
|
bgNumber = (NumberPicker) view.findViewById(R.id.overview_calibration_bg);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.general.overview.dialogs;
|
package info.nightscout.androidaps.plugins.general.overview.dialogs;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.HandlerThread;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -316,36 +315,36 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
||||||
int carbs = editCarbs.getValue().intValue();
|
int carbs = editCarbs.getValue().intValue();
|
||||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
||||||
|
|
||||||
final String units = currentProfile.getUnits();
|
final String units = ProfileFunctions.getSystemUnits();
|
||||||
DefaultValueHelper helper = new DefaultValueHelper();
|
DefaultValueHelper helper = new DefaultValueHelper();
|
||||||
|
|
||||||
int activityTTDuration = helper.determineActivityTTDuration();
|
int activityTTDuration = helper.determineActivityTTDuration();
|
||||||
double activityTT = helper.determineActivityTT(units);
|
double activityTT = helper.determineActivityTT();
|
||||||
|
|
||||||
int eatingSoonTTDuration = helper.determineEatingSoonTTDuration();
|
int eatingSoonTTDuration = helper.determineEatingSoonTTDuration();
|
||||||
double eatingSoonTT = helper.determineEatingSoonTT(units);
|
double eatingSoonTT = helper.determineEatingSoonTT();
|
||||||
|
|
||||||
int hypoTTDuration = helper.determineHypoTTDuration();
|
int hypoTTDuration = helper.determineHypoTTDuration();
|
||||||
double hypoTT = helper.determineHypoTT(units);
|
double hypoTT = helper.determineHypoTT();
|
||||||
|
|
||||||
List<String> actions = new LinkedList<>();
|
List<String> actions = new LinkedList<>();
|
||||||
|
|
||||||
if (startActivityTTCheckbox.isChecked()) {
|
if (startActivityTTCheckbox.isChecked()) {
|
||||||
String unitLabel = "mg/dl";
|
String unitLabel = "mg/dl";
|
||||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
unitLabel = "mmol/l";
|
unitLabel = "mmol/l";
|
||||||
}
|
}
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)</font>");
|
||||||
}
|
}
|
||||||
if (startEatingSoonTTCheckbox.isChecked()) {
|
if (startEatingSoonTTCheckbox.isChecked()) {
|
||||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)</font>");
|
||||||
} else {
|
} else {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)</font>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (startHypoTTCheckbox.isChecked()) {
|
if (startHypoTTCheckbox.isChecked()) {
|
||||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(hypoTT) + " mmol/l (" + hypoTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(hypoTT) + " mmol/l (" + hypoTTDuration + " min)</font>");
|
||||||
} else {
|
} else {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(hypoTT) + " mg/dl (" + hypoTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(hypoTT) + " mg/dl (" + hypoTTDuration + " min)</font>");
|
||||||
|
@ -398,8 +397,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
||||||
.duration(finalActivityTTDuration)
|
.duration(finalActivityTTDuration)
|
||||||
.reason(MainApp.gs(R.string.activity))
|
.reason(MainApp.gs(R.string.activity))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits()));
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (startEatingSoonTTCheckbox.isChecked()) {
|
} else if (startEatingSoonTTCheckbox.isChecked()) {
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
|
@ -407,8 +406,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
||||||
.duration(finalEatingSoonTTDuration)
|
.duration(finalEatingSoonTTDuration)
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(MainApp.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()));
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (startHypoTTCheckbox.isChecked()) {
|
} else if (startHypoTTCheckbox.isChecked()) {
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
|
@ -416,8 +415,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
||||||
.duration(finalHypoTTDuration)
|
.duration(finalHypoTTDuration)
|
||||||
.reason(MainApp.gs(R.string.hypo))
|
.reason(MainApp.gs(R.string.hypo))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits()));
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.HandlerThread;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -56,9 +55,9 @@ import static info.nightscout.androidaps.utils.DateUtil.now;
|
||||||
public class NewInsulinDialog extends DialogFragment implements OnClickListener {
|
public class NewInsulinDialog extends DialogFragment implements OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class);
|
private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class);
|
||||||
|
|
||||||
public static final double PLUS1_DEFAULT = 0.5d;
|
private static final double PLUS1_DEFAULT = 0.5d;
|
||||||
public static final double PLUS2_DEFAULT = 1d;
|
private static final double PLUS2_DEFAULT = 1d;
|
||||||
public static final double PLUS3_DEFAULT = 2d;
|
private static final double PLUS3_DEFAULT = 2d;
|
||||||
|
|
||||||
private CheckBox startEatingSoonTTCheckbox;
|
private CheckBox startEatingSoonTTCheckbox;
|
||||||
private CheckBox recordOnlyCheckbox;
|
private CheckBox recordOnlyCheckbox;
|
||||||
|
@ -207,9 +206,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
|
||||||
okClicked = true;
|
okClicked = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Profile currentProfile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
if (currentProfile == null || pump == null)
|
if (pump == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||||
|
@ -228,11 +226,11 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
|
||||||
|
|
||||||
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
|
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
|
||||||
eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration;
|
eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration;
|
||||||
double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl);
|
double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, ProfileFunctions.getSystemUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl);
|
||||||
eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl;
|
eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : ProfileFunctions.getSystemUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl;
|
||||||
|
|
||||||
if (startEatingSoonTTCheckbox.isChecked()) {
|
if (startEatingSoonTTCheckbox.isChecked()) {
|
||||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)</font>");
|
||||||
} else
|
} else
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)</font>");
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)</font>");
|
||||||
|
@ -272,8 +270,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
|
||||||
.duration(finalEatingSoonTTDuration)
|
.duration(finalEatingSoonTTDuration)
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(MainApp.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()));
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ class WizardDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val profileList: ArrayList<CharSequence>
|
val profileList: ArrayList<CharSequence>
|
||||||
profileList = profileStore.profileList
|
profileList = profileStore.getProfileList()
|
||||||
profileList.add(0, MainApp.gs(R.string.active))
|
profileList.add(0, MainApp.gs(R.string.active))
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||||
|
@ -222,7 +222,7 @@ class WizardDialog : DialogFragment() {
|
||||||
} ?: return
|
} ?: return
|
||||||
|
|
||||||
|
|
||||||
val units = profile.units
|
val units = ProfileFunctions.getSystemUnits()
|
||||||
treatments_wizard_bgunits.text = units
|
treatments_wizard_bgunits.text = units
|
||||||
if (units == Constants.MGDL)
|
if (units == Constants.MGDL)
|
||||||
treatments_wizard_bg_input.setStep(1.0)
|
treatments_wizard_bg_input.setStep(1.0)
|
||||||
|
@ -302,7 +302,7 @@ class WizardDialog : DialogFragment() {
|
||||||
treatment_wizard_notes.text.toString(), carbTime)
|
treatment_wizard_notes.text.toString(), carbTime)
|
||||||
|
|
||||||
wizard?.let { wizard ->
|
wizard?.let { wizard ->
|
||||||
treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, specificProfile.units)).valueToUnitsToString(specificProfile.units), wizard.sens)
|
treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, ProfileFunctions.getSystemUnits())).valueToUnitsToString(ProfileFunctions.getSystemUnits()), wizard.sens)
|
||||||
treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG)
|
treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG)
|
||||||
|
|
||||||
treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic)
|
treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic)
|
||||||
|
@ -320,8 +320,8 @@ class WizardDialog : DialogFragment() {
|
||||||
// Trend
|
// Trend
|
||||||
if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) {
|
if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) {
|
||||||
treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "")
|
treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "")
|
||||||
+ Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, specificProfile.units)
|
+ Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, ProfileFunctions.getSystemUnits())
|
||||||
+ " " + specificProfile.units)
|
+ " " + ProfileFunctions.getSystemUnits())
|
||||||
} else {
|
} else {
|
||||||
treatments_wizard_bgtrend.text = ""
|
treatments_wizard_bgtrend.text = ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class GraphData {
|
||||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||||
|
|
||||||
public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
|
public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
|
||||||
units = ProfileFunctions.getInstance().getProfileUnits();
|
units = ProfileFunctions.getSystemUnits();
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||||
}
|
}
|
||||||
|
@ -264,9 +264,9 @@ public class GraphData {
|
||||||
TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time);
|
TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time);
|
||||||
double value;
|
double value;
|
||||||
if (tt == null) {
|
if (tt == null) {
|
||||||
value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2;
|
value = Profile.fromMgdlToUnits((profile.getTargetLowMgdl(time) + profile.getTargetHighMgdl(time)) / 2, ProfileFunctions.getSystemUnits());
|
||||||
} else {
|
} else {
|
||||||
value = Profile.fromMgdlToUnits(tt.target(), profile.getUnits());
|
value = Profile.fromMgdlToUnits(tt.target(), ProfileFunctions.getSystemUnits());
|
||||||
}
|
}
|
||||||
if (lastTarget != value) {
|
if (lastTarget != value) {
|
||||||
if (lastTarget != -1)
|
if (lastTarget != -1)
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class PersistentNotificationPlugin extends PluginBase {
|
||||||
line1 = MainApp.gs(R.string.loading);
|
line1 = MainApp.gs(R.string.loading);
|
||||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) {
|
} else if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) {
|
||||||
String line1_aa;
|
String line1_aa;
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
|
|
||||||
|
|
||||||
BgReading lastBG = DatabaseHelper.lastBg();
|
BgReading lastBG = DatabaseHelper.lastBg();
|
||||||
|
|
|
@ -259,7 +259,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
val actualBG = DatabaseHelper.actualBg()
|
val actualBG = DatabaseHelper.actualBg()
|
||||||
val lastBG = DatabaseHelper.lastBg()
|
val lastBG = DatabaseHelper.lastBg()
|
||||||
var reply = ""
|
var reply = ""
|
||||||
val units = ProfileFunctions.getInstance().profileUnits
|
val units = ProfileFunctions.getSystemUnits()
|
||||||
if (actualBG != null) {
|
if (actualBG != null) {
|
||||||
reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "
|
reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "
|
||||||
} else if (lastBG != null) {
|
} else if (lastBG != null) {
|
||||||
|
@ -428,7 +428,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val list = store.profileList
|
val list = store.getProfileList()
|
||||||
if (splitted[1].toUpperCase(Locale.getDefault()) == "STATUS") {
|
if (splitted[1].toUpperCase(Locale.getDefault()) == "STATUS") {
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().profileName))
|
sendSMS(Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().profileName))
|
||||||
} else if (splitted[1].toUpperCase(Locale.getDefault()) == "LIST") {
|
} else if (splitted[1].toUpperCase(Locale.getDefault()) == "LIST") {
|
||||||
|
@ -735,8 +735,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
|
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
val currentProfile = ProfileFunctions.getInstance().profile
|
val units = ProfileFunctions.getSystemUnits()
|
||||||
if (currentProfile != null) {
|
|
||||||
var keyDuration = 0
|
var keyDuration = 0
|
||||||
var defaultTargetDuration = 0
|
var defaultTargetDuration = 0
|
||||||
var keyTarget = 0
|
var keyTarget = 0
|
||||||
|
@ -763,22 +762,20 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
var ttDuration = SP.getInt(keyDuration, defaultTargetDuration)
|
var ttDuration = SP.getInt(keyDuration, defaultTargetDuration)
|
||||||
ttDuration = if (ttDuration > 0) ttDuration else defaultTargetDuration
|
ttDuration = if (ttDuration > 0) ttDuration else defaultTargetDuration
|
||||||
var tt = SP.getDouble(keyTarget, if (currentProfile.units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL)
|
var tt = SP.getDouble(keyTarget, if (units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL)
|
||||||
tt = if (tt > 0) tt else if (currentProfile.units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL
|
tt = Profile.toCurrentUnits(tt)
|
||||||
|
tt = if (tt > 0) tt else if (units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(ttDuration)
|
.duration(ttDuration)
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(MainApp.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(tt, currentProfile.units))
|
.low(Profile.toMgdl(tt, units))
|
||||||
.high(Profile.toMgdl(tt, currentProfile.units))
|
.high(Profile.toMgdl(tt, units))
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
||||||
val ttString = if (currentProfile.units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
|
val ttString = if (units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
|
||||||
val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
|
val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
|
||||||
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
|
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
|
||||||
} else {
|
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (isStop) {
|
} else if (isStop) {
|
||||||
|
@ -787,8 +784,6 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
|
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
val currentProfile = ProfileFunctions.getInstance().profile
|
|
||||||
if (currentProfile != null) {
|
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.date(DateUtil.now())
|
.date(DateUtil.now())
|
||||||
|
@ -798,9 +793,6 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
||||||
val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_canceled))
|
val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_canceled))
|
||||||
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
|
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
|
||||||
} else {
|
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -41,12 +41,12 @@ class ProfileElement private constructor(ps: ProfileSwitch)
|
||||||
checkNotNull(profile)
|
checkNotNull(profile)
|
||||||
for (br in profile.basalValues)
|
for (br in profile.basalValues)
|
||||||
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
|
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
|
||||||
for (target in profile.singleTargets)
|
for (target in profile.singleTargetsMgdl)
|
||||||
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, Profile.toMgdl(target.value, profile.units)))
|
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value))
|
||||||
for (ic in profile.ics)
|
for (ic in profile.ics)
|
||||||
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value))
|
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value))
|
||||||
for (isf in profile.isfs)
|
for (isf in profile.isfsMgdl)
|
||||||
insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, Profile.toMgdl(isf.value, profile.units)))
|
insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class BasalProfile internal constructor(
|
inner class BasalProfile internal constructor(
|
||||||
|
|
|
@ -131,12 +131,7 @@ public class ActionStringHandler {
|
||||||
///////////////////////////////////////////////////////// TEMPTARGET
|
///////////////////////////////////////////////////////// TEMPTARGET
|
||||||
boolean isMGDL = Boolean.parseBoolean(act[1]);
|
boolean isMGDL = Boolean.parseBoolean(act[1]);
|
||||||
|
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MGDL) != isMGDL) {
|
||||||
if (profile == null) {
|
|
||||||
sendError("No profile found!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (profile.getUnits().equals(Constants.MGDL) != isMGDL) {
|
|
||||||
sendError("Different units used on watch and phone!");
|
sendError("Different units used on watch and phone!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +217,7 @@ public class ActionStringHandler {
|
||||||
DecimalFormat format = new DecimalFormat("0.00");
|
DecimalFormat format = new DecimalFormat("0.00");
|
||||||
DecimalFormat formatInt = new DecimalFormat("0");
|
DecimalFormat formatInt = new DecimalFormat("0");
|
||||||
BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(),
|
BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(),
|
||||||
carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profile.getUnits()),
|
carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(ProfileFunctions.getSystemUnits()),
|
||||||
0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend);
|
0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend);
|
||||||
|
|
||||||
if (Math.abs(bolusWizard.getInsulinAfterConstraints() - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) {
|
if (Math.abs(bolusWizard.getInsulinAfterConstraints() - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) {
|
||||||
|
@ -534,14 +529,14 @@ public class ActionStringHandler {
|
||||||
//Check for Temp-Target:
|
//Check for Temp-Target:
|
||||||
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory();
|
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory();
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits());
|
ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, ProfileFunctions.getSystemUnits());
|
||||||
ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
|
ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
|
||||||
ret += "\n\n";
|
ret += "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += "DEFAULT RANGE: ";
|
ret += "DEFAULT RANGE: ";
|
||||||
ret += profile.getTargetLow() + " - " + profile.getTargetHigh();
|
ret += Profile.fromMgdlToUnits(profile.getTargetLowMgdl(), ProfileFunctions.getSystemUnits()) + " - " + Profile.fromMgdlToUnits(profile.getTargetHighMgdl(), ProfileFunctions.getSystemUnits());
|
||||||
ret += " target: " + profile.getTarget();
|
ret += " target: " + Profile.fromMgdlToUnits(profile.getTargetMgdl(), ProfileFunctions.getSystemUnits());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.general.wear.wearintegration;
|
package info.nightscout.androidaps.plugins.general.wear.wearintegration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
@ -17,9 +10,10 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
import com.google.android.gms.wearable.CapabilityApi;
|
import com.google.android.gms.wearable.CapabilityApi;
|
||||||
|
@ -32,31 +26,37 @@ import com.google.android.gms.wearable.PutDataRequest;
|
||||||
import com.google.android.gms.wearable.Wearable;
|
import com.google.android.gms.wearable.Wearable;
|
||||||
import com.google.android.gms.wearable.WearableListenerService;
|
import com.google.android.gms.wearable.WearableListenerService;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
|
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
|
||||||
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
|
|
||||||
public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
||||||
|
@ -88,7 +88,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
|
|
||||||
|
|
||||||
boolean wear_integration = false;
|
boolean wear_integration = false;
|
||||||
SharedPreferences mPrefs;
|
|
||||||
private static boolean lastLoopStatus;
|
private static boolean lastLoopStatus;
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
|
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
|
||||||
|
@ -108,7 +107,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
||||||
listenForChangeInSettings();
|
listenForChangeInSettings();
|
||||||
setSettings();
|
setSettings();
|
||||||
if (wear_integration) {
|
if (wear_integration) {
|
||||||
|
@ -303,10 +301,10 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
|
|
||||||
|
|
||||||
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
|
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
|
|
||||||
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
|
Double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
|
||||||
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
|
Double highLine = OverviewPlugin.INSTANCE.determineHighLine();
|
||||||
|
|
||||||
// convert to mg/dl
|
// convert to mg/dl
|
||||||
if (!units.equals(Constants.MGDL)) {
|
if (!units.equals(Constants.MGDL)) {
|
||||||
|
@ -323,7 +321,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
highLine = OverviewPlugin.INSTANCE.getBgTargetHigh();
|
highLine = OverviewPlugin.INSTANCE.getBgTargetHigh();
|
||||||
}
|
}
|
||||||
|
|
||||||
long sgvLevel = 0l;
|
long sgvLevel = 0L;
|
||||||
if (lastBG.value > highLine) {
|
if (lastBG.value > highLine) {
|
||||||
sgvLevel = 1;
|
sgvLevel = 1;
|
||||||
} else if (lastBG.value < lowLine) {
|
} else if (lastBG.value < lowLine) {
|
||||||
|
@ -721,7 +719,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
//bgi
|
//bgi
|
||||||
|
|
||||||
|
|
||||||
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf();
|
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.fromMgdlToUnits(profile.getIsfMgdl(), ProfileFunctions.getSystemUnits());
|
||||||
bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi);
|
bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi);
|
||||||
|
|
||||||
status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString);
|
status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString);
|
||||||
|
@ -748,14 +746,14 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
dataMapRequest.getDataMap().putString("externalStatusString", status);
|
dataMapRequest.getDataMap().putString("externalStatusString", status);
|
||||||
dataMapRequest.getDataMap().putString("iobSum", iobSum);
|
dataMapRequest.getDataMap().putString("iobSum", iobSum);
|
||||||
dataMapRequest.getDataMap().putString("iobDetail", iobDetail);
|
dataMapRequest.getDataMap().putString("iobDetail", iobDetail);
|
||||||
dataMapRequest.getDataMap().putBoolean("detailedIob", mPrefs.getBoolean("wear_detailediob", false));
|
dataMapRequest.getDataMap().putBoolean("detailedIob", SP.getBoolean(R.string.key_wear_detailediob, false));
|
||||||
dataMapRequest.getDataMap().putString("cob", cobString);
|
dataMapRequest.getDataMap().putString("cob", cobString);
|
||||||
dataMapRequest.getDataMap().putString("currentBasal", currentBasal);
|
dataMapRequest.getDataMap().putString("currentBasal", currentBasal);
|
||||||
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
|
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
|
||||||
dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
|
dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
|
||||||
dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus);
|
dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus);
|
||||||
dataMapRequest.getDataMap().putString("bgi", bgiString);
|
dataMapRequest.getDataMap().putString("bgi", bgiString);
|
||||||
dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false));
|
dataMapRequest.getDataMap().putBoolean("showBgi", SP.getBoolean(R.string.key_wear_showbgi, false));
|
||||||
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);
|
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);
|
||||||
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||||
debugData("sendStatus", putDataRequest);
|
debugData("sendStatus", putDataRequest);
|
||||||
|
@ -818,7 +816,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
}
|
}
|
||||||
|
|
||||||
String iobString = "";
|
String iobString = "";
|
||||||
if (mPrefs.getBoolean("wear_detailediob", false)) {
|
if (SP.getBoolean(R.string.key_wear_detailediob, false)) {
|
||||||
iobString = iobSum + " " + iobDetail;
|
iobString = iobSum + " " + iobDetail;
|
||||||
} else {
|
} else {
|
||||||
iobString = iobSum + "U";
|
iobString = iobSum + "U";
|
||||||
|
@ -827,7 +825,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
||||||
status += currentBasal + " " + iobString;
|
status += currentBasal + " " + iobString;
|
||||||
|
|
||||||
//add BGI if shown, otherwise return
|
//add BGI if shown, otherwise return
|
||||||
if (mPrefs.getBoolean("wear_showbgi", false)) {
|
if (SP.getBoolean(R.string.key_wear_showbgi, false)) {
|
||||||
status += " " + bgiString;
|
status += " " + bgiString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ public class StatuslinePlugin extends PluginBase {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf();
|
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.fromMgdlToUnits(profile.getIsfMgdl(), ProfileFunctions.getSystemUnits());
|
||||||
|
|
||||||
status += " " + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to2Decimal(bgi);
|
status += " " + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to2Decimal(bgi);
|
||||||
status += " " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "StatuslinePlugin").generateCOBString();
|
status += " " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "StatuslinePlugin").generateCOBString();
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class InsulinFragment extends Fragment {
|
||||||
private void updateGUI() {
|
private void updateGUI() {
|
||||||
insulinName.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getFriendlyName());
|
insulinName.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getFriendlyName());
|
||||||
insulinComment.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getComment());
|
insulinComment.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getComment());
|
||||||
insulinDia.setText(MainApp.gs(R.string.dia) + " " + ConfigBuilderPlugin.getPlugin().getActiveInsulin().getDia() + "h");
|
insulinDia.setText(MainApp.gs(R.string.dia) + ": " + ConfigBuilderPlugin.getPlugin().getActiveInsulin().getDia() + "h");
|
||||||
insulinGraph.show(ConfigBuilderPlugin.getPlugin().getActiveInsulin());
|
insulinGraph.show(ConfigBuilderPlugin.getPlugin().getActiveInsulin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class AutosensData implements DataPointWithLabelInterface {
|
||||||
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) {
|
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) {
|
||||||
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile(t.date);
|
Profile profile = ProfileFunctions.getInstance().getProfile(t.date);
|
||||||
double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits());
|
double sens = profile.getIsfMgdl(t.date);
|
||||||
double ic = profile.getIc(t.date);
|
double ic = profile.getIc(t.date);
|
||||||
min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic;
|
min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic;
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
|
|
|
@ -149,7 +149,7 @@ public class IobCobOref1Thread extends Thread {
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")");
|
log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")");
|
||||||
|
|
||||||
double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits());
|
double sens = profile.getIsfMgdl(bgTime);
|
||||||
|
|
||||||
AutosensData autosensData = new AutosensData();
|
AutosensData autosensData = new AutosensData();
|
||||||
autosensData.time = bgTime;
|
autosensData.time = bgTime;
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class IobCobThread extends Thread {
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")");
|
log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")");
|
||||||
|
|
||||||
double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits());
|
double sens = profile.getIsfMgdl(bgTime);
|
||||||
|
|
||||||
AutosensData autosensData = new AutosensData();
|
AutosensData autosensData = new AutosensData();
|
||||||
autosensData.time = bgTime;
|
autosensData.time = bgTime;
|
||||||
|
|
|
@ -1,212 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.profile.local;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
import info.nightscout.androidaps.utils.NumberPicker;
|
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
|
||||||
import info.nightscout.androidaps.utils.TimeListEdit;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
|
||||||
|
|
||||||
import static info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA;
|
|
||||||
|
|
||||||
public class LocalProfileFragment extends Fragment {
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
private NumberPicker diaView;
|
|
||||||
private RadioButton mgdlView;
|
|
||||||
private RadioButton mmolView;
|
|
||||||
private TimeListEdit basalView;
|
|
||||||
private Button profileswitchButton;
|
|
||||||
private Button resetButton;
|
|
||||||
private Button saveButton;
|
|
||||||
|
|
||||||
private TextView invalidProfile;
|
|
||||||
|
|
||||||
private Runnable save = () -> {
|
|
||||||
doEdit();
|
|
||||||
if (basalView != null) {
|
|
||||||
basalView.updateLabel(MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private TextWatcher textWatch = new TextWatcher() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start,
|
|
||||||
int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start,
|
|
||||||
int before, int count) {
|
|
||||||
LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
|
|
||||||
doEdit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription();
|
|
||||||
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
|
|
||||||
diaView = layout.findViewById(R.id.localprofile_dia);
|
|
||||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, layout.findViewById(R.id.localprofile_save), textWatch);
|
|
||||||
mgdlView = layout.findViewById(R.id.localprofile_mgdl);
|
|
||||||
mmolView = layout.findViewById(R.id.localprofile_mmol);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
profileswitchButton = layout.findViewById(R.id.localprofile_profileswitch);
|
|
||||||
resetButton = layout.findViewById(R.id.localprofile_reset);
|
|
||||||
saveButton = layout.findViewById(R.id.localprofile_save);
|
|
||||||
|
|
||||||
|
|
||||||
invalidProfile = layout.findViewById(R.id.invalidprofile);
|
|
||||||
|
|
||||||
if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isTempBasalCapable) {
|
|
||||||
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
|
||||||
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
|
|
||||||
|
|
||||||
mgdlView.setOnClickListener(v -> {
|
|
||||||
LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
|
|
||||||
LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl;
|
|
||||||
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
|
|
||||||
doEdit();
|
|
||||||
});
|
|
||||||
mmolView.setOnClickListener(v -> {
|
|
||||||
LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked();
|
|
||||||
LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol;
|
|
||||||
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
|
||||||
doEdit();
|
|
||||||
});
|
|
||||||
|
|
||||||
profileswitchButton.setOnClickListener(view -> {
|
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
|
||||||
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT;
|
|
||||||
profileswitch.executeProfileSwitch = true;
|
|
||||||
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
|
||||||
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
|
|
||||||
});
|
|
||||||
|
|
||||||
resetButton.setOnClickListener(view -> {
|
|
||||||
LocalProfilePlugin.getPlugin().loadSettings();
|
|
||||||
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
|
||||||
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
|
|
||||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.localprofile_save), textWatch);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
|
|
||||||
new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
|
|
||||||
updateGUI();
|
|
||||||
});
|
|
||||||
|
|
||||||
saveButton.setOnClickListener(view -> {
|
|
||||||
if (!LocalProfilePlugin.getPlugin().isValidEditState()) {
|
|
||||||
return; //Should not happen as saveButton should not be visible if not valid
|
|
||||||
}
|
|
||||||
LocalProfilePlugin.getPlugin().storeSettings();
|
|
||||||
updateGUI();
|
|
||||||
});
|
|
||||||
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
disposable.add(RxBus.INSTANCE
|
|
||||||
.toObservable(EventInitializationChanged.class)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
|
||||||
);
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
disposable.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doEdit() {
|
|
||||||
LocalProfilePlugin.getPlugin().setEdited(true);
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getSumLabel() {
|
|
||||||
ProfileStore profile = LocalProfilePlugin.getPlugin().createProfileStore();
|
|
||||||
if (profile != null)
|
|
||||||
return " ∑" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + MainApp.gs(R.string.insulin_unit_shortname);
|
|
||||||
else
|
|
||||||
return MainApp.gs(R.string.localprofile);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
|
|
||||||
boolean isEdited = LocalProfilePlugin.getPlugin().isEdited();
|
|
||||||
if (isValid) {
|
|
||||||
invalidProfile.setVisibility(View.GONE); //show invalid profile
|
|
||||||
|
|
||||||
if (isEdited) {
|
|
||||||
//edited profile -> save first
|
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
|
||||||
saveButton.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
|
||||||
saveButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
invalidProfile.setVisibility(View.VISIBLE);
|
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
|
||||||
saveButton.setVisibility(View.GONE); //don't save an invalid profile
|
|
||||||
}
|
|
||||||
|
|
||||||
//Show reset button iff data was edited
|
|
||||||
if (isEdited) {
|
|
||||||
resetButton.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
resetButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,265 @@
|
||||||
|
package info.nightscout.androidaps.plugins.profile.local
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment
|
||||||
|
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog
|
||||||
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA
|
||||||
|
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
|
||||||
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import kotlinx.android.synthetic.main.localprofile_fragment.*
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
|
class LocalProfileFragment : Fragment() {
|
||||||
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
private var basalView: TimeListEdit? = null
|
||||||
|
private var spinner: SpinnerHelper? = null
|
||||||
|
|
||||||
|
private val save = Runnable {
|
||||||
|
doEdit()
|
||||||
|
basalView?.updateLabel(MainApp.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel())
|
||||||
|
}
|
||||||
|
|
||||||
|
private val textWatch = object : TextWatcher {
|
||||||
|
override fun afterTextChanged(s: Editable) {}
|
||||||
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||||
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||||
|
LocalProfilePlugin.currentProfile().dia = SafeParse.stringToDouble(localprofile_dia.text.toString())
|
||||||
|
LocalProfilePlugin.currentProfile().name = localprofile_name.text.toString()
|
||||||
|
doEdit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sumLabel(): String {
|
||||||
|
val profile = LocalProfilePlugin.createProfileStore().getDefaultProfile()
|
||||||
|
val sum = profile?.baseBasalSum() ?: 0.0
|
||||||
|
return " ∑" + DecimalFormatter.to2Decimal(sum) + MainApp.gs(R.string.insulin_unit_shortname)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.localprofile_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
// activate DIA tab
|
||||||
|
processVisibilityOnClick(dia_tab)
|
||||||
|
localprofile_dia_placeholder.visibility = View.VISIBLE
|
||||||
|
// setup listeners
|
||||||
|
dia_tab.setOnClickListener {
|
||||||
|
processVisibilityOnClick(it)
|
||||||
|
localprofile_dia_placeholder.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
ic_tab.setOnClickListener {
|
||||||
|
processVisibilityOnClick(it)
|
||||||
|
localprofile_ic.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
isf_tab.setOnClickListener {
|
||||||
|
processVisibilityOnClick(it)
|
||||||
|
localprofile_isf.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
basal_tab.setOnClickListener {
|
||||||
|
processVisibilityOnClick(it)
|
||||||
|
localprofile_basal.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
target_tab.setOnClickListener {
|
||||||
|
processVisibilityOnClick(it)
|
||||||
|
localprofile_target.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build() {
|
||||||
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
||||||
|
val units = if (LocalProfilePlugin.currentProfile().mgdl) Constants.MGDL else Constants.MMOL
|
||||||
|
|
||||||
|
localprofile_name.removeTextChangedListener(textWatch)
|
||||||
|
localprofile_name.setText(LocalProfilePlugin.currentProfile().name)
|
||||||
|
localprofile_name.addTextChangedListener(textWatch)
|
||||||
|
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, HardLimits.MINDIA, HardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label), LocalProfilePlugin.currentProfile().ic, null, HardLimits.MINIC, HardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save)
|
||||||
|
basalView = TimeListEdit(context, view, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), LocalProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||||
|
if (units == Constants.MGDL) {
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label), LocalProfilePlugin.currentProfile().isf, null, HardLimits.MINISF, HardLimits.MAXISF, 1.0, DecimalFormat("0"), save)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label), LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save)
|
||||||
|
} else {
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label), LocalProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(HardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label), LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spinner
|
||||||
|
spinner = SpinnerHelper(view?.findViewById(R.id.localprofile_spinner))
|
||||||
|
val profileList: ArrayList<CharSequence> = LocalProfilePlugin.profile?.getProfileList()
|
||||||
|
?: ArrayList()
|
||||||
|
context?.let { context ->
|
||||||
|
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||||
|
spinner?.adapter = adapter
|
||||||
|
spinner?.setSelection(LocalProfilePlugin.currentProfileIndex)
|
||||||
|
} ?: return
|
||||||
|
spinner?.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
if (LocalProfilePlugin.isEdited) {
|
||||||
|
activity?.let { activity ->
|
||||||
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantswitchprofile), {
|
||||||
|
LocalProfilePlugin.currentProfileIndex = position
|
||||||
|
build()
|
||||||
|
}, {
|
||||||
|
spinner?.setSelection(LocalProfilePlugin.currentProfileIndex)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LocalProfilePlugin.currentProfileIndex = position
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
localprofile_profile_add.setOnClickListener {
|
||||||
|
if (LocalProfilePlugin.isEdited) {
|
||||||
|
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
|
||||||
|
} else {
|
||||||
|
LocalProfilePlugin.addNewProfile()
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localprofile_profile_clone.setOnClickListener {
|
||||||
|
if (LocalProfilePlugin.isEdited) {
|
||||||
|
activity?.let { OKDialog.show(it, "", MainApp.gs(R.string.saveorresetchangesfirst), null) }
|
||||||
|
} else {
|
||||||
|
LocalProfilePlugin.cloneProfile()
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localprofile_profile_remove.setOnClickListener {
|
||||||
|
activity?.let { activity ->
|
||||||
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.deletecurrentprofile), {
|
||||||
|
LocalProfilePlugin.removeCurrentProfile()
|
||||||
|
build()
|
||||||
|
}, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is probably not possible because it leads to invalid profile
|
||||||
|
// if (!pumpDescription.isTempBasalCapable) localprofile_basal.visibility = View.GONE
|
||||||
|
|
||||||
|
@Suppress("SETTEXTL18N")
|
||||||
|
localprofile_units.text = MainApp.gs(R.string.units_colon) + " " + (if (LocalProfilePlugin.currentProfile().mgdl) MainApp.gs(R.string.mgdl) else MainApp.gs(R.string.mmol))
|
||||||
|
|
||||||
|
localprofile_profileswitch.setOnClickListener {
|
||||||
|
// TODO: select in dialog LocalProfilePlugin.currentProfileIndex
|
||||||
|
val newDialog = NewNSTreatmentDialog()
|
||||||
|
val profileSwitch = CareportalFragment.PROFILESWITCHDIRECT
|
||||||
|
profileSwitch.executeProfileSwitch = true
|
||||||
|
newDialog.setOptions(profileSwitch, R.string.careportal_profileswitch)
|
||||||
|
fragmentManager?.let { newDialog.show(it, "NewNSTreatmentDialog") }
|
||||||
|
}
|
||||||
|
|
||||||
|
localprofile_reset.setOnClickListener {
|
||||||
|
LocalProfilePlugin.loadSettings()
|
||||||
|
@Suppress("SETTEXTL18N")
|
||||||
|
localprofile_units.text = MainApp.gs(R.string.units_colon) + " " + (if (LocalProfilePlugin.currentProfile().mgdl) MainApp.gs(R.string.mgdl) else MainApp.gs(R.string.mmol))
|
||||||
|
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, MIN_DIA, 12.0, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.currentProfile().ic, null, 0.5, 50.0, 0.1, DecimalFormat("0.0"), save)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.currentProfile().isf, null, 0.5, 500.0, 0.1, DecimalFormat("0.0"), save)
|
||||||
|
basalView = TimeListEdit(context, view, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), LocalProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
|
||||||
|
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, 3.0, 200.0, 0.1, DecimalFormat("0.0"), save)
|
||||||
|
updateGUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
localprofile_save.setOnClickListener {
|
||||||
|
if (!LocalProfilePlugin.isValidEditState()) {
|
||||||
|
return@setOnClickListener //Should not happen as saveButton should not be visible if not valid
|
||||||
|
}
|
||||||
|
LocalProfilePlugin.storeSettings(activity)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
updateGUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
disposable.add(RxBus
|
||||||
|
.toObservable(EventLocalProfileChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ build() }, { FabricPrivacy.logException(it) })
|
||||||
|
)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doEdit() {
|
||||||
|
LocalProfilePlugin.isEdited = true
|
||||||
|
updateGUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateGUI() {
|
||||||
|
if (localprofile_profileswitch == null) return
|
||||||
|
val isValid = LocalProfilePlugin.isValidEditState()
|
||||||
|
val isEdited = LocalProfilePlugin.isEdited
|
||||||
|
if (isValid) {
|
||||||
|
this.view?.setBackgroundColor(MainApp.gc(R.color.ok_background))
|
||||||
|
|
||||||
|
if (isEdited) {
|
||||||
|
//edited profile -> save first
|
||||||
|
localprofile_profileswitch.visibility = View.GONE
|
||||||
|
localprofile_save.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
localprofile_profileswitch.visibility = View.VISIBLE
|
||||||
|
localprofile_save.visibility = View.GONE
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.view?.setBackgroundColor(MainApp.gc(R.color.error_background))
|
||||||
|
localprofile_profileswitch.visibility = View.GONE
|
||||||
|
localprofile_save.visibility = View.GONE //don't save an invalid profile
|
||||||
|
}
|
||||||
|
|
||||||
|
//Show reset button if data was edited
|
||||||
|
if (isEdited) {
|
||||||
|
localprofile_reset.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
localprofile_reset.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processVisibilityOnClick(selected: View) {
|
||||||
|
dia_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||||
|
ic_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||||
|
isf_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||||
|
basal_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||||
|
target_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||||
|
selected.setBackgroundColor(MainApp.gc(R.color.tabBgColorSelected))
|
||||||
|
localprofile_dia_placeholder.visibility = View.GONE
|
||||||
|
localprofile_ic.visibility = View.GONE
|
||||||
|
localprofile_isf.visibility = View.GONE
|
||||||
|
localprofile_basal.visibility = View.GONE
|
||||||
|
localprofile_target.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,231 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.profile.local;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.events.EventProfileStoreChanged;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.08.2016.
|
|
||||||
*/
|
|
||||||
public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
|
|
||||||
public static final String LOCAL_PROFILE = "LocalProfile";
|
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
|
|
||||||
|
|
||||||
private static LocalProfilePlugin localProfilePlugin;
|
|
||||||
|
|
||||||
public static LocalProfilePlugin getPlugin() {
|
|
||||||
if (localProfilePlugin == null)
|
|
||||||
localProfilePlugin = new LocalProfilePlugin();
|
|
||||||
return localProfilePlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProfileStore convertedProfile = null;
|
|
||||||
|
|
||||||
private static final String DEFAULTARRAY = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]";
|
|
||||||
|
|
||||||
public boolean isEdited() {
|
|
||||||
return edited;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEdited(boolean edited) {
|
|
||||||
this.edited = edited;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean edited;
|
|
||||||
boolean mgdl;
|
|
||||||
boolean mmol;
|
|
||||||
Double dia;
|
|
||||||
JSONArray ic;
|
|
||||||
JSONArray isf;
|
|
||||||
JSONArray basal;
|
|
||||||
JSONArray targetLow;
|
|
||||||
JSONArray targetHigh;
|
|
||||||
|
|
||||||
public LocalProfilePlugin() {
|
|
||||||
super(new PluginDescription()
|
|
||||||
.mainType(PluginType.PROFILE)
|
|
||||||
.fragmentClass(LocalProfileFragment.class.getName())
|
|
||||||
.pluginName(R.string.localprofile)
|
|
||||||
.shortName(R.string.localprofile_shortname)
|
|
||||||
.description(R.string.description_profile_local)
|
|
||||||
);
|
|
||||||
loadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void storeSettings() {
|
|
||||||
SP.putBoolean(LOCAL_PROFILE + "mmol", mmol);
|
|
||||||
SP.putBoolean(LOCAL_PROFILE + "mgdl", mgdl);
|
|
||||||
SP.putString(LOCAL_PROFILE + "dia", dia.toString());
|
|
||||||
SP.putString(LOCAL_PROFILE + "ic", ic.toString());
|
|
||||||
SP.putString(LOCAL_PROFILE + "isf", isf.toString());
|
|
||||||
SP.putString(LOCAL_PROFILE + "basal", basal.toString());
|
|
||||||
SP.putString(LOCAL_PROFILE + "targetlow", targetLow.toString());
|
|
||||||
SP.putString(LOCAL_PROFILE + "targethigh", targetHigh.toString());
|
|
||||||
|
|
||||||
createAndStoreConvertedProfile();
|
|
||||||
edited = false;
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
|
||||||
log.debug("Storing settings: " + getRawProfile().getData().toString());
|
|
||||||
RxBus.INSTANCE.send(new EventProfileStoreChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void loadSettings() {
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
|
||||||
log.debug("Loading stored settings");
|
|
||||||
|
|
||||||
mgdl = SP.getBoolean(LOCAL_PROFILE + "mgdl", false);
|
|
||||||
mmol = SP.getBoolean(LOCAL_PROFILE + "mmol", true);
|
|
||||||
dia = SP.getDouble(LOCAL_PROFILE + "dia", Constants.defaultDIA);
|
|
||||||
try {
|
|
||||||
ic = new JSONArray(SP.getString(LOCAL_PROFILE + "ic", DEFAULTARRAY));
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
try {
|
|
||||||
ic = new JSONArray(DEFAULTARRAY);
|
|
||||||
} catch (JSONException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
isf = new JSONArray(SP.getString(LOCAL_PROFILE + "isf", DEFAULTARRAY));
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
try {
|
|
||||||
isf = new JSONArray(DEFAULTARRAY);
|
|
||||||
} catch (JSONException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
basal = new JSONArray(SP.getString(LOCAL_PROFILE + "basal", DEFAULTARRAY));
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
try {
|
|
||||||
basal = new JSONArray(DEFAULTARRAY);
|
|
||||||
} catch (JSONException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
targetLow = new JSONArray(SP.getString(LOCAL_PROFILE + "targetlow", DEFAULTARRAY));
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
try {
|
|
||||||
targetLow = new JSONArray(DEFAULTARRAY);
|
|
||||||
} catch (JSONException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
targetHigh = new JSONArray(SP.getString(LOCAL_PROFILE + "targethigh", DEFAULTARRAY));
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
try {
|
|
||||||
targetHigh = new JSONArray(DEFAULTARRAY);
|
|
||||||
} catch (JSONException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
edited = false;
|
|
||||||
createAndStoreConvertedProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"_id": "576264a12771b7500d7ad184",
|
|
||||||
"startDate": "2016-06-16T08:35:00.000Z",
|
|
||||||
"defaultProfile": "Default",
|
|
||||||
"store": {
|
|
||||||
"Default": {
|
|
||||||
"dia": "3",
|
|
||||||
"carbratio": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "30"
|
|
||||||
}],
|
|
||||||
"carbs_hr": "20",
|
|
||||||
"delay": "20",
|
|
||||||
"sens": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "100"
|
|
||||||
}],
|
|
||||||
"timezone": "UTC",
|
|
||||||
"basal": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0.1"
|
|
||||||
}],
|
|
||||||
"target_low": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0"
|
|
||||||
}],
|
|
||||||
"target_high": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0"
|
|
||||||
}],
|
|
||||||
"startDate": "1970-01-01T00:00:00.000Z",
|
|
||||||
"units": "mmol"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"created_at": "2016-06-16T08:34:41.256Z"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
private void createAndStoreConvertedProfile() {
|
|
||||||
convertedProfile = createProfileStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isValidEditState() {
|
|
||||||
return createProfileStore().getDefaultProfile().isValid(MainApp.gs(R.string.localprofile), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public ProfileStore createProfileStore() {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
JSONObject store = new JSONObject();
|
|
||||||
JSONObject profile = new JSONObject();
|
|
||||||
|
|
||||||
try {
|
|
||||||
json.put("defaultProfile", LOCAL_PROFILE);
|
|
||||||
json.put("store", store);
|
|
||||||
profile.put("dia", dia);
|
|
||||||
profile.put("carbratio", ic);
|
|
||||||
profile.put("sens", isf);
|
|
||||||
profile.put("basal", basal);
|
|
||||||
profile.put("target_low", targetLow);
|
|
||||||
profile.put("target_high", targetHigh);
|
|
||||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
|
||||||
store.put(LOCAL_PROFILE, profile);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return new ProfileStore(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProfileStore getProfile() {
|
|
||||||
if (!convertedProfile.getDefaultProfile().isValid(MainApp.gs(R.string.localprofile)))
|
|
||||||
return null;
|
|
||||||
return convertedProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProfileStore getRawProfile() {
|
|
||||||
return convertedProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnits() {
|
|
||||||
return mgdl ? Constants.MGDL : Constants.MMOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProfileName() {
|
|
||||||
return DecimalFormatter.to2Decimal(convertedProfile.getDefaultProfile().percentageBasalSum()) + "U ";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,429 @@
|
||||||
|
package info.nightscout.androidaps.plugins.profile.local
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore
|
||||||
|
import info.nightscout.androidaps.events.EventProfileStoreChanged
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileInterface
|
||||||
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
object LocalProfilePlugin : PluginBase(PluginDescription()
|
||||||
|
.mainType(PluginType.PROFILE)
|
||||||
|
.fragmentClass(LocalProfileFragment::class.java.name)
|
||||||
|
.pluginName(R.string.localprofile)
|
||||||
|
.shortName(R.string.localprofile_shortname)
|
||||||
|
.description(R.string.description_profile_local)), ProfileInterface {
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
loadSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val log = LoggerFactory.getLogger(L.PROFILE)
|
||||||
|
|
||||||
|
private var rawProfile: ProfileStore? = null
|
||||||
|
|
||||||
|
const val LOCAL_PROFILE = "LocalProfile"
|
||||||
|
|
||||||
|
private const val DEFAULTARRAY = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]"
|
||||||
|
|
||||||
|
class SingleProfile {
|
||||||
|
internal var name: String? = null
|
||||||
|
internal var mgdl: Boolean = false
|
||||||
|
internal var dia: Double = Constants.defaultDIA
|
||||||
|
internal var ic: JSONArray? = null
|
||||||
|
internal var isf: JSONArray? = null
|
||||||
|
internal var basal: JSONArray? = null
|
||||||
|
internal var targetLow: JSONArray? = null
|
||||||
|
internal var targetHigh: JSONArray? = null
|
||||||
|
|
||||||
|
fun deepClone(): SingleProfile {
|
||||||
|
val sp = SingleProfile()
|
||||||
|
sp.name = name
|
||||||
|
sp.mgdl = mgdl
|
||||||
|
sp.dia = dia
|
||||||
|
sp.ic = JSONArray(ic.toString())
|
||||||
|
sp.isf = JSONArray(isf.toString())
|
||||||
|
sp.basal = JSONArray(basal.toString())
|
||||||
|
sp.targetLow = JSONArray(targetLow.toString())
|
||||||
|
sp.targetHigh = JSONArray(targetHigh.toString())
|
||||||
|
return sp
|
||||||
|
}
|
||||||
|
|
||||||
|
fun copyFrom(profile: Profile, newName: String): SingleProfile {
|
||||||
|
var verifiedName = newName
|
||||||
|
if (rawProfile?.getSpecificProfile(newName) != null) {
|
||||||
|
verifiedName += " " + DateUtil.now().toString()
|
||||||
|
}
|
||||||
|
val sp = SingleProfile()
|
||||||
|
sp.name = verifiedName
|
||||||
|
sp.mgdl = profile.units == Constants.MGDL
|
||||||
|
sp.dia = profile.dia
|
||||||
|
sp.ic = JSONArray(profile.data.getJSONArray("carbratio").toString())
|
||||||
|
sp.isf = JSONArray(profile.data.getJSONArray("sens").toString())
|
||||||
|
sp.basal = JSONArray(profile.data.getJSONArray("basal").toString())
|
||||||
|
sp.targetLow = JSONArray(profile.data.getJSONArray("target_low").toString())
|
||||||
|
sp.targetHigh = JSONArray(profile.data.getJSONArray("target_high").toString())
|
||||||
|
return sp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isEdited: Boolean = false
|
||||||
|
var profiles: ArrayList<SingleProfile> = ArrayList()
|
||||||
|
|
||||||
|
internal var numOfProfiles = 0
|
||||||
|
internal var currentProfileIndex = 0
|
||||||
|
|
||||||
|
fun currentProfile() = profiles[currentProfileIndex]
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun isValidEditState(): Boolean {
|
||||||
|
return createProfileStore().getDefaultProfile()?.isValid(MainApp.gs(R.string.localprofile), false)
|
||||||
|
?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun storeSettings(activity: Activity? = null) {
|
||||||
|
for (i in 0 until numOfProfiles) {
|
||||||
|
profiles[i].run {
|
||||||
|
val LOCAL_PROFILE_NUMBERED = LOCAL_PROFILE + "_" + i + "_"
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "name", name)
|
||||||
|
SP.putBoolean(LOCAL_PROFILE_NUMBERED + "mgdl", mgdl)
|
||||||
|
SP.putDouble(LOCAL_PROFILE_NUMBERED + "dia", dia)
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "ic", ic.toString())
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "isf", isf.toString())
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "basal", basal.toString())
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "targetlow", targetLow.toString())
|
||||||
|
SP.putString(LOCAL_PROFILE_NUMBERED + "targethigh", targetHigh.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SP.putInt(LOCAL_PROFILE + "_profiles", numOfProfiles)
|
||||||
|
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
isEdited = false
|
||||||
|
if (L.isEnabled(L.PROFILE))
|
||||||
|
log.debug("Storing settings: " + rawProfile?.data.toString())
|
||||||
|
RxBus.send(EventProfileStoreChanged())
|
||||||
|
var namesOK = true
|
||||||
|
profiles.forEach {
|
||||||
|
val name = it.name ?: "."
|
||||||
|
if (name.contains(".")) namesOK = false
|
||||||
|
}
|
||||||
|
if (namesOK)
|
||||||
|
rawProfile?.let { NSUpload.uploadProfileStore(it.data) }
|
||||||
|
else
|
||||||
|
activity?.let {
|
||||||
|
OKDialog.show(it,"", MainApp.gs(R.string.profilenamecontainsdot), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun loadSettings() {
|
||||||
|
if (SP.contains(LOCAL_PROFILE + "mgdl")) {
|
||||||
|
doConversion()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfProfiles = SP.getInt(LOCAL_PROFILE + "_profiles", 0)
|
||||||
|
profiles.clear()
|
||||||
|
numOfProfiles = Math.max(numOfProfiles, 1) // create at least one default profile if none exists
|
||||||
|
|
||||||
|
for (i in 0 until numOfProfiles) {
|
||||||
|
val p = SingleProfile()
|
||||||
|
val LOCAL_PROFILE_NUMBERED = LOCAL_PROFILE + "_" + i + "_"
|
||||||
|
|
||||||
|
p.name = SP.getString(LOCAL_PROFILE_NUMBERED + "name", LOCAL_PROFILE + i)
|
||||||
|
if (isExistingName(p.name)) continue
|
||||||
|
p.mgdl = SP.getBoolean(LOCAL_PROFILE_NUMBERED + "mgdl", false)
|
||||||
|
p.dia = SP.getDouble(LOCAL_PROFILE_NUMBERED + "dia", Constants.defaultDIA)
|
||||||
|
try {
|
||||||
|
p.ic = JSONArray(SP.getString(LOCAL_PROFILE_NUMBERED + "ic", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.ic = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
log.error("Exception", e1)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.isf = JSONArray(SP.getString(LOCAL_PROFILE_NUMBERED + "isf", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.isf = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
log.error("Exception", e1)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.basal = JSONArray(SP.getString(LOCAL_PROFILE_NUMBERED + "basal", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.basal = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
log.error("Exception", e1)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.targetLow = JSONArray(SP.getString(LOCAL_PROFILE_NUMBERED + "targetlow", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.targetLow = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
log.error("Exception", e1)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.targetHigh = JSONArray(SP.getString(LOCAL_PROFILE_NUMBERED + "targethigh", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.targetHigh = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
log.error("Exception", e1)
|
||||||
|
}
|
||||||
|
|
||||||
|
profiles.add(p)
|
||||||
|
}
|
||||||
|
isEdited = false
|
||||||
|
numOfProfiles = profiles.size
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isExistingName(name: String?): Boolean {
|
||||||
|
for (p in profiles) {
|
||||||
|
if (p.name == name) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private fun doConversion() { // conversion from 2.3 to 2.4 format
|
||||||
|
if (L.isEnabled(L.PROFILE))
|
||||||
|
log.debug("Loading stored settings")
|
||||||
|
val p = SingleProfile()
|
||||||
|
|
||||||
|
p.mgdl = SP.getBoolean(LOCAL_PROFILE + "mgdl", ProfileFunctions.getSystemUnits() == Constants.MGDL)
|
||||||
|
p.dia = SP.getDouble(LOCAL_PROFILE + "dia", Constants.defaultDIA)
|
||||||
|
try {
|
||||||
|
p.ic = JSONArray(SP.getString(LOCAL_PROFILE + "ic", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.ic = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.isf = JSONArray(SP.getString(LOCAL_PROFILE + "isf", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.isf = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.basal = JSONArray(SP.getString(LOCAL_PROFILE + "basal", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.basal = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.targetLow = JSONArray(SP.getString(LOCAL_PROFILE + "targetlow", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.targetLow = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
p.targetHigh = JSONArray(SP.getString(LOCAL_PROFILE + "targethigh", DEFAULTARRAY))
|
||||||
|
} catch (e1: JSONException) {
|
||||||
|
try {
|
||||||
|
p.targetHigh = JSONArray(DEFAULTARRAY)
|
||||||
|
} catch (ignored: JSONException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.name = LOCAL_PROFILE
|
||||||
|
|
||||||
|
SP.remove(LOCAL_PROFILE + "mgdl")
|
||||||
|
SP.remove(LOCAL_PROFILE + "mmol")
|
||||||
|
SP.remove(LOCAL_PROFILE + "dia")
|
||||||
|
SP.remove(LOCAL_PROFILE + "ic")
|
||||||
|
SP.remove(LOCAL_PROFILE + "isf")
|
||||||
|
SP.remove(LOCAL_PROFILE + "basal")
|
||||||
|
SP.remove(LOCAL_PROFILE + "targetlow")
|
||||||
|
SP.remove(LOCAL_PROFILE + "targethigh")
|
||||||
|
|
||||||
|
currentProfileIndex = 0
|
||||||
|
numOfProfiles = 1
|
||||||
|
profiles.clear()
|
||||||
|
profiles.add(p)
|
||||||
|
storeSettings()
|
||||||
|
|
||||||
|
isEdited = false
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"_id": "576264a12771b7500d7ad184",
|
||||||
|
"startDate": "2016-06-16T08:35:00.000Z",
|
||||||
|
"defaultProfile": "Default",
|
||||||
|
"store": {
|
||||||
|
"Default": {
|
||||||
|
"dia": "3",
|
||||||
|
"carbratio": [{
|
||||||
|
"time": "00:00",
|
||||||
|
"value": "30"
|
||||||
|
}],
|
||||||
|
"carbs_hr": "20",
|
||||||
|
"delay": "20",
|
||||||
|
"sens": [{
|
||||||
|
"time": "00:00",
|
||||||
|
"value": "100"
|
||||||
|
}],
|
||||||
|
"timezone": "UTC",
|
||||||
|
"basal": [{
|
||||||
|
"time": "00:00",
|
||||||
|
"value": "0.1"
|
||||||
|
}],
|
||||||
|
"target_low": [{
|
||||||
|
"time": "00:00",
|
||||||
|
"value": "0"
|
||||||
|
}],
|
||||||
|
"target_high": [{
|
||||||
|
"time": "00:00",
|
||||||
|
"value": "0"
|
||||||
|
}],
|
||||||
|
"startDate": "1970-01-01T00:00:00.000Z",
|
||||||
|
"units": "mmol"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"created_at": "2016-06-16T08:34:41.256Z"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
private fun createAndStoreConvertedProfile() {
|
||||||
|
rawProfile = createProfileStore()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addNewProfile() {
|
||||||
|
var free = 0
|
||||||
|
for (i in 1..10000) {
|
||||||
|
if (rawProfile?.getSpecificProfile(LOCAL_PROFILE + i) == null) {
|
||||||
|
free = i;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val p = SingleProfile()
|
||||||
|
p.name = LOCAL_PROFILE + free
|
||||||
|
p.mgdl = ProfileFunctions.getSystemUnits() == Constants.MGDL
|
||||||
|
p.dia = Constants.defaultDIA
|
||||||
|
p.ic = JSONArray(DEFAULTARRAY)
|
||||||
|
p.isf = JSONArray(DEFAULTARRAY)
|
||||||
|
p.basal = JSONArray(DEFAULTARRAY)
|
||||||
|
p.targetLow = JSONArray(DEFAULTARRAY)
|
||||||
|
p.targetHigh = JSONArray(DEFAULTARRAY)
|
||||||
|
profiles.add(p)
|
||||||
|
currentProfileIndex = profiles.size - 1
|
||||||
|
numOfProfiles++
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
storeSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cloneProfile() {
|
||||||
|
val p = profiles[currentProfileIndex].deepClone()
|
||||||
|
p.name = p.name + " copy"
|
||||||
|
profiles.add(p)
|
||||||
|
currentProfileIndex = profiles.size - 1
|
||||||
|
numOfProfiles++
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
storeSettings()
|
||||||
|
isEdited = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addProfile(p: SingleProfile) {
|
||||||
|
profiles.add(p)
|
||||||
|
currentProfileIndex = profiles.size - 1
|
||||||
|
numOfProfiles++
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
storeSettings()
|
||||||
|
isEdited = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeCurrentProfile() {
|
||||||
|
profiles.removeAt(currentProfileIndex)
|
||||||
|
numOfProfiles--
|
||||||
|
if (profiles.size == 0) addNewProfile()
|
||||||
|
currentProfileIndex = 0
|
||||||
|
createAndStoreConvertedProfile()
|
||||||
|
storeSettings()
|
||||||
|
isEdited = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createProfileStore(): ProfileStore {
|
||||||
|
val json = JSONObject()
|
||||||
|
val store = JSONObject()
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (i in 0 until numOfProfiles) {
|
||||||
|
profiles[i].run {
|
||||||
|
val profile = JSONObject()
|
||||||
|
profile.put("dia", dia)
|
||||||
|
profile.put("carbratio", ic)
|
||||||
|
profile.put("sens", isf)
|
||||||
|
profile.put("basal", basal)
|
||||||
|
profile.put("target_low", targetLow)
|
||||||
|
profile.put("target_high", targetHigh)
|
||||||
|
profile.put("units", if (mgdl) Constants.MGDL else Constants.MMOL)
|
||||||
|
profile.put("timezone", TimeZone.getDefault().id)
|
||||||
|
store.put(name, profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.put("defaultProfile", currentProfile().name)
|
||||||
|
json.put("startDate", DateUtil.toISOAsUTC(DateUtil.now()))
|
||||||
|
json.put("store", store)
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
log.error("Unhandled exception", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProfileStore(json)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProfile(): ProfileStore? {
|
||||||
|
return rawProfile
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProfileName(): String {
|
||||||
|
return DecimalFormatter.to2Decimal(rawProfile?.getDefaultProfile()?.percentageBasalSum()
|
||||||
|
?: 0.0) + "U "
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.nightscout.androidaps.plugins.profile.local.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventLocalProfileChanged : Event() {
|
||||||
|
}
|
|
@ -119,7 +119,7 @@ class NSProfileFragment : Fragment() {
|
||||||
profileview_noprofile.visibility = View.VISIBLE
|
profileview_noprofile.visibility = View.VISIBLE
|
||||||
|
|
||||||
NSProfilePlugin.getPlugin().profile?.let { profileStore ->
|
NSProfilePlugin.getPlugin().profile?.let { profileStore ->
|
||||||
val profileList = profileStore.profileList
|
val profileList = profileStore.getProfileList()
|
||||||
val adapter = ArrayAdapter(context!!, R.layout.spinner_centered, profileList)
|
val adapter = ArrayAdapter(context!!, R.layout.spinner_centered, profileList)
|
||||||
nsprofile_spinner.adapter = adapter
|
nsprofile_spinner.adapter = adapter
|
||||||
// set selected to actual profile
|
// set selected to actual profile
|
||||||
|
|
|
@ -118,11 +118,6 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnits() {
|
|
||||||
return profile != null ? profile.getUnits() : Constants.MGDL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
return profile.getDefaultProfileName();
|
return profile.getDefaultProfileName();
|
||||||
|
|
|
@ -1,159 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.profile.simple;
|
|
||||||
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
|
||||||
|
|
||||||
public class SimpleProfileFragment extends Fragment {
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
EditText diaView;
|
|
||||||
RadioButton mgdlView;
|
|
||||||
RadioButton mmolView;
|
|
||||||
EditText icView;
|
|
||||||
EditText isfView;
|
|
||||||
EditText basalView;
|
|
||||||
EditText targetlowView;
|
|
||||||
EditText targethighView;
|
|
||||||
Button profileswitchButton;
|
|
||||||
TextView invalidProfile;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View layout = inflater.inflate(R.layout.simpleprofile_fragment, container, false);
|
|
||||||
diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia);
|
|
||||||
mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl);
|
|
||||||
mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol);
|
|
||||||
icView = (EditText) layout.findViewById(R.id.simpleprofile_ic);
|
|
||||||
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
|
|
||||||
basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate);
|
|
||||||
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
|
|
||||||
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
|
||||||
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
|
|
||||||
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
|
|
||||||
|
|
||||||
if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isTempBasalCapable) {
|
|
||||||
layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE);
|
|
||||||
layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
|
|
||||||
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
|
|
||||||
diaView.setText(SimpleProfilePlugin.getPlugin().dia.toString());
|
|
||||||
icView.setText(SimpleProfilePlugin.getPlugin().ic.toString());
|
|
||||||
isfView.setText(SimpleProfilePlugin.getPlugin().isf.toString());
|
|
||||||
basalView.setText(SimpleProfilePlugin.getPlugin().basal.toString());
|
|
||||||
targetlowView.setText(SimpleProfilePlugin.getPlugin().targetLow.toString());
|
|
||||||
targethighView.setText(SimpleProfilePlugin.getPlugin().targetHigh.toString());
|
|
||||||
|
|
||||||
mgdlView.setOnClickListener(v -> {
|
|
||||||
SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
|
|
||||||
SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl;
|
|
||||||
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
|
|
||||||
SimpleProfilePlugin.getPlugin().storeSettings();
|
|
||||||
});
|
|
||||||
mmolView.setOnClickListener(v -> {
|
|
||||||
SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked();
|
|
||||||
SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol;
|
|
||||||
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
|
|
||||||
SimpleProfilePlugin.getPlugin().storeSettings();
|
|
||||||
});
|
|
||||||
|
|
||||||
profileswitchButton.setOnClickListener(view -> {
|
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
|
||||||
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
|
|
||||||
profileswitch.executeProfileSwitch = true;
|
|
||||||
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
|
||||||
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
|
|
||||||
});
|
|
||||||
|
|
||||||
TextWatcher textWatch = new TextWatcher() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start,
|
|
||||||
int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start,
|
|
||||||
int before, int count) {
|
|
||||||
SimpleProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().ic = SafeParse.stringToDouble(icView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().isf = SafeParse.stringToDouble(isfView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().basal = SafeParse.stringToDouble(basalView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
|
|
||||||
SimpleProfilePlugin.getPlugin().storeSettings();
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
diaView.addTextChangedListener(textWatch);
|
|
||||||
icView.addTextChangedListener(textWatch);
|
|
||||||
isfView.addTextChangedListener(textWatch);
|
|
||||||
basalView.addTextChangedListener(textWatch);
|
|
||||||
targetlowView.addTextChangedListener(textWatch);
|
|
||||||
targethighView.addTextChangedListener(textWatch);
|
|
||||||
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
disposable.add(RxBus.INSTANCE
|
|
||||||
.toObservable(EventInitializationChanged.class)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
|
||||||
);
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
disposable.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateGUI() {
|
|
||||||
boolean isValid = SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile));
|
|
||||||
if (!ConfigBuilderPlugin.getPlugin().getActivePump().isInitialized() || ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended() || !isValid) {
|
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
if (isValid)
|
|
||||||
invalidProfile.setVisibility(View.GONE);
|
|
||||||
else
|
|
||||||
invalidProfile.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,181 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.profile.simple;
|
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.events.EventProfileStoreChanged;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.08.2016.
|
|
||||||
*/
|
|
||||||
public class SimpleProfilePlugin extends PluginBase implements ProfileInterface {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
|
|
||||||
|
|
||||||
private static SimpleProfilePlugin simpleProfilePlugin;
|
|
||||||
|
|
||||||
public static SimpleProfilePlugin getPlugin() {
|
|
||||||
if (simpleProfilePlugin == null)
|
|
||||||
simpleProfilePlugin = new SimpleProfilePlugin();
|
|
||||||
return simpleProfilePlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProfileStore convertedProfile = null;
|
|
||||||
|
|
||||||
boolean mgdl;
|
|
||||||
boolean mmol;
|
|
||||||
Double dia;
|
|
||||||
Double ic;
|
|
||||||
Double isf;
|
|
||||||
Double basal;
|
|
||||||
Double targetLow;
|
|
||||||
Double targetHigh;
|
|
||||||
|
|
||||||
private SimpleProfilePlugin() {
|
|
||||||
super(new PluginDescription()
|
|
||||||
.mainType(PluginType.PROFILE)
|
|
||||||
.fragmentClass(SimpleProfileFragment.class.getName())
|
|
||||||
.pluginName(R.string.simpleprofile)
|
|
||||||
.shortName(R.string.simpleprofile_shortname)
|
|
||||||
.description(R.string.description_profile_simple)
|
|
||||||
);
|
|
||||||
loadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void storeSettings() {
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
|
||||||
log.debug("Storing settings");
|
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
editor.putBoolean("SimpleProfile" + "mmol", mmol);
|
|
||||||
editor.putBoolean("SimpleProfile" + "mgdl", mgdl);
|
|
||||||
editor.putString("SimpleProfile" + "dia", dia.toString());
|
|
||||||
editor.putString("SimpleProfile" + "ic", ic.toString());
|
|
||||||
editor.putString("SimpleProfile" + "isf", isf.toString());
|
|
||||||
editor.putString("SimpleProfile" + "basal", basal.toString());
|
|
||||||
editor.putString("SimpleProfile" + "targetlow", targetLow.toString());
|
|
||||||
editor.putString("SimpleProfile" + "targethigh", targetHigh.toString());
|
|
||||||
|
|
||||||
editor.apply();
|
|
||||||
createConvertedProfile();
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
|
||||||
log.debug("Storing settings: " + getRawProfile().getData().toString());
|
|
||||||
RxBus.INSTANCE.send(new EventProfileStoreChanged());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadSettings() {
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
|
||||||
log.debug("Loading stored settings");
|
|
||||||
|
|
||||||
mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);
|
|
||||||
mmol = SP.getBoolean("SimpleProfile" + "mmol", false);
|
|
||||||
dia = SP.getDouble("SimpleProfile" + "dia", Constants.defaultDIA);
|
|
||||||
ic = SP.getDouble("SimpleProfile" + "ic", 0d);
|
|
||||||
isf = SP.getDouble("SimpleProfile" + "isf", 0d);
|
|
||||||
basal = SP.getDouble("SimpleProfile" + "basal", 0d);
|
|
||||||
targetLow = SP.getDouble("SimpleProfile" + "targetlow", 0d);
|
|
||||||
targetHigh = SP.getDouble("SimpleProfile" + "targethigh", 0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"_id": "576264a12771b7500d7ad184",
|
|
||||||
"startDate": "2016-06-16T08:35:00.000Z",
|
|
||||||
"defaultProfile": "Default",
|
|
||||||
"store": {
|
|
||||||
"Default": {
|
|
||||||
"dia": "3",
|
|
||||||
"carbratio": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "30"
|
|
||||||
}],
|
|
||||||
"carbs_hr": "20",
|
|
||||||
"delay": "20",
|
|
||||||
"sens": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "100"
|
|
||||||
}],
|
|
||||||
"timezone": "UTC",
|
|
||||||
"basal": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0.1"
|
|
||||||
}],
|
|
||||||
"target_low": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0"
|
|
||||||
}],
|
|
||||||
"target_high": [{
|
|
||||||
"time": "00:00",
|
|
||||||
"value": "0"
|
|
||||||
}],
|
|
||||||
"startDate": "1970-01-01T00:00:00.000Z",
|
|
||||||
"units": "mmol"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"created_at": "2016-06-16T08:34:41.256Z"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
private void createConvertedProfile() {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
JSONObject store = new JSONObject();
|
|
||||||
JSONObject profile = new JSONObject();
|
|
||||||
|
|
||||||
try {
|
|
||||||
json.put("defaultProfile", "SimpleProfile");
|
|
||||||
json.put("store", store);
|
|
||||||
profile.put("dia", dia);
|
|
||||||
profile.put("carbratio", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", ic)));
|
|
||||||
profile.put("sens", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", isf)));
|
|
||||||
profile.put("basal", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", basal)));
|
|
||||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetLow)));
|
|
||||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetHigh)));
|
|
||||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
|
||||||
store.put("SimpleProfile", profile);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
convertedProfile = new ProfileStore(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProfileStore getProfile() {
|
|
||||||
if (convertedProfile == null)
|
|
||||||
createConvertedProfile();
|
|
||||||
if (!convertedProfile.getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile)))
|
|
||||||
return null;
|
|
||||||
return convertedProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProfileStore getRawProfile() {
|
|
||||||
if (convertedProfile == null)
|
|
||||||
createConvertedProfile();
|
|
||||||
return convertedProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnits() {
|
|
||||||
return mgdl ? Constants.MGDL : Constants.MMOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProfileName() {
|
|
||||||
return "SimpleProfile";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -444,11 +444,6 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
||||||
return DanaRPump.getInstance().createConvertedProfile();
|
return DanaRPump.getInstance().createConvertedProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnits() {
|
|
||||||
return DanaRPump.getInstance().getUnits();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
return DanaRPump.getInstance().createConvertedProfileName();
|
return DanaRPump.getInstance().createConvertedProfileName();
|
||||||
|
|
|
@ -41,7 +41,6 @@ import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
|
@ -49,8 +48,6 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
static Profile profile = null;
|
|
||||||
|
|
||||||
Spinner historyTypeSpinner;
|
Spinner historyTypeSpinner;
|
||||||
TextView statusView;
|
TextView statusView;
|
||||||
Button reloadButton;
|
Button reloadButton;
|
||||||
|
@ -182,11 +179,6 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
clearCardView();
|
clearCardView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
if (profile == null) {
|
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.noprofile));
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
|
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
|
||||||
|
@ -252,7 +244,7 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
holder.alarm.setVisibility(View.GONE);
|
holder.alarm.setVisibility(View.GONE);
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||||
holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profile.getUnits()));
|
holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, ProfileFunctions.getSystemUnits()));
|
||||||
// rest is the same
|
// rest is the same
|
||||||
case RecordTypes.RECORD_TYPE_CARBO:
|
case RecordTypes.RECORD_TYPE_CARBO:
|
||||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||||
|
|
|
@ -184,7 +184,7 @@ public class DanaRNSHistorySync {
|
||||||
log.debug("Syncing glucose record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
|
log.debug("Syncing glucose record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put(DANARSIGNATURE, record.bytes);
|
nsrec.put(DANARSIGNATURE, record.bytes);
|
||||||
nsrec.put("eventType", "BG Check");
|
nsrec.put("eventType", "BG Check");
|
||||||
nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, ProfileFunctions.getInstance().getProfileUnits()));
|
nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, ProfileFunctions.getSystemUnits()));
|
||||||
nsrec.put("glucoseType", "Finger");
|
nsrec.put("glucoseType", "Finger");
|
||||||
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
|
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
|
|
|
@ -285,11 +285,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
return DanaRPump.getInstance().createConvertedProfile();
|
return DanaRPump.getInstance().createConvertedProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnits() {
|
|
||||||
return DanaRPump.getInstance().getUnits();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
return DanaRPump.getInstance().createConvertedProfileName();
|
return DanaRPump.getInstance().createConvertedProfileName();
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
|
||||||
Double[] deviations = new Double[deviationsArray.size()];
|
Double[] deviations = new Double[deviationsArray.size()];
|
||||||
deviations = deviationsArray.toArray(deviations);
|
deviations = deviationsArray.toArray(deviations);
|
||||||
|
|
||||||
double sens = profile.getIsf();
|
double sens = profile.getIsfMgdl();
|
||||||
|
|
||||||
String ratioLimit = "";
|
String ratioLimit = "";
|
||||||
String sensResult = "";
|
String sensResult = "";
|
||||||
|
@ -148,7 +148,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
|
||||||
Arrays.sort(deviations);
|
Arrays.sort(deviations);
|
||||||
|
|
||||||
double percentile = IobCobCalculatorPlugin.percentile(deviations, 0.50);
|
double percentile = IobCobCalculatorPlugin.percentile(deviations, 0.50);
|
||||||
double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
double basalOff = percentile * (60 / 5) / sens;
|
||||||
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||||
|
|
||||||
if (percentile < 0) { // sensitive
|
if (percentile < 0) { // sensitive
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
|
||||||
Double[] deviations = new Double[deviationsArray.size()];
|
Double[] deviations = new Double[deviationsArray.size()];
|
||||||
deviations = deviationsArray.toArray(deviations);
|
deviations = deviationsArray.toArray(deviations);
|
||||||
|
|
||||||
double sens = profile.getIsf();
|
double sens = profile.getIsfMgdl();
|
||||||
|
|
||||||
double ratio = 1;
|
double ratio = 1;
|
||||||
String ratioLimit = "";
|
String ratioLimit = "";
|
||||||
|
@ -154,10 +154,10 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
|
||||||
double basalOff = 0;
|
double basalOff = 0;
|
||||||
|
|
||||||
if (pSensitive < 0) { // sensitive
|
if (pSensitive < 0) { // sensitive
|
||||||
basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
basalOff = pSensitive * (60 / 5.0) / sens;
|
||||||
sensResult = "Excess insulin sensitivity detected";
|
sensResult = "Excess insulin sensitivity detected";
|
||||||
} else if (pResistant > 0) { // resistant
|
} else if (pResistant > 0) { // resistant
|
||||||
basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
basalOff = pResistant * (60 / 5.0) / sens;
|
||||||
sensResult = "Excess insulin resistance detected";
|
sensResult = "Excess insulin resistance detected";
|
||||||
} else {
|
} else {
|
||||||
sensResult = "Sensitivity normal";
|
sensResult = "Sensitivity normal";
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
||||||
Double[] deviations = new Double[deviationsArray.size()];
|
Double[] deviations = new Double[deviationsArray.size()];
|
||||||
deviations = deviationsArray.toArray(deviations);
|
deviations = deviationsArray.toArray(deviations);
|
||||||
|
|
||||||
double sens = profile.getIsf();
|
double sens = profile.getIsfMgdl();
|
||||||
|
|
||||||
double ratio = 1;
|
double ratio = 1;
|
||||||
String ratioLimit = "";
|
String ratioLimit = "";
|
||||||
|
@ -174,10 +174,10 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
||||||
double basalOff = 0;
|
double basalOff = 0;
|
||||||
|
|
||||||
if (pSensitive < 0) { // sensitive
|
if (pSensitive < 0) { // sensitive
|
||||||
basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
basalOff = pSensitive * (60 / 5.0) / sens;
|
||||||
sensResult = "Excess insulin sensitivity detected";
|
sensResult = "Excess insulin sensitivity detected";
|
||||||
} else if (pResistant > 0) { // resistant
|
} else if (pResistant > 0) { // resistant
|
||||||
basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
basalOff = pResistant * (60 / 5.0) / sens;
|
||||||
sensResult = "Excess insulin resistance detected";
|
sensResult = "Excess insulin resistance detected";
|
||||||
} else {
|
} else {
|
||||||
sensResult = "Sensitivity normal";
|
sensResult = "Sensitivity normal";
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
double sens = profile.getIsf();
|
double sens = profile.getIsfMgdl();
|
||||||
|
|
||||||
String ratioLimit = "";
|
String ratioLimit = "";
|
||||||
String sensResult;
|
String sensResult;
|
||||||
|
@ -173,7 +173,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
|
||||||
log.debug("Records: " + index + " " + pastSensitivity);
|
log.debug("Records: " + index + " " + pastSensitivity);
|
||||||
|
|
||||||
double average = weightedsum / weights;
|
double average = weightedsum / weights;
|
||||||
double basalOff = average * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
double basalOff = average * (60 / 5.0) / sens;
|
||||||
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||||
|
|
||||||
if (average < 0) { // sensitive
|
if (average < 0) { // sensitive
|
||||||
|
|
|
@ -16,12 +16,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
@ -38,8 +37,6 @@ public class BGSourceFragment extends Fragment {
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
|
|
||||||
String units = Constants.MGDL;
|
|
||||||
|
|
||||||
final long MILLS_TO_THE_PAST = T.hours(12).msecs();
|
final long MILLS_TO_THE_PAST = T.hours(12).msecs();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,9 +54,6 @@ public class BGSourceFragment extends Fragment {
|
||||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false));
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile().getDefaultProfile() != null)
|
|
||||||
units = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile().getDefaultProfile().getUnits();
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FabricPrivacy.logException(e);
|
FabricPrivacy.logException(e);
|
||||||
|
@ -109,7 +103,7 @@ public class BGSourceFragment extends Fragment {
|
||||||
holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE);
|
||||||
holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE);
|
holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE);
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(bgReading.date));
|
holder.date.setText(DateUtil.dateAndTimeString(bgReading.date));
|
||||||
holder.value.setText(bgReading.valueToUnitsToString(units));
|
holder.value.setText(bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits()));
|
||||||
holder.direction.setText(bgReading.directionToSymbol());
|
holder.direction.setText(bgReading.directionToSymbol());
|
||||||
holder.remove.setTag(bgReading);
|
holder.remove.setTag(bgReading);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +141,7 @@ public class BGSourceFragment extends Fragment {
|
||||||
case R.id.bgsource_remove:
|
case R.id.bgsource_remove:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(MainApp.gs(R.string.confirmation));
|
builder.setTitle(MainApp.gs(R.string.confirmation));
|
||||||
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(units));
|
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits()));
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
/* final String _id = bgReading._id;
|
/* final String _id = bgReading._id;
|
||||||
|
|
|
@ -58,7 +58,7 @@ class ProfileViewerDialog : DialogFragment() {
|
||||||
profileview_datelayout.visibility = View.VISIBLE
|
profileview_datelayout.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
Mode.PUMP_PROFILE -> {
|
Mode.PUMP_PROFILE -> {
|
||||||
profile = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profile?.defaultProfile
|
profile = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profile?.getDefaultProfile()
|
||||||
profileName = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profileName
|
profileName = (ConfigBuilderPlugin.getPlugin().activePump as ProfileInterface?)?.profileName
|
||||||
date = ""
|
date = ""
|
||||||
profileview_reload.visibility = View.VISIBLE
|
profileview_reload.visibility = View.VISIBLE
|
||||||
|
|
|
@ -1,242 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.treatments.fragments;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.cardview.widget.CardView;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
|
||||||
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 13/01/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class TreatmentsProfileSwitchFragment extends Fragment implements View.OnClickListener {
|
|
||||||
private Logger log = LoggerFactory.getLogger(L.UI);
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
RecyclerView recyclerView;
|
|
||||||
LinearLayoutManager llm;
|
|
||||||
Button refreshFromNS;
|
|
||||||
|
|
||||||
Context context;
|
|
||||||
|
|
||||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ProfileSwitchViewHolder> {
|
|
||||||
|
|
||||||
List<ProfileSwitch> profileSwitchList;
|
|
||||||
|
|
||||||
RecyclerViewAdapter(List<ProfileSwitch> profileSwitchList) {
|
|
||||||
this.profileSwitchList = profileSwitchList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProfileSwitchViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_profileswitch_item, viewGroup, false);
|
|
||||||
return new ProfileSwitchViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(ProfileSwitchViewHolder holder, int position) {
|
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
if (profile == null) return;
|
|
||||||
ProfileSwitch profileSwitch = profileSwitchList.get(position);
|
|
||||||
holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
|
||||||
holder.ns.setVisibility(NSUpload.isIdValid(profileSwitch._id) ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date));
|
|
||||||
if (!profileSwitch.isEndingEvent()) {
|
|
||||||
holder.duration.setText(DecimalFormatter.to0Decimal(profileSwitch.durationInMinutes) + " min");
|
|
||||||
} else {
|
|
||||||
holder.duration.setText("");
|
|
||||||
}
|
|
||||||
holder.name.setText(profileSwitch.getCustomizedName());
|
|
||||||
if (profileSwitch.isInProgress())
|
|
||||||
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
|
||||||
else
|
|
||||||
holder.date.setTextColor(holder.duration.getCurrentTextColor());
|
|
||||||
holder.remove.setTag(profileSwitch);
|
|
||||||
holder.name.setTag(profileSwitch);
|
|
||||||
holder.date.setTag(profileSwitch);
|
|
||||||
holder.invalid.setVisibility(profileSwitch.isValid() ? View.GONE : View.VISIBLE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return profileSwitchList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
|
||||||
super.onAttachedToRecyclerView(recyclerView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ProfileSwitchViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
||||||
CardView cv;
|
|
||||||
TextView date;
|
|
||||||
TextView duration;
|
|
||||||
TextView name;
|
|
||||||
TextView remove;
|
|
||||||
TextView ph;
|
|
||||||
TextView ns;
|
|
||||||
TextView invalid;
|
|
||||||
|
|
||||||
ProfileSwitchViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
cv = (CardView) itemView.findViewById(R.id.profileswitch_cardview);
|
|
||||||
date = (TextView) itemView.findViewById(R.id.profileswitch_date);
|
|
||||||
duration = (TextView) itemView.findViewById(R.id.profileswitch_duration);
|
|
||||||
name = (TextView) itemView.findViewById(R.id.profileswitch_name);
|
|
||||||
ph = (TextView) itemView.findViewById(R.id.pump_sign);
|
|
||||||
ns = (TextView) itemView.findViewById(R.id.ns_sign);
|
|
||||||
invalid = (TextView) itemView.findViewById(R.id.invalid_sign);
|
|
||||||
remove = (TextView) itemView.findViewById(R.id.profileswitch_remove);
|
|
||||||
remove.setOnClickListener(this);
|
|
||||||
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
|
||||||
name.setOnClickListener(this);
|
|
||||||
date.setOnClickListener(this);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
final ProfileSwitch profileSwitch = (ProfileSwitch) v.getTag();
|
|
||||||
if (profileSwitch == null) {
|
|
||||||
log.error("profileSwitch == null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (v.getId()) {
|
|
||||||
case R.id.profileswitch_remove:
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(MainApp.gs(R.string.confirmation));
|
|
||||||
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(profileSwitch.date));
|
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
final String _id = profileSwitch._id;
|
|
||||||
if (NSUpload.isIdValid(_id)) {
|
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
|
||||||
} else {
|
|
||||||
UploadQueue.removeID("dbAdd", _id);
|
|
||||||
}
|
|
||||||
MainApp.getDbHelper().delete(profileSwitch);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
|
||||||
builder.show();
|
|
||||||
break;
|
|
||||||
case R.id.profileswitch_date:
|
|
||||||
case R.id.profileswitch_name:
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putLong("time", ((ProfileSwitch) v.getTag()).date);
|
|
||||||
args.putLong("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal());
|
|
||||||
ProfileViewerDialog pvd = new ProfileViewerDialog();
|
|
||||||
pvd.setArguments(args);
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
if (manager != null)
|
|
||||||
pvd.show(manager, "ProfileViewDialog");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.treatments_profileswitch_fragment, container, false);
|
|
||||||
|
|
||||||
recyclerView = (RecyclerView) view.findViewById(R.id.profileswitch_recyclerview);
|
|
||||||
recyclerView.setHasFixedSize(true);
|
|
||||||
llm = new LinearLayoutManager(view.getContext());
|
|
||||||
recyclerView.setLayoutManager(llm);
|
|
||||||
|
|
||||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false));
|
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
refreshFromNS = (Button) view.findViewById(R.id.profileswitch_refreshfromnightscout);
|
|
||||||
refreshFromNS.setOnClickListener(this);
|
|
||||||
|
|
||||||
context = getContext();
|
|
||||||
|
|
||||||
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
|
|
||||||
if (nsUploadOnly)
|
|
||||||
refreshFromNS.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
disposable.add(RxBus.INSTANCE
|
|
||||||
.toObservable(EventProfileNeedsUpdate.class)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
|
||||||
);
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
disposable.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
switch (view.getId()) {
|
|
||||||
case R.id.profileswitch_refreshfromnightscout:
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
|
|
||||||
builder.setTitle(MainApp.gs(R.string.confirmation));
|
|
||||||
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
|
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
MainApp.getDbHelper().resetProfileSwitch();
|
|
||||||
RxBus.INSTANCE.send(new EventNSClientRestart());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
|
||||||
builder.show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateGUI() {
|
|
||||||
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false)), false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
package info.nightscout.androidaps.plugins.treatments.fragments
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.cardview.widget.CardView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.db.ProfileSwitch
|
||||||
|
import info.nightscout.androidaps.db.Source
|
||||||
|
import info.nightscout.androidaps.events.EventProfileNeedsUpdate
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||||
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
||||||
|
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsProfileSwitchFragment.RecyclerProfileViewAdapter.ProfileSwitchViewHolder
|
||||||
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import kotlinx.android.synthetic.main.treatments_profileswitch_fragment.*
|
||||||
|
|
||||||
|
class TreatmentsProfileSwitchFragment : Fragment() {
|
||||||
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.treatments_profileswitch_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
profileswitch_recyclerview.setHasFixedSize(true)
|
||||||
|
profileswitch_recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||||
|
profileswitch_recyclerview.adapter = RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false))
|
||||||
|
|
||||||
|
profileswitch_refreshfromnightscout.setOnClickListener {
|
||||||
|
val builder = AlertDialog.Builder(this.context!!)
|
||||||
|
builder.setTitle(MainApp.gs(R.string.confirmation))
|
||||||
|
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?")
|
||||||
|
builder.setPositiveButton(MainApp.gs(R.string.ok)) { dialog: DialogInterface?, id: Int ->
|
||||||
|
MainApp.getDbHelper().resetProfileSwitch()
|
||||||
|
RxBus.send(EventNSClientRestart())
|
||||||
|
}
|
||||||
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null)
|
||||||
|
builder.show()
|
||||||
|
}
|
||||||
|
if (SP.getBoolean(R.string.key_ns_upload_only, false)) profileswitch_refreshfromnightscout.visibility = View.GONE
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
disposable.add(RxBus
|
||||||
|
.toObservable(EventProfileNeedsUpdate::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ updateGUI() }) { FabricPrivacy.logException(it) }
|
||||||
|
)
|
||||||
|
updateGUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateGUI() =
|
||||||
|
profileswitch_recyclerview?.swapAdapter(RecyclerProfileViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false)), false)
|
||||||
|
|
||||||
|
inner class RecyclerProfileViewAdapter(var profileSwitchList: List<ProfileSwitch>) : RecyclerView.Adapter<ProfileSwitchViewHolder>() {
|
||||||
|
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ProfileSwitchViewHolder {
|
||||||
|
return ProfileSwitchViewHolder(LayoutInflater.from(viewGroup.context).inflate(R.layout.treatments_profileswitch_item, viewGroup, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ProfileSwitchViewHolder, position: Int) {
|
||||||
|
val profileSwitch = profileSwitchList[position]
|
||||||
|
holder.ph.visibility = if (profileSwitch.source == Source.PUMP) View.VISIBLE else View.GONE
|
||||||
|
holder.ns.visibility = if (NSUpload.isIdValid(profileSwitch._id)) View.VISIBLE else View.GONE
|
||||||
|
holder.date.text = DateUtil.dateAndTimeString(profileSwitch.date)
|
||||||
|
if (!profileSwitch.isEndingEvent) {
|
||||||
|
holder.duration.text = DecimalFormatter.to0Decimal(profileSwitch.durationInMinutes.toDouble()) + " " + MainApp.gs(R.string.unit_minute_short)
|
||||||
|
} else {
|
||||||
|
holder.duration.text = ""
|
||||||
|
}
|
||||||
|
holder.name.text = profileSwitch.customizedName
|
||||||
|
if (profileSwitch.isInProgress) holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)) else holder.date.setTextColor(holder.duration.currentTextColor)
|
||||||
|
holder.remove.tag = profileSwitch
|
||||||
|
holder.clone.tag = profileSwitch
|
||||||
|
holder.name.tag = profileSwitch
|
||||||
|
holder.date.tag = profileSwitch
|
||||||
|
holder.invalid.visibility = if (profileSwitch.isValid()) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return profileSwitchList.size
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class ProfileSwitchViewHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
||||||
|
var cv: CardView = itemView.findViewById<View>(R.id.profileswitch_cardview) as CardView
|
||||||
|
var date: TextView = itemView.findViewById<View>(R.id.profileswitch_date) as TextView
|
||||||
|
var duration: TextView = itemView.findViewById<View>(R.id.profileswitch_duration) as TextView
|
||||||
|
var name: TextView = itemView.findViewById<View>(R.id.profileswitch_name) as TextView
|
||||||
|
var remove: TextView = itemView.findViewById<View>(R.id.profileswitch_remove) as TextView
|
||||||
|
var clone: TextView = itemView.findViewById<View>(R.id.profileswitch_clone) as TextView
|
||||||
|
var ph: TextView = itemView.findViewById<View>(R.id.pump_sign) as TextView
|
||||||
|
var ns: TextView = itemView.findViewById<View>(R.id.ns_sign) as TextView
|
||||||
|
var invalid: TextView = itemView.findViewById<View>(R.id.invalid_sign) as TextView
|
||||||
|
|
||||||
|
override fun onClick(v: View) {
|
||||||
|
val profileSwitch = v.tag as ProfileSwitch
|
||||||
|
when (v.id) {
|
||||||
|
R.id.profileswitch_remove ->
|
||||||
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.removerecord) + "\n" + profileSwitch.profileName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date)) {
|
||||||
|
val id = profileSwitch._id
|
||||||
|
if (NSUpload.isIdValid(id)) NSUpload.removeCareportalEntryFromNS(id)
|
||||||
|
else UploadQueue.removeID("dbAdd", id)
|
||||||
|
MainApp.getDbHelper().delete(profileSwitch)
|
||||||
|
}
|
||||||
|
R.id.profileswitch_clone ->
|
||||||
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.copytolocalprofile) + "\n" + profileSwitch.customizedName + "\n" + DateUtil.dateAndTimeString(profileSwitch.date)) {
|
||||||
|
profileSwitch.profileObject?.let {
|
||||||
|
val nonCustomized = it.convertToNonCustomizedProfile()
|
||||||
|
LocalProfilePlugin.addProfile(LocalProfilePlugin.SingleProfile().copyFrom(nonCustomized, profileSwitch.customizedName + " " + DateUtil.dateAndTimeString(profileSwitch.date).replace(".", "_")))
|
||||||
|
RxBus.send(EventLocalProfileChanged())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
R.id.profileswitch_date, R.id.profileswitch_name -> {
|
||||||
|
val args = Bundle()
|
||||||
|
args.putLong("time", (v.tag as ProfileSwitch).date)
|
||||||
|
args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal)
|
||||||
|
val pvd = ProfileViewerDialog()
|
||||||
|
pvd.arguments = args
|
||||||
|
fragmentManager?.let { pvd.show(it, "ProfileViewDialog") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
remove.setOnClickListener(this)
|
||||||
|
clone.setOnClickListener(this)
|
||||||
|
remove.paintFlags = remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||||
|
clone.paintFlags = clone.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||||
|
name.setOnClickListener(this)
|
||||||
|
date.setOnClickListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,7 +69,7 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(TempTargetsViewHolder holder, int position) {
|
public void onBindViewHolder(TempTargetsViewHolder holder, int position) {
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
TempTarget tempTarget = tempTargetList.getReversed(position);
|
TempTarget tempTarget = tempTargetList.getReversed(position);
|
||||||
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE);
|
||||||
|
|
|
@ -33,10 +33,9 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfileFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
|
|
||||||
import info.nightscout.androidaps.setupwizard.elements.SWBreak;
|
import info.nightscout.androidaps.setupwizard.elements.SWBreak;
|
||||||
import info.nightscout.androidaps.setupwizard.elements.SWButton;
|
import info.nightscout.androidaps.setupwizard.elements.SWButton;
|
||||||
|
import info.nightscout.androidaps.setupwizard.elements.SWEditNumberWithUnits;
|
||||||
import info.nightscout.androidaps.setupwizard.elements.SWEditString;
|
import info.nightscout.androidaps.setupwizard.elements.SWEditString;
|
||||||
import info.nightscout.androidaps.setupwizard.elements.SWEditUrl;
|
import info.nightscout.androidaps.setupwizard.elements.SWEditUrl;
|
||||||
import info.nightscout.androidaps.setupwizard.elements.SWFragment;
|
import info.nightscout.androidaps.setupwizard.elements.SWFragment;
|
||||||
|
@ -110,6 +109,29 @@ public class SWDefinition {
|
||||||
.visibility(() -> !SP.getBoolean(R.string.key_i_understand, false))
|
.visibility(() -> !SP.getBoolean(R.string.key_i_understand, false))
|
||||||
.validator(() -> SP.getBoolean(R.string.key_i_understand, false));
|
.validator(() -> SP.getBoolean(R.string.key_i_understand, false));
|
||||||
|
|
||||||
|
private SWScreen screenUnits = new SWScreen(R.string.units)
|
||||||
|
.skippable(false)
|
||||||
|
.add(new SWRadioButton()
|
||||||
|
.option(R.array.unitsArray, R.array.unitsValues)
|
||||||
|
.preferenceId(R.string.key_units).label(R.string.units)
|
||||||
|
.comment(R.string.setupwizard_units_prompt))
|
||||||
|
.validator(() -> SP.contains(R.string.key_units));
|
||||||
|
|
||||||
|
private SWScreen displaySettings = new SWScreen(R.string.wear_display_settings)
|
||||||
|
.skippable(false)
|
||||||
|
.add(new SWEditNumberWithUnits(4d, 3d, 8d)
|
||||||
|
.preferenceId(R.string.key_low_mark)
|
||||||
|
.updateDelay(5)
|
||||||
|
.label(R.string.low_mark)
|
||||||
|
.comment(R.string.low_mark_comment))
|
||||||
|
.add(new SWBreak())
|
||||||
|
.add(new SWEditNumberWithUnits(10d, 5d, 20d)
|
||||||
|
.preferenceId(R.string.key_high_mark)
|
||||||
|
.updateDelay(5)
|
||||||
|
.label(R.string.high_mark)
|
||||||
|
.comment(R.string.high_mark_comment))
|
||||||
|
.validator(() -> SP.contains(R.string.key_low_mark) && SP.contains(R.string.key_high_mark));
|
||||||
|
|
||||||
private SWScreen screenPermissionBattery = new SWScreen(R.string.permission)
|
private SWScreen screenPermissionBattery = new SWScreen(R.string.permission)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(new SWInfotext()
|
.add(new SWInfotext()
|
||||||
|
@ -270,15 +292,8 @@ public class SWDefinition {
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(new SWFragment(this)
|
.add(new SWFragment(this)
|
||||||
.add(new LocalProfileFragment()))
|
.add(new LocalProfileFragment()))
|
||||||
.validator(() -> LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard"))
|
.validator(() -> LocalProfilePlugin.INSTANCE.getProfile() != null && LocalProfilePlugin.INSTANCE.getProfile().getDefaultProfile() != null && LocalProfilePlugin.INSTANCE.getProfile().getDefaultProfile().isValid("StartupWizard"))
|
||||||
.visibility(() -> LocalProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE));
|
.visibility(() -> LocalProfilePlugin.INSTANCE.isEnabled(PluginType.PROFILE));
|
||||||
|
|
||||||
private SWScreen screenSimpleProfile = new SWScreen(R.string.simpleprofile)
|
|
||||||
.skippable(false)
|
|
||||||
.add(new SWFragment(this)
|
|
||||||
.add(new SimpleProfileFragment()))
|
|
||||||
.validator(() -> SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid("StartupWizard"))
|
|
||||||
.visibility(() -> SimpleProfilePlugin.getPlugin().isEnabled(PluginType.PROFILE));
|
|
||||||
|
|
||||||
private SWScreen screenProfileSwitch = new SWScreen(R.string.profileswitch)
|
private SWScreen screenProfileSwitch = new SWScreen(R.string.profileswitch)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
|
@ -421,6 +436,8 @@ public class SWDefinition {
|
||||||
.add(screenPermissionBt)
|
.add(screenPermissionBt)
|
||||||
.add(screenPermissionStore)
|
.add(screenPermissionStore)
|
||||||
.add(screenImport)
|
.add(screenImport)
|
||||||
|
.add(screenUnits)
|
||||||
|
.add(displaySettings)
|
||||||
.add(screenNsClient)
|
.add(screenNsClient)
|
||||||
.add(screenAge)
|
.add(screenAge)
|
||||||
.add(screenInsulin)
|
.add(screenInsulin)
|
||||||
|
@ -428,7 +445,6 @@ public class SWDefinition {
|
||||||
.add(screenProfile)
|
.add(screenProfile)
|
||||||
.add(screenNsProfile)
|
.add(screenNsProfile)
|
||||||
.add(screenLocalProfile)
|
.add(screenLocalProfile)
|
||||||
.add(screenSimpleProfile)
|
|
||||||
.add(screenProfileSwitch)
|
.add(screenProfileSwitch)
|
||||||
.add(screenPump)
|
.add(screenPump)
|
||||||
.add(screenAps)
|
.add(screenAps)
|
||||||
|
@ -448,6 +464,8 @@ public class SWDefinition {
|
||||||
.add(screenPermissionBt)
|
.add(screenPermissionBt)
|
||||||
.add(screenPermissionStore)
|
.add(screenPermissionStore)
|
||||||
.add(screenImport)
|
.add(screenImport)
|
||||||
|
.add(screenUnits)
|
||||||
|
.add(displaySettings)
|
||||||
.add(screenNsClient)
|
.add(screenNsClient)
|
||||||
.add(screenAge)
|
.add(screenAge)
|
||||||
.add(screenInsulin)
|
.add(screenInsulin)
|
||||||
|
@ -455,7 +473,6 @@ public class SWDefinition {
|
||||||
.add(screenProfile)
|
.add(screenProfile)
|
||||||
.add(screenNsProfile)
|
.add(screenNsProfile)
|
||||||
.add(screenLocalProfile)
|
.add(screenLocalProfile)
|
||||||
.add(screenSimpleProfile)
|
|
||||||
.add(screenProfileSwitch)
|
.add(screenProfileSwitch)
|
||||||
.add(screenPump)
|
.add(screenPump)
|
||||||
.add(screenSensitivity)
|
.add(screenSensitivity)
|
||||||
|
@ -470,6 +487,8 @@ public class SWDefinition {
|
||||||
.add(screenPermissionBattery)
|
.add(screenPermissionBattery)
|
||||||
.add(screenPermissionStore)
|
.add(screenPermissionStore)
|
||||||
.add(screenImport)
|
.add(screenImport)
|
||||||
|
.add(screenUnits)
|
||||||
|
.add(displaySettings)
|
||||||
.add(screenNsClient)
|
.add(screenNsClient)
|
||||||
.add(screenBgSource)
|
.add(screenBgSource)
|
||||||
.add(screenAge)
|
.add(screenAge)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.setupwizard;
|
||||||
|
|
||||||
|
public interface SWNumberValidator {
|
||||||
|
boolean isValid(double value);
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
package info.nightscout.androidaps.setupwizard.elements;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
|
import info.nightscout.androidaps.setupwizard.SWNumberValidator;
|
||||||
|
import info.nightscout.androidaps.utils.NumberPicker;
|
||||||
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
|
|
||||||
|
|
||||||
|
public class SWEditNumberWithUnits extends SWItem {
|
||||||
|
|
||||||
|
private SWNumberValidator validator = new SWNumberValidator() {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(double value) {
|
||||||
|
return value >= min && value <= max;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private int updateDelay = 0;
|
||||||
|
private double init, min, max;
|
||||||
|
|
||||||
|
public SWEditNumberWithUnits(double defaultMMOL, double minMMOL, double maxMMOL) {
|
||||||
|
super(Type.UNITNUMBER);
|
||||||
|
init = defaultMMOL;
|
||||||
|
min = minMMOL;
|
||||||
|
max = maxMMOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateDialog(LinearLayout layout) {
|
||||||
|
Context context = layout.getContext();
|
||||||
|
|
||||||
|
TextWatcher watcher = new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
if (validator != null && validator.isValid(SafeParse.stringToDouble(s.toString())))
|
||||||
|
save(s.toString(), updateDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TextView l = new TextView(context);
|
||||||
|
l.setId(View.generateViewId());
|
||||||
|
l.setText(label);
|
||||||
|
l.setTypeface(l.getTypeface(), Typeface.BOLD);
|
||||||
|
layout.addView(l);
|
||||||
|
|
||||||
|
double initValue = SP.getDouble(preferenceId, init);
|
||||||
|
initValue = Profile.toCurrentUnits(initValue);
|
||||||
|
|
||||||
|
NumberPicker numberPicker = new NumberPicker(context);
|
||||||
|
if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL))
|
||||||
|
numberPicker.setParams(initValue, min, max, 0.1d, new DecimalFormat("0.0"), false, null, watcher);
|
||||||
|
else
|
||||||
|
numberPicker.setParams(initValue, min * 18, max * 18, 1d, new DecimalFormat("0"), false, null, watcher);
|
||||||
|
|
||||||
|
// LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) numberPicker.getLayoutParams();
|
||||||
|
// ll.gravity = Gravity.CENTER;
|
||||||
|
// numberPicker.setLayoutParams(ll);
|
||||||
|
layout.addView(numberPicker);
|
||||||
|
|
||||||
|
TextView c = new TextView(context);
|
||||||
|
c.setId(View.generateViewId());
|
||||||
|
c.setText(comment);
|
||||||
|
c.setTypeface(c.getTypeface(), Typeface.ITALIC);
|
||||||
|
layout.addView(c);
|
||||||
|
|
||||||
|
super.generateDialog(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SWEditNumberWithUnits preferenceId(int preferenceId) {
|
||||||
|
this.preferenceId = preferenceId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SWEditNumberWithUnits updateDelay(int updateDelay) {
|
||||||
|
this.updateDelay = updateDelay;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import android.graphics.Typeface;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -31,19 +32,19 @@ public class SWEditString extends SWItem {
|
||||||
Context context = layout.getContext();
|
Context context = layout.getContext();
|
||||||
|
|
||||||
TextView l = new TextView(context);
|
TextView l = new TextView(context);
|
||||||
l.setId(layout.generateViewId());
|
l.setId(View.generateViewId());
|
||||||
l.setText(label);
|
l.setText(label);
|
||||||
l.setTypeface(l.getTypeface(), Typeface.BOLD);
|
l.setTypeface(l.getTypeface(), Typeface.BOLD);
|
||||||
layout.addView(l);
|
layout.addView(l);
|
||||||
|
|
||||||
TextView c = new TextView(context);
|
TextView c = new TextView(context);
|
||||||
c.setId(layout.generateViewId());
|
c.setId(View.generateViewId());
|
||||||
c.setText(comment);
|
c.setText(comment);
|
||||||
c.setTypeface(c.getTypeface(), Typeface.ITALIC);
|
c.setTypeface(c.getTypeface(), Typeface.ITALIC);
|
||||||
layout.addView(c);
|
layout.addView(c);
|
||||||
|
|
||||||
EditText editText = new EditText(context);
|
EditText editText = new EditText(context);
|
||||||
editText.setId(layout.generateViewId());
|
editText.setId(View.generateViewId());
|
||||||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
editText.setMaxLines(1);
|
editText.setMaxLines(1);
|
||||||
editText.setText(SP.getString(preferenceId, ""));
|
editText.setText(SP.getString(preferenceId, ""));
|
||||||
|
|
|
@ -38,7 +38,8 @@ public class SWItem {
|
||||||
RADIOBUTTON,
|
RADIOBUTTON,
|
||||||
PLUGIN,
|
PLUGIN,
|
||||||
BUTTON,
|
BUTTON,
|
||||||
FRAGMENT
|
FRAGMENT,
|
||||||
|
UNITNUMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
|
|
@ -117,12 +117,12 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
private fun doCalc() {
|
private fun doCalc() {
|
||||||
|
|
||||||
// Insulin from BG
|
// Insulin from BG
|
||||||
sens = profile.isf
|
sens = Profile.fromMgdlToUnits(profile.isfMgdl, ProfileFunctions.getSystemUnits())
|
||||||
targetBGLow = profile.targetLow
|
targetBGLow = Profile.fromMgdlToUnits(profile.targetLowMgdl, ProfileFunctions.getSystemUnits())
|
||||||
targetBGHigh = profile.targetHigh
|
targetBGHigh = Profile.fromMgdlToUnits(profile.targetHighMgdl, ProfileFunctions.getSystemUnits())
|
||||||
if (useTT && tempTarget != null) {
|
if (useTT && tempTarget != null) {
|
||||||
targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, profile.units)
|
targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits())
|
||||||
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, profile.units)
|
targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits())
|
||||||
}
|
}
|
||||||
if (useBg && bg > 0) {
|
if (useBg && bg > 0) {
|
||||||
bgDiff = when {
|
bgDiff = when {
|
||||||
|
@ -138,7 +138,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
glucoseStatus?.let {
|
glucoseStatus?.let {
|
||||||
if (useTrend) {
|
if (useTrend) {
|
||||||
trend = it.short_avgdelta
|
trend = it.short_avgdelta
|
||||||
insulinFromTrend = Profile.fromMgdlToUnits(trend, profile.units) * 3 / sens
|
insulinFromTrend = Profile.fromMgdlToUnits(trend, ProfileFunctions.getSystemUnits()) * 3 / sens
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.utils;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
|
|
||||||
public class DefaultValueHelper {
|
public class DefaultValueHelper {
|
||||||
|
|
||||||
|
@ -41,11 +43,12 @@ public class DefaultValueHelper {
|
||||||
/**
|
/**
|
||||||
* returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
|
* returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
|
||||||
*
|
*
|
||||||
* @param units
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double determineEatingSoonTT(String units) {
|
public double determineEatingSoonTT() {
|
||||||
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
double value = SP.getDouble(R.string.key_eatingsoon_target, this.getDefaultEatingSoonTT(units));
|
double value = SP.getDouble(R.string.key_eatingsoon_target, this.getDefaultEatingSoonTT(units));
|
||||||
|
value = Profile.toCurrentUnits(value);
|
||||||
return value > 0 ? value : this.getDefaultEatingSoonTT(units);
|
return value > 0 ? value : this.getDefaultEatingSoonTT(units);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +61,12 @@ public class DefaultValueHelper {
|
||||||
/**
|
/**
|
||||||
* returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
|
* returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
|
||||||
*
|
*
|
||||||
* @param units
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double determineActivityTT(String units) {
|
public double determineActivityTT() {
|
||||||
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
double value = SP.getDouble(R.string.key_activity_target, this.getDefaultActivityTT(units));
|
double value = SP.getDouble(R.string.key_activity_target, this.getDefaultActivityTT(units));
|
||||||
|
value = Profile.toCurrentUnits(value);
|
||||||
return value > 0 ? value : this.getDefaultActivityTT(units);
|
return value > 0 ? value : this.getDefaultActivityTT(units);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,11 +78,12 @@ public class DefaultValueHelper {
|
||||||
/**
|
/**
|
||||||
* returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
|
* returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
|
||||||
*
|
*
|
||||||
* @param units
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double determineHypoTT(String units) {
|
public double determineHypoTT() {
|
||||||
|
String units = ProfileFunctions.getSystemUnits();
|
||||||
double value = SP.getDouble(R.string.key_hypo_target, this.getDefaultHypoTT(units));
|
double value = SP.getDouble(R.string.key_hypo_target, this.getDefaultHypoTT(units));
|
||||||
|
value = Profile.toCurrentUnits(value);
|
||||||
return value > 0 ? value : this.getDefaultHypoTT(units);
|
return value > 0 ? value : this.getDefaultHypoTT(units);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
||||||
|
|
||||||
public NumberPicker(Context context) {
|
public NumberPicker(Context context) {
|
||||||
super(context, null);
|
super(context, null);
|
||||||
|
this.initialize(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NumberPicker(Context context, AttributeSet attrs) {
|
public NumberPicker(Context context, AttributeSet attrs) {
|
||||||
|
@ -94,9 +95,13 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
|
||||||
this.initialize(context);
|
this.initialize(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void inflate(Context context) {
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.number_picker_layout, this, true);
|
||||||
|
}
|
||||||
|
|
||||||
private void initialize(Context context) {
|
private void initialize(Context context) {
|
||||||
// set layout view
|
// set layout view
|
||||||
LayoutInflater.from(context).inflate(R.layout.number_picker_layout, this, true);
|
inflate(context);
|
||||||
|
|
||||||
// init ui components
|
// init ui components
|
||||||
minusButton = findViewById(R.id.decrement);
|
minusButton = findViewById(R.id.decrement);
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package info.nightscout.androidaps.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 28.06.2016.
|
||||||
|
*/
|
||||||
|
public class NumberPickerVertical extends NumberPicker {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(NumberPickerVertical.class);
|
||||||
|
|
||||||
|
public NumberPickerVertical(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberPickerVertical(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void inflate(Context context) {
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.number_picker_layout_vertical, this, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -83,4 +83,24 @@ public class OKDialog {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showConfirmation(final Activity activity, String message, final Runnable ok, final Runnable cancel) {
|
||||||
|
AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (ok != null) {
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
activity.runOnUiThread(ok);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
|
||||||
|
dialog.dismiss();
|
||||||
|
if (cancel != null) {
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
activity.runOnUiThread(cancel);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,11 +84,11 @@ public class TimeListEdit {
|
||||||
|
|
||||||
textlabel = new TextView(context);
|
textlabel = new TextView(context);
|
||||||
textlabel.setText(label);
|
textlabel.setText(label);
|
||||||
textlabel.setGravity(Gravity.START);
|
textlabel.setGravity(Gravity.CENTER);
|
||||||
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
|
llp.setMargins(0, 5, 0, 5);
|
||||||
textlabel.setLayoutParams(llp);
|
textlabel.setLayoutParams(llp);
|
||||||
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
|
//textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
|
||||||
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
|
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
|
||||||
layout.addView(textlabel);
|
layout.addView(textlabel);
|
||||||
|
|
||||||
|
@ -119,7 +119,8 @@ public class TimeListEdit {
|
||||||
private void inflateRow(final int position) {
|
private void inflateRow(final int position) {
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(context);
|
LayoutInflater inflater = LayoutInflater.from(context);
|
||||||
View childView = intervals[position] = inflater.inflate(R.layout.timelistedit_element, layout, false);
|
int resource = data2 == null ? R.layout.timelistedit_element : R.layout.timelistedit_element_vertical;
|
||||||
|
View childView = intervals[position] = inflater.inflate(resource, layout, false);
|
||||||
spinners[position] = new SpinnerHelper(childView.findViewById(R.id.timelistedit_time));
|
spinners[position] = new SpinnerHelper(childView.findViewById(R.id.timelistedit_time));
|
||||||
numberPickers1[position] = childView.findViewById(R.id.timelistedit_edit1);
|
numberPickers1[position] = childView.findViewById(R.id.timelistedit_edit1);
|
||||||
numberPickers2[position] = childView.findViewById(R.id.timelistedit_edit2);
|
numberPickers2[position] = childView.findViewById(R.id.timelistedit_edit2);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class XdripCalibrations {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putDouble("glucose_number", bg);
|
bundle.putDouble("glucose_number", bg);
|
||||||
bundle.putString("units", ProfileFunctions.getInstance().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
|
bundle.putString("units", ProfileFunctions.getSystemUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
|
||||||
bundle.putLong("timestamp", System.currentTimeMillis());
|
bundle.putLong("timestamp", System.currentTimeMillis());
|
||||||
Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
|
Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
|
|
BIN
app/src/main/res/drawable/clone.png
Normal file
BIN
app/src/main/res/drawable/clone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 643 B |
|
@ -9,98 +9,210 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/invalidprofile"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="start"
|
||||||
android:text="@string/invalidprofile"
|
android:orientation="horizontal">
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
||||||
android:textColor="@android:color/holo_red_light"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/linearBlockBackground"
|
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="@string/units"
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:text="@string/selected_profile"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/localprofile_spinner"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_horizontal"
|
android:layout_marginBottom="10dp"
|
||||||
|
android:gravity="start"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<RadioButton
|
<TextView
|
||||||
android:id="@+id/localprofile_mgdl"
|
android:id="@+id/localprofile_units"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/mgdl" />
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:text="@string/units_colon"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<RadioButton
|
<TextView
|
||||||
android:id="@+id/localprofile_mmol"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/mmol" />
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/localprofile_profile_add"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="15dp"
|
||||||
|
android:contentDescription="@string/addnew"
|
||||||
|
android:src="@drawable/add" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/localprofile_profile_clone"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="15dp"
|
||||||
|
android:contentDescription="@string/clone_label"
|
||||||
|
android:src="@drawable/clone" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/localprofile_profile_remove"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="15dp"
|
||||||
|
android:contentDescription="@string/remove_label"
|
||||||
|
android:src="@drawable/remove" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="5"
|
||||||
|
android:paddingBottom="10dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/dia_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/dia_short"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ic_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/ic_short"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/isf_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/isf_short"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/basal_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/basal_short"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/target_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/target_short"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/localprofile_dia_placeholder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/linearBlockBackground"
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="@string/dia"
|
android:layout_marginBottom="10dp"
|
||||||
|
android:labelFor="@+id/localprofile_name"
|
||||||
|
android:text="@string/profile_name"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/localprofile_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ems="10"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="text" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp">
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall">
|
|
||||||
|
|
||||||
<!-- dummy to align with TimeListEdits added dynamically -->
|
<TextView
|
||||||
<Spinner
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:minWidth="80dp"
|
android:text="@string/dia"
|
||||||
android:visibility="invisible"/>
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<info.nightscout.androidaps.utils.NumberPicker
|
<info.nightscout.androidaps.utils.NumberPicker
|
||||||
android:id="@+id/localprofile_dia"
|
android:id="@+id/localprofile_dia"
|
||||||
android:layout_width="130dp"
|
android:layout_width="130dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_marginEnd="5dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:layout_marginBottom="10dp" />
|
android:layout_marginBottom="10dp" />
|
||||||
|
|
||||||
<!-- dummy to align with TimeListEdits added dynamically -->
|
<TextView
|
||||||
<ImageView
|
|
||||||
android:id="@+id/timelistedit_add"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginStart="15dp"
|
android:text="@string/hours"
|
||||||
android:src="@drawable/add"
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
android:visibility="invisible"/>
|
|
||||||
|
|
||||||
<!-- dummy to align with TimeListEdits added dynamically -->
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/timelistedit_remove"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginStart="15dp"
|
|
||||||
android:src="@drawable/remove"
|
|
||||||
android:visibility="invisible"/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/localprofile_ic"
|
android:id="@+id/localprofile_ic"
|
||||||
|
@ -136,7 +248,7 @@
|
||||||
android:id="@+id/localprofile_profileswitch"
|
android:id="@+id/localprofile_profileswitch"
|
||||||
style="?android:attr/buttonStyle"
|
style="?android:attr/buttonStyle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginBottom="3dp"
|
android:layout_marginBottom="3dp"
|
||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
|
|
39
app/src/main/res/layout/number_picker_layout_vertical.xml
Normal file
39
app/src/main/res/layout/number_picker_layout_vertical.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:background="@drawable/background_darkgray"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/increment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:padding="0dp"
|
||||||
|
android:text="+"
|
||||||
|
android:textColor="@color/mdtp_white"
|
||||||
|
android:textSize="25sp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/display"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:background="@drawable/border_gray"
|
||||||
|
android:gravity="center"
|
||||||
|
android:imeOptions="actionDone"
|
||||||
|
android:inputType="number"
|
||||||
|
android:text="1"
|
||||||
|
android:textColor="@android:color/black" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/decrement"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:padding="0dp"
|
||||||
|
android:text="—"
|
||||||
|
android:textColor="@color/mdtp_white"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -1,145 +0,0 @@
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".plugins.profile.simple.SimpleProfileFragment">
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/invalidprofile"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:text="@string/invalidprofile"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
||||||
android:textColor="@android:color/holo_red_light"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/units"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/simpleprofile_mgdl"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/mgdl" />
|
|
||||||
|
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/simpleprofile_mmol"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/mmol" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/dia"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_dia"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/nsprofileview_ic_label"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_ic"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/nsprofileview_isf_label"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_isf"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/simpleprofile_basalrate_label"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/basal_rate"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_basalrate"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/target_range"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_targetlow"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/simpleprofile_targethigh"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/simpleprofile_profileswitch"
|
|
||||||
style="?android:attr/buttonStyle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:layout_marginBottom="3dp"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:layout_marginTop="3dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:paddingLeft="10dp"
|
|
||||||
android:paddingRight="10dp"
|
|
||||||
android:text="@string/activate_profile"
|
|
||||||
android:textColor="@color/colorProfileSwitchButton" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
49
app/src/main/res/layout/timelistedit_element_vertical.xml
Normal file
49
app/src/main/res/layout/timelistedit_element_vertical.xml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/timelistedit_time"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:minWidth="80dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<info.nightscout.androidaps.utils.NumberPickerVertical
|
||||||
|
android:id="@+id/timelistedit_edit1"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
<info.nightscout.androidaps.utils.NumberPickerVertical
|
||||||
|
android:id="@+id/timelistedit_edit2"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="100dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/timelistedit_add"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:src="@drawable/add" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/timelistedit_remove"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:src="@drawable/remove" />
|
||||||
|
</LinearLayout>
|
|
@ -88,6 +88,16 @@
|
||||||
android:text="NS"
|
android:text="NS"
|
||||||
android:textColor="@color/colorSetTempButton" />
|
android:textColor="@color/colorSetTempButton" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/profileswitch_clone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:paddingStart="10dp"
|
||||||
|
android:text="@string/clone_label"
|
||||||
|
android:textAlignment="viewEnd"
|
||||||
|
android:textColor="@android:color/holo_blue_light" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/profileswitch_remove"
|
android:id="@+id/profileswitch_remove"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -97,6 +107,7 @@
|
||||||
android:text="@string/overview_quickwizard_item_remove_button"
|
android:text="@string/overview_quickwizard_item_remove_button"
|
||||||
android:textAlignment="viewEnd"
|
android:textAlignment="viewEnd"
|
||||||
android:textColor="@android:color/holo_orange_light" />
|
android:textColor="@android:color/holo_orange_light" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
|
|
@ -10,6 +10,15 @@
|
||||||
<item>open</item>
|
<item>open</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="unitsArray">
|
||||||
|
<item>mg/dL</item>
|
||||||
|
<item>mmol/L</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="unitsValues" translatable="false">
|
||||||
|
<item>mg/dl</item>
|
||||||
|
<item>mmol</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="languagesArray">
|
<string-array name="languagesArray">
|
||||||
<item>@string/en_lang</item>
|
<item>@string/en_lang</item>
|
||||||
<item>@string/af_lang</item>
|
<item>@string/af_lang</item>
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
<color name="graphgrid">#757575</color>
|
<color name="graphgrid">#757575</color>
|
||||||
<color name="colorLightGray">#d8d8d8</color>
|
<color name="colorLightGray">#d8d8d8</color>
|
||||||
<color name="warning">#ff1a1a</color>
|
<color name="warning">#ff1a1a</color>
|
||||||
|
<color name="error_background">#66FC0000</color>
|
||||||
|
<color name="ok_background">#323232</color>
|
||||||
|
|
||||||
<color name="defaultbackground">#424242</color>
|
<color name="defaultbackground">#424242</color>
|
||||||
<color name="defaulttext">#BBBBBB</color>
|
<color name="defaulttext">#BBBBBB</color>
|
||||||
|
|
|
@ -410,10 +410,11 @@
|
||||||
<string name="button1">Button 1</string>
|
<string name="button1">Button 1</string>
|
||||||
<string name="button2">Button 2</string>
|
<string name="button2">Button 2</string>
|
||||||
<string name="button3">Button 3</string>
|
<string name="button3">Button 3</string>
|
||||||
<string name="units">Units:</string>
|
<string name="units_colon">Units:</string>
|
||||||
|
<string name="units">Units</string>
|
||||||
<string name="mgdl">mg/dl</string>
|
<string name="mgdl">mg/dl</string>
|
||||||
<string name="mmol">mmol/l</string>
|
<string name="mmol">mmol/l</string>
|
||||||
<string name="dia">DIA:</string>
|
<string name="dia">DIA</string>
|
||||||
<string name="target_range">Target range:</string>
|
<string name="target_range">Target range:</string>
|
||||||
<string name="prefs_range_title">Range for Visualization</string>
|
<string name="prefs_range_title">Range for Visualization</string>
|
||||||
<string name="prefs_range_summary">High and low mark for the charts in Overview and Smartwatch</string>
|
<string name="prefs_range_summary">High and low mark for the charts in Overview and Smartwatch</string>
|
||||||
|
@ -1627,6 +1628,11 @@
|
||||||
<string name="format_percent">%1$d%%</string>
|
<string name="format_percent">%1$d%%</string>
|
||||||
<string name="boluswizard">Bolus wizard</string>
|
<string name="boluswizard">Bolus wizard</string>
|
||||||
<string name="unit_minute_short">min</string>
|
<string name="unit_minute_short">min</string>
|
||||||
|
<string name="profile_name">Profile name:</string>
|
||||||
|
<string name="selected_profile">Selected:</string>
|
||||||
|
<string name="unitsnosemicolon">Units</string>
|
||||||
|
<string name="key_units" translatable="false">units</string>
|
||||||
|
<string name="doyouwantswitchprofile">Do you want to switch profile and discard changes made to current profile?</string>
|
||||||
<string name="key_wizard_calculation_visible" translatable="false">wizard_calculation_visible</string>
|
<string name="key_wizard_calculation_visible" translatable="false">wizard_calculation_visible</string>
|
||||||
<string name="format_carbs">%1$dg</string>
|
<string name="format_carbs">%1$dg</string>
|
||||||
<string name="common_on">On</string>
|
<string name="common_on">On</string>
|
||||||
|
@ -1635,5 +1641,24 @@
|
||||||
<string name="objectives_button_unstart">Clear started</string>
|
<string name="objectives_button_unstart">Clear started</string>
|
||||||
<string name="timedetection">Time detection</string>
|
<string name="timedetection">Time detection</string>
|
||||||
<string name="doyouwantresetstart">Do you want reset objective start? You may lose your progress.</string>
|
<string name="doyouwantresetstart">Do you want reset objective start? You may lose your progress.</string>
|
||||||
|
<string name="nopumpselected">No pump selected</string>
|
||||||
|
<string name="setupwizard_units_prompt">Select units you want to display values in</string>
|
||||||
|
<string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string>
|
||||||
|
<string name="ns_ploadlocalprofile">Upload local profile changes to NS</string>
|
||||||
|
<string name="key_low_mark" translatable="false">low_mark</string>
|
||||||
|
<string name="key_high_mark" translatable="false">high_mark</string>
|
||||||
|
<string name="key_wear_detailediob" translatable="false">wear_detailediob</string>
|
||||||
|
<string name="key_wear_showbgi" translatable="false">wear_showbgi</string>
|
||||||
|
<string name="dia_short">DIA</string>
|
||||||
|
<string name="ic_short">IC</string>
|
||||||
|
<string name="isf_short">ISF</string>
|
||||||
|
<string name="target_short">TARG</string>
|
||||||
|
<string name="clone_label">Clone</string>
|
||||||
|
<string name="saveorresetchangesfirst">Save or reset current changes first</string>
|
||||||
|
<string name="deletecurrentprofile">Delete current profile?</string>
|
||||||
|
<string name="copytolocalprofile">Create new local profile from this profile switch?</string>
|
||||||
|
<string name="profilenamecontainsdot">Profile name contains dots.\nThis is not supported by NS.\nProfile is not uploaded to NS.</string>
|
||||||
|
<string name="low_mark_comment">Lower value of in range area (display only)</string>
|
||||||
|
<string name="high_mark_comment">Higher value of in range area (display only)</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/configbuilder_general">
|
android:title="@string/configbuilder_general">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:title="@string/unitsnosemicolon"
|
||||||
|
android:defaultValue="mg/dl"
|
||||||
|
android:entries="@array/unitsArray"
|
||||||
|
android:entryValues="@array/unitsValues"
|
||||||
|
android:key="@string/key_units" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:title="@string/language"
|
android:title="@string/language"
|
||||||
android:defaultValue="en"
|
android:defaultValue="en"
|
||||||
android:entries="@array/languagesArray"
|
android:entries="@array/languagesArray"
|
||||||
android:entryValues="@array/languagesValues"
|
android:entryValues="@array/languagesValues"
|
||||||
android:key="@string/key_language" />
|
android:key="@string/key_language" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
|
@ -25,6 +25,11 @@
|
||||||
android:key="@string/key_ns_logappstartedevent"
|
android:key="@string/key_ns_logappstartedevent"
|
||||||
android:title="@string/ns_logappstartedevent" />
|
android:title="@string/ns_logappstartedevent" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/key_ns_uploadlocalprofile"
|
||||||
|
android:title="@string/ns_ploadlocalprofile" />
|
||||||
|
|
||||||
<PreferenceScreen android:title="@string/ns_alarmoptions">
|
<PreferenceScreen android:title="@string/ns_alarmoptions">
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
|
|
@ -59,12 +59,12 @@
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="0"
|
android:defaultValue="0"
|
||||||
android:inputType="numberDecimal"
|
android:inputType="numberDecimal"
|
||||||
android:key="low_mark"
|
android:key="@string/key_low_mark"
|
||||||
android:title="@string/low_mark" />
|
android:title="@string/low_mark" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="0"
|
android:defaultValue="0"
|
||||||
android:inputType="numberDecimal"
|
android:inputType="numberDecimal"
|
||||||
android:key="high_mark"
|
android:key="@string/key_high_mark"
|
||||||
android:title="@string/high_mark" />
|
android:title="@string/high_mark" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
android:title="@string/wear_display_settings">
|
android:title="@string/wear_display_settings">
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="wear_detailediob"
|
android:key="@string/key_wear_detailediob"
|
||||||
android:summary="@string/wear_detailedIOB_summary"
|
android:summary="@string/wear_detailedIOB_summary"
|
||||||
android:title="@string/wear_detailedIOB_title" />
|
android:title="@string/wear_detailedIOB_title" />
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="wear_showbgi"
|
android:key="@string/key_wear_showbgi"
|
||||||
android:summary="@string/wear_showbgi_summary"
|
android:summary="@string/wear_showbgi_summary"
|
||||||
android:title="@string/wear_showbgi_title" />
|
android:title="@string/wear_showbgi_title" />
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
|
|
@ -281,10 +281,10 @@ public class AAPSMocker {
|
||||||
public static void mockProfileFunctions() {
|
public static void mockProfileFunctions() {
|
||||||
PowerMockito.mockStatic(ProfileFunctions.class);
|
PowerMockito.mockStatic(ProfileFunctions.class);
|
||||||
profileFunctions = PowerMockito.mock(ProfileFunctions.class);
|
profileFunctions = PowerMockito.mock(ProfileFunctions.class);
|
||||||
|
PowerMockito.when(ProfileFunctions.getSystemUnits()).thenReturn(Constants.MGDL);
|
||||||
PowerMockito.when(ProfileFunctions.getInstance()).thenReturn(profileFunctions);
|
PowerMockito.when(ProfileFunctions.getInstance()).thenReturn(profileFunctions);
|
||||||
profile = getValidProfile();
|
profile = getValidProfile();
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfile()).thenReturn(profile);
|
PowerMockito.when(ProfileFunctions.getInstance().getProfile()).thenReturn(profile);
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
|
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME);
|
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ public class ProfileTest {
|
||||||
c.set(Calendar.MINUTE, 0);
|
c.set(Calendar.MINUTE, 0);
|
||||||
c.set(Calendar.SECOND, 0);
|
c.set(Calendar.SECOND, 0);
|
||||||
c.set(Calendar.MILLISECOND, 0);
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
Assert.assertEquals(100d, p.getIsf(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(1800d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
||||||
c.set(Calendar.HOUR_OF_DAY, 2);
|
c.set(Calendar.HOUR_OF_DAY, 2);
|
||||||
Assert.assertEquals(110d, p.getIsf(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(1980d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
||||||
Assert.assertEquals(110d, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01d);
|
Assert.assertEquals(110d, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01d);
|
||||||
Assert.assertEquals("00:00 100,0 mmol/U\n" + "02:00 110,0 mmol/U", p.getIsfList().replace(".", ","));
|
Assert.assertEquals("00:00 100,0 mmol/U\n" + "02:00 110,0 mmol/U", p.getIsfList().replace(".", ","));
|
||||||
Assert.assertEquals(30d, p.getIc(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(30d, p.getIc(c.getTimeInMillis()), 0.01d);
|
||||||
|
@ -73,10 +73,10 @@ public class ProfileTest {
|
||||||
Assert.assertEquals(0.1d, p.getMaxDailyBasal());
|
Assert.assertEquals(0.1d, p.getMaxDailyBasal());
|
||||||
Assert.assertEquals(2.4d, p.percentageBasalSum(), 0.01d);
|
Assert.assertEquals(2.4d, p.percentageBasalSum(), 0.01d);
|
||||||
Assert.assertEquals(2.4d, p.baseBasalSum(), 0.01d);
|
Assert.assertEquals(2.4d, p.baseBasalSum(), 0.01d);
|
||||||
Assert.assertEquals(4.5d, p.getTarget(2 * 60 * 60), 0.01d);
|
Assert.assertEquals(81d, p.getTargetMgdl(2 * 60 * 60), 0.01d);
|
||||||
Assert.assertEquals(4d, p.getTargetLow(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(72d, p.getTargetLowMgdl(c.getTimeInMillis()), 0.01d);
|
||||||
Assert.assertEquals(4d, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01d);
|
Assert.assertEquals(4d, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01d);
|
||||||
Assert.assertEquals(5d, p.getTargetHigh(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(90d, p.getTargetHighMgdl(c.getTimeInMillis()), 0.01d);
|
||||||
Assert.assertEquals(5d, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01d);
|
Assert.assertEquals(5d, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01d);
|
||||||
Assert.assertEquals("00:00 4,0 - 5,0 mmol", p.getTargetList().replace(".", ","));
|
Assert.assertEquals("00:00 4,0 - 5,0 mmol", p.getTargetList().replace(".", ","));
|
||||||
Assert.assertEquals(100, p.getPercentage());
|
Assert.assertEquals(100, p.getPercentage());
|
||||||
|
@ -122,7 +122,7 @@ public class ProfileTest {
|
||||||
Assert.assertEquals(0.05d, p.getBasal(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(0.05d, p.getBasal(c.getTimeInMillis()), 0.01d);
|
||||||
Assert.assertEquals(1.2d, p.percentageBasalSum(), 0.01d);
|
Assert.assertEquals(1.2d, p.percentageBasalSum(), 0.01d);
|
||||||
Assert.assertEquals(60d, p.getIc(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(60d, p.getIc(c.getTimeInMillis()), 0.01d);
|
||||||
Assert.assertEquals(220d, p.getIsf(c.getTimeInMillis()), 0.01d);
|
Assert.assertEquals(3960d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
|
||||||
|
|
||||||
// Test timeshift functionality
|
// Test timeshift functionality
|
||||||
p = new Profile(new JSONObject(validProfile), 100, 1);
|
p = new Profile(new JSONObject(validProfile), 100, 1);
|
||||||
|
@ -140,7 +140,7 @@ public class ProfileTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareMock() throws Exception {
|
public void prepareMock() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockConfigBuilder();
|
AAPSMocker.mockConfigBuilder();
|
||||||
AAPSMocker.mockStrings();
|
AAPSMocker.mockStrings();
|
||||||
|
@ -148,8 +148,5 @@ public class ProfileTest {
|
||||||
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
|
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
|
||||||
|
|
||||||
PowerMockito.mockStatic(FabricPrivacy.class);
|
PowerMockito.mockStatic(FabricPrivacy.class);
|
||||||
// PowerMockito.doNothing().when(FabricPrivacy.log(""));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,12 +132,8 @@ public class TriggerDeltaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void initializerTest(){
|
public void initializerTest(){
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MMOL);
|
|
||||||
TriggerDelta t = new TriggerDelta();
|
TriggerDelta t = new TriggerDelta();
|
||||||
Assert.assertTrue(t.getUnits().equals(Constants.MMOL));
|
Assert.assertTrue(t.getUnits().equals(Constants.MGDL));
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
|
|
||||||
t = new TriggerDelta();
|
|
||||||
Assert.assertEquals(Constants.MGDL, t.getUnits());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BgReading> generateValidBgData() {
|
List<BgReading> generateValidBgData() {
|
||||||
|
|
|
@ -75,5 +75,8 @@ public class NewNSTreatmentDialogTest {
|
||||||
.thenReturn(profilePlugin);
|
.thenReturn(profilePlugin);
|
||||||
|
|
||||||
dialog = new NewNSTreatmentDialog();
|
dialog = new NewNSTreatmentDialog();
|
||||||
|
|
||||||
|
PowerMockito.spy(System.class);
|
||||||
|
when(System.currentTimeMillis()).thenReturn(1000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
@ -57,7 +57,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
L.class, SP.class, MainApp.class, DateUtil.class, ProfileFunctions.class,
|
L.class, SP.class, MainApp.class, DateUtil.class, ProfileFunctions.class,
|
||||||
TreatmentsPlugin.class, SmsManager.class, IobCobCalculatorPlugin.class,
|
TreatmentsPlugin.class, SmsManager.class, IobCobCalculatorPlugin.class,
|
||||||
CommandQueue.class, ConfigBuilderPlugin.class, NSUpload.class, ProfileInterface.class,
|
CommandQueue.class, ConfigBuilderPlugin.class, NSUpload.class, ProfileInterface.class,
|
||||||
SimpleProfilePlugin.class, XdripCalibrations.class, VirtualPumpPlugin.class, LoopPlugin.class
|
LocalProfilePlugin.class, XdripCalibrations.class, VirtualPumpPlugin.class, LoopPlugin.class
|
||||||
})
|
})
|
||||||
|
|
||||||
public class SmsCommunicatorPluginTest {
|
public class SmsCommunicatorPluginTest {
|
||||||
|
@ -439,7 +439,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
ProfileInterface profileInterface = mock(SimpleProfilePlugin.class);
|
ProfileInterface profileInterface = mock(LocalProfilePlugin.class);
|
||||||
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface);
|
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface);
|
||||||
|
|
||||||
//PROFILE LIST (no profile defined)
|
//PROFILE LIST (no profile defined)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.data.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -28,7 +29,7 @@ import static org.mockito.Mockito.when;
|
||||||
* Created by kuchjir on 12/12/2017.
|
* Created by kuchjir on 12/12/2017.
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, ConstraintChecker.class})
|
@PrepareForTest({MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, ConstraintChecker.class, ProfileFunctions.class})
|
||||||
public class BolusWizardTest {
|
public class BolusWizardTest {
|
||||||
private static final double PUMP_BOLUS_STEP = 0.1;
|
private static final double PUMP_BOLUS_STEP = 0.1;
|
||||||
|
|
||||||
|
@ -68,9 +69,9 @@ public class BolusWizardTest {
|
||||||
|
|
||||||
private Profile setupProfile(Double targetLow, Double targetHigh, Double insulinSensitivityFactor, Double insulinToCarbRatio) {
|
private Profile setupProfile(Double targetLow, Double targetHigh, Double insulinSensitivityFactor, Double insulinToCarbRatio) {
|
||||||
Profile profile = mock(Profile.class);
|
Profile profile = mock(Profile.class);
|
||||||
when(profile.getTargetLow()).thenReturn(targetLow);
|
when(profile.getTargetLowMgdl()).thenReturn(targetLow);
|
||||||
when(profile.getTargetHigh()).thenReturn(targetHigh);
|
when(profile.getTargetHighMgdl()).thenReturn(targetHigh);
|
||||||
when(profile.getIsf()).thenReturn(insulinSensitivityFactor);
|
when(profile.getIsfMgdl()).thenReturn(insulinSensitivityFactor);
|
||||||
when(profile.getIc()).thenReturn(insulinToCarbRatio);
|
when(profile.getIc()).thenReturn(insulinToCarbRatio);
|
||||||
|
|
||||||
PowerMockito.mockStatic(GlucoseStatus.class);
|
PowerMockito.mockStatic(GlucoseStatus.class);
|
||||||
|
@ -95,6 +96,7 @@ public class BolusWizardTest {
|
||||||
return constraint;
|
return constraint;
|
||||||
}).when(AAPSMocker.constraintChecker).applyBolusConstraints(any(Constraint.class));
|
}).when(AAPSMocker.constraintChecker).applyBolusConstraints(any(Constraint.class));
|
||||||
|
|
||||||
|
AAPSMocker.mockProfileFunctions();
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue