low_mark, high_mark units dependent

This commit is contained in:
Milos Kozak 2019-11-28 19:54:59 +01:00
parent 599261081b
commit ec535b9c61
7 changed files with 48 additions and 44 deletions

View file

@ -105,7 +105,13 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
} }
// convert preferences values to current units // convert preferences values to current units
String[] unitDependent = new String[]{MainApp.gs(R.string.key_hypo_target), MainApp.gs(R.string.key_activity_target), MainApp.gs(R.string.key_eatingsoon_target)}; String[] unitDependent = new String[]{
MainApp.gs(R.string.key_hypo_target),
MainApp.gs(R.string.key_activity_target),
MainApp.gs(R.string.key_eatingsoon_target),
MainApp.gs(R.string.key_high_mark),
MainApp.gs(R.string.key_low_mark)
};
if (Arrays.asList(unitDependent).contains(pref.getKey())) { if (Arrays.asList(unitDependent).contains(pref.getKey())) {
editTextPref = (EditTextPreference) pref; editTextPref = (EditTextPreference) pref;
String converted = Profile.toCurrentUnitsString(SafeParse.stringToDouble(editTextPref.getText())); String converted = Profile.toCurrentUnitsString(SafeParse.stringToDouble(editTextPref.getText()));

View file

@ -1041,8 +1041,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final String profileName = ProfileFunctions.getInstance().getProfileName(); final String profileName = ProfileFunctions.getInstance().getProfileName();
final String units = ProfileFunctions.getSystemUnits(); final String units = ProfileFunctions.getSystemUnits();
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); final double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); final double highLine = OverviewPlugin.INSTANCE.determineHighLine();
//Start with updating the BG as it is unaffected by loop. //Start with updating the BG as it is unaffected by loop.
// **** BG value **** // **** BG value ****

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.general.overview package info.nightscout.androidaps.plugins.general.overview
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
@ -9,7 +8,6 @@ import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore
@ -65,19 +63,17 @@ object OverviewPlugin : PluginBase(PluginDescription()
super.onStop() super.onStop()
} }
@JvmOverloads fun determineHighLine(): Double {
fun determineHighLine(units: String = ProfileFunctions.getSystemUnits()): Double { var highLineSetting = SP.getDouble(R.string.key_high_mark, bgTargetHigh)
var highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(bgTargetHigh, units))!! if (highLineSetting < 1) highLineSetting = 180.0
if (highLineSetting < 1) highLineSetting = Profile.toCurrentUnits(highLineSetting)
highLineSetting = Profile.fromMgdlToUnits(180.0, units)
return highLineSetting return highLineSetting
} }
@JvmOverloads fun determineLowLine(): Double {
fun determineLowLine(units: String = ProfileFunctions.getSystemUnits()): Double { var lowLineSetting = SP.getDouble(R.string.key_low_mark, bgTargetLow)
var lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(bgTargetLow, units))!! if (lowLineSetting < 1) lowLineSetting = 76.0
if (lowLineSetting < 1) lowLineSetting = Profile.toCurrentUnits(lowLineSetting)
lowLineSetting = Profile.fromMgdlToUnits(76.0, units)
return lowLineSetting return lowLineSetting
} }
} }

View file

