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
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())) {
editTextPref = (EditTextPreference) pref;
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 units = ProfileFunctions.getSystemUnits();
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
final double highLine = OverviewPlugin.INSTANCE.determineHighLine();
//Start with updating the BG as it is unaffected by loop.
// **** BG value ****

View file

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

View file

@ -1,12 +1,5 @@
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.Intent;
import android.content.IntentFilter;
@ -17,9 +10,10 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
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.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.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
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.TreatmentsInterface;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
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.overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
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.SP;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.ToastUtils;
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;
SharedPreferences mPrefs;
private static boolean lastLoopStatus;
private static Logger log = LoggerFactory.getLogger(WatchUpdaterService.class);
@ -108,7 +107,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
@Override
public void onCreate() {
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
listenForChangeInSettings();
setSettings();
if (wear_integration) {
@ -139,7 +137,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
googleApiClient.disconnect();
}
googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Wearable.API).build();
.addOnConnectionFailedListener(this).addApi(Wearable.API).build();
Wearable.MessageApi.addListener(googleApiClient, this);
if (googleApiClient.isConnected()) {
log.debug(logPrefix + "API client is connected");
@ -305,8 +303,8 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) {
String units = ProfileFunctions.getSystemUnits();
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
Double lowLine = OverviewPlugin.INSTANCE.determineLowLine();
Double highLine = OverviewPlugin.INSTANCE.determineHighLine();
// convert to mg/dl
if (!units.equals(Constants.MGDL)) {
@ -748,14 +746,14 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
dataMapRequest.getDataMap().putString("externalStatusString", status);
dataMapRequest.getDataMap().putString("iobSum", iobSum);
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("currentBasal", currentBasal);
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus);
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);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
debugData("sendStatus", putDataRequest);
@ -789,7 +787,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
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) {
// task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// } else {
@ -818,7 +816,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
}
String iobString = "";
if (mPrefs.getBoolean("wear_detailediob", false)) {
if (SP.getBoolean(R.string.key_wear_detailediob, false)) {
iobString = iobSum + " " + iobDetail;
} else {
iobString = iobSum + "U";
@ -827,7 +825,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
status += currentBasal + " " + iobString;
//add BGI if shown, otherwise return
if (mPrefs.getBoolean("wear_showbgi", false)) {
if (SP.getBoolean(R.string.key_wear_showbgi, false)) {
status += " " + bgiString;
}

View file

@ -1639,7 +1639,11 @@
<string name="common_off">Off</string>
<string name="nopumpselected">No pump selected</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="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>

View file

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

View file

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