danar profile dia&car configurable in preferences

This commit is contained in:
Milos Kozak 2016-07-15 20:56:07 +02:00
parent f01b03979d
commit 7f661b7fa6
6 changed files with 46 additions and 11 deletions

View file

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

View file

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

View file

@ -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:0021:59
// Night / 22:005: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));
}
}

View file

@ -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" />
</LinearLayout>
</LinearLayout>

View file

@ -257,5 +257,8 @@
<string name="glucosetype_manual">Manual</string>
<string name="careportal_temporarytarget">Temporary Target</string>
<string name="careportal_temporarytargetcancel">Temporary Target Cancel</string>
<string name="danarprofile">DanaR profile settings</string>
<string name="danarprofile_dia">DIA [h]</string>
<string name="danarprofile_car">Carbs absorption rate</string>
</resources>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="DanaRProfile"
android:title="@string/danarprofile">
<EditTextPreference
android:defaultValue=""
android:key="danarprofile_dia"
android:numeric="decimal"
android:title="@string/danarprofile_dia" />
<EditTextPreference
android:defaultValue=""
android:key="danarprofile_car"
android:numeric="decimal"
android:title="@string/danarprofile_car" />
</PreferenceCategory>
</PreferenceScreen>