@ -1,12 +1,5 @@
package info.nightscout.androidaps.plugins.general.wear.wearintegration; package info.nightscout.androidaps.plugins.general.wear.wearintegration;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -17,9 +10,10 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.CapabilityApi; import com.google.android.gms.wearable.CapabilityApi;
@ -32,31 +26,37 @@ import com.google.android.gms.wearable.PutDataRequest;
import com.google.android.gms.wearable.Wearable; import com.google.android.gms.wearable.Wearable;
import com.google.android.gms.wearable.WearableListenerService; import com.google.android.gms.wearable.WearableListenerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin; import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.ToastUtils; import info.nightscout.androidaps.utils.ToastUtils;
public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
@ -88,7 +88,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
boolean wear_integration = false; boolean wear_integration = false;
SharedPreferences mPrefs;
private static boolean lastLoopStatus; private static boolean lastLoopStatus;
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class); private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
@ -108,7 +107,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
@Override @Override
public void onCreate() { public void onCreate() {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
listenForChangeInSettings(); listenForChangeInSettings();
setSettings(); setSettings();
if (wear_integration) { if (wear_integration) {
@ -305,8 +303,8 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) { private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
String units = ProfileFunctions.getSystemUnits(); String units = ProfileFunctions.getSystemUnits();
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); Double highLine = OverviewPlugin.INSTANCE.determineHighLine();
// convert to mg/dl // convert to mg/dl
if (!units.equals(Constants.MGDL)) { if (!units.equals(Constants.MGDL)) {
@ -748,14 +746,14 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
dataMapRequest.getDataMap().putString("externalStatusString", status); dataMapRequest.getDataMap().putString("externalStatusString", status);
dataMapRequest.getDataMap().putString("iobSum", iobSum); dataMapRequest.getDataMap().putString("iobSum", iobSum);
dataMapRequest.getDataMap().putString("iobDetail", iobDetail); dataMapRequest.getDataMap().putString("iobDetail", iobDetail);
dataMapRequest.getDataMap().putBoolean("detailedIob", mPrefs.getBoolean("wear_detailediob", false)); dataMapRequest.getDataMap().putBoolean("detailedIob", SP.getBoolean(R.string.key_wear_detailediob, false));
dataMapRequest.getDataMap().putString("cob", cobString); dataMapRequest.getDataMap().putString("cob", cobString);
dataMapRequest.getDataMap().putString("currentBasal", currentBasal); dataMapRequest.getDataMap().putString("currentBasal", currentBasal);
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery); dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
dataMapRequest.getDataMap().putString("rigBattery", rigBattery); dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus); dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus);
dataMapRequest.getDataMap().putString("bgi", bgiString); dataMapRequest.getDataMap().putString("bgi", bgiString);
dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putBoolean("showBgi", SP.getBoolean(R.string.key_wear_showbgi, false));
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
debugData("sendStatus", putDataRequest); debugData("sendStatus", putDataRequest);
@ -789,7 +787,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
private void executeTask(AsyncTask task, DataMap... parameters) { private void executeTask(AsyncTask task, DataMap... parameters) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])parameters); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) parameters);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// } else { // } else {
@ -818,7 +816,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
} }
String iobString = ""; String iobString = "";
if (mPrefs.getBoolean("wear_detailediob", false)) { if (SP.getBoolean(R.string.key_wear_detailediob, false)) {
iobString = iobSum + " " + iobDetail; iobString = iobSum + " " + iobDetail;
} else { } else {
iobString = iobSum + "U"; iobString = iobSum + "U";
@ -827,7 +825,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
status += currentBasal + " " + iobString; status += currentBasal + " " + iobString;
//add BGI if shown, otherwise return //add BGI if shown, otherwise return
if (mPrefs.getBoolean("wear_showbgi", false)) { if (SP.getBoolean(R.string.key_wear_showbgi, false)) {
status += " " + bgiString; status += " " + bgiString;
} }

View file

@ -1639,7 +1639,11 @@
<string name="common_off">Off</string> <string name="common_off">Off</string>
<string name="nopumpselected">No pump selected</string> <string name="nopumpselected">No pump selected</string>
<string name="setupwizard_units_prompt">Select units you want to display values in</string> <string name="setupwizard_units_prompt">Select units you want to display values in</string>
<string name="key_ns_uploadlocalprofile">ns_uploadlocalprofile</string> <string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string>
<string name="ns_ploadlocalprofile">Upload local profile changes to NS</string> <string name="ns_ploadlocalprofile">Upload local profile changes to NS</string>
<string name="key_low_mark" translatable="false">low_mark</string>
<string name="key_high_mark" translatable="false">high_mark</string>
<string name="key_wear_detailediob" translatable="false">wear_detailediob</string>
<string name="key_wear_showbgi" translatable="false">wear_showbgi</string>
</resources> </resources>

View file

@ -59,12 +59,12 @@
<EditTextPreference <EditTextPreference
android:defaultValue="0" android:defaultValue="0"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:key="low_mark" android:key="@string/key_low_mark"
android:title="@string/low_mark" /> android:title="@string/low_mark" />
<EditTextPreference <EditTextPreference
android:defaultValue="0" android:defaultValue="0"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:key="high_mark" android:key="@string/key_high_mark"
android:title="@string/high_mark" /> android:title="@string/high_mark" />
</PreferenceScreen> </PreferenceScreen>
<SwitchPreference <SwitchPreference

View file

@ -61,7 +61,7 @@
android:title="@string/wear_display_settings"> android:title="@string/wear_display_settings">
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="wear_detailediob" android:key="@string/key_wear_detailediob"
android:summary="@string/wear_detailedIOB_summary" android:summary="@string/wear_detailedIOB_summary"
android:title="@string/wear_detailedIOB_title" /> android:title="@string/wear_detailedIOB_title" />
@ -73,7 +73,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="wear_showbgi" android:key="@string/key_wear_showbgi"
android:summary="@string/wear_showbgi_summary" android:summary="@string/wear_showbgi_summary"
android:title="@string/wear_showbgi_title" /> android:title="@string/wear_showbgi_title" />
<SwitchPreference <SwitchPreference