diff --git a/.idea/misc.xml b/.idea/misc.xml
index fbb68289f4..5d19981032 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 49d9835d85..c4e7fb350d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -34,7 +34,7 @@
diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index 8cfc357768..f95f396499 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -27,6 +27,8 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.SafetyFragment.SafetyFragment;
import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment;
+import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
+import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment;
@@ -73,6 +75,8 @@ public class MainActivity extends AppCompatActivity {
pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(SafetyFragment.newInstance());
pluginsList.add(ObjectivesFragment.newInstance());
+ pluginsList.add(SourceXdripFragment.newInstance());
+ pluginsList.add(SourceNSClientFragment.newInstance());
pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance());
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
index 2d1a088299..e37dfed275 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -32,6 +32,7 @@ import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv;
@@ -297,37 +298,39 @@ public class DataService extends IntentService {
}
if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) {
- try {
- if (bundles.containsKey("sgv")) {
- String sgvstring = bundles.getString("sgv");
- JSONObject sgvJson = new JSONObject(sgvstring);
- NSSgv nsSgv = new NSSgv(sgvJson);
- BgReading bgReading = new BgReading(nsSgv);
- MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
- if (Config.logIncommingData)
- log.debug("ADD: Stored new BG: " + bgReading.toString());
- }
-
- if (bundles.containsKey("sgvs")) {
- String sgvstring = bundles.getString("sgvs");
- JSONArray jsonArray = new JSONArray(sgvstring);
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject sgvJson = jsonArray.getJSONObject(i);
+ if (MainActivity.getConfigBuilder().getActiveBgSource().getClass().equals(SourceNSClientFragment.class)) {
+ try {
+ if (bundles.containsKey("sgv")) {
+ String sgvstring = bundles.getString("sgv");
+ JSONObject sgvJson = new JSONObject(sgvstring);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
if (Config.logIncommingData)
log.debug("ADD: Stored new BG: " + bgReading.toString());
}
- }
- MainApp.bus().post(new EventTreatmentChange());
- } catch (JSONException e) {
- e.printStackTrace();
- } catch (Exception e1) {
- e1.printStackTrace();
+ if (bundles.containsKey("sgvs")) {
+ String sgvstring = bundles.getString("sgvs");
+ JSONArray jsonArray = new JSONArray(sgvstring);
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JSONObject sgvJson = jsonArray.getJSONObject(i);
+ NSSgv nsSgv = new NSSgv(sgvJson);
+ BgReading bgReading = new BgReading(nsSgv);
+ MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
+ if (Config.logIncommingData)
+ log.debug("ADD: Stored new BG: " + bgReading.toString());
+ }
+ }
+ MainApp.bus().post(new EventTreatmentChange());
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ MainApp.bus().post(new EventNewBG());
}
- MainApp.bus().post(new EventNewBG());
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java
new file mode 100644
index 0000000000..7ecc89ef66
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/BgSourceInterface.java
@@ -0,0 +1,7 @@
+package info.nightscout.androidaps.interfaces;
+
+/**
+ * Created by mike on 20.06.2016.
+ */
+public interface BgSourceInterface {
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java
index b4233df298..d36c511542 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java
@@ -14,6 +14,7 @@ public interface PluginBase {
int PUMP = 6;
int CONSTRAINTS = 7;
int LOOP = 8;
+ int BGSOURCE = 9;
public int getType();
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java
index ab04d9c478..0f85dcdcad 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java
@@ -39,6 +39,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
+import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
@@ -54,6 +55,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
private static final String PREFS_NAME = "Settings";
+ ListView bgsourceListView;
ListView pumpListView;
ListView loopListView;
ListView treatmentsListView;
@@ -63,6 +65,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
ListView constraintsListView;
ListView generalListView;
+ PluginCustomAdapter bgsourceDataAdapter = null;
PluginCustomAdapter pumpDataAdapter = null;
PluginCustomAdapter loopDataAdapter = null;
PluginCustomAdapter treatmentsDataAdapter = null;
@@ -73,6 +76,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
PluginCustomAdapter generalDataAdapter = null;
+ BgSourceInterface activeBgSource;
PumpInterface activePump;
ProfileInterface activeProfile;
TreatmentsInterface activeTreatments;
@@ -108,6 +112,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
+ bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview);
pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview);
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
@@ -122,6 +127,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
void setViews() {
+ bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE));
+ bgsourceListView.setAdapter(bgsourceDataAdapter);
+ setListViewHeightBasedOnChildren(bgsourceListView);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP));
pumpListView.setAdapter(pumpDataAdapter);
setListViewHeightBasedOnChildren(pumpListView);
@@ -198,11 +206,6 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
*
* Config builder return itself as a pump and check constraints before it passes command to pump driver
*/
- @Nullable
- public PumpInterface getActivePump() {
- return this;
- }
-
@Override
public boolean isTempBasalInProgress() {
return activePump.isTempBasalInProgress();
@@ -465,6 +468,16 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
}
+ @Nullable
+ public BgSourceInterface getActiveBgSource() {
+ return activeBgSource;
+ }
+
+ @Nullable
+ public PumpInterface getActivePump() {
+ return this;
+ }
+
@Nullable
public ProfileInterface getActiveProfile() {
return activeProfile;
@@ -492,6 +505,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
// Single selection allowed
case PluginBase.PROFILE:
case PluginBase.PUMP:
+ case PluginBase.BGSOURCE:
case PluginBase.LOOP:
case PluginBase.TEMPBASAL:
case PluginBase.TREATMENT:
@@ -513,7 +527,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
private void verifySelectionInCategories() {
- for (int category : new int[]{PluginBase.GENERAL, PluginBase.APS, PluginBase.PROFILE, PluginBase.PUMP, PluginBase.LOOP, PluginBase.TEMPBASAL, PluginBase.TREATMENT}) {
+ for (int category : new int[]{PluginBase.GENERAL, PluginBase.APS, PluginBase.PROFILE, PluginBase.PUMP, PluginBase.LOOP, PluginBase.TEMPBASAL, PluginBase.TREATMENT, PluginBase.BGSOURCE}) {
ArrayList pluginsInCategory = MainActivity.getSpecificPluginsList(category);
switch (category) {
// Multiple selection allowed
@@ -522,6 +536,17 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
case PluginBase.CONSTRAINTS:
break;
// Single selection allowed
+ case PluginBase.BGSOURCE:
+ activeBgSource = (BgSourceInterface) getTheOneEnabledInArray(pluginsInCategory);
+ if (Config.logConfigBuilder)
+ log.debug("Selected bgSource interface: " + ((PluginBase) activeBgSource).getName());
+ for (PluginBase p : pluginsInCategory) {
+ if (!p.getName().equals(((PluginBase) activeBgSource).getName())) {
+ p.setFragmentVisible(false);
+ }
+ }
+ break;
+ // Single selection allowed
case PluginBase.PROFILE:
activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory);
if (Config.logConfigBuilder)
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java
new file mode 100644
index 0000000000..c2e53dc016
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java
@@ -0,0 +1,63 @@
+package info.nightscout.androidaps.plugins.SourceNSClient;
+
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.BgSourceInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+
+public class SourceNSClientFragment extends Fragment implements PluginBase, BgSourceInterface {
+
+ boolean fragmentEnabled = true;
+
+ public SourceNSClientFragment() {
+ }
+
+ @Override
+ public int getType() {
+ return PluginBase.BGSOURCE;
+ }
+
+ @Override
+ public String getName() {
+ return MainApp.instance().getString(R.string.nsclient);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return fragmentEnabled;
+ }
+
+ @Override
+ public boolean isVisibleInTabs() {
+ return false;
+ }
+
+ @Override
+ public boolean canBeHidden() {
+ return true;
+ }
+
+ @Override
+ public void setFragmentEnabled(boolean fragmentEnabled) {
+ this.fragmentEnabled = fragmentEnabled;
+ }
+
+ @Override
+ public void setFragmentVisible(boolean fragmentVisible) {
+
+ }
+
+ public static SourceNSClientFragment newInstance() {
+ SourceNSClientFragment fragment = new SourceNSClientFragment();
+ return fragment;
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java
new file mode 100644
index 0000000000..fc3bfa33c8
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java
@@ -0,0 +1,62 @@
+package info.nightscout.androidaps.plugins.SourceXdrip;
+
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.BgSourceInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+
+public class SourceXdripFragment extends Fragment implements PluginBase, BgSourceInterface {
+
+ boolean fragmentEnabled = true;
+
+ public SourceXdripFragment() {
+ }
+
+
+ @Override
+ public int getType() {
+ return PluginBase.BGSOURCE;
+ }
+
+ @Override
+ public String getName() {
+ return MainApp.instance().getString(R.string.xdrip);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return fragmentEnabled;
+ }
+
+ @Override
+ public boolean isVisibleInTabs() {
+ return false;
+ }
+
+ @Override
+ public boolean canBeHidden() {
+ return true;
+ }
+
+ @Override
+ public void setFragmentEnabled(boolean fragmentEnabled) {
+ this.fragmentEnabled = fragmentEnabled;
+ }
+
+ @Override
+ public void setFragmentVisible(boolean fragmentVisible) {
+ }
+
+ public static SourceXdripFragment newInstance() {
+ SourceXdripFragment fragment = new SourceXdripFragment();
+ return fragment;
+ }
+}
diff --git a/app/src/main/java/info/nightscout/client/receivers/NSClientDataReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSClientDataReceiver.java
similarity index 75%
rename from app/src/main/java/info/nightscout/client/receivers/NSClientDataReceiver.java
rename to app/src/main/java/info/nightscout/androidaps/receivers/NSClientDataReceiver.java
index 10c1c6fcec..25b2b8a270 100644
--- a/app/src/main/java/info/nightscout/client/receivers/NSClientDataReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSClientDataReceiver.java
@@ -1,4 +1,4 @@
-package info.nightscout.client.receivers;
+package info.nightscout.androidaps.receivers;
import android.content.Context;
import android.content.Intent;
@@ -7,8 +7,11 @@ import android.support.v4.content.WakefulBroadcastReceiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
+import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
public class NSClientDataReceiver extends WakefulBroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(NSClientDataReceiver.class);
diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/xDripReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/xDripReceiver.java
index 2c2af6404d..ef006b7400 100644
--- a/app/src/main/java/info/nightscout/androidaps/receivers/xDripReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/xDripReceiver.java
@@ -7,8 +7,10 @@ import android.support.v4.content.WakefulBroadcastReceiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.Services.DataService;
import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
public class xDripReceiver extends WakefulBroadcastReceiver {
@@ -16,10 +18,16 @@ public class xDripReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if (Config.logFunctionCalls)
- log.debug("onReceive " + intent);
- startWakefulService(context, new Intent(context, DataService.class)
- .setAction(intent.getAction())
- .putExtras(intent));
+ if (MainActivity.getConfigBuilder().getActiveBgSource() == null) {
+ log.debug("getActiveBgSource is still null");
+ return;
+ }
+ if (MainActivity.getConfigBuilder().getActiveBgSource().getClass().equals(SourceXdripFragment.class)) {
+ if (Config.logFunctionCalls)
+ log.debug("onReceive " + intent);
+ startWakefulService(context, new Intent(context, DataService.class)
+ .setAction(intent.getAction())
+ .putExtras(intent));
+ }
}
}
diff --git a/app/src/main/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml
index 4c3140ddf3..44e5bbd6b2 100644
--- a/app/src/main/res/layout/configbuilder_fragment.xml
+++ b/app/src/main/res/layout/configbuilder_fragment.xml
@@ -14,6 +14,23 @@
android:orientation="vertical">
+
+
+
+
+ Carbs
Change your input!
Set new extended bolus:
+ BG Source
+ xDrip
+ NSClient