Merge pull request #47 from MilosKozak/profileswitch

Actions page & offline profile switch
This commit is contained in:
Milos Kozak 2016-11-05 21:55:20 +01:00 committed by GitHub
commit c5c1a194d5
17 changed files with 286 additions and 118 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</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" />
</component>
<component name="ProjectType">

View file

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

View file

@ -0,0 +1,65 @@
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.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog;
/**
* 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);
view.findViewById(R.id.actions_extendedbolus).setOnClickListener(this);
view.findViewById(R.id.actions_settempbasal).setOnClickListener(this);
return view;
}
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
switch (view.getId()) {
case R.id.actions_profileswitch:
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
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);
newDialog.show(manager, "NewNSTreatmentDialog");
break;
case R.id.actions_extendedbolus:
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
newExtendedDialog.show(manager, "NewExtendedDialog");
break;
case R.id.actions_settempbasal:
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
newTempDialog.show(manager, "NewTempDialog");
break;
}
}
}

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

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.Overview.Dialogs;
package info.nightscout.androidaps.plugins.Actions.dialogs;
import android.content.Context;
import android.content.DialogInterface;

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.Overview.Dialogs;
package info.nightscout.androidaps.plugins.Actions.dialogs;
import android.content.Context;
import android.content.DialogInterface;

View file

@ -22,44 +22,6 @@ public class CareportalFragment extends Fragment implements FragmentBase, View.O
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
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);

View file

@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.Careportal.Dialogs;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
@ -43,13 +43,10 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.PlusMinusEditText;
@ -62,7 +59,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
private FragmentActivity context;
private static CareportalFragment.OptionsToShow options;
private static OptionsToShow options;
NSProfile profile;
String units;
@ -107,10 +104,23 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
Date eventTime;
public void setOptions(CareportalFragment.OptionsToShow options) {
private static Handler sHandler;
private static HandlerThread sHandlerThread;
public void setOptions(OptionsToShow options) {
this.options = options;
}
public NewNSTreatmentDialog() {
super();
if (sHandlerThread == null) {
sHandlerThread = new HandlerThread(NewNSTreatmentDialog.class.getSimpleName());
sHandlerThread.start();
sHandler = new Handler(sHandlerThread.getLooper());
}
}
@Override
public void onAttach(Activity activity) {
context = (FragmentActivity) activity;
@ -532,6 +542,30 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
if (options.executeProfileSwitch) {
if (data.has("profile")) {
sHandler.post(new Runnable() {
@Override
public void run() {
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);

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

@ -43,7 +43,7 @@ import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResult;
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;

View file

@ -11,7 +11,6 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
@ -60,8 +59,6 @@ import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
import info.nightscout.androidaps.plugins.Overview.GraphSeriesExtension.PointsWithLabelGraphSeries;
@ -70,7 +67,6 @@ import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;
public class OverviewFragment extends Fragment {
@ -91,14 +87,11 @@ public class OverviewFragment extends Fragment {
GraphView bgGraph;
LinearLayout cancelTempLayout;
LinearLayout setTempLayout;
LinearLayout acceptTempLayout;
LinearLayout quickWizardLayout;
Button cancelTempButton;
Button treatmentButton;
Button wizardButton;
Button setTempButton;
Button setExtenedButton;
Button acceptTempButton;
Button quickWizardButton;
@ -131,10 +124,7 @@ public class OverviewFragment extends Fragment {
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp);
treatmentButton = (Button) view.findViewById(R.id.overview_treatment);
wizardButton = (Button) view.findViewById(R.id.overview_wizard);
setExtenedButton = (Button) view.findViewById(R.id.overview_extendedbolus);
setTempButton = (Button) view.findViewById(R.id.overview_settempbasal);
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp);
setTempLayout = (LinearLayout) view.findViewById(R.id.overview_settemplayout);
cancelTempLayout = (LinearLayout) view.findViewById(R.id.overview_canceltemplayout);
acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton);
acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout);
@ -183,23 +173,6 @@ public class OverviewFragment extends Fragment {
}
});
setTempButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
newTempDialog.show(manager, "NewTempDialog");
}
});
setExtenedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
newExtendedDialog.show(manager, "NewExtendedDialog");
}
});
acceptTempButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -465,26 +438,20 @@ public class OverviewFragment extends Fragment {
if (pump.isTempBasalInProgress()) {
TempBasal activeTemp = pump.getTempBasal();
cancelTempLayout.setVisibility(View.VISIBLE);
setTempLayout.setVisibility(View.GONE);
cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + ": " + activeTemp.toString());
runningTempView.setText(activeTemp.toString());
} else {
cancelTempLayout.setVisibility(View.GONE);
setTempLayout.setVisibility(View.VISIBLE);
Double currentBasal = pump.getBaseBasalRate();
runningTempView.setText(DecimalFormatter.to2Decimal(currentBasal) + " U/h");
}
if (profile == null) {
// disable all treatment buttons because we are not able to check constraints without profile
setExtenedButton.setVisibility(View.INVISIBLE);
setTempLayout.setVisibility(View.INVISIBLE);
wizardButton.setVisibility(View.INVISIBLE);
treatmentButton.setVisibility(View.INVISIBLE);
return;
} else {
setExtenedButton.setVisibility(View.VISIBLE);
setTempLayout.setVisibility(View.VISIBLE);
wizardButton.setVisibility(View.VISIBLE);
treatmentButton.setVisibility(View.VISIBLE);
}

View file

@ -349,6 +349,19 @@ public class NSProfile {
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() {
Double max = 0d;
for (Integer hour = 0; hour < 24; hour++) {

View file

@ -0,0 +1,53 @@
<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="vertical">
<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" />
<Button
android:id="@+id/actions_settempbasal"
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/overview_tempbasal_button"
android:textColor="@color/colorSetTempButton" />
<Button
android:id="@+id/actions_extendedbolus"
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/overview_extendedbolus_button"
android:textColor="@color/colorSetExtendedButton" />
</LinearLayout>
</FrameLayout>

View file

@ -136,39 +136,6 @@
</LinearLayout>
<LinearLayout
android:id="@+id/overview_settemplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/overview_settempbasal"
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/overview_tempbasal_button"
android:textColor="@color/colorSetTempButton" />
<Button
android:id="@+id/overview_extendedbolus"
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/overview_extendedbolus_button"
android:textColor="@color/colorSetExtendedButton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

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

View file

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

View file

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