Actions page & offline profile switch

This commit is contained in:
Milos Kozak 2016-11-05 15:46:11 +01:00
parent 75b07d0f18
commit 3ac9811d9a
12 changed files with 231 additions and 41 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

@ -16,6 +16,7 @@ import java.util.ArrayList;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -62,6 +63,7 @@ public class MainApp extends Application {
pluginsList = new ArrayList<>(); pluginsList = new ArrayList<>();
// Register all tabs in app here // Register all tabs in app here
pluginsList.add(OverviewFragment.getPlugin()); pluginsList.add(OverviewFragment.getPlugin());
pluginsList.add(ActionsFragment.getPlugin());
if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin());
if (Config.MM640G) pluginsList.add(MM640gFragment.getPlugin()); if (Config.MM640G) pluginsList.add(MM640gFragment.getPlugin());
if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.getPlugin()); if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.getPlugin());

View file

@ -0,0 +1,57 @@
package info.nightscout.androidaps.plugins.Actions;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
/**
* A simple {@link Fragment} subclass.
*/
public class ActionsFragment extends Fragment implements FragmentBase, View.OnClickListener {
static ActionsPlugin actionsPlugin = new ActionsPlugin();
static public ActionsPlugin getPlugin() {
return actionsPlugin;
}
public ActionsFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.actions_fragment, container, false);
view.findViewById(R.id.actions_profileswitch).setOnClickListener(this);
return view;
}
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
switch (view.getId()) {
case R.id.actions_profileswitch:
final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, false, false, false, true, false);
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch);
break;
default:
newDialog = null;
}
if (newDialog != null)
newDialog.show(manager, "NewNSTreatmentDialog");
}
}

View file

@ -0,0 +1,56 @@
package info.nightscout.androidaps.plugins.Actions;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
/**
* Created by mike on 05.11.2016.
*/
public class ActionsPlugin implements PluginBase {
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
@Override
public int getType() {
return PluginBase.GENERAL;
}
@Override
public String getFragmentClass() {
return ActionsFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.actions);
}
@Override
public boolean isEnabled(int type) {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
this.fragmentVisible = fragmentVisible;
}
}

View file

@ -22,44 +22,6 @@ public class CareportalFragment extends Fragment implements FragmentBase, View.O
return careportalPlugin; return careportalPlugin;
} }
public class OptionsToShow {
public int eventType;
public int eventName;
public boolean bg;
public boolean insulin;
public boolean carbs;
public boolean prebolus;
public boolean duration;
public boolean percent;
public boolean absolute;
public boolean profile;
public boolean split;
public OptionsToShow(int eventType,
int eventName,
boolean bg,
boolean insulin,
boolean carbs,
boolean prebolus,
boolean duration,
boolean percent,
boolean absolute,
boolean profile,
boolean split) {
this.eventType = eventType;
this.eventName = eventName;
this.bg = bg;
this.insulin = insulin;
this.carbs = carbs;
this.prebolus = prebolus;
this.duration = duration;
this.percent = percent;
this.absolute = absolute;
this.profile = profile;
this.split = split;
}
}
// bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split // bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split
final OptionsToShow bgcheck = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck, true, true, true, false, false, false, false, false, false); final OptionsToShow bgcheck = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck, true, true, true, false, false, false, false, false, false);
final OptionsToShow snackbolus = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus, true, true, true, true, false, false, false, false, false); final OptionsToShow snackbolus = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus, true, true, true, true, false, false, false, false, false);

View file

@ -40,12 +40,16 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
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.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
@ -62,7 +66,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
private FragmentActivity context; private FragmentActivity context;
private static CareportalFragment.OptionsToShow options; private static OptionsToShow options;
NSProfile profile; NSProfile profile;
String units; String units;
@ -107,7 +111,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
Date eventTime; Date eventTime;
public void setOptions(CareportalFragment.OptionsToShow options) { public void setOptions(OptionsToShow options) {
this.options = options; this.options = options;
} }
@ -532,6 +536,26 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
ConfigBuilderPlugin.uploadCareportalEntryToNS(data); ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
if (options.executeProfileSwitch) {
if (data.has("profile")) {
try {
String profile = data.getString("profile");
NSProfile nsProfile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
nsProfile.setActiveProfile(profile);
PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null) {
pump.setNewBasalProfile(nsProfile);
log.debug("Setting new profile: " + profile);
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
} else {
log.error("No active pump selected");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
} }
}); });
builder.setNegativeButton(getContext().getString(R.string.cancel), null); builder.setNegativeButton(getContext().getString(R.string.cancel), null);

View file

@ -0,0 +1,46 @@
package info.nightscout.androidaps.plugins.Careportal;
/**
* Created by mike on 05.11.2016.
*/
public class OptionsToShow {
public int eventType;
public int eventName;
public boolean bg;
public boolean insulin;
public boolean carbs;
public boolean prebolus;
public boolean duration;
public boolean percent;
public boolean absolute;
public boolean profile;
public boolean split;
// perform direct actions
public boolean executeProfileSwitch = false;
public OptionsToShow(int eventType,
int eventName,
boolean bg,
boolean insulin,
boolean carbs,
boolean prebolus,
boolean duration,
boolean percent,
boolean absolute,
boolean profile,
boolean split) {
this.eventType = eventType;
this.eventName = eventName;
this.bg = bg;
this.insulin = insulin;
this.carbs = carbs;
this.prebolus = prebolus;
this.duration = duration;
this.percent = percent;
this.absolute = absolute;
this.profile = profile;
this.split = split;
}
}

View file

@ -349,6 +349,19 @@ public class NSProfile {
return activeProfile; return activeProfile;
} }
public void setActiveProfile(String newProfile) {
try {
JSONObject store = json.getJSONObject("store");
if (newProfile != null && store.has(newProfile)) {
activeProfile = newProfile;
} else {
log.error("Attempt to set wrong active profile");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public Double getMaxDailyBasal() { public Double getMaxDailyBasal() {
Double max = 0d; Double max = 0d;
for (Integer hour = 0; hour < 24; hour++) { for (Integer hour = 0; hour < 24; hour++) {

View file

@ -0,0 +1,27 @@
<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="info.nightscout.androidaps.plugins.Actions.ActionsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/actions_profileswitch"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/careportal_profileswitch"
android:textColor="@color/colorProfileSwitchButton" />
</LinearLayout>
</FrameLayout>

View file

@ -321,4 +321,5 @@
<string name="mealbolus">Bolus</string> <string name="mealbolus">Bolus</string>
<string name="ko_lang">Korean</string> <string name="ko_lang">Korean</string>
<string name="correctionbous">Korekce</string> <string name="correctionbous">Korekce</string>
<string name="actions">Akce</string>
</resources> </resources>

View file

@ -15,6 +15,7 @@
<color name="colorCancelTempButton">#47c8ff</color> <color name="colorCancelTempButton">#47c8ff</color>
<color name="colorSetTempButton">#FF478EFF</color> <color name="colorSetTempButton">#FF478EFF</color>
<color name="colorSetExtendedButton">#FFDD7792</color> <color name="colorSetExtendedButton">#FFDD7792</color>
<color name="colorProfileSwitchButton">#ca77dd</color>
<color name="colorInProgress">#c45026</color> <color name="colorInProgress">#c45026</color>
<color name="colorAffectingIOB">#830400</color> <color name="colorAffectingIOB">#830400</color>

View file

@ -333,5 +333,6 @@
<string name="mealbolus">Meal</string> <string name="mealbolus">Meal</string>
<string name="correctionbous">Corr</string> <string name="correctionbous">Corr</string>
<string name="ko_lang">Korean</string> <string name="ko_lang">Korean</string>
<string name="actions">Actions</string>
</resources> </resources>