From ec535b9c61e6b5e935db8313f677ceef42d21bda Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 28 Nov 2019 19:54:59 +0100 Subject: [PATCH] low_mark, high_mark units dependent --- .../activities/PreferencesActivity.java | 8 +++- .../general/overview/OverviewFragment.java | 4 +- .../general/overview/OverviewPlugin.kt | 20 ++++---- .../wearintegration/WatchUpdaterService.java | 46 +++++++++---------- app/src/main/res/values/strings.xml | 6 ++- app/src/main/res/xml/pref_others.xml | 4 +- app/src/main/res/xml/pref_wear.xml | 4 +- 7 files changed, 48 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 3490c2d98f..34b52498f8 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -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())); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index ccf7c3a95d..f3b718743e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -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 **** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt index bcba0e335e..96d6396f87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt @@ -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 } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index 4f241cec6b..39676f17b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -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; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5dc900c68f..b05d0844fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1639,7 +1639,11 @@ Off No pump selected Select units you want to display values in - ns_uploadlocalprofile + ns_uploadlocalprofile Upload local profile changes to NS + low_mark + high_mark + wear_detailediob + wear_showbgi diff --git a/app/src/main/res/xml/pref_others.xml b/app/src/main/res/xml/pref_others.xml index cbe2b9c705..cea39d60e8 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -59,12 +59,12 @@ @@ -73,7 +73,7 @@