diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 1943c85e5f..ffba1be639 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -3,5 +3,6 @@
+
\ No newline at end of file
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/build.gradle b/app/build.gradle
index 6a72c4b51d..b984333c3a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,8 +23,8 @@ android {
applicationId "info.nightscout.androidaps"
minSdkVersion 21
targetSdkVersion 23
- versionCode 1
- versionName "1.0"
+ versionCode 1002
+ versionName "1.0.02"
}
buildTypes {
release {
@@ -37,10 +37,15 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
+ compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
+ transitive = true;
+ }
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
+ compile 'com.android.support:gridlayout-v7:23.4.0'
+ compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.squareup:otto:1.3.7'
compile 'com.j256.ormlite:ormlite-core:4.46'
compile 'com.j256.ormlite:ormlite-android:4.46'
@@ -48,7 +53,4 @@ dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
compile 'com.jjoe64:graphview:4.0.1'
compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar'
- compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
- transitive = true;
- }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java
index 1c39cb32c9..5719010eb4 100644
--- a/app/src/main/java/info/nightscout/androidaps/Config.java
+++ b/app/src/main/java/info/nightscout/androidaps/Config.java
@@ -11,6 +11,7 @@ public class Config {
public static final boolean OPENAPSMAENABLED = APS && true;
public static final boolean LOOPENABLED = APS && true;
public static final boolean OBJECTIVESENABLED = APS && true;
+ public static final boolean CAREPORTALENABLED = true;
public static final boolean detailedLog = true;
public static final boolean logFunctionCalls = true;
diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index 9a7366d1f2..601298c859 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment;
@@ -64,6 +65,7 @@ public class MainActivity extends AppCompatActivity {
// Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance());
pluginsList.add(VirtualPumpFragment.newInstance());
+ if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.newInstance());
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.newInstance());
if (Config.LOWSUSPEDENABLED) pluginsList.add(LowSuspendFragment.newInstance());
if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.newInstance());
@@ -72,7 +74,7 @@ public class MainActivity extends AppCompatActivity {
pluginsList.add(TreatmentsFragment.newInstance());
pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(SafetyFragment.newInstance());
- if (Config.OPENAPSMAENABLED) pluginsList.add(ObjectivesFragment.newInstance());
+ if (Config.OBJECTIVESENABLED) pluginsList.add(ObjectivesFragment.newInstance());
pluginsList.add(SourceXdripFragment.newInstance());
pluginsList.add(SourceNSClientFragment.newInstance());
pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance());
@@ -164,11 +166,15 @@ public class MainActivity extends AppCompatActivity {
public static ArrayList getSpecificPluginsList(int type) {
ArrayList newList = new ArrayList();
- Iterator it = pluginsList.iterator();
- while (it.hasNext()) {
- PluginBase p = it.next();
- if (p.getType() == type)
- newList.add(p);
+ if (pluginsList != null) {
+ Iterator it = pluginsList.iterator();
+ while (it.hasNext()) {
+ PluginBase p = it.next();
+ if (p.getType() == type)
+ newList.add(p);
+ }
+ } else {
+ log.error("pluginsList=null");
}
return newList;
}
@@ -176,11 +182,15 @@ public class MainActivity extends AppCompatActivity {
public static ArrayList getSpecificPluginsListByInterface(Class interfaceClass) {
ArrayList newList = new ArrayList();
- Iterator it = pluginsList.iterator();
- while (it.hasNext()) {
- PluginBase p = it.next();
- if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
- newList.add(p);
+ if (pluginsList != null) {
+ Iterator it = pluginsList.iterator();
+ while (it.hasNext()) {
+ PluginBase p = it.next();
+ if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
+ newList.add(p);
+ }
+ } else {
+ log.error("pluginsList=null");
}
return newList;
}
@@ -195,7 +205,7 @@ public class MainActivity extends AppCompatActivity {
return p;
}
} else {
- log.debug("pluginsList=null");
+ log.error("pluginsList=null");
}
return null;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
index f71067c705..6fe9233979 100644
--- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
@@ -33,6 +33,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResource(R.xml.pref_openapsma);
if (Config.LOWSUSPEDENABLED)
addPreferencesFromResource(R.xml.pref_lowsuspend);
+ if (Config.CAREPORTALENABLED)
+ addPreferencesFromResource(R.xml.pref_careportal);
}
}
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 d91b87fef0..ed76971ae4 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -49,7 +49,7 @@ import info.nightscout.utils.ToastUtils;
public class DataService extends IntentService {
private static Logger log = LoggerFactory.getLogger(DataService.class);
- boolean xDripEnabled = true;
+ boolean xDripEnabled = false;
boolean nsClientEnabled = true;
public DataService() {
@@ -178,10 +178,10 @@ public class DataService extends IntentService {
if (settings.has("thresholds")) {
JSONObject thresholds = settings.getJSONObject("thresholds");
OverviewFragment overviewFragment = (OverviewFragment) MainActivity.getSpecificPlugin(OverviewFragment.class);
- if (thresholds.has("bgTargetTop")) {
+ if (overviewFragment != null && thresholds.has("bgTargetTop")) {
overviewFragment.bgTargetHigh = thresholds.getDouble("bgTargetTop");
}
- if (thresholds.has("bgTargetBottom")) {
+ if (overviewFragment != null && thresholds.has("bgTargetBottom")) {
overviewFragment.bgTargetLow = thresholds.getDouble("bgTargetBottom");
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java
index 012d6e8488..bc498246bc 100644
--- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java
+++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java
@@ -20,6 +20,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.MainApp;
+import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
@@ -117,11 +118,7 @@ public class Treatment {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
+ DbLogger.dbAdd(intent, data.toString(), Treatment.class);
}
public void updateToNSClient() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java
new file mode 100644
index 0000000000..2a1e3c9c8d
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java
@@ -0,0 +1,220 @@
+package info.nightscout.androidaps.plugins.Careportal;
+
+
+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.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
+
+public class CareportalFragment extends Fragment implements PluginBase, View.OnClickListener {
+
+ 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);
+ final OptionsToShow mealbolus = new OptionsToShow(R.id.careportal_mealbolus, R.string.careportal_mealbolus, true, true, true, true, false, false, false, false, false);
+ final OptionsToShow correctionbolus = new OptionsToShow(R.id.careportal_correctionbolus, R.string.careportal_correctionbolus, true, true, true, true, false, false, false, false, false);
+ final OptionsToShow carbcorrection = new OptionsToShow(R.id.careportal_carbscorrection, R.string.careportal_carbscorrection, true, false, true, false, false, false, false, false, false);
+ final OptionsToShow combobolus = new OptionsToShow(R.id.careportal_combobolus, R.string.careportal_combobolus, true, true, true, true, true, false, false, false, true);
+ final OptionsToShow announcement = new OptionsToShow(R.id.careportal_announcement, R.string.careportal_announcement, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow note = new OptionsToShow(R.id.careportal_note, R.string.careportal_note, true, false, false, false, true, false, false, false, false);
+ final OptionsToShow question = new OptionsToShow(R.id.careportal_question, R.string.careportal_question, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow exercise = new OptionsToShow(R.id.careportal_exercise, R.string.careportal_exercise, false, false, false, false, true, false, false, false, false);
+ final OptionsToShow sitechange = new OptionsToShow(R.id.careportal_pumpsitechange, R.string.careportal_pumpsitechange, true, true, false, false, false, false, false, false, false);
+ final OptionsToShow sensorstart = new OptionsToShow(R.id.careportal_cgmsensorstart, R.string.careportal_cgmsensorstart, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow sensorchange = new OptionsToShow(R.id.careportal_cgmsensorinsert, R.string.careportal_cgmsensorinsert, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow insulinchange = new OptionsToShow(R.id.careportal_insulincartridgechange, R.string.careportal_insulincartridgechange, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow tempbasalstart = new OptionsToShow(R.id.careportal_tempbasalstart, R.string.careportal_tempbasalstart, true, false, false, false, true, true, true, false, false);
+ final OptionsToShow tempbasalend = new OptionsToShow(R.id.careportal_tempbasalend, R.string.careportal_tempbasalend, true, false, false, false, false, false, false, false, false);
+ final OptionsToShow profileswitch = new OptionsToShow(R.id.careportal_profileswitch, R.string.careportal_profileswitch, true, false, false, false, false, false, false, true, false);
+ final OptionsToShow openapsoffline = new OptionsToShow(R.id.careportal_openapsoffline, R.string.careportal_openapsoffline, false, false, false, false, true, false, false, false, false);
+
+ boolean fragmentEnabled = true;
+ boolean fragmentVisible = true;
+
+ public CareportalFragment() {
+ // Required empty public constructor
+ }
+
+ public static CareportalFragment newInstance() {
+ CareportalFragment fragment = new CareportalFragment();
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public int getType() {
+ return PluginBase.GENERAL;
+ }
+
+ @Override
+ public String getName() {
+ return MainApp.resources.getString(R.string.careportal);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return fragmentEnabled;
+ }
+
+ @Override
+ public boolean isVisibleInTabs() {
+ return fragmentVisible;
+ }
+
+ @Override
+ public boolean canBeHidden() {
+ return true;
+ }
+
+ @Override
+ public void setFragmentEnabled(boolean fragmentEnabled) {
+ this.fragmentEnabled = fragmentEnabled;
+ }
+
+ @Override
+ public void setFragmentVisible(boolean fragmentVisible) {
+ this.fragmentVisible = fragmentVisible;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.careportal_fragment, container, false);
+
+ view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
+ view.findViewById(R.id.careportal_announcement).setOnClickListener(this);
+ view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this);
+ view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this);
+ view.findViewById(R.id.careportal_combobolus).setOnClickListener(this);
+ view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this);
+ view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this);
+ view.findViewById(R.id.careportal_exercise).setOnClickListener(this);
+ view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this);
+ view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this);
+ view.findViewById(R.id.careportal_note).setOnClickListener(this);
+ view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this);
+ view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this);
+ view.findViewById(R.id.careportal_question).setOnClickListener(this);
+ view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this);
+ view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this);
+ view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this);
+ view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this);
+ return view;
+ }
+
+ @Override
+ public void onClick(View view) {
+ FragmentManager manager = getFragmentManager();
+ NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
+ switch (view.getId()) {
+ case R.id.careportal_bgcheck:
+ newDialog.setOptions(bgcheck);
+ break;
+ case R.id.careportal_announcement:
+ newDialog.setOptions(announcement);
+ break;
+ case R.id.careportal_cgmsensorinsert:
+ newDialog.setOptions(sensorchange);
+ break;
+ case R.id.careportal_cgmsensorstart:
+ newDialog.setOptions(sensorstart);
+ break;
+ case R.id.careportal_combobolus:
+ newDialog.setOptions(combobolus);
+ break;
+ case R.id.careportal_correctionbolus:
+ newDialog.setOptions(correctionbolus);
+ break;
+ case R.id.careportal_carbscorrection:
+ newDialog.setOptions(carbcorrection);
+ break;
+ case R.id.careportal_exercise:
+ newDialog.setOptions(exercise);
+ break;
+ case R.id.careportal_insulincartridgechange:
+ newDialog.setOptions(insulinchange);
+ break;
+ case R.id.careportal_mealbolus:
+ newDialog.setOptions(mealbolus);
+ break;
+ case R.id.careportal_note:
+ newDialog.setOptions(note);
+ break;
+ case R.id.careportal_profileswitch:
+ newDialog.setOptions(profileswitch);
+ break;
+ case R.id.careportal_pumpsitechange:
+ newDialog.setOptions(sitechange);
+ break;
+ case R.id.careportal_question:
+ newDialog.setOptions(question);
+ break;
+ case R.id.careportal_snackbolus:
+ newDialog.setOptions(snackbolus);
+ break;
+ case R.id.careportal_tempbasalstart:
+ newDialog.setOptions(tempbasalstart);
+ break;
+ case R.id.careportal_tempbasalend:
+ newDialog.setOptions(tempbasalend);
+ break;
+ case R.id.careportal_openapsoffline:
+ newDialog.setOptions(openapsoffline);
+ break;
+ default:
+ newDialog = null;
+ }
+ if (newDialog != null)
+ newDialog.show(manager, "NewNSTreatmentDialog");
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java
new file mode 100644
index 0000000000..19e0969e7f
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java
@@ -0,0 +1,549 @@
+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.preference.PreferenceManager;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v7.app.AlertDialog;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
+import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
+import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.DateFormat;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+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.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;
+import info.nightscout.utils.SafeParse;
+import info.nightscout.utils.ToastUtils;
+
+public class NewNSTreatmentDialog extends DialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
+ private static Logger log = LoggerFactory.getLogger(NewNSTreatmentDialog.class);
+
+ private FragmentActivity context;
+
+ private CareportalFragment.OptionsToShow options;
+
+ NSProfile profile;
+ String units;
+
+ LinearLayout layoutBg;
+ LinearLayout layoutBgSource;
+ LinearLayout layoutInsulin;
+ LinearLayout layoutCarbs;
+ LinearLayout layoutSplit;
+ LinearLayout layoutDuration;
+ LinearLayout layoutPercent;
+ LinearLayout layoutAbsolute;
+ LinearLayout layoutCarbTime;
+ LinearLayout layoutProfile;
+ Button dateButton;
+ Button timeButton;
+ Button okButton;
+
+ TextView bgUnitsView;
+ RadioButton meterRadioButton;
+ RadioButton sensorRadioButton;
+ RadioButton otherRadioButton;
+ EditText notesEdit;
+ EditText bgInputEdit;
+ EditText insulinEdit;
+ EditText carbsEdit;
+ EditText percentEdit;
+ EditText absoluteEdit;
+ EditText durationeEdit;
+ EditText carbTimeEdit;
+ EditText splitEdit;
+ Spinner profileSpinner;
+
+ PlusMinusEditText editBg;
+ PlusMinusEditText editCarbs;
+ PlusMinusEditText editInsulin;
+ PlusMinusEditText editSplit;
+ PlusMinusEditText editDuration;
+ PlusMinusEditText editPercent;
+ PlusMinusEditText editAbsolute;
+ PlusMinusEditText editCarbTime;
+
+ Date eventTime;
+
+ public void setOptions(CareportalFragment.OptionsToShow options) {
+ this.options = options;
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ context = (FragmentActivity) activity;
+ super.onAttach(activity);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ getDialog().setTitle(getString(options.eventName));
+ View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false);
+
+ layoutBg = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bg_layout);
+ layoutBgSource = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout);
+ layoutInsulin = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_insulin_layout);
+ layoutCarbs = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbs_layout);
+ layoutSplit = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_split_layout);
+ layoutDuration = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_duration_layout);
+ layoutPercent = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_percent_layout);
+ layoutAbsolute = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_absolute_layout);
+ layoutCarbTime = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout);
+ layoutProfile = (LinearLayout) view.findViewById(R.id.careportal_newnstreatment_profile_layout);
+
+ showOrHide(layoutBg, options.bg);
+ showOrHide(layoutBgSource, options.bg);
+ showOrHide(layoutInsulin, options.insulin);
+ showOrHide(layoutCarbs, options.carbs);
+ showOrHide(layoutSplit, options.split);
+ showOrHide(layoutDuration, options.duration);
+ showOrHide(layoutPercent, options.percent);
+ showOrHide(layoutAbsolute, options.absolute);
+ showOrHide(layoutCarbTime, options.prebolus);
+ showOrHide(layoutProfile, options.profile);
+
+ bgUnitsView = (TextView) view.findViewById(R.id.careportal_newnstreatment_bgunits);
+ meterRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_meter);
+ sensorRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_sensor);
+ otherRadioButton = (RadioButton) view.findViewById(R.id.careportal_newnstreatment_other);
+ profileSpinner = (Spinner) view.findViewById(R.id.careportal_newnstreatment_profile);
+
+ bgInputEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_bginput);
+ insulinEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_insulininput);
+ carbsEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_carbsinput);
+ percentEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_percentinput);
+ percentEdit.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start,
+ int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start,
+ int before, int count) {
+ layoutAbsolute.setVisibility(View.GONE);
+ }
+ });
+ absoluteEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
+ absoluteEdit.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start,
+ int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start,
+ int before, int count) {
+ layoutPercent.setVisibility(View.GONE);
+ }
+ });
+ durationeEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_durationinput);
+ carbTimeEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput);
+ notesEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_notes);
+ splitEdit = (EditText) view.findViewById(R.id.careportal_newnstreatment_splitinput);
+
+ eventTime = new Date();
+ dateButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventdate);
+ timeButton = (Button) view.findViewById(R.id.careportal_newnstreatment_eventtime);
+ DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
+ DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT);
+ dateButton.setText(df.format(eventTime));
+ timeButton.setText(tf.format(eventTime));
+ dateButton.setOnClickListener(this);
+ timeButton.setOnClickListener(this);
+
+ okButton = (Button) view.findViewById(R.id.careportal_newnstreatment_ok);
+ okButton.setOnClickListener(this);
+
+ // BG
+ profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
+ ArrayList profileList;
+ units = Constants.MGDL;
+ if (profile == null) {
+ ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), context.getString(R.string.noprofile));
+ profileList = new ArrayList();
+ } else {
+ units = profile.getUnits();
+ profileList = profile.getProfileList();
+ }
+ ArrayAdapter adapter = new ArrayAdapter(getContext(),
+ android.R.layout.simple_spinner_item, profileList);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ profileSpinner.setAdapter(adapter);
+
+ bgUnitsView.setText(units);
+
+ // Set BG if not old
+ BgReading lastBg = MainApp.getDbHelper().lastBg();
+ Double lastBgValue = 0d;
+ if (lastBg != null) {
+ lastBgValue = lastBg.valueToUnits(units);
+ sensorRadioButton.setChecked(true);
+ } else {
+ meterRadioButton.setChecked(true);
+ }
+
+ if (units.equals(Constants.MMOL))
+ editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, lastBgValue, 0d, 40d, 0.1d, new DecimalFormat("0.0"), false);
+ else
+ editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, lastBgValue, 0d, 500d, 1d, new DecimalFormat("0"), false);
+
+ Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit);
+ editCarbs = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbsinput, R.id.careportal_newnstreatment_carbs_plus, R.id.careportal_newnstreatment_carbs_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false);
+
+ Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
+ editInsulin = new PlusMinusEditText(view, R.id.careportal_newnstreatment_insulininput, R.id.careportal_newnstreatment_insulin_plus, R.id.careportal_newnstreatment_insulin_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false);
+
+ editSplit = new PlusMinusEditText(view, R.id.careportal_newnstreatment_splitinput, R.id.careportal_newnstreatment_split_plus, R.id.careportal_newnstreatment_split_minus, 100d, 0d, 100d, 5d, new DecimalFormat("0"), true);
+ editDuration = new PlusMinusEditText(view, R.id.careportal_newnstreatment_durationinput, R.id.careportal_newnstreatment_duration_plus, R.id.careportal_newnstreatment_duration_minus, 0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false);
+
+ Integer maxPercent = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalPercentOnlyForCheckLimit);
+ editPercent = new PlusMinusEditText(view, R.id.careportal_newnstreatment_percentinput, R.id.careportal_newnstreatment_percent_plus, R.id.careportal_newnstreatment_percent_minus, 0d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true);
+
+ Double maxAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
+ editAbsolute = new PlusMinusEditText(view, R.id.careportal_newnstreatment_absoluteinput, R.id.careportal_newnstreatment_absolute_plus, R.id.careportal_newnstreatment_absolute_minus, 0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true);
+
+ editCarbTime = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbtimeinput, R.id.careportal_newnstreatment_carbtime_plus, R.id.careportal_newnstreatment_carbtime_minus, 0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
+
+ return view;
+ }
+
+ @Override
+ public void onClick(View view) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(eventTime);
+ switch (view.getId()) {
+ case R.id.careportal_newnstreatment_eventdate:
+ DatePickerDialog dpd = DatePickerDialog.newInstance(
+ this,
+ calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH)
+ );
+ dpd.setThemeDark(true);
+ dpd.dismissOnPause(true);
+ dpd.show(context.getFragmentManager(), "Datepickerdialog");
+ break;
+ case R.id.careportal_newnstreatment_eventtime:
+ android.text.format.DateFormat df = new android.text.format.DateFormat();
+ TimePickerDialog tpd = TimePickerDialog.newInstance(
+ this,
+ calendar.get(Calendar.HOUR_OF_DAY),
+ calendar.get(Calendar.MINUTE),
+ df.is24HourFormat(context)
+ );
+ tpd.setThemeDark(true);
+ tpd.dismissOnPause(true);
+ tpd.show(context.getFragmentManager(), "Timepickerdialog");
+ break;
+ case R.id.careportal_newnstreatment_ok:
+ createNSTreatment();
+ dismiss();
+ break;
+ }
+ }
+
+ private void showOrHide(LinearLayout layout, boolean visible) {
+ if (visible) layout.setVisibility(View.VISIBLE);
+ else layout.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
+ eventTime.setYear(year);
+ eventTime.setMonth(monthOfYear);
+ eventTime.setDate(dayOfMonth);
+ DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
+ dateButton.setText(df.format(eventTime));
+ }
+
+ @Override
+ public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
+ eventTime.setHours(hourOfDay);
+ eventTime.setMinutes(minute);
+ eventTime.setSeconds(second);
+ DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT);
+ timeButton.setText(tf.format(eventTime));
+ }
+
+
+ JSONObject gatherData() {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
+ String enteredBy = SP.getString("careportal_enteredby", "");
+ JSONObject data = new JSONObject();
+ try {
+ data.put("created_at", DateUtil.toISOString(eventTime));
+ switch (options.eventType) {
+ case R.id.careportal_bgcheck:
+ data.put("eventType", "BG Check");
+ break;
+ case R.id.careportal_announcement:
+ data.put("eventType", "Announcement");
+ break;
+ case R.id.careportal_cgmsensorinsert:
+ data.put("eventType", "Sensor Change");
+ break;
+ case R.id.careportal_cgmsensorstart:
+ data.put("eventType", "Sensor Start");
+ break;
+ case R.id.careportal_combobolus:
+ data.put("splitNow", SafeParse.stringToDouble(splitEdit.getText().toString()));
+ data.put("splitExt", 100 - SafeParse.stringToDouble(splitEdit.getText().toString()));
+ data.put("eventType", "Combo Bolus");
+ break;
+ case R.id.careportal_correctionbolus:
+ data.put("eventType", "Correction Bolus");
+ break;
+ case R.id.careportal_carbscorrection:
+ data.put("eventType", "Carb Correction");
+ break;
+ case R.id.careportal_exercise:
+ data.put("eventType", "Exercise");
+ break;
+ case R.id.careportal_insulincartridgechange:
+ data.put("eventType", "Insulin Change");
+ break;
+ case R.id.careportal_mealbolus:
+ data.put("eventType", "Meal Bolus");
+ break;
+ case R.id.careportal_note:
+ data.put("eventType", "Note");
+ break;
+ case R.id.careportal_profileswitch:
+ data.put("eventType", "Profile Switch");
+ break;
+ case R.id.careportal_pumpsitechange:
+ data.put("eventType", "Site Change");
+ break;
+ case R.id.careportal_question:
+ data.put("eventType", "Question");
+ break;
+ case R.id.careportal_snackbolus:
+ data.put("eventType", "Snack Bolus");
+ break;
+ case R.id.careportal_tempbasalstart:
+ data.put("eventType", "Temp Basal");
+ break;
+ case R.id.careportal_tempbasalend:
+ data.put("eventType", "Temp Basal");
+ break;
+ case R.id.careportal_openapsoffline:
+ data.put("eventType", "OpenAPS Offline");
+ break;
+ }
+ if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) {
+ data.put("glucose", SafeParse.stringToDouble(bgInputEdit.getText().toString()));
+ if (meterRadioButton.isChecked()) data.put("glucoseType", "Finger");
+ if (sensorRadioButton.isChecked()) data.put("glucoseType", "Sensor");
+ if (otherRadioButton.isChecked()) data.put("glucoseType", "Manual");
+ }
+ if (SafeParse.stringToDouble(carbsEdit.getText().toString()) != 0d)
+ data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString()));
+ if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d)
+ data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString()));
+ if (SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d)
+ data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString()));
+ if (layoutPercent.getVisibility() != View.GONE)
+ data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString()));
+ if (layoutAbsolute.getVisibility() != View.GONE)
+ data.put("absolute", profileSpinner.getSelectedItem().toString());
+ if (options.profile) data.put("profile", profileSpinner.getSelectedItem().toString());
+ if (SafeParse.stringToDouble(carbTimeEdit.getText().toString()) != 0d)
+ data.put("preBolus", SafeParse.stringToDouble(carbTimeEdit.getText().toString()));
+ if (!notesEdit.getText().toString().equals(""))
+ data.put("notes", notesEdit.getText().toString());
+ data.put("units", units);
+ if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
+ if (options.eventType == R.id.careportal_combobolus) {
+ Double enteredInsulin = SafeParse.stringToDouble(insulinEdit.getText().toString());
+ data.put("enteredinsulin", enteredInsulin);
+ data.put("insulin", enteredInsulin * SafeParse.stringToDouble(splitEdit.getText().toString()) / 100);
+ data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(splitEdit.getText().toString())) / 100 / SafeParse.stringToDouble(durationeEdit.getText().toString()) * 60);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return data;
+ }
+
+ String buildConfirmText(JSONObject data) {
+ String ret = "";
+ try {
+ if (data.has("eventType")) {
+ ret += getString(R.string.careportal_newnstreatment_eventtype);
+ ret += ": ";
+ ret += data.get("eventType"); // TODO: translate this too
+ ret += "\n";
+ }
+ if (data.has("glucose")) {
+ ret += getString(R.string.treatments_wizard_bg_label);
+ ret += ": ";
+ ret += data.get("glucose");
+ ret += " " + units + "\n";
+ }
+ if (data.has("glucoseType")) {
+ ret += getString(R.string.careportal_newnstreatment_glucosetype);
+ ret += ": ";
+ ret += data.get("glucoseType"); // TODO: translate this too
+ ret += "\n";
+ }
+ if (data.has("carbs")) {
+ ret += getString(R.string.careportal_newnstreatment_carbs_label);
+ ret += ": ";
+ ret += data.get("carbs");
+ ret += " g\n";
+ }
+ if (data.has("insulin")) {
+ ret += getString(R.string.careportal_newnstreatment_insulin_label);
+ ret += ": ";
+ ret += data.get("insulin");
+ ret += " U\n";
+ }
+ if (data.has("duration")) {
+ ret += getString(R.string.careportal_newnstreatment_duration_label);
+ ret += ": ";
+ ret += data.get("duration");
+ ret += " min\n";
+ }
+ if (data.has("percent")) {
+ ret += getString(R.string.careportal_newnstreatment_percent_label);
+ ret += ": ";
+ ret += data.get("percent");
+ ret += " %\n";
+ }
+ if (data.has("absolute")) {
+ ret += getString(R.string.careportal_newnstreatment_absolute_label);
+ ret += ": ";
+ ret += data.get("absolute");
+ ret += " U/h\n";
+ }
+ if (data.has("preBolus")) {
+ ret += getString(R.string.careportal_newnstreatment_carbtime_label);
+ ret += ": ";
+ ret += data.get("preBolus");
+ ret += " min\n";
+ }
+ if (data.has("notes")) {
+ ret += getString(R.string.careportal_newnstreatment_notes_label);
+ ret += ": ";
+ ret += data.get("notes");
+ ret += "\n";
+ }
+ if (data.has("profile")) {
+ ret += getString(R.string.careportal_newnstreatment_profile_label);
+ ret += ": ";
+ ret += data.get("profile");
+ ret += "\n";
+ }
+ if (data.has("created_at")) {
+ ret += getString(R.string.careportal_newnstreatment_eventtime_label);
+ ret += ": ";
+ ret += eventTime.toLocaleString();
+ ret += "\n";
+ }
+ if (data.has("enteredBy")) {
+ ret += getString(R.string.careportal_newnstreatment_enteredby_title);
+ ret += ": ";
+ ret += data.get("enteredBy");
+ ret += "\n";
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ return ret;
+ }
+
+ void createNSTreatment() {
+ final JSONObject data = gatherData();
+ String confirmText = buildConfirmText(data);
+ AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
+ builder.setTitle(getContext().getString(R.string.dialog));
+ builder.setMessage(confirmText);
+ builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ sendTreatmentToNS(data);
+ }
+ });
+ builder.setNegativeButton(getContext().getString(R.string.cancel), null);
+ builder.show();
+ }
+
+ static void sendTreatmentToNS(JSONObject data) {
+ try {
+ if (data.has("preBolus") && data.has("carbs")) {
+ JSONObject prebolus = new JSONObject();
+ prebolus.put("carbs", data.get("carbs"));
+ data.remove("carbs");
+ prebolus.put("eventType", data.get("eventType"));
+ prebolus.put("enteredBy", data.get("enteredBy"));
+ if (data.has("notes")) prebolus.put("notes", data.get("notes"));
+ long mills = DateUtil.fromISODateString(data.getString("created_at")).getTime();
+ Date preBolusDate = new Date(mills + data.getInt("preBolus") * 60000L);
+ prebolus.put("created_at", DateUtil.toISOString(preBolusDate));
+ sendTreatmentToNS(prebolus);
+ }
+ Context context = MainApp.instance().getApplicationContext();
+ 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);
+ DbLogger.dbAdd(intent, data.toString(), NewExtendedBolusDialog.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+}
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 3493566f97..834fb5c211 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
@@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResult;
+import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
@@ -861,12 +862,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
- context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
+ DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class);
} catch (JSONException e) {
}
}
@@ -888,11 +884,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
+ DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class);
} catch (JSONException e) {
}
}
@@ -912,11 +904,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
+ DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class);
} catch (JSONException e) {
}
}
@@ -941,11 +929,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
+ DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class);
} catch (JSONException e) {
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java
index b533ecb134..fa4ba2a8d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java
@@ -15,6 +15,7 @@ import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
+import info.nightscout.client.data.DbLogger;
/*
{
@@ -416,10 +417,6 @@ public class DeviceStatus {
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
- List q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
- if (q.size() < 1) {
- log.error("DBADD No receivers");
- } else if (Config.logNSUpload)
- log.debug("DBADD dbAdd " + q.size() + " receivers " + mongoRecord().toString());
+ DbLogger.dbAdd(intent, mongoRecord().toString(), DeviceStatus.class);
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
index 7f6410fba3..c5dd57f9c8 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java
@@ -178,7 +178,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable("lastrun", lastRun);
+ //outState.putParcelable("lastrun", lastRun);
}
private void registerBus() {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java
index 9f4d40bee9..6ea7c3a92f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java
@@ -44,8 +44,8 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit);
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
- editCarbs = new PlusMinusEditText(view, R.id.treatments_newtreatment_carbsamount, R.id.treatments_newtreatment_carbsamount_plus, R.id.treatments_newtreatment_carbsamount_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"));
- editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"));
+ editCarbs = new PlusMinusEditText(view, R.id.treatments_newtreatment_carbsamount, R.id.treatments_newtreatment_carbsamount_plus, R.id.treatments_newtreatment_carbsamount_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false);
+ editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false);
return view;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
index c687eede0e..026faae74a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java
@@ -115,9 +115,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit);
Double maxCorrection = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
- editBg = new PlusMinusEditText(view, R.id.treatments_wizard_bginput, R.id.treatments_wizard_bginput_plus, R.id.treatments_wizard_bginput_minus, 0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"));
- editCarbs = new PlusMinusEditText(view, R.id.treatments_wizard_carbsinput, R.id.treatments_wizard_carbsinput_plus, R.id.treatments_wizard_carbsinput_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"));
- editCorr = new PlusMinusEditText(view, R.id.treatments_wizard_correctioninput, R.id.treatments_wizard_correctioninput_plus, R.id.treatments_wizard_correctioninput_minus, 0d, 0d, maxCorrection, 0.05d, new DecimalFormat("0.00"));
+ editBg = new PlusMinusEditText(view, R.id.treatments_wizard_bginput, R.id.treatments_wizard_bginput_plus, R.id.treatments_wizard_bginput_minus, 0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
+ editCarbs = new PlusMinusEditText(view, R.id.treatments_wizard_carbsinput, R.id.treatments_wizard_carbsinput_plus, R.id.treatments_wizard_carbsinput_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false);
+ editCorr = new PlusMinusEditText(view, R.id.treatments_wizard_correctioninput, R.id.treatments_wizard_correctioninput_plus, R.id.treatments_wizard_correctioninput_minus, 0d, 0d, maxCorrection, 0.05d, new DecimalFormat("0.00"), false);
initDialog();
return view;
}
@@ -179,7 +179,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "No profile loaded from NS yet");
+ ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.noprofile));
return;
}
diff --git a/app/src/main/java/info/nightscout/client/data/DbLogger.java b/app/src/main/java/info/nightscout/client/data/DbLogger.java
new file mode 100644
index 0000000000..14dc8f4d92
--- /dev/null
+++ b/app/src/main/java/info/nightscout/client/data/DbLogger.java
@@ -0,0 +1,30 @@
+package info.nightscout.client.data;
+
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import info.nightscout.androidaps.Config;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.utils.ToastUtils;
+
+/**
+ * Created by mike on 02.07.2016.
+ */
+public class DbLogger {
+ public static void dbAdd(Intent intent, String data, Class sender) {
+ Logger log = LoggerFactory.getLogger(sender);
+ List q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0);
+ if (q.size() < 1) {
+ ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.resources.getString(R.string.nsclientnotinstalled));
+ log.error("DBADD No receivers");
+ } else if (Config.logNSUpload)
+ log.debug("DBADD dbAdd " + q.size() + " receivers " + data);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/client/data/NSProfile.java b/app/src/main/java/info/nightscout/client/data/NSProfile.java
index 472aa796de..74d22e2b15 100644
--- a/app/src/main/java/info/nightscout/client/data/NSProfile.java
+++ b/app/src/main/java/info/nightscout/client/data/NSProfile.java
@@ -5,8 +5,10 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.text.DecimalFormat;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.Iterator;
import java.util.TimeZone;
import info.nightscout.androidaps.Constants;
@@ -38,6 +40,26 @@ public class NSProfile {
return profile;
}
+ public ArrayList getProfileList() {
+ ArrayList ret = new ArrayList();
+
+ JSONObject store;
+ JSONObject profile = null;
+ try {
+ store = json.getJSONObject("store");
+ Iterator> keys = store.keys();
+
+ while( keys.hasNext() ) {
+ String profileName = (String) keys.next();
+ ret.add(profileName);
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ return ret;
+ }
+
public String log() {
String ret = "\n";
for (Integer hour = 0; hour < 24; hour ++) {
diff --git a/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java b/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java
index 10b213585c..6faf77ffa8 100644
--- a/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java
+++ b/app/src/main/java/info/nightscout/utils/PlusMinusEditText.java
@@ -34,6 +34,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
Double maxValue = 1d;
Double step = 1d;
NumberFormat formater;
+ boolean allowZero = false;
private Handler mHandler;
private ScheduledExecutorService mUpdater;
@@ -57,7 +58,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
private static final int MSG_INC = 0;
private static final int MSG_DEC = 1;
- public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater) {
+ public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero) {
editText = (TextView) view.findViewById(editTextID);
minusImage = (ImageView) view.findViewById(minusID);
plusImage = (ImageView) view.findViewById(plusID);
@@ -67,6 +68,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
this.maxValue = maxValue;
this.step = step;
this.formater = formater;
+ this.allowZero = allowZero;
mHandler = new Handler() {
@Override
@@ -89,6 +91,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
plusImage.setOnTouchListener(this);
plusImage.setOnKeyListener(this);
plusImage.setOnClickListener(this);
+ updateEditText();
}
public void setValue(Double value) {
@@ -117,7 +120,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
}
private void updateEditText() {
- if (value == 0d)
+ if (value == 0d && !allowZero)
editText.setText("");
else
editText.setText(formater.format(value));
diff --git a/app/src/main/res/layout/careportal_fragment.xml b/app/src/main/res/layout/careportal_fragment.xml
new file mode 100644
index 0000000000..d2123d6193
--- /dev/null
+++ b/app/src/main/res/layout/careportal_fragment.xml
@@ -0,0 +1,202 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml
new file mode 100644
index 0000000000..f515ea73dd
--- /dev/null
+++ b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml
@@ -0,0 +1,632 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index dfa05227dc..30413c03d7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -95,6 +95,8 @@
Temp Basals
Treatments
Virtual Pump
+ Careportal
+
Pump
Treatments
@@ -150,6 +152,7 @@
Open Loop
New suggestion available
Unsupported version of NSClient
+ NSClient not installed. Record lost!
BG available in NS
Pump status available in NS
Manual enacts
@@ -159,5 +162,42 @@
Basal IOB
Bolus constraint applied
Carbs constraint applied
+ BG Check
+ Announcement
+ Note
+ Question
+ Exercise
+ Pump Site Change
+ CGM Sensor Insert
+ CGM Sensor Start
+ Insulin Cartridge Change
+ Profile Switch
+ Snack Bolus
+ Meal Bolus
+ Correction Bolus
+ Combo Bolus
+ Temp Basal Start
+ Temp Basal End
+ Carbs correction
+ OpenAPS Offline
+
+ Event type
+ Other
+ Meter
+ Sensor
+ Carbs
+ Insulin
+ Carb time
+ Split
+ Duration
+ Percent
+ Absolute
+ min
+ Notes
+ Event time
+ Profile
+ Entered By
+ Glucose type
+ No profile loaded from NS yet
diff --git a/app/src/main/res/xml/pref_careportal.xml b/app/src/main/res/xml/pref_careportal.xml
new file mode 100644
index 0000000000..fa19ea3833
--- /dev/null
+++ b/app/src/main/res/xml/pref_careportal.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
\ No newline at end of file