diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index b2681b6f54..20ba73d57e 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -13,7 +13,9 @@ import android.preference.PreferenceManager; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference; +import info.nightscout.androidaps.plugins.DanaR.DanaRFragment; import info.nightscout.utils.LocaleHelper; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -85,8 +87,13 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (Config.LOWSUSPEDENABLED) addPreferencesFromResource(R.xml.pref_lowsuspend); addPreferencesFromResource(R.xml.pref_nightscout); - if (Config.DANAR) + if (Config.DANAR) { addPreferencesFromResource(R.xml.pref_danar); + DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class); + if (danaRFragment != null && danaRFragment.isEnabled(PluginBase.PROFILE)) { + addPreferencesFromResource(R.xml.pref_danarprofile); + } + } if (Config.MM640G) addPreferencesFromResource(R.xml.pref_mm640g); if (Config.SMSCOMMUNICATORENABLED) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java index f305bc76ed..23ff2db5ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java @@ -67,8 +67,6 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface Handler loopHandler = new Handler(); Runnable refreshLoop = null; - NSProfile convertedProfile = null; - TextView lastConnectionView; TextView btConnectionView; TextView lastBolusView; @@ -851,7 +849,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface DanaRPump pump = getDanaRPump(); if (pump.lastSettingsRead.getTime() == 0) return null; // no info now - return pump.convertedProfile; + return pump.createConvertedProfile(); } // Reply for sms communicator diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java index 64cef160b8..03dd4c76e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java @@ -1,5 +1,8 @@ package info.nightscout.androidaps.plugins.DanaR; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -8,7 +11,9 @@ import java.text.DecimalFormat; import java.util.Date; import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; import info.nightscout.client.data.NSProfile; +import info.nightscout.utils.SafeParse; /** * Created by mike on 04.07.2016. @@ -86,9 +91,7 @@ public class DanaRPump { public double maxBolus; public double maxBasal; - NSProfile convertedProfile = null; - - public void createConvertedProfile() { + public NSProfile createConvertedProfile() { JSONObject json = new JSONObject(); JSONObject store = new JSONObject(); JSONObject profile = new JSONObject(); @@ -98,10 +101,14 @@ public class DanaRPump { // Evening / 17:00–21:59 // Night / 22:00–5:59 + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + double dia = SafeParse.stringToDouble(SP.getString("danarprofile_dia", "3")); + double car = SafeParse.stringToDouble(SP.getString("danarprofile_car", "20")); + try { json.put("defaultProfile", "" + (activeProfile + 1)); json.put("store", store); - profile.put("dia", 3); // TODO: fixed DIA, maybe would be needed to have it configurable in settings + profile.put("dia", dia); JSONArray carbratios = new JSONArray(); carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF)); @@ -111,7 +118,7 @@ public class DanaRPump { carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF)); profile.put("carbratio", carbratios); - profile.put("carbs_hr", 20); // TODO: fixed CAR, maybe would be needed to have it configurable in settings + profile.put("carbs_hr", car); JSONArray sens = new JSONArray(); sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR)); @@ -143,7 +150,7 @@ public class DanaRPump { } catch (JSONException e) { e.printStackTrace(); } - convertedProfile = new NSProfile(json, "" + (activeProfile + 1)); + return new NSProfile(json, "" + (activeProfile + 1)); } } diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index 750dc36b7a..d0f3db9249 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -260,7 +260,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/danar_viewprofile" - android:id="@+id/danar_viewprofile" /> + android:id="@+id/danar_viewprofile" + android:layout_weight="1" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d0f23731d..bcef304893 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -257,5 +257,8 @@ Manual Temporary Target Temporary Target Cancel + DanaR profile settings + DIA [h] + Carbs absorption rate diff --git a/app/src/main/res/xml/pref_danarprofile.xml b/app/src/main/res/xml/pref_danarprofile.xml new file mode 100644 index 0000000000..b88bb60f2e --- /dev/null +++ b/app/src/main/res/xml/pref_danarprofile.xml @@ -0,0 +1,19 @@ + + + + + + + + + \ No newline at end of file