Merge pull request #18 from MilosKozak/master

dev
This commit is contained in:
LadyViktoria 2016-06-21 01:31:48 +02:00 committed by GitHub
commit 38d1386ad4
14 changed files with 271 additions and 39 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

@ -34,7 +34,7 @@
<!-- Receiver from NSClient -->
<receiver
android:name="info.nightscout.client.receivers.NSClientDataReceiver"
android:name=".receivers.NSClientDataReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>

View file

@ -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);

View file

@ -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());
}
}

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.interfaces;
/**
* Created by mike on 20.06.2016.
*/
public interface BgSourceInterface {
}

View file

@ -14,6 +14,7 @@ public interface PluginBase {
int PUMP = 6;
int CONSTRAINTS = 7;
int LOOP = 8;
int BGSOURCE = 9;
public int getType();

View file

@ -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();
@ -310,8 +313,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
// TODO: constraints here
return activePump.setExtendedBolus(insulin, durationInMinutes);
Double rateAfterConstraints = applyBasalConstraints(insulin);
Result result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
if (result.enacted) {
uploadExtendedBolus(result.bolusDelivered, result.duration);
MainApp.bus().post(new EventTreatmentChange());
}
return result;
}
@Override
@ -460,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;
@ -487,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:
@ -508,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<PluginBase> pluginsInCategory = MainActivity.getSpecificPluginsList(category);
switch (category) {
// Multiple selection allowed
@ -517,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)
@ -803,4 +833,32 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
}
public static void uploadExtendedBolus(Double insulin, double durationInMinutes) {
try {
Context context = MainApp.instance().getApplicationContext();
JSONObject data = new JSONObject();
data.put("eventType", "Combo Bolus");
data.put("duration", durationInMinutes);
data.put("splitNow", 0);
data.put("splitExt", 100);
data.put("enteredinsulin", insulin);
data.put("relative", insulin);
data.put("created_at", DateUtil.toISOString(new Date()));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) {
log.error("DBADD No receivers");
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
} catch (JSONException e) {
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -309,12 +309,15 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
extendedBolus.isAbsolute = true;
result.success = true;
result.enacted = true;
result.bolusDelivered = insulin;
result.duration = durationInMinutes;
result.comment = getString(R.string.virtualpump_resultok);
try {
MainApp.instance().getDbHelper().getDaoTempBasals().create(extendedBolus);
} catch (SQLException e) {
e.printStackTrace();
result.success = false;
result.enacted = false;
result.comment = getString(R.string.virtualpump_sqlerror);
}
if (Config.logPumpComm)

View file

@ -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);

View file

@ -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));
}
}
}

View file

@ -14,6 +14,23 @@
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/configbuilder_bgsource"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_bgsourcelistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/cardColorBackground" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"

View file

@ -142,5 +142,8 @@
<string name="carbs">Carbs</string>
<string name="changeyourinput">Change your input!</string>
<string name="setextendedbolusquestion">Set new extended bolus:</string>
<string name="configbuilder_bgsource">BG Source</string>
<string name="xdrip">xDrip</string>
<string name="nsclient">NSClient</string>
</resources>