diff --git a/app/build.gradle b/app/build.gradle index a8fd84511e..18cf49f1b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { minSdkVersion 21 targetSdkVersion 23 versionCode 1100 - versionName "1.1e" + versionName "1.1g" buildConfigField "String", "BUILDVERSION", generateGitBuild() } lintOptions { diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 96f18396ce..52cb5d85a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -49,4 +49,7 @@ public class Constants { public static final int[] VERY_HARD_LIMIT_TEMP_MIN_BG = {72,180}; public static final int[] VERY_HARD_LIMIT_TEMP_MAX_BG = {72,270}; public static final int[] VERY_HARD_LIMIT_TEMP_TARGET_BG = {72,200}; + + //DanaR + public static final double dailyLimitWarning = 0.95d; } diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index c804f8ae58..36931ccd5b 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.tabs.TabPageAdapter; import info.nightscout.utils.LogDialog; import info.nightscout.utils.ImportExportPrefs; import info.nightscout.utils.LocaleHelper; +import info.nightscout.utils.PasswordProtection; public class MainActivity extends AppCompatActivity { private static Logger log = LoggerFactory.getLogger(MainActivity.class); @@ -125,8 +126,13 @@ public class MainActivity extends AppCompatActivity { int id = item.getItemId(); switch (id) { case R.id.nav_preferences: - Intent i = new Intent(getApplicationContext(), PreferencesActivity.class); - startActivity(i); + PasswordProtection.QueryPassword(this, R.string.settings_password, "settings_password", new Runnable() { + @Override + public void run() { + Intent i = new Intent(getApplicationContext(), PreferencesActivity.class); + startActivity(i); + } + }, null); break; case R.id.nav_resetdb: new AlertDialog.Builder(this) diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index ccd6fc3857..f0d60cae19 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin; import info.nightscout.utils.LocaleHelper; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -54,7 +55,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } if (pref instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) pref; - if (pref.getKey().contains("danar_password")) { + if (pref.getKey().contains("password")) { pref.setSummary("******"); } else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) { ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); @@ -82,6 +83,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_password); addPreferencesFromResource(R.xml.pref_quickwizard); addPreferencesFromResource(R.xml.pref_language); if (Config.CAREPORTALENABLED) @@ -104,6 +106,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_danarprofile); } } + VirtualPumpPlugin virtualPumpPlugin = (VirtualPumpPlugin) MainApp.getSpecificPlugin(VirtualPumpPlugin.class); + if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) { + addPreferencesFromResource(R.xml.pref_virtualpump); + } if (Config.SMSCOMMUNICATORENABLED) addPreferencesFromResource(R.xml.pref_smscommunicator); addPreferencesFromResource(R.xml.pref_others); diff --git a/app/src/main/java/info/nightscout/androidaps/data/MealData.java b/app/src/main/java/info/nightscout/androidaps/data/MealData.java index a03dde3181..b8e73c3e00 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/MealData.java +++ b/app/src/main/java/info/nightscout/androidaps/data/MealData.java @@ -28,7 +28,7 @@ public class MealData { List bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * profile.getDia() * 2), false); long now = new Date().getTime(); - long dia_ago = now - (new Double(profile.getDia() * 60 * 60 * 1000l)).longValue(); + long dia_ago = now - (new Double(1.5d * profile.getDia() * 60 * 60 * 1000l)).longValue(); long t = treatment.created_at.getTime(); if (t > dia_ago && t <= now) { if (treatment.carbs >= 1) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index e2ace23845..47b8aa222f 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -230,6 +230,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTreatmentChange(); } + public void delete(Treatment treatment) { + try { + getDaoTreatments().delete(treatment); + latestTreatmentChange = treatment.getTimeIndex(); + } catch (SQLException e) { + e.printStackTrace(); + } + scheduleTreatmentChange(); + } + public int delete(String _id) { Treatment stored = findTreatmentById(_id); int removed = 0; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index f1d4de5257..550b05103e 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -17,6 +17,8 @@ import info.nightscout.client.data.NSProfile; public interface PumpInterface { boolean isInitialized(); + boolean isSuspended(); + boolean isBusy(); boolean isTempBasalInProgress(); boolean isExtendedBoluslInProgress(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index e7a8bb2efc..c3ea14dc79 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -94,19 +94,19 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) extendedBolus.setVisibility(View.GONE); else extendedBolus.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) tempBasal.setVisibility(View.GONE); else tempBasal.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) fill.setVisibility(View.GONE); else fill.setVisibility(View.VISIBLE); 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 index 2693505f74..4c93b88102 100644 --- 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 @@ -13,11 +13,13 @@ import android.support.v4.app.FragmentActivity; import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.TextWatcher; +import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RadioButton; @@ -44,6 +46,7 @@ import java.util.Date; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.interfaces.PumpInterface; @@ -264,10 +267,32 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick // 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, 0d, 0d, 40d, 0.1d, new DecimalFormat("0.0"), false); + Double bg = NSProfile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL); + if (profile == null) + editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false); + else if (profile.getUnits().equals(Constants.MMOL)) + editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 30d, 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, 0d, 0d, 500d, 1d, new DecimalFormat("0"), false); + editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 1d, new DecimalFormat("0"), false); + bgInputEdit.addTextChangedListener(new TextWatcher() { + + public void afterTextChanged(Editable s) {} + + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + public void onTextChanged(CharSequence s, int start, int before, int count) { + if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true); + } + }); + sensorRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); + if (profile == null) return; + Double bg = NSProfile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits()); + editBg.setValue(bg); + } + }); 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); @@ -330,7 +355,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), - df.is24HourFormat(context) + DateFormat.is24HourFormat(context) ); tpd.setThemeDark(true); tpd.dismissOnPause(true); @@ -588,7 +613,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick public void run() { try { String profile = data.getString("profile"); - NSProfile nsProfile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + NSProfile nsProfile = ConfigBuilderPlugin.getActiveProfile().getProfile(); nsProfile.setActiveProfile(profile); PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) { @@ -598,8 +623,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } else { log.error("No active pump selected"); } - if (MainApp.getConfigBuilder().getActiveProfile() instanceof CircadianPercentageProfilePlugin) { - CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getConfigBuilder().getActiveProfile(); + if (ConfigBuilderPlugin.getActiveProfile() instanceof CircadianPercentageProfilePlugin) { + CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfile(); data.put("CircadianPercentageProfile", true); data.put("timeshift", cpp.timeshift); data.put("percentage", cpp.percentage); @@ -623,8 +648,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick tempTarget.duration = data.getInt("duration"); tempTarget.reason = data.getString("reason"); if(tempTarget.duration != 0) { - tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); - tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); + tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits()); + tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits()); } else { tempTarget.low = 0; tempTarget.high = 0; @@ -635,9 +660,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick dao.createIfNotExists(tempTarget); MainApp.bus().post(new EventTempTargetRangeChange()); ConfigBuilderPlugin.uploadCareportalEntryToNS(data); - } catch (JSONException e) { - e.printStackTrace(); - } catch (SQLException e) { + } catch (JSONException | SQLException e) { e.printStackTrace(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 0b31f360bb..bb4513b069 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.support.design.widget.Snackbar; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; @@ -68,7 +69,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag ImageView iceditIcon; ImageView isfeditIcon; BasalEditDialog basalEditDialog; - LinearLayout ll; + FrameLayout fl; Snackbar mSnackBar; static Boolean percentageViewHint = true; @@ -78,8 +79,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false); - ll = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_linearlayout); - ll.requestFocusFromTouch(); + fl = (FrameLayout) layout.findViewById(R.id.circadianpercentageprofile_framelayout); + fl.requestFocusFromTouch(); diaView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_dia); mgdlView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mgdl); mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); @@ -203,7 +204,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag mSnackBar.dismiss(); } timeshiftView.clearFocus(); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } else { if (timeshiftViewHint) { @@ -222,7 +223,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag mSnackBar.dismiss(); } percentageView.clearFocus(); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } else { if (percentageViewHint) { @@ -238,7 +239,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { diaView.clearFocus(); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } } }); @@ -249,7 +250,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { targethighView.clearFocus(); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } } }); @@ -260,7 +261,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { targetlowView.clearFocus(); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } } }); @@ -325,11 +326,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag this.snackbarCaller = snackbarCaller; if (timeshiftViewHint || percentageViewHint) { - mSnackBar = Snackbar.make(view, - Msg, - Snackbar.LENGTH_LONG) - .setDuration(Snackbar.LENGTH_LONG) - .setActionTextColor(getResources().getColor(R.color.notificationInfo)) + //noinspection WrongConstant + mSnackBar = Snackbar.make(view, Msg, 7000) + .setActionTextColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationInfo)) .setAction(getString(R.string.dont_show_again), new View.OnClickListener() { @Override public void onClick(View v) { @@ -344,9 +343,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; view.setLayoutParams(params); - view.setBackgroundColor(getResources().getColor(R.color.cardview_dark_background)); + view.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardview_dark_background)); TextView mainTextView = (TextView) (view).findViewById(android.support.design.R.id.snackbar_text); - mainTextView.setTextColor(getResources().getColor(R.color.mdtp_white)); + mainTextView.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.mdtp_white)); mSnackBar.show(); } } @@ -383,7 +382,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag basalEditDialog.dismiss(); } basalEditDialog = null; - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } public static class BasalEditDialog extends DialogFragment { @@ -464,7 +463,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag basalEditDialog = null; MainApp.bus().unregister(this); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } @Override @@ -472,7 +471,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag super.onResume(); MainApp.bus().register(this); onStatusEvent(null); - ll.requestFocusFromTouch(); + fl.requestFocusFromTouch(); } @Subscribe @@ -482,7 +481,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); 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 ad7d4ae647..bf9f3fb0b2 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 @@ -9,7 +9,9 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.CheckBox; +import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; @@ -28,6 +30,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin; import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin; +import info.nightscout.utils.PasswordProtection; public class ConfigBuilderFragment extends Fragment implements FragmentBase { @@ -62,6 +65,8 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase { PluginCustomAdapter constraintsDataAdapter = null; PluginCustomAdapter generalDataAdapter = null; + LinearLayout mainLayout; + Button unlock; // TODO: sorting @@ -89,6 +94,25 @@ public class ConfigBuilderFragment extends Fragment implements FragmentBase { if (ConfigBuilderPlugin.nightscoutVersionCode < 900) nightscoutVerView.setTextColor(Color.RED); setViews(); + + unlock = (Button) view.findViewById(R.id.configbuilder_unlock); + mainLayout = (LinearLayout) view.findViewById(R.id.configbuilder_mainlayout); + + if (PasswordProtection.isLocked("settings_password")) { + mainLayout.setVisibility(View.GONE); + unlock.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() { + @Override + public void run() { + mainLayout.setVisibility(View.VISIBLE); + unlock.setVisibility(View.GONE); + } + }, null); + } + }); + } return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 005e78cb2d..a0b2a7b3b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -18,6 +18,10 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -75,7 +79,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain static ArrayList pluginList; - static Date lastDeviceStatusUpload = new Date(0); + private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); + private static ScheduledFuture scheduledPost = null; PowerManager.WakeLock mWakeLock; @@ -336,6 +341,16 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return activePump.isInitialized(); } + @Override + public boolean isSuspended() { + return activePump.isSuspended(); + } + + @Override + public boolean isBusy() { + return activePump.isBusy(); + } + @Override public boolean isTempBasalInProgress() { return activePump.isTempBasalInProgress(); @@ -608,6 +623,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain result.comment = MainApp.sResources.getString(R.string.pumpNotInitialized); result.enacted = false; result.success = false; + log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized)); + return result; + } + + if (isSuspended()) { + result = new PumpEnactResult(); + result.comment = MainApp.sResources.getString(R.string.pumpsuspended); + result.enacted = false; + result.success = false; + log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended)); + return result; } if (Config.logCongigBuilderActions) @@ -801,22 +827,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain @Subscribe public void onStatusEvent(final EventNewBG ev) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - // Give some time to Loop - try { - Thread.sleep(120 * 1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - // if status not uploaded, upload pump status only - if (new Date().getTime() - lastDeviceStatusUpload.getTime() > 120 * 1000L) { - uploadDeviceStatus(); - } - } - }); - t.start(); + uploadDeviceStatus(120); } public void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) { @@ -922,11 +933,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } } - public void uploadDeviceStatus() { + public void doUploadDeviceStatus() { DeviceStatus deviceStatus = new DeviceStatus(); try { LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; - if (lastRun != null && lastRun.lastAPSRun.getTime() > new Date().getTime() - 60 * 1000L) { + if (lastRun != null && lastRun.lastAPSRun.getTime() > new Date().getTime() - 300 * 1000L) { // do not send if result is older than 1 min APSResult apsResult = lastRun.request; apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun)); @@ -958,18 +969,36 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } if (activePump != null) { deviceStatus.device = "openaps://" + deviceID(); - deviceStatus.pump = getJSONStatus(); + JSONObject pumpstatus = getJSONStatus(); + if (pumpstatus != null) { + deviceStatus.pump = getJSONStatus(); + } deviceStatus.created_at = DateUtil.toISOString(new Date()); deviceStatus.sendToNSClient(); - lastDeviceStatusUpload = new Date(); } } catch (JSONException e) { e.printStackTrace(); } } + static public void uploadDeviceStatus(int sec) { + class PostRunnable implements Runnable { + public void run() { + MainApp.getConfigBuilder().doUploadDeviceStatus(); + scheduledPost = null; + } + } + // prepare task for execution + // cancel waiting task to prevent sending multiple posts + if (scheduledPost != null) + scheduledPost.cancel(false); + Runnable task = new PostRunnable(); + scheduledPost = worker.schedule(task, sec, TimeUnit.SECONDS); + log.debug("Scheduling devicestatus upload in " + sec + " sec"); + } + public void uploadBolusWizardRecord(Treatment t, double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { JSONObject data = new JSONObject(); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 3eb8e2c881..7889471d6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -211,6 +211,17 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled; } + @Override + public boolean isSuspended() { + return getDanaRPump().pumpSuspended; + } + + @Override + public boolean isBusy() { + if (sExecutionService == null) return false; + return sExecutionService.isConnected() || sExecutionService.isConnecting(); + } + // Pump interface @Override public boolean isTempBasalInProgress() { @@ -705,7 +716,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf JSONObject extended = new JSONObject(); try { battery.put("percent", getDanaRPump().batteryRemaining); - status.put("status", "normal"); + status.put("status", getDanaRPump().pumpSuspended ? "suspended" : "normal"); status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection)); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("PumpIOB", getDanaRPump().iob); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index 5ce5fafdae..e7ecb4c742 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.UUID; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.Treatment; @@ -33,6 +34,7 @@ import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaR.DanaRPump; import info.nightscout.androidaps.plugins.DanaR.SerialIOThread; @@ -78,6 +80,8 @@ import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -276,6 +280,7 @@ public class ExecutionService extends Service { private boolean getPumpStatus() { try { + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); @@ -336,6 +341,13 @@ public class ExecutionService extends Service { danaRPump.lastConnection = now; MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); + MainApp.getConfigBuilder().uploadDeviceStatus(60); + if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) { + log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); + Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(reportFail)); + MainApp.getConfigBuilder().uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); + } } catch (Exception e) { e.printStackTrace(); } @@ -345,30 +357,37 @@ public class ExecutionService extends Service { public boolean tempBasal(int percent, int durationInHours) { connect("tempBasal"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean tempBasalStop() { connect("tempBasalStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolus(double insulin, int durationInHalfHours) { connect("extendedBolus"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolusStop() { connect("extendedBolusStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); return true; @@ -482,6 +501,7 @@ public class ExecutionService extends Service { public boolean updateBasalsInPump(final NSProfile profile) { connect("updateBasalsInPump"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates))); double[] basal = buildDanaRProfileRecord(profile); MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal); mSerialIOThread.sendMessage(msgSet); @@ -489,6 +509,7 @@ public class ExecutionService extends Service { mSerialIOThread.sendMessage(msgActivate); danaRPump.lastSettingsRead = new Date(0); // force read full settings getPumpStatus(); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java index a74529416a..fef8868d2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java @@ -4,12 +4,20 @@ public class EventDanaRConnectionStatus { public static final int CONNECTING = 0; public static final int CONNECTED = 1; public static final int DISCONNECTED = 2; + public static final int PERFORMING = 3; public int sStatus = DISCONNECTED; public int sSecondsElapsed = 0; + public String sAction = ""; public EventDanaRConnectionStatus(int status, int secondsElapsed) { sStatus = status; sSecondsElapsed = secondsElapsed; } + + public EventDanaRConnectionStatus(int status, int secondsElapsed, String action) { + sStatus = status; + sSecondsElapsed = secondsElapsed; + sAction = action; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java index 6876e5f9f8..1384be16e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java @@ -211,6 +211,17 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints return getDanaRPump().lastConnection.getTime() > 0 && !getDanaRPump().isConfigUD && !getDanaRPump().isEasyModeEnabled && getDanaRPump().isExtendedBolusEnabled; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + if (sExecutionService == null) return false; + return sExecutionService.isConnected() || sExecutionService.isConnecting(); + } + // Pump interface @Override public boolean isTempBasalInProgress() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java index bcd49e3d7e..0bad19b38e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.UUID; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.Treatment; @@ -74,6 +75,8 @@ import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgSettingShippingInf import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgStatusBasic; import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgStatusBolusExtended; import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgStatusTempBasal; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; @@ -272,6 +275,7 @@ public class ExecutionService extends Service { private boolean getPumpStatus() { try { + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus))); //MsgStatus statusMsg = new MsgStatus(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); @@ -330,6 +334,13 @@ public class ExecutionService extends Service { danaRKoreanPump.lastConnection = now; MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); + MainApp.getConfigBuilder().uploadDeviceStatus(60); + if (danaRKoreanPump.dailyTotalUnits > danaRKoreanPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) { + log.debug("Approaching daily limit: " + danaRKoreanPump.dailyTotalUnits + "/" + danaRKoreanPump.maxDailyTotalUnits); + Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(reportFail)); + MainApp.getConfigBuilder().uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRKoreanPump.dailyTotalUnits + "/" + danaRKoreanPump.maxDailyTotalUnits + "U"); + } } catch (Exception e) { e.printStackTrace(); } @@ -339,32 +350,40 @@ public class ExecutionService extends Service { public boolean tempBasal(int percent, int durationInHours) { connect("tempBasal"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean tempBasalStop() { connect("tempBasalStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolus(double insulin, int durationInHalfHours) { connect("extendedBolus"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolusStop() { connect("extendedBolusStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } @@ -476,11 +495,13 @@ public class ExecutionService extends Service { public boolean updateBasalsInPump(final NSProfile profile) { connect("updateBasalsInPump"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates))); double[] basal = buildDanaRProfileRecord(profile); MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal); mSerialIOThread.sendMessage(msgSet); danaRKoreanPump.lastSettingsRead = new Date(0); // force read full settings getPumpStatus(); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java index 6000cfddaa..552a05cc28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java @@ -156,7 +156,7 @@ public class LocalProfileFragment extends Fragment implements FragmentBase { activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index 291fd36675..a183e28345 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -76,7 +76,14 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Frag public void onClick(View view) { switch (view.getId()) { case R.id.loop_run: - getPlugin().invoke("Loop button", true); + lastRunView.setText(MainApp.sResources.getString(R.string.executing)); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + getPlugin().invoke("Loop button", true); + } + }); + thread.start(); break; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index a357d519b9..76eb14eb1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -228,7 +228,7 @@ public class LoopPlugin implements PluginBase { } MainApp.bus().post(new EventLoopUpdateGui()); - MainApp.getConfigBuilder().uploadDeviceStatus(); + MainApp.getConfigBuilder().uploadDeviceStatus(120); } finally { if (Config.logFunctionCalls) log.debug("invoke end"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java index 377468f43a..ce48a966de 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java @@ -115,6 +115,16 @@ public class MDIPlugin implements PluginBase, PumpInterface { return true; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + return false; + } + @Override public boolean isTempBasalInProgress() { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index 8a7a9b00ae..5d83a76cc7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -22,6 +22,7 @@ public class Notification { public static final int BASAL_VALUE_BELOW_MINIMUM = 7; public static final int OLD_NSCLIENT = 8; public static final int INVALID_PHONE_NUMBER = 9; + public static final int APPROACHING_DAILY_LIMIT = 10; public int id; public Date date; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 4620a633ed..61f4279a51 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -71,6 +71,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; @@ -116,7 +117,7 @@ public class OverviewFragment extends Fragment { TextView iobView; TextView apsModeView; TextView tempTargetView; - TextView initializingView; + TextView pumpStatusView; GraphView bgGraph; CheckBox showPredictionView; @@ -162,7 +163,7 @@ public class OverviewFragment extends Fragment { baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal); basalLayout = (LinearLayout) view.findViewById(R.id.overview_basallayout); activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); - initializingView = (TextView) view.findViewById(R.id.overview_initializing); + pumpStatusView = (TextView) view.findViewById(R.id.overview_initializing); iobView = (TextView) view.findViewById(R.id.overview_iob); apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); @@ -268,7 +269,7 @@ public class OverviewFragment extends Fragment { finalLastRun.setByPump = applyResult; finalLastRun.lastEnact = new Date(); finalLastRun.lastOpenModeAccept = new Date(); - MainApp.getConfigBuilder().uploadDeviceStatus(); + MainApp.getConfigBuilder().uploadDeviceStatus(15); ObjectivesPlugin objectivesPlugin = (ObjectivesPlugin) MainApp.getSpecificPlugin(ObjectivesPlugin.class); if (objectivesPlugin != null) { objectivesPlugin.manualEnacts++; @@ -287,22 +288,35 @@ public class OverviewFragment extends Fragment { } }); + pumpStatusView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized()) + sHandler.post(new Runnable() { + @Override + public void run() { + MainApp.getConfigBuilder().updateStatus("RefreshClicked"); + } + }); + } + }); + updateGUI(); return view; } void processQuickWizard() { - final BgReading lastBG = GlucoseStatus.lastBg(); + final BgReading actualBg = GlucoseStatus.actualBg(); if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet return; final NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); - if (quickWizardEntry != null && lastBG != null) { + if (quickWizardEntry != null && actualBg != null) { quickWizardButton.setVisibility(View.VISIBLE); String text = MainApp.sResources.getString(R.string.bolus) + ": " + quickWizardEntry.buttonText(); BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile.getDefaultProfile(), quickWizardEntry.carbs(), lastBG.valueToUnits(profile.getUnits()), 0d, true, true); + wizard.doCalc(profile.getDefaultProfile(), quickWizardEntry.carbs(), actualBg.valueToUnits(profile.getUnits()), 0d, true, true); final JSONObject boluscalcJSON = new JSONObject(); try { @@ -314,7 +328,7 @@ public class OverviewFragment extends Fragment { boluscalcJSON.put("iob", -(wizard.insulingFromBolusIOB + wizard.insulingFromBasalsIOB)); boluscalcJSON.put("bolusiobused", true); boluscalcJSON.put("basaliobused", true); - boluscalcJSON.put("bg", lastBG.valueToUnits(profile.getUnits())); + boluscalcJSON.put("bg", actualBg.valueToUnits(profile.getUnits())); boluscalcJSON.put("insulinbg", wizard.insulinFromBG); boluscalcJSON.put("insulinbgused", true); boluscalcJSON.put("bgdiff", wizard.bgDiff); @@ -361,7 +375,7 @@ public class OverviewFragment extends Fragment { getContext(), finalInsulinAfterConstraints, finalCarbsAfterConstraints, - lastBG.valueToUnits(profile.getUnits()), + actualBg.valueToUnits(profile.getUnits()), "Manual", 0, boluscalcJSON @@ -443,16 +457,41 @@ public class OverviewFragment extends Fragment { } @Subscribe - public void onStatusEvent(final EventNewBasalProfile ev) { updateGUIIfVisible(); } + public void onStatusEvent(final EventNewBasalProfile ev) { + updateGUIIfVisible(); + } @Subscribe - public void onStatusEvent(final EventTempTargetRangeChange ev) {updateGUIIfVisible();} + public void onStatusEvent(final EventTempTargetRangeChange ev) { + updateGUIIfVisible(); + } @Subscribe - public void onStatusEvent(final EventNewNotification n) { updateNotifications(); } + public void onStatusEvent(final EventNewNotification n) { + updateNotifications(); + } @Subscribe - public void onStatusEvent(final EventDismissNotification n) { updateNotifications(); } + public void onStatusEvent(final EventDismissNotification n) { + updateNotifications(); + } + + @Subscribe + public void onStatusEvent(final EventDanaRConnectionStatus s) { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (s.sStatus == EventDanaRConnectionStatus.CONNECTING) + updatePumpStatus(String.format(getString(R.string.danar_history_connectingfor), s.sSecondsElapsed)); + else if (s.sStatus == EventDanaRConnectionStatus.PERFORMING) + updatePumpStatus(s.sAction); + else if (s.sStatus == EventDanaRConnectionStatus.DISCONNECTED) + updatePumpStatus(null); + } + }); + } private void hideTempRecommendation() { Activity activity = getActivity(); @@ -476,6 +515,35 @@ public class OverviewFragment extends Fragment { }); } + private void updatePumpStatus(String status) { + PumpInterface pump = MainApp.getConfigBuilder(); + if (status != null) { + pumpStatusView.setText(status); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (pump.isBusy()) { + pumpStatusView.setText(R.string.pumpbusy); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (pump.isSuspended()) { + // disable all treatment buttons because we are not able to check constraints without profile + wizardButton.setVisibility(View.INVISIBLE); + treatmentButton.setVisibility(View.INVISIBLE); + quickWizardButton.setVisibility(View.INVISIBLE); + pumpStatusView.setText(R.string.pumpsuspendedclicktorefresh); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (!pump.isInitialized()) { + // disable all treatment buttons because we are not able to check constraints without profile + wizardButton.setVisibility(View.INVISIBLE); + treatmentButton.setVisibility(View.INVISIBLE); + quickWizardButton.setVisibility(View.INVISIBLE); + pumpStatusView.setText(R.string.waitingforpumpclicktorefresh); + pumpStatusView.setVisibility(View.VISIBLE); + } else { + wizardButton.setVisibility(View.VISIBLE); + treatmentButton.setVisibility(View.VISIBLE); + pumpStatusView.setVisibility(View.GONE); + } + } + @SuppressLint("SetTextI18n") public void updateGUI() { updateNotifications(); @@ -483,11 +551,11 @@ public class OverviewFragment extends Fragment { BgReading lastBG = GlucoseStatus.lastBg(); if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null || MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet - initializingView.setText(R.string.noprofileset); - initializingView.setVisibility(View.VISIBLE); + pumpStatusView.setText(R.string.noprofileset); + pumpStatusView.setVisibility(View.VISIBLE); return; } else { - initializingView.setVisibility(View.GONE); + pumpStatusView.setVisibility(View.GONE); } // Skip if not initialized yet @@ -504,7 +572,7 @@ public class OverviewFragment extends Fragment { apsModeView.setBackgroundResource(R.drawable.loopmodeborder); apsModeView.setTextColor(Color.BLACK); final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); - if(activeloop != null && activeloop.isEnabled(activeloop.getType())) { + if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { if (MainApp.getConfigBuilder().isClosedModeEnabled()) { apsModeView.setText(MainApp.sResources.getString(R.string.closedloop)); } else { @@ -522,10 +590,10 @@ public class OverviewFragment extends Fragment { @Override public boolean onLongClick(View view) { view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - if (activeloop == null){ + if (activeloop == null) { log.error("no active loop?"); return true; - } else if (activeloop.isEnabled(PluginBase.LOOP)){ + } else if (activeloop.isEnabled(PluginBase.LOOP)) { activeloop.setFragmentEnabled(PluginBase.LOOP, false); activeloop.setFragmentVisible(PluginBase.LOOP, false); } else { @@ -578,7 +646,7 @@ public class OverviewFragment extends Fragment { showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested - if (showAcceptButton && pump.isInitialized() && ConfigBuilderPlugin.getActiveLoop() != null) { + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && ConfigBuilderPlugin.getActiveLoop() != null) { acceptTempLayout.setVisibility(View.VISIBLE); acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); } else { @@ -644,7 +712,7 @@ public class OverviewFragment extends Fragment { // QuickWizard button QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); - if (quickWizardEntry != null && lastBG != null && pump.isInitialized()) { + if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { quickWizardButton.setVisibility(View.VISIBLE); String text = MainApp.sResources.getString(R.string.bolus) + ": " + quickWizardEntry.buttonText() + " " + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = new BolusWizard(); @@ -663,7 +731,7 @@ public class OverviewFragment extends Fragment { bgView.setText(lastBG.valueToUnitsToString(profile.getUnits())); arrowView.setText(lastBG.directionToSymbol()); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (glucoseStatus != null){ + if (glucoseStatus != null) { deltaView.setText("Δ " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units); avgdeltaView.setText("øΔ15m: " + NSProfile.toUnitsString(glucoseStatus.short_avgdelta, glucoseStatus.short_avgdelta * Constants.MGDL_TO_MMOLL, units) + " øΔ40m: " + NSProfile.toUnitsString(glucoseStatus.long_avgdelta, glucoseStatus.long_avgdelta * Constants.MGDL_TO_MMOLL, units)); @@ -717,7 +785,7 @@ public class OverviewFragment extends Fragment { long fromTime; long endTime; if (showPrediction) { - int predHours = (int) (Math.ceil(((DetermineBasalResultAMA)finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000)); + int predHours = (int) (Math.ceil(((DetermineBasalResultAMA) finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000)); predHours = Math.min(2, predHours); predHours = Math.max(0, predHours); hoursToFetch = (int) (6 - predHours); @@ -734,11 +802,11 @@ public class OverviewFragment extends Fragment { Double lowLine = SafeParse.stringToDouble(prefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(prefs.getString("high_mark", "0")); - if (lowLine < 1){ + if (lowLine < 1) { lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units); } - if(highLine < 1){ + if (highLine < 1) { highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); } @@ -847,7 +915,7 @@ public class OverviewFragment extends Fragment { } maxBgValue = NSProfile.fromMgdlToUnits(maxBgValue, units); maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; - if(highLine > maxBgValue) maxBgValue = highLine; + if (highLine > maxBgValue) maxBgValue = highLine; Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); BgReading[] inRange = new BgReading[inRangeArray.size()]; @@ -935,20 +1003,7 @@ public class OverviewFragment extends Fragment { bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(ContextCompat.getColor(MainApp.instance(), R.color.background_material_dark)); // same color as backround = hide } - // Pump not initialized message - if (!pump.isInitialized()) { - // disable all treatment buttons because we are not able to check constraints without profile - wizardButton.setVisibility(View.INVISIBLE); - treatmentButton.setVisibility(View.INVISIBLE); - quickWizardButton.setVisibility(View.INVISIBLE); - initializingView.setText(R.string.waitingforpump); - initializingView.setVisibility(View.VISIBLE); - } else { - wizardButton.setVisibility(View.VISIBLE); - treatmentButton.setVisibility(View.VISIBLE); - initializingView.setVisibility(View.GONE); - } - + updatePumpStatus(null); } //Notifications @@ -1040,5 +1095,4 @@ public class OverviewFragment extends Fragment { } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java index 3c5ed08377..4a31333ad9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java @@ -170,7 +170,7 @@ public class SimpleProfileFragment extends Fragment implements FragmentBase { activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index fed1191f38..38a4904b56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -1,9 +1,11 @@ package info.nightscout.androidaps.plugins.Treatments; import android.app.Activity; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Paint; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; @@ -55,7 +57,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener TextView activityTotal; Button refreshFromNS; - public static class RecyclerViewAdapter extends RecyclerView.Adapter { + Context context; + + public class RecyclerViewAdapter extends RecyclerView.Adapter { List treatments; @@ -88,6 +92,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorAffectingIOB)); else holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground)); + holder.remove.setTag(treatments.get(position)); } @Override @@ -100,7 +105,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener super.onAttachedToRecyclerView(recyclerView); } - public static class TreatmentsViewHolder extends RecyclerView.ViewHolder { + public class TreatmentsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { CardView cv; TextView date; TextView insulin; @@ -109,6 +114,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener TextView activity; TextView mealOrCorrection; LinearLayout dateLinearLayout; + TextView remove; TreatmentsViewHolder(View itemView) { super(itemView); @@ -120,6 +126,35 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener activity = (TextView) itemView.findViewById(R.id.treatments_activity); mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection); dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout); + remove = (TextView) itemView.findViewById(R.id.treatments_remove); + remove.setOnClickListener(this); + remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + } + + @Override + public void onClick(View v) { + final Treatment treatment = (Treatment) v.getTag(); + final Context finalContext = context; + switch (v.getId()) { + case R.id.treatments_remove: + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); + builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(treatment.created_at)); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + final String _id = treatment._id; + if (_id != null && !_id.equals("")) { + MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id); + } + MainApp.getDbHelper().delete(treatment); + treatmentsPlugin.initializeData(); + updateGUI(); + } + }); + builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null); + builder.show(); + break; + } } } } @@ -143,6 +178,8 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout); refreshFromNS.setOnClickListener(this); + context = getContext(); + updateGUI(); return view; } @@ -153,8 +190,8 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener case R.id.treatments_reshreshfromnightscout: SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); - if(nsUploadOnly){ - ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled)); + if (nsUploadOnly) { + ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled)); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); builder.setTitle(this.getContext().getString(R.string.confirmation)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java index 4e9ee89a9a..e90916122f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java @@ -1,6 +1,8 @@ package info.nightscout.androidaps.plugins.VirtualPump; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import org.json.JSONException; import org.json.JSONObject; @@ -124,6 +126,16 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return true; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + return false; + } + @Override public boolean isTempBasalInProgress() { return getTempBasal() != null; @@ -391,6 +403,10 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public JSONObject getJSONStatus() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + if (!preferences.getBoolean("virtualpump_uploadstatus", false)) { + return null; + } JSONObject pump = new JSONObject(); JSONObject battery = new JSONObject(); JSONObject status = new JSONObject(); diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 926451033e..a7f3f02f36 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -58,7 +58,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { } }); t.start(); - } else if (isStatusOutdated) { + } else if (isStatusOutdated && !pump.isBusy()) { Thread t = new Thread(new Runnable() { @Override public void run() { @@ -66,7 +66,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { } }); t.start(); - } else if (isBasalOutdated) { + } else if (isBasalOutdated && !pump.isBusy()) { Thread t = new Thread(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/info/nightscout/utils/PasswordProtection.java b/app/src/main/java/info/nightscout/utils/PasswordProtection.java new file mode 100644 index 0000000000..2b8d7a59c1 --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/PasswordProtection.java @@ -0,0 +1,72 @@ +package info.nightscout.utils; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + +/** + * Created by mike on 14.02.2017. + */ + +public class PasswordProtection { + static public boolean isLocked(String preference) { + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + final String password = SP.getString(preference, ""); + if (password.equals("")) { + return false; + } + return true; + } + + static public void QueryPassword(final Context context, int stringID, String preference, final Runnable ok, final Runnable fail) { + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + final String password = SP.getString(preference, ""); + if (password.equals("")) { + if (ok != null) ok.run(); + return; + } + LayoutInflater li = LayoutInflater.from(context); + View promptsView = li.inflate(R.layout.passwordprompt, null); + + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); + alertDialogBuilder.setView(promptsView); + + final TextView label = (TextView) promptsView.findViewById(R.id.passwordprompt_text); + label.setText(MainApp.sResources.getString(stringID)); + final EditText userInput = (EditText) promptsView.findViewById(R.id.passwordprompt_pass); + + // set dialog message + alertDialogBuilder + .setCancelable(false) + .setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + String enteredPassword = userInput.getText().toString(); + if (password.equals(enteredPassword)) { + if (ok != null) ok.run(); + } else { + ToastUtils.showToastInUiThread(context, MainApp.sResources.getString(R.string.wrongpassword)); + if (fail != null) fail.run(); + } + } + }) + .setNegativeButton("Cancel", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + dialog.cancel(); + } + }); + + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); + } +} diff --git a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml index 5bc0e35579..70a4a09eb3 100644 --- a/app/src/main/res/layout/careportal_newnstreatment_dialog.xml +++ b/app/src/main/res/layout/careportal_newnstreatment_dialog.xml @@ -94,14 +94,15 @@ android:id="@+id/careportal_newnstreatment_meter" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:checked="true" + android:checked="false" android:text="@string/careportal_newnstreatment_meter" /> + android:text="@string/careportal_newnstreatment_sensor" + android:checked="true" /> + android:orientation="vertical"> +