Merge pull request #277 from AdrianLxM/refactor-profileswitch
extract method for new ProfileSwitch
This commit is contained in:
commit
e33d757975
|
@ -593,40 +593,11 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (options.executeProfileSwitch) {
|
if (options.executeProfileSwitch) {
|
||||||
if (data.has("profile")) {
|
if (data.has("profile")) {
|
||||||
sHandler.post(new Runnable() {
|
try {
|
||||||
@Override
|
doProfileSwitch(profileStore, data.getString("profile"), data.getInt("duration"));
|
||||||
public void run() {
|
} catch (JSONException e) {
|
||||||
try {
|
e.printStackTrace();
|
||||||
String profileName = data.getString("profile");
|
}
|
||||||
ProfileSwitch profileSwitch = new ProfileSwitch();
|
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
|
||||||
profileSwitch.source = Source.USER;
|
|
||||||
profileSwitch.profileName = profileName;
|
|
||||||
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
|
||||||
profileSwitch.durationInMinutes = data.getInt("duration");
|
|
||||||
if (ConfigBuilderPlugin.getActiveProfileInterface() instanceof CircadianPercentageProfilePlugin) {
|
|
||||||
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfileInterface();
|
|
||||||
profileSwitch.isCPP = true;
|
|
||||||
profileSwitch.timeshift = cpp.timeshift;
|
|
||||||
profileSwitch.percentage = cpp.percentage;
|
|
||||||
}
|
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
if (pump != null) {
|
|
||||||
pump.setNewBasalProfile(profileStore.getSpecificProfile(profileName));
|
|
||||||
log.debug("Setting new profile: " + profile);
|
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
|
||||||
} else {
|
|
||||||
log.error("No active pump selected");
|
|
||||||
}
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else if (options.executeTempTarget) {
|
} else if (options.executeTempTarget) {
|
||||||
try {
|
try {
|
||||||
|
@ -670,4 +641,35 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration) {
|
||||||
|
sHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ProfileSwitch profileSwitch = new ProfileSwitch();
|
||||||
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
|
profileSwitch.source = Source.USER;
|
||||||
|
profileSwitch.profileName = profileName;
|
||||||
|
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
||||||
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||||
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
if (ConfigBuilderPlugin.getActiveProfileInterface() instanceof CircadianPercentageProfilePlugin) {
|
||||||
|
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfileInterface();
|
||||||
|
profileSwitch.isCPP = true;
|
||||||
|
profileSwitch.timeshift = cpp.timeshift;
|
||||||
|
profileSwitch.percentage = cpp.percentage;
|
||||||
|
}
|
||||||
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
|
if (pump != null) {
|
||||||
|
pump.setNewBasalProfile(profileStore.getSpecificProfile(profileName));
|
||||||
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
|
} else {
|
||||||
|
log.error("No active pump selected");
|
||||||
|
}
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue