objectives fragment complete
This commit is contained in:
parent
6ebbfdc339
commit
a3d32fcb44
13 changed files with 359 additions and 75 deletions
|
@ -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">
|
||||
|
|
|
@ -160,6 +160,18 @@ public class MainActivity extends AppCompatActivity {
|
|||
return newList;
|
||||
}
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
|
||||
|
||||
Iterator<PluginBase> it = pluginsList.iterator();
|
||||
while (it.hasNext()) {
|
||||
PluginBase p = it.next();
|
||||
if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
|
||||
newList.add(p);
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static PluginBase getSpecificPlugin(Class pluginClass) {
|
||||
Iterator<PluginBase> it = pluginsList.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
|
|
@ -157,17 +157,42 @@ public class DataService extends IntentService {
|
|||
log.debug("Received status: " + bundles);
|
||||
if (bundles.containsKey("nsclientversioncode")) {
|
||||
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
|
||||
configBuilderFragment.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
||||
configBuilderFragment.nightscoutVersionName = bundles.getString("nightscoutversionname");
|
||||
configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
|
||||
configBuilderFragment.nsClientVersionName = bundles.getString("nsclientversionname");
|
||||
log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName);
|
||||
if (configBuilderFragment.nsClientVersionCode < 117)
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
|
||||
if (configBuilderFragment != null) {
|
||||
configBuilderFragment.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
||||
configBuilderFragment.nightscoutVersionName = bundles.getString("nightscoutversionname");
|
||||
configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
|
||||
configBuilderFragment.nsClientVersionName = bundles.getString("nsclientversionname");
|
||||
log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName);
|
||||
if (configBuilderFragment.nsClientVersionCode < 117)
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
|
||||
}
|
||||
}
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
|
||||
if (nsClientEnabled) {
|
||||
try {
|
||||
if (bundles.containsKey("devicestatuses")) {
|
||||
String devicestatusesstring = bundles.getString("devicestatuses");
|
||||
JSONArray jsonArray = new JSONArray(devicestatusesstring);
|
||||
if (jsonArray.length() > 0) {
|
||||
JSONObject devicestatusJson = jsonArray.getJSONObject(0);
|
||||
if (devicestatusJson.has("pump")) {
|
||||
// Objectives 0
|
||||
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
|
||||
if (objectivesFragment != null) {
|
||||
objectivesFragment.pumpStatusIsAvailableInNS = true;
|
||||
objectivesFragment.saveProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle profile
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
|
||||
try {
|
||||
|
@ -242,10 +267,8 @@ public class DataService extends IntentService {
|
|||
MainApp.bus().post(new EventTreatmentChange());
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -301,10 +324,8 @@ public class DataService extends IntentService {
|
|||
MainApp.bus().post(new EventTreatmentChange());
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,10 +349,8 @@ public class DataService extends IntentService {
|
|||
}
|
||||
MainApp.bus().post(new EventTreatmentChange());
|
||||
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,16 +389,17 @@ public class DataService extends IntentService {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
// Objectives 0
|
||||
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
|
||||
if (objectivesFragment != null) objectivesFragment.bgIsAvailableInNS = true;
|
||||
if (objectivesFragment != null) {
|
||||
objectivesFragment.bgIsAvailableInNS = true;
|
||||
objectivesFragment.saveProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,24 @@ import info.nightscout.androidaps.plugins.APSResult;
|
|||
*/
|
||||
public interface ConstraintsInterface {
|
||||
|
||||
boolean isLoopEnabled();
|
||||
|
||||
boolean isClosedModeEnabled();
|
||||
|
||||
boolean isAutosensModeEnabled();
|
||||
|
||||
boolean isAMAModeEnabled();
|
||||
|
||||
APSResult applyBasalConstraints(APSResult request);
|
||||
|
||||
Double applyBasalConstraints(Double absoluteRate);
|
||||
|
||||
Integer applyBasalConstraints(Integer percentRate);
|
||||
|
||||
Double applyBolusConstraints(Double insulin);
|
||||
|
||||
Integer applyCarbsConstraints(Integer carbs);
|
||||
|
||||
Double applyMaxIOBConstraints(Double maxIob);
|
||||
|
||||
}
|
||||
|
|
|
@ -722,11 +722,24 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
/**
|
||||
* Constraints interface
|
||||
**/
|
||||
@Override
|
||||
public boolean isLoopEnabled() {
|
||||
boolean result = true;
|
||||
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
result = result && constrain.isLoopEnabled();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosedModeEnabled() {
|
||||
boolean result = true;
|
||||
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
|
@ -735,9 +748,35 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutosensModeEnabled() {
|
||||
boolean result = true;
|
||||
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
result = result && constrain.isAutosensModeEnabled();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
boolean result = true;
|
||||
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
result = result && constrain.isAMAModeEnabled();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APSResult applyBasalConstraints(APSResult result) {
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
|
@ -749,11 +788,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
@Override
|
||||
public Double applyBasalConstraints(Double absoluteRate) {
|
||||
Double rateAfterConstrain = absoluteRate;
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
rateAfterConstrain = constrain.applyBasalConstraints(rateAfterConstrain);
|
||||
rateAfterConstrain = Math.min(constrain.applyBasalConstraints(rateAfterConstrain), rateAfterConstrain);
|
||||
}
|
||||
return rateAfterConstrain;
|
||||
}
|
||||
|
@ -761,11 +800,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
@Override
|
||||
public Integer applyBasalConstraints(Integer percentRate) {
|
||||
Integer rateAfterConstrain = percentRate;
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
rateAfterConstrain = constrain.applyBasalConstraints(rateAfterConstrain);
|
||||
rateAfterConstrain = Math.min(constrain.applyBasalConstraints(rateAfterConstrain), rateAfterConstrain);
|
||||
}
|
||||
return rateAfterConstrain;
|
||||
}
|
||||
|
@ -773,11 +812,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
@Override
|
||||
public Double applyBolusConstraints(Double insulin) {
|
||||
Double insulinAfterConstrain = insulin;
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
insulinAfterConstrain = constrain.applyBolusConstraints(insulinAfterConstrain);
|
||||
insulinAfterConstrain = Math.min(constrain.applyBolusConstraints(insulinAfterConstrain), insulinAfterConstrain);
|
||||
}
|
||||
return insulinAfterConstrain;
|
||||
}
|
||||
|
@ -785,15 +824,27 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
@Override
|
||||
public Integer applyCarbsConstraints(Integer carbs) {
|
||||
Integer carbsAfterConstrain = carbs;
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS);
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
carbsAfterConstrain = constrain.applyCarbsConstraints(carbsAfterConstrain);
|
||||
carbsAfterConstrain = Math.min(constrain.applyCarbsConstraints(carbsAfterConstrain), carbsAfterConstrain);
|
||||
}
|
||||
return carbsAfterConstrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyMaxIOBConstraints(Double maxIob) {
|
||||
Double maxIobAfterConstrain = maxIob;
|
||||
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled()) continue;
|
||||
maxIobAfterConstrain = Math.min(constrain.applyMaxIOBConstraints(maxIobAfterConstrain), maxIobAfterConstrain);
|
||||
}
|
||||
return maxIobAfterConstrain;
|
||||
}
|
||||
|
||||
public static void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) {
|
||||
try {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
|
|
|
@ -215,6 +215,18 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
public void invoke(boolean allowNotification) {
|
||||
ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder();
|
||||
if (!constraintsInterface.isLoopEnabled()) {
|
||||
clearGUI();
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastRunView.setText(activity.getString(R.string.loopdisabled));
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump();
|
||||
APSResult result = null;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.Objectives;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
@ -15,6 +16,8 @@ import android.widget.CheckBox;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -23,8 +26,10 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.APSResult;
|
||||
|
@ -34,7 +39,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
CheckBox enableFakeTime;
|
||||
CheckBox enableFake; // TODO: remove faking
|
||||
|
||||
boolean fragmentVisible = true;
|
||||
|
||||
|
@ -84,13 +89,15 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
}
|
||||
|
||||
class Objective {
|
||||
Integer num;
|
||||
String objective;
|
||||
String gate;
|
||||
Date started;
|
||||
Integer durationInDays;
|
||||
Date accomplished;
|
||||
|
||||
Objective(String objective, String gate, Date started, Integer durationInDays, Date accomplished) {
|
||||
Objective(Integer num, String objective, String gate, Date started, Integer durationInDays, Date accomplished) {
|
||||
this.num = num;
|
||||
this.objective = objective;
|
||||
this.gate = gate;
|
||||
this.started = started;
|
||||
|
@ -102,36 +109,91 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
// Objective 0
|
||||
public boolean bgIsAvailableInNS = false;
|
||||
public boolean pumpStatusIsAvailableInNS = false;
|
||||
// Objective 1
|
||||
public Integer manualEnacts = 0;
|
||||
public final Integer manualEnactsNeeded = 20;
|
||||
|
||||
class RequirementResult {
|
||||
boolean done = false;
|
||||
String comment = "";
|
||||
|
||||
public RequirementResult(boolean done, String comment) {
|
||||
this.done = done;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
|
||||
private String yesOrNo(boolean yes) {
|
||||
if (yes) return "☺";
|
||||
else return "---";
|
||||
}
|
||||
|
||||
private RequirementResult requirementsMet(Integer objNum) {
|
||||
switch (objNum) {
|
||||
case 0:
|
||||
return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS,
|
||||
getString(R.string.bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS)
|
||||
+ " " + getString(R.string.pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS));
|
||||
case 1:
|
||||
return new RequirementResult(manualEnacts >= manualEnactsNeeded,
|
||||
getString(R.string.manualenacts) + ": " + manualEnacts + "/" + manualEnactsNeeded);
|
||||
case 2:
|
||||
return new RequirementResult(true, "");
|
||||
default:
|
||||
return new RequirementResult(false, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<Objective> objectives;
|
||||
|
||||
private void initializeData() {
|
||||
objectives = new ArrayList<>();
|
||||
objectives.add(new Objective("Setting up visualization and monitoring, and analyzing basals and ratios",
|
||||
objectives.add(new Objective(0,
|
||||
"Setting up visualization and monitoring, and analyzing basals and ratios",
|
||||
"Verify that BG is available in Nightscout, and pump insulin data is being uploaded",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Starting on an open loop",
|
||||
new Date(0, 0, 0),
|
||||
1, // 1 day
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(1,
|
||||
"Starting on an open loop",
|
||||
"Run in Open Loop mode for a few days, and manually enact lots of temp basals",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Understanding your open loop, including its temp basal recommendations",
|
||||
"Based on that experience, decide what max basal should be, and set it on the pump",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Starting to close the loop with Low Glucose Suspend",
|
||||
new Date(0, 0, 0),
|
||||
7, // 7 days
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(2,
|
||||
"Understanding your open loop, including its temp basal recommendations",
|
||||
"Based on that experience, decide what max basal should be, and set it on the pump and preferences",
|
||||
new Date(0, 0, 0),
|
||||
0, // 0 days
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(3,
|
||||
"Starting to close the loop with Low Glucose Suspend",
|
||||
"Run in closed loop with max IOB = 0 for a few days without too many LGS events",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Tuning the closed loop, raising max IOB above 0 and gradually lowering BG targets",
|
||||
new Date(0, 0, 0),
|
||||
5, // 5 days
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(4,
|
||||
"Tuning the closed loop, raising max IOB above 0 and gradually lowering BG targets",
|
||||
"Run for a few days, and at least one night with no low BG alarms, before dropping BG",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Adjust basals and ratios if needed, and then enable auto-sens",
|
||||
new Date(0, 0, 0),
|
||||
1,
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(5,
|
||||
"Adjust basals and ratios if needed, and then enable auto-sens",
|
||||
"1 week successful daytime looping with regular carb entry",
|
||||
new Date(0, 0, 0), 7, new Date(0, 0, 0)));
|
||||
objectives.add(new Objective("Enabling additional features for daytime use, such as advanced meal assist",
|
||||
new Date(0, 0, 0),
|
||||
7,
|
||||
new Date(0, 0, 0)));
|
||||
objectives.add(new Objective(6,
|
||||
"Enabling additional features for daytime use, such as advanced meal assist",
|
||||
"",
|
||||
new Date(0, 0, 0), 1, new Date(0, 0, 0)));
|
||||
new Date(0, 0, 0),
|
||||
1,
|
||||
new Date(0, 0, 0)));
|
||||
}
|
||||
|
||||
void saveProgress() {
|
||||
public void saveProgress() {
|
||||
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
for (int num = 0; num < objectives.size(); num++) {
|
||||
|
@ -139,6 +201,9 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
editor.putLong(num + "started", o.started.getTime());
|
||||
editor.putLong(num + "accomplished", o.accomplished.getTime());
|
||||
}
|
||||
editor.putBoolean("bgIsAvailableInNS", bgIsAvailableInNS);
|
||||
editor.putBoolean("pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
||||
editor.putInt("manualEnacts", manualEnacts);
|
||||
editor.commit();
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Objectives stored");
|
||||
|
@ -151,14 +216,13 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
o.started = new Date(settings.getLong(num + "started", 0));
|
||||
o.accomplished = new Date(settings.getLong(num + "accomplished", 0));
|
||||
}
|
||||
bgIsAvailableInNS = settings.getBoolean("bgIsAvailableInNS", false);
|
||||
pumpStatusIsAvailableInNS = settings.getBoolean("pumpStatusIsAvailableInNS", false);
|
||||
manualEnacts = settings.getInt("manualEnacts", 0);
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Objectives loaded");
|
||||
}
|
||||
|
||||
boolean isAPSEnabledAtAll() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ObjectiveViewHolder> {
|
||||
|
||||
List<Objective> objectives;
|
||||
|
@ -177,11 +241,13 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
@Override
|
||||
public void onBindViewHolder(ObjectiveViewHolder holder, int position) {
|
||||
Objective o = objectives.get(position);
|
||||
RequirementResult requirementsMet = requirementsMet(position);
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
holder.position.setText(String.valueOf(position + 1));
|
||||
holder.objective.setText(o.objective);
|
||||
holder.gate.setText(o.gate);
|
||||
holder.duration.setText(context.getString(R.string.minimalduration) + " " + o.durationInDays + " " + context.getString(R.string.days));
|
||||
holder.progress.setText(requirementsMet.comment);
|
||||
holder.started.setText(o.started.toLocaleString());
|
||||
holder.accomplished.setText(o.accomplished.toLocaleString());
|
||||
|
||||
|
@ -192,16 +258,18 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
public void onClick(View v) {
|
||||
Objective o = (Objective) v.getTag();
|
||||
o.started = new Date();
|
||||
updateView();
|
||||
//saveProgress();
|
||||
updateGUI();
|
||||
saveProgress();
|
||||
}
|
||||
});
|
||||
holder.verifyButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Objective o = (Objective) v.getTag();
|
||||
o.accomplished = new Date();
|
||||
updateView();
|
||||
//saveProgress();
|
||||
if (requirementsMet(o.num).done || enableFake.isChecked()) {
|
||||
o.accomplished = new Date();
|
||||
updateGUI();
|
||||
saveProgress();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -210,18 +278,20 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
// Phase 0: previous not completed
|
||||
holder.startedLayout.setVisibility(View.GONE);
|
||||
holder.durationLayout.setVisibility(View.GONE);
|
||||
holder.progressLayout.setVisibility(View.GONE);
|
||||
holder.verifyLayout.setVisibility(View.GONE);
|
||||
} else if (o.started.getTime() == 0) {
|
||||
// Phase 1: not started
|
||||
holder.durationLayout.setVisibility(View.GONE);
|
||||
holder.progressLayout.setVisibility(View.GONE);
|
||||
holder.verifyLayout.setVisibility(View.GONE);
|
||||
holder.started.setVisibility(View.GONE);
|
||||
} else if (o.started.getTime() > 0 && !enableFakeTime.isChecked() && o.accomplished.getTime() == 0 && o.started.getTime() + o.durationInDays * 24 * 60 * 60 * 1000 > now) {
|
||||
// Phase 2: started, waiting for duration
|
||||
} else if (o.started.getTime() > 0 && !enableFake.isChecked() && o.accomplished.getTime() == 0 && o.started.getTime() + o.durationInDays * 24 * 60 * 60 * 1000 > now && !requirementsMet.done) {
|
||||
// Phase 2: started, waiting for duration and met requirements
|
||||
holder.startButton.setEnabled(false);
|
||||
holder.verifyLayout.setVisibility(View.GONE);
|
||||
} else if (o.accomplished.getTime() == 0 ) {
|
||||
// Phase 3: started, after duration
|
||||
} else if (o.accomplished.getTime() == 0) {
|
||||
// Phase 3: started, after duration, requirements met
|
||||
holder.startButton.setEnabled(false);
|
||||
holder.accomplished.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
|
@ -229,6 +299,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
holder.gateLayout.setVisibility(View.GONE);
|
||||
holder.startedLayout.setVisibility(View.GONE);
|
||||
holder.durationLayout.setVisibility(View.GONE);
|
||||
holder.progressLayout.setVisibility(View.GONE);
|
||||
holder.verifyButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
@ -251,6 +322,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
TextView gate;
|
||||
TextView duration;
|
||||
LinearLayout durationLayout;
|
||||
TextView progress;
|
||||
LinearLayout progressLayout;
|
||||
TextView started;
|
||||
Button startButton;
|
||||
LinearLayout startedLayout;
|
||||
|
@ -265,6 +338,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
objective = (TextView) itemView.findViewById(R.id.objectives_objective);
|
||||
durationLayout = (LinearLayout) itemView.findViewById(R.id.objectives_duration_linearlayout);
|
||||
duration = (TextView) itemView.findViewById(R.id.objectives_duration);
|
||||
progressLayout = (LinearLayout) itemView.findViewById(R.id.objectives_progresslayout);
|
||||
progress = (TextView) itemView.findViewById(R.id.objectives_progress);
|
||||
gateLayout = (LinearLayout) itemView.findViewById(R.id.objectives_gate_linearlayout);
|
||||
gate = (TextView) itemView.findViewById(R.id.objectives_gate);
|
||||
startedLayout = (LinearLayout) itemView.findViewById(R.id.objectives_start_linearlayout);
|
||||
|
@ -281,6 +356,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
super();
|
||||
initializeData();
|
||||
loadProgress();
|
||||
registerBus();
|
||||
}
|
||||
|
||||
public static ObjectivesFragment newInstance() {
|
||||
|
@ -302,29 +378,84 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
recyclerView.setHasFixedSize(true);
|
||||
llm = new LinearLayoutManager(view.getContext());
|
||||
recyclerView.setLayoutManager(llm);
|
||||
enableFakeTime = (CheckBox) view.findViewById(R.id.objectives_faketime);
|
||||
enableFakeTime.setOnClickListener(new View.OnClickListener() {
|
||||
enableFake = (CheckBox) view.findViewById(R.id.objectives_fake);
|
||||
enableFake.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
updateView();
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
updateView();
|
||||
updateGUI();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
void updateView() {
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectives);
|
||||
recyclerView.setAdapter(adapter);
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
else
|
||||
log.debug("EventNewBG: Activity is null");
|
||||
}
|
||||
|
||||
void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectives);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraints interface
|
||||
**/
|
||||
@Override
|
||||
public boolean isLoopEnabled() {
|
||||
return objectives.get(1).started.getTime() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosedModeEnabled() {
|
||||
return true; // TODO: revert back
|
||||
//return objectives.get(3).started.getTime() > 0;
|
||||
return objectives.get(3).started.getTime() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutosensModeEnabled() {
|
||||
return objectives.get(5).started.getTime() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return objectives.get(6).started.getTime() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyMaxIOBConstraints(Double maxIob) {
|
||||
if (objectives.get(4).started.getTime() > 0)
|
||||
return maxIob;
|
||||
else {
|
||||
if (Config.logConstraintsChanges)
|
||||
log.debug("Limiting maxIOB " + maxIob + " to " + 0 + "U");
|
||||
return 0d;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -273,6 +273,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
|
||||
TreatmentsFragment.MealData mealData = treatments.getMealData();
|
||||
|
||||
maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob);
|
||||
|
||||
determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, pump, iobTotal, glucoseStatus, mealData);
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.List;
|
|||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
|
@ -52,6 +53,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
||||
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
|
||||
|
@ -241,6 +243,11 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
finalLastRun.lastEnact = new Date();
|
||||
finalLastRun.lastOpenModeAccept = new Date();
|
||||
MainApp.getConfigBuilder().uploadDeviceStatus();
|
||||
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
|
||||
if (objectivesFragment != null) {
|
||||
objectivesFragment.manualEnacts++;
|
||||
objectivesFragment.saveProgress();
|
||||
}
|
||||
}
|
||||
updateGUI();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,11 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoopEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraints interface
|
||||
**/
|
||||
|
@ -72,9 +77,19 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
return mode.equals("closed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutosensModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public APSResult applyBasalConstraints(APSResult result) {
|
||||
result.rate = applyBasalConstraints(result.rate);
|
||||
result.rate = Math.min(applyBasalConstraints(result.rate), result.rate);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -182,4 +197,9 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
return carbs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double applyMaxIOBConstraints(Double maxIob) {
|
||||
return maxIob;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enable fake time"
|
||||
android:id="@+id/objectives_faketime" />
|
||||
android:text="Enable fake time and progress"
|
||||
android:id="@+id/objectives_fake" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/objectives_recyclerview"
|
||||
|
|
|
@ -124,6 +124,18 @@
|
|||
android:id="@+id/objectives_duration" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/objectives_progresslayout">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/objectives_progress" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
<string name="loop_constraintsprocessed_label">After processed constraints</string>
|
||||
<string name="loop_setbypump_label">Set by pump</string>
|
||||
<string name="openapsma_lastenact_label">Last enacted</string>
|
||||
<string name="dialog">Dialog</string>
|
||||
<string name="dialog">Confirmation</string>
|
||||
<string name="alert">Alert</string>
|
||||
<string name="refreshfromnightscout">Do you want to refresh treatments from Nightscout</string>
|
||||
<string name="ok">OK</string>
|
||||
|
@ -150,5 +150,9 @@
|
|||
<string name="openloop">Open Loop</string>
|
||||
<string name="openloop_newsuggestion">New suggestion available</string>
|
||||
<string name="unsupportedclientver">Unsupported version of NSClient</string>
|
||||
<string name="bgavailableinns">BG available in NS</string>
|
||||
<string name="pumpstatusavailableinns">Pump status available in NS</string>
|
||||
<string name="manualenacts">Manual enacts</string>
|
||||
<string name="loopdisabled">LOOP DISABLED BY CONSTRAINTS</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